]>
Commit | Line | Data |
---|---|---|
8efc0c15 | 1 | /* |
5260325f | 2 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
3 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | |
4 | * All rights reserved | |
5260325f | 5 | * Password authentication. This file contains the functions to check whether |
6 | * the password is valid for the user. | |
bcbf86ec | 7 | * |
8 | * As far as I am concerned, the code I have written for this software | |
9 | * can be used freely for any purpose. Any derived versions of this | |
10 | * software must be clearly marked as such, and if the derived work is | |
11 | * incompatible with the protocol description in the RFC file, it must be | |
12 | * called by a name other than "ssh" or "Secure Shell". | |
13 | * | |
14 | * | |
15 | * Copyright (c) 1999 Dug Song. All rights reserved. | |
16 | * | |
17 | * Redistribution and use in source and binary forms, with or without | |
18 | * modification, are permitted provided that the following conditions | |
19 | * are met: | |
20 | * 1. Redistributions of source code must retain the above copyright | |
21 | * notice, this list of conditions and the following disclaimer. | |
22 | * 2. Redistributions in binary form must reproduce the above copyright | |
23 | * notice, this list of conditions and the following disclaimer in the | |
24 | * documentation and/or other materials provided with the distribution. | |
25 | * | |
26 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
27 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
28 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
29 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
30 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
31 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
35 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 | * | |
37 | * | |
38 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | |
39 | * | |
40 | * Redistribution and use in source and binary forms, with or without | |
41 | * modification, are permitted provided that the following conditions | |
42 | * are met: | |
43 | * 1. Redistributions of source code must retain the above copyright | |
44 | * notice, this list of conditions and the following disclaimer. | |
45 | * 2. Redistributions in binary form must reproduce the above copyright | |
46 | * notice, this list of conditions and the following disclaimer in the | |
47 | * documentation and/or other materials provided with the distribution. | |
48 | * | |
49 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
50 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
51 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
52 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
53 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
54 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
55 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
56 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
57 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
58 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
5260325f | 59 | */ |
8efc0c15 | 60 | |
61 | #include "includes.h" | |
bcbf86ec | 62 | RCSID("$OpenBSD: auth-passwd.c,v 1.17 2000/09/07 20:27:49 deraadt Exp $"); |
8efc0c15 | 63 | |
4d33e531 | 64 | #if !defined(USE_PAM) && !defined(HAVE_OSF_SIA) |
65 | ||
8efc0c15 | 66 | #include "packet.h" |
67 | #include "ssh.h" | |
68 | #include "servconf.h" | |
69 | #include "xmalloc.h" | |
b2344d54 | 70 | |
4c40f834 | 71 | #ifdef WITH_AIXAUTHENTICATE |
2b763e31 | 72 | # include <login.h> |
73 | #endif | |
74 | #ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW | |
75 | # include <hpsecurity.h> | |
76 | # include <prot.h> | |
4c40f834 | 77 | #endif |
b2344d54 | 78 | #ifdef HAVE_SHADOW_H |
d94aa2ae | 79 | # include <shadow.h> |
caf3bc51 | 80 | #endif |
a423beaf | 81 | #ifdef HAVE_GETPWANAM |
82 | # include <sys/label.h> | |
83 | # include <sys/audit.h> | |
84 | # include <pwdadj.h> | |
85 | #endif | |
d94aa2ae | 86 | #if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) |
87 | # include "md5crypt.h" | |
88 | #endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */ | |
caf3bc51 | 89 | |
3c62e7eb | 90 | #ifdef HAVE_CYGWIN |
91 | #undef ERROR | |
92 | #include <windows.h> | |
93 | #include <sys/cygwin.h> | |
94 | #define is_winnt (GetVersion() < 0x80000000) | |
95 | #endif | |
96 | ||
5260325f | 97 | /* |
98 | * Tries to authenticate the user using password. Returns true if | |
99 | * authentication succeeds. | |
100 | */ | |
6ae2364d | 101 | int |
5260325f | 102 | auth_password(struct passwd * pw, const char *password) |
8efc0c15 | 103 | { |
5260325f | 104 | extern ServerOptions options; |
105 | char *encrypted_password; | |
f498ed15 | 106 | char *pw_password; |
107 | char *salt; | |
b2344d54 | 108 | #ifdef HAVE_SHADOW_H |
5260325f | 109 | struct spwd *spw; |
b2344d54 | 110 | #endif |
a423beaf | 111 | #ifdef HAVE_GETPWANAM |
112 | struct passwd_adjunct *spw; | |
113 | #endif | |
7f8f5e00 | 114 | # ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW |
115 | struct pr_passwd *prpw; | |
116 | #endif | |
4c40f834 | 117 | #ifdef WITH_AIXAUTHENTICATE |
118 | char *authmsg; | |
119 | char *loginmsg; | |
120 | int reenter = 1; | |
121 | #endif | |
8efc0c15 | 122 | |
13f825f4 | 123 | /* deny if no user. */ |
124 | if (pw == NULL) | |
125 | return 0; | |
3c62e7eb | 126 | #ifndef HAVE_CYGWIN |
aa3378df | 127 | if (pw->pw_uid == 0 && options.permit_root_login == 2) |
5260325f | 128 | return 0; |
3c62e7eb | 129 | #endif |
130 | #ifdef HAVE_CYGWIN | |
131 | /* | |
132 | * Empty password is only possible on NT if the user has _really_ | |
133 | * an empty password and authentication is done, though. | |
134 | */ | |
135 | if (!is_winnt) | |
136 | #endif | |
aa3378df | 137 | if (*password == '\0' && options.permit_empty_passwd == 0) |
5260325f | 138 | return 0; |
8efc0c15 | 139 | |
3c62e7eb | 140 | #ifdef HAVE_CYGWIN |
141 | if (is_winnt) { | |
142 | HANDLE hToken = cygwin_logon_user(pw, password); | |
143 | ||
144 | if (hToken == INVALID_HANDLE_VALUE) | |
145 | return 0; | |
146 | cygwin_set_impersonation_token(hToken); | |
147 | return 1; | |
148 | } | |
149 | #endif | |
150 | ||
8efc0c15 | 151 | #ifdef SKEY |
5260325f | 152 | if (options.skey_authentication == 1) { |
57112b5a | 153 | int ret = auth_skey_password(pw, password); |
154 | if (ret == 1 || ret == 0) | |
155 | return ret; | |
5260325f | 156 | /* Fall back to ordinary passwd authentication. */ |
157 | } | |
8efc0c15 | 158 | #endif |
4c40f834 | 159 | |
160 | #ifdef WITH_AIXAUTHENTICATE | |
161 | return (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0); | |
162 | #endif | |
163 | ||
57112b5a | 164 | #ifdef KRB4 |
165 | if (options.kerberos_authentication == 1) { | |
166 | int ret = auth_krb4_password(pw, password); | |
167 | if (ret == 1 || ret == 0) | |
168 | return ret; | |
5260325f | 169 | /* Fall back to ordinary passwd authentication. */ |
8efc0c15 | 170 | } |
57112b5a | 171 | #endif |
5260325f | 172 | |
7f8f5e00 | 173 | # ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW |
174 | prpw = getprpwnam(pw->pw_name); | |
175 | pw_password = prpw->ufld.fd_encrypt; | |
176 | #else | |
177 | pw_password = pw->pw_passwd; | |
178 | #endif | |
179 | ||
5260325f | 180 | /* Check for users with no password. */ |
7f8f5e00 | 181 | if (strcmp(password, "") == 0 && strcmp(pw_password, "") == 0) |
5260325f | 182 | return 1; |
8efc0c15 | 183 | |
59dd7a31 | 184 | #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) |
5260325f | 185 | spw = getspnam(pw->pw_name); |
76b8607f | 186 | if (spw != NULL) |
187 | { | |
188 | /* Check for users with no password. */ | |
189 | if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0) | |
190 | return 1; | |
b2344d54 | 191 | |
76b8607f | 192 | pw_password = spw->sp_pwdp; |
193 | } | |
f498ed15 | 194 | #endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */ |
a423beaf | 195 | #if defined(HAVE_GETPWANAM) && !defined(DISABLE_SHADOW) |
196 | if (issecure() && (spw = getpwanam(pw->pw_name)) != NULL) | |
197 | { | |
198 | /* Check for users with no password. */ | |
199 | if (strcmp(password, "") == 0 && strcmp(spw->pwa_passwd, "") == 0) | |
200 | return 1; | |
201 | ||
202 | pw_password = spw->pwa_passwd; | |
203 | } | |
204 | #endif /* defined(HAVE_GETPWANAM) && !defined(DISABLE_SHADOW) */ | |
b2344d54 | 205 | |
f498ed15 | 206 | if (pw_password[0] != '\0') |
207 | salt = pw_password; | |
5260325f | 208 | else |
f498ed15 | 209 | salt = "xx"; |
59dd7a31 | 210 | |
211 | #ifdef HAVE_MD5_PASSWORDS | |
f498ed15 | 212 | if (is_md5_salt(salt)) |
213 | encrypted_password = md5_crypt(password, salt); | |
59dd7a31 | 214 | else |
f498ed15 | 215 | encrypted_password = crypt(password, salt); |
59dd7a31 | 216 | #else /* HAVE_MD5_PASSWORDS */ |
2b763e31 | 217 | # ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW |
218 | encrypted_password = bigcrypt(password, salt); | |
219 | # else | |
f498ed15 | 220 | encrypted_password = crypt(password, salt); |
2b763e31 | 221 | # endif /* HAVE_HPUX_TRUSTED_SYSTEM_PW */ |
59dd7a31 | 222 | #endif /* HAVE_MD5_PASSWORDS */ |
b2344d54 | 223 | |
5260325f | 224 | /* Authentication is accepted if the encrypted passwords are identical. */ |
f498ed15 | 225 | return (strcmp(encrypted_password, pw_password) == 0); |
8efc0c15 | 226 | } |
4d33e531 | 227 | #endif /* !USE_PAM && !HAVE_OSF_SIA */ |