X-Git-Url: https://git.cameronkatri.com/pw-darwin.git/blobdiff_plain/d8f99db12f55e1f07f7eb60a408904a29aa56d65..915db992527047f57a15af2b1af49bf841b7d78a:/adduser/adduser.perl
diff --git a/adduser/adduser.perl b/adduser/adduser.perl
index 42a1c5e..8e5dc53 100644
--- a/adduser/adduser.perl
+++ b/adduser/adduser.perl
@@ -24,7 +24,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $Id: adduser.perl,v 1.24 1996/12/29 15:06:52 wosch Exp $
+# $Id: adduser.perl,v 1.38 1997/12/24 11:44:14 wosch Exp $
# read variables
@@ -33,7 +33,7 @@ sub variables {
$defaultpasswd = "yes"; # use password for new users
$dotdir = "/usr/share/skel"; # copy dotfiles from this dir
$dotdir_bak = $dotdir;
- $send_message = "no"; # send message to new user
+ $send_message = "/etc/adduser.message"; # send message to new user
$send_message_bak = '/etc/adduser.message';
$config = "/etc/adduser.conf"; # config file for adduser
$config_read = 1; # read config file
@@ -53,6 +53,7 @@ sub variables {
$defaultshell = 'sh'; # defaultshell if not empty
$group_uniq = 'USER';
$defaultgroup = $group_uniq;# login groupname, $group_uniq means username
+ $defaultclass = '';
$uid_start = 1000; # new users get this uid
$uid_end = 32000; # max. uid
@@ -73,18 +74,6 @@ sub variables {
# shell
$shell = ''; # $shell{`basename sh`} = sh
- # only for me (=Wolfram)
- if ($test) {
- $home = "/home/w/tmp/adduser/home";
- $etc_shells = "./shells";
- $etc_passwd = "./master.passwd";
- $group = "./group";
- $pwd_mkdb = "pwd_mkdb -p -d .";
- $config = "adduser.conf";
- $send_message = "./adduser.message";
- $logfile = "./log.adduser";
- }
-
umask 022; # don't give login group write access
$ENV{'PATH'} = "/sbin:/bin:/usr/sbin:/usr/bin";
@@ -116,13 +105,13 @@ sub shells_read {
}
}
-# Allow /nonexistent and /bin/date as a valid shell for system utils
+ # Allow /nonexistent and /bin/date as a valid shell for system utils
push(@list, "/nonexistent");
- push(@shellpref, "no");
+ push(@shellpref, "no") if !grep(/^no$/, @shellpref);
$shell{"no"} = "/nonexistent";
push(@list, "/bin/date");
- push(@shellpref, "date");
+ push(@shellpref, "date") if !grep(/^date$/, @shellpref);
$shell{"date"} = "/bin/date";
return $err;
@@ -231,7 +220,7 @@ sub home_partition_valid {
# check for valid passwddb
sub passwd_check {
- system("$pwd_mkdb -c $etc_passwd");
+ system("$pwd_mkdb -C $etc_passwd");
die "\nInvalid $etc_passwd - cannot add any users!\n" if $?;
}
@@ -245,6 +234,10 @@ sub passwd_read {
while(
) {
chop;
push(@passwd_backup, $_);
+ # ignore comments
+ next if /^\s*$/;
+ next if /^\s*#/;
+
($p_username, $pw, $p_uid, $p_gid, $sh) = (split(/:/, $_))[0..3,9];
print "$p_username already exists with uid: $username{$p_username}!\n"
@@ -256,7 +249,7 @@ sub passwd_read {
if ($verbose && $sh &&
!$shell{&basename($sh)} &&
$p_username !~ /^(news|xten|bin|nobody|uucp)$/ &&
- $sh !~ /\/(pppd|sliplogin)$/);
+ $sh !~ /\/(pppd|sliplogin|nologin|nonexistent)$/);
$uid{$p_uid} = $p_username;
$pwgid{$p_gid} = $p_username;
}
@@ -272,6 +265,10 @@ sub group_read {
while() {
chop;
push(@group_backup, $_);
+ # ignore comments
+ next if /^\s*$/;
+ next if /^\s*#/;
+
($g_groupname, $pw, $g_gid, $memb) = (split(/:/, $_))[0..3];
$groupmembers{$g_gid} = $memb;
@@ -320,7 +317,7 @@ sub new_users_name {
sub new_users_name_valid {
local($name) = @_;
- if ($name !~ /^[a-z0-9_][a-z0-9_\-]*$/) {
+ if ($name !~ /^[a-z0-9_][a-z0-9_\-]*$/ || $name eq "a-z0-9_-") {
warn "Wrong username. " .
"Please use only lowercase characters or digits\a\n";
return 0;
@@ -372,17 +369,30 @@ sub new_users_id {
! $uid{$u_id_tmp};
if ($uid{$u_id_tmp}) {
warn "Uid ``$u_id_tmp'' in use!\a\n";
+ $uid_start = $u_id_tmp;
+ ($u_id, $g_id) = &next_id($name);
+ next;
} else {
warn "Wrong uid.\a\n";
}
}
# use calculated uid
- return ($u_id_tmp, $g_id) if $u_id_tmp eq $u_id;
+ # return ($u_id_tmp, $g_id) if $u_id_tmp eq $u_id;
# recalculate gid
$uid_start = $u_id_tmp;
return &next_id($name);
}
+# return login class for user
+sub new_users_class {
+ local($def) = @_;
+ local($class);
+
+ $class = &confirm_list("Enter login class:", 1, $def, ($def, "default"));
+ $class = "" if $class eq "default";
+ return $class;
+}
+
# add user to group
sub add_group {
local($gid, $name) = @_;
@@ -524,6 +534,7 @@ Password: ****
Fullname: $fullname
Uid: $u_id
Gid: $g_id ($group_login)
+Class: $class
Groups: $group_login $new_groups
HOME: $home/$name
Shell: $sh
@@ -668,9 +679,10 @@ sub new_users {
# sh: shell
# u_id: user id
# g_id: group id
+ # class: login class
# group_login: groupname of g_id
# new_groups: some other groups
- local($name, $group_login, $fullname, $sh, $u_id, $g_id, $new_groups);
+ local($name, $group_login, $fullname, $sh, $u_id, $g_id, $class, $new_groups);
local($groupmembers_bak, $cryptpwd);
local($new_users_ok) = 1;
@@ -683,6 +695,7 @@ sub new_users {
$fullname = &new_users_fullname($name);
$sh = &new_users_shell;
($u_id, $g_id) = &new_users_id($name);
+ $class = &new_users_class($defaultclass);
($group_login, $defaultgroup) =
&new_users_grplogin($name, $defaultgroup, $new_users_ok);
# do not use uniq username and login group
@@ -699,7 +712,7 @@ sub new_users {
$cryptpwd = crypt($password, &salt) if $password ne "";
# obscure perl bug
$new_entry = "$name\:" . "$cryptpwd" .
- "\:$u_id\:$g_id\::0:0:$fullname:$home/$name:$sh";
+ "\:$u_id\:$g_id\:$class\:0:0:$fullname:$home/$name:$sh";
&append_file($etc_passwd, "$new_entry");
&new_users_pwdmkdb("$new_entry");
&new_users_group_update;
@@ -719,7 +732,7 @@ sub new_users {
}
sub batch {
- local($name, $groups, $fullname, $password) = @_;
+ local($name, $groups, $class, $fullname, $password) = @_;
local($sh);
$defaultshell = &shell_default_valid($defaultshell);
@@ -736,11 +749,12 @@ sub batch {
($flag, $new_groups) = &new_users_groups_valid($groups);
return 0 if $flag;
+ $class = $defaultclass if $class eq "";
$cryptpwd = "";
$cryptpwd = crypt($password, &salt) if $password ne "";
# obscure perl bug
$new_entry = "$name\:" . "$cryptpwd" .
- "\:$u_id\:$g_id\::0:0:$fullname:$home/$name:$sh";
+ "\:$u_id\:$g_id\:$class\:0:0:$fullname:$home/$name:$sh";
&append_file($etc_passwd, "$new_entry");
&new_users_pwdmkdb("$new_entry");
&new_users_group_update;
@@ -770,8 +784,9 @@ sub check_root {
sub usage {
warn <