| 1 |
From: Sam Hartman <[email protected]> |
| 2 |
Date: Mon, 11 Sep 2023 14:00:42 -0600 |
| 3 |
Subject: _pam_wheel_getlogin_considered_harmful |
| 4 |
|
| 5 |
Patch for Debian bug #163787 et al |
| 6 |
|
| 7 |
Always use the process uid, not getlogin(), to identify an applicant in |
| 8 |
pam_wheel; utmp may be wrong or may have no entry at all in the case of |
| 9 |
an xterm |
| 10 |
|
| 11 |
Authors: Ben Collins <[email protected]> |
| 12 |
|
| 13 |
Upstream status: submitted in <[email protected]> |
| 14 |
--- |
| 15 |
modules/pam_wheel/pam_wheel.8.xml | 17 +-------------- |
| 16 |
modules/pam_wheel/pam_wheel.c | 45 ++++++++------------------------------- |
| 17 |
2 files changed, 10 insertions(+), 52 deletions(-) |
| 18 |
|
| 19 |
diff --git a/modules/pam_wheel/pam_wheel.8.xml b/modules/pam_wheel/pam_wheel.8.xml |
| 20 |
index af0fd61..b42e27d 100644 |
| 21 |
--- a/modules/pam_wheel/pam_wheel.8.xml |
| 22 |
+++ b/modules/pam_wheel/pam_wheel.8.xml |
| 23 |
@@ -30,9 +30,6 @@ |
| 24 |
<arg choice="opt" rep="norepeat"> |
| 25 |
trust |
| 26 |
</arg> |
| 27 |
- <arg choice="opt" rep="norepeat"> |
| 28 |
- use_uid |
| 29 |
- </arg> |
| 30 |
</cmdsynopsis> |
| 31 |
</refsynopsisdiv> |
| 32 |
|
| 33 |
@@ -113,18 +110,6 @@ |
| 34 |
</para> |
| 35 |
</listitem> |
| 36 |
</varlistentry> |
| 37 |
- <varlistentry> |
| 38 |
- <term> |
| 39 |
- use_uid |
| 40 |
- </term> |
| 41 |
- <listitem> |
| 42 |
- <para> |
| 43 |
- The check will be done against the real uid of the calling process, |
| 44 |
- instead of trying to obtain the user from the login session |
| 45 |
- associated with the terminal in use. |
| 46 |
- </para> |
| 47 |
- </listitem> |
| 48 |
- </varlistentry> |
| 49 |
</variablelist> |
| 50 |
</refsect1> |
| 51 |
|
| 52 |
@@ -237,4 +222,4 @@ su auth required pam_unix.so |
| 53 |
</para> |
| 54 |
</refsect1> |
| 55 |
|
| 56 |
-</refentry> |
| 57 |
\ No newline at end of file |
| 58 |
+</refentry> |
| 59 |
diff --git a/modules/pam_wheel/pam_wheel.c b/modules/pam_wheel/pam_wheel.c |
| 60 |
index dd047af..93000ce 100644 |
| 61 |
--- a/modules/pam_wheel/pam_wheel.c |
| 62 |
+++ b/modules/pam_wheel/pam_wheel.c |
| 63 |
@@ -47,9 +47,8 @@ |
| 64 |
/* argument parsing */ |
| 65 |
|
| 66 |
#define PAM_DEBUG_ARG 0x0001 |
| 67 |
-#define PAM_USE_UID_ARG 0x0002 |
| 68 |
-#define PAM_TRUST_ARG 0x0004 |
| 69 |
-#define PAM_DENY_ARG 0x0010 |
| 70 |
+#define PAM_TRUST_ARG 0x0002 |
| 71 |
+#define PAM_DENY_ARG 0x0004 |
| 72 |
#define PAM_ROOT_ONLY_ARG 0x0020 |
| 73 |
|
| 74 |
static int |
| 75 |
@@ -68,8 +67,7 @@ _pam_parse (const pam_handle_t *pamh, int argc, const char **argv, |
| 76 |
|
| 77 |
if (!strcmp(*argv,"debug")) |
| 78 |
ctrl |= PAM_DEBUG_ARG; |
| 79 |
- else if (!strcmp(*argv,"use_uid")) |
| 80 |
- ctrl |= PAM_USE_UID_ARG; |
| 81 |
+ else if (!strcmp(*argv,"use_uid")); /* ignored for compat. */ |
| 82 |
else if (!strcmp(*argv,"trust")) |
| 83 |
ctrl |= PAM_TRUST_ARG; |
| 84 |
else if (!strcmp(*argv,"deny")) |
| 85 |
@@ -118,39 +116,14 @@ perform_check (pam_handle_t *pamh, int ctrl, const char *use_group) |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
- if (ctrl & PAM_USE_UID_ARG) { |
| 90 |
- tpwd = pam_modutil_getpwuid (pamh, getuid()); |
| 91 |
- if (tpwd == NULL) { |
| 92 |
- if (ctrl & PAM_DEBUG_ARG) { |
| 93 |
- pam_syslog(pamh, LOG_NOTICE, "who is running me ?!"); |
| 94 |
- } |
| 95 |
- return PAM_SERVICE_ERR; |
| 96 |
- } |
| 97 |
- fromsu = tpwd->pw_name; |
| 98 |
- } else { |
| 99 |
- fromsu = pam_modutil_getlogin(pamh); |
| 100 |
- |
| 101 |
- /* if getlogin fails try a fallback to PAM_RUSER */ |
| 102 |
- if (fromsu == NULL) { |
| 103 |
- const char *rhostname; |
| 104 |
- |
| 105 |
- retval = pam_get_item(pamh, PAM_RHOST, (const void **)&rhostname); |
| 106 |
- if (retval != PAM_SUCCESS || rhostname == NULL) { |
| 107 |
- retval = pam_get_item(pamh, PAM_RUSER, (const void **)&fromsu); |
| 108 |
- } |
| 109 |
- } |
| 110 |
- |
| 111 |
- if (fromsu != NULL) { |
| 112 |
- tpwd = pam_modutil_getpwnam (pamh, fromsu); |
| 113 |
- } |
| 114 |
- |
| 115 |
- if (fromsu == NULL || tpwd == NULL) { |
| 116 |
- if (ctrl & PAM_DEBUG_ARG) { |
| 117 |
- pam_syslog(pamh, LOG_NOTICE, "who is running me ?!"); |
| 118 |
- } |
| 119 |
- return PAM_SERVICE_ERR; |
| 120 |
+ tpwd = pam_modutil_getpwuid (pamh, getuid()); |
| 121 |
+ if (tpwd == NULL) { |
| 122 |
+ if (ctrl & PAM_DEBUG_ARG) { |
| 123 |
+ pam_syslog(pamh, LOG_NOTICE, "who is running me ?!"); |
| 124 |
} |
| 125 |
+ return PAM_SERVICE_ERR; |
| 126 |
} |
| 127 |
+ fromsu = tpwd->pw_name; |
| 128 |
|
| 129 |
/* |
| 130 |
* At this point fromsu = username-of-invoker; tpwd = pwd ptr for fromsu |