X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;ds=sidebyside;f=groupmanage%2Fgroupmanage;h=21a7327c76da7f544ab9daa3aec6cc476c1fd794;hb=564fbf9bcb4ff56ff2fcbc018fd5a85cdfeb4ea2;hp=9d9401955c549c2ba33a3d019ee6e2c4d938fad3;hpb=85dbc5e7cd8fd86fe1b35926f58f3589a4c8376e;p=userv-utils.git diff --git a/groupmanage/groupmanage b/groupmanage/groupmanage index 9d94019..21a7327 100755 --- a/groupmanage/groupmanage +++ b/groupmanage/groupmanage @@ -1,10 +1,10 @@ #!/usr/bin/perl # -# Copyright (C)1995-9 Ian Jackson +# Copyright (C) 1995-9, 2003 Ian Jackson # Copyright (C) 1999, 2003 -# Chancellor Masters and Scholars of the University of Cambridge +# Chancellor Masters and Scholars of the University of Cambridge # -# Hacked by Ben Harris in 1999 and 2003 for Unix +# Improved by Ben Harris in 1999 and 2003 for Unix # Support's own nefarious purposes. # # This is free software; you can redistribute it and/or modify it @@ -61,7 +61,6 @@ $groupname =~ m/^\w[-0-9A-Za-z]*$/ || @ARGV || push(@ARGV,'--info'); $callinguser= exists $ENV{'USERV_UID'} ? $ENV{'USERV_UID'} : $<; -$callingname = exists $ENV{'USERV_USER'} ? $ENV{'USERV_USER'} : getpwuid($<); %opt= ('user-create','0', 'user-create-minunameu','5', @@ -73,6 +72,7 @@ $callingname = exists $ENV{'USERV_USER'} ? $ENV{'USERV_USER'} : getpwuid($<); 'gtmp-file','gtmp', 'grouplist-file','grouplist', 'name-regexp','', + 'name-maxlen','8', 'admin-group','', 'finish-command',''); %ovalid= ('user-create','boolean', @@ -85,6 +85,7 @@ $callingname = exists $ENV{'USERV_USER'} ? $ENV{'USERV_USER'} : getpwuid($<); 'gtmp-file','string', 'grouplist-file','string', 'name-regexp','string', + 'name-maxlen','number', 'admin-group','string', 'finish-command','string'); @@ -148,10 +149,9 @@ END if ($ARGV[0] eq '--create') { $opt{'user-create'} || !$callinguser || - ($opt{'admin-group'} && - (getgrnam($opt{'admin-group'}))[3] =~ /(^| )$callingname( |$)/) || &quit("group creation by users disabled by administrator"); - length($groupname) <= 8 || &quit("group names must be 8 chars or fewer"); + length($groupname) <= $opt{'name-maxlen'} || + &quit("group names must be $opt{'name-maxlen'} chars or fewer"); $!=0; (@pw= getpwuid($callinguser)) || &quit("cannot get your passwd entry: $!"); $createby= $pw[0]; @@ -194,8 +194,6 @@ if ($create) { } &weare($owner) || grep(&weare($_),@managers) || !$callinguser || - ($opt{'admin-group'} && - (getgrnam($opt{'admin-group'}))[3] =~ /(^| )$callingname( |$)/) || &quit("you may not manage $groupname"); $action= 'none'; @@ -232,7 +230,7 @@ while (@ARGV) { } elsif (m/^\w[-0-9A-Za-z]*$/) { y/\n//d; $chgu=$_; - getpwnam($chgu) || &quit("username $chgu does not exist"); + defined(getpwnam($chgu)) || &quit("username $chgu does not exist"); eval "\@l = \@$clist; 1" || &quit("internal error: $@"); $already= grep($_ eq $chgu, @l); if ($action eq 'add') { @@ -268,7 +266,7 @@ $grouplist[$grouplistix]= &save($opt{'group-file'},@groupfile); &save($opt{'grouplist-file'},@grouplist); if ($opt{'finish-command'}) { - !system($opt{'finish-command'}) || &quit("finish-command: $!"); + !system($opt{'finish-command'}) || &quit("finish-command: $?"); } unlink($opt{'gtmp-file'}) || &quit("unlock group (remove gtmp): $!"); &p_out; @@ -340,20 +338,7 @@ sub quit { } sub lock { - # NFS-safe Locking per Linux open(2) - my($hostname) = `hostname`; - chomp($hostname); - my($hitching_post) = "$opt{'gtmp-file'}.$hostname.$$"; - open(LOCK, ">$hitching_post") || die "$hitching_post: $!"; - close(LOCK); - link($hitching_post, $opt{'gtmp-file'}); - if ((stat($hitching_post))[3] != 2) { - close(OUT); - unlink($hitching_post); - &quit("group file locked -- giving up..."); - } - unlink($hitching_post); -# link($opt{'group-file'},$opt{'gtmp-file'}) || &quit("create gtmp: $!"); + link($opt{'group-file'},$opt{'gtmp-file'}) || &quit("create gtmp: $!"); $locked++; }