diff options
author | Thorsten Kukuk <kukuk@thkukuk.de> | 2010-11-24 12:28:01 +0000 |
---|---|---|
committer | Thorsten Kukuk <kukuk@thkukuk.de> | 2010-11-24 12:28:01 +0000 |
commit | 76d789aa7a3ced98ed8421c6c8ed978042ebd477 (patch) | |
tree | 6d7eca03891e95e0b6e102fcdae7c35666176f8d /modules/pam_securetty | |
parent | a56c03f5b878796f8357e1b306b00279350ebf7a (diff) | |
download | pam-76d789aa7a3ced98ed8421c6c8ed978042ebd477.tar.gz pam-76d789aa7a3ced98ed8421c6c8ed978042ebd477.tar.bz2 pam-76d789aa7a3ced98ed8421c6c8ed978042ebd477.zip |
Relevant BUGIDs:
Purpose of commit: new feature
Commit summary:
---------------
2010-11-24 Thorsten Kukuk <kukuk@thkukuk.de>
* modules/pam_securetty/pam_securetty.c: Parse console= kernel
option, add noconsole option.
* modules/pam_securetty/pam_securetty.8.xml: Document new behavior
for serial console.
Patch from Lennart Poettering.
Diffstat (limited to 'modules/pam_securetty')
-rw-r--r-- | modules/pam_securetty/pam_securetty.8.xml | 13 | ||||
-rw-r--r-- | modules/pam_securetty/pam_securetty.c | 39 |
2 files changed, 52 insertions, 0 deletions
diff --git a/modules/pam_securetty/pam_securetty.8.xml b/modules/pam_securetty/pam_securetty.8.xml index dd57705b..90d99a3d 100644 --- a/modules/pam_securetty/pam_securetty.8.xml +++ b/modules/pam_securetty/pam_securetty.8.xml @@ -61,6 +61,19 @@ </para> </listitem> </varlistentry> + <varlistentry> + <term> + <option>noconsole</option> + </term> + <listitem> + <para> + By default pam_securetty will allow root logins on the + kernel console device, as specified with the console= + switch on the kernel command line. Use this switch to turn + of this behaviour. + </para> + </listitem> + </varlistentry> </variablelist> </refsect1> diff --git a/modules/pam_securetty/pam_securetty.c b/modules/pam_securetty/pam_securetty.c index a3c2010d..99c6371f 100644 --- a/modules/pam_securetty/pam_securetty.c +++ b/modules/pam_securetty/pam_securetty.c @@ -2,6 +2,7 @@ #define SECURETTY_FILE "/etc/securetty" #define TTY_PREFIX "/dev/" +#define CMDLINE_FILE "/proc/cmdline" /* * by Elliot Lee <sopwith@redhat.com>, Red Hat Software. @@ -22,6 +23,7 @@ #include <pwd.h> #include <string.h> #include <ctype.h> +#include <limits.h> /* * here, we make a definition for the externally accessible function @@ -38,6 +40,7 @@ #include <security/pam_ext.h> #define PAM_DEBUG_ARG 0x0001 +#define PAM_NOCONSOLE_ARG 0x0002 static int _pam_parse (const pam_handle_t *pamh, int argc, const char **argv) @@ -51,6 +54,8 @@ _pam_parse (const pam_handle_t *pamh, int argc, const char **argv) if (!strcmp(*argv,"debug")) ctrl |= PAM_DEBUG_ARG; + else if (!strcmp(*argv, "noconsole")) + ctrl |= PAM_NOCONSOLE_ARG; else { pam_syslog(pamh, LOG_ERR, "unknown option: %s", *argv); } @@ -144,6 +149,40 @@ securetty_perform_check (pam_handle_t *pamh, int ctrl, } fclose(ttyfile); + if (retval && !(ctrl & PAM_NOCONSOLE_ARG)) { + FILE *cmdlinefile; + + /* Allow access from the kernel console, if enabled */ + cmdlinefile = fopen(CMDLINE_FILE, "r"); + + if (cmdlinefile != NULL) { + char line[LINE_MAX], *p; + + line[0] = 0; + fgets(line, sizeof(line), cmdlinefile); + fclose(cmdlinefile); + + for (p = line; p; p = strstr(p+1, "console=")) { + char *e; + + /* Test whether this is a beginning of a word? */ + if (p > line && p[-1] != ' ') + continue; + + /* Ist this our console? */ + if (strncmp(p + 8, uttyname, strlen(uttyname))) + continue; + + /* Is there any garbage after the TTY name? */ + e = p + 8 + strlen(uttyname); + if (*e == ',' || *e == ' ' || *e == '\n' || *e == 0) { + retval = 0; + break; + } + } + } + } + if (retval) { pam_syslog(pamh, LOG_WARNING, "access denied: tty '%s' is not secure !", uttyname); |