~ubuntu-branches/ubuntu/raring/sudo/raring

« back to all changes in this revision

Viewing changes to debian/patches/pam_env_merge.patch

  • Committer: Steve Langasek
  • Date: 2012-05-23 06:03:22 UTC
  • Revision ID: steve.langasek@canonical.com-20120523060322-onx1jw1e1twvbdf2
Tags: 1.8.3p2-1ubuntu2
* debian/patches/pam_env_merge.patch: Merge the PAM environment into the
  user environment (LP: #982684)
* debian/sudo.pam: Use pam_env to read /etc/environment and
  /etc/default/locale environment files. Reading ~/.pam_environment is not
  permitted due to security reasons.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: Merge the PAM environment into the user environment
 
2
 Variables unique to the PAM environment are merged into the user
 
3
 environment. None of the user's environment is overwritten.
 
4
Origin: backport, http://www.sudo.ws/repos/sudo/rev/15abe30f755d
 
5
Origin: backport, http://www.sudo.ws/repos/sudo/rev/3319c6cce1e7
 
6
Origin: backport, http://www.sudo.ws/repos/sudo/rev/078bee18fec1
 
7
 
 
8
Index: sudo-1.8.3p1/config.h.in
 
9
===================================================================
 
10
--- sudo-1.8.3p1.orig/config.h.in       2012-05-17 13:28:18.805606789 -0500
 
11
+++ sudo-1.8.3p1/config.h.in    2012-05-17 13:28:25.245638726 -0500
 
12
@@ -377,6 +377,9 @@
 
13
 /* Define to 1 if you use PAM authentication. */
 
14
 #undef HAVE_PAM
 
15
 
 
16
+/* Define to 1 if you have the `pam_getenvlist' function. */
 
17
+#undef HAVE_PAM_GETENVLIST
 
18
+
 
19
 /* Define to 1 if you use a specific PAM session for sudo -i. */
 
20
 #undef HAVE_PAM_LOGIN
 
21
 
 
22
Index: sudo-1.8.3p1/configure
 
23
===================================================================
 
24
--- sudo-1.8.3p1.orig/configure 2012-05-17 13:28:18.817606850 -0500
 
25
+++ sudo-1.8.3p1/configure      2012-05-17 13:28:25.257638788 -0500
 
26
@@ -17899,6 +17899,21 @@
 
27
 done
 
28
 
 
29
     if test "$with_pam" = "yes"; then
 
30
+       # Older PAM implementations lack pam_getenvlist
 
31
+       OLIBS="$LIBS"
 
32
+       LIBS="$LIBS -lpam $lt_cv_dlopen_libs"
 
33
+       for ac_func in pam_getenvlist
 
34
+do :
 
35
+  ac_fn_c_check_func "$LINENO" "pam_getenvlist" "ac_cv_func_pam_getenvlist"
 
36
+if test "x$ac_cv_func_pam_getenvlist" = xyes; then :
 
37
+  cat >>confdefs.h <<_ACEOF
 
38
+#define HAVE_PAM_GETENVLIST 1
 
39
+_ACEOF
 
40
+
 
41
+fi
 
42
+done
 
43
+
 
44
+       LIBS="$OLIBS"
 
45
        $as_echo "#define HAVE_PAM 1" >>confdefs.h
 
46
 
 
47
        AUTH_OBJS="$AUTH_OBJS pam.lo";
 
48
Index: sudo-1.8.3p1/configure.in
 
49
===================================================================
 
50
--- sudo-1.8.3p1.orig/configure.in      2012-05-17 13:28:18.741606474 -0500
 
51
+++ sudo-1.8.3p1/configure.in   2012-05-17 13:28:25.265638824 -0500
 
52
@@ -2365,6 +2365,11 @@
 
53
     dnl
 
54
     AC_CHECK_HEADERS([security/pam_appl.h] [pam/pam_appl.h], [with_pam=yes; break])
 
55
     if test "$with_pam" = "yes"; then
 
56
+       # Older PAM implementations lack pam_getenvlist
 
57
+       OLIBS="$LIBS"
 
58
+       LIBS="$LIBS -lpam $lt_cv_dlopen_libs"
 
59
+       AC_CHECK_FUNCS(pam_getenvlist)
 
60
+       LIBS="$OLIBS"
 
61
        AC_DEFINE(HAVE_PAM)
 
62
        AUTH_OBJS="$AUTH_OBJS pam.lo";
 
63
        AUTH_EXCL=PAM
 
64
Index: sudo-1.8.3p1/plugins/sudoers/sudoers.c
 
65
===================================================================
 
66
--- sudo-1.8.3p1.orig/plugins/sudoers/sudoers.c 2012-05-17 13:28:18.789606714 -0500
 
67
+++ sudo-1.8.3p1/plugins/sudoers/sudoers.c      2012-05-17 13:28:25.269638848 -0500
 
68
@@ -582,7 +582,7 @@
 
69
            NewArgv[1] = "--login";
 
70
        }
 
