@@ -10,16 +10,16 @@ set -o pipefail
1010shopt -s nullglob
1111
1212run_cmd () {
13- echo " INFO: normal executing : $@ "
13+ printf ' %s\n ' " INFO: normal executing : $@ "
1414 " $@ "
1515}
1616
1717run_cmd_whitelist () {
18- echo " INFO: whitelist executing: $@ "
18+ printf ' %s\n ' " INFO: whitelist executing: $@ "
1919 " $@ "
2020}
2121
22- echo " $0 : INFO: START"
22+ printf ' %s\n ' " $0 : INFO: START"
2323
2424default_variables_set () {
2525 sysfs_whitelist=1
@@ -33,7 +33,7 @@ parse_configuration() {
3333 # # Allows for disabling the whitelist.
3434 local i
3535 for i in /usr/local/etc/hide-hardware-info.d/* .conf /etc/hide-hardware-info.d/* .conf ; do
36- bash -n " ${i} "
36+ bash -n -- " ${i} "
3737 source " ${i} "
3838 done
3939}
@@ -44,19 +44,19 @@ create_whitelist() {
4444 elif [ " ${1} " = " cpuinfo" ]; then
4545 whitelist_path=" /proc/cpuinfo"
4646 else
47- echo " ERROR: ${1} is not a correct parameter."
47+ printf ' %s\n ' " ERROR: ${1} is not a correct parameter."
4848 exit 1
4949 fi
5050
51- if grep -q " ${1} " /etc/group ; then
51+ if getent group -- " ${1} " > /dev/null ; then
5252 # # Changing the permissions of /sys recursively
5353 # # causes errors as the permissions of /sys/kernel/debug
5454 # # and /sys/fs/cgroup cannot be changed.
55- run_cmd_whitelist chgrp --quiet --recursive " ${1} " " ${whitelist_path} " || true
55+ run_cmd_whitelist chgrp --quiet --recursive -- " ${1} " " ${whitelist_path} " || true
5656
57- run_cmd_whitelist chmod o-rwx " ${whitelist_path} "
57+ run_cmd_whitelist chmod -- o-rwx " ${whitelist_path} "
5858 else
59- echo " ERROR: The ${1} group does not exist, the ${1} whitelist was not created."
59+ printf ' %s\n ' " ERROR: The ${1} group does not exist, the ${1} whitelist was not created."
6060 fi
6161}
6262
@@ -78,25 +78,25 @@ for i in /proc/cpuinfo /proc/bus /proc/scsi /sys ; do
7878 if [ " ${sysfs_whitelist} " = " 1" ]; then
7979 create_whitelist sysfs
8080 else
81- echo " INFO: The sysfs whitelist is not enabled. Some things may not work properly. Full sysfs hardening..."
82- run_cmd chmod og-rwx /sys
81+ printf ' %s\n ' " INFO: The sysfs whitelist is not enabled. Some things may not work properly. Full sysfs hardening..."
82+ run_cmd chmod -- og-rwx /sys
8383 fi
8484 fi
8585 elif [ " ${i} " = " /proc/cpuinfo" ]; then
8686 if [ " ${cpuinfo_whitelist} " = " 1" ]; then
8787 create_whitelist cpuinfo
8888 else
89- echo " INFO: The cpuinfo whitelist is not enabled. Some things may not work properly. Full cpuinfo hardening..."
90- run_cmd chmod og-rwx /proc/cpuinfo
89+ printf ' %s\n ' " INFO: The cpuinfo whitelist is not enabled. Some things may not work properly. Full cpuinfo hardening..."
90+ run_cmd chmod -- og-rwx /proc/cpuinfo
9191 fi
9292 else
93- run_cmd chmod og-rwx " ${i} "
93+ run_cmd chmod -- og-rwx " ${i} "
9494 fi
9595 else
9696 # # /proc/scsi doesn't exist on Debian so errors
9797 # # are expected here.
9898 if ! [ " ${i} " = " /proc/scsi" ]; then
99- echo " ERROR: ${i} could not be found."
99+ printf ' %s\n ' " ERROR: ${i} could not be found."
100100 fi
101101 fi
102102done
@@ -109,30 +109,30 @@ if [ "${sysfs}" = "1" ]; then
109109 # # Using '|| true':
110110 # # https://github.com/Kicksecure/security-misc/pull/108
111111 if [ " ${sysfs_whitelist} " = " 1" ]; then
112- run_cmd chmod o-rwx " ${i} " || true
112+ run_cmd chmod -- o-rwx " ${i} " || true
113113 else
114- run_cmd chmod og-rwx " ${i} " || true
114+ run_cmd chmod -- og-rwx " ${i} " || true
115115 fi
116116 done
117117
118118 # # polkit needs stat access to /sys/fs/cgroup
119119 # # to function properly
120- run_cmd chmod o+rx /sys /sys/fs
120+ run_cmd chmod -- o+rx /sys /sys/fs
121121
122122 # # on SELinux systems, at least /sys/fs/selinux
123123 # # must be visible to unprivileged users, else
124124 # # SELinux userspace utilities will not function
125125 # # properly
126126 if [ -d /sys/fs/selinux ]; then
127- echo " INFO: SELinux detected because folder /sys/fs/selinux exists. See also:"
128- echo " https://www.kicksecure.com/wiki/Security-misc#selinux"
127+ printf ' %s\n ' " INFO: SELinux detected because folder /sys/fs/selinux exists. See also:"
128+ printf ' %s\n ' " https://www.kicksecure.com/wiki/Security-misc#selinux"
129129 if [ " ${selinux} " = " 1" ]; then
130- run_cmd chmod o+rx /sys /sys/fs /sys/fs/selinux
131- echo " INFO: SELinux mode enabled. Restrictions loosened slightly in order to allow userspace utilities to function."
130+ run_cmd chmod -- o+rx /sys /sys/fs /sys/fs/selinux
131+ printf ' %s\n ' " INFO: SELinux mode enabled. Restrictions loosened slightly in order to allow userspace utilities to function."
132132 else
133- echo " INFO: SELinux detected, but SELinux mode is not enabled. Some userspace utilities may not work properly."
133+ printf ' %s\n ' " INFO: SELinux detected, but SELinux mode is not enabled. Some userspace utilities may not work properly."
134134 fi
135135 fi
136136fi
137137
138- echo " $0 : INFO: END"
138+ printf ' %s\n ' " $0 : INFO: END"
0 commit comments