From aba2fa2373dea84823061afdfda661283eccf4dd Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Thu, 18 Mar 2010 13:10:28 -0700 Subject: Convert addaccess and rmaccess to use the Piny modules. --- usr/local/sbin/addaccess | 34 +++++++--------------------------- usr/local/sbin/rmaccess | 34 +++++++--------------------------- 2 files changed, 14 insertions(+), 54 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() { - 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 ); diff --git a/usr/local/sbin/rmaccess b/usr/local/sbin/rmaccess index 06b4f07..86b2dd0 100755 --- a/usr/local/sbin/rmaccess +++ b/usr/local/sbin/rmaccess @@ -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: rmaccess 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: rmaccess 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() { - 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/deluser $ARGV[0] git-$reponame" ); +$repo->remove_access( @users ); -- cgit v1.2.3