3 # Copyright (c) 2012-2013 Devin Teske
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 ############################################################ INCLUDES
31 BSDCFG_SHARE="/usr/share/bsdconfig"
32 . $BSDCFG_SHARE/common.subr || exit 1
33 f_dprintf "%s: loading includes..." "$0"
34 f_include $BSDCFG_SHARE/dialog.subr
35 f_include $BSDCFG_SHARE/mustberoot.subr
36 f_include $BSDCFG_SHARE/sysrc.subr
38 BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="130.security"
39 f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
41 f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
44 ############################################################ FUNCTIONS
48 # Display the dialog(1)-based application main menu.
52 local prompt="$msg_menu_text"
54 'X $msg_exit' '$msg_exit_this_menu'
56 local defaultitem= # Calculated below
57 local hline="$hline_arrows_tab_enter"
59 # Obtain default-item (adjusted below for dynamic tags)
60 f_dialog_default_fetch defaultitem
61 local ditem="${defaultitem%%[$IFS]*}"
64 # Add dynamically tagged entry for kern_securelevels
67 case "$( f_sysrc_get kern_securelevel_enable )" in
69 local kern_securelevel="$( f_sysrc_get kern_securelevel )"
70 if [ ${#kern_securelevel} -eq 1 ] &&
71 f_isinteger "$kern_securelevel" &&
72 [ $kern_securelevel -lt 9 ]
74 mark="$kern_securelevel"
82 '2 [$mark] $msg_securelevel' '$msg_securelevel_desc'"
84 # Update default-item if appropriate
85 [ "$ditem" = 2 ] && defaultitem="2 [$mark] $msg_securelevel"
88 # Add dynamically tagged entry for nfs_reserved_port_only
90 case "$( f_sysrc_get nfs_reserved_port_only )" in
91 [Yy][Ee][Ss]) mark="X" ;;
95 '3 [$mark] $msg_nfs_port' '$msg_nfs_port_desc'"
97 # Update default-item if appropriate
98 [ "$ditem" = 3 ] && defaultitem="3 [$mark] $msg_nfs_port"
100 local height width rows
101 eval f_dialog_menu_size height width rows \
103 \"\$DIALOG_BACKTITLE\" \
109 menu_choice=$( eval $DIALOG \
110 --title \"\$DIALOG_TITLE\" \
111 --backtitle \"\$DIALOG_BACKTITLE\" \
112 --hline \"\$hline\" \
113 --ok-label \"\$msg_ok\" \
114 --cancel-label \"\$msg_cancel\" \
115 --default-item \"\$defaultitem\" \
116 --menu \"\$prompt\" \
117 $height $width $rows \
119 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
122 f_dialog_data_sanitize menu_choice
123 f_dialog_menutag_store "$menu_choice"
125 # Only update default-item on success
126 [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice"
131 ############################################################ MAIN
133 # Incorporate rc-file if it exists
134 [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
137 # Process command-line arguments
139 while getopts h$GETOPTS_STDARGS flag; do
141 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
144 shift $(( $OPTIND - 1 ))
149 f_dialog_title "$msg_system_security_options_menu"
150 f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
154 # Launch application main menu (loop for menu update after selection)
157 dialog_menu_main || f_die
158 f_dialog_menutag_fetch mtag
161 "X $msg_exit") break ;;
162 "2 ["?"] $msg_securelevel") # Configure securelevels for the system
163 $BSDCFG_LIBE/$APP_DIR/kern_securelevel ${USE_XDIALOG:+-X} ;;
164 "3 [X] $msg_nfs_port") # Require that NFS clients use reserved ports
165 f_eval_catch "$0" f_sysrc_set \
166 'f_sysrc_set nfs_reserved_port_only NO' ;;
167 "3 [ ] $msg_nfs_port") # Same; Toggle value
168 f_eval_catch "$0" f_sysrc_set \
169 'f_sysrc_set nfs_reserved_port_only YES' ;;
171 f_die 1 "$msg_unknown_security_menu_selection"
177 ################################################################################
179 ################################################################################