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 */
33 #ifdef ENABLE_SVR_PASSWORD_AUTH
35 /* Process a password auth request, sending success or failure messages as
37 void svr_auth_password() {
40 struct spwd
*spasswd
= NULL
;
42 char * passwdcrypt
= NULL
; /* the crypt from /etc/passwd or /etc/shadow */
43 char * testcrypt
= NULL
; /* crypt generated from the user's password sent */
44 unsigned char * password
;
45 unsigned int passwordlen
;
47 unsigned int changepw
;
49 passwdcrypt
= ses
.authstate
.pw_passwd
;
51 /* get the shadow password if possible */
52 spasswd
= getspnam(ses
.authstate
.pw_name
);
53 if (spasswd
!= NULL
&& spasswd
->sp_pwdp
!= NULL
) {
54 passwdcrypt
= spasswd
->sp_pwdp
;
58 #ifdef DEBUG_HACKCRYPT
59 /* debugging crypt for non-root testing with shadows */
60 passwdcrypt
= DEBUG_HACKCRYPT
;
63 /* check for empty password - need to do this again here
64 * since the shadow password may differ to that tested
66 if (passwdcrypt
[0] == '\0') {
67 dropbear_log(LOG_WARNING
, "user '%s' has blank password, rejected",
68 ses
.authstate
.pw_name
);
69 send_msg_userauth_failure(0, 1);
73 /* check if client wants to change password */
74 changepw
= buf_getbool(ses
.payload
);
76 /* not implemented by this server */
77 send_msg_userauth_failure(0, 1);
81 password
= buf_getstring(ses
.payload
, &passwordlen
);
83 /* the first bytes of passwdcrypt are the salt */
84 testcrypt
= crypt((char*)password
, passwdcrypt
);
85 m_burn(password
, passwordlen
);
88 if (strcmp(testcrypt
, passwdcrypt
) == 0) {
89 /* successful authentication */
90 dropbear_log(LOG_NOTICE
,
91 "password auth succeeded for '%s' from %s",
92 ses
.authstate
.pw_name
,
94 send_msg_userauth_success();
96 dropbear_log(LOG_WARNING
,
97 "bad password attempt for '%s' from %s",
98 ses
.authstate
.pw_name
,
100 send_msg_userauth_failure(0, 1);