head	1.20;
access;
symbols
	RELENG_9:1.20.0.2;
locks; strict;
comment	@# @;


1.20
date	2013.07.06.00.40.32;	author svnexp;	state Exp;
branches
	1.20.2.1;
next	1.19;

1.19
date	2013.06.25.00.35.22;	author svnexp;	state Exp;
branches;
next	1.18;

1.18
date	2013.06.20.03.23.54;	author svnexp;	state Exp;
branches;
next	1.17;

1.17
date	2013.06.20.03.23.11;	author svnexp;	state Exp;
branches;
next	1.16;

1.16
date	2013.06.09.00.43.38;	author svnexp;	state Exp;
branches;
next	1.15;

1.15
date	2013.06.03.00.51.04;	author svnexp;	state Exp;
branches;
next	1.14;

1.14
date	2013.06.03.00.32.49;	author svnexp;	state Exp;
branches;
next	1.13;

1.13
date	2013.06.02.00.37.30;	author svnexp;	state Exp;
branches;
next	1.12;

1.12
date	2013.06.01.00.35.21;	author svnexp;	state Exp;
branches;
next	1.11;

1.11
date	2013.04.23.00.30.01;	author svnexp;	state Exp;
branches;
next	1.10;

1.10
date	2013.01.15.00.52.23;	author svnexp;	state Exp;
branches;
next	1.9;

1.9
date	2012.12.25.11.03.38;	author svnexp;	state Exp;
branches;
next	1.8;

1.8
date	2012.12.25.09.37.00;	author svnexp;	state Exp;
branches;
next	1.7;

1.7
date	2012.12.21.20.40.51;	author svnexp;	state Exp;
branches;
next	1.6;

1.6
date	2012.12.21.19.30.51;	author svnexp;	state Exp;
branches;
next	1.5;

1.5
date	2012.11.17.04.41.48;	author svnexp;	state Exp;
branches;
next	1.4;

1.4
date	2012.11.17.01.54.40;	author svnexp;	state Exp;
branches;
next	1.3;

1.3
date	2012.09.20.23.44.13;	author dteske;	state Exp;
branches;
next	1.2;

1.2
date	2012.09.18.22.28.42;	author dteske;	state Exp;
branches;
next	1.1;

1.1
date	2012.07.14.03.16.57;	author dteske;	state Exp;
branches;
next	;

1.20.2.1
date	2013.07.06.00.40.32;	author svnexp;	state dead;
branches;
next	1.20.2.2;

1.20.2.2
date	2013.07.07.20.03.18;	author svnexp;	state Exp;
branches;
next	1.20.2.3;

1.20.2.3
date	2014.03.27.04.02.36;	author svnexp;	state dead;
branches;
next	;


desc
@@


1.20
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252795
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@#!/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: head/usr.sbin/bsdconfig/usermgmt/userinput 252795 2013-07-05 16:00:01Z dteske $
#
############################################################ 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

ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"

