]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pam-systemd: use secure_getenv() rather than getenv()
authorLennart Poettering <lennart@poettering.net>
Mon, 4 Feb 2019 09:23:43 +0000 (10:23 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 8 Apr 2019 08:24:03 +0000 (10:24 +0200)
And explain why in a comment.

src/login/pam_systemd.c

index 372ba44874fb12360411a448d241eaab42803037..2bf3b7987e1c4628cc27df8eae382486641eaf8b 100644 (file)
@@ -327,14 +327,21 @@ static const char* getenv_harder(pam_handle_t *handle, const char *key, const ch
         assert(handle);
         assert(key);
 
-        /* Looks for an environment variable, preferrably in the environment block associated with the specified PAM
-         * handle, falling back to the process' block instead. */
+        /* Looks for an environment variable, preferrably in the environment block associated with the
+         * specified PAM handle, falling back to the process' block instead. Why check both? Because we want
+         * to permit configuration of session properties from unit files that invoke PAM services, so that
+         * PAM services don't have to be reworked to set systemd-specific properties, but these properties
+         * can still be set from the unit file Environment= block. */
 
         v = pam_getenv(handle, key);
         if (!isempty(v))
                 return v;
 
-        v = getenv(key);
+        /* We use secure_getenv() here, since we might get loaded into su/sudo, which are SUID. Ideally
+         * they'd clean up the environment before invoking foreign code (such as PAM modules), but alas they
+         * currently don't (to be precise, they clean up the environment they pass to their children, but
+         * not their own environ[]). */
+        v = secure_getenv(key);
         if (!isempty(v))
                 return v;