adduser.sh revision 110595
1#!/bin/sh 2# 3# Copyright (c) 2002 Michael Telahun Makonnen. All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 3. The name of the author may not be used to endorse or promote products 14# derived from this software without specific prior written permission. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Email: Mike Makonnen <mtm@identd.net> 28# 29# $FreeBSD: head/usr.sbin/adduser/adduser.sh 110595 2003-02-09 18:29:09Z mtm $ 30# 31 32# err msg 33# Display $msg on stderr, unless we're being quiet. 34# 35err() { 36 if [ -z "$quietflag" ]; then 37 echo 1>&2 ${THISCMD}: ERROR: $* 38 fi 39} 40 41# info msg 42# Display $msg on stdout, unless we're being quiet. 43# 44info() { 45 if [ -z "$quietflag" ]; then 46 echo ${THISCMD}: INFO: $* 47 fi 48} 49 50# get_nextuid 51# Output the value of $_uid if it is available for use. If it 52# is not, output the value of the next higher uid that is available. 53# If a uid is not specified, output the first available uid, as indicated 54# by pw(8). 55# 56get_nextuid () { 57 _uid=$1 58 _nextuid= 59 60 if [ -z "$_uid" ]; then 61 _nextuid="`${PWCMD} usernext | cut -f1 -d:`" 62 else 63 while : ; do 64 ${PWCMD} usershow $_uid > /dev/null 2>&1 65 if [ ! "$?" -eq 0 ]; then 66 _nextuid=$_uid 67 break 68 fi 69 _uid=$(($_uid + 1)) 70 done 71 fi 72 echo $_nextuid 73} 74 75# show_usage 76# Display usage information for this utility. 77# 78show_usage() { 79 echo "usage: ${THISCMD} [options]" 80 echo " options may include:" 81 echo " -C save to the configuration file only" 82 echo " -E disable this account after creation" 83 echo " -G additional groups to add accounts to" 84 echo " -L login class of the user" 85 echo " -N do not read configuration file" 86 echo " -d home directory" 87 echo " -f file from which input will be received" 88 echo " -h display this usage message" 89 echo " -k path to skeleton home directory" 90 echo " -m user welcome message file" 91 echo " -q absolute minimal user feedback" 92 echo " -s shell" 93 echo " -u uid to start at" 94 echo " -w password type: no, none, yes or random" 95} 96 97# valid_shells 98# Outputs a list of valid shells from /etc/shells. Only the 99# basename of the shell is output. 100# 101valid_shells() { 102 _prefix= 103 cat ${ETCSHELLS} | 104 while read _path _junk ; do 105 case $_path in 106 \#*|'') 107 ;; 108 *) 109 echo -n "${_prefix}`basename $_path`" 110 _prefix=' ' 111 ;; 112 esac 113 done 114} 115 116# fullpath_from_shell shell 117# Given $shell, the basename component of a valid shell, get the 118# full path to the shell from the /etc/shells file. 119# 120fullpath_from_shell() { 121 _shell=$1 122 [ -z "$_shell" ] && return 1 123 124 cat ${ETCSHELLS} | 125 while read _path _junk ; do 126 case "$_path" in 127 \#*|'') 128 ;; 129 *) 130 if [ "`basename $_path`" = "$_shell" ]; then 131 echo $_path 132 return 0 133 fi 134 ;; 135 esac 136 done 137 return 1 138} 139 140# save_config 141# Save some variables to a configuration file. 142# Note: not all script variables are saved, only those that 143# it makes sense to save. 144# 145save_config() { 146 echo "# Configuration file for adduser(8)." > ${ADDUSERCONF} 147 echo "# NOTE: only *some* variables are saved." >> ${ADDUSERCONF} 148 echo "# Last Modified on `${DATECMD}`." >> ${ADDUSERCONF} 149 echo '' >> ${ADDUSERCONF} 150 echo "defaultclass=$uclass" >> ${ADDUSERCONF} 151 echo "defaultgroups=$ugroups" >> ${ADDUSERCONF} 152 echo "passwdtype=$passwdtype" >> ${ADDUSERCONF} 153 echo "homeprefix=$homeprefix" >> ${ADDUSERCONF} 154 echo "defaultshell=$ushell" >> ${ADDUSERCONF} 155 echo "udotdir=$udotdir" >> ${ADDUSERCONF} 156 echo "msgfile=$msgfile" >> ${ADDUSERCONF} 157 echo "disableflag=$disableflag" >> ${ADDUSERCONF} 158} 159 160# add_user 161# Add a user to the user database. If the user chose to send a welcome 162# message or lock the account, do so. 163# 164add_user() { 165 166 # Is this a configuration run? If so, don't modify user database. 167 # 168 if [ -n "$configflag" ]; then 169 save_config 170 return 171 fi 172 173 _uid= 174 _name= 175 _comment= 176 _gecos= 177 _home= 178 _group= 179 _grouplist= 180 _shell= 181 _class= 182 _dotdir= 183 _expire= 184 _pwexpire= 185 _passwd= 186 _upasswd= 187 _passwdmethod= 188 189 _name="-n '$username'" 190 [ -n "$uuid" ] && _uid='-u "$uuid"' 191 [ -n "$ulogingroup" ] && _group='-g "$ulogingroup"' 192 [ -n "$ugroups" ] && _grouplist='-G "$ugroups"' 193 [ -n "$ushell" ] && _shell='-s "$ushell"' 194 [ -n "$uhome" ] && _home='-m -d "$uhome"' 195 [ -n "$uclass" ] && _class='-L "$uclass"' 196 [ -n "$ugecos" ] && _comment='-c "$ugecos"' 197 [ -n "$udotdir" ] && _dotdir='-k "$udotdir"' 198 [ -n "$uexpire" ] && _expire='-e "$uexpire"' 199 [ -n "$upwexpire" ] && _pwexpire='-p "$upwexpire"' 200 case $passwdtype in 201 no) 202 _passwdmethod="-w no" 203 _passwd="-h -" 204 ;; 205 yes) 206 # Note on processing the password: The outer double quotes 207 # make literal everything except ` and \ and $. 208 # The outer single quotes make literal ` and $. 209 # We can ensure the \ isn't treated specially by specifying 210 # the -r switch to the read command used to obtain the input. 211 # 212 _passwdmethod="-w yes" 213 _passwd="-h 0" 214 _upasswd='echo "$upass" |' 215 ;; 216 none) 217 _passwdmethod="-w none" 218 ;; 219 random) 220 _passwdmethod="-w random" 221 ;; 222 esac 223 224 _pwcmd="$_upasswd ${PWCMD} useradd $_uid $_name $_group $_grouplist $_comment" 225 _pwcmd="$_pwcmd $_shell $_class $_home $_dotdir $_passwdmethod $_passwd" 226 _pwcmd="$_pwcmd $_expire $_pwexpire" 227 228 if ! _output=`eval $_pwcmd` ; then 229 err "There was an error adding user ($username)." 230 return 1 231 else 232 info "Successfully added ($username) to the user database." 233 if [ "random" = "$passwdtype" ]; then 234 randompass="$_output" 235 info "Password for ($username) is: $randompass" 236 fi 237 fi 238 239 if [ -n "$disableflag" ]; then 240 if ${PWCMD} lock $username ; then 241 info "Account ($username) is locked." 242 else 243 info "Account ($username) could NOT be locked." 244 fi 245 fi 246 247 _line= 248 _owner= 249 _perms= 250 if [ -n "$msgflag" ]; then 251 [ -r "$msgfile" ] && { 252 # We're evaluating the contents of an external file. 253 # Let's not open ourselves up for attack. _perms will 254 # be empty if it's writeable only by the owner. _owner 255 # will *NOT* be empty if the file is owned by root. 256 # 257 _dir="`dirname $msgfile`" 258 _file="`basename $msgfile`" 259 _perms=`/usr/bin/find $_dir -name $_file -perm +07022 -prune` 260 _owner=`/usr/bin/find $_dir -name $_file -user 0 -prune` 261 if [ -z "$_owner" -o -n "$_perms" ]; then 262 err "The message file ($msgfile) may be writeable only by root." 263 return 1 264 fi 265 cat "$msgfile" | 266 while read _line ; do 267 eval echo "$_line" 268 done | ${MAILCMD} -s"Welcome" ${username} 269 info "Sent welcome message to ($username)." 270 } 271 fi 272} 273 274# get_user 275# Reads username of the account from standard input or from a global 276# variable containing an account line from a file. The username is 277# required. If this is an interactive session it will prompt in 278# a loop until a username is entered. If it is batch processing from 279# a file it will output an error message and return to the caller. 280# 281get_user() { 282 _input= 283 284 # No need to take down user names if this is a configuration saving run. 285 [ -n "$configflag" ] && return 286 287 while : ; do 288 if [ -z "$fflag" ]; then 289 echo -n "Username: " 290 read _input 291 else 292 _input="`echo "$fileline" | cut -f1 -d:`" 293 fi 294 295 # There *must* be a username. If this is an interactive 296 # session give the user an opportunity to retry. 297 # 298 if [ -z "$_input" ]; then 299 err "You must enter a username!" 300 [ -z "$fflag" ] && continue 301 fi 302 break 303 done 304 username="$_input" 305} 306 307# get_gecos 308# Reads extra information about the user. Can be used both in interactive 309# and batch (from file) mode. 310# 311get_gecos() { 312 _input= 313 314 # No need to take down additional user information for a configuration run. 315 [ -n "$configflag" ] && return 316 317 if [ -z "$fflag" ]; then 318 echo -n "Full name: " 319 read _input 320 else 321 _input="`echo "$fileline" | cut -f7 -d:`" 322 fi 323 ugecos="$_input" 324} 325 326# get_shell 327# Get the account's shell. Works in interactive and batch mode. It 328# accepts only the base name of the shell, NOT the full path. 329# If an invalid shell is entered it will simply use the default shell. 330# 331get_shell() { 332 _input= 333 _fullpath= 334 ushell="$defaultshell" 335 336 # Make sure the current value of the shell is a valid one 337 _shellchk="${GREPCMD} '^$ushell$' ${ETCSHELLS} > /dev/null 2>&1" 338 eval $_shellchk || { 339 err "Invalid shell ($ushell). Using default shell ${defaultshell}." 340 ushell="$defaultshell" 341 } 342 343 if [ -z "$fflag" ]; then 344 echo -n "Shell ($shells) [`basename $ushell`]: " 345 read _input 346 else 347 _input="`echo "$fileline" | cut -f9 -d:`" 348 fi 349 if [ -n "$_input" ]; then 350 _fullpath=`fullpath_from_shell $_input` 351 if [ -n "$_fullpath" ]; then 352 ushell="$_fullpath" 353 else 354 err "Invalid shell selection. Using default shell ${defaultshell}." 355 ushell="$defaultshell" 356 fi 357 fi 358} 359 360# get_homedir 361# Reads the account's home directory. Used both with interactive input 362# and batch input. 363# 364get_homedir() { 365 _input= 366 if [ -z "$fflag" ]; then 367 echo -n "Home directory [${homeprefix}/${username}]: " 368 read _input 369 else 370 _input="`echo "$fileline" | cut -f8 -d:`" 371 fi 372 373 if [ -n "$_input" ]; then 374 uhome="$_input" 375 # if this is a configuration run, then user input is the home 376 # directory prefix. Otherwise it is understood to 377 # be $prefix/$user 378 # 379 [ -z "$configflag" ] && homeprefix="`dirname $uhome`" || homeprefix="$uhome" 380 else 381 uhome="${homeprefix}/${username}" 382 fi 383} 384 385# get_uid 386# Reads a numeric userid in an interactive or batch session. Automatically 387# allocates one if it is not specified. 388# 389get_uid() { 390 uuid=${uidstart} 391 _input= 392 _prompt= 393 394 # No need to take down uids for a configuration saving run. 395 [ -n "$configflag" ] && return 396 397 if [ -n "$uuid" ]; then 398 _prompt="Uid [$uuid]: " 399 else 400 _prompt="Uid (Leave empty for default): " 401 fi 402 if [ -z "$fflag" ]; then 403 echo -n "$_prompt" 404 read _input 405 else 406 _input="`echo "$fileline" | cut -f2 -d:`" 407 fi 408 409 [ -n "$_input" ] && uuid=$_input 410 uuid=`get_nextuid $uuid` 411 uidstart=$uuid 412} 413 414# get_class 415# Reads login class of account. Can be used in interactive or batch mode. 416# 417get_class() { 418 uclass="$defaultclass" 419 _input= 420 _class=${uclass:-"default"} 421 422 if [ -z "$fflag" ]; then 423 echo -n "Login class [$_class]: " 424 read _input 425 else 426 _input="`echo "$fileline" | cut -f4 -d:`" 427 fi 428 429 [ -n "$_input" ] && uclass="$_input" 430} 431 432# get_logingroup 433# Reads user's login group. Can be used in both interactive and batch 434# modes. The specified value can be a group name or its numeric id. 435# This routine leaves the field blank if nothing is provided. The pw(8) 436# command will then provide a login group with the same name as the username. 437# 438get_logingroup() { 439 ulogingroup= 440 _input= 441 442 # No need to take down a login group for a configuration saving run. 443 [ -n "$configflag" ] && return 444 445 if [ -z "$fflag" ]; then 446 echo -n "Login group [$username]: " 447 read _input 448 else 449 _input="`echo "$fileline" | cut -f3 -d:`" 450 fi 451 452 # Pw(8) will use the username as login group if it's left empty 453 [ -n "$_input" ] && ulogingroup="$_input" || ulogingroup= 454} 455 456# get_groups 457# Read additional groups for the user. It can be used in both interactive 458# and batch modes. 459# 460get_groups() { 461 ugroups="$defaultgroups" 462 _input= 463 _group=${ulogingroup:-"${username}"} 464 465 if [ -z "$configflag" ]; then 466 [ -z "$fflag" ] && echo -n "Login group is $_group. Invite $username" 467 [ -z "$fflag" ] && echo -n " into other groups? [$ugroups]: " 468 else 469 [ -z "$fflag" ] && echo -n "Enter additional groups [$ugroups]: " 470 fi 471 read _input 472 473 [ -n "$_input" ] && ugroups="$_input" 474} 475 476# get_expire_dates 477# Read expiry information for the account and also for the password. This 478# routine is used only from batch processing mode. 479# 480get_expire_dates() { 481 upwexpire="`echo "$fileline" | cut -f5 -d:`" 482 uexpire="`echo "$fileline" | cut -f6 -d:`" 483} 484 485# get_password 486# Read the password in batch processing mode. The password field matters 487# only when the password type is "yes" or "random". If the field is empty and the 488# password type is "yes", then it assumes the account has an empty passsword 489# and changes the password type accordingly. If the password type is "random" 490# and the password field is NOT empty, then it assumes the account will NOT 491# have a random password and set passwdtype to "yes." 492# 493get_password() { 494 # We may temporarily change a password type. Make sure it's changed 495 # back to whatever it was before we process the next account. 496 # 497 [ -n "$savedpwtype" ] && { 498 passwdtype=$savedpwtype 499 savedpwtype= 500 } 501 502 # There may be a ':' in the password 503 upass=${fileline#*:*:*:*:*:*:*:*:*:} 504 505 if [ -z "$upass" ]; then 506 case $passwdtype in 507 yes) 508 # if it's empty, assume an empty password 509 passwdtype=none 510 savedpwtype=yes 511 ;; 512 esac 513 else 514 case $passwdtype in 515 random) 516 passwdtype=yes 517 savedpwtype=random 518 ;; 519 esac 520 fi 521} 522 523# input_from_file 524# Reads a line of account information from standard input and 525# adds it to the user database. 526# 527input_from_file() { 528 _field= 529 530 while read -r fileline ; do 531 case "$fileline" in 532 \#*|'') 533 return 0 534 ;; 535 esac 536 537 get_user || continue 538 get_gecos 539 get_uid 540 get_logingroup 541 get_class 542 get_shell 543 get_homedir 544 get_password 545 get_expire_dates 546 547 add_user 548 done 549} 550 551# input_interactive 552# Prompts for user information interactively, and commits to 553# the user database. 554# 555input_interactive() { 556 557 _disable= 558 _pass= 559 _passconfirm= 560 _random="no" 561 _emptypass="no" 562 _usepass="yes" 563 case $passwdtype in 564 none) 565 _emptypass="yes" 566 _usepass="yes" 567 ;; 568 no) 569 _usepass="no" 570 ;; 571 random) 572 _random="yes" 573 ;; 574 esac 575 576 get_user 577 get_gecos 578 get_uid 579 580 # The case where group = user is handled elsewhere, so 581 # validate any other groups the user is invited to. 582 until [ "$_logingroup_ok" = yes ]; do 583 get_logingroup 584 _logingroup_ok=yes 585 if [ -n "$ulogingroup" -a "$username" != "$ulogingroup" ]; then 586 if ! ${PWCMD} show group $ulogingroup > /dev/null 2>&1; then 587 echo "Group $ulogingroup does not exist!" 588 _logingroup_ok=no 589 fi 590 fi 591 done 592 until [ "$_groups_ok" = yes ]; do 593 get_groups 594 _groups_ok=yes 595 for i in $ugroups; do 596 if [ "$username" != "$i" ]; then 597 if ! ${PWCMD} show group $i > /dev/null 2>&1; then 598 echo "Group $i does not exist!" 599 _groups_ok=no 600 fi 601 fi 602 done 603 done 604 605 get_class 606 get_shell 607 get_homedir 608 609 while : ; do 610 echo -n "Use password-based authentication? [$_usepass]: " 611 read _input 612 [ -z "$_input" ] && _input=$_usepass 613 case $_input in 614 [Nn][Oo]|[Nn]) 615 passwdtype="no" 616 ;; 617 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 618 while : ; do 619 echo -n "Use an empty password? (yes/no) [$_emptypass]: " 620 read _input 621 [ -n "$_input" ] && _emptypass=$_input 622 case $_emptypass in 623 [Nn][Oo]|[Nn]) 624 echo -n "Use a random password? (yes/no) [$_random]: " 625 read _input 626 [ -n "$_input" ] && _random="$_input" 627 case $_random in 628 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 629 passwdtype="random" 630 break 631 ;; 632 esac 633 passwdtype="yes" 634 [ -n "$configrun" ] && break 635 trap 'stty echo; exit' 0 1 2 3 15 636 stty -echo 637 echo -n "Enter password: " 638 read -r upass 639 echo'' 640 echo -n "Enter password again: " 641 read _passconfirm 642 echo '' 643 stty echo 644 # if user entered a blank password 645 # explicitly ask again. 646 [ -z "$upass" -a -z "$_passconfirm" ] \ 647 && continue 648 ;; 649 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 650 passwdtype="none" 651 break; 652 ;; 653 *) 654 # invalid answer; repeat the loop 655 continue 656 ;; 657 esac 658 if [ "$upass" != "$_passconfirm" ]; then 659 echo "Passwords did not match!" 660 continue 661 fi 662 break 663 done 664 ;; 665 *) 666 # invalid answer; repeat loop 667 continue 668 ;; 669 esac 670 break; 671 done 672 _disable=${disableflag:-"no"} 673 while : ; do 674 echo -n "Lock out the account after creation? [$_disable]: " 675 read _input 676 [ -z "$_input" ] && _input=$_disable 677 case $_input in 678 [Nn][Oo]|[Nn]) 679 disableflag= 680 ;; 681 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 682 disableflag=yes 683 ;; 684 *) 685 # invalid answer; repeat loop 686 continue 687 ;; 688 esac 689 break 690 done 691 692 # Display the information we have so far and prompt to 693 # commit it. 694 # 695 _disable=${disableflag:-"no"} 696 [ -z "$configflag" ] && printf "%-10s : %s\n" Username $username 697 case $passwdtype in 698 yes) 699 _pass='*****' 700 ;; 701 no) 702 _pass='<disabled>' 703 ;; 704 none) 705 _pass='<blank>' 706 ;; 707 random) 708 _pass='<random>' 709 ;; 710 esac 711 [ -z "$configflag" ] && printf "%-10s : %s\n" "Password" "$_pass" 712 [ -n "$configflag" ] && printf "%-10s : %s\n" "Pass Type" "$passwdtype" 713 [ -z "$configflag" ] && printf "%-10s : %s\n" "Full Name" "$ugecos" 714 [ -z "$configflag" ] && printf "%-10s : %s\n" "Uid" "$uuid" 715 printf "%-10s : %s\n" "Class" "$uclass" 716 [ -z "$configflag" ] && printf "%-10s : %s %s\n" "Groups" "${ulogingroup:-$username}" "$ugroups" 717 printf "%-10s : %s\n" "Home" "$uhome" 718 printf "%-10s : %s\n" "Shell" "$ushell" 719 printf "%-10s : %s\n" "Locked" "$_disable" 720 while : ; do 721 echo -n "OK? (yes/no): " 722 read _input 723 case $_input in 724 [Nn][Oo]|[Nn]) 725 return 1 726 ;; 727 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 728 add_user 729 ;; 730 *) 731 continue 732 ;; 733 esac 734 break 735 done 736 return 0 737} 738 739#### END SUBROUTINE DEFENITION #### 740 741THISCMD=`/usr/bin/basename $0` 742DEFAULTSHELL=/bin/sh 743ADDUSERCONF="${ADDUSERCONF:-/etc/adduser.conf}" 744PWCMD="${PWCMD:-/usr/sbin/pw}" 745MAILCMD="${MAILCMD:-mail}" 746ETCSHELLS="${ETCSHELLS:-/etc/shells}" 747GREPCMD="/usr/bin/grep" 748DATECMD="/bin/date" 749 750# Set default values 751# 752username= 753uuid= 754uidstart= 755ugecos= 756ulogingroup= 757uclass= 758uhome= 759upass= 760ushell= 761udotdir=/usr/share/skel 762ugroups= 763uexpire= 764upwexpire= 765shells="`valid_shells`" 766passwdtype="yes" 767msgfile=/etc/adduser.msg 768msgflag= 769quietflag= 770configflag= 771fflag= 772infile= 773disableflag= 774readconfig="yes" 775homeprefix="/home" 776randompass= 777fileline= 778savedpwtype= 779defaultclass= 780defaultgoups= 781defaultshell="${DEFAULTSHELL}" 782 783# Make sure the user running this program is root. This isn't a security 784# measure as much as it is a usefull method of reminding the user to 785# 'su -' before he/she wastes time entering data that won't be saved. 786# 787procowner=${procowner:-`/usr/bin/id -u`} 788if [ "$procowner" != "0" ]; then 789 err 'you must be the super-user (uid 0) to use this utility.' 790 exit 1 791fi 792 793# Overide from our conf file 794# Quickly go through the commandline line to see if we should read 795# from our configuration file. The actual parsing of the commandline 796# arguments happens after we read in our configuration file (commandline 797# should override configuration file). 798# 799for _i in $* ; do 800 if [ "$_i" = "-N" ]; then 801 readconfig= 802 break; 803 fi 804done 805if [ -n "$readconfig" ]; then 806 # On a long-lived system, the first time this script is run it 807 # will barf upon reading the configuration file for its perl predecessor. 808 if ( . ${ADDUSERCONF} > /dev/null 2>&1 ); then 809 [ -r ${ADDUSERCONF} ] && . ${ADDUSERCONF} > /dev/null 2>&1 810 fi 811fi 812 813# Proccess command-line options 814# 815for _switch ; do 816 case $_switch in 817 -L) 818 defaultclass="$2" 819 shift; shift 820 ;; 821 -C) 822 configflag=yes 823 shift 824 ;; 825 -E) 826 disableflag=yes 827 shift 828 ;; 829 -k) 830 udotdir="$2" 831 shift; shift 832 ;; 833 -f) 834 [ "$2" != "-" ] && infile="$2" 835 fflag=yes 836 shift; shift 837 ;; 838 -G) 839 defaultgroups="$2" 840 shift; shift 841 ;; 842 -h) 843 show_usage 844 exit 0 845 ;; 846 -d) 847 homeprefix="$2" 848 shift; shift 849 ;; 850 -m) 851 case "$2" in 852 [Nn][Oo]) 853 msgflag= 854 ;; 855 *) 856 msgflag=yes 857 msgfile="$2" 858 ;; 859 esac 860 shift; shift 861 ;; 862 -N) 863 readconfig= 864 shift 865 ;; 866 -w) 867 case "$2" in 868 no|none|random|yes) 869 passwdtype=$2 870 ;; 871 *) 872 show_usage 873 exit 1 874 ;; 875 esac 876 shift; shift 877 ;; 878 -q) 879 quietflag=yes 880 shift 881 ;; 882 -s) 883 defaultshell="`fullpath_from_shell $2`" 884 shift; shift 885 ;; 886 -u) 887 uidstart=$2 888 shift; shift 889 ;; 890 esac 891done 892 893# If the -f switch was used, get input from a file. Otherwise, 894# this is an interactive session. 895# 896if [ -n "$fflag" ]; then 897 if [ -z "$infile" ]; then 898 input_from_file 899 elif [ -n "$infile" ]; then 900 if [ -r "$infile" ]; then 901 input_from_file < $infile 902 else 903 err "File ($infile) is unreadable or does not exist." 904 fi 905 fi 906else 907 input_interactive 908 while : ; do 909 echo -n "Add another user? (yes/no): " 910 read _input 911 case $_input in 912 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 913 uidstart=`get_nextuid $uidstart` 914 input_interactive 915 continue 916 ;; 917 [Nn][Oo]|[Nn]) 918 echo "Goodbye!" 919 ;; 920 *) 921 continue 922 ;; 923 esac 924 break 925 done 926fi 927