summaryrefslogtreecommitdiff
path: root/usr/local/sbin/rmaccess
diff options
context:
space:
mode:
Diffstat (limited to 'usr/local/sbin/rmaccess')
-rwxr-xr-xusr/local/sbin/rmaccess39
1 files changed, 39 insertions, 0 deletions
diff --git a/usr/local/sbin/rmaccess b/usr/local/sbin/rmaccess
new file mode 100755
index 0000000..2f7e06e
--- /dev/null
+++ b/usr/local/sbin/rmaccess
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my( $reponame, $uid, $gitowner);
+
+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), plus (+) and minus (-) signs, and periods (.).\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);
+
+unless( -d "/srv/git/$reponame.git" ) {
+ print( "/srv/git/$reponame.git doesn't exist!\n" );
+ exit( 2 );
+};
+
+$gitowner = (stat( "/srv/git/$reponame.git" ))[4]; # grab owner uid of repository
+
+if( ( $gitowner != $uid ) and ( $gitowner != 65534 ) ) {
+ print( "$reponame is not owned by you!\n" );
+ exit( 3 );
+};
+
+system( "/usr/sbin/deluser $ARGV[0] git-$reponame" );