]>
git.cameronkatri.com Git - pw-darwin.git/blob - adduser/adduser.sh
5 # Copyright (c) 1994 GB Data Systems
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. The name of the Author may not be used to endorse or promote products
16 # derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY GB DATA AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL GB DATA OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # $Id: adduser,v 1.4 1994/12/28 17:27:21 gclarkii Exp $
33 $configfile = "\/etc\/adduser.conf";
36 open
(CONFIG
, "$configfile");
42 open
(WHOAMI
, "whoami|");
49 if ($whoami ne
"root") {
51 print
"\n\nYou must be root to add an user\n\n";
57 # Start getting information and print a banner
60 print
" A system utility for adding users with defaults\n";
68 print
"Please enter the login name of the user: ";
69 chop
($userlogin = <STDIN
>);
74 print
"Please enter the user id or hit enter for the next id: ";
75 chop
($userid = <STDIN
>);
82 open
(USERID
, "+<$userids");
83 chop
($xxuserid = <USERID
>);
84 $userid = $xxuserid + 1;
86 open
(USERID
, "+>$userids");
87 print
(USERID
"$userid\n");
98 print
"Please enter the group id or hit enter for the default id: ";
99 chop
($groupid = <STDIN
>);
107 $groupid = "$defgroupid";
108 } else { &groupids
; }
109 } else { &groupids
; }
116 print
"Please enter the user's name: ";
117 chop
($username = <STDIN
>);
123 print
"Please enter the users home directory or hit enter for default: ";
124 chop
($userdir = <STDIN
>);
127 $userdir = "$defusrdir\/$userlogin";
135 print
"Please enter the users login shell or hit enter for default: ";
136 chop
($usershell = <STDIN
>);
139 $usershell = "$userdefshell";
140 print
"$usershell\n";
144 # Create password file entry
147 print
"Opening and locking passwd file in blocking mode.\n";
148 open
(PASS
, '>>/etc/master.passwd');
149 flock
(PASS
, 2) || die
"Can't lock passwd file, must be in use!!\n";
150 print
(PASS
"$userlogin::$userid:$groupid::0:0:$username,,,:$userdir:$usershell\n");
151 print
"Unlocking and closing password file\n";
154 print
"Re-indexing password databases\n";
155 system
'pwd_mkdb -p /etc/master.passwd';
156 system
"passwd $userlogin";
159 # Create user directory
161 print
"Creating user directory\n";
162 if (! -e $defusrdir) {
163 system
"mkdir -p $defusrdir\/$userdir";
165 system
"mkdir $userdir";
169 print
"Copying user shell files\n";
170 system
"cp $skel_location\/dot.login $userdir\/\.login";
171 system
"cp $skel_location\/dot.profile $userdir\/\.profile";
173 if ($usershell eq
"\/bin\/csh" || $usershell eq
"\/usr\/local\/bin\/tcsh")
175 system
"cp $skel_location\/dot.cshrc $userdir\/.cshrc";
177 system
"chmod -R 664 $userdir";
178 system
"chown -R $userid.$groupid $userdir";
183 # Print out information used in creation of this account
186 print
"Information used to create this account follows.\n";
188 print
"Login Name: $userlogin\n";
189 print
"UserId: $userid\n";
190 print
"GroupId: $groupid\n";
191 print
"UserName: $username\n";
192 print
"HomeDir: $userdir\n";
193 print
"Shell: $usershell\n";