adduser.sh revision 109751
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 109751 2003-01-23 20:07:40Z fjoe $ 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 echo "adduserlog=$adduserlog" >> ${ADDUSERCONF} 159} 160 161# add_user 162# Add a user to the user database. If the user chose to send a welcome 163# message or lock the account, do so. 164# 165add_user() { 166 167 # Is this a configuration run? If so, don't modify user database. 168 # 169 if [ -n "$configflag" ]; then 170 save_config 171 return 172 fi 173 174 _uid= 175 _name= 176 _comment= 177 _gecos= 178 _home= 179 _group= 180 _grouplist= 181 _shell= 182 _class= 183 _dotdir= 184 _expire= 185 _pwexpire= 186 _passwd= 187 _upasswd= 188 _passwdmethod= 189 190 _name="-n '$username'" 191 [ -n "$uuid" ] && _uid="-u '$uuid'" 192 [ -n "$ulogingroup" ] && _group="-g '$ulogingroup'" 193 [ -n "$ugroups" ] && _grouplist="-G '$ugroups'" 194 [ -n "$ushell" ] && _shell="-s '$ushell'" 195 [ -n "$uhome" ] && _home="-m -d '$uhome'" 196 [ -n "$uclass" ] && _class="-L '$uclass'" 197 [ -n "$ugecos" ] && _comment="-c '$ugecos'" 198 [ -n "$udotdir" ] && _dotdir="-k '$udotdir'" 199 [ -n "$uexpire" ] && _expire="-e '$uexpire'" 200 [ -n "$upwexpire" ] && _pwexpire="-p '$upwexpire'" 201 case $passwdtype in 202 no) 203 _passwdmethod="-w no" 204 _passwd="-h -" 205 ;; 206 yes) 207 _passwdmethod="-w yes" 208 _passwd="-h 0" 209 _upasswd="echo '$upass' |" 210 ;; 211 none) 212 _passwdmethod="-w none" 213 ;; 214 random) 215 _passwdmethod="-w random" 216 ;; 217 esac 218 219 _pwcmd="$_upasswd ${PWCMD} useradd $_uid $_name $_group $_grouplist $_comment" 220 _pwcmd="$_pwcmd $_shell $_class $_home $_dotdir $_passwdmethod $_passwd" 221 _pwcmd="$_pwcmd $_expire $_pwexpire" 222 223 if ! _output=`eval $_pwcmd` ; then 224 err "There was an error adding user ($username)." 225 return 1 226 else 227 info "Successfully added ($username) to the user database." 228 if [ "random" = "$passwdtype" ]; then 229 randompass="$_output" 230 info "Password for ($username) is: $randompass" 231 fi 232 fi 233 234 if [ -n "$disableflag" ]; then 235 if ${PWCMD} lock $username ; then 236 info "Account ($username) is locked." 237 else 238 info "Account ($username) could NOT be locked." 239 fi 240 fi 241 242 _log=${adduserlog:-no} 243 [ x"$_log" = x"no" ] || (echo "$(${DATECMD} +'%Y/%m/%d %T') $(${PWCMD} 2>/dev/null usershow -n $username)" >> $_log) 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 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 case $passwdtype in 562 none) 563 _emptypass="yes" 564 _usepass="yes" 565 ;; 566 no) 567 _usepass="no" 568 ;; 569 random) 570 _random="yes" 571 ;; 572 esac 573 574 get_user 575 get_gecos 576 get_uid 577 get_logingroup 578 get_groups 579 get_class 580 get_shell 581 get_homedir 582 583 while : ; do 584 echo -n "Use password-based authentication? [$_usepass]: " 585 read _input 586 [ -z "$_input" ] && _input=$_usepass 587 case $_input in 588 [Nn][Oo]|[Nn]) 589 passwdtype="no" 590 ;; 591 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 592 while : ; do 593 echo -n "Use an empty password? (yes/no) [$_emptypass]: " 594 read _input 595 [ -n "$_input" ] && _emptypass=$_input 596 case $_emptypass in 597 [Nn][Oo]|[Nn]) 598 echo -n "Use a random password? (yes/no) [$_random]: " 599 read _input 600 [ -n "$_input" ] && _random="$_input" 601 case $_random in 602 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 603 passwdtype="random" 604 break 605 ;; 606 esac 607 passwdtype="yes" 608 [ -n "$configrun" ] && break 609 trap 'stty echo; exit' 0 1 2 3 15 610 stty -echo 611 echo -n "Enter password: " 612 read upass 613 echo'' 614 echo -n "Enter password again: " 615 read _passconfirm 616 echo '' 617 stty echo 618 # if user entered a blank password 619 # explicitly ask again. 620 [ -z "$upass" -a -z "$_passconfirm" ] \ 621 && continue 622 ;; 623 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 624 passwdtype="none" 625 break; 626 ;; 627 *) 628 # invalid answer; repeat the loop 629 continue 630 ;; 631 esac 632 if [ "$upass" != "$_passconfirm" ]; then 633 echo "Passwords did not match!" 634 continue 635 fi 636 break 637 done 638 ;; 639 *) 640 # invalid answer; repeat loop 641 continue 642 ;; 643 esac 644 break; 645 done 646 _disable=${disableflag:-"no"} 647 while : ; do 648 echo -n "Lock out the account after creation? [$_disable]: " 649 read _input 650 [ -z "$_input" ] && _input=$_disable 651 case $_input in 652 [Nn][Oo]|[Nn]) 653 disableflag= 654 ;; 655 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 656 disableflag=yes 657 ;; 658 *) 659 # invalid answer; repeat loop 660 continue 661 ;; 662 esac 663 break 664 done 665 666 # Display the information we have so far and prompt to 667 # commit it. 668 # 669 _disable=${disableflag:-"no"} 670 [ -z "$configflag" ] && printf "%-10s : %s\n" Username $username 671 case $passwdtype in 672 yes) 673 _pass='*****' 674 ;; 675 no) 676 _pass='<disabled>' 677 ;; 678 none) 679 _pass='<blank>' 680 ;; 681 random) 682 _pass='<random>' 683 ;; 684 esac 685 [ -z "$configflag" ] && printf "%-10s : %s\n" "Password" "$_pass" 686 [ -n "$configflag" ] && printf "%-10s : %s\n" "Pass Type" "$passwdtype" 687 [ -z "$configflag" ] && printf "%-10s : %s\n" "Full Name" "$ugecos" 688 [ -z "$configflag" ] && printf "%-10s : %s\n" "Uid" "$uuid" 689 printf "%-10s : %s\n" "Class" "$uclass" 690 [ -z "$configflag" ] && printf "%-10s : %s %s\n" "Groups" "${ulogingroup:-$username}" "$ugroups" 691 printf "%-10s : %s\n" "Home" "$uhome" 692 printf "%-10s : %s\n" "Shell" "$ushell" 693 printf "%-10s : %s\n" "Locked" "$_disable" 694 while : ; do 695 echo -n "OK? (yes/no): " 696 read _input 697 case $_input in 698 [Nn][Oo]|[Nn]) 699 return 1 700 ;; 701 [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) 702 add_user 703 ;; 704 *) 705 continue 706 ;; 707 esac 708 break 709 done 710 return 0 711} 712 713#### END SUBROUTINE DEFENITION #### 714 715THISCMD=`/usr/bin/basename $0` 716DEFAULTSHELL=/bin/sh 717ADDUSERCONF="${ADDUSERCONF:-/etc/adduser.conf}" 718ADDUSERLOG="${ADDUSERLOG:-/var/log/adduser}" 719PWCMD="${PWCMD:-/usr/sbin/pw}" 720MAILCMD="${MAILCMD:-mail}" 721ETCSHELLS="${ETCSHELLS:-/etc/shells}" 722GREPCMD="/usr/bin/grep" 723DATECMD="/bin/date" 724 725# Set default values 726# 727username= 728uuid= 729uidstart= 730ugecos= 731ulogingroup= 732uclass= 733uhome= 734upass= 735ushell= 736udotdir=/usr/share/skel 737ugroups= 738uexpire= 739upwexpire= 740shells="`valid_shells`" 741passwdtype="yes" 742msgfile=/etc/adduser.msg 743msgflag= 744quietflag= 745configflag= 746fflag= 747infile= 748disableflag= 749adduserlog="${ADDUSERLOG}" 750readconfig="yes" 751homeprefix="/home" 752randompass= 753fileline= 754savedpwtype= 755defaultclass= 756defaultgoups= 757defaultshell="${DEFAULTSHELL}" 758 759# Make sure the user running this program is root. This isn't a security 760# measure as much as it is a usefull method of reminding the user to 761# 'su -' before he/she wastes time entering data that won't be saved. 762# 763procowner=${procowner:-`/usr/bin/id -u`} 764if [ "$procowner" != "0" ]; then 765 err 'you must be the super-user (uid 0) to use this utility.' 766 exit 1 767fi 768 769# Overide from our conf file 770# Quickly go through the commandline line to see if we should read 771# from our configuration file. The actual parsing of the commandline 772# arguments happens after we read in our configuration file (commandline 773# should override configuration file). 774# 775for _i in $* ; do 776 if [ "$_i" = "-N" ]; then 777 readconfig= 778 break; 779 fi 780done 781if [ -n "$readconfig" ]; then 782 # On a long-lived system, the first time this script is run it 783 # will barf upon reading the configuration file for its perl predecessor. 784 if ( . ${ADDUSERCONF} > /dev/null 2>&1 ); then 785 [ -r ${ADDUSERCONF} ] && . ${ADDUSERCONF} > /dev/null 2>&1 786 fi 787fi 788 789# Proccess command-line options 790# 791for _switch ; do 792 case $_switch in 793 -L) 794 defaultclass="$2" 795 shift; shift 796 ;; 797 -C) 798 configflag=yes 799 shift 800 ;; 801 -E) 802 disableflag=yes 803 shift 804 ;; 805 -k) 806 udotdir="$2" 807 shift; shift 808 ;; 809 -f) 810 [ "$2" != "-" ] && infile="$2" 811 fflag=yes 812 shift; shift 813 ;; 814 -G) 815 defaultgroups="$2" 816 shift; shift 817 ;; 818 -h) 819 show_usage 820 exit 0 821 ;; 822 -d) 823 homeprefix="$2" 824 shift; shift 825 ;; 826 -m) 827 case "$2" in 828 [Nn][Oo]) 829 msgflag= 830 ;; 831 *) 832 msgflag=yes 833 msgfile="$2" 834 ;; 835 esac 836 shift; shift 837 ;; 838 -N) 839 readconfig= 840 shift 841 ;; 842 -w) 843 case "$2" in 844 no|none|random|yes) 845 passwdtype=$2 846 ;; 847 *) 848 show_usage 849 exit 1 850 ;; 851 esac 852 shift; shift 853 ;; 854 -q) 855 quietflag=yes 856 shift 857 ;; 858 -s) 859 defaultshell="`fullpath_from_shell $2`" 860 shift; shift 861 ;; 862 -u) 863 uidstart=$2 864 shift; shift 865 ;; 866 esac 867done 868 869# If the -f switch was used, get input from a file. Otherwise, 870# this is an interactive session. 871# 872if [ -n "$fflag" ]; then 873 if [ -z "$infile" ]; then 874 input_from_file 875 elif [ -n "$infile" ]; then 876 if [ -r "$infile" ]; then 877 input_from_file < $infile 878 else 879 err "File ($infile) is unreadable or does not exist." 880 fi 881 fi 882else 883 input_interactive 884fi 885