# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
-# $Id: adduser.perl,v 1.17 1996/09/11 08:36:54 jkh Exp $
+# $Id: adduser.perl,v 1.30 1997/05/01 23:23:06 ache Exp $
# read 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
$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
while(<P>) {
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"
print "User $p_username: illegal shell: ``$sh''\n"
if ($verbose && $sh &&
!$shell{&basename($sh)} &&
- $p_username !~ /^(bin|uucp|falcon|nobody)$/ &&
+ $p_username !~ /^(news|xten|bin|nobody|uucp)$/ &&
$sh !~ /\/(pppd|sliplogin)$/);
$uid{$p_uid} = $p_username;
$pwgid{$p_gid} = $p_username;
while(<G>) {
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;
local($name);
while(1) {
- $name = &confirm_list("Enter username", 1, "a-z0-9", "");
- if (length($name) > 8) {
- warn "Username is longer than 8 chars\a\n";
+ $name = &confirm_list("Enter username", 1, "a-z0-9_-", "");
+ if (length($name) > 16) {
+ warn "Username is longer than 16 chars\a\n";
next;
}
last if (&new_users_name_valid($name) eq $name);
sub new_users_name_valid {
local($name) = @_;
- if ($name !~ /^[a-z0-9]+$/) {
+ if ($name !~ /^[a-z0-9_][a-z0-9_\-]*$/) {
warn "Wrong username. " .
"Please use only lowercase characters or digits\a\n";
return 0;
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) = @_;
Fullname: $fullname
Uid: $u_id
Gid: $g_id ($group_login)
+Class: $class
Groups: $group_login $new_groups
HOME: $home/$name
Shell: $sh
# 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;
$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
$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;
}
sub batch {
- local($name, $groups, $fullname, $password) = @_;
+ local($name, $groups, $class, $fullname, $password) = @_;
local($sh);
$defaultshell = &shell_default_valid($defaultshell);
($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;
sub usage {
warn <<USAGE;
usage: adduser
- [-batch username [group[,group]...] [fullname] [password]]
+ [-batch username [group[,group]...] [class] [fullname] [password]]
[-check_only]
+ [-class login_class]
[-config_create]
[-dotdir dotdir]
[-group login_group]
[-message message_file]
[-noconfig]
[-shell shell]
- [-s|-silent|-q|-quit]
+ [-s|-silent|-q|-quiet]
[-uid uid_start]
[-v|-verbose]
home=$home shell=$defaultshell dotdir=$dotdir login_group=$defaultgroup
-message_file=$send_message uid_start=$uid_start
+login_class=$defaultclass message_file=$send_message uid_start=$uid_start
USAGE
exit 1;
}
shift @argv;
last if /^--$/;
if (/^--?(v|verbose)$/) { $verbose = 1 }
- elsif (/^--?(s|silent|q|quit)$/) { $verbose = 0 }
+ elsif (/^--?(s|silent|q|quiet)$/) { $verbose = 0 }
elsif (/^--?(debug)$/) { $verbose = 2 }
elsif (/^--?(h|help|\?)$/) { &usage }
elsif (/^--?(home)$/) { $home = $argv[0]; shift @argv }
elsif (/^--?(shell)$/) { $defaultshell = $argv[0]; shift @argv }
elsif (/^--?(dotdir)$/) { $dotdir = $argv[0]; shift @argv }
elsif (/^--?(uid)$/) { $uid_start = $argv[0]; shift @argv }
+ elsif (/^--?(class)$/) { $defaultclass = $argv[0]; shift @argv }
elsif (/^--?(group)$/) { $defaultgroup = $argv[0]; shift @argv }
elsif (/^--?(check_only)$/) { $check_only = 1 }
elsif (/^--?(message)$/) { $send_message = $argv[0]; shift @argv;
$sendmessage = 1; }
elsif (/^--?(batch)$/) {
- @batch = splice(@argv, 0, 4); $verbose = 0;
+ @batch = splice(@argv, 0, 5); $verbose = 0;
die "batch: too few arguments\n" if $#batch < 0;
}
# see &config_read
\$fullname,
-your account ``\$name'' was created. Your password is ``\$password''.
-Please expire your password. Have fun!
+your account ``\$name'' was created.
+Have fun!
See also chpass(1), finger(1), passwd(1)
EOF
# defaultshell if not empty ("bash")
defaultshell = "$defaultshell"
-# defaultgroup ('USER' for same as username or any other valid group
+# defaultgroup ('USER' for same as username or any other valid group)
defaultgroup = $defaultgroup
+# defaultclass if not empty
+defaultclass = "$defaultclass"
+
# new users get this uid (1000)
uid_start = 1000