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 */
35 extern int glbAccessMode;
38 #ifdef ENABLE_SVR_PASSWORD_AUTH
40 /* Process a password auth request, sending success or failure messages as
42 void svr_auth_password() {
48 struct spwd *spasswd = NULL;
50 char * passwdcrypt = NULL; /* the crypt from /etc/passwd or /etc/shadow */
51 char * testcrypt = NULL; /* crypt generated from the user's password sent */
52 unsigned char * password;
53 unsigned int passwordlen;
55 unsigned int changepw;
56 // brcm add notMatched flag.
58 passwdcrypt = ses.authstate.pw->pw_passwd;
60 /* get the shadow password if possible */
61 spasswd = getspnam(ses.authstate.printableuser);
62 if (spasswd != NULL && spasswd->sp_pwdp != NULL) {
63 passwdcrypt = spasswd->sp_pwdp;
67 #ifdef DEBUG_HACKCRYPT
68 /* debugging crypt for non-root testing with shadows */
69 passwdcrypt = DEBUG_HACKCRYPT;
72 /* check for empty password - need to do this again here
73 * since the shadow password may differ to that tested
75 if (passwdcrypt[0] == '\0') {
76 dropbear_log(LOG_WARNING, "user '%s' has blank password, rejected",
77 ses.authstate.printableuser);
78 send_msg_userauth_failure(0, 1);
82 /* check if client wants to change password */
83 changepw = buf_getbool(ses.payload);
85 /* not implemented by this server */
86 send_msg_userauth_failure(0, 1);
90 password = buf_getstring(ses.payload, &passwordlen);
92 /* the first bytes of passwdcrypt are the salt */
93 testcrypt = crypt((char*)password, passwdcrypt);
95 // brcm add local/remote login check
96 if ((glbAccessMode == CLI_ACCESS_LOCAL && \
97 (strcmp(ses.authstate.username, "ses.authstate.username") && strcmp(ses.authstate.username, "admin"))) ||
98 (glbAccessMode == CLI_ACCESS_REMOTE && strcmp(ses.authstate.username, "support")))
101 m_burn(password, passwordlen);
103 // USR9108 No "user" access.
104 if (strcmp(ses.authstate.username, "user") == 0) {
105 dropbear_log(LOG_WARNING,
106 "Unauthorized attempt for '%s' from %s",
107 ses.authstate.printableuser,
109 send_msg_userauth_failure(0, 1);
110 } else if (strcmp(testcrypt, passwdcrypt) == 0) {
111 /* successful authentication */
112 // brcm commented next msg
113 //dropbear_log(LOG_NOTICE,
114 // "password auth succeeded for '%s' from %s",
115 // ses.authstate.printableuser,
116 // svr_ses.addrstring);
117 send_msg_userauth_success();
119 dropbear_log(LOG_WARNING,
120 "bad password attempt for '%s' from %s",
121 ses.authstate.printableuser,
123 send_msg_userauth_failure(0, 1);
125 #endif // brcm end, ifndef SSHD_GENKEY