From 24a0dde01d3b64d36773e06eeb300d94992b2886 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Fri, 8 Mar 2013 19:29:38 +0100 Subject: Pass only single commands through su wrapper It is a healthy coding practice to keep each argument separate when executing system calls, i.e. quote each variable separately instead of relying on whitespace to indicate argument separation. Quoting shell-inside-shell is tricky to do right, and gets trickier when more than a single command is wrapped together. This patch simplifies convoluted shell calls to contain only one command each. --- Makefile | 2 ++ src/share/list_primary_fingerprints | 5 +++++ src/share/ma/add_certifier | 2 +- src/share/ma/update_users | 2 +- src/share/mh/add_revoker | 2 +- src/share/process_authorized_user_ids | 8 ++++++++ 6 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 src/share/list_primary_fingerprints create mode 100644 src/share/process_authorized_user_ids diff --git a/Makefile b/Makefile index d281bcb..322a79d 100755 --- a/Makefile +++ b/Makefile @@ -50,6 +50,8 @@ install: all installman install src/monkeysphere-authentication-keys-for-user $(DESTDIR)$(PREFIX)/share/monkeysphere install -m 0644 src/share/common $(DESTDIR)$(PREFIX)/share/monkeysphere install -m 0644 src/share/defaultenv $(DESTDIR)$(PREFIX)/share/monkeysphere + install -m 0644 src/share/list_primary_fingerprints $(DESTDIR)$(PREFIX)/share/monkeysphere + install -m 0644 src/share/process_authorized_user_ids $(DESTDIR)$(PREFIX)/share/monkeysphere sed -i 's:__SYSCONFDIR_PREFIX__:$(ETCPREFIX):' $(DESTDIR)$(PREFIX)/share/monkeysphere/defaultenv sed -i 's:__SYSDATADIR_PREFIX__:$(LOCALSTATEDIR):' $(DESTDIR)$(PREFIX)/share/monkeysphere/defaultenv install -m 0755 src/share/checkperms $(DESTDIR)$(PREFIX)/share/monkeysphere diff --git a/src/share/list_primary_fingerprints b/src/share/list_primary_fingerprints new file mode 100644 index 0000000..17f299c --- /dev/null +++ b/src/share/list_primary_fingerprints @@ -0,0 +1,5 @@ +# -*-shell-script-*- +# This should be sourced by bash (though we welcome changes to make it POSIX sh compliant) + +. "${SYSSHAREDIR}/common" +list_primary_fingerprints diff --git a/src/share/ma/add_certifier b/src/share/ma/add_certifier index 3ce5000..de8b1d1 100644 --- a/src/share/ma/add_certifier +++ b/src/share/ma/add_certifier @@ -101,7 +101,7 @@ if [ -f "$keyID" -o "$keyID" = '-' ] ; then # check the key is ok as monkeysphere user before loading log debug "checking keys in file..." fingerprint=$(su_monkeysphere_user \ - ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$keyID") + ". ${SYSSHAREDIR}/list_primary_fingerprints" < "$keyID") if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then failure "There was not exactly one gpg key in the file." diff --git a/src/share/ma/update_users b/src/share/ma/update_users index a70d000..1330c8d 100644 --- a/src/share/ma/update_users +++ b/src/share/ma/update_users @@ -79,7 +79,7 @@ for uname in $unames ; do # process authorized_user_ids file, as monkeysphere user su_monkeysphere_user \ - ". ${SYSSHAREDIR}/common; STRICT_MODES='$STRICT_MODES' process_authorized_user_ids -" \ + ". ${SYSSHAREDIR}/process_authorized_user_ids '$STRICT_MODES' -" \ < "$authorizedUserIDs" \ > "$tmpAuthorizedKeys" diff --git a/src/share/mh/add_revoker b/src/share/mh/add_revoker index 41cf090..da6f71e 100644 --- a/src/share/mh/add_revoker +++ b/src/share/mh/add_revoker @@ -52,7 +52,7 @@ if [ -f "$revokerKeyID" -o "$revokerKeyID" = '-' ] ; then # check the key is ok as monkeysphere user before loading log debug "checking keys in file..." fingerprint=$(su_monkeysphere_user \ - ". ${SYSSHAREDIR}/common; list_primary_fingerprints" < "$revokerKeyID") + ". ${SYSSHAREDIR}/list_primary_fingerprints" < "$revokerKeyID") if [ $(printf "%s" "$fingerprint" | egrep -c '^[A-F0-9]{40}$') -ne 1 ] ; then failure "There was not exactly one gpg key in the file." diff --git a/src/share/process_authorized_user_ids b/src/share/process_authorized_user_ids new file mode 100644 index 0000000..71ea0a6 --- /dev/null +++ b/src/share/process_authorized_user_ids @@ -0,0 +1,8 @@ +# -*-shell-script-*- +# This should be sourced by bash (though we welcome changes to make it POSIX sh compliant) + +STRICT_MODES="$1" +shift + +. "${SYSSHAREDIR}/common" +process_authorized_user_ids "$@" -- cgit v1.2.3