Debian patch to add a new 'nullok_secure' option to pam_unix, which accepts users with null passwords only when the applicant is connected from a tty listed in /etc/securetty. Authors: Sam Hartman , Steve Langasek Upstream status: not yet submitted Index: pam.deb/modules/pam_unix/support.c =================================================================== --- pam.deb.orig/modules/pam_unix/support.c +++ pam.deb/modules/pam_unix/support.c @@ -85,15 +85,22 @@ /* now parse the arguments to this module */ while (argc-- > 0) { - int j; + int j, sl; D(("pam_unix arg: %s", *argv)); for (j = 0; j < UNIX_CTRLS_; ++j) { - if (unix_args[j].token - && !strncmp(*argv, unix_args[j].token, strlen(unix_args[j].token))) - { - break; + if (unix_args[j].token) { + sl = strlen(unix_args[j].token); + if (unix_args[j].token[sl-1] == '=') { + /* exclude argument from comparison */ + if (!strncmp(*argv, unix_args[j].token, sl)) + break; + } else { + /* compare full strings */ + if (!strcmp(*argv, unix_args[j].token)) + break; + } } } @@ -449,6 +456,7 @@ child = fork(); if (child == 0) { int i=0; + int nullok = off(UNIX__NONULL, ctrl); struct rlimit rlim; static char *envp[] = { NULL }; char *args[] = { NULL, NULL, NULL, NULL }; @@ -476,7 +484,18 @@ /* exec binary helper */ args[0] = strdup(CHKPWD_HELPER); args[1] = x_strdup(user); - if (off(UNIX__NONULL, ctrl)) { /* this means we've succeeded */ + + if (on(UNIX_NULLOK_SECURE, ctrl)) { + const void *uttyname; + retval = pam_get_item(pamh, PAM_TTY, &uttyname); + if (retval != PAM_SUCCESS || uttyname == NULL + || _pammodutil_tty_secure(pamh, (const char *)uttyname) != PAM_SUCCESS) + { + nullok = 0; + } + } + + if (nullok) { args[2]=strdup("nullok"); } else { args[2]=strdup("nonull"); @@ -557,6 +576,17 @@ if (on(UNIX__NONULL, ctrl)) return 0; /* will fail but don't let on yet */ + if (on(UNIX_NULLOK_SECURE, ctrl)) { + int retval2; + const void *uttyname; + retval2 = pam_get_item(pamh, PAM_TTY, &uttyname); + if (retval2 != PAM_SUCCESS || uttyname == NULL) + return 0; + + if (_pammodutil_tty_secure(pamh, (const char *)uttyname) != PAM_SUCCESS) + return 0; + } + /* UNIX passwords area */ retval = get_pwd_hash(pamh, name, &pwd, &salt); @@ -643,7 +673,8 @@ } } } else { - retval = verify_pwd_hash(p, salt, off(UNIX__NONULL, ctrl)); + retval = verify_pwd_hash(p, salt, + _unix_blankpasswd(pamh, ctrl, name)); } if (retval == PAM_SUCCESS) { Index: pam.deb/modules/pam_unix/support.h =================================================================== --- pam.deb.orig/modules/pam_unix/support.h +++ pam.deb/modules/pam_unix/support.h @@ -92,8 +92,9 @@ #define UNIX_MAX_PASS_LEN 27 /* internal, for compatibility only */ #define UNIX_MIN_PASS_LEN 28 /* min length for password */ #define UNIX_OBSCURE_CHECKS 29 /* enable obscure checks on passwords */ +#define UNIX_NULLOK_SECURE 30 /* NULL passwords allowed only on secure ttys */ /* -------------- */ -#define UNIX_CTRLS_ 30 /* number of ctrl arguments defined */ +#define UNIX_CTRLS_ 31 /* number of ctrl arguments defined */ #define UNIX_HASH_MASK (UNIX_MD5_PASS|UNIX_BIGCRYPT|UNIX_SHA256_PASS|UNIX_SHA512_PASS|UNIX_BLOWFISH_PASS) @@ -111,7 +112,7 @@ /* UNIX_NOT_SET_PASS */ {"not_set_pass", _ALL_ON_, 0x40}, /* UNIX__PRELIM */ {NULL, _ALL_ON_^(0x180), 0x80}, /* UNIX__UPDATE */ {NULL, _ALL_ON_^(0x180), 0x100}, -/* UNIX__NONULL */ {NULL, _ALL_ON_, 0x200}, +/* UNIX__NONULL */ {NULL, _ALL_ON_^(0x8000000), 0x200}, /* UNIX__QUIET */ {NULL, _ALL_ON_, 0x400}, /* UNIX_USE_AUTHTOK */ {"use_authtok", _ALL_ON_, 0x800}, /* UNIX_SHADOW */ {"shadow", _ALL_ON_, 0x1000}, @@ -132,6 +133,7 @@ /* UNIX_MAX_PASS_LEN */ {"max=", _ALL_ON_, 0}, /* UNIX_MIN_PASS_LEN */ {"min=", _ALL_ON_, 0x4000000}, /* UNIX_OBSCURE_CHECKS */ {"obscure", _ALL_ON_, 0x8000000}, +/* UNIX__NULLOK */ {"nullok_secure", _ALL_ON_^(0x200), 0x10000000}, }; #define UNIX_DEFAULTS (unix_args[UNIX__NONULL].flag) @@ -167,6 +169,9 @@ ,const char *data_name ,const void **pass); +extern int _pammodutil_tty_secure(const pam_handle_t *pamh, + const char *uttyname); + extern int _unix_run_verify_binary(pam_handle_t *pamh, unsigned int ctrl, const char *user, int *daysleft); #endif /* _PAM_UNIX_SUPPORT_H */ Index: pam.deb/modules/pam_unix/Makefile.am =================================================================== --- pam.deb.orig/modules/pam_unix/Makefile.am +++ pam.deb/modules/pam_unix/Makefile.am @@ -29,7 +29,8 @@ pam_unix_la_LDFLAGS += -Wl,--version-script=$(srcdir)/../modules.map endif pam_unix_la_LIBADD = @LIBNSL@ -L$(top_builddir)/libpam -lpam \ - @LIBCRYPT@ @LIBSELINUX@ + @LIBCRYPT@ @LIBSELINUX@ \ + ../pam_securetty/tty_secure.lo securelib_LTLIBRARIES = pam_unix.la Index: pam.deb/modules/pam_unix/README =================================================================== --- pam.deb.orig/modules/pam_unix/README +++ pam.deb/modules/pam_unix/README @@ -57,7 +57,16 @@ The default action of this module is to not permit the user access to a service if their official password is blank. The nullok argument overrides - this default. + this default and allows any user with a blank password to access the + service. + +nullok_secure + + The default action of this module is to not permit the user access to a + service if their official password is blank. The nullok_secure 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. try_first_pass Index: pam.deb/modules/pam_unix/pam_unix.8 =================================================================== --- pam.deb.orig/modules/pam_unix/pam_unix.8 +++ pam.deb/modules/pam_unix/pam_unix.8 @@ -218,7 +218,14 @@ .RS 4 The default action of this module is to not permit the user access to a service if their official password is blank\&. The \fBnullok\fR -argument overrides this default\&. +argument overrides this default and allows any user with a blank password to access the service\&. +.RE +.PP +\fBnullok_secure\fR +.RS 4 +The default action of this module is to not permit the user access to a service if their official password is blank\&. The +\fBnullok_secure\fR +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\&. .RE .PP \fBtry_first_pass\fR Index: pam.deb/modules/pam_unix/pam_unix.8.xml =================================================================== --- pam.deb.orig/modules/pam_unix/pam_unix.8.xml +++ pam.deb/modules/pam_unix/pam_unix.8.xml @@ -135,7 +135,24 @@ The default action of this module is to not permit the user access to a service if their official password is blank. - The argument overrides this default. + The argument overrides this default + and allows any user with a blank password to access the + service. + + + + + + + + + + The default action of this module is to not permit the + user access to a service if their official password is blank. + The 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.