From f620044156b1e80354b45ac0d8934bed5da1c098 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Sun, 6 Dec 2009 14:39:40 +0530 Subject: [PATCH] wildrepos: implement getperms and setperms --- src/gitolite.pm | 20 ++++++++++++++++++++ src/gl-auth-command | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/gitolite.pm b/src/gitolite.pm index f341ab1..4507f54 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -123,6 +123,26 @@ sub repo_rights return ($c, $r, $w); } +# ---------------------------------------------------------------------------- +# getperms and setperms +# ---------------------------------------------------------------------------- + +sub get_set_perms +{ + my($repo_base_abs, $repo, $verb, $user) = @_; + my ($creater, $dummy, $dummy2) = &repo_rights($repo_base_abs, $repo, ""); + die "$repo doesnt exist or is not yours\n" unless $user eq $creater; + wrap_chdir("$repo_base_abs"); + wrap_chdir("$repo.git"); + if ($verb eq 'getperms') { + print STDERR `cat gl-perms 2>/dev/null`; + } else { + system("cat > gl-perms"); + print STDERR "New perms are:\n"; + print STDERR `cat gl-perms`; + } +} + # ---------------------------------------------------------------------------- # parse the compiled acl # ---------------------------------------------------------------------------- diff --git a/src/gl-auth-command b/src/gl-auth-command index eff0d77..d74b20d 100755 --- a/src/gl-auth-command +++ b/src/gl-auth-command @@ -60,6 +60,36 @@ unless ($ENV{SSH_ORIGINAL_COMMAND}) { } my $cmd = $ENV{SSH_ORIGINAL_COMMAND}; +my $repo_base_abs = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" ); + +# ---------------------------------------------------------------------------- +# get and set perms for actual repo created by wildcard-autoviv +# ---------------------------------------------------------------------------- + +my $CUSTOM_COMMANDS=qr/^\s*(expand|getperms|setperms)\s/; + +# note that all the subs called here chdir somewhere else and do not come +# back; they all blithely take advantage of the fact that processing custom +# commands is sort of a dead end for normal (git) processing + +if ($cmd =~ $CUSTOM_COMMANDS) { + my ($verb, $repo) = ($cmd =~ /^\s*(\S+)\s+\/?(.*?)(?:.git)?$/); + if ($repo =~ $REPONAME_PATT and $verb =~ /getperms|setperms/) { + # with an actual reponame, you can "getperms" or "setperms" + get_set_perms($repo_base_abs, $repo, $verb, $user); + } + elsif ($repo !~ $REPONAME_PATT and $verb eq 'expand') { + # with a wildcard, you can "expand" it to see what repos actually match + die "not implemented yet\n"; + } else { + die "$cmd doesn't make sense to me\n"; + } + exit 1; +} + +# ---------------------------------------------------------------------------- +# normal (git) processing +# ---------------------------------------------------------------------------- # split into command and arguments; the pattern allows old style as well as # new style: "git-subcommand arg" or "git subcommand arg", just like gitosis @@ -78,8 +108,6 @@ die "bad command: $cmd. Make sure the repo name is exactly as in your config\n" # first level permissions check # ---------------------------------------------------------------------------- -my $repo_base_abs = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" ); - if ( -d "$repo_base_abs/$repo.git" ) { # existing repo my ($creater, $user_R, $user_W) = &repo_rights($repo_base_abs, $repo, $user);