71
 
 
72
-#if defined(__linux__) || defined(_AIX)
 
73
+#if defined(_AIX) || (defined(__linux__) && !defined(HAVE_PAM))
 
74
        /* Insert system-wide environment variables. */
 
75
        read_env_file(_PATH_ENVIRONMENT, TRUE);
 
76
 #endif
 
77
Index: sudo-1.8.3p1/plugins/sudoers/auth/pam.c
 
78
===================================================================
 
79
--- sudo-1.8.3p1.orig/plugins/sudoers/auth/pam.c        2012-05-17 13:28:18.761606572 -0500
 
80
+++ sudo-1.8.3p1/plugins/sudoers/auth/pam.c     2012-05-17 13:28:25.269638848 -0500
 
81
@@ -195,6 +195,9 @@
 
82
 int
 
83
 pam_begin_session(struct passwd *pw, sudo_auth *auth)
 
84
 {
 
85
+#ifdef HAVE_PAM_GETENVLIST
 
86
+    char **pam_envp;
 
87
+#endif
 
88
     int status = PAM_SUCCESS;
 
89
 
 
90
     /*
 
91
@@ -226,6 +229,20 @@
 
92
      */
 
93
     (void) pam_setcred(pamh, PAM_ESTABLISH_CRED);
 
94
 
 
95
+#ifdef HAVE_PAM_GETENVLIST
 
96
+    /*
 
97
+     * Update environment based on what is stored in pamh.
 
98
+     * If no authentication is done we will only have environment
 
99
+     * variables if pam_env is called via session.
 
100
+     */
 
101
+    if ((pam_envp = pam_getenvlist(pamh)) != NULL) {
 
102
+       /* Merge pam env with user env but do not overwrite. */
 
103
+       env_merge(pam_envp, FALSE);
 
104
+       efree(pam_envp);
 
105
+       /* XXX - we leak any duplicates that were in pam_envp */
 
106
+    }
 
107
+#endif /* HAVE_PAM_GETENVLIST */
 
108
+
 
109
 #ifndef NO_PAM_SESSION
 
110
     status = pam_open_session(pamh, 0);
 
111
     if (status != PAM_SUCCESS) {
 
112
Index: sudo-1.8.3p1/plugins/sudoers/env.c
 
113
===================================================================
 
114
--- sudo-1.8.3p1.orig/plugins/sudoers/env.c     2012-05-17 13:28:18.749606510 -0500
 
115
+++ sudo-1.8.3p1/plugins/sudoers/env.c  2012-05-17 13:28:25.273638863 -0500
 
116
@@ -323,6 +323,18 @@
 
117
 }
 
118
 
 
119
 /*
 
120
+ * Merge another environment with our private copy.
 
121
+ */
 
122
+void
 
123
+env_merge(char * const envp[], int overwrite)
 
124
+{
 
125
+    char * const *ep;
 
126
 
127
+    for (ep = envp; *ep != NULL; ep++)
 
128
+       sudo_putenv(*ep, TRUE, overwrite);
 
129
+}
 
130
+
 
131
+/*
 
132
  * Check the env_delete blacklist.
 
133
  * Returns TRUE if the variable was found, else false.
 
134
  */
 
135
Index: sudo-1.8.3p1/plugins/sudoers/sudoers.h
 
136
===================================================================
 
137
--- sudo-1.8.3p1.orig/plugins/sudoers/sudoers.h 2012-05-17 13:28:18.777606649 -0500
 
138
+++ sudo-1.8.3p1/plugins/sudoers/sudoers.h      2012-05-17 13:28:25.273638863 -0500
 
139
@@ -303,6 +303,7 @@
 
140
 /* env.c */
 
141
 char **env_get(void);
 
142
 void env_init(char * const envp[]);
 
143
+void env_merge(char * const envp[], int overwrite);
 
144
 void init_envtables(void);
 
145
 void insert_env_vars(char * const envp[]);
 
146
 void read_env_file(const char *, int);