]> andersk Git - gssapi-openssh.git/blobdiff - openssh/auth.c
merged OpenSSH 3.9p1 to trunk
[gssapi-openssh.git] / openssh / auth.c
index 594cccedb20d9273d9bc698a3c0a72ae8564392b..f35600eed1fe302754c3d40e50f83164dd1b1d3a 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenBSD: auth.c,v 1.78 2007/09/21 08:15:29 djm Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  *
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: auth.c,v 1.58 2005/03/14 11:44:42 dtucker Exp $");
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+
+#include <netinet/in.h>
+
+#include <errno.h>
+#ifdef HAVE_PATHS_H
+# include <paths.h>
+#endif
+#include <pwd.h>
 #ifdef HAVE_LOGIN_H
 #include <login.h>
 #endif
 #ifdef USE_SHADOW
 #include <shadow.h>
 #endif
-
 #ifdef HAVE_LIBGEN_H
 #include <libgen.h>
 #endif
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
 
 #include "xmalloc.h"
 #include "match.h"
 #include "groupaccess.h"
 #include "log.h"
+#include "buffer.h"
 #include "servconf.h"
+#include "key.h"
+#include "hostfile.h"
 #include "auth.h"
 #include "auth-options.h"
 #include "canohost.h"
-#include "buffer.h"
-#include "bufaux.h"
 #include "uidswap.h"
 #include "misc.h"
-#include "bufaux.h"
 #include "packet.h"
 #include "loginrec.h"
+#ifdef GSSAPI
+#include "ssh-gss.h"
+#endif
 #include "monitor_wrap.h"
 
 /* import */
 extern ServerOptions options;
+extern int use_privsep;
 extern Buffer loginmsg;
+extern struct passwd *privsep_pw;
 
 /* Debugging messages */
 Buffer auth_debug;
@@ -76,7 +94,7 @@ allowed_user(struct passwd * pw)
        struct stat st;
        const char *hostname = NULL, *ipaddr = NULL, *passwd = NULL;
        char *shell;
-       int i;
+       u_int i;
 #ifdef USE_SHADOW
        struct spwd *spw = NULL;
 #endif
@@ -97,7 +115,11 @@ allowed_user(struct passwd * pw)
        /* grab passwd field for locked account check */
 #ifdef USE_SHADOW
        if (spw != NULL)
+#ifdef USE_LIBIAF
+               passwd = get_iaf_password(pw);
+#else
                passwd = spw->sp_pwdp;
+#endif /* USE_LIBIAF */
 #else
        passwd = pw->pw_passwd;
 #endif
@@ -119,6 +141,9 @@ allowed_user(struct passwd * pw)
                if (strstr(passwd, LOCKED_PASSWD_SUBSTR))
                        locked = 1;
 #endif
+#ifdef USE_LIBIAF
+               free(passwd);
+#endif /* USE_LIBIAF */
                if (locked) {
                        logit("User %.100s not allowed because account is locked",
                            pw->pw_name);
@@ -224,6 +249,9 @@ auth_log(Authctxt *authctxt, int authenticated, char *method, char *info)
        void (*authlog) (const char *fmt,...) = verbose;
        char *authmsg;
 
+       if (use_privsep && !mm_is_monitor() && !authctxt->postponed)
+               return;
+
        /* Raise logging level */
        if (authenticated == 1 ||
            !authctxt->valid ||
@@ -241,7 +269,7 @@ auth_log(Authctxt *authctxt, int authenticated, char *method, char *info)
            method,
            authctxt->valid ? "" : "invalid user ",
            (authctxt->user && authctxt->user[0]) ?
-               authctxt->user : "<implicit>",
+               authctxt->user : "unknown",
            get_remote_ipaddr(),
            get_remote_port(),
            info);
@@ -253,44 +281,15 @@ auth_log(Authctxt *authctxt, int authenticated, char *method, char *info)
            strcmp(method, "challenge-response") == 0))
                record_failed_login(authctxt->user,
                    get_canonical_hostname(options.use_dns), "ssh");
+# ifdef WITH_AIXAUTHENTICATE
+       if (authenticated)
+               sys_auth_record_login(authctxt->user,
+                   get_canonical_hostname(options.use_dns), "ssh", &loginmsg);
+# endif
 #endif
 #ifdef SSH_AUDIT_EVENTS
-       if (authenticated == 0 && !authctxt->postponed) {
-               ssh_audit_event_t event;
-
-               debug3("audit failed auth attempt, method %s euid %d",
-                   method, (int)geteuid());
-               /*
-                * Because the auth loop is used in both monitor and slave,
-                * we must be careful to send each event only once and with
-                * enough privs to write the event.
-                */
-               event = audit_classify_auth(method);
-               switch(event) {
-               case SSH_AUTH_FAIL_NONE:
-               case SSH_AUTH_FAIL_PASSWD:
-               case SSH_AUTH_FAIL_KBDINT:
-                       if (geteuid() == 0)
-                               audit_event(event);
-                       break;
-               case SSH_AUTH_FAIL_PUBKEY:
-               case SSH_AUTH_FAIL_HOSTBASED:
-               case SSH_AUTH_FAIL_GSSAPI:
-                       /*
-                        * This is required to handle the case where privsep
-                        * is enabled but it's root logging in, since
-                        * use_privsep won't be cleared until after a
-                        * successful login.
-                        */
-                       if (geteuid() == 0)
-                               audit_event(event);
-                       else
-                               PRIVSEP(audit_event(event));
-                       break;
-               default:
-                       error("unknown authentication audit event %d", event);
-               }
-       }
+       if (authenticated == 0 && !authctxt->postponed)
+               audit_event(audit_classify_auth(method));
 #endif
 }
 
