summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/usermgmt/groupinput
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bsdconfig/usermgmt/groupinput')
-rwxr-xr-xusr.sbin/bsdconfig/usermgmt/groupinput295
1 files changed, 295 insertions, 0 deletions
diff --git a/usr.sbin/bsdconfig/usermgmt/groupinput b/usr.sbin/bsdconfig/usermgmt/groupinput
new file mode 100755
index 0000000..96186be
--- /dev/null
+++ b/usr.sbin/bsdconfig/usermgmt/groupinput
@@ -0,0 +1,295 @@
+#!/bin/sh
+#-
+# Copyright (c) 2012 Ron McDowell
+# Copyright (c) 2012 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_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
+
+APP_DIR="070.usermgmt"
+f_include $BSDCFG_LIBE/$APP_DIR/include/group_input.subr
+f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
+
+ipgm=$( f_index_menu_selection $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"}
+
+############################################################ FUNCTIONS
+
+# save_changes
+#
+# Save any/all settings (actions performed depend on $mode value).
+#
+save_changes()
+{
+ local err retval=$SUCCESS
+
+ case "$mode" in
+ Delete)
+ err=$( pw groupdel "$group_name" 2>&1 )
+ retval=$?
+ if [ $retval -ne $SUCCESS ]; then
+ f_show_msg "%s %s\n" "$msg_error" "$err"
+ return $retval
+ fi
+ f_show_msg "$msg_group_deleted"
+ ;;
+ Add)
+ local cmd="pw groupadd -n '$group_name'"
+ [ "$group_gid" ] && cmd="$cmd -g '$group_gid'"
+ [ "$group_members" != "$cur_group_members" ] &&
+ cmd="$cmd -M '$group_members'"
+ if [ "$pw_group_password_disable" ]; then
+ cmd="$cmd -h -"
+ elif [ "$group_password" ]; then
+ cmd="echo \"\$group_password\" | $cmd -h 0"
+ fi
+ f_dprintf "cmd=$cmd"
+ err=$( eval $cmd 2>&1 )
+ retval=$?
+ if [ $retval -ne $SUCCESS ]; then
+ f_show_msg "%s %s\n" "$msg_error" "$err"
+ return $retval
+ fi
+ f_show_msg "$msg_group_added"
+ ;;
+ Edit/View)
+ local cmd="pw groupmod -n '$group_name'"
+ [ "$group_gid" ] && cmd="$cmd -g '$group_gid'"
+ [ "$group_members" != "$cur_group_members" ] &&
+ cmd="$cmd -M '$group_members'"
+ if [ "$pw_group_password_disable" ]; then
+ cmd="$cmd -h -"
+ elif [ "$group_password" ]; then
+ cmd="echo \"\$group_password\" | $cmd -h 0"
+ fi
+ f_dprintf "cmd=$cmd"
+ err=$( eval $cmd 2>&1 )
+ retval=$?
+ if [ $retval -ne $SUCCESS ]; then
+ f_show_msg "%s %s\n" "$msg_error" "$err"
+ return $retval
+ fi
+ f_show_msg "$msg_group_updated"
+ ;;
+ 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_group" ;;
+ Edit/View) f_dialog_title "$msg_edit_view $msg_group: $group" ;;
+ Delete) f_dialog_title "$msg_delete $msg_group: $group" ;;
+ 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=[$key] value=[$value]"
+ case "$key" in
+ mode) mode="$value";;
+ group) group="$value";;
+ esac
+ shift
+done
+f_dprintf "mode=[$mode] group=[$group]"
+
+#
+# Initialize
+#
+f_dialog_init
+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
+ #
+ # 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 groupmenu.
+ #
+
+ f_dialog_input_group_name || exit 0
+ [ "$passwdtype" = "yes" ] &&
+ { f_dialog_input_group_password || exit 0; }
+ f_dialog_input_group_gid || exit 0
+ f_dialog_input_group_members || exit 0
+fi
+
+if [ "$mode" = "Edit/View" -o "$mode" = "Delete" ]; then
+ f_input_group "$group" || f_die 1 "$msg_group_not_found"
+fi
+
+cur_group_name="$group_name"
+cur_group_password="$group_password"
+cur_group_gid="$group_gid"
+cur_group_members="$group_members"
+
+[ "$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
+
+ case "$mode" in
+ Delete)
+ menu_items="
+ 'X' '$menu_exit'
+ '1' '$msg_group: $group_name'
+ '-' '$msg_password: -----'
+ '-' '$msg_group_id: $group_gid'
+ '-' '$msg_group_members: $group_members'
+ " # END-QUOTE
+ ;;
+ *)
+ menu_items="
+ 'X' '$menu_exit'
+ '1' '$msg_group: $group_name'
+ '2' '$msg_password: -----'
+ '3' '$msg_group_id: $group_gid'
+ '4' '$msg_group_members: $group_members'
+ " # END-QUOTE
+ esac
+
+ size=$( eval f_dialog_menu_size \
+ \"\$DIALOG_TITLE\" \
+ \"\$DIALOG_BACKTITLE\" \
+ \"\$menu_text\" \
+ \"\$hline\" \
+ $menu_items )
+
+ eval $DIALOG \
+ --title \"\$DIALOG_TITLE\" \
+ --backtitle \"\$DIALOG_BACKTITLE\" \
+ --hline \"\$hline\" \
+ --ok-label \"\$msg_ok\" \
+ --cancel-label \"\$msg_cancel\" \
+ --menu \"\$menu_text\" $size \
+ $menu_items \
+ 2> $DIALOG_TMPDIR/dialog.menu.$$
+
+ retval=$?
+ mtag=$( f_dialog_menutag )
+ f_dprintf "retval=$retval mtag=[$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) # Group Name
+ case "$mode" in
+ Add) f_dialog_input_group_name "$group_name" ;;
+ Edit/View|Delete)
+ f_dialog_menu_group_list
+ retval=$?
+ mtag=$( f_dialog_menutag )
+ f_dprintf "retval=$retval mtag=[$mtag]"
+
+ # Loop if user has either pressed ESC or chosen Cancel/No
+ [ $retval -eq $SUCCESS ] || continue
+
+ [ "$mtag" = "X $msg_exit" ] && continue
+
+ group="$mtag"
+ f_input_group "$group" || f_die 1 "$msg_group_not_found"
+ cur_group_name="$group_name"
+ cur_group_password="$group_password"
+ cur_group_gid="$group_gid"
+ cur_group_members="$group_members"
+ [ "$mode" != "Delete" ] && save_flag=
+ esac
+ ;;
+ 2) # Password
+ f_dialog_input_group_password
+ ;;
+ 3) # GID
+ f_dialog_input_group_gid "$group_gid"
+ ;;
+ 4) # Users in Group
+ f_dialog_input_group_members "$group_members"
+ ;;
+ esac
+
+done
+
+exit $SUCCESS
+
+################################################################################
+# END
+################################################################################
OpenPOWER on IntegriCloud