annotate svr-authpasswd.c @ 317:063cf9e8efea ucc-axis-hack

dropbear_log to stderr since it works now
author Matt Johnston <matt@ucc.asn.au>
date Sat, 01 Apr 2006 12:09:46 +0000
parents 5d5bbca82aba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 * Dropbear - a SSH2 server
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 * All rights reserved.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 * of this software and associated documentation files (the "Software"), to deal
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 * in the Software without restriction, including without limitation the rights
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 * copies of the Software, and to permit persons to whom the Software is
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 * furnished to do so, subject to the following conditions:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 * The above copyright notice and this permission notice shall be included in
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 * all copies or substantial portions of the Software.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 *
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 * SOFTWARE. */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 /* Validates a user password */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #include "includes.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #include "session.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #include "buffer.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 #include "dbutil.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 #include "auth.h"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32
68
eee77ac31ccc cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents: 54
diff changeset
33 #ifdef ENABLE_SVR_PASSWORD_AUTH
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 /* Process a password auth request, sending success or failure messages as
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36 * appropriate */
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
37 void svr_auth_password() {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 #ifdef HAVE_SHADOW_H
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 68
diff changeset
40 struct spwd *spasswd = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 #endif
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 68
diff changeset
42 char * passwdcrypt = NULL; /* the crypt from /etc/passwd or /etc/shadow */
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 68
diff changeset
43 char * testcrypt = NULL; /* crypt generated from the user's password sent */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 unsigned char * password;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 unsigned int passwordlen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 68
diff changeset
47 unsigned int changepw;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48
306
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
49 buffer * pw_buf;
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
50 char * newline = NULL;
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
51 unsigned int match = 0;
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
52
299
740e782679be Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
53 #if 0
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
54 passwdcrypt = ses.authstate.pw->pw_passwd;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 #ifdef HAVE_SHADOW_H
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 /* get the shadow password if possible */
53
0fe267cc9dee Be a bit safer with reentrant pw_name
Matt Johnston <matt@ucc.asn.au>
parents: 33
diff changeset
57 spasswd = getspnam(ses.authstate.printableuser);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 if (spasswd != NULL && spasswd->sp_pwdp != NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 passwdcrypt = spasswd->sp_pwdp;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 #ifdef DEBUG_HACKCRYPT
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 /* debugging crypt for non-root testing with shadows */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 passwdcrypt = DEBUG_HACKCRYPT;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 /* check for empty password - need to do this again here
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 * since the shadow password may differ to that tested
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70 * in auth.c */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 if (passwdcrypt[0] == '\0') {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 dropbear_log(LOG_WARNING, "user '%s' has blank password, rejected",
33
f789045062e6 Progressing client support
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
73 ses.authstate.printableuser);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 send_msg_userauth_failure(0, 1);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76 }
299
740e782679be Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
77 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 /* check if client wants to change password */
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 158
diff changeset
80 changepw = buf_getbool(ses.payload);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 if (changepw) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 /* not implemented by this server */
299
740e782679be Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
83 TRACE(("changepw, wah!?"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 send_msg_userauth_failure(0, 1);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 password = buf_getstring(ses.payload, &passwordlen);
299
740e782679be Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
89 TRACE(("password '%s' %d", password, passwordlen))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90
299
740e782679be Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
91 #if 0
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 /* the first bytes of passwdcrypt are the salt */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 testcrypt = crypt((char*)password, passwdcrypt);
299
740e782679be Various changes to compile+kind of run on UCC's axis board.
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
94 #endif
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95
306
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
96 pw_buf = buf_new(100);
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
97 if (buf_readfile(pw_buf, RAW_PASSWORD_FILE) != DROPBEAR_SUCCESS) {
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
98 dropbear_exit("Failed to read %s", RAW_PASSWORD_FILE);
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
99 }
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
100
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
101 /* Blah, only one line. */
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
102 buf_putbyte(pw_buf, '\0');
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
103 newline = strchr(pw_buf->data, '\n');
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
104 if (newline) {
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
105 *newline = '\0';
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
106 }
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
107
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
108
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
109 if (strcmp(password, pw_buf->data) == 0) {
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
110 match = 1;
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
111 } else {
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
112 match = 0;
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
113 }
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
114
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
115 m_burn(password, passwordlen);
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
116 m_free(password);
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
117 buf_burn(pw_buf);
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
118 buf_free(pw_buf);
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
119 pw_buf = NULL;
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
120
5d5bbca82aba Use password file, add serial option
Matt Johnston <matt@ucc.asn.au>
parents: 299
diff changeset
121 if (match) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 /* successful authentication */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 dropbear_log(LOG_NOTICE,
158
364a75cfebab Log the IP along with auth success/fail attempts
Matt Johnston <matt@ucc.asn.au>
parents: 119
diff changeset
124 "password auth succeeded for '%s' from %s",
364a75cfebab Log the IP along with auth success/fail attempts
Matt Johnston <matt@ucc.asn.au>
parents: 119
diff changeset
125 ses.authstate.printableuser,
364a75cfebab Log the IP along with auth success/fail attempts
Matt Johnston <matt@ucc.asn.au>
parents: 119
diff changeset
126 svr_ses.addrstring);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 send_msg_userauth_success();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 dropbear_log(LOG_WARNING,
158
364a75cfebab Log the IP along with auth success/fail attempts
Matt Johnston <matt@ucc.asn.au>
parents: 119
diff changeset
130 "bad password attempt for '%s' from %s",
364a75cfebab Log the IP along with auth success/fail attempts
Matt Johnston <matt@ucc.asn.au>
parents: 119
diff changeset
131 ses.authstate.printableuser,
364a75cfebab Log the IP along with auth success/fail attempts
Matt Johnston <matt@ucc.asn.au>
parents: 119
diff changeset
132 svr_ses.addrstring);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 send_msg_userauth_failure(0, 1);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136
68
eee77ac31ccc cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents: 54
diff changeset
137 #endif