diff options
author | Julian Blake Kongslie <jblake@omgwallhack.org> | 2010-03-18 13:10:28 -0700 |
---|---|---|
committer | Julian Blake Kongslie <jblake@omgwallhack.org> | 2010-03-18 13:10:28 -0700 |
commit | aba2fa2373dea84823061afdfda661283eccf4dd (patch) | |
tree | bf718a45c0fa4d5428d1515518d7cf165406c5da /usr/local/sbin/addaccess | |
parent | 0df6b8d376c6cbac0ed3df910cdcc10c06bd3e18 (diff) | |
download | piny-code-aba2fa2373dea84823061afdfda661283eccf4dd.tar.gz piny-code-aba2fa2373dea84823061afdfda661283eccf4dd.zip |
Convert addaccess and rmaccess to use the Piny modules.
Diffstat (limited to 'usr/local/sbin/addaccess')
-rwxr-xr-x | usr/local/sbin/addaccess | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/usr/local/sbin/addaccess b/usr/local/sbin/addaccess index b1b2916..e2817ca 100755 --- a/usr/local/sbin/addaccess +++ b/usr/local/sbin/addaccess @@ -3,37 +3,17 @@ use strict; use warnings; -my( $reponame, $uid, $gitowner); +use Piny; -if ( ( ! scalar $ARGV[1] ) or ( scalar $ARGV[2] ) ) { # must have exactly two arguments - print( "Usage: addaccess USER REPONAME\n" ); - exit( 1 ); -} elsif ( ( $ARGV[0] !~ /^[a-zA-Z0-9_.][a-zA-Z0-9_.-]+$/ ) or ( $ARGV[1] !~ /^[a-z0-9][a-z0-9-]+$/ ) ) { # Extra paranoid sanity checking - print( "Usage: addaccess USER REPONAME\n" ); - print( " USER must consist only of letters, digits, underscores, periods, and dashes, and not start with a dash.\n" ); - print( " REPONAME must consist only of lower case letters (a-z), digits (0-9), and minus (-) signs.\n" ); - print( " REPONAME must be at least two characters long and must start with an alphanumeric character.\n" ); - exit( 1 ); -} else { - $reponame = $ARGV[1]; -}; - -open (PASSWD, '/etc/passwd'); -while(<PASSWD>) { - if( $_ =~ /^$ENV{SUDO_USER}:.+?:(.+?):/ ) { $uid = $1; }; # grabbing uid. -}; -close(PASSWD); +my $env = Piny::Environment->new( ); -unless( -d "/srv/git/$reponame.git" ) { - print( "/srv/git/$reponame.git doesn't exist!\n" ); - exit( 2 ); -}; +my ( $reponame, @users ) = @ARGV; -$gitowner = (stat( "/srv/git/$reponame.git" ))[4]; # grab owner uid of repository +my $repo = Piny::Repo->new( $reponame ); -if( ( $gitowner != $uid ) and ( $gitowner != 65534 ) ) { - print( "$reponame is not owned by you!\n" ); +if ( $repo->user->uid != $env->user->uid ) { + print "You are not the owner of that repo!\n"; exit( 3 ); }; -system( "/usr/sbin/adduser $ARGV[0] git-$reponame" ); +$repo->add_access( @users ); |