2 * Dropbear - a SSH2 server
4 * Copyright (c) 2002,2003 Matt Johnston
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 /* Validates a user password */
32 #include "authpasswd.h"
37 extern int glbAccessMode;
41 #ifdef DROPBEAR_PASSWORD_AUTH
43 /* Process a password auth request, sending success or failure messages as
54 char * passwdcrypt; /* the crypt from /etc/passwd or /etc/shadow */
55 char * testcrypt; /* crypt generated from the user's password sent */
56 unsigned char * password;
57 unsigned int passwordlen;
59 unsigned char changepw;
60 // brcm add notMatched flag.
63 passwdcrypt = ses.authstate.pw->pw_passwd;
65 /* get the shadow password if possible */
66 spasswd = getspnam(ses.authstate.pw->pw_name);
67 if (spasswd != NULL && spasswd->sp_pwdp != NULL) {
68 passwdcrypt = spasswd->sp_pwdp;
72 #ifdef DEBUG_HACKCRYPT
73 /* debugging crypt for non-root testing with shadows */
74 passwdcrypt = DEBUG_HACKCRYPT;
77 /* check for empty password - need to do this again here
78 * since the shadow password may differ to that tested
80 if (passwdcrypt[0] == '\0') {
81 dropbear_log(LOG_WARNING,
82 "disallowed login with empty password for '%s' from %s",
83 ses.authstate.printableuser, ses.addrstring);
84 send_msg_userauth_failure(0, 1);
88 /* check if client wants to change password */
89 changepw = buf_getbyte(ses.payload);
91 /* not implemented by this server */
92 send_msg_userauth_failure(0, 1);
96 password = buf_getstring(ses.payload, &passwordlen);
98 /* clear the buffer containing the password */
99 buf_incrpos(ses.payload, -passwordlen - 4);
100 m_burn(buf_getptr(ses.payload, passwordlen + 4), passwordlen + 4);
102 /* the first bytes of passwdcrypt are the salt */
103 testcrypt = crypt((char*)password, passwdcrypt);
105 // brcm add local/remote login check
106 if ((glbAccessMode == CLI_ACCESS_LOCAL && \
107 (strcmp(ses.authstate.username, "ses.authstate.username") && strcmp(ses.authstate.username, "root"))) ||
108 (glbAccessMode == CLI_ACCESS_REMOTE && strcmp(ses.authstate.username, "support")))
111 if (strcmp(testcrypt, passwdcrypt) == 0 && notMatched == 0) {
112 /* successful authentication */
113 // brcm commented next msg
114 //dropbear_log(LOG_NOTICE,
115 // "password auth succeeded for '%s' from %s",
116 // ses.authstate.printableuser, ses.addrstring);
117 send_msg_userauth_success();
119 dropbear_log(LOG_WARNING,
120 "bad password attempt for '%s' from %s",
121 ses.authstate.printableuser, ses.addrstring);
122 send_msg_userauth_failure(0, 1);
125 m_burn(password, passwordlen);
128 #endif // brcm end, ifndef SSHD_GENKEY
131 #endif /* DROPBEAR_PASSWORD_AUTH */