Changeset 450 for server


Ignore:
Timestamp:
Oct 6, 2007, 8:42:50 PM (15 years ago)
Author:
andersk
Message:
Rewrite admof to suck somewhat less.  In particular, do pts membership
in the right cell.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/common/oursrc/accountadm/admof.in

    r323 r450  
    3838}
    3939
    40 my $uid = getpwnam $targetuser;
    41 if(defined $uid && $uid <= 1000) {
    42   error();
     40my (undef, undef, $uid, undef, undef, undef, undef, $home, undef, undef)
     41  = getpwnam $targetuser;
     42if(defined $uid) {
     43  error() if ($uid <= 1000);
     44} else {
     45  $home = "/mit/$targetuser";
    4346}
    4447
    45 my $fs = `@fs_path@ 2>/dev/null la /mit/$targetuser/`;
    46 my @fs = split(/\n/, $fs);
     48my $cell;
     49unless(open WHICHCELL, '-|') {
     50  close STDERR;
     51  exec '@fs_path@', 'whichcell', '-path', $home;
     52  die;
     53}
     54
     55unless(($cell) = (<WHICHCELL> =~ /^File \Q$home\E lives in cell '(.*)'$/)) {
     56  error("Cannot find locker <$targetuser>.");
     57}
     58close WHICHCELL;
     59
     60open LISTACL, '-|', '@fs_path@', 'listacl', '-path', $home;
    4761
    4862#Access list for . is
     
    5165#  system:anyuser rl
    5266
    53 unless($fs[0] =~ /^Access list for \/mit\/$targetuser\/ is$/ &&
    54        $fs[1] =~ /^Normal rights:$/) {
     67unless(<LISTACL> eq "Access list for $home is\n" &&
     68       <LISTACL> eq "Normal rights:\n") {
    5569  error("Cannot find locker <$targetuser>.");
    5670}
    5771
    58 if($ARGV[2] && !getpwnam($targetuser)) {
     72if($ARGV[2] && !defined $uid) {
    5973  error("Locker <$targetuser> does not have a scripts.mit.edu account.");
    6074}
    6175
    62 for(my $i = 2; $i < @fs; $i++) {
    63   my ($id) = ($fs[$i] =~ /^  ([\w:_\.-]+) rlidwka$/);
    64   if($id eq "") { next; }
    65   my $group;
    66   if($id eq $curuser) { success(); }
    67   elsif(($group) = ($id =~ /^(system:.+)/)) {
    68     my $mems = `@pts_path@ 2>/dev/null membership $group`;
    69     my @mems = split(/\n/, $mems);
     76while(<LISTACL>) {
     77  last unless /^  /;
     78  my ($name) = /^  ([\w:_.-]+) \w*a\w*$/ or next;
     79  if($name eq $curuser) { success(); }
     80  elsif($name =~ /:/) {
     81    unless(open MEMBERSHIP, '-|') {
     82      close STDERR;
     83      exec '@pts_path@', 'membership', '-nameorid', $name, '-cell', $cell;
     84      die;
     85    }
    7086
    7187#Members of system:scripts-root (id: -56104) are:
     
    7692#  hartmans.root
    7793
    78     next if($mems[0] !~ /^Members of $group \(id: \S+\) are:$/);
    79    
    80     if($mems =~ /\s+\Q$curuser\E\s+/) {
    81         success();
     94    next unless(<MEMBERSHIP> =~ /^Members of \Q$name\E \(id: \S+\) are:$/);
     95    while(<MEMBERSHIP>) {
     96      success() if($_ eq "  $curuser\n");
    8297    }
     98    close MEMBERSHIP;
    8399  }
    84100}
Note: See TracChangeset for help on using the changeset viewer.