]> git.proxmox.com Git - swtpm.git/commitdiff
samples: Require --root flag if root user runs script
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Wed, 28 Oct 2020 01:17:39 +0000 (21:17 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Wed, 28 Oct 2020 12:32:50 +0000 (08:32 -0400)
Since the config files created by the swtpm-create-user-config-files
script will shadow those typically installed in /etc, we now require the
option --root if 'root' runs this script so that root is aware what he is
doing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
samples/swtpm-create-user-config-files.in

index f8469a6663c9f3d29b532c67a498706fe8624d13..b86a4b7a900adca16b0ba99ed332fe795538fdc0 100755 (executable)
@@ -12,6 +12,7 @@ SWTPM_LOCALCA_CONF="${XDG_CONFIG_HOME}/swtpm-localca.conf"
 SWTPM_LOCALCA_OPTIONS="${XDG_CONFIG_HOME}/swtpm-localca.options"
 
 FLAG_OVERWRITE=1
+FLAG_ROOT=2
 
 function help() {
        cat <<_EOF_
@@ -20,6 +21,9 @@ Usage: $1 [options]
 The following options are supported:
 --overwrite    : Overwrite existing config files
 
+--root          : Allow the installation of the config files under the root account.
+                  This will shadow the default configuration files under @SYSCONFDIR@.
+
 --help|-h|-?   : Display this help screen and exit
 
 _EOF_
@@ -31,12 +35,21 @@ function main() {
        while [ $# -ne 0 ]; do
                case "$1" in
                --overwrite) flags=$((flags | FLAG_OVERWRITE));;
+               --root) flags=$((flags | FLAG_ROOT));;
                --help|-h|-?) help $0; exit 0;;
                *) echo -e "Unknown option $1\n" >&2; help $0; exit 1;;
                esac
                shift
        done
 
+       if [ "$(id -u)" = "0" ]; then
+               if [[ $((flags & FLAG_ROOT)) -eq 0 ]]; then
+                       echo "Requiring the --root flag since the configuration files will shadow"
+                       echo "those in @SYSCONFDIR@."
+                       exit 1
+               fi
+       fi
+
        if [[ $((flags & FLAG_OVERWRITE)) -eq 0 ]]; then
                for f in "${SWTPM_SETUP_CONF}" \
                        "${SWTPM_LOCALCA_CONF}" \