]> granicus.if.org Git - sudo/commitdiff
For PAM authentication, merge the PAM environment with the user
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 30 Mar 2012 16:47:42 +0000 (12:47 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 30 Mar 2012 16:47:42 +0000 (12:47 -0400)
environment in pam_begin_session().

--HG--
branch : 1.7

auth/pam.c
env.c
sudo.h

index 39d658e5d3188fcc88d12d818ea5f0eba6c4d2de..89e9fa99e33be302541d554d4eb157263596114c 100644 (file)
@@ -206,6 +206,9 @@ int
 pam_begin_session(pw)
     struct passwd *pw;
 {
+#ifdef HAVE_PAM_GETENVLIST
+    char **pam_envp;
+#endif
     int status = PAM_SUCCESS;
 
     /*
@@ -237,6 +240,20 @@ pam_begin_session(pw)
      */
     (void) pam_setcred(pamh, PAM_ESTABLISH_CRED);
 
+#ifdef HAVE_PAM_GETENVLIST
+    /*
+     * Update environment based on what is stored in pamh.
+     * If no authentication is done we will only have environment
+     * variables if pam_env is called via session.
+     */
+    if ((pam_envp = pam_getenvlist(pamh)) != NULL) {
+       /* Merge pam env with user env but do not overwrite. */
+       env_merge(pam_envp, FALSE);
+       efree(pam_envp);
+       /* XXX - we leak any duplicates that were in pam_envp */
+    }
+#endif /* HAVE_PAM_GETENVLIST */
+
 #ifndef NO_PAM_SESSION
     status = pam_open_session(pamh, 0);
     if (status != PAM_SUCCESS) {
diff --git a/env.c b/env.c
index 95bd84a81efc4c695c7813428691694d95dab790..962ade147a706f44d707f82e63e33bc8efcab795 100644 (file)
--- a/env.c
+++ b/env.c
@@ -496,6 +496,18 @@ sudo_putenv(str, dupcheck, overwrite)
     }
 }
 
+/*
+ * Merge another environment with our private copy.
+ */
+void
+env_merge(char * const envp[], int overwrite)
+{
+    char * const *ep;
+  
+    for (ep = envp; *ep != NULL; ep++)
+       sudo_putenv(*ep, TRUE, overwrite);
+}
+
 /*
  * Check the env_delete blacklist.
  * Returns TRUE if the variable was found, else false.
diff --git a/sudo.h b/sudo.h
index 19eaeba1decf6aadc0d3cc924c295f228216373d..b106162d45d6b64d86b5d66a4df6cbd523cbce22 100644 (file)
--- a/sudo.h
+++ b/sudo.h
@@ -226,6 +226,7 @@ void remove_timestamp       __P((int));
 /* env.c */
 char **env_get         __P((void));
 void env_init          __P((int lazy));
+void env_merge         __P((char * const envp[], int overwrite));
 void init_envtables    __P((void));
 void insert_env_vars   __P((struct list_member *));
 void read_env_file     __P((const char *, int));