Rewrite usermgmt -- hooking it into the scripting system with dispatch

commands addUser, deleteUser, and editUser. Getting rid of the awkward-
to-use `userinput' bolt-on which Ron and I talked about rewriting.
This commit is contained in:
Devin Teske 2014-03-14 03:42:05 +00:00
parent b00c7d1aa2
commit f589320a0e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=263150
11 changed files with 2084 additions and 1043 deletions

View File

@ -38,6 +38,7 @@ f_include $BSDCFG_SHARE/mustberoot.subr
f_include $BSDCFG_SHARE/networking/services.subr
f_include $BSDCFG_SHARE/packages/packages.subr
f_include $BSDCFG_SHARE/usermgmt/group.subr
f_include $BSDCFG_SHARE/usermgmt/user.subr
f_include $BSDCFG_SHARE/variable.subr
############################################################ GLOBALS
@ -204,6 +205,11 @@ f_resword_new addGroup f_group_add
f_resword_new deleteGroup f_group_delete
f_resword_new editGroup f_group_edit
# usermgmt/user.subr
f_resword_new addUser f_user_add
f_resword_new deleteUser f_user_delete
f_resword_new editUser f_user_edit
# variable.subr
f_resword_new installVarDefaults f_variable_set_defaults
f_resword_new dumpVariables f_dump_variables

View File

@ -283,6 +283,21 @@ f_variable_new VAR_SLOW_ETHER slowEthernetCard
f_variable_new VAR_TRY_DHCP tryDHCP
f_variable_new VAR_TRY_RTSOL tryRTSOL
f_variable_new VAR_UFS_PATH ufs
f_variable_new VAR_USER user
f_variable_new VAR_USER_ACCOUNT_EXPIRE userAccountExpire
f_variable_new VAR_USER_DOTFILES_CREATE userDotfilesCreate
f_variable_new VAR_USER_GECOS userGecos
f_variable_new VAR_USER_GID userGid
f_variable_new VAR_USER_GROUPS userGroups
f_variable_new VAR_USER_GROUP_DELETE userGroupDelete
f_variable_new VAR_USER_HOME userHome
f_variable_new VAR_USER_HOME_CREATE userHomeCreate
f_variable_new VAR_USER_HOME_DELETE userHomeDelete
f_variable_new VAR_USER_LOGIN_CLASS userLoginClass
f_variable_new VAR_USER_PASSWORD userPassword
f_variable_new VAR_USER_PASSWORD_EXPIRE userPasswordExpire
f_variable_new VAR_USER_SHELL userShell
f_variable_new VAR_USER_UID userUid
f_variable_new VAR_ZFSINTERACTIVE zfsInteractive
#

View File

@ -8,8 +8,7 @@ FILESDIR= ${LIBEXECDIR}/bsdconfig/070.usermgmt
FILES= INDEX USAGE
SCRIPTSDIR= ${FILESDIR}
SCRIPTS= groupadd groupdel groupedit useradd userdel useredit \
userinput usermgmt
SCRIPTS= groupadd groupdel groupedit useradd userdel useredit usermgmt
beforeinstall:
mkdir -p ${DESTDIR}${FILESDIR}

View File

@ -33,7 +33,7 @@ hline_arrows_tab_enter="Press arrows, TAB or ENTER"
hline_num_arrows_tab_enter="Use numbers, arrows, TAB or ENTER"
hline_num_tab_enter="Use numbers, TAB or ENTER"
msg_account_does_not_expire="Account does not expire"
msg_account_expires_in_how_many_days="Account expires in how many days?"
msg_account_expire_manual_edit="Enter account expiration time. Format is one of:\n\n a) decimal for UNIX time since %s\n b) dd-mmm-yy[yy] for day, month, and 2- or 4-digit year\n c) +n[mhdwoy] for relative time from current date\n\nNOTE: Value of zero disables expiration."
msg_account_expires_on="Account Expires on"
msg_add="Add"
msg_add_group="Add Group"
@ -56,6 +56,7 @@ msg_edit_group="Edit/View Group"
msg_edit_login="Edit/View Login"
msg_edit_view="Edit/View"
msg_enter_group_members_manually="Enter Group Members manually"
msg_enter_groups_manually="Enter Groups manually"
msg_enter_number_of_days_into_the_future="Enter number of days into the future"
msg_enter_value_manually="Edit value manually"
msg_error="ERROR!"
@ -74,9 +75,8 @@ msg_group_not_found="%s: Group not found."
msg_group_password="Group Password"
msg_group_passwords_do_not_match="Group Passwords do not match."
msg_group_updated="Group Updated"
msg_groups="Groups"
msg_home_directory="Home Directory"
msg_invalid_number_of_days="Invalid number of days."
msg_invalid_number_of_seconds="Invalid number of seconds."
msg_login="Login"
msg_login_added="Login Added"
msg_login_already_used="%s: Login is already used."
@ -85,25 +85,28 @@ msg_login_deleted="Login Deleted"
msg_login_is_empty="Login is empty."
msg_login_management="Login/Group Management"
msg_login_must_start_with_letter="Login must start with a letter."
msg_login_not_found="Login not found."
msg_login_not_found="%s: Login not found."
msg_login_updated="Login Updated"
msg_member_of_groups="Member of Groups"
msg_n_a="N/A"
msg_no="No"
msg_no_group_specified="No group specified!"
msg_no_user_specified="No user specified!"
msg_number_of_seconds_since_epoch="Number of seconds since the Epoch\n(1 = %s)\nNULL or zero to disable:"
msg_ok="OK"
msg_password="Password"
msg_password_does_not_expire="Password does not expire"
msg_password_expires_in_how_many_days="Password expires in how many days?"
msg_password_expire_manual_edit="Enter password expiration time. Format is one of:\n\n a) decimal for UNIX time since %s\n b) dd-mmm-yy[yy] for day, month, and 2- or 4-digit year\n c) +n[mhdwoy] for relative time from current date\n\nNOTE: Value of zero disables expiration."
msg_password_expires_on="Password Expires on"
msg_passwords_do_not_match="Passwords do not match."
msg_please_enter_a_group_name="Please enter a group name!"
msg_please_enter_a_user_name="Please enter a user name!"
msg_reenter_group_password="Re-enter Group Password"
msg_reenter_password="Re-enter Password"
msg_save="Save"
msg_save_exit_or_cancel="Choose Save/Exit when finished or Cancel."
msg_select_group_members_from_list="Select Group Members from a list"
msg_select_groups_from_list="Select Groups from a list"
msg_select_login_shell="Select Login Shell"
msg_separated_by_commas="Separated by commas"
msg_shell="Shell"

View File

@ -3,7 +3,7 @@
NO_OBJ=
FILESDIR= ${SHAREDIR}/bsdconfig/usermgmt
FILES= group.subr group_input.subr user_input.subr
FILES= group.subr group_input.subr user.subr user_input.subr
beforeinstall:
mkdir -p ${DESTDIR}${FILESDIR}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
# Copyright (c) 2012-2013 Devin Teske
# Copyright (c) 2012-2014 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -33,8 +33,11 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." "$0"
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/mustberoot.subr
f_include $BSDCFG_SHARE/usermgmt/user.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
pgm="${ipgm:-$pgm}"
@ -55,9 +58,19 @@ done
shift $(( $OPTIND - 1 ))
#
# Chain-load to userinput to centralize code and minimize duplication
# Initialize
#
$BSDCFG_LIBE/$APP_DIR/userinput ${USE_XDIALOG:+-X} mode="Add"
f_dialog_title "$msg_add $msg_user"
f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
#
# Add a user
#
# NB: If given an argument on the command-line use it; otherwise fall-back to
# environment variable $user (handle $VAR_USER).
#
f_user_add ${1:+"$1"}
################################################################################
# END

View File

@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
# Copyright (c) 2012-2013 Devin Teske
# Copyright (c) 2012-2014 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -34,6 +34,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
f_dprintf "%s: loading includes..." "$0"
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/mustberoot.subr
f_include $BSDCFG_SHARE/usermgmt/user.subr
f_include $BSDCFG_SHARE/usermgmt/user_input.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
@ -64,10 +65,18 @@ f_dialog_title "$msg_delete $msg_login"
f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
#
# If given a user name, operate on it and exit
#
if [ "$1" ]; then
f_user_delete "$1"
exit $SUCCESS
fi
#
# Loop until the user Exits, Cancels or presses ESC
#
defaultitem=""
defaultitem=
while :; do
f_dialog_menu_user_list "$defaultitem"
retval=$?
@ -81,8 +90,7 @@ while :; do
# Anything else is a userid
$BSDCFG_LIBE/$APP_DIR/userinput \
${USE_XDIALOG:+-X} mode="Delete" user="$mtag"
f_user_delete "$mtag"
done
exit $SUCCESS

View File

@ -1,7 +1,7 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
# Copyright (c) 2012-2013 Devin Teske
# Copyright (c) 2012-2014 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -34,6 +34,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
f_dprintf "%s: loading includes..." "$0"
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/mustberoot.subr
f_include $BSDCFG_SHARE/usermgmt/user.subr
f_include $BSDCFG_SHARE/usermgmt/user_input.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
@ -65,9 +66,17 @@ f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
#
# Loop until the user Exits, Cancels or presses ESC
# If given a user name, operate on it and exit
#
defaultitem=""
if [ "$1" ]; then
f_user_edit "$1"
exit $SUCCESS
fi
#
# Present a list of users and loop until user Exits, Cancels or presses ESC
#
defaultitem=
while :; do
f_dialog_menu_user_list "$defaultitem"
retval=$?
@ -81,8 +90,7 @@ while :; do
# Anything else is a userid
$BSDCFG_LIBE/$APP_DIR/userinput \
${USE_XDIALOG:+-X} mode="Edit/View" user="$mtag"
f_user_edit "$mtag"
done
exit $SUCCESS

View File

@ -1,508 +0,0 @@
#!/bin/sh
#-
# Copyright (c) 2012 Ron McDowell
# Copyright (c) 2012-2013 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#
############################################################ INCLUDES
BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." "$0"
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/mustberoot.subr
f_include $BSDCFG_SHARE/usermgmt/user_input.subr
BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
pgm="${ipgm:-$pgm}"
############################################################ CONFIGURATION
# set some reasonable defaults if /etc/adduser.conf does not exist.
[ -f /etc/adduser.conf ] && f_include /etc/adduser.conf
: ${passwdtype:="yes"}
: ${homeprefix:="/home"}
: ${defaultshell:="/bin/sh"}
: ${udotdir:="/usr/share/skel"}
############################################################ FUNCTIONS
# copy_dotfiles
#
# Copy `skel' dot-files to a new home directory.
#
copy_dotfiles()
{
( # Operate within sub-shell to protect CWD/glob of parent
cd "$udotdir" || exit $?
set +f # glob
for file in dot.*; do
cp -n "$file" "$pw_home_dir/${file#dot}" || exit $?
done
)
}
# save_changes
#
# Save any/all settings (actions performed depend on $mode value).
#
save_changes()
{
local funcname=save_changes
case "$mode" in
Delete)
f_eval_catch $funcname pw 'pw userdel -u "%s"' "$pw_uid" ||
return $?
f_show_msg "$msg_login_deleted"
if [ "$pw_group_delete" = "$msg_yes" ] &&
f_quietly pw groupshow -g "$pw_gid"
then
f_eval_catch $funcname pw \
'pw groupdel -g "%s"' "$pw_gid"
fi
if [ "$pw_home_delete" = "$msg_yes" ]; then
f_dialog_info "$msg_deleting_home_directory"
f_eval_catch $funcname rm 'rm -Rf "%s"' "$pw_home_dir"
fi
;;
Add)
local cmd="pw useradd -n '$pw_name'"
[ "$pw_member_groups" ] && cmd="$cmd -G '$pw_member_groups'"
[ "$pw_class" ] && cmd="$cmd -L '$pw_class'"
[ "$pw_gecos" ] && cmd="$cmd -c '$pw_gecos'"
[ "$pw_home_dir" ] && cmd="$cmd -d '$pw_home_dir'"
[ "$pw_account_expire" ] && cmd="$cmd -e '$pw_account_expire'"
[ "$pw_gid" ] && cmd="$cmd -g '$pw_gid'"
[ "$pw_password_expire" ] && cmd="$cmd -p '$pw_password_expire'"
[ "$pw_shell" ] && cmd="$cmd -s '$pw_shell'"
[ "$pw_uid" ] && cmd="$cmd -u '$pw_uid'"
if [ "$pw_password_disable" ]; then
f_eval_catch $funcname pw '%s -h -' "$cmd"
elif [ "$pw_password" ]; then
echo "$pw_password" |
f_eval_catch $funcname pw '%s -h 0' "$cmd"
else
f_eval_catch $funcname pw '%s' "$cmd"
fi || return $?
f_show_msg "$msg_login_added"
if [ "$pw_home_create" = "$msg_yes" ]; then
if f_eval_catch $funcname mkdir \
'mkdir -p "%s"' "$pw_home_dir"
then
f_eval_catch $funcname chown \
'chown -R "%s" "%s"' \
"$pw_uid:$pw_gid" "$pw_home_dir"
fi
fi
[ "$pw_dotfiles_create" = "$msg_yes" ] &&
f_eval_catch $funcname copy_dotfiles copy_dotfiles
user="$pw_name"
f_quietly pw usershow -n "$pw_name" &&
mode="Edit/View" # Change mode
;;
Edit/View)
local cmd="pw usermod -n '$pw_name'"
[ "$pw_member_groups" ] && cmd="$cmd -G '$pw_member_groups'"
[ "$pw_class" ] && cmd="$cmd -L '$pw_class'"
[ "$pw_gecos" ] && cmd="$cmd -c '$pw_gecos'"
[ "$pw_home_dir" ] && cmd="$cmd -d '$pw_home_dir'"
[ "$pw_account_expire" ] && cmd="$cmd -e '$pw_account_expire'"
[ "$pw_gid" ] && cmd="$cmd -g '$pw_gid'"
[ "$pw_password_expire" ] && cmd="$cmd -p '$pw_password_expire'"
[ "$pw_shell" ] && cmd="$cmd -s '$pw_shell'"
[ "$pw_uid" ] && cmd="$cmd -u '$pw_uid'"
if [ "$pw_password_disable" ]; then
f_eval_catch $funcname pw '%s -h -' "$cmd"
elif [ "$pw_password" ]; then
echo "$pw_password" |
f_eval_catch $funcname pw '%s -h 0' "$cmd"
else
f_eval_catch $funcname pw '%s' "$cmd"
fi || return $?
f_show_msg "$msg_login_updated"
if [ "$pw_home_create" = "$msg_yes" ]; then
if f_eval_catch $funcname mkdir \
'mkdir -p "%s"' "$pw_home_dir"
then
f_eval_catch $funcname chown \
'chown -R "%i:%i" "%s"' \
"$pw_uid" "$pw_gid" "$pw_home_dir"
fi
fi
[ "$pw_dotfiles_create" = "$msg_yes" ] &&
f_eval_catch $funcname copy_dotfiles copy_dotfiles
;;
esac
save_flag=
return $SUCCESS
}
# dialog_title_update $mode
#
# Set the title based on the given $mode.
#
dialog_title_update()
{
local mode="$1"
case "$mode" in
Add) f_dialog_title "$msg_add $msg_user" ;;
Edit/View) f_dialog_title "$msg_edit_view $msg_user: $user" ;;
Delete) f_dialog_title "$msg_delete $msg_user: $user" ;;
esac
}
############################################################ MAIN
# Incorporate rc-file if it exists
[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
#
# Process command-line arguments
#
while [ $# -gt 0 ]; do
key="${1%%=*}"
value="${1#*=}"
f_dprintf "key=[%s] value=[%s]" "$key" "$value"
case "$key" in
mode) mode="$value" ;;
user) user="$value" ;;
esac
shift
done
f_dprintf "mode=[%s] user=[%s]" "$mode" "$user"
#
# Initialize
#
dialog_title_update "$mode"
f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
f_mustberoot_init
menu_text=
save_flag=
hline="$hline_arrows_tab_enter"
if [ "$mode" = "Add" ]; then
f_dialog_input_name || exit 0
#
# Set some sensible defaults for account attributes
#
pw_gecos="${pw_gecos-$pw_name}"
pw_home_dir="${pw_home_dir:-$homeprefix/$pw_name}"
if [ -d "$pw_home_dir" ]; then
pw_home_create="${pw_home_create:-$msg_no}"
pw_dotfiles_create="${pw_dotfiles_create:-$msg_no}"
else
pw_home_create="${pw_home_create:-$msg_yes}"
pw_dotfiles_create="${pw_dotfiles_create:-$msg_yes}"
fi
pw_shell="${pw_shell:-$defaultshell}"
f_dialog_noyes "$msg_use_default_values_for_all_account_details"
retval=$?
if [ $retval -eq $DIALOG_ESC ]; then
exit $SUCCESS
elif [ $retval -ne $DIALOG_OK ]; then
#
# Ask a series of questions to pre-fill the editor screen.
#
# The defaults used in each dialog should allow the user to
# simply hit ENTER to proceed, because cancelling a single
# dialog will cause them to be returned to the main usermenu.
#
f_dialog_input_gecos "$pw_gecos" || exit 0
[ "$passwdtype" = "yes" ] &&
{ f_dialog_input_password || exit 0; }
f_dialog_input_uid || exit 0
f_dialog_input_gid || exit 0
f_dialog_input_member_groups || exit 0
f_dialog_input_class || exit 0
f_dialog_input_expire_password || exit 0
f_dialog_input_expire_account || exit 0
f_dialog_input_home_dir "$pw_home_dir" || exit 0
if [ ! -d "$pw_home_dir" ]; then
f_dialog_input_home_create || exit 0
[ "$pw_home_create" = "$msg_yes" ] &&
{ f_dialog_input_dotfiles_create || exit 0; }
fi
f_dialog_input_shell "$pw_shell" || exit 0
fi
fi
if [ "$mode" = "Edit/View" -o "$mode" = "Delete" ]; then
f_input_user "$user" || f_die 1 "$msg_login_not_found"
fi
if [ "$mode" = "Edit/View" ]; then
[ -d "$pw_home_dir" ] || pw_home_create="$msg_no"
pw_dotfiles_create="$msg_no"
fi
if [ "$mode" = "Delete" ]; then
f_dialog_input_group_delete || exit 0
pw_home_delete="$msg_no"
[ -d "$pw_home_dir" ] &&
{ f_dialog_input_home_delete || exit 0; }
fi
cur_pw_name="$pw_name"
cur_pw_password="$pw_password"
cur_pw_uid="$pw_uid"
cur_pw_gid="$pw_gid"
cur_pw_member_groups="$pw_member_groups"
cur_pw_class="$pw_class"
cur_pw_password_expire="$pw_password_expire"
cur_pw_account_expire="$pw_account_expire"
cur_pw_gecos="$pw_gecos"
cur_pw_home_dir="$pw_home_dir"
cur_pw_shell="$pw_shell"
cur_pw_group_delete="$pw_group_delete"
cur_pw_home_create="$pw_home_create"
cur_pw_home_delete="$pw_home_delete"
cur_pw_dotfiles_create="$pw_dotfiles_create"
[ "$mode" = "Delete" ] && save_flag=1
#
# Loop until the user decides to Exit, Cancel, or presses ESC
#
while :; do
dialog_title_update "$mode"
menu_text=
menu_exit="$msg_exit"
if [ "$save_flag" ]; then
if [ "$mode" = "Delete" ]; then
menu_exit="$msg_delete/$msg_exit"
menu_text="$msg_delete_exit_or_cancel"
else
menu_exit="$msg_save/$msg_exit"
menu_text="$msg_save_exit_or_cancel"
fi
fi
pw_password_expires_on="$pw_password_expire"
f_isinteger "$pw_password_expire" && [ $pw_password_expire -ne 0 ] &&
pw_password_expires_on=$(
date -r "$pw_password_expire" "+%F %T %Z"
)
pw_account_expires_on="$pw_account_expire"
f_isinteger "$pw_account_expire" && [ "$pw_account_expire" -ne 0 ] &&
pw_account_expires_on=$(
date -r "$pw_account_expire" "+%F %T %Z"
)
case "$mode" in
Delete)
menu_items="
'X' '$menu_exit'
'1' '$msg_login: $pw_name'
'-' '$msg_full_name: $pw_gecos'
'-' '$msg_password: -----'
'-' '$msg_user_id: $pw_uid'
'-' '$msg_group_id: $pw_gid'
'-' '$msg_member_of_groups: $pw_member_groups'
'-' '$msg_login_class: $pw_class'
'-' '$msg_password_expires_on: $pw_password_expires_on'
'-' '$msg_account_expires_on: $pw_account_expires_on'
'-' '$msg_home_directory: $pw_home_dir'
'-' '$msg_shell: $pw_shell'
" # END-QUOTE
;;
*)
menu_items="
'X' '$menu_exit'
'1' '$msg_login: $pw_name'
'2' '$msg_full_name: $pw_gecos'
'3' '$msg_password: -----'
'4' '$msg_user_id: $pw_uid'
'5' '$msg_group_id: $pw_gid'
'6' '$msg_member_of_groups: $pw_member_groups'
'7' '$msg_login_class: $pw_class'
'8' '$msg_password_expires_on: $pw_password_expires_on'
'9' '$msg_account_expires_on: $pw_account_expires_on'
'A' '$msg_home_directory: $pw_home_dir'
'B' '$msg_shell: $pw_shell'
" # END-QUOTE
esac
case "$mode" in
Add|Edit/View)
if [ -d "$pw_home_dir" ]; then menu_items="$menu_items
'-' '$msg_create_home_directory: $msg_n_a'
'D' '$msg_create_dotfiles: $pw_dotfiles_create'
"; else menu_items="$menu_items
'C' '$msg_create_home_directory: $pw_home_create'
'D' '$msg_create_dotfiles: $pw_dotfiles_create'
"; fi
;;
Delete)
if [ -d "$pw_home_dir" ]; then menu_items="$menu_items
'C' '$msg_delete_primary_group: $pw_group_delete'
'D' '$msg_delete_home_directory: $pw_home_delete'
"; else menu_items="$menu_items
'C' '$msg_delete_primary_group: $pw_group_delete'
'-' '$msg_delete_home_directory: $msg_n_a'
"; fi
;;
esac
eval f_dialog_menu_size height width rows \
\"\$DIALOG_TITLE\" \
\"\$DIALOG_BACKTITLE\" \
\"\$menu_text\" \
\"\$hline\" \
$menu_items
f_dialog_default_fetch defaultitem
mtag=$( eval $DIALOG \
--title \"\$DIALOG_TITLE\" \
--backtitle \"\$DIALOG_BACKTITLE\" \
--hline \"\$hline\" \
--ok-label \"\$msg_ok\" \
--cancel-label \"\$msg_cancel\" \
--default-item \"\$defaultitem\" \
--menu \"\$menu_text\" \
$height $width $rows \
$menu_items \
2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
)
retval=$?
f_dialog_data_sanitize mtag
f_dialog_default_store "$mtag"
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
# Exit if user has either pressed ESC or chosen Cancel/No
[ $retval -eq $DIALOG_OK ] || f_die
case "$mtag" in
X) # Exit
if [ "$save_flag" ]; then
save_changes || continue
fi
break
;;
1) # Login
case "$mode" in
Add) f_dialog_input_name "$pw_name" ;;
Edit/View|Delete)
f_dialog_menu_user_list "$pw_name"
retval=$?
f_dialog_menutag_fetch mtag
f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
# Loop if user has either pressed ESC or chosen Cancel/No
[ $retval -eq $DIALOG_OK ] || continue
[ "$mtag" = "X $msg_exit" ] && continue
user="$mtag"
f_input_user "$user" || f_die 1 "$msg_login_not_found"
cur_pw_name="$pw_name"
cur_pw_password="$pw_password"
cur_pw_uid="$pw_uid"
cur_pw_gid="$pw_gid"
cur_pw_member_groups="$pw_member_groups"
cur_pw_class="$pw_class"
cur_pw_password_expire="$pw_password_expire"
cur_pw_account_expire="$pw_account_expire"
cur_pw_gecos="$pw_gecos"
cur_pw_home_dir="$pw_home_dir"
cur_pw_shell="$pw_shell"
cur_pw_group_delete="$pw_group_delete"
cur_pw_home_create="$pw_home_create"
cur_pw_home_delete="$pw_home_delete"
cur_pw_dotfiles_create="$pw_dotfiles_create"
[ "$mode" != "Delete" ] && save_flag=
esac
;;
2) # Full Name
f_dialog_input_gecos "$pw_gecos" ;;
3) # Password
f_dialog_input_password ;;
4) # UID
f_dialog_input_uid "$pw_uid" ;;
5) # Default Group
f_dialog_input_gid "$pw_gid" ;;
6) # Member of Groups
f_dialog_input_member_groups "$pw_member_groups" ;;
7) # Login Class
f_dialog_input_class "$pw_class" ;;
8) # Password Expire on
f_dialog_input_expire_password "$pw_password_expire" ;;
9) # Account Expire on
f_dialog_input_expire_account "$pw_account_expire" ;;
A) # Home Directory
f_dialog_input_home_dir "$pw_home_dir" ;;
B) # Shell
f_dialog_input_shell "$pw_shell" ;;
esac
case "$mode" in
Delete)
case "$mtag" in
C) # Delete Primary Group
f_dialog_input_group_delete ;;
D) # Delete Home Directory
f_dialog_input_home_delete ;;
esac
;;
Add|Edit/View)
case "$mtag" in
C) # Create Home Directory
f_dialog_input_home_create
[ "$pw_home_create" = "$msg_no" ] &&
pw_dotfiles_create="$msg_no"
;;
D) # Create Dotfiles
f_dialog_input_dotfiles_create
[ "$pw_dotfiles_create" = "$msg_yes" ] &&
pw_home_create="$msg_yes"
;;
esac
;;
esac
done
exit $SUCCESS
################################################################################
# END
################################################################################