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

Last change on this file since 378 was 378, checked in by geofft, 15 years ago
should fix the fakestat bug [help.mit.edu #460923]
File size: 3.0 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
30complain("banned username") if(`@grep_path@ '$username' /afs/athena.mit.edu/contrib/scripts/admin/users.banned` != "");
31
32my $homedir;
33my $filsys = `@hesinfo_path@ $username filsys`;
34# AFS /afs/athena.mit.edu/user/j/b/jbarnold w /mit/jbarnold
35if($filsys =~ /^AFS\s(\/afs\/[\w\._\/-]+)\s.*\s\/mit\/$username$/) {
36        $homedir = $1;
37}
38else {
39        complain("athena user not found");
40}
41
42# Tell AFS that we don't want to trigger fakestat
43chdir $homedir;
44
45# Run ls to confirm user's homedir and obtain user's homedir uid
46my $ls_regexp = '^\S*\s+\S*\s+(\S*)\s+(\S*)\s+\S*\s+\S*\s+\S*\s+\S*\s+(\S*).*$';
47my ($uid1, $gid1, $name1) = (`@ls_path@ -dln '$homedir'` =~ $ls_regexp);
48
49# Complain if user's homedir does not exist
50complain("athena homedir not found") unless($name1 eq $homedir);
51
52# Complain if user's uid is too low or too high
53complain("bad uid") unless($uid1 > 110 and $uid1 < (1 << 31));
54
55# Run ls to confirm user's .scripts-signup file
56my ($uid2, $gid2, $name2) = (`@ls_path@ -dln '$homedir/.scripts-signup'` =~ $ls_regexp);
57
58# Complain if user's .scripts-signup file does not exist
59#complain("scripts-signup file not found") unless($name2 eq "$homedir/.scripts-signup");
60
61# Complain if the user's username is already taken
62complain("username already taken") if(getpwnam $username);
63
64# Complain if user's uid is already taken
65complain("uid already taken") if(getpwuid $uid1);
66
67if($homedir !~ /\/afs\/athena\.mit\.edu\/user\//) {
68        $gid1 = $uid1;
69}
70
71# Complain if user's gid is already taken
72complain("gid already taken") if(getgrgid $gid1);
73
74# Add user to /etc/passwd
75`@sudo_path@ -u root @groupadd_path@ -g '$gid1' '$username'`;
76`@sudo_path@ -u root @useradd_path@ -d '$homedir' -s '/usr/local/bin/mbash' -u '$uid1' -g '$gid1' -G users '$username'`;
77# Add disk quota for user
78`@sudo_path@ -u root @setquota_path@ '$username' 0 25000 0 10000 -a`;
79
80printexit("done", 0);
81
82sub complain {
83  my ($complaint) = @_;
84  printexit($complaint, 1);
85}
86
87sub printexit {
88  my ($msg, $status) = @_;
89  print $msg;
90  exit($status);
91}
Note: See TracBrowser for help on using the repository browser.