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
28 ############################################################ INCLUDES
30 BSDCFG_SHARE="/usr/share/bsdconfig"
31 . $BSDCFG_SHARE/common.subr || exit 1
32 f_dprintf "%s: loading includes..." "$0"
33 f_include $BSDCFG_SHARE/dialog.subr
34 f_include $BSDCFG_SHARE/mustberoot.subr
35 f_include $BSDCFG_SHARE/sysrc.subr
37 BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="130.security"
38 f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr
40 SECURELEVEL_HELPFILE=$BSDCFG_LIBE/$APP_DIR/include/securelevel.hlp
42 f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ipgm &&
45 ############################################################ FUNCTIONS
49 # Display the dialog(1)-based application main menu.
53 local prompt="$msg_securelevels_menu_text"
55 '$msg_disabled' '$msg_disable_securelevels'
56 '$msg_secure' '$msg_secure_mode'
57 '$msg_highly_secure' '$msg_highly_secure_mode'
58 '$msg_network_secure' '$msg_network_secure_mode'
60 local defaultitem= # Calculated below
61 local hline="$hline_select_securelevel_to_operate_at"
63 local height width rows
64 eval f_dialog_menu_size height width rows \
66 \"\$DIALOG_BACKTITLE\" \
71 case "$( f_sysrc_get kern_securelevel_enable )" in
72 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
73 case "$( f_sysrc_get kern_securelevel )" in
74 1) defaultitem="$msg_secure" ;;
75 2) defaultitem="$msg_highly_secure" ;;
76 3) defaultitem="$msg_network_secure" ;;
79 defaultitem="$msg_disabled"
83 menu_choice=$( eval $DIALOG \
84 --title \"\$DIALOG_TITLE\" \
85 --backtitle \"\$DIALOG_BACKTITLE\" \
87 --ok-label \"\$msg_ok\" \
88 --cancel-label \"\$msg_cancel\" \
90 --help-label \"\$msg_help\" \
91 ${USE_XDIALOG:+--help \"\"} \
92 --default-item \"\$defaultitem\" \
94 $height $width $rows \
96 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
99 f_dialog_menutag_store -s "$menu_choice"
103 ############################################################ MAIN
105 # Incorporate rc-file if it exists
106 [ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc"
109 # Process command-line arguments
111 while getopts h$GETOPTS_STDARGS flag; do
113 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm" ;;
116 shift $(( $OPTIND - 1 ))
121 f_dialog_title "$msg_securelevels_menu_title"
122 f_dialog_backtitle "${ipgm:+bsdconfig }$pgm"
126 # Launch application main menu (loop for additional `Help' button)
131 f_dialog_menutag_fetch mtag
133 if [ $retval -eq $DIALOG_HELP ]; then
134 f_show_help "$SECURELEVEL_HELPFILE"
136 elif [ $retval -ne $DIALOG_OK ]; then
145 f_eval_catch "$0" f_sysrc_set \
146 'f_sysrc_set kern_securelevel_enable NO' || f_die
149 f_eval_catch "$0" f_sysrc_set \
150 'f_sysrc_set kern_securelevel_enable YES' || f_die
151 f_eval_catch "$0" f_sysrc_set \
152 'f_sysrc_set kern_securelevel 1' || f_die
154 "$msg_highly_secure")
155 f_eval_catch "$0" f_sysrc_set \
156 'f_sysrc_set kern_securelevel_enable YES' || f_die
157 f_eval_catch "$0" f_sysrc_set \
158 'f_sysrc_set kern_securelevel 2' || f_die
160 "$msg_network_secure")
161 f_eval_catch "$0" f_sysrc_set \
162 'f_sysrc_set kern_securelevel_enable YES' || f_die
163 f_eval_catch "$0" f_sysrc_set \
164 'f_sysrc_set kern_securelevel 3' || f_die
167 f_die 1 "$msg_unknown_kern_securelevel_selection"
172 ################################################################################
174 ################################################################################