source: server/common/oursrc/accountadm/signup-scripts-backend.in @ 732

Last change on this file since 732 was 732, checked in by andersk, 17 years ago
Apparently defined(%hash) is deprecated.
File size: 3.8 KB
Line 
1#!/usr/bin/perl
2use 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
25my $username = $ARGV[0];
26
27# Complain unless submitted username contains only valid characters
28complain("bad username") unless($username =~ /^[\w._-]+$/);
29
30open BANNEDUSERS, "</afs/athena.mit.edu/contrib/scripts/admin/users.banned" or
31    complain("internal error");
32while (<BANNEDUSERS>) {
33    chomp;
34    complain("banned username") if ($_ eq $username);
35}
36close(BANNEDUSERS);
37
38my %filsys;
39open HESINFO, '-|', '@hesinfo_path@', '--', $username, 'filsys' or
40    complain("internal error");
41while (<HESINFO>) {
42        chomp;
43        my %f; @f{qw(type path rw mount order)} = split / /;
44        %filsys = %f if (($f{order} || 9999) <= ($filsys{order} || 9999));
45}
46close HESINFO;
47unless (%filsys &&
48        $filsys{type} eq 'AFS' &&
49        $filsys{path} =~ /^\/afs\/[\w\._\/-]+/ &&
50        $filsys{mount} eq "/mit/$username") {
51        complain("athena user not found");
52}
53my $homedir = $filsys{path};
54
55# Tell AFS that we don't want to trigger fakestat, and confirm user's homedir
56chdir $homedir or complain("athena homedir not found");
57
58# Obtain user's homedir uid
59my (undef, undef, undef, undef, $uid1, $gid1, undef, undef, undef, undef, undef, undef, undef) = stat '.' or complain("athena homedir not found");
60
61# Complain if user's uid is too low or too high
62complain("bad uid") unless($uid1 > 110 and $uid1 < (1 << 31));
63
64# Complain if user's .scripts-signup file does not exist
65#complain("scripts-signup file not found") unless(-e '.scripts-signup');
66
67# Complain if the user's username is already taken
68complain("username already taken") if(getpwnam $username);
69
70# Complain if user's uid is already taken
71complain("uid already taken") if(getpwuid $uid1);
72
73if($homedir !~ /\/afs\/athena\.mit\.edu\/user\//) {
74        $gid1 = $uid1;
75}
76
77# Complain if user's gid is already taken
78complain("gid already taken") if(getgrgid $gid1);
79
80my $pid;
81defined ($pid = open LDAP, '|-') or complain("internal error");
82if (!$pid) {
83        close STDOUT;
84        open STDOUT, '>/dev/null';
85        exec '@ldapadd_path@', '-c', '-x', '-D', 'cn=Directory Manager', '-y', '/etc/signup-ldap-pw';
86        exit 1;
87}
88print LDAP <<EOF;
89dn: uid=$username,ou=People,dc=scripts,dc=mit,dc=edu
90objectClass: posixAccount
91cn: $username
92uid: $username
93uidNumber: $uid1
94gidNumber: $gid1
95homeDirectory: $homedir
96loginShell: /usr/local/bin/mbash
97
98dn: cn=$username,ou=Groups,dc=scripts,dc=mit,dc=edu
99objectClass: posixGroup
100cn: $username
101gidNumber: $gid1
102
103dn: apacheServerName=$username.scripts.mit.edu,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
104objectclass: apacheConfig
105apacheServerName: $username.scripts.mit.edu
106apacheServerAlias: $username.scripts
107apacheDocumentRoot: $homedir/web_scripts
108apacheSuexecUid: $uid1
109apacheSuexecGid: $gid1
110
111EOF
112close LDAP or complain("internal error");
113# Add disk quota for user
114#system('@sudo_path@', '-u', 'root', '/usr/sbin/setquota', $username, '0', '25000', '0', '10000', '-a');
115
116printexit("done", 0);
117
118sub complain {
119  my ($complaint) = @_;
120  printexit($complaint, 1);
121}
122
123sub printexit {
124  my ($msg, $status) = @_;
125  print $msg;
126  exit($status);
127}
Note: See TracBrowser for help on using the repository browser.