adduser.sh revision 112401
1#!/bin/sh 2# 3# Copyright (c) 2002, 2003 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# 14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24# 25# Email: Mike Makonnen <mtm@identd.net> 26# 27# $FreeBSD: head/usr.sbin/adduser/adduser.sh 112401 2003-03-19 08:07:15Z mtm $ 28# 29 30# err msg 31# Display $msg on stderr, unless we're being quiet. 32# 33err() { 34 if [ -z "$quietflag" ]; then 35 echo 1>&2 ${THISCMD}: ERROR: $* 36 fi 37} 38 39# info msg 40# Display $msg on stdout, unless we're being quiet. 41# 42info() { 43 if [ -z "$quietflag" ]; then 44 echo ${THISCMD}: INFO: $* 45 fi 46} 47 48# get_nextuid 49# Output the value of $_uid if it is available for use. If it 50# is not, output the value of the next higher uid that is available. 51# If a uid is not specified, output the first available uid, as indicated 52# by pw(8). 53# 54get_nextuid () { 55 _uid=$1 56 _nextuid= 57 58 if [ -z "$_uid" ]; then 59 _nextuid="`${PWCMD} usernext | cut -f1 -d:`" 60 else 61 while : ; do 62 ${PWCMD} usershow $_uid > /dev/null 2>&1 63 if [ ! "$?" -eq 0 ]; then 64 _nextuid=$_uid 65 break 66 fi 67 _uid=$(($_uid + 1)) 68 done 69 fi 70 echo $_nextuid 71} 72 73# show_usage 74# Display usage information for this utility. 75# 76show_usage() { 77 echo "usage: ${THISCMD} [options]" 78 echo " options may include:" 79 echo " -C save to the configuration file only" 80 echo " -E disable this account after creation" 81 echo " -G additional groups to add accounts to" 82 echo " -L login class of the user" 83 echo " -N do not read configuration file" 84 echo " -d home directory" 85 echo " -f file from which input will be received" 86 echo " -h display this usage message" 87 echo " -k path to skeleton home directory" 88 echo " -m user welcome message file" 89 echo " -q absolute minimal user feedback" 90 echo " -s shell" 91 echo " -u uid to start at" 92 echo " -w password type: no, none, yes or random" 93} 94 95# valid_shells 96# Outputs a list of valid shells from /etc/shells. Only the 97# basename of the shell is output. 98# 99valid_shells() { 100 _prefix= 101 cat ${ETCSHELLS} | 102 while read _path _junk ; do 103 case $_path in 104 \#*|'') 105 ;; 106 *) 107 echo -n "${_prefix}`basename $_path`" 108 _prefix=' ' 109 ;; 110 esac 111 done 112} 113 114# fullpath_from_shell shell 115# Given $shell, the basename component of a valid shell, get the 116# full path to the shell from the /etc/shells file. 117# 118fullpath_from_shell() { 119 _shell=$1 120 [ -z "$_shell" ] && return 1 121 122 cat ${ETCSHELLS} | 123 while read _path _junk ; do 124 case "$_path" in 125 \#*|'') 126 ;; 127 *) 128 if [ "`basename $_path`" = "$_shell" ]; then 129 echo $_path 130 return 0 131 fi 132 ;; 133 esac 134 done 135 return 1 136} 137 138# save_config 139# Save some variables to a configuration file. 140# Note: not all script variables are saved, only those that 141# it makes sense to save. 142# 143save_config() { 144 echo "# Configuration file for adduser(8)." > ${ADDUSERCONF} 145 echo "# NOTE: only *some* variables are saved." >> ${ADDUSERCONF} 146 echo "# Last Modified on `${DATECMD}`." >> ${ADDUSERCONF} 147 echo '' >> ${ADDUSERCONF} 148 echo "defaultclass=$uclass" >> ${ADDUSERCONF} 149 echo "defaultgroups=$ugroups" >> ${ADDUSERCONF} 150 echo "passwdtype=$passwdtype" >> ${ADDUSERCONF} 151 echo "homeprefix=$homeprefix" >> ${ADDUSERCONF} 152 echo "defaultshell=$ushell" >> ${ADDUSERCONF} 153 echo "udotdir=$udotdir" >> ${ADDUSERCONF} 154 echo "msgfile=$msgfile" >> ${ADDUSERCONF} 155 echo "disableflag=$disableflag" >> ${ADDUSERCONF} 156} 157 158# add_user 159# Add a user to the user database. If the user chose to send a welcome 160# message or lock the account, do so. 161# 162add_user() { 163 164 # Is this a configuration run? If so, don't modify user database. 165 # 166 if [ -n "$configflag" ]; then 167 save_config 168 return 169 fi 170 171 _uid= 172 _name= 173 _comment= 174 _gecos= 175 _home= 176 _group= 177 _grouplist= 178 _shell= 179 _class= 180 _dotdir= 181 _expire= 182 _pwexpire= 183 _passwd= 184 _upasswd= 185 _passwdmethod= 186 187 _name="-n '$username'" 188 [ -n "$uuid" ] && _uid='-u "$uuid"' 189 [ -n "$ulogingroup" ] && _group='-g "$ulogingroup"' 190 [ -n "$ugroups" ] && _grouplist='-G "$ugroups"' 191 [ -n "$ushell" ] && _shell='-s "$ushell"' 192 [ -n "$uhome" ] && _home='-m -d "$uhome"' 193 [ -n "$uclass" ] && _class='-L "$uclass"' 194 [ -n "$ugecos" ] && _comment='-c "$ugecos"' 195 [ -n "$udotdir" ] && _dotdir='-k "$udotdir"' 196 [ -n "$uexpire" ] && _expire='-e "$uexpire"' 197 [ -n "$upwexpire" ] && _pwexpire='-p "$upwexpire"' 198 case $passwdtype in 199 no) 200 _passwdmethod="-w no" 201 _passwd="-h -" 202 ;; 203 yes) 204 # Note on processing the password: The outer double quotes 205 # make literal everything except ` and \ and $. 206 # The outer single quotes make literal ` and $. 207 # We can ensure the \ isn't treated specially by specifying 208 # the -r switch to the read command used to obtain the input. 209 # 210 _passwdmethod="-w yes" 211 _passwd="-h 0" 212 _upasswd='echo "$upass" |' 213 ;; 214 none) 215 _passwdmethod="-w none" 216 ;; 217 random) 218 _passwdmethod="-w random" 219 ;; 220 esac 221 222 _pwcmd="$_upasswd ${PWCMD} useradd $_uid $_name $_group $_grouplist $_comment" 223 _pwcmd="$_pwcmd $_shell $_class $_home $_dotdir $_passwdmethod $_passwd" 224 _pwcmd="$_pwcmd $_expire $_pwexpire" 225 226 if ! _output=`eval $_pwcmd` ; then 227 err "There was an error adding user ($username)." 228 return 1 229 else 230 info "Successfully added ($username) to the user database." 231 if [ "random" = "$passwdtype" ]; then 232 randompass="$_output" 233 info "Password for ($username) is: $randompass" 234 fi 235 fi 236 237 if [ -n "$disableflag" ]; then 238 if ${PWCMD} lock $username ; then 239 info "Account ($username) is locked." 240 else 241 info "Account ($username) could NOT be locked." 242 fi 243 fi 244 245 _line= 246 _owner= 247 _perms= 248 if [ -n "$msgflag" ]; then 249 [ -r "$msgfile" ] && { 250 # We're evaluating the contents of an external file. 251 # Let's not open ourselves up for attack. _perms will 252 # be empty if it's writeable only by the owner. _owner 253 # will *NOT* be empty if the file is owned by root. 254 # 255 _dir="`dirname $msgfile`" 256 _file="`basename $msgfile`" 257 _perms=`/usr/bin/find $_dir -name $_file -perm +07022 -prune` 258 _owner=`/usr/bin/find $_dir -name $_file -user 0 -prune` 259 if [ -z "$_owner" -o -n "$_perms" ]; then 260 err "The message file ($msgfile) may be writeable only by root." 261 return 1 262 fi 263 cat "$msgfile" | 264 while read _line ; do 265 eval echo "$_line" 266 done | ${MAILCMD} -s"Welcome" ${username} 267 info "Sent welcome message to ($username)." 268 } 269 fi 270} 271 272# get_user 273# Reads username of the account from standard input or from a global 274# variable containing an account line from a file. The username is 275# required. If this is an interactive session it will prompt in 276# a loop until a username is entered. If it is batch processing from 277# a file it will output an error message and return to the caller. 278# 279get_user() { 280 _input= 281 282 # No need to take down user names if this is a configuration saving run. 283 [ -n "$configflag" ] && return 284 285 while : ; do 286 if [ -z "$fflag" ]; then 287 echo -n "Username: " 288 read _input 289 else 290 _input="`echo "$fileline" | cut -f1 -d:`" 291 fi 292 293 # There *must* be a username. If this is an interactive 294 # session give the user an opportunity to retry. 295 # 296 if [ -z "$_input" ]; then 297 err "You must enter a username!" 298 [ -z "$fflag" ] && continue 299 fi 300 break 301 done 302 username="$_input" 303} 304 305# get_gecos 306# Reads extra information about the user. Can be used both in interactive 307# and batch (from file) mode. 308# 309get_gecos() { 310 _input= 311 312 # No need to take down additional user information for a configuration run. 313 [ -n "$configflag" ] && return 314 315 if [ -z "$fflag" ]; then 316 echo -n "Full name: " 317 read _input 318 else 319 _input="`echo "$fileline" | cut -f7 -d:`" 320 fi 321 ugecos="$_input" 322} 323 324# get_shell 325# Get the account's shell. Works in interactive and batch mode. It 326# accepts only the base name of the shell, NOT the full path. 327# If an invalid shell is entered it will simply use the default shell. 328# 329get_shell() { 330 _input= 331 _fullpath= 332 ushell="$defaultshell" 333 334 # Make sure the current value of the shell is a valid one 335 _shellchk="${GREPCMD} '^$ushell$' ${ETCSHELLS} > /dev/null 2>&1" 336 eval $_shellchk || { 337 err "Invalid shell ($ushell). Using default shell ${defaultshell}." 338 ushell="$defaultshell" 339 } 340 341 if [ -z "$fflag" ]; then 342 echo -n "Shell ($shells) [`basename $ushell`]: " 343 read _input 344 else 345 _input="`echo "$fileline" | cut -f9 -d:`" 346 fi 347 if [ -n "$_input" ]; then 348 _fullpath=`fullpath_from_shell $_input` 349 if [ -n "$_fullpath" ]; then 350 ushell="$_fullpath" 351 else 352 err "Invalid shell selection. Using default shell ${defaultshell}." 353 ushell="$defaultshell" 354 fi 355 fi 356} 357 358# get_homedir 359# Reads the account's home directory. Used both with interactive input 360# and batch input. 361# 362get_homedir() { 363 _input= 364 if [ -z "$fflag" ]; then 365 echo -n "Home directory [${homeprefix}/${username}]: " 366 read _input 367 else 368 _input="`echo "$fileline" | cut -f8 -d:`" 369 fi 370 371 if [ -n "$_input" ]; then 372 uhome="$_input" 373 # if this is a configuration run, then user input is the home 374 # directory prefix. Otherwise it is understood to 375 # be $prefix/$user 376 # 377 [ -z "$configflag" ] && homeprefix="`dirname $uhome`" || homeprefix="$uhome" 378 else 379 uhome="${homeprefix}/${username}" 380 fi 381} 382 383# get_uid 384# Reads a numeric userid in an interactive or batch session. Automatically 385# allocates one if it is not specified. 386# 387get_uid() { 388 uuid=${uidstart} 389 _input= 390 _prompt= 391 392 # No need to take down uids for a configuration saving run. 393 [ -n "$configflag" ] && return 394 395 if [ -n "$uuid" ]; then 396 _prompt="Uid [$uuid]: " 397 else 398 _prompt="Uid (Leave empty for default): " 399 fi 400 if [ -z "$fflag" ]; then 401 echo -n "$_prompt" 402 read _input 403 else 404 _input="`echo "$fileline" | cut -f2 -d:`" 405 fi 406 407 [ -n "$_input" ] && uuid=$_input 408 uuid=`get_nextuid $uuid` 409 uidstart=$uuid 410} 411 412# get_class 413# Reads login class of account. Can be used in interactive or batch mode. 414# 415get_class() { 416 uclass="$defaultclass" 417 _input= 418 _class=${uclass:-"default"} 419 420 if [ -z "$fflag" ]; then 421 echo -n "Login class [$_class]: " 422 read _input 423 else 424 _input="`echo "$fileline" | cut -f4 -d:`" 425 fi 426 427 [ -n "$_input" ] && uclass="$_input" 428} 429 430# get_logingroup 431# Reads user's login group. Can be used in both interactive and batch 432# modes. The specified value can be a group name or its numeric id. 433# This routine leaves the field blank if nothing is provided. The pw(8) 434# command will then provide a login group with the same name as the username. 435# 436get_logingroup() { 437 ulogingroup= 438 _input= 439 440 # No need to take down a login group for a configuration saving run. 441 [ -n "$configflag" ] && return 442 443 if [ -z "$fflag" ]; then 444 echo -n "Login group [$username]: " 445 read _input 446 else 447 _input="`echo "$fileline" | cut -f3 -d:`" 448 fi 449 450 # Pw(8) will use the username as login group if it's left empty 451 [ -n "$_input" ] && ulogingroup="$_input" || ulogingroup= 452} 453 454# get_groups 455# Read additional groups for the user. It can be used in both interactive 456# and batch modes. 457# 458get_groups() { 459 ugroups="$defaultgroups" 460 _input= 461 _group=${ulogingroup:-"${username}"} 462 463 if [ -z "$configflag" ]; then 464 [ -z "$fflag" ] && echo -n "Login group is $_group. Invite $username" 465 [ -z "$fflag" ] && echo -n " into other groups? [$ugroups]: " 466 else 467 [ -z "$fflag" ] && echo -n "Enter additional groups [$ugroups]: " 468 fi 469 read _input 470 471 [ -n "$_input" ] && ugroups="$_input" 472} 473 474# get_expire_dates 475# Read expiry information for the account and also for the password. This 476# routine is used only from batch processing mode. 477# 478get_expire_dates() { 479 upwexpire="`echo "$fileline" | cut -f5 -d:`" 480 uexpire="`echo "$fileline" | cut -f6 -d:`" 481} 482 483# get_password 484# Read the password in batch processing mode. The password field matters 485# only when the password type is "yes" or "random". If the field is empty and the 486# password type is "yes", then it assumes the account has an empty passsword 487# and changes the password type accordingly. If the password type is "random" 488# and the password field is NOT empty, then it assumes the account will NOT 489# have a random password and set passwdtype to "yes." 490# 491get_password() { 492 # We may temporarily change a password type. Make sure it's changed 493 # back to whatever it was before we process the next account. 494 # 495 [ -n "$savedpwtype" ] && { 496 passwdtype=$savedpwtype 497 savedpwtype= 498 } 499 500 # There may be a ':' in the password 501 upass=${fileline#*:*:*:*:*:*:*:*:*:} 502 503 if [ -z "$upass" ]; then 504 case $passwdtype in 505 yes) 506 # if it's empty, assume an empty password 507 passwdtype=none 508 savedpwtype=yes 509 ;; 510 esac 511 else 512 case $passwdtype in 513 random) 514 passwdtype=yes 515 savedpwtype=random 516 ;; 517 esac 518 fi 519} 520 521# input_from_file 522# Reads a line of account information from standard input and 523# adds it to the user database. 524# 525input_from_file() { 526 _field= 527 528 while read -r fileline ; do 529 case "$fileline" in 530 \#*|'') 531 return 0 532 ;; 533 esac 534 535 get_user || continue 536 get_gecos 537 get_uid 538 get_logingroup 539 get_class 540 get_shell 541 get_homedir 542 get_password 543 get_expire_dates 544 545 add_user 546 done 547} 548 549# input_interactive 550# Prompts for user information interactively, and commits to 551# the user database. 552# 553input_interactive() { 554 555 _disable= 556 _pass= 557 _passconfirm= 558 _random="no" 559 _emptypass="no" 560 _usepass="yes" 561 _logingroup_ok="no" 562 _groups_ok="no" 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 "$configflag" ] && 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 if [ -z "$configflag" ]; then 910 echo -n "Add another user? (yes/no): " 911 else 912 echo -n "Re-edit the default configuration? (yes/no): " 913 fi 914 read _input 915 case $_input in 916 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 917 uidstart=`get_nextuid $uidstart` 918 input_interactive 919 continue 920 ;; 921 [Nn][Oo]|[Nn]) 922 echo "Goodbye!" 923 ;; 924 *) 925 continue 926 ;; 927 esac 928 break 929 done 930fi 931