]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm-setup: follow XDG spec more closely for default config
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Tue, 19 Feb 2019 15:36:23 +0000 (16:36 +0100)
committerStefan Berger <stefanb@us.ibm.com>
Tue, 26 Feb 2019 13:36:10 +0000 (08:36 -0500)
According to the XDG spec,
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html:
"If $XDG_CONFIG_HOME is either not set or empty, a default equal to
$HOME/.config should be used."

This fixes setting up a TPM with libvirt running in a user session.

It works by checking if configuration files are readable in the
directory priority order (XDG_CONFIG_HOME, then HOME, then SYSCONFDIR).

When libvirt is running as a system instance, $HOME isn't set, so it
will fall back on @SYSCONFDIR@ (/etc usually)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
samples/swtpm-localca.in [changed mode: 0644->0755]
src/swtpm_setup/swtpm_setup.sh.in

old mode 100644 (file)
new mode 100755 (executable)
index 08be183..2bb382b
@@ -43,8 +43,23 @@ SETUP_TPM2_F=1
 ALLOW_SIGNING_F=2
 DECRYPTION_F=4
 
-LOCALCA_OPTIONS=${XDG_CONFIG_HOME:-@SYSCONFDIR@}/swtpm-localca.options
-LOCALCA_CONFIG=${XDG_CONFIG_HOME:-@SYSCONFDIR@}/swtpm-localca.conf
+LOCALCA_OPTIONS="swtpm-localca.options"
+if [ -n "$XDG_CONFIG_HOME" ] && [ -r "$XDG_CONFIG_HOME/$LOCALCA_OPTIONS" ]; then
+    LOCALCA_OPTIONS="$XDG_CONFIG_HOME/$LOCALCA_OPTIONS"
+elif [ -n "$HOME" ] && [ -r "$HOME/.config/$LOCALCA_OPTIONS" ]; then
+    LOCALCA_OPTIONS="$HOME/.config/$LOCALCA_OPTIONS"
+else
+    LOCALCA_OPTIONS="@SYSCONFDIR@/$LOCALCA_OPTIONS"
+fi
+
+LOCALCA_CONFIG="swtpm-localca.conf"
+if [ -n "$XDG_CONFIG_HOME" ] && [ -r "$XDG_CONFIG_HOME/$LOCALCA_CONFIG" ]; then
+    LOCALCA_CONFIG="$XDG_CONFIG_HOME/$LOCALCA_CONFIG"
+elif [ -n "$HOME" ] && [ -r "$HOME/.config/$LOCALCA_CONFIG" ]; then
+    LOCALCA_CONFIG="$HOME/.config/$LOCALCA_CONFIG"
+else
+    LOCALCA_CONFIG="@SYSCONFDIR@/$LOCALCA_CONFIG"
+fi
 
 # Default logging goes to stderr
 LOGFILE=""
index 50b367ed0d51f2bbe17c99b4432282953b4f20d6..a2ef47266d7ac3450b0d7b8327b567bc2aef7a92 100755 (executable)
@@ -79,7 +79,15 @@ DEFAULT_OWNER_PASSWORD=ooo
 DEFAULT_SRK_PASSWORD=sss
 
 # default configuration file
-DEFAULT_CONFIG_FILE="${XDG_CONFIG_HOME:-@SYSCONFDIR@}/swtpm_setup.conf"
+SWTPM_SETUP_CONF="swtpm_setup.conf"
+
+if [ -n "$XDG_CONFIG_HOME" ] && [ -r "$XDG_CONFIG_HOME/$SWTPM_SETUP_CONF" ] ; then
+    DEFAULT_CONFIG_FILE="$XDG_CONFIG_HOME/$SWTPM_SETUP_CONF"
+elif [ -n "$HOME" ] && [ -r "$HOME/.config/$SWTPM_SETUP_CONF" ] ; then
+    DEFAULT_CONFIG_FILE="$HOME/.config/$SWTPM_SETUP_CONF"
+else
+    DEFAULT_CONFIG_FILE="@SYSCONFDIR@/$SWTPM_SETUP_CONF"
+fi
 
 #default PCR banks to activate for TPM 2
 DEFAULT_PCR_BANKS="sha1,sha256"