xref: /freebsd/usr.sbin/bsdconfig/usermgmt/share/group_input.subr (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1ab2043b8SDevin Teskeif [ ! "$_USERMGMT_GROUP_INPUT_SUBR" ]; then _USERMGMT_GROUP_INPUT_SUBR=1
2ab2043b8SDevin Teske#
3ab2043b8SDevin Teske# Copyright (c) 2012 Ron McDowell
427c43fe1SDevin Teske# Copyright (c) 2012-2014 Devin Teske
5ab2043b8SDevin Teske# All rights reserved.
6ab2043b8SDevin Teske#
7ab2043b8SDevin Teske# Redistribution and use in source and binary forms, with or without
8ab2043b8SDevin Teske# modification, are permitted provided that the following conditions
9ab2043b8SDevin Teske# are met:
10ab2043b8SDevin Teske# 1. Redistributions of source code must retain the above copyright
11ab2043b8SDevin Teske#    notice, this list of conditions and the following disclaimer.
12ab2043b8SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright
13ab2043b8SDevin Teske#    notice, this list of conditions and the following disclaimer in the
14ab2043b8SDevin Teske#    documentation and/or other materials provided with the distribution.
15ab2043b8SDevin Teske#
16ab2043b8SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17ab2043b8SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18ab2043b8SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19ab2043b8SDevin Teske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20ab2043b8SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21ab2043b8SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22ab2043b8SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23ab2043b8SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24ab2043b8SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25ab2043b8SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26ab2043b8SDevin Teske# SUCH DAMAGE.
27ab2043b8SDevin Teske#
28ab2043b8SDevin Teske#
29ab2043b8SDevin Teske############################################################ INCLUDES
30ab2043b8SDevin Teske
31ab2043b8SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
32ab2043b8SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
3356961fd7SDevin Teskef_dprintf "%s: loading includes..." usermgmt/group_input.subr
34ab2043b8SDevin Teskef_include $BSDCFG_SHARE/dialog.subr
35ab2043b8SDevin Teskef_include $BSDCFG_SHARE/strings.subr
36ab2043b8SDevin Teske
37ab2043b8SDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
38ab2043b8SDevin Teskef_include_lang $BSDCFG_LIBE/include/messages.subr
39ab2043b8SDevin Teskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
40ab2043b8SDevin Teske
41ab2043b8SDevin Teske############################################################ FUNCTIONS
42ab2043b8SDevin Teske
43ab2043b8SDevin Teske# f_input_group $group
44ab2043b8SDevin Teske#
45ab2043b8SDevin Teske# Given $group name or id, create the environment variables group_name,
46ab2043b8SDevin Teske# group_gid, and group_members (and group_password is reset to NULL).
47ab2043b8SDevin Teske#
48ab2043b8SDevin Teskef_input_group()
49ab2043b8SDevin Teske{
5027c43fe1SDevin Teske	local funcname=f_input_group
5127c43fe1SDevin Teske	local group="$1"
5227c43fe1SDevin Teske
5327c43fe1SDevin Teske	f_dprintf "$funcname: Getting info for group \`%s'" "$group"
5427c43fe1SDevin Teske	eval "$( pw groupshow "$group" 2> /dev/null | awk -F: '
55*b00c7d1aSDevin Teske	function set_value(var, value) {
56*b00c7d1aSDevin Teske		gsub(/'\''/, "'\''\\'\'\''", value)
57*b00c7d1aSDevin Teske		printf "group_%s='\'%s\''\n", var, value
58*b00c7d1aSDevin Teske	}
59ab2043b8SDevin Teske	{
6027c43fe1SDevin Teske		found = $1 != ""
61*b00c7d1aSDevin Teske		set_value("name",     $1)
62*b00c7d1aSDevin Teske		set_value("password", "")
63*b00c7d1aSDevin Teske		set_value("gid",      $3)
64*b00c7d1aSDevin Teske		set_value("members",  $4)
65ab2043b8SDevin Teske		exit
6627c43fe1SDevin Teske	}
6727c43fe1SDevin Teske	END { if (!found) print "false" }' )"
68ab2043b8SDevin Teske}
69ab2043b8SDevin Teske
70d3a0f918SDevin Teske# f_dialog_menu_group_list [$default]
71ab2043b8SDevin Teske#
72d3a0f918SDevin Teske# Allows the user to select a group from a list. Optionally, if present and
73d3a0f918SDevin Teske# non-NULL, initially highlight $default group.
74ab2043b8SDevin Teske#
75ab2043b8SDevin Teskef_dialog_menu_group_list()
76ab2043b8SDevin Teske{
77052f8969SDevin Teske	local prompt=
78052f8969SDevin Teske	local menu_list="
79ab2043b8SDevin Teske		'X $msg_exit' ''
80ab2043b8SDevin Teske	" # END-QUOTE
81052f8969SDevin Teske	local defaultitem="$1"
82052f8969SDevin Teske	local hline="$hline_alnum_punc_tab_enter"
83ab2043b8SDevin Teske
84ab2043b8SDevin Teske	# Add groups from group(5)
85ab2043b8SDevin Teske	menu_list="$menu_list $( pw groupshow -a | awk -F: '
86*b00c7d1aSDevin Teske		function mprint(tag, item) {
87*b00c7d1aSDevin Teske			gsub(/'\''/, "'\''\\'\'\''", tag)
88*b00c7d1aSDevin Teske			gsub(/'\''/, "'\''\\'\'\''", item)
89*b00c7d1aSDevin Teske			printf "'\'%s\'\ \'%s\''\n", tag, item
90*b00c7d1aSDevin Teske		}
91*b00c7d1aSDevin Teske		!/^[[:space:]]*(#|$)/ { mprint($1, $1) }
92*b00c7d1aSDevin Teske	' )"
93ab2043b8SDevin Teske
9474036c4dSDevin Teske	local height width rows
9574036c4dSDevin Teske	eval f_dialog_menu_size height width rows \
96ab2043b8SDevin Teske	                        \"\$DIALOG_TITLE\"     \
97ab2043b8SDevin Teske	                        \"\$DIALOG_BACKTITLE\" \
98052f8969SDevin Teske	                        \"\$prompt\"           \
99ab2043b8SDevin Teske	                        \"\$hline\"            \
10074036c4dSDevin Teske	                        $menu_list
101ab2043b8SDevin Teske
102fd962ac6SDevin Teske	local menu_choice
103fd962ac6SDevin Teske	menu_choice=$( eval $DIALOG \
104d3a0f918SDevin Teske		--title \"\$DIALOG_TITLE\"         \
105ab2043b8SDevin Teske		--backtitle \"\$DIALOG_BACKTITLE\" \
106ab2043b8SDevin Teske		--hline \"\$hline\"                \
107ab2043b8SDevin Teske		--ok-label \"\$msg_ok\"            \
108ab2043b8SDevin Teske		--cancel-label \"\$msg_cancel\"    \
109d3a0f918SDevin Teske		--default-item \"\$defaultitem\"   \
110052f8969SDevin Teske		--menu \"\$prompt\"                \
11174036c4dSDevin Teske		$height $width $rows               \
11274036c4dSDevin Teske		$menu_list                         \
11389498fdfSDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
11489498fdfSDevin Teske	)
11589498fdfSDevin Teske	local retval=$?
116fd962ac6SDevin Teske	f_dialog_menutag_store -s "$menu_choice"
11789498fdfSDevin Teske	return $retval
118ab2043b8SDevin Teske}
119ab2043b8SDevin Teske
12027c43fe1SDevin Teske# f_dialog_input_group_name $var_to_set [$group_name]
121ab2043b8SDevin Teske#
12227c43fe1SDevin Teske# Allows the user to enter a name for a new group. If the user does not cancel
12327c43fe1SDevin Teske# or press ESC, the $var_to_set variable will hold the newly-configured value
12427c43fe1SDevin Teske# upon return.
125ab2043b8SDevin Teske#
126ab2043b8SDevin Teskef_dialog_input_group_name()
127ab2043b8SDevin Teske{
12827c43fe1SDevin Teske	local __var_to_set="$1" __name="$2"
12927c43fe1SDevin Teske
130ab2043b8SDevin Teske	#
131ab2043b8SDevin Teske	# Loop until the user provides taint-free/valid input
132ab2043b8SDevin Teske	#
13327c43fe1SDevin Teske	local __input="$__name"
134ab2043b8SDevin Teske	while :; do
135ab2043b8SDevin Teske		# Return if user has either pressed ESC or chosen Cancel/No
13627c43fe1SDevin Teske		f_dialog_input __input "$msg_group" "$__input" \
137f677a9e2SDevin Teske		               "$hline_alnum_tab_enter" || return $?
138ab2043b8SDevin Teske
139ab2043b8SDevin Teske		# Check for no-change
14027c43fe1SDevin Teske		if [ "$__input" = "$__name" ]; then
14127c43fe1SDevin Teske			setvar "$__var_to_set" "$__input"
142f677a9e2SDevin Teske			return $DIALOG_OK
143ab2043b8SDevin Teske		fi
144ab2043b8SDevin Teske
145ab2043b8SDevin Teske		# Check for NULL entry
14627c43fe1SDevin Teske		if [ ! "$__input" ]; then
1477079fc4eSDevin Teske			f_show_msg "$msg_group_is_empty"
148ab2043b8SDevin Teske			continue
149ab2043b8SDevin Teske		fi
150ab2043b8SDevin Teske
151ab2043b8SDevin Teske		# Check for invalid entry
15227c43fe1SDevin Teske		case "$__input" in [!a-zA-Z]*)
1537079fc4eSDevin Teske			f_show_msg "$msg_group_must_start_with_letter"
154ab2043b8SDevin Teske			continue
15527c43fe1SDevin Teske		esac
156ab2043b8SDevin Teske
157ab2043b8SDevin Teske		# Check for duplicate entry
15827c43fe1SDevin Teske		if f_quietly pw groupshow -n "$__input"; then
15927c43fe1SDevin Teske			f_show_msg "$msg_group_already_used" "$__input"
160ab2043b8SDevin Teske			continue
161ab2043b8SDevin Teske		fi
162ab2043b8SDevin Teske
16327c43fe1SDevin Teske		setvar "$__var_to_set" "$__input"
164ab2043b8SDevin Teske		break
165ab2043b8SDevin Teske	done
166ab2043b8SDevin Teske
167f677a9e2SDevin Teske	return $DIALOG_OK
168ab2043b8SDevin Teske}
169ab2043b8SDevin Teske
17027c43fe1SDevin Teske# f_dialog_input_group_password $var_to_set $dvar_to_set
171ab2043b8SDevin Teske#
17227c43fe1SDevin Teske# Prompt the user to enter a password (twice). If the user does not cancel or
17327c43fe1SDevin Teske# press ESC, $var_to_set will hold the confirmed user entry. Otherwise, if the
17427c43fe1SDevin Teske# user cancels or enters a NULL password (twice), they are given the choice to
17527c43fe1SDevin Teske# disable password authentication for the given group, wherein $dvar_to_set has
17627c43fe1SDevin Teske# a value of 1 to indicate password authentication should be disabled.
177ab2043b8SDevin Teske#
178ab2043b8SDevin Teskef_dialog_input_group_password()
179ab2043b8SDevin Teske{
18027c43fe1SDevin Teske	local __var_to_set="$1" __dvar_to_set="$2"
18127c43fe1SDevin Teske	local __prompt1="$msg_group_password"
18227c43fe1SDevin Teske	local __prompt2="$msg_reenter_group_password"
18327c43fe1SDevin Teske	local __hline="$hline_alnum_punc_tab_enter"
184ab2043b8SDevin Teske
18527c43fe1SDevin Teske	local __height1 __width1
18627c43fe1SDevin Teske	f_dialog_inputbox_size __height1 __width1 \
187ab2043b8SDevin Teske	        	"$DIALOG_TITLE"     \
188ab2043b8SDevin Teske	        	"$DIALOG_BACKTITLE" \
18927c43fe1SDevin Teske	        	"$__prompt1"        \
190ab2043b8SDevin Teske	        	""                  \
19127c43fe1SDevin Teske	        	"$__hline"
192ab2043b8SDevin Teske
19327c43fe1SDevin Teske	local __height2 __width2
19427c43fe1SDevin Teske	f_dialog_inputbox_size __height2 __width2 \
195ab2043b8SDevin Teske	        	"$DIALOG_TITLE"     \
196ab2043b8SDevin Teske	        	"$DIALOG_BACKTITLE" \
19727c43fe1SDevin Teske	        	"$__prompt2"        \
198ab2043b8SDevin Teske	        	""                  \
19927c43fe1SDevin Teske	        	"$__hline"
200ab2043b8SDevin Teske
201ab2043b8SDevin Teske	#
202ab2043b8SDevin Teske	# Loop until the user provides taint-free/valid input
203ab2043b8SDevin Teske	#
20427c43fe1SDevin Teske	local __retval __password1 __password2
205ab2043b8SDevin Teske	while :; do
20627c43fe1SDevin Teske		__password1=$( $DIALOG \
20774036c4dSDevin Teske			--title "$DIALOG_TITLE"         \
20874036c4dSDevin Teske			--backtitle "$DIALOG_BACKTITLE" \
20927c43fe1SDevin Teske			--hline "$__hline"              \
21074036c4dSDevin Teske			--ok-label "$msg_ok"            \
21174036c4dSDevin Teske			--cancel-label "$msg_cancel"    \
212ab2043b8SDevin Teske			--insecure                      \
21327c43fe1SDevin Teske			--passwordbox "$__prompt1"      \
21427c43fe1SDevin Teske			$__height1 $__width1            \
21589498fdfSDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
21689498fdfSDevin Teske		)
21727c43fe1SDevin Teske		__retval=$?
21827c43fe1SDevin Teske		debug= f_dialog_line_sanitize __password1
219ab2043b8SDevin Teske
220ab2043b8SDevin Teske		# Return if user has either pressed ESC or chosen Cancel/No
22127c43fe1SDevin Teske		[ $__retval -eq $DIALOG_OK ] || return $__retval
222ab2043b8SDevin Teske
22327c43fe1SDevin Teske		__password2=$( $DIALOG \
22474036c4dSDevin Teske			--title "$DIALOG_TITLE"         \
22574036c4dSDevin Teske			--backtitle "$DIALOG_BACKTITLE" \
22627c43fe1SDevin Teske			--hline "$__hline"              \
22774036c4dSDevin Teske			--ok-label "$msg_ok"            \
22874036c4dSDevin Teske			--cancel-label "$msg_cancel"    \
229ab2043b8SDevin Teske			--insecure                      \
23027c43fe1SDevin Teske			--passwordbox "$__prompt2"      \
23127c43fe1SDevin Teske			$__height2 $__width2            \
23289498fdfSDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
23389498fdfSDevin Teske		)
23427c43fe1SDevin Teske		__retval=$?
23527c43fe1SDevin Teske		debug= f_dialog_line_sanitize __password2
236ab2043b8SDevin Teske
237ab2043b8SDevin Teske		# Return if user has either pressed ESC or chosen Cancel/No
23827c43fe1SDevin Teske		[ $__retval -eq $DIALOG_OK ] || return $__retval
239ab2043b8SDevin Teske
240ab2043b8SDevin Teske		# Check for password mismatch
24127c43fe1SDevin Teske		if [ "$__password1" != "$__password2" ]; then
2427079fc4eSDevin Teske			f_show_msg "$msg_group_passwords_do_not_match"
243ab2043b8SDevin Teske			continue
244ab2043b8SDevin Teske		fi
245ab2043b8SDevin Teske
246ab2043b8SDevin Teske		# Check for NULL entry
24727c43fe1SDevin Teske		if [ ! "$__password1" ]; then
2487ca5c4cbSDevin Teske			f_dialog_yesno "$msg_disable_password_auth_for_group"
24927c43fe1SDevin Teske			__retval=$?
25027c43fe1SDevin Teske			if [ $__retval -eq $DIALOG_ESC ]; then
25127c43fe1SDevin Teske				return $__retval
25227c43fe1SDevin Teske			elif [ $__retval -eq $DIALOG_OK ]; then
25327c43fe1SDevin Teske				setvar "$__dvar_to_set" 1
254528318aeSDevin Teske			else
255350db065SDevin Teske				continue # back to password prompt
256528318aeSDevin Teske			fi
257ab2043b8SDevin Teske		else
25827c43fe1SDevin Teske			setvar "$__dvar_to_set" ""
259ab2043b8SDevin Teske		fi
260ab2043b8SDevin Teske
26127c43fe1SDevin Teske		setvar "$__var_to_set" "$__password1"
262ab2043b8SDevin Teske		break
263ab2043b8SDevin Teske	done
264ab2043b8SDevin Teske
265f677a9e2SDevin Teske	return $DIALOG_OK
266ab2043b8SDevin Teske}
267ab2043b8SDevin Teske
26827c43fe1SDevin Teske# f_dialog_input_group_gid $var_to_set [$group_gid]
269ab2043b8SDevin Teske#
270ab2043b8SDevin Teske# Allow the user to enter a new GID for a given group. If the user does not
27127c43fe1SDevin Teske# cancel or press ESC, the $var_to_set variable will hold the newly-configured
272ab2043b8SDevin Teske# value upon return.
273ab2043b8SDevin Teske#
274ab2043b8SDevin Teskef_dialog_input_group_gid()
275ab2043b8SDevin Teske{
27627c43fe1SDevin Teske	local __var_to_set="$1" __input="$2"
277ab2043b8SDevin Teske
278ab2043b8SDevin Teske	# Return if user has either pressed ESC or chosen Cancel/No
27927c43fe1SDevin Teske	f_dialog_input __input "$msg_group_id_leave_empty_for_default" \
28027c43fe1SDevin Teske	               "$__input" "$hline_num_tab_enter" || return $?
281ab2043b8SDevin Teske
28227c43fe1SDevin Teske	setvar "$__var_to_set" "$__input"
283f677a9e2SDevin Teske	return $DIALOG_OK
284ab2043b8SDevin Teske}
285ab2043b8SDevin Teske
28627c43fe1SDevin Teske# f_dialog_input_group_members $var_to_set [$group_members]
287ab2043b8SDevin Teske#
288f4844f65SDevin Teske# Allow the user to modify a list of members for a given group. If the user
28927c43fe1SDevin Teske# does not cancel or press ESC, the $var_to_set variable will hold the newly-
29027c43fe1SDevin Teske# configured value upon return.
291ab2043b8SDevin Teske#
292ab2043b8SDevin Teskef_dialog_input_group_members()
293ab2043b8SDevin Teske{
29427c43fe1SDevin Teske	local __var_to_set="$1" __input="$2"
29527c43fe1SDevin Teske	local __prompt="$msg_group_members:"
29627c43fe1SDevin Teske	local __menu_list="
297ab2043b8SDevin Teske		'X' '$msg_continue'
298ab2043b8SDevin Teske		'1' '$msg_select_group_members_from_list'
299ab2043b8SDevin Teske		'2' '$msg_enter_group_members_manually'
300ab2043b8SDevin Teske	" # END-QUOTE
30127c43fe1SDevin Teske	local __defaultitem=
30227c43fe1SDevin Teske	local __hline="$hline_num_arrows_tab_enter"
303ab2043b8SDevin Teske
30427c43fe1SDevin Teske	local __mheight __mwidth __mrows
30527c43fe1SDevin Teske	eval f_dialog_menu_size __mheight __mwidth __mrows \
30627c43fe1SDevin Teske	                        \"\$DIALOG_TITLE\"     \
30727c43fe1SDevin Teske	                        \"\$DIALOG_BACKTITLE\" \
30827c43fe1SDevin Teske	                        \"\$__prompt\"         \
30927c43fe1SDevin Teske	                        \"\$__hline\"          \
310072b47f3SDevin Teske	                        $__menu_list
31127c43fe1SDevin Teske
31227c43fe1SDevin Teske	local __menu_choice __retval
31327c43fe1SDevin Teske	while :; do
31427c43fe1SDevin Teske		__menu_choice=$( eval $DIALOG \
31527c43fe1SDevin Teske			--title \"\$DIALOG_TITLE\"         \
31627c43fe1SDevin Teske			--backtitle \"\$DIALOG_BACKTITLE\" \
31727c43fe1SDevin Teske			--hline \"\$__hline\"              \
31827c43fe1SDevin Teske			--ok-label \"\$msg_ok\"            \
31927c43fe1SDevin Teske			--cancel-label \"\$msg_cancel\"    \
32027c43fe1SDevin Teske			--default-item \"\$__defaultitem\" \
32127c43fe1SDevin Teske			--menu \"\$__prompt\"              \
32227c43fe1SDevin Teske			$__mheight $__mwidth $__mrows      \
32327c43fe1SDevin Teske			$__menu_list                       \
32427c43fe1SDevin Teske			2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
32527c43fe1SDevin Teske		)
32627c43fe1SDevin Teske		__retval=$?
32727c43fe1SDevin Teske		f_dialog_data_sanitize __menu_choice
32827c43fe1SDevin Teske		__defaultitem="$__menu_choice"
32927c43fe1SDevin Teske		f_dprintf "retval=%u menu_choice=[%s]" \
33027c43fe1SDevin Teske		          $__retval "$__menu_choice"
33127c43fe1SDevin Teske
33227c43fe1SDevin Teske		# Return if user has either pressed ESC or chosen Cancel/No
33327c43fe1SDevin Teske		[ $__retval -eq $DIALOG_OK ] || return $__retval
33427c43fe1SDevin Teske
33527c43fe1SDevin Teske		local __group_members
33627c43fe1SDevin Teske		case "$__menu_choice" in
33727c43fe1SDevin Teske		X) # Exit
33827c43fe1SDevin Teske			break ;;
33927c43fe1SDevin Teske		1) # Select Group Members from a list
340*b00c7d1aSDevin Teske			local __check_list= # Calculated below
341*b00c7d1aSDevin Teske			local __user_list __u __user __length=0
34227c43fe1SDevin Teske			__user_list=$( pw usershow -a |
34327c43fe1SDevin Teske				awk -F: '!/^[[:space:]]*(#|$)/{print $1}' )
34427c43fe1SDevin Teske			while [ $__length -ne ${#__user_list} ]; do
345*b00c7d1aSDevin Teske				__u="${__user_list%%$NL*}" # First line
346*b00c7d1aSDevin Teske				f_shell_escape "$__u" __user
34727c43fe1SDevin Teske
34827c43fe1SDevin Teske				# Format of a checklist entry: tag item status
34927c43fe1SDevin Teske				__check_list="$__check_list '$__user' ''"
35027c43fe1SDevin Teske				case "$__input" in
351*b00c7d1aSDevin Teske				"$__u"|"$__u",*|*,"$__u",*|*,"$__u")
35227c43fe1SDevin Teske					__check_list="$__check_list on" ;;
35327c43fe1SDevin Teske				*)
35427c43fe1SDevin Teske					__check_list="$__check_list off"
35527c43fe1SDevin Teske				esac
35627c43fe1SDevin Teske
35727c43fe1SDevin Teske				__length=${#__user_list}
35827c43fe1SDevin Teske				__user_list="${__user_list#*$NL}" # Kill line
35927c43fe1SDevin Teske			done
36027c43fe1SDevin Teske
36127c43fe1SDevin Teske			local __cheight __cwidth __crows
36227c43fe1SDevin Teske			eval f_dialog_checklist_size \
36327c43fe1SDevin Teske				__cheight __cwidth __crows \
36427c43fe1SDevin Teske				\"\$DIALOG_TITLE\"     \
36527c43fe1SDevin Teske				\"\$DIALOG_BACKTITLE\" \
36627c43fe1SDevin Teske				\"\$__prompt\"         \
36727c43fe1SDevin Teske				\"\$__hline\"          \
36827c43fe1SDevin Teske				$__check_list
36927c43fe1SDevin Teske			__group_members=$( eval $DIALOG \
37027c43fe1SDevin Teske				--title \"\$DIALOG_TITLE\"         \
37127c43fe1SDevin Teske				--backtitle \"\$DIALOG_BACKTITLE\" \
37227c43fe1SDevin Teske				--separate-output                  \
37327c43fe1SDevin Teske				--hline \"\$__hline\"              \
37427c43fe1SDevin Teske				--ok-label \"\$msg_ok\"            \
37527c43fe1SDevin Teske				--cancel-label \"\$msg_cancel\"    \
37627c43fe1SDevin Teske				--checklist \"\$__prompt\"         \
37727c43fe1SDevin Teske				$__cheight $__cwidth $__crows      \
37827c43fe1SDevin Teske				$__check_list                      \
37927c43fe1SDevin Teske				2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
38027c43fe1SDevin Teske			) || continue
38127c43fe1SDevin Teske				# Return to previous menu if user either
38227c43fe1SDevin Teske				# pressed ESC or chose Cancel/No
38327c43fe1SDevin Teske			f_dialog_data_sanitize __group_members
38427c43fe1SDevin Teske
38527c43fe1SDevin Teske			#
38627c43fe1SDevin Teske			# Convert the newline separated list into a comma-
38727c43fe1SDevin Teske			# separated one so that if the user switches over to
38827c43fe1SDevin Teske			# manual editing, list reflects checklist selections
38927c43fe1SDevin Teske			#
39027c43fe1SDevin Teske			f_replaceall "$__group_members" "[$NL]" "," __input
39127c43fe1SDevin Teske			;;
39227c43fe1SDevin Teske		2) # Enter Group Members manually
39327c43fe1SDevin Teske			local __prompt2="$msg_group_members"
39427c43fe1SDevin Teske			__prompt2="$__prompt2 ($msg_separated_by_commas)"
39527c43fe1SDevin Teske
39627c43fe1SDevin Teske			f_dialog_input __group_members \
39727c43fe1SDevin Teske			               "$__prompt2" "$__input" \
39827c43fe1SDevin Teske			               "$hline_num_tab_enter" || continue
39927c43fe1SDevin Teske				# Return to previous menu if user either
40027c43fe1SDevin Teske				# pressed ESC or chose Cancel/No
40127c43fe1SDevin Teske
40227c43fe1SDevin Teske			__input="$__group_members"
40327c43fe1SDevin Teske			;;
40427c43fe1SDevin Teske		esac
40527c43fe1SDevin Teske	done
40627c43fe1SDevin Teske
40727c43fe1SDevin Teske	setvar "$__var_to_set" "$__input"
40827c43fe1SDevin Teske	return $DIALOG_OK
40927c43fe1SDevin Teske}
41027c43fe1SDevin Teske
41127c43fe1SDevin Teske# f_dialog_menu_group_add [$defaultitem]
41227c43fe1SDevin Teske#
41327c43fe1SDevin Teske# Present a menu detailing the properties of a group that is about to be added.
41427c43fe1SDevin Teske# The user's menu choice is available using f_dialog_menutag_fetch(). Returns
41527c43fe1SDevin Teske# success unless the user chose Cancel or pressed ESC. Data to display is taken
41627c43fe1SDevin Teske# from environment variables group_name, group_gid, and group_members. If
41727c43fe1SDevin Teske# $defaultitem is present and non-NULL, initially highlight the item in the
41827c43fe1SDevin Teske# menu.
41927c43fe1SDevin Teske#
42027c43fe1SDevin Teskef_dialog_menu_group_add()
42127c43fe1SDevin Teske{
42227c43fe1SDevin Teske	local prompt="$msg_save_exit_or_cancel"
42327c43fe1SDevin Teske	local menu_list # Calculated below
42427c43fe1SDevin Teske	local defaultitem="$1"
42527c43fe1SDevin Teske	local hline="$hline_arrows_tab_enter"
42627c43fe1SDevin Teske
427*b00c7d1aSDevin Teske	# Localize potentially hostile variables and escape their values
428*b00c7d1aSDevin Teske	# to the local variable (see f_shell_escape() of `strings.subr')
429*b00c7d1aSDevin Teske	local var
430*b00c7d1aSDevin Teske	for var in gid members name; do
431*b00c7d1aSDevin Teske		local _group_$var
432*b00c7d1aSDevin Teske		eval f_shell_escape \"\$group_$var\" _group_$var
433*b00c7d1aSDevin Teske	done
434*b00c7d1aSDevin Teske
43527c43fe1SDevin Teske	menu_list="
43627c43fe1SDevin Teske		'X' '$msg_add/$msg_exit'
437*b00c7d1aSDevin Teske		'1' '$msg_group: $_group_name'
43827c43fe1SDevin Teske		'2' '$msg_password: -----'
439*b00c7d1aSDevin Teske		'3' '$msg_group_id: $_group_gid'
440*b00c7d1aSDevin Teske		'4' '$msg_group_members: $_group_members'
44127c43fe1SDevin Teske	" # END-QUOTE
44227c43fe1SDevin Teske
44327c43fe1SDevin Teske	local height width rows
44427c43fe1SDevin Teske	eval f_dialog_menu_size height width rows \
445ab2043b8SDevin Teske	                        \"\$DIALOG_TITLE\"     \
446ab2043b8SDevin Teske	                        \"\$DIALOG_BACKTITLE\" \
447052f8969SDevin Teske	                        \"\$prompt\"           \
448ab2043b8SDevin Teske	                        \"\$hline\"            \
44974036c4dSDevin Teske	                        $menu_list
45074036c4dSDevin Teske
45127c43fe1SDevin Teske	local menu_choice
452fd962ac6SDevin Teske	menu_choice=$( eval $DIALOG \
453ab2043b8SDevin Teske		--title \"\$DIALOG_TITLE\"         \
454ab2043b8SDevin Teske		--backtitle \"\$DIALOG_BACKTITLE\" \
455ab2043b8SDevin Teske		--hline \"\$hline\"                \
456ab2043b8SDevin Teske		--ok-label \"\$msg_ok\"            \
457ab2043b8SDevin Teske		--cancel-label \"\$msg_cancel\"    \
458d3a0f918SDevin Teske		--default-item \"\$defaultitem\"   \
459052f8969SDevin Teske		--menu \"\$prompt\"                \
46027c43fe1SDevin Teske		$height $width $rows               \
461ab2043b8SDevin Teske		$menu_list                         \
46289498fdfSDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
46389498fdfSDevin Teske	)
46427c43fe1SDevin Teske	local retval=$?
465fd962ac6SDevin Teske	f_dialog_data_sanitize menu_choice
46627c43fe1SDevin Teske	f_dialog_menutag_store "$menu_choice"
46727c43fe1SDevin Teske	return $retval
46827c43fe1SDevin Teske}
469ab2043b8SDevin Teske
47027c43fe1SDevin Teske# f_dialog_menu_group_delete $group [$defaultitem]
47127c43fe1SDevin Teske#
47227c43fe1SDevin Teske# Present a menu detailing the properties of a group that is about to be
47327c43fe1SDevin Teske# deleted. The user's menu choice is available using f_dialog_menutag_fetch().
47427c43fe1SDevin Teske# Returns success unless the user chose Cancel or pressed ESC. Data to display
47527c43fe1SDevin Teske# is populated automatically from the system accounting database for the given
47627c43fe1SDevin Teske# $group argument. If $defaultitem is present and non-NULL, initially highlight
47727c43fe1SDevin Teske# the item in the menu.
47827c43fe1SDevin Teske#
47927c43fe1SDevin Teskef_dialog_menu_group_delete()
48027c43fe1SDevin Teske{
48127c43fe1SDevin Teske	local prompt="$msg_delete_exit_or_cancel"
48227c43fe1SDevin Teske	local menu_list # Calculated below
48327c43fe1SDevin Teske	local defaultitem="$2"
48427c43fe1SDevin Teske	local hline="$hline_arrows_tab_enter"
485ab2043b8SDevin Teske
48627c43fe1SDevin Teske	local group_name group_password group_gid group_members
48727c43fe1SDevin Teske	f_input_group "$1"
488ab2043b8SDevin Teske
489*b00c7d1aSDevin Teske	# Localize potentially hostile variables and escape their values
490*b00c7d1aSDevin Teske	# to the local variable (see f_shell_escape() of `strings.subr')
491*b00c7d1aSDevin Teske	local var
492*b00c7d1aSDevin Teske	for var in gid members name; do
493*b00c7d1aSDevin Teske		local _group_$var
494*b00c7d1aSDevin Teske		eval f_shell_escape \"\$group_$var\" _group_$var
495*b00c7d1aSDevin Teske	done
496*b00c7d1aSDevin Teske
49727c43fe1SDevin Teske	menu_list="
49827c43fe1SDevin Teske		'X' '$msg_delete/$msg_exit'
499*b00c7d1aSDevin Teske		'1' '$msg_group: $_group_name'
50027c43fe1SDevin Teske		'-' '$msg_password: -----'
501*b00c7d1aSDevin Teske		'-' '$msg_group_id: $_group_gid'
502*b00c7d1aSDevin Teske		'-' '$msg_group_members: $_group_members'
50327c43fe1SDevin Teske	" # END-QUOTE
50427c43fe1SDevin Teske
50527c43fe1SDevin Teske	local height width rows
50627c43fe1SDevin Teske	eval f_dialog_menu_size height width rows \
507ab2043b8SDevin Teske	                        \"\$DIALOG_TITLE\"     \
508ab2043b8SDevin Teske	                        \"\$DIALOG_BACKTITLE\" \
509052f8969SDevin Teske	                        \"\$prompt\"           \
510ab2043b8SDevin Teske	                        \"\$hline\"            \
51127c43fe1SDevin Teske	                        $menu_list
51227c43fe1SDevin Teske
51327c43fe1SDevin Teske	local menu_choice
51427c43fe1SDevin Teske	menu_choice=$( eval $DIALOG \
515ab2043b8SDevin Teske		--title \"\$DIALOG_TITLE\"         \
516ab2043b8SDevin Teske		--backtitle \"\$DIALOG_BACKTITLE\" \
517ab2043b8SDevin Teske		--hline \"\$hline\"                \
518ab2043b8SDevin Teske		--ok-label \"\$msg_ok\"            \
519ab2043b8SDevin Teske		--cancel-label \"\$msg_cancel\"    \
52027c43fe1SDevin Teske		--default-item \"\$defaultitem\"   \
52127c43fe1SDevin Teske		--menu \"\$prompt\"                \
52227c43fe1SDevin Teske		$height $width $rows               \
52327c43fe1SDevin Teske		$menu_list                         \
52489498fdfSDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
52527c43fe1SDevin Teske	)
52627c43fe1SDevin Teske	local retval=$?
52727c43fe1SDevin Teske	f_dialog_data_sanitize menu_choice
52827c43fe1SDevin Teske	f_dialog_menutag_store "$menu_choice"
52927c43fe1SDevin Teske	return $retval
53027c43fe1SDevin Teske}
531ab2043b8SDevin Teske
53227c43fe1SDevin Teske# f_dialog_menu_group_edit [$defaultitem]
533d4ae33f0SDevin Teske#
53427c43fe1SDevin Teske# Present a menu detailing the properties of a group that is about to be
53527c43fe1SDevin Teske# modified. The user's menu choice is available using f_dialog_menutag_fetch().
53627c43fe1SDevin Teske# Returns success unless the user chose Cancel or pressed ESC. Data to display
53727c43fe1SDevin Teske# is taken from environment variables group_name, group_gid, and group_members.
53827c43fe1SDevin Teske# If $defaultitem is present and non-NULL, initially highlight the item in the
53927c43fe1SDevin Teske# menu.
540d4ae33f0SDevin Teske#
54127c43fe1SDevin Teskef_dialog_menu_group_edit()
54227c43fe1SDevin Teske{
54327c43fe1SDevin Teske	local prompt="$msg_save_exit_or_cancel"
54427c43fe1SDevin Teske	local menu_list # Calculated below
54527c43fe1SDevin Teske	local defaultitem="$1"
54627c43fe1SDevin Teske	local hline="$hline_arrows_tab_enter"
547ab2043b8SDevin Teske
548*b00c7d1aSDevin Teske	# Localize potentially hostile variables and escape their values
549*b00c7d1aSDevin Teske	# to the local variable (see f_shell_escape() of `strings.subr')
550*b00c7d1aSDevin Teske	local var
551*b00c7d1aSDevin Teske	for var in gid members name; do
552*b00c7d1aSDevin Teske		local _group_$var
553*b00c7d1aSDevin Teske		eval f_shell_escape \"\$group_$var\" _group_$var
554*b00c7d1aSDevin Teske	done
555*b00c7d1aSDevin Teske
55627c43fe1SDevin Teske	menu_list="
55727c43fe1SDevin Teske		'X' '$msg_save/$msg_exit'
558*b00c7d1aSDevin Teske		'1' '$msg_group: $_group_name'
55927c43fe1SDevin Teske		'2' '$msg_password: -----'
560*b00c7d1aSDevin Teske		'3' '$msg_group_id: $_group_gid'
561*b00c7d1aSDevin Teske		'4' '$msg_group_members: $_group_members'
56227c43fe1SDevin Teske	" # END-QUOTE
563ab2043b8SDevin Teske
56427c43fe1SDevin Teske	local height width rows
56527c43fe1SDevin Teske	eval f_dialog_menu_size height width rows \
56627c43fe1SDevin Teske	                        \"\$DIALOG_TITLE\"     \
56727c43fe1SDevin Teske	                        \"\$DIALOG_BACKTITLE\" \
56827c43fe1SDevin Teske	                        \"\$prompt\"           \
56927c43fe1SDevin Teske	                        \"\$hline\"            \
57027c43fe1SDevin Teske	                        $menu_list
571ab2043b8SDevin Teske
57227c43fe1SDevin Teske	local menu_choice
57327c43fe1SDevin Teske	menu_choice=$( eval $DIALOG \
57427c43fe1SDevin Teske		--title \"\$DIALOG_TITLE\"         \
57527c43fe1SDevin Teske		--backtitle \"\$DIALOG_BACKTITLE\" \
57627c43fe1SDevin Teske		--hline \"\$hline\"                \
57727c43fe1SDevin Teske		--ok-label \"\$msg_ok\"            \
57827c43fe1SDevin Teske		--cancel-label \"\$msg_cancel\"    \
57927c43fe1SDevin Teske		--default-item \"\$defaultitem\"   \
58027c43fe1SDevin Teske		--menu \"\$prompt\"                \
58127c43fe1SDevin Teske		$height $width $rows               \
58227c43fe1SDevin Teske		$menu_list                         \
58327c43fe1SDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
58427c43fe1SDevin Teske	)
58527c43fe1SDevin Teske	local retval=$?
58627c43fe1SDevin Teske	f_dialog_data_sanitize menu_choice
58727c43fe1SDevin Teske	f_dialog_menutag_store "$menu_choice"
58827c43fe1SDevin Teske	return $retval
589ab2043b8SDevin Teske}
590ab2043b8SDevin Teske
59156961fd7SDevin Teske############################################################ MAIN
59256961fd7SDevin Teske
59356961fd7SDevin Teskef_dprintf "%s: Successfully loaded." usermgmt/group_input.subr
59456961fd7SDevin Teske
595ab2043b8SDevin Teskefi # ! $_USERMGMT_GROUP_INPUT_SUBR
596