############################################################ 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 err retval=$SUCCESS

	case "$mode" in
	Delete)
		err=$( pw userdel -u "$pw_uid" 2>&1 )
		retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_dialog_msgbox "$msg_error $err\n"
			return $retval
		fi
		f_show_msg "$msg_login_deleted"

		if [ "$pw_group_delete" = "$msg_yes" ] &&
		   f_quietly pw groupshow -g "$pw_gid"
		then
			err=$( pw groupdel -g "$pw_gid" 2>&1 ) ||
				f_dialog_msgbox "$msg_warning $err\n"
		fi

		if [ "$pw_home_delete" = "$msg_yes" ]; then
			f_dialog_info "$msg_deleting_home_directory"
			err=$( rm -Rf "$pw_home_dir" 2>&1 ) ||
				f_dialog_msgbox "$msg_warning $err\n"
		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
			cmd="$cmd -h -"
		elif [ "$pw_password" ]; then
			cmd="echo \"\$pw_password\" | $cmd -h 0"
		fi
		f_dprintf "cmd=%s" "$cmd"
		err=$( eval $cmd 2>&1 )
		retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_dialog_msgbox "$msg_error $err\n"
			return $retval
		fi
		f_show_msg "$msg_login_added"

		if [ "$pw_home_create" = "$msg_yes" ]; then
			err=$( mkdir -p "$pw_home_dir" 2>&1 )
			if [ $? -ne $SUCCESS ]; then
				f_dialog_msgbox "$msg_warning $err\n"
			elif [ -e "$pw_home_dir" ]; then
				err=$( chown -R "$pw_uid:$pw_gid" \
				                "$pw_home_dir" 2>&1 )
				[ $? -eq $SUCCESS ] ||
					f_dialog_msgbox "$msg_warning $err\n"
			fi
		fi

		if [ "$pw_dotfiles_create" = "$msg_yes" ]; then
			err=$( copy_dotfiles 2>&1 ) ||
				f_dialog_msgbox "$msg_warning $err\n"
		fi

		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
			cmd="$cmd -h -"
		elif [ "$pw_password" ]; then
			cmd="echo \"\$pw_password\" | $cmd -h 0"
		fi
		f_dprintf "cmd=%s" "$cmd"
		err=$( eval $cmd 2>&1 )
		retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_dialog_msgbox "$msg_error $err\n"
			return $retval
		fi
		f_show_msg "$msg_login_updated"

		if [ "$pw_home_create" = "$msg_yes" ]; then
			err=$( mkdir -p "$pw_home_dir" )
			if [ $? -ne $SUCCESS ]; then
				f_dialog_msgbox "$msg_warning $err\n"
			elif [ -e "$pw_home_dir" ]; then
				err=$( chown -R "$pw_uid:$pw_gid" \
				                "$pw_home_dir" 2>&1 )
				[ $? -eq $SUCCESS ] ||
					f_dialog_msgbox "$msg_warning $err\n"
			fi
		fi

		if [ "$pw_dotfiles_create" = "$msg_yes" ]; then
			err=$( copy_dotfiles 2>&1 ) ||
				f_dialog_msgbox "$msg_warning $err\n"
		fi
		;;
	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 255 ]; then # User pressed ESC
		exit $SUCCESS
	elif [ $retval -ne $SUCCESS ]; 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 $SUCCESS ] || 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 $SUCCESS ] || 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
################################################################################
@


1.20.2.1
log
@file userinput was added on branch RELENG_9 on 2013-07-07 20:03:18 +0000
@
text
@d1 529
@


1.20.2.2
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252995
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a0 529
#!/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: stable/9/usr.sbin/bsdconfig/usermgmt/userinput 252995 2013-07-07 19:13:34Z dteske $
#
############################################################ 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

ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"

