source: server/common/oursrc/accountadm/admof.in @ 389

Last change on this file since 389 was 323, checked in by geofft, 17 years ago
fix a regex
File size: 3.0 KB
Line 
1#!/usr/bin/perl
2use strict;
3
4# admof
5# Copyright (C) 2006  Jeff Arnold <jbarnold@mit.edu>
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License
9# as published by the Free Software Foundation; either version 2
10# of the License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20#
21# See /COPYRIGHT in this repository for more information.
22
23$ENV{PATH} = '';
24
25my $targetuser;
26unless(($targetuser) = ($ARGV[0] =~ /^([\w._-]+)$/)) {
27  error("Invalid locker name: <$ARGV[0]>.");
28}
29my $curuser;
30unless(($curuser) = ($ARGV[1] =~ /^([\w._\/-]+)\@ATHENA\.MIT\.EDU$/)) {
31  error("An internal error has occurred.\nContact scripts\@mit.edu for assistance.");
32}
33
34($curuser) =~ s|/|.|; # Replace first instance of a / only; pts membership prints foo/root as foo.root
35
36if (($curuser) =~ m|/|) { # There were two /'s in their name. What?
37  error("An internal error has occurred.\nContact scripts\@mit.edu for assistance.");
38}
39
40my $uid = getpwnam $targetuser;
41if(defined $uid && $uid <= 1000) {
42  error();
43}
44
45my $fs = `@fs_path@ 2>/dev/null la /mit/$targetuser/`;
46my @fs = split(/\n/, $fs);
47
48#Access list for . is
49#Normal rights:
50#  system:scripts-root rlidwka
51#  system:anyuser rl
52
53unless($fs[0] =~ /^Access list for \/mit\/$targetuser\/ is$/ &&
54       $fs[1] =~ /^Normal rights:$/) {
55  error("Cannot find locker <$targetuser>.");
56}
57
58if($ARGV[2] && !getpwnam($targetuser)) {
59  error("Locker <$targetuser> does not have a scripts.mit.edu account.");
60}
61
62for(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);
70
71#Members of system:scripts-root (id: -56104) are:
72#  hartmans
73#  jbarnold
74#  presbrey
75#  tabbott
76#  hartmans.root
77
78    next if($mems[0] !~ /^Members of $group \(id: \S+\) are:$/);
79   
80    if($mems =~ /\s+\Q$curuser\E\s+/) {
81        success();
82    }
83  }
84}
85
86print <<END;
87
88ERROR:
89It appears as though you are not an administrator of locker <$targetuser>.
90In order to be able to su to <$targetuser>, you must have full AFS access
91to the root directory of locker <$targetuser>.  Try running the command
92fs sa /mit/$targetuser $curuser all
93on Athena in order to explicitly grant yourself full AFS access.
94Contact scripts\@mit.edu if you are unable to solve the problem.
95
96END
97
98exit(1);
99
100sub error {
101  print "\nERROR:\n$_[0]\n\n";
102  exit(1);
103}
104
105sub success {
106  print "yes";
107  exit(33);
108}
Note: See TracBrowser for help on using the repository browser.