From 76d789aa7a3ced98ed8421c6c8ed978042ebd477 Mon Sep 17 00:00:00 2001 From: Thorsten Kukuk Date: Wed, 24 Nov 2010 12:28:01 +0000 Subject: Relevant BUGIDs: Purpose of commit: new feature Commit summary: --------------- 2010-11-24 Thorsten Kukuk * 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. --- modules/pam_securetty/pam_securetty.8.xml | 13 +++++++++++ modules/pam_securetty/pam_securetty.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'modules/pam_securetty') 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 @@ + + + + + + + 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. + + + 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 , Red Hat Software. @@ -22,6 +23,7 @@ #include #include #include +#include /* * here, we make a definition for the externally accessible function @@ -38,6 +40,7 @@ #include #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); -- cgit v1.2.3