############################################################ 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 err retval=$SUCCESS

	case "$mode" in
	Delete)
		err=$( pw userdel -u "$pw_uid" 2>&1 )
		retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_dialog_msgbox "$msg_error $err\n"
			return $retval
		fi
		f_show_msg "$msg_login_deleted"

		if [ "$pw_group_delete" = "$msg_yes" ] &&
		   f_quietly pw groupshow -g "$pw_gid"
		then
			err=$( pw groupdel -g "$pw_gid" 2>&1 ) ||
				f_dialog_msgbox "$msg_warning $err\n"
		fi

		if [ "$pw_home_delete" = "$msg_yes" ]; then
			f_dialog_info "$msg_deleting_home_directory"
			err=$( rm -Rf "$pw_home_dir" 2>&1 ) ||
				f_dialog_msgbox "$msg_warning $err\n"
		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
			cmd="$cmd -h -"
		elif [ "$pw_password" ]; then
			cmd="echo \"\$pw_password\" | $cmd -h 0"
		fi
		f_dprintf "cmd=%s" "$cmd"
		err=$( eval $cmd 2>&1 )
		retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_dialog_msgbox "$msg_error $err\n"
			return $retval
		fi
		f_show_msg "$msg_login_added"

		if [ "$pw_home_create" = "$msg_yes" ]; then
			err=$( mkdir -p "$pw_home_dir" 2>&1 )
			if [ $? -ne $SUCCESS ]; then
				f_dialog_msgbox "$msg_warning $err\n"
			elif [ -e "$pw_home_dir" ]; then
				err=$( chown -R "$pw_uid:$pw_gid" \
				                "$pw_home_dir" 2>&1 )
				[ $? -eq $SUCCESS ] ||
					f_dialog_msgbox "$msg_warning $err\n"
			fi
		fi

		if [ "$pw_dotfiles_create" = "$msg_yes" ]; then
			err=$( copy_dotfiles 2>&1 ) ||
				f_dialog_msgbox "$msg_warning $err\n"
		fi

		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
			cmd="$cmd -h -"
		elif [ "$pw_password" ]; then
			cmd="echo \"\$pw_password\" | $cmd -h 0"
		fi
		f_dprintf "cmd=%s" "$cmd"
		err=$( eval $cmd 2>&1 )
		retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_dialog_msgbox "$msg_error $err\n"
			return $retval
		fi
		f_show_msg "$msg_login_updated"

		if [ "$pw_home_create" = "$msg_yes" ]; then
			err=$( mkdir -p "$pw_home_dir" )
			if [ $? -ne $SUCCESS ]; then
				f_dialog_msgbox "$msg_warning $err\n"
			elif [ -e "$pw_home_dir" ]; then
				err=$( chown -R "$pw_uid:$pw_gid" \
				                "$pw_home_dir" 2>&1 )
				[ $? -eq $SUCCESS ] ||
					f_dialog_msgbox "$msg_warning $err\n"
			fi
		fi

		if [ "$pw_dotfiles_create" = "$msg_yes" ]; then
			err=$( copy_dotfiles 2>&1 ) ||
				f_dialog_msgbox "$msg_warning $err\n"
		fi
		;;
	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 255 ]; then # User pressed ESC
		exit $SUCCESS
	elif [ $retval -ne $SUCCESS ]; 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 $SUCCESS ] || 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 $SUCCESS ] || 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
################################################################################
@


1.20.2.3
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/263791
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@@


1.19
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252178
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 252178 2013-06-24 20:58:54Z dteske $
d87 1
a87 1
		f_dialog_msgbox "$msg_login_deleted"
d125 1
a125 1
		f_dialog_msgbox "$msg_login_added"
d171 1
a171 1
		f_dialog_msgbox "$msg_login_updated"
@


1.18
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252001
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 252001 2013-06-19 18:32:18Z dteske $
d223 2
a224 2
	mode) mode="$value";;
	user) user="$value";;
@


1.17
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/252000
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 252000 2013-06-19 18:13:58Z dteske $
d478 1
a478 2
	   f_dialog_input_gecos "$pw_gecos"
	   ;;
d480 1
a480 2
	   f_dialog_input_password
	   ;;
d482 1
a482 2
	   f_dialog_input_uid "$pw_uid"
	   ;;
d484 1
a484 2
	   f_dialog_input_gid "$pw_gid"
	   ;;
d486 1
a486 2
	   f_dialog_input_member_groups "$pw_member_groups"
	   ;;
d488 1
a488 2
	   f_dialog_input_class "$pw_class"
	   ;;
d490 1
a490 2
	   f_dialog_input_expire_password "$pw_password_expire"
	   ;;
d492 1
a492 2
	   f_dialog_input_expire_account "$pw_account_expire"
	   ;;
d494 1
a494 2
	   f_dialog_input_home_dir "$pw_home_dir"
	   ;;
d496 1
a496 2
	   f_dialog_input_shell "$pw_shell"
	   ;;
@


1.16
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251549
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 251549 2013-06-08 19:13:49Z dteske $
a532 1

@


