|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# run-shellcheck |
| 4 | +# |
| 5 | +# CIS Debian Hardening |
| 6 | +# |
| 7 | + |
| 8 | +# |
| 9 | +# Ensure GDM disabling of automount is not overridden (Automated) |
| 10 | +# |
| 11 | + |
| 12 | +set -e # One error, it's over |
| 13 | +set -u # One variable unset, it's over |
| 14 | + |
| 15 | +# shellcheck disable=2034 |
| 16 | +HARDENING_LEVEL=2 |
| 17 | +# shellcheck disable=2034 |
| 18 | +DESCRIPTION="Ensure GDM disabling of automount is not overridden." |
| 19 | + |
| 20 | +PACKAGE='gdm3' |
| 21 | +DCONF_PROFILE_DIR='/etc/dconf/profile' |
| 22 | +DCONF_DB_DIR='/etc/dconf/db/local.d' |
| 23 | +DCONF_LOCK_DIR='/etc/dconf/db/local.d/locks' |
| 24 | +USER_PROFILE_FILE="$DCONF_PROFILE_DIR/user" |
| 25 | +AUTOMOUNT_CONF_FILE="$DCONF_DB_DIR/00-media-automount" |
| 26 | +AUTOMOUNT_LOCK_FILE="$DCONF_LOCK_DIR/media-automount" |
| 27 | + |
| 28 | +# Global state |
| 29 | +GDM_AUTOMOUNT_INSTALLED=1 |
| 30 | +GDM_AUTOMOUNT_PROFILE_OK=1 |
| 31 | +GDM_AUTOMOUNT_SETTINGS_OK=1 |
| 32 | +GDM_AUTOMOUNT_LOCKS_OK=1 |
| 33 | + |
| 34 | +# This function will be called if the script status is on enabled / audit mode |
| 35 | +audit() { |
| 36 | + is_pkg_installed "$PACKAGE" |
| 37 | + if [ "$FNRET" != 0 ]; then |
| 38 | + ok "$PACKAGE is not installed, automount settings not applicable" |
| 39 | + GDM_AUTOMOUNT_INSTALLED=0 |
| 40 | + return |
| 41 | + fi |
| 42 | + ok "$PACKAGE is installed" |
| 43 | + |
| 44 | + # Check profile file |
| 45 | + if [ ! -f "$USER_PROFILE_FILE" ]; then |
| 46 | + crit "DConf user profile file $USER_PROFILE_FILE does not exist" |
| 47 | + GDM_AUTOMOUNT_PROFILE_OK=0 |
| 48 | + else |
| 49 | + does_pattern_exist_in_file "$USER_PROFILE_FILE" "user-db:user" |
| 50 | + if [ "$FNRET" != 0 ]; then |
| 51 | + crit "DConf user profile missing 'user-db:user' directive" |
| 52 | + GDM_AUTOMOUNT_PROFILE_OK=0 |
| 53 | + else |
| 54 | + does_pattern_exist_in_file "$USER_PROFILE_FILE" "system-db:local" |
| 55 | + if [ "$FNRET" != 0 ]; then |
| 56 | + crit "DConf user profile missing 'system-db:local' directive" |
| 57 | + GDM_AUTOMOUNT_PROFILE_OK=0 |
| 58 | + else |
| 59 | + ok "DConf user profile correctly configured" |
| 60 | + fi |
| 61 | + fi |
| 62 | + fi |
| 63 | + |
| 64 | + # Check automount settings |
| 65 | + if [ ! -f "$AUTOMOUNT_CONF_FILE" ]; then |
| 66 | + crit "Automount configuration file $AUTOMOUNT_CONF_FILE does not exist" |
| 67 | + GDM_AUTOMOUNT_SETTINGS_OK=0 |
| 68 | + else |
| 69 | + does_pattern_exist_in_file "$AUTOMOUNT_CONF_FILE" "automount=false" |
| 70 | + if [ "$FNRET" != 0 ]; then |
| 71 | + crit "automount not set to false in $AUTOMOUNT_CONF_FILE" |
| 72 | + GDM_AUTOMOUNT_SETTINGS_OK=0 |
| 73 | + else |
| 74 | + ok "automount correctly set to false" |
| 75 | + fi |
| 76 | + does_pattern_exist_in_file "$AUTOMOUNT_CONF_FILE" "automount-open=false" |
| 77 | + if [ "$FNRET" != 0 ]; then |
| 78 | + crit "automount-open not set to false in $AUTOMOUNT_CONF_FILE" |
| 79 | + GDM_AUTOMOUNT_SETTINGS_OK=0 |
| 80 | + else |
| 81 | + ok "automount-open correctly set to false" |
| 82 | + fi |
| 83 | + fi |
| 84 | + |
| 85 | + # Check locks |
| 86 | + if [ ! -f "$AUTOMOUNT_LOCK_FILE" ]; then |
| 87 | + crit "Automount lock file $AUTOMOUNT_LOCK_FILE does not exist" |
| 88 | + GDM_AUTOMOUNT_LOCKS_OK=0 |
| 89 | + else |
| 90 | + does_pattern_exist_in_file "$AUTOMOUNT_LOCK_FILE" "/org/gnome/desktop/media-handling/automount" |
| 91 | + if [ "$FNRET" != 0 ]; then |
| 92 | + crit "automount not locked in $AUTOMOUNT_LOCK_FILE" |
| 93 | + GDM_AUTOMOUNT_LOCKS_OK=0 |
| 94 | + else |
| 95 | + ok "automount is locked" |
| 96 | + fi |
| 97 | + does_pattern_exist_in_file "$AUTOMOUNT_LOCK_FILE" "/org/gnome/desktop/media-handling/automount-open" |
| 98 | + if [ "$FNRET" != 0 ]; then |
| 99 | + crit "automount-open not locked in $AUTOMOUNT_LOCK_FILE" |
| 100 | + GDM_AUTOMOUNT_LOCKS_OK=0 |
| 101 | + else |
| 102 | + ok "automount-open is locked" |
| 103 | + fi |
| 104 | + fi |
| 105 | +} |
| 106 | + |
| 107 | +# This function will be called if the script status is on enabled mode |
| 108 | +apply() { |
| 109 | + if [ "$GDM_AUTOMOUNT_INSTALLED" -eq 0 ]; then |
| 110 | + ok "$PACKAGE is not installed, nothing to apply" |
| 111 | + return |
| 112 | + fi |
| 113 | + |
| 114 | + # Create profile directory and file |
| 115 | + if [ "$GDM_AUTOMOUNT_PROFILE_OK" -eq 0 ]; then |
| 116 | + info "Creating/updating DConf user profile" |
| 117 | + mkdir -p "$DCONF_PROFILE_DIR" |
| 118 | + cat >"$USER_PROFILE_FILE" <<EOF |
| 119 | +user-db:user |
| 120 | +system-db:local |
| 121 | +EOF |
| 122 | + GDM_AUTOMOUNT_PROFILE_OK=1 |
| 123 | + fi |
| 124 | + |
| 125 | + # Create automount settings |
| 126 | + if [ "$GDM_AUTOMOUNT_SETTINGS_OK" -eq 0 ]; then |
| 127 | + info "Creating automount configuration" |
| 128 | + mkdir -p "$DCONF_DB_DIR" |
| 129 | + cat >"$AUTOMOUNT_CONF_FILE" <<EOF |
| 130 | +[org/gnome/desktop/media-handling] |
| 131 | +automount=false |
| 132 | +automount-open=false |
| 133 | +EOF |
| 134 | + GDM_AUTOMOUNT_SETTINGS_OK=1 |
| 135 | + fi |
| 136 | + |
| 137 | + # Create locks |
| 138 | + if [ "$GDM_AUTOMOUNT_LOCKS_OK" -eq 0 ]; then |
| 139 | + info "Creating automount locks" |
| 140 | + mkdir -p "$DCONF_LOCK_DIR" |
| 141 | + cat >"$AUTOMOUNT_LOCK_FILE" <<EOF |
| 142 | +/org/gnome/desktop/media-handling/automount |
| 143 | +/org/gnome/desktop/media-handling/automount-open |
| 144 | +EOF |
| 145 | + GDM_AUTOMOUNT_LOCKS_OK=1 |
| 146 | + fi |
| 147 | + |
| 148 | + # Update dconf database |
| 149 | + if command -v dconf >/dev/null 2>&1; then |
| 150 | + info "Updating dconf database" |
| 151 | + dconf update |
| 152 | + fi |
| 153 | +} |
| 154 | + |
| 155 | +# This function will check config parameters required |
| 156 | +check_config() { |
| 157 | + : |
| 158 | +} |
| 159 | + |
| 160 | +# Source Root Dir Parameter |
| 161 | +if [ -r /etc/default/cis-hardening ]; then |
| 162 | + # shellcheck source=../../debian/default |
| 163 | + . /etc/default/cis-hardening |
| 164 | +fi |
| 165 | +if [ -z "${CIS_LIB_DIR}" ]; then |
| 166 | + echo "There is no /etc/default/cis-hardening file nor cis-hardening directory in current environment." |
| 167 | + echo "Cannot source CIS_LIB_DIR variable, aborting." |
| 168 | + exit 128 |
| 169 | +fi |
| 170 | + |
| 171 | +# Main function, will call the proper functions given the configuration (audit, enabled, disabled) |
| 172 | +if [ -r "${CIS_LIB_DIR}"/main.sh ]; then |
| 173 | + # shellcheck source=../../lib/main.sh |
| 174 | + . "${CIS_LIB_DIR}"/main.sh |
| 175 | +else |
| 176 | + echo "Cannot find main.sh, have you correctly defined your root directory? Current value is ${CIS_LIB_DIR} in /etc/default/cis-hardening" |
| 177 | + exit 128 |
| 178 | +fi |
0 commit comments