xref: /freebsd/usr.sbin/bsdconfig/usermgmt/usermgmt (revision 3c91c65a2b999a8d27e99bcc6493de7cf812c948)
1641a6cfbSDevin Teske#!/bin/sh
2641a6cfbSDevin Teske#-
3641a6cfbSDevin Teske# Copyright (c) 2012 Ron McDowell
4641a6cfbSDevin Teske# Copyright (c) 2012 Devin Teske
5641a6cfbSDevin Teske# All rights reserved.
6641a6cfbSDevin Teske#
7641a6cfbSDevin Teske# Redistribution and use in source and binary forms, with or without
8641a6cfbSDevin Teske# modification, are permitted provided that the following conditions
9641a6cfbSDevin Teske# are met:
10641a6cfbSDevin Teske# 1. Redistributions of source code must retain the above copyright
11641a6cfbSDevin Teske#    notice, this list of conditions and the following disclaimer.
12641a6cfbSDevin Teske# 2. Redistributions in binary form must reproduce the above copyright
13641a6cfbSDevin Teske#    notice, this list of conditions and the following disclaimer in the
14641a6cfbSDevin Teske#    documentation and/or other materials provided with the distribution.
15641a6cfbSDevin Teske#
16641a6cfbSDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17641a6cfbSDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18641a6cfbSDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19641a6cfbSDevin Teske# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20641a6cfbSDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21641a6cfbSDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22641a6cfbSDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23641a6cfbSDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24641a6cfbSDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25641a6cfbSDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26641a6cfbSDevin Teske# SUCH DAMAGE.
27641a6cfbSDevin Teske#
28641a6cfbSDevin Teske# $FreeBSD$
29641a6cfbSDevin Teske#
30641a6cfbSDevin Teske############################################################ INCLUDES
31641a6cfbSDevin Teske
32ab2043b8SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig"
33ab2043b8SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1
3456961fd7SDevin Teskef_dprintf "%s: loading includes..." "$0"
35ab2043b8SDevin Teskef_include $BSDCFG_SHARE/dialog.subr
36ab2043b8SDevin Teskef_include $BSDCFG_SHARE/mustberoot.subr
37641a6cfbSDevin Teske
38ab2043b8SDevin TeskeBSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
39641a6cfbSDevin Teskef_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
40641a6cfbSDevin Teske
41724b4bfdSDevin TeskeUSERMGMT_HELPFILE=$BSDCFG_LIBE/$APP_DIR/include/usermgmt.hlp
42724b4bfdSDevin Teske
4348c5129fSDevin Teskeipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
44641a6cfbSDevin Teske[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm"
45641a6cfbSDevin Teske
46641a6cfbSDevin Teske############################################################ FUNCTIONS
47641a6cfbSDevin Teske
48641a6cfbSDevin Teske# dialog_menu_main
49641a6cfbSDevin Teske#
50641a6cfbSDevin Teske# Display the dialog(1)-based application main menu.
51641a6cfbSDevin Teske#
52641a6cfbSDevin Teskedialog_menu_main()
53641a6cfbSDevin Teske{
54641a6cfbSDevin Teske	local menu_list size
55641a6cfbSDevin Teske	local hline="$hline_arrows_tab_enter"
56641a6cfbSDevin Teske
57641a6cfbSDevin Teske	menu_list="
58641a6cfbSDevin Teske		'X' '$msg_exit'
59641a6cfbSDevin Teske		'1' '$msg_add_login'
60641a6cfbSDevin Teske		'2' '$msg_edit_login'
61641a6cfbSDevin Teske		'3' '$msg_delete_login'
62641a6cfbSDevin Teske		'-' '-'
63641a6cfbSDevin Teske		'4' '$msg_add_group'
64641a6cfbSDevin Teske		'5' '$msg_edit_group'
65641a6cfbSDevin Teske		'6' '$msg_delete_group'
66641a6cfbSDevin Teske	" # END-QUOTE
67641a6cfbSDevin Teske
68641a6cfbSDevin Teske	size=$( eval f_dialog_menu_size \
69641a6cfbSDevin Teske	        	\"\$DIALOG_TITLE\"     \
70641a6cfbSDevin Teske	        	\"\$DIALOG_BACKTITLE\" \
71641a6cfbSDevin Teske	        	\"\"                   \
72641a6cfbSDevin Teske	        	\"\$hline\"            \
73641a6cfbSDevin Teske	        	$menu_list             )
74641a6cfbSDevin Teske
75724b4bfdSDevin Teske	if [ "$USE_XDIALOG" ]; then
76724b4bfdSDevin Teske		# need to bump the width for the buttons
77724b4bfdSDevin Teske		local height menu_height
78724b4bfdSDevin Teske		height="${size%%[$IFS]*}" # first word
79724b4bfdSDevin Teske		menu_height="${size##*[$IFS]}" # last word
80724b4bfdSDevin Teske		size="$height 40 $menu_height"
81724b4bfdSDevin Teske	fi
82724b4bfdSDevin Teske
8389498fdfSDevin Teske	local dialog_menu
8489498fdfSDevin Teske	dialog_menu=$( eval $DIALOG \
85641a6cfbSDevin Teske		--clear --title \"\$DIALOG_TITLE\" \
86641a6cfbSDevin Teske		--backtitle \"\$DIALOG_BACKTITLE\" \
87641a6cfbSDevin Teske		--hline \"\$hline\"                \
88641a6cfbSDevin Teske		--ok-label \"\$msg_ok\"            \
89641a6cfbSDevin Teske		--cancel-label \"\$msg_cancel\"    \
90724b4bfdSDevin Teske		--help-button                      \
91*3c91c65aSDevin Teske		--help-label \"\$msg_help\"        \
92724b4bfdSDevin Teske		${USE_XDIALOG:+--help \"\"}        \
93641a6cfbSDevin Teske		--menu \"\" $size $menu_list       \
9489498fdfSDevin Teske		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
9589498fdfSDevin Teske	)
9689498fdfSDevin Teske	local retval=$?
9789498fdfSDevin Teske	setvar DIALOG_MENU_$$ "$dialog_menu"
9889498fdfSDevin Teske	return $retval
99641a6cfbSDevin Teske}
100641a6cfbSDevin Teske
101641a6cfbSDevin Teske############################################################ MAIN
102641a6cfbSDevin Teske
103641a6cfbSDevin Teske# Incorporate rc-file if it exists
104641a6cfbSDevin Teske[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
105641a6cfbSDevin Teske
106641a6cfbSDevin Teske#
107641a6cfbSDevin Teske# Process command-line arguments
108641a6cfbSDevin Teske#
109641a6cfbSDevin Teskewhile getopts hSX flag; do
110641a6cfbSDevin Teske	case "$flag" in
111641a6cfbSDevin Teske	h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
112641a6cfbSDevin Teske	esac
113641a6cfbSDevin Teskedone
114641a6cfbSDevin Teskeshift $(( $OPTIND - 1 ))
115641a6cfbSDevin Teske
116641a6cfbSDevin Teske#
117641a6cfbSDevin Teske# Initialize
118641a6cfbSDevin Teske#
119641a6cfbSDevin Teskef_dialog_title "$msg_login_management"
120641a6cfbSDevin Teskef_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
121641a6cfbSDevin Teskef_mustberoot_init
122641a6cfbSDevin Teske
123641a6cfbSDevin Teske#
124641a6cfbSDevin Teske# Launch application main menu
125641a6cfbSDevin Teske#
126641a6cfbSDevin Teskewhile :; do
127641a6cfbSDevin Teske	dialog_menu_main
128641a6cfbSDevin Teske	retval=$?
129641a6cfbSDevin Teske	mtag=$( f_dialog_menutag )
130526e1dc1SDevin Teske	f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
131641a6cfbSDevin Teske
132724b4bfdSDevin Teske	if [ $retval -eq 2 ]; then
133724b4bfdSDevin Teske		# The Help button was pressed
134724b4bfdSDevin Teske		f_show_help "$USERMGMT_HELPFILE"
135724b4bfdSDevin Teske		continue
136724b4bfdSDevin Teske	elif [ $retval -ne $SUCCESS ]; then
137724b4bfdSDevin Teske		f_die
138724b4bfdSDevin Teske	fi
139641a6cfbSDevin Teske
140641a6cfbSDevin Teske	case "$mtag" in
141641a6cfbSDevin Teske	X) # Exit
142641a6cfbSDevin Teske	   exit 0
143641a6cfbSDevin Teske	   ;;
144641a6cfbSDevin Teske
145641a6cfbSDevin Teske	1) # Add User
146641a6cfbSDevin Teske	   $BSDCFG_LIBE/$APP_DIR/useradd ${USE_XDIALOG:+-X}
147641a6cfbSDevin Teske	   ;;
148641a6cfbSDevin Teske
149641a6cfbSDevin Teske	2) # Edit/View User
150641a6cfbSDevin Teske	   $BSDCFG_LIBE/$APP_DIR/useredit ${USE_XDIALOG:+-X}
151641a6cfbSDevin Teske	   ;;
152641a6cfbSDevin Teske
153641a6cfbSDevin Teske	3) # Delete User
154641a6cfbSDevin Teske	   $BSDCFG_LIBE/$APP_DIR/userdel ${USE_XDIALOG:+-X}
155641a6cfbSDevin Teske	   ;;
156641a6cfbSDevin Teske
157641a6cfbSDevin Teske	4) # Add Group
158641a6cfbSDevin Teske	   $BSDCFG_LIBE/$APP_DIR/groupadd ${USE_XDIALOG:+-X}
159641a6cfbSDevin Teske	   ;;
160641a6cfbSDevin Teske
161641a6cfbSDevin Teske	5) # Edit/View Group
162641a6cfbSDevin Teske	   $BSDCFG_LIBE/$APP_DIR/groupedit ${USE_XDIALOG:+-X}
163641a6cfbSDevin Teske	   ;;
164641a6cfbSDevin Teske
165641a6cfbSDevin Teske	6) # Delete Group
166641a6cfbSDevin Teske	   $BSDCFG_LIBE/$APP_DIR/groupdel ${USE_XDIALOG:+-X}
167641a6cfbSDevin Teske	   ;;
168641a6cfbSDevin Teske
169641a6cfbSDevin Teske	esac
170641a6cfbSDevin Teskedone
171641a6cfbSDevin Teske
172641a6cfbSDevin Teske################################################################################
173641a6cfbSDevin Teske# END
174641a6cfbSDevin Teske################################################################################
175