Lines Matching +full:common +full:- +full:account

4 # Copyright (c) 2012-2015 Devin Teske
32 . $BSDCFG_SHARE/common.subr || exit 1
45 [ -f /etc/adduser.conf ] && f_include /etc/adduser.conf
52 # Default account expire time. Format is similar to upwexpire variable.
56 # UNIX time in decimal, or a date in dd-mmm-yy[yy] format, where dd is
101 f_eval_catch $funcname mkdir "mkdir -p '%s'" "$_user_home_dir" ||
109 # Copy `skel' dot-files from $udotdir (global inherited from /etc/adduser.conf)
110 # to the home-directory of $user. Attempts to create the home-directory first
126 f_dprintf "Copying dot-files from \`%s' to \`%s'" \
130 [ -d "$user_home_dir" ] ||
138 local - # Localize `set' to this function
139 set +f # Enable glob pattern-matching for paths
144 [ -e "$file" ] || continue # no-match
147 f_eval_catch $funcname cp "cp -n '%s' '%s'" \
150 [ $retval -eq $SUCCESS ] || break
152 "chown -h '%i:%i' '%s'" \
156 [ $retval -eq $SUCCESS ] || break
159 cd -
165 # Create a login account. If both $user (as a first argument) and $VAR_USER are
166 # unset or NULL and we are running interactively, prompt the end-user to enter
167 # the name of a new login account and (if $VAR_NO_CONFIRM is unset or NULL)
168 # prompt the end-user to answer some questions about the new account. Variables
172 # The login to add. Ignored if given non-NULL first-argument.
174 # The account expiration time. Format is similar to
176 # expire the account.
178 # If non-NULL, populate the user's home directory with the
181 # Often the full name of the account holder. Default is NULL.
183 # Numerical primary-group ID to use. If NULL or unset, the group
186 # Comma-separated list of additional groups to which the user is
192 # If non-NULL, create the user's home directory if it doesn't
201 # UNIX time in decimal, or a date in dd-mmm-yy[yy] format, where
209 # account password.
216 # Returns success if the user account was successfully created.
228 f_getvar 3:-\$$VAR_USER input "$1"
231 # NB: pw(8) has a ``feature'' wherein `-n name' can be taken as UID
232 # instead of name. Work-around is to also pass `-u UID' at the same
235 if [ "$input" ] && f_quietly pw usershow -n "$input" -u 1337; then
255 f_getvar $VAR_USER_ACCOUNT_EXPIRE-\$uexpire user_account_expire
257 f_getvar $VAR_USER_GECOS-\$ugecos user_gecos
260 f_getvar $VAR_USER_HOME:-\${homeprefix%/}/\$user_name \
263 f_getvar $VAR_USER_LOGIN_CLASS-\$defaultclass user_class
265 f_getvar $VAR_USER_PASSWORD_EXPIRE-\$upwexpire user_password_expire
266 f_getvar $VAR_USER_SHELL-\$defaultshell user_shell
269 # Create home-dir if no script-override and does not exist
270 f_isset $VAR_USER_HOME_CREATE || [ -d "$user_home_dir" ] ||
272 # Copy dotfiles if home-dir creation is desired, does not yet exist,
273 # and no script-override has been set
276 [ -d "$user_home_dir" ] || user_dotfiles_create="$msg_yes"
277 # Create home-dir if copying dotfiles but home-dir does not exist
278 [ "$user_dotfiles_create" -a ! -d "$user_home_dir" ] &&
281 # Set flags for meaningful NULL values if-provided
299 if [ $retval -eq $DIALOG_ESC ]; then
301 elif [ $retval -ne $DIALOG_OK ]; then
303 # Ask series of questions to pre-fill the editor screen
332 if [ ! -d "$user_home_dir" ]; then
362 [ $retval -eq $DIALOG_OK ] || return $FAILURE
374 local cmd="pw useradd -n '$_user_name'"
375 [ "$user_gid" ] && cmd="$cmd -g '$_user_gid'"
376 [ "$user_shell" ] && cmd="$cmd -s '$_user_shell'"
377 [ "$user_uid" ] && cmd="$cmd -u '$_user_uid'"
378 [ "$user_account_expire" -o \
380 cmd="$cmd -e '$_user_account_expire'"
381 [ "$user_class" -o "$null_class" ] &&
382 cmd="$cmd -L '$_user_class'"
383 [ "$user_gecos" -o "$null_gecos" ] &&
384 cmd="$cmd -c '$_user_gecos'"
386 cmd="$cmd -d '$_user_home_dir'"
388 cmd="$cmd -G '$_user_member_groups'"
389 [ "$user_password_expire" -o \
391 cmd="$cmd -p '$_user_password_expire'"
395 f_eval_catch $funcname pw '%s -h -' "$cmd"
398 $funcname pw '%s -h 0' "$cmd"
404 [ "${user_home_create:-$msg_no}" != "$msg_no" ] &&
408 [ "${user_dotfiles_create:-$msg_no}" != \
416 if f_quietly pw usershow -n "$input" -u 1337; then
447 9) # Account Expires On
458 if [ "${user_home_create:-$msg_no}" != "$msg_no" ]
465 if [ "${user_dotfiles_create:-$msg_no}" != \
484 local cmd="pw useradd -n '$_user_name'"
485 [ "$user_gid" ] && cmd="$cmd -g '$_user_gid'"
486 [ "$user_home_dir" ] && cmd="$cmd -d '$_user_home_dir'"
487 [ "$user_shell" ] && cmd="$cmd -s '$_user_shell'"
488 [ "$user_uid" ] && cmd="$cmd -u '$_user_uid'"
489 [ "$user_account_expire" -o "$no_account_expire" ] &&
490 cmd="$cmd -e '$_user_account_expire'"
491 [ "$user_class" -o "$null_class" ] &&
492 cmd="$cmd -L '$_user_class'"
493 [ "$user_gecos" -o "$null_gecos" ] &&
494 cmd="$cmd -c '$_user_gecos'"
495 [ "$user_member_groups" -o "$null_members" ] &&
496 cmd="$cmd -G '$_user_member_groups'"
497 [ "$user_password_expire" -o "$no_password_expire" ] &&
498 cmd="$cmd -p '$_user_password_expire'"
503 f_eval_catch -k err $funcname pw '%s -h -' "$cmd"
505 err=$( echo "$user_password" | f_eval_catch -de \
506 $funcname pw '%s -h 0' "$cmd" 2>&1 )
508 f_eval_catch -k err $funcname pw '%s' "$cmd"
511 if [ $retval -ne $SUCCESS ]; then
517 [ "${user_home_create:-$msg_no}" != "$msg_no" ] &&
521 [ "${user_dotfiles_create:-$msg_no}" != "$msg_no" ] &&
528 [ "$no_confirm" -a "$USE_DIALOG" ] && sleep 1
536 # NULL and we are running interactively, prompt the end-user to select a user
537 # account from a list of those available. Variables that can be used to script
541 # The user to delete. Ignored if given non-NULL first-argument.
543 # Returns success if the user account was successfully deleted.
555 f_getvar 3:-\$$VAR_USER input "$1"
575 f_getvar $VAR_USER_GROUP_DELETE:-\$msg_no user_group_delete
576 f_getvar $VAR_USER_HOME_DELETE:-\$msg_no user_home_delete
580 if user_group=$( pw groupshow -g "$user_gid" 2> /dev/null ); then
582 # Default to delete the primary group if no script-override and
605 [ $retval -eq $DIALOG_OK ] || return $FAILURE
613 if [ "${user_group_delete:-$msg_no}" = "$msg_no" ]
619 # Remove user-to-delete from group members
622 while [ $length -ne ${#group_members} ]; do
641 local cmd="pw userdel -u '$_user_uid'"
642 if [ "$user_home_delete" = "$msg_yes" -a \
648 f_eval_catch -e $funcname pw \
649 "%s -r" "$cmd" \
657 f_eval_catch $funcname pw '%s -r' "$cmd"
676 if [ "${user_group_delete:-$msg_no}" != "$msg_no" ]
678 f_quietly pw groupshow -g "$user_gid" &&
680 "pw groupdel -g '%s'" "$_user_gid"
681 elif ! f_quietly pw groupshow -g "$group_gid" &&
682 [ "$group_name" -a "$group_gid" ]
685 local cmd="pw groupadd -n '$_group_name'"
686 cmd="$cmd -g '$_group_gid'"
687 cmd="$cmd -M '$_group_members'"
692 group_password_enc=$( getent group | awk -F: '
702 pw '%s -H 0' "$cmd"
705 pw '%s -h -' "$cmd"
727 if [ "${user_group_delete:-$msg_no}" != "$msg_no" ]
734 if [ "${user_home_delete:-$msg_no}" != "$msg_no" ]
747 if [ "${user_group_delete:-$msg_no}" = "$msg_no" ]; then
755 while [ $length -ne ${#group_members} ]; do
773 local err cmd="pw userdel -u '$_user_uid'"
774 if [ "$user_home_delete" = "$msg_yes" -a "$USE_XDIALOG" ]; then
777 f_eval_catch -de $funcname pw \
778 '%s -r' "$cmd" 2>&9 | f_xdialog_info \
784 f_eval_catch -k err $funcname pw '%s -r' "$cmd"
786 f_eval_catch -k err $funcname pw '%s' "$cmd"
789 if [ $retval -ne $SUCCESS ]; then
807 if [ "${user_group_delete:-$msg_no}" != "$msg_no" ]
809 f_quietly pw groupshow -g "$user_gid" &&
811 "pw groupdel -g '%s'" "$_user_gid"
812 elif ! f_quietly pw groupshow -g "$group_gid" &&
813 [ "$group_name" -a "$group_gid" ]
816 local cmd="pw groupadd -n '$_group_name'"
817 cmd="$cmd -g '$_group_gid'"
818 cmd="$cmd -M '$_group_members'"
820 group_password_enc=$( getent group | awk -F: '
830 pw '%s -H 0' "$cmd"
832 f_eval_catch $funcname pw '%s -h -' "$cmd"
840 [ "$no_confirm" -a "$USE_DIALOG" ] && sleep 1
847 # Modify a login account. If both $user (as a first argument) and $VAR_USER are
848 # unset or NULL and we are running interactively, prompt the end-user to select
849 # a login account from a list of those available. Variables that can be used to
853 # The login to modify. Ignored if given non-NULL first-argument.
855 # The account expiration time. Format is similar to
856 # VAR_USER_PASSWORD_EXPIRE variable below. If unset, account
857 # expiry is unchanged. If set but NULL, account expiration is
860 # If non-NULL, re-populate the user's home directory with the
863 # Often the full name of the account holder. If unset, the GECOS
866 # Numerical primary-group ID to set. If NULL or unset, the group
869 # Comma-separated list of additional groups to which the user is
877 # If non-NULL, create the user's home directory if it doesn't
888 # UNIX time in decimal, or a date in dd-mmm-yy[yy] format, where
905 # Returns success if the user account was successfully modified.
917 f_getvar 3:-\$$VAR_USER input "$1"
920 # NB: pw(8) has a ``feature'' wherein `-n name' can be taken as UID
921 # instead of name. Work-around is to also pass `-u UID' at the same
924 if [ "$input" ] && ! f_quietly pw usershow -n "$input" -u 1337; then
1003 [ $retval -eq $DIALOG_OK ] || return $FAILURE
1015 local cmd="pw usermod -n '$_user_name'"
1016 [ "$user_gid" ] && cmd="$cmd -g '$_user_gid'"
1017 [ "$user_shell" ] && cmd="$cmd -s '$_user_shell'"
1018 [ "$user_uid" ] && cmd="$cmd -u '$_user_uid'"
1019 [ "$user_account_expire" -o \
1021 cmd="$cmd -e '$_user_account_expire'"
1022 [ "$user_class" -o "$null_class" ] &&
1023 cmd="$cmd -L '$_user_class'"
1024 [ "$user_gecos" -o "$null_gecos" ] &&
1025 cmd="$cmd -c '$_user_gecos'"
1027 cmd="$cmd -d '$_user_home_dir'"
1028 [ "$user_member_groups" -o "$null_members" ] &&
1029 cmd="$cmd -G '$_user_member_groups'"
1030 [ "$user_password_expire" -o \
1032 cmd="$cmd -p '$_user_password_expire'"
1036 f_eval_catch $funcname pw '%s -h -' "$cmd"
1039 $funcname pw '%s -h 0' "$cmd"
1045 [ "${user_home_create:-$msg_no}" != "$msg_no" ] &&
1049 [ "${user_dotfiles_create:-$msg_no}" != \
1092 9) # Account Expires On
1103 if [ "${user_home_create:-$msg_no}" != "$msg_no" ]
1110 if [ "${user_dotfiles_create:-$msg_no}" != \
1129 local cmd="pw usermod -n '$_user_name'"
1130 [ "$user_gid" ] && cmd="$cmd -g '$_user_gid'"
1131 [ "$user_home_dir" ] && cmd="$cmd -d '$_user_home_dir'"
1132 [ "$user_shell" ] && cmd="$cmd -s '$_user_shell'"
1133 [ "$user_uid" ] && cmd="$cmd -u '$_user_uid'"
1134 [ "$user_account_expire" -o "$no_account_expire" ] &&
1135 cmd="$cmd -e '$_user_account_expire'"
1136 [ "$user_class" -o "$null_class" ] &&
1137 cmd="$cmd -L '$_user_class'"
1138 [ "$user_gecos" -o "$null_gecos" ] &&
1139 cmd="$cmd -c '$_user_gecos'"
1140 [ "$user_member_groups" -o "$null_members" ] &&
1141 cmd="$cmd -G '$_user_member_groups'"
1142 [ "$user_password_expire" -o "$no_password_expire" ] &&
1143 cmd="$cmd -p '$_user_password_expire'"
1148 f_eval_catch -k err $funcname pw '%s -h -' "$cmd"
1150 err=$( echo "$user_password" | f_eval_catch -de \
1151 $funcname pw '%s -h 0' "$cmd" 2>&1 )
1153 f_eval_catch -k err $funcname pw '%s' "$cmd"
1156 if [ $retval -ne $SUCCESS ]; then
1162 [ "${user_home_create:-$msg_no}" != "$msg_no" ] &&
1166 [ "${user_dotfiles_create:-$msg_no}" != "$msg_no" ] &&
1173 [ "$no_confirm" -a "$USE_DIALOG" ] && sleep 1