summaryrefslogtreecommitdiff
path: root/usr/local/sbin/addaccess
diff options
context:
space:
mode:
authorroot <root@piny.svcs.cs.pdx.edu>2009-09-06 04:26:13 -0700
committerroot <root@piny.svcs.cs.pdx.edu>2009-09-06 04:26:13 -0700
commit29355a1653a12742928ce563e4c077a77f67c9f9 (patch)
treea502a34c06c33c08cfb8050527e2c7ae5ceb47ad /usr/local/sbin/addaccess
parent3d47e7f272d128780a2c6c5d94e4c61d7888c3d1 (diff)
downloadpiny-code-29355a1653a12742928ce563e4c077a77f67c9f9.tar.gz
piny-code-29355a1653a12742928ce563e4c077a77f67c9f9.zip
Import of unversioned piny code.
Diffstat (limited to 'usr/local/sbin/addaccess')
-rwxr-xr-xusr/local/sbin/addaccess39
1 files changed, 39 insertions, 0 deletions
diff --git a/usr/local/sbin/addaccess b/usr/local/sbin/addaccess
new file mode 100755
index 0000000..07cc893
--- /dev/null
+++ b/usr/local/sbin/addaccess
@@ -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: 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), 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/adduser $ARGV[0] git-$reponame" );