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

Last change on this file since 1137 was 827, checked in by andersk, 14 years ago
Create scriptsVhost records automatically.
File size: 4.1 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");
57opendir TEMP, '.';
58closedir TEMP;
59
60# Obtain user's homedir uid
61my (undef, undef, undef, undef, $uid1, $gid1, undef, undef, undef, undef, undef, undef, undef) = stat '.' or complain("athena homedir not found");
62
63# Complain if user's uid is too low or too high
64complain("bad uid") unless($uid1 > 110 and $uid1 < (1 << 31));
65
66# Complain if user's .scripts-signup file does not exist
67#complain("scripts-signup file not found") unless(-e '.scripts-signup');
68
69# Complain if the user's username is already taken
70complain("username already taken") if(getpwnam $username);
71
72# Complain if user's uid is already taken
73complain("uid already taken") if(getpwuid $uid1);
74
75if($homedir !~ /\/afs\/athena\.mit\.edu\/user\//) {
76        $gid1 = $uid1;
77}
78
79# Complain if user's gid is already taken
80complain("gid already taken") if(getgrgid $gid1);
81
82my $pid;
83defined ($pid = open LDAP, '|-') or complain("internal error");
84if (!$pid) {
85        close STDOUT;
86        open STDOUT, '>/dev/null';
87        exec '@ldapadd_path@', '-c', '-x', '-D', 'cn=Directory Manager', '-y', '/etc/signup-ldap-pw';
88        exit 1;
89}
90print LDAP <<EOF;
91dn: uid=$username,ou=People,dc=scripts,dc=mit,dc=edu
92objectClass: posixAccount
93cn: $username
94uid: $username
95uidNumber: $uid1
96gidNumber: $gid1
97homeDirectory: $homedir
98loginShell: /usr/local/bin/mbash
99
100dn: cn=$username,ou=Groups,dc=scripts,dc=mit,dc=edu
101objectClass: posixGroup
102cn: $username
103gidNumber: $gid1
104
105dn: apacheServerName=$username.scripts.mit.edu,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
106objectClass: apacheConfig
107apacheServerName: $username.scripts.mit.edu
108apacheServerAlias: $username.scripts
109apacheDocumentRoot: $homedir/web_scripts
110apacheSuexecUid: $uid1
111apacheSuexecGid: $gid1
112
113dn: scriptsVhostName=$username.scripts.mit.edu,ou=VirtualHosts,dc=scripts,dc=mit,dc=edu
114objectClass: scriptsVhost
115scriptsVhostName: $username.scripts.mit.edu
116scriptsVhostAlias: $username.scripts
117scriptsVhostAccount: uid=$username,ou=People,dc=scripts,dc=mit,dc=edu
118scriptsVhostDirectory:
119
120EOF
121close LDAP or complain("internal error");
122# Add disk quota for user
123#system('@sudo_path@', '-u', 'root', '/usr/sbin/setquota', $username, '0', '25000', '0', '10000', '-a');
124
125printexit("done", 0);
126
127sub complain {
128  my ($complaint) = @_;
129  printexit($complaint, 1);
130}
131
132sub printexit {
133  my ($msg, $status) = @_;
134  print $msg;
135  exit($status);
136}
Note: See TracBrowser for help on using the repository browser.