| [1] | 1 | #!/usr/bin/perl | 
|---|
|  | 2 | use 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 |  | 
|---|
|  | 25 | my $targetuser; | 
|---|
|  | 26 | unless(($targetuser) = ($ARGV[0] =~ /^([\w._-]+)$/)) { | 
|---|
|  | 27 | error("Invalid locker name: <$ARGV[0]>."); | 
|---|
|  | 28 | } | 
|---|
|  | 29 | my $curuser; | 
|---|
| [322] | 30 | unless(($curuser) = ($ARGV[1] =~ /^([\w._\/-]+)\@ATHENA\.MIT\.EDU$/)) { | 
|---|
| [1] | 31 | error("An internal error has occurred.\nContact scripts\@mit.edu for assistance."); | 
|---|
|  | 32 | } | 
|---|
|  | 33 |  | 
|---|
| [322] | 34 | ($curuser) =~ s|/|.|; # Replace first instance of a / only; pts membership prints foo/root as foo.root | 
|---|
|  | 35 |  | 
|---|
|  | 36 | if (($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 |  | 
|---|
| [450] | 40 | my (undef, undef, $uid, undef, undef, undef, undef, $home, undef, undef) | 
|---|
|  | 41 | = getpwnam $targetuser; | 
|---|
|  | 42 | if(defined $uid) { | 
|---|
|  | 43 | error() if ($uid <= 1000); | 
|---|
|  | 44 | } else { | 
|---|
|  | 45 | $home = "/mit/$targetuser"; | 
|---|
| [170] | 46 | } | 
|---|
|  | 47 |  | 
|---|
| [450] | 48 | my $cell; | 
|---|
|  | 49 | unless(open WHICHCELL, '-|') { | 
|---|
|  | 50 | close STDERR; | 
|---|
|  | 51 | exec '@fs_path@', 'whichcell', '-path', $home; | 
|---|
|  | 52 | die; | 
|---|
|  | 53 | } | 
|---|
| [1] | 54 |  | 
|---|
| [450] | 55 | unless(($cell) = (<WHICHCELL> =~ /^File \Q$home\E lives in cell '(.*)'$/)) { | 
|---|
|  | 56 | error("Cannot find locker <$targetuser>."); | 
|---|
|  | 57 | } | 
|---|
|  | 58 | close WHICHCELL; | 
|---|
|  | 59 |  | 
|---|
|  | 60 | open LISTACL, '-|', '@fs_path@', 'listacl', '-path', $home; | 
|---|
|  | 61 |  | 
|---|
| [1] | 62 | #Access list for . is | 
|---|
|  | 63 | #Normal rights: | 
|---|
|  | 64 | #  system:scripts-root rlidwka | 
|---|
|  | 65 | #  system:anyuser rl | 
|---|
|  | 66 |  | 
|---|
| [450] | 67 | unless(<LISTACL> eq "Access list for $home is\n" && | 
|---|
|  | 68 | <LISTACL> eq "Normal rights:\n") { | 
|---|
| [1] | 69 | error("Cannot find locker <$targetuser>."); | 
|---|
|  | 70 | } | 
|---|
|  | 71 |  | 
|---|
| [450] | 72 | if($ARGV[2] && !defined $uid) { | 
|---|
| [1] | 73 | error("Locker <$targetuser> does not have a scripts.mit.edu account."); | 
|---|
|  | 74 | } | 
|---|
|  | 75 |  | 
|---|
| [494] | 76 | my @targetacl = <LISTACL>; | 
|---|
| [496] | 77 | unshift(@targetacl, "  system:scripts-root a"); | 
|---|
| [494] | 78 |  | 
|---|
|  | 79 | close LISTACL; | 
|---|
|  | 80 |  | 
|---|
|  | 81 | foreach(@targetacl) { | 
|---|
| [450] | 82 | last unless /^  /; | 
|---|
|  | 83 | my ($name) = /^  ([\w:_.-]+) \w*a\w*$/ or next; | 
|---|
|  | 84 | if($name eq $curuser) { success(); } | 
|---|
|  | 85 | elsif($name =~ /:/) { | 
|---|
|  | 86 | unless(open MEMBERSHIP, '-|') { | 
|---|
|  | 87 | close STDERR; | 
|---|
|  | 88 | exec '@pts_path@', 'membership', '-nameorid', $name, '-cell', $cell; | 
|---|
|  | 89 | die; | 
|---|
|  | 90 | } | 
|---|
| [1] | 91 |  | 
|---|
|  | 92 | #Members of system:scripts-root (id: -56104) are: | 
|---|
|  | 93 | #  hartmans | 
|---|
|  | 94 | #  jbarnold | 
|---|
|  | 95 | #  presbrey | 
|---|
|  | 96 | #  tabbott | 
|---|
|  | 97 | #  hartmans.root | 
|---|
|  | 98 |  | 
|---|
| [450] | 99 | next unless(<MEMBERSHIP> =~ /^Members of \Q$name\E \(id: \S+\) are:$/); | 
|---|
|  | 100 | while(<MEMBERSHIP>) { | 
|---|
|  | 101 | success() if($_ eq "  $curuser\n"); | 
|---|
| [1] | 102 | } | 
|---|
| [450] | 103 | close MEMBERSHIP; | 
|---|
| [1] | 104 | } | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | print <<END; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | ERROR: | 
|---|
|  | 110 | It appears as though you are not an administrator of locker <$targetuser>. | 
|---|
|  | 111 | In order to be able to su to <$targetuser>, you must have full AFS access | 
|---|
|  | 112 | to the root directory of locker <$targetuser>.  Try running the command | 
|---|
|  | 113 | fs sa /mit/$targetuser $curuser all | 
|---|
|  | 114 | on Athena in order to explicitly grant yourself full AFS access. | 
|---|
|  | 115 | Contact scripts\@mit.edu if you are unable to solve the problem. | 
|---|
|  | 116 |  | 
|---|
|  | 117 | END | 
|---|
|  | 118 |  | 
|---|
|  | 119 | exit(1); | 
|---|
|  | 120 |  | 
|---|
|  | 121 | sub error { | 
|---|
| [124] | 122 | print "\nERROR:\n$_[0]\n\n"; | 
|---|
| [1] | 123 | exit(1); | 
|---|
|  | 124 | } | 
|---|
|  | 125 |  | 
|---|
|  | 126 | sub success { | 
|---|
| [124] | 127 | print "yes"; | 
|---|
| [1] | 128 | exit(33); | 
|---|
|  | 129 | } | 
|---|