]> andersk Git - openssh.git/blobdiff - auth1.c
- (tim) [configure.ac] Some platforms need sys/types.h for arpa/nameser.h.
[openssh.git] / auth1.c
diff --git a/auth1.c b/auth1.c
index dfe944dd1acd6c6e3822fbed63f0302cf4474511..d08928455c52320665bcf4d7d50ae0e0342ccb7a 100644 (file)
--- a/auth1.c
+++ b/auth1.c
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: auth1.c,v 1.52 2003/08/28 12:54:34 markus Exp $");
+RCSID("$OpenBSD: auth1.c,v 1.59 2004/07/28 09:40:29 markus Exp $");
 
 #include "xmalloc.h"
 #include "rsa.h"
 #include "ssh1.h"
 #include "packet.h"
 #include "buffer.h"
-#include "mpaux.h"
 #include "log.h"
 #include "servconf.h"
 #include "compat.h"
@@ -26,9 +25,11 @@ RCSID("$OpenBSD: auth1.c,v 1.52 2003/08/28 12:54:34 markus Exp $");
 #include "session.h"
 #include "uidswap.h"
 #include "monitor_wrap.h"
+#include "buffer.h"
 
 /* import */
 extern ServerOptions options;
+extern Buffer loginmsg;
 
 /*
  * convert ssh auth msg type into description
@@ -70,10 +71,9 @@ do_authloop(Authctxt *authctxt)
        u_int dlen;
        u_int ulen;
        int prev, type = 0;
-       struct passwd *pw = authctxt->pw;
 
        debug("Attempting authentication for %s%.100s.",
-           authctxt->valid ? "" : "illegal user ", authctxt->user);
+           authctxt->valid ? "" : "invalid user ", authctxt->user);
 
        /* If the user has no password, accept authentication immediately. */
        if (options.password_authentication &&
@@ -81,8 +81,13 @@ do_authloop(Authctxt *authctxt)
            (!options.kerberos_authentication || options.kerberos_or_local_passwd) &&
 #endif
            PRIVSEP(auth_password(authctxt, ""))) {
-               auth_log(authctxt, 1, "without authentication", "");
-               return;
+#ifdef USE_PAM
+               if (options.use_pam && (PRIVSEP(do_pam_account())))
+#endif
+               {
+                       auth_log(authctxt, 1, "without authentication", "");
+                       return;
+               }
        }
 
        /* Indicate that authentication is needed. */
@@ -139,7 +144,7 @@ do_authloop(Authctxt *authctxt)
                                    BN_num_bits(client_host_key->rsa->n), bits);
                        packet_check_eom();
 
-                       authenticated = auth_rhosts_rsa(pw, client_user,
+                       authenticated = auth_rhosts_rsa(authctxt, client_user,
                            client_host_key);
                        key_free(client_host_key);
 
@@ -156,7 +161,7 @@ do_authloop(Authctxt *authctxt)
                                fatal("do_authloop: BN_new failed");
                        packet_get_bignum(n);
                        packet_check_eom();
-                       authenticated = auth_rsa(pw, n);
+                       authenticated = auth_rsa(authctxt, n);
                        BN_clear_free(n);
                        break;
 
@@ -233,22 +238,42 @@ do_authloop(Authctxt *authctxt)
 
 #ifdef HAVE_CYGWIN
                if (authenticated &&
-                   !check_nt_auth(type == SSH_CMSG_AUTH_PASSWORD, pw)) {
+                   !check_nt_auth(type == SSH_CMSG_AUTH_PASSWORD, 
+                   authctxt->pw)) {
                        packet_disconnect("Authentication rejected for uid %d.",
-                       pw == NULL ? -1 : pw->pw_uid);
+                           authctxt->pw == NULL ? -1 : authctxt->pw->pw_uid);
                        authenticated = 0;
                }
 #else
                /* Special handling for root */
                if (authenticated && authctxt->pw->pw_uid == 0 &&
-                   !auth_root_allowed(get_authname(type)))
+                   !auth_root_allowed(get_authname(type))) {
                        authenticated = 0;
+# ifdef SSH_AUDIT_EVENTS
+                       PRIVSEP(audit_event(SSH_LOGIN_ROOT_DENIED));
+# endif
+               }
 #endif
 
 #ifdef USE_PAM
-               if (options.use_pam && authenticated && 
-                   !PRIVSEP(do_pam_account()))
-                       authenticated = 0;
+               if (options.use_pam && authenticated &&
+                   !PRIVSEP(do_pam_account())) {
+                       char *msg;
+                       size_t len;
+
+                       error("Access denied for user %s by PAM account "
+                          "configuration", authctxt->user);
+                       len = buffer_len(&loginmsg);
+                       buffer_append(&loginmsg, "\0", 1);
+                       msg = buffer_ptr(&loginmsg);
+                       /* strip trailing newlines */
+                       if (len > 0)
+                               while (len > 0 && msg[--len] == '\n')
+                                       msg[len] = '\0';
+                       else
+                               msg = "Access denied.";
+                       packet_disconnect(msg);
+               }
 #endif
 
                /* Log before sending the reply */
@@ -262,8 +287,12 @@ do_authloop(Authctxt *authctxt)
                if (authenticated)
                        return;
 
-               if (authctxt->failures++ > AUTH_FAIL_MAX)
+               if (authctxt->failures++ > options.max_authtries) {
+#ifdef SSH_AUDIT_EVENTS
+                       PRIVSEP(audit_event(SSH_LOGIN_EXCEED_MAXTRIES));
+#endif
                        packet_disconnect(AUTH_FAIL_MSG, authctxt->user);
+               }
 
                packet_start(SSH_SMSG_FAILURE);
                packet_send();
@@ -275,10 +304,9 @@ do_authloop(Authctxt *authctxt)
  * Performs authentication of an incoming connection.  Session key has already
  * been exchanged and encryption is enabled.
  */
-Authctxt *
-do_authentication(void)
+void
+do_authentication(Authctxt *authctxt)
 {
-       Authctxt *authctxt;
        u_int ulen;
        char *user, *style = NULL;
 
@@ -292,7 +320,6 @@ do_authentication(void)
        if ((style = strchr(user, ':')) != NULL)
                *style++ = '\0';
 
-       authctxt = authctxt_new();
        authctxt->user = user;
        authctxt->style = style;
 
@@ -300,16 +327,16 @@ do_authentication(void)
        if ((authctxt->pw = PRIVSEP(getpwnamallow(user))) != NULL)
                authctxt->valid = 1;
        else {
-               debug("do_authentication: illegal user %s", user);
+               debug("do_authentication: invalid user %s", user);
                authctxt->pw = fakepw();
        }
 
-       setproctitle("%s%s", authctxt->pw ? user : "unknown",
+       setproctitle("%s%s", authctxt->valid ? user : "unknown",
            use_privsep ? " [net]" : "");
 
 #ifdef USE_PAM
        if (options.use_pam)
-               PRIVSEP(start_pam(user));
+               PRIVSEP(start_pam(authctxt));
 #endif
 
        /*
@@ -332,6 +359,4 @@ do_authentication(void)
        packet_start(SSH_SMSG_SUCCESS);
        packet_send();
        packet_write_wait();
-
-       return (authctxt);
 }
This page took 0.050008 seconds and 4 git commands to generate.