@@ -303,7 +302,6 @@ auth_root_allowed(char *method)
        switch (options.permit_root_login) {
        case PERMIT_YES:
                return 1;
-               break;
        case PERMIT_NO_PASSWD:
                if (strcmp(method, "password") != 0)
                        return 1;
@@ -328,63 +326,38 @@ auth_root_allowed(char *method)
  * This returns a buffer allocated by xmalloc.
  */
 char *
-expand_filename(const char *filename, struct passwd *pw)
+expand_authorized_keys(const char *filename, struct passwd *pw)
 {
-       Buffer buffer;
-       char *file;
-       const char *cp;
+       char *file, ret[MAXPATHLEN];
+       int i;
 
-       /*
-        * Build the filename string in the buffer by making the appropriate
-        * substitutions to the given file name.
-        */
-       buffer_init(&buffer);
-       for (cp = filename; *cp; cp++) {
-               if (cp[0] == '%' && cp[1] == '%') {
-                       buffer_append(&buffer, "%", 1);
-                       cp++;
-                       continue;
-               }
-               if (cp[0] == '%' && cp[1] == 'h') {
-                       buffer_append(&buffer, pw->pw_dir, strlen(pw->pw_dir));
-                       cp++;
-                       continue;
-               }
-               if (cp[0] == '%' && cp[1] == 'u') {
-                       buffer_append(&buffer, pw->pw_name,
-                           strlen(pw->pw_name));
-                       cp++;
-                       continue;
-               }
-               buffer_append(&buffer, cp, 1);
-       }
-       buffer_append(&buffer, "\0", 1);
+       file = percent_expand(filename, "h", pw->pw_dir,
+           "u", pw->pw_name, (char *)NULL);
 
        /*
         * Ensure that filename starts anchored. If not, be backward
         * compatible and prepend the '%h/'
         */
-       file = xmalloc(MAXPATHLEN);
-       cp = buffer_ptr(&buffer);
-       if (*cp != '/')
-               snprintf(file, MAXPATHLEN, "%s/%s", pw->pw_dir, cp);
-       else
-               strlcpy(file, cp, MAXPATHLEN);
-
-       buffer_free(&buffer);
-       return file;
+       if (*file == '/')
+               return (file);
+
+       i = snprintf(ret, sizeof(ret), "%s/%s", pw->pw_dir, file);
+       if (i < 0 || (size_t)i >= sizeof(ret))
+               fatal("expand_authorized_keys: path too long");
+       xfree(file);
+       return (xstrdup(ret));
 }
 
 char *
 authorized_keys_file(struct passwd *pw)
 {
-       return expand_filename(options.authorized_keys_file, pw);
+       return expand_authorized_keys(options.authorized_keys_file, pw);
 }
 
 char *
 authorized_keys_file2(struct passwd *pw)
 {
-       return expand_filename(options.authorized_keys_file2, pw);
+       return expand_authorized_keys(options.authorized_keys_file2, pw);
 }
 
 /* return ok if key exists in sysfile or userfile */
@@ -509,10 +482,13 @@ getpwnamallow(const char *user)
 #endif
        struct passwd *pw;
 
+       parse_server_match_config(&options, user,
+           get_canonical_hostname(options.use_dns), get_remote_ipaddr());
+
        pw = getpwnam(user);
        if (pw == NULL) {
                logit("Invalid user %.100s from %.100s",
-                     (user && user[0]) ? user : "<implicit>",
+                     (user && user[0]) ? user : "unknown",
                      get_remote_ipaddr());
 #ifdef CUSTOM_FAILED_LOGIN
                record_failed_login(user,
@@ -595,8 +571,8 @@ fakepw(void)
        fake.pw_passwd =
            "$2a$06$r3.juUaHZDlIbQaO2dS9FuYxL1W9M81R1Tc92PoSNmzvpEqLkLGrK";
        fake.pw_gecos = "NOUSER";
-       fake.pw_uid = (uid_t)-1;
-       fake.pw_gid = (gid_t)-1;
+       fake.pw_uid = privsep_pw == NULL ? (uid_t)-1 : privsep_pw->pw_uid;
+       fake.pw_gid = privsep_pw == NULL ? (gid_t)-1 : privsep_pw->pw_gid;
 #ifdef HAVE_PW_CLASS_IN_PASSWD
        fake.pw_class = "";
 #endif
This page took 0.068321 seconds and 4 git commands to generate.