Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | From 9bdc197474795f2d000c2bc04f58f7cef8898f21 Mon Sep 17 00:00:00 2001 |
| 2 | From: Amarnath Valluri <amarnath.valluri@intel.com> |
| 3 | Date: Wed, 15 Jul 2015 13:07:20 +0300 |
| 4 | Subject: [PATCH] Debian patch to add a new 'nullok_secure' option to pam_unix, |
| 5 | which accepts users with null passwords only when the applicant is connected |
| 6 | from a tty listed in /etc/securetty. |
| 7 | |
| 8 | Authors: Sam Hartman <hartmans@debian.org>, |
| 9 | Steve Langasek <vorlon@debian.org> |
| 10 | |
| 11 | Upstream-Status: Pending |
| 12 | |
| 13 | Signed-off-by: Ming Liu <ming.liu@windriver.com> |
| 14 | |
| 15 | v2: |
| 16 | - Forward ported from v1.1.6 to v1.2.1 |
| 17 | |
| 18 | Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> |
| 19 | --- |
| 20 | modules/pam_unix/Makefile.am | 3 ++- |
| 21 | modules/pam_unix/README | 11 ++++++++++- |
| 22 | modules/pam_unix/pam_unix.8 | 9 ++++++++- |
| 23 | modules/pam_unix/pam_unix.8.xml | 19 ++++++++++++++++++- |
| 24 | modules/pam_unix/support.c | 40 +++++++++++++++++++++++++++++++++++----- |
| 25 | modules/pam_unix/support.h | 8 ++++++-- |
| 26 | 6 files changed, 79 insertions(+), 11 deletions(-) |
| 27 | |
| 28 | diff --git a/modules/pam_unix/Makefile.am b/modules/pam_unix/Makefile.am |
| 29 | index 56ed591..9a372ac 100644 |
| 30 | --- a/modules/pam_unix/Makefile.am |
| 31 | +++ b/modules/pam_unix/Makefile.am |
| 32 | @@ -30,7 +30,8 @@ if HAVE_VERSIONING |
| 33 | pam_unix_la_LDFLAGS += -Wl,--version-script=$(srcdir)/../modules.map |
| 34 | endif |
| 35 | pam_unix_la_LIBADD = $(top_builddir)/libpam/libpam.la \ |
| 36 | - @LIBCRYPT@ @LIBSELINUX@ $(NIS_LIBS) |
| 37 | + @LIBCRYPT@ @LIBSELINUX@ $(NIS_LIBS) \ |
| 38 | + ../pam_securetty/tty_secure.lo |
| 39 | |
| 40 | securelib_LTLIBRARIES = pam_unix.la |
| 41 | |
| 42 | diff --git a/modules/pam_unix/README b/modules/pam_unix/README |
| 43 | index 3935dba..7880d91 100644 |
| 44 | --- a/modules/pam_unix/README |
| 45 | +++ b/modules/pam_unix/README |
| 46 | @@ -67,7 +67,16 @@ nullok |
| 47 | |
| 48 | The default action of this module is to not permit the user access to a |
| 49 | service if their official password is blank. The nullok argument overrides |
| 50 | - this default. |
| 51 | + this default and allows any user with a blank password to access the |
| 52 | + service. |
| 53 | + |
| 54 | +nullok_secure |
| 55 | + |
| 56 | + The default action of this module is to not permit the user access to a |
| 57 | + service if their official password is blank. The nullok_secure argument |
| 58 | + overrides this default and allows any user with a blank password to access |
| 59 | + the service as long as the value of PAM_TTY is set to one of the values |
| 60 | + found in /etc/securetty. |
| 61 | |
| 62 | try_first_pass |
| 63 | |
| 64 | diff --git a/modules/pam_unix/pam_unix.8 b/modules/pam_unix/pam_unix.8 |
| 65 | index 339178b..a4bd906 100644 |
| 66 | --- a/modules/pam_unix/pam_unix.8 |
| 67 | +++ b/modules/pam_unix/pam_unix.8 |
| 68 | @@ -92,7 +92,14 @@ Turns off informational messages namely messages about session open and close vi |
| 69 | .RS 4 |
| 70 | The default action of this module is to not permit the user access to a service if their official password is blank\&. The |
| 71 | \fBnullok\fR |
| 72 | -argument overrides this default\&. |
| 73 | +argument overrides this default and allows any user with a blank password to access the service\&. |
| 74 | +.RE |
| 75 | +.PP |
| 76 | +\fBnullok_secure\fR |
| 77 | +.RS 4 |
| 78 | +The default action of this module is to not permit the user access to a service if their official password is blank\&. The |
| 79 | +\fBnullok_secure\fR |
| 80 | +argument overrides this default and allows any user with a blank password to access the service as long as the value of PAM_TTY is set to one of the values found in /etc/securetty\&. |
| 81 | .RE |
| 82 | .PP |
| 83 | \fBtry_first_pass\fR |
| 84 | diff --git a/modules/pam_unix/pam_unix.8.xml b/modules/pam_unix/pam_unix.8.xml |
| 85 | index a8b64bb..1ced6f4 100644 |
| 86 | --- a/modules/pam_unix/pam_unix.8.xml |
| 87 | +++ b/modules/pam_unix/pam_unix.8.xml |
| 88 | @@ -159,7 +159,24 @@ |
| 89 | <para> |
| 90 | The default action of this module is to not permit the |
| 91 | user access to a service if their official password is blank. |
| 92 | - The <option>nullok</option> argument overrides this default. |
| 93 | + The <option>nullok</option> argument overrides this default |
| 94 | + and allows any user with a blank password to access the |
| 95 | + service. |
| 96 | + </para> |
| 97 | + </listitem> |
| 98 | + </varlistentry> |
| 99 | + <varlistentry> |
| 100 | + <term> |
| 101 | + <option>nullok_secure</option> |
| 102 | + </term> |
| 103 | + <listitem> |
| 104 | + <para> |
| 105 | + The default action of this module is to not permit the |
| 106 | + user access to a service if their official password is blank. |
| 107 | + The <option>nullok_secure</option> argument overrides this |
| 108 | + default and allows any user with a blank password to access |
| 109 | + the service as long as the value of PAM_TTY is set to one of |
| 110 | + the values found in /etc/securetty. |
| 111 | </para> |
| 112 | </listitem> |
| 113 | </varlistentry> |
| 114 | diff --git a/modules/pam_unix/support.c b/modules/pam_unix/support.c |
| 115 | index abccd82..2361957 100644 |
| 116 | --- a/modules/pam_unix/support.c |
| 117 | +++ b/modules/pam_unix/support.c |
| 118 | @@ -189,13 +189,22 @@ int _set_ctrl(pam_handle_t *pamh, int flags, int *remember, int *rounds, |
| 119 | /* now parse the arguments to this module */ |
| 120 | |
| 121 | for (; argc-- > 0; ++argv) { |
| 122 | + int sl; |
| 123 | |
| 124 | D(("pam_unix arg: %s", *argv)); |
| 125 | |
| 126 | for (j = 0; j < UNIX_CTRLS_; ++j) { |
| 127 | - if (unix_args[j].token |
| 128 | - && !strncmp(*argv, unix_args[j].token, strlen(unix_args[j].token))) { |
| 129 | - break; |
| 130 | + if (unix_args[j].token) { |
| 131 | + sl = strlen(unix_args[j].token); |
| 132 | + if (unix_args[j].token[sl-1] == '=') { |
| 133 | + /* exclude argument from comparison */ |
| 134 | + if (!strncmp(*argv, unix_args[j].token, sl)) |
| 135 | + break; |
| 136 | + } else { |
| 137 | + /* compare full strings */ |
| 138 | + if (!strcmp(*argv, unix_args[j].token)) |
| 139 | + break; |
| 140 | + } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | @@ -566,6 +575,7 @@ static int _unix_run_helper_binary(pam_handle_t *pamh, const char *passwd, |
| 145 | if (child == 0) { |
| 146 | static char *envp[] = { NULL }; |
| 147 | const char *args[] = { NULL, NULL, NULL, NULL }; |
| 148 | + int nullok = off(UNIX__NONULL, ctrl); |
| 149 | |
| 150 | /* XXX - should really tidy up PAM here too */ |
| 151 | |
| 152 | @@ -593,7 +603,16 @@ static int _unix_run_helper_binary(pam_handle_t *pamh, const char *passwd, |
| 153 | /* exec binary helper */ |
| 154 | args[0] = CHKPWD_HELPER; |
| 155 | args[1] = user; |
| 156 | - if (off(UNIX__NONULL, ctrl)) { /* this means we've succeeded */ |
| 157 | + if (on(UNIX_NULLOK_SECURE, ctrl)) { |
| 158 | + const void *uttyname; |
| 159 | + retval = pam_get_item(pamh, PAM_TTY, &uttyname); |
| 160 | + if (retval != PAM_SUCCESS || uttyname == NULL |
| 161 | + || _pammodutil_tty_secure(pamh, (const char *)uttyname) != PAM_SUCCESS) { |
| 162 | + nullok = 0; |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + if (nullok) { |
| 167 | args[2]="nullok"; |
| 168 | } else { |
| 169 | args[2]="nonull"; |
| 170 | @@ -678,6 +697,17 @@ _unix_blankpasswd (pam_handle_t *pamh, unsigned int ctrl, const char *name) |
| 171 | if (on(UNIX__NONULL, ctrl)) |
| 172 | return 0; /* will fail but don't let on yet */ |
| 173 | |
| 174 | + if (on(UNIX_NULLOK_SECURE, ctrl)) { |
| 175 | + int retval2; |
| 176 | + const void *uttyname; |
| 177 | + retval2 = pam_get_item(pamh, PAM_TTY, &uttyname); |
| 178 | + if (retval2 != PAM_SUCCESS || uttyname == NULL) |
| 179 | + return 0; |
| 180 | + |
| 181 | + if (_pammodutil_tty_secure(pamh, (const char *)uttyname) != PAM_SUCCESS) |
| 182 | + return 0; |
| 183 | + } |
| 184 | + |
| 185 | /* UNIX passwords area */ |
| 186 | |
| 187 | retval = get_pwd_hash(pamh, name, &pwd, &salt); |
| 188 | @@ -764,7 +794,7 @@ int _unix_verify_password(pam_handle_t * pamh, const char *name |
| 189 | } |
| 190 | } |
| 191 | } else { |
| 192 | - retval = verify_pwd_hash(p, salt, off(UNIX__NONULL, ctrl)); |
| 193 | + retval = verify_pwd_hash(p, salt, _unix_blankpasswd(pamh, ctrl, name)); |
| 194 | } |
| 195 | |
| 196 | if (retval == PAM_SUCCESS) { |
| 197 | diff --git a/modules/pam_unix/support.h b/modules/pam_unix/support.h |
| 198 | index 3729ce0..43cdbea 100644 |
| 199 | --- a/modules/pam_unix/support.h |
| 200 | +++ b/modules/pam_unix/support.h |
| 201 | @@ -99,8 +99,9 @@ typedef struct { |
| 202 | #define UNIX_MIN_PASS_LEN 27 /* min length for password */ |
| 203 | #define UNIX_QUIET 28 /* Don't print informational messages */ |
| 204 | #define UNIX_DES 29 /* DES, default */ |
| 205 | +#define UNIX_NULLOK_SECURE 30 /* NULL passwords allowed only on secure ttys */ |
| 206 | /* -------------- */ |
| 207 | -#define UNIX_CTRLS_ 30 /* number of ctrl arguments defined */ |
| 208 | +#define UNIX_CTRLS_ 31 /* number of ctrl arguments defined */ |
| 209 | |
| 210 | #define UNIX_DES_CRYPT(ctrl) (off(UNIX_MD5_PASS,ctrl)&&off(UNIX_BIGCRYPT,ctrl)&&off(UNIX_SHA256_PASS,ctrl)&&off(UNIX_SHA512_PASS,ctrl)&&off(UNIX_BLOWFISH_PASS,ctrl)) |
| 211 | |
| 212 | @@ -118,7 +119,7 @@ static const UNIX_Ctrls unix_args[UNIX_CTRLS_] = |
| 213 | /* UNIX_NOT_SET_PASS */ {"not_set_pass", _ALL_ON_, 0100, 0}, |
| 214 | /* UNIX__PRELIM */ {NULL, _ALL_ON_^(0600), 0200, 0}, |
| 215 | /* UNIX__UPDATE */ {NULL, _ALL_ON_^(0600), 0400, 0}, |
| 216 | -/* UNIX__NONULL */ {NULL, _ALL_ON_, 01000, 0}, |
| 217 | +/* UNIX__NONULL */ {NULL, _ALL_ON_^(02000000000), 01000, 0}, |
| 218 | /* UNIX__QUIET */ {NULL, _ALL_ON_, 02000, 0}, |
| 219 | /* UNIX_USE_AUTHTOK */ {"use_authtok", _ALL_ON_, 04000, 0}, |
| 220 | /* UNIX_SHADOW */ {"shadow", _ALL_ON_, 010000, 0}, |
| 221 | @@ -139,6 +140,7 @@ static const UNIX_Ctrls unix_args[UNIX_CTRLS_] = |
| 222 | /* UNIX_MIN_PASS_LEN */ {"minlen=", _ALL_ON_, 0400000000, 0}, |
| 223 | /* UNIX_QUIET */ {"quiet", _ALL_ON_, 01000000000, 0}, |
| 224 | /* UNIX_DES */ {"des", _ALL_ON_^(0260420000), 0, 1}, |
| 225 | +/* UNIX_NULLOK_SECURE */ {"nullok_secure", _ALL_ON_^(01000), 02000000000, 0}, |
| 226 | }; |
| 227 | |
| 228 | #define UNIX_DEFAULTS (unix_args[UNIX__NONULL].flag) |
| 229 | @@ -171,6 +173,8 @@ extern int _unix_read_password(pam_handle_t * pamh |
| 230 | ,const char *prompt2 |
| 231 | ,const char *data_name |
| 232 | ,const void **pass); |
| 233 | +extern int _pammodutil_tty_secure(const pam_handle_t *pamh, |
| 234 | + const char *uttyname); |
| 235 | |
| 236 | extern int _unix_run_verify_binary(pam_handle_t *pamh, |
| 237 | unsigned int ctrl, const char *user, int *daysleft); |
| 238 | -- |
| 239 | 2.1.4 |
| 240 | |