| [1] | 1 | #!/usr/bin/perl | 
|---|
|  | 2 | use strict; | 
|---|
|  | 3 |  | 
|---|
|  | 4 | # signup-scripts-backend | 
|---|
|  | 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 $username = $ARGV[0]; | 
|---|
|  | 26 |  | 
|---|
|  | 27 | # Complain unless submitted username contains only valid characters | 
|---|
|  | 28 | complain("bad username") unless($username =~ /^[\w._-]+$/); | 
|---|
|  | 29 |  | 
|---|
| [489] | 30 | open BANNEDUSERS, "</afs/athena.mit.edu/contrib/scripts/admin/users.banned" or | 
|---|
|  | 31 | complain("internal error"); | 
|---|
| [488] | 32 | while (<BANNEDUSERS>) { | 
|---|
|  | 33 | chomp; | 
|---|
| [489] | 34 | complain("banned username") if ($_ eq $username); | 
|---|
| [488] | 35 | } | 
|---|
|  | 36 | close(BANNEDUSERS); | 
|---|
| [1] | 37 |  | 
|---|
|  | 38 | my $homedir; | 
|---|
| [435] | 39 | my $filsys = `@hesinfo_path@ $username filsys | @sort_path@ -nk5 | @head_path@ -n1`; | 
|---|
| [1] | 40 | # AFS /afs/athena.mit.edu/user/j/b/jbarnold w /mit/jbarnold | 
|---|
| [435] | 41 | if($filsys =~ /^AFS\s(\/afs\/[\w\._\/-]+)\s.*\s\/mit\/$username(?: [0-9]+)?$/) { | 
|---|
| [1] | 42 | $homedir = $1; | 
|---|
|  | 43 | } | 
|---|
|  | 44 | else { | 
|---|
|  | 45 | complain("athena user not found"); | 
|---|
|  | 46 | } | 
|---|
|  | 47 |  | 
|---|
| [432] | 48 | # Tell AFS that we don't want to trigger fakestat, and confirm user's homedir | 
|---|
|  | 49 | chdir $homedir or complain("athena homedir not found"); | 
|---|
| [378] | 50 |  | 
|---|
| [432] | 51 | # Obtain user's homedir uid | 
|---|
|  | 52 | my ($spam, $spam, $spam, $spam, $uid1, $gid1, $spam, $spam, $spam, $spam, $spam, $egg, $spam) = stat '.' or complain("athena homedir not found"); | 
|---|
| [1] | 53 |  | 
|---|
|  | 54 | # Complain if user's uid is too low or too high | 
|---|
| [11] | 55 | complain("bad uid") unless($uid1 > 110 and $uid1 < (1 << 31)); | 
|---|
| [1] | 56 |  | 
|---|
|  | 57 | # Complain if user's .scripts-signup file does not exist | 
|---|
| [432] | 58 | #complain("scripts-signup file not found") unless(-e '.scripts-signup'); | 
|---|
| [1] | 59 |  | 
|---|
|  | 60 | # Complain if the user's username is already taken | 
|---|
|  | 61 | complain("username already taken") if(getpwnam $username); | 
|---|
|  | 62 |  | 
|---|
|  | 63 | # Complain if user's uid is already taken | 
|---|
|  | 64 | complain("uid already taken") if(getpwuid $uid1); | 
|---|
|  | 65 |  | 
|---|
|  | 66 | if($homedir !~ /\/afs\/athena\.mit\.edu\/user\//) { | 
|---|
|  | 67 | $gid1 = $uid1; | 
|---|
|  | 68 | } | 
|---|
|  | 69 |  | 
|---|
|  | 70 | # Complain if user's gid is already taken | 
|---|
|  | 71 | complain("gid already taken") if(getgrgid $gid1); | 
|---|
|  | 72 |  | 
|---|
| [485] | 73 | my $pid; | 
|---|
|  | 74 | defined ($pid = open LDAP, '|-') or complain("internal error"); | 
|---|
|  | 75 | if (!$pid) { | 
|---|
|  | 76 | close STDOUT; | 
|---|
|  | 77 | open STDOUT, '>/dev/null'; | 
|---|
|  | 78 | exec '@ldapadd_path@', '-c', '-x', '-D', 'cn=Directory Manager', '-y', '/etc/signup-ldap-pw'; | 
|---|
|  | 79 | exit 1; | 
|---|
|  | 80 | } | 
|---|
|  | 81 | print LDAP <<EOF; | 
|---|
|  | 82 | dn: uid=$username,ou=People,dc=scripts,dc=mit,dc=edu | 
|---|
|  | 83 | objectClass: posixAccount | 
|---|
|  | 84 | cn: $username | 
|---|
|  | 85 | uid: $username | 
|---|
|  | 86 | uidNumber: $uid1 | 
|---|
|  | 87 | gidNumber: $gid1 | 
|---|
|  | 88 | homeDirectory: $homedir | 
|---|
|  | 89 | loginShell: /usr/local/bin/mbash | 
|---|
|  | 90 |  | 
|---|
|  | 91 | dn: cn=$username,ou=Groups,dc=scripts,dc=mit,dc=edu | 
|---|
|  | 92 | objectClass: posixGroup | 
|---|
|  | 93 | cn: $username | 
|---|
|  | 94 | gidNumber: $gid1 | 
|---|
|  | 95 |  | 
|---|
|  | 96 | dn: apacheServerName=$username.scripts.mit.edu,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu | 
|---|
|  | 97 | objectclass: apacheConfig | 
|---|
|  | 98 | apacheServerName: $username.scripts.mit.edu | 
|---|
|  | 99 | apacheServerAlias: $username.scripts | 
|---|
|  | 100 | apacheDocumentRoot: $homedir | 
|---|
|  | 101 | apacheSuexecUid: $uid1 | 
|---|
|  | 102 | apacheSuexecGid: $gid1 | 
|---|
|  | 103 |  | 
|---|
|  | 104 | EOF | 
|---|
|  | 105 | close LDAP or complain("internal error"); | 
|---|
| [1] | 106 | # Add disk quota for user | 
|---|
| [485] | 107 | #system('@sudo_path@', '-u', 'root', '/usr/sbin/setquota', $username, '0', '25000', '0', '10000', '-a'); | 
|---|
| [1] | 108 |  | 
|---|
|  | 109 | printexit("done", 0); | 
|---|
|  | 110 |  | 
|---|
|  | 111 | sub complain { | 
|---|
|  | 112 | my ($complaint) = @_; | 
|---|
|  | 113 | printexit($complaint, 1); | 
|---|
|  | 114 | } | 
|---|
|  | 115 |  | 
|---|
|  | 116 | sub printexit { | 
|---|
|  | 117 | my ($msg, $status) = @_; | 
|---|
|  | 118 | print $msg; | 
|---|
|  | 119 | exit($status); | 
|---|
|  | 120 | } | 
|---|