1.15
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251273
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 251273 2013-06-02 23:12:32Z dteske $
d241 2
d244 1
a244 5
	# 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.
d246 13
d260 27
a286 16
	f_dialog_input_name || exit 0
	f_dialog_input_gecos "$pw_name" || 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 "$homeprefix/$pw_name" || exit 0
	pw_dotfiles_create="$msg_no"
	if [ ! -d "$homeprefix/$pw_name" ]; then
		f_dialog_input_home_create || exit 0
		[ "$pw_home_create" = "$msg_yes" ] &&
			{ f_dialog_input_dotfiles_create || exit 0; }
a287 1
	f_dialog_input_shell "$defaultshell" || exit 0
@


1.14
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251244
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 251244 2013-06-02 09:02:12Z dteske $
d257 2
a258 2
	f_dialog_input_change || exit 0
	f_dialog_input_expire || exit 0
d475 1
a475 1
	   f_dialog_input_change "$pw_password_expire"
d478 1
a478 1
	   f_dialog_input_expire "$pw_account_expire"
@


1.13
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251236
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 251236 2013-06-01 23:58:44Z dteske $
d394 1
d396 9
a404 9
		--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                         \
d409 1
a409 1
	setvar DEFAULTITEM_$$ "$mtag"
@


1.12
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/251190
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 251190 2013-05-31 19:07:17Z dteske $
d394 1
a394 1
	dialog_menu=$( eval $DIALOG \
a405 1

d407 2
a408 3
	setvar DEFAULTITEM_$$ "$dialog_menu"
	setvar DIALOG_MENU_$$ "$dialog_menu"
	mtag=$( f_dialog_menutag )
d427 1
a427 1
	   	mtag=$( f_dialog_menutag )
@


1.11
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/249751
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 249751 2013-04-22 05:52:06Z dteske $
d387 6
a392 6
	size=$( eval f_dialog_menu_size \
	        	\"\$DIALOG_TITLE\"     \
	        	\"\$DIALOG_BACKTITLE\" \
	        	\"\$menu_text\"        \
	        	\"\$hline\"            \
	        	$menu_items            )
d401 2
a402 1
		--menu \"\$menu_text\" $size        \
@


1.10
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/245437
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d4 1
a4 1
# Copyright (c) 2012 Devin Teske
d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 245437 2013-01-14 21:03:34Z dteske $
d395 8
a402 7
		--title \"\$DIALOG_TITLE\"         \
		--backtitle \"\$DIALOG_BACKTITLE\" \
		--hline \"\$hline\"                \
		--ok-label \"\$msg_ok\"            \
		--cancel-label \"\$msg_cancel\"    \
		--menu \"\$menu_text\" $size       \
		$menu_items                        \
d407 1
d426 1
a426 1
	   	f_dialog_menu_user_list
@


1.9
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/244675
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 244675 2012-12-25 10:47:45Z dteske $
d84 1
a84 1
			f_show_msg "%s %s\n" "$msg_error" "$err"
d87 1
a87 1
		f_show_msg "$msg_login_deleted"
d93 1
a93 1
				f_show_msg "%s %s\n" "$msg_warning" "$err"
d99 1
a99 1
				f_show_msg "%s %s\n" "$msg_warning" "$err"
d122 1
a122 1
			f_show_msg "%s %s\n" "$msg_error" "$err"
d125 1
a125 1
		f_show_msg "$msg_login_added"
d130 1
a130 1
				f_show_msg "%s %s\n" "$msg_warning" "$err"
d134 2
a135 2
				[ $? -eq $SUCCESS ] || f_show_msg \
					"%s %s\n" "$msg_warning" "$err"
d141 1
a141 1
				f_show_msg "%s %s\n" "$msg_warning" "$err"
d168 1
a168 1
			f_show_msg "%s %s\n" "$msg_error" "$err"
d171 1
a171 1
		f_show_msg "$msg_login_updated"
d176 1
a176 1
				f_show_msg "%s %s\n" "$msg_warning" "$err"
d180 2
a181 2
				[ $? -eq $SUCCESS ] || f_show_msg \
					"%s %s\n" "$msg_warning" "$err"
d187 1
a187 1
				f_show_msg "%s %s\n" "$msg_warning" "$err"
@


1.8
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/244674
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 244674 2012-12-25 09:30:25Z dteske $
d34 1
@


1.7
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/244556
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 244556 2012-12-21 20:36:12Z dteske $
a231 1
f_dialog_init
@


1.6
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/244550
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 244550 2012-12-21 19:26:17Z dteske $
a393 1
	local dialog_menu
@


1.5
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/243112
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r243112 | dteske | 2012-11-16 00:59:11 +0000 (Fri, 16 Nov 2012) | 11 lines
## SVN ##
## SVN ## Replicate a feature from sysinstall documented in
## SVN ## stable/9/usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below):
## SVN ##
## SVN ## If /usr/sbin/sysinstall is linked to another filename, say
## SVN ## `/usr/local/bin/configPackages', then the basename will be used
## SVN ## as an implicit command name.
## SVN ##
## SVN ## To get a list of modules you can link to, see `bsdconfig -h' output.
## SVN ##
## SVN ## Approved by:	adrian (co-mentor) (implicit)
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 243112 2012-11-16 00:59:11Z dteske $
d117 1
a117 1
		f_dprintf "cmd=$cmd"
d163 1
a163 1
		f_dprintf "cmd=$cmd"
d220 1
a220 1
	f_dprintf "key=[$key] value=[$value]"
d227 1
a227 1
f_dprintf "mode=[$mode] user=[$user]"
d409 1
a409 1
	f_dprintf "retval=$retval mtag=[$mtag]"
d428 1
a428 1
	   	f_dprintf "retval=$retval mtag=[$mtag]"
@


1.4
log
@Switching exporter and resync
@
text
@d28 1
a28 1
# $FreeBSD: head/usr.sbin/bsdconfig/usermgmt/userinput 240768 2012-09-20 23:44:13Z dteske $
d41 1
a41 1
ipgm=$( f_index_menu_selection $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
@


1.3
log
@SVN rev 240768 on 2012-09-20 23:44:13Z by dteske

Change all invocations of dialog(1) to no-longer require temporary files.
This allows bsdconfig to -- like bsdinstall -- operate from read-only media.

Reviewed by:	adrian (co-mentor)
Approved by:	adrian (co-mentor)
@
text
@d28 1
a28 1
# $FreeBSD$
@


1.2
log
@SVN rev 240684 on 2012-09-18 22:28:42Z by dteske

Move major includes into /usr/share/bsdconfig for easy external access.

Reviewed by:	adrian (co-mentor)
Approved by:	adrian (co-mentor)
@
text
@d394 2
a395 1
	eval $DIALOG \
d403 2
a404 1
		2> $DIALOG_TMPDIR/dialog.menu.$$
d407 1
@


1.1
log
@SVN rev 238438 on 2012-07-14 03:16:57Z by dteske

Import bsdconfig(8) as a replacement for the post-install abilities of
deprecated sysinstall(8). NOTE: WITH_BSDCONFIG is currently required.

Submitted by:	Devin Teske (dteske), Ron McDowell <rcm@@fuzzwad.org>
Reviewed by:	Ron McDowell <rcm@@fuzzwad.org>
Approved by:	Ed Maste (emaste)
@
text
@d32 5
a36 4
BSDCFG_LIBE="/usr/libexec/bsdconfig"
. $BSDCFG_LIBE/include/common.subr || exit 1
f_include $BSDCFG_LIBE/include/dialog.subr
f_include $BSDCFG_LIBE/include/mustberoot.subr
d38 1
a38 2
APP_DIR="070.usermgmt"
f_include $BSDCFG_LIBE/$APP_DIR/include/user_input.subr
@

