]> granicus.if.org Git - linux-pam/commitdiff
Relevant BUGIDs:
authorThorsten Kukuk <kukuk@thkukuk.de>
Wed, 24 Nov 2010 12:28:01 +0000 (12:28 +0000)
committerThorsten Kukuk <kukuk@thkukuk.de>
Wed, 24 Nov 2010 12:28:01 +0000 (12:28 +0000)
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.

ChangeLog
modules/pam_securetty/pam_securetty.8.xml
modules/pam_securetty/pam_securetty.c

index 87610bab12bcdd2aa59aff8b1cb29e9751f84a07..c42e20efb96c1b27066fb2e687ef36b1da16b5a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+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.
+
 2010-11-24  Tomas Mraz  <tm@t8m.info>
 
        * modules/pam_limits/limits.conf.5.xml: Document the %group syntax.
index dd57705b74c8d11d6a6934861234d40606709c08..90d99a3d4e426ac1fe0eb2a1d11da9ae3bcd9a4b 100644 (file)
           </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>
 
index a3c2010d806eca12e2643e2af9db2749a3b177ee..99c6371fddeaca10d6b8ca298b092c1a13b6264a 100644 (file)
@@ -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);