]>
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 | |
5 | * Created: Sat Mar 18 05:11:38 1995 ylo | |
6 | * Password authentication. This file contains the functions to check whether | |
7 | * the password is valid for the user. | |
8 | */ | |
8efc0c15 | 9 | |
10 | #include "includes.h" | |
caf3bc51 | 11 | |
d94aa2ae | 12 | #ifndef USE_PAM |
caf3bc51 | 13 | |
8efc0c15 | 14 | RCSID("$Id$"); |
15 | ||
16 | #include "packet.h" | |
17 | #include "ssh.h" | |
18 | #include "servconf.h" | |
19 | #include "xmalloc.h" | |
b2344d54 | 20 | |
21 | #ifdef HAVE_SHADOW_H | |
d94aa2ae | 22 | # include <shadow.h> |
caf3bc51 | 23 | #endif |
d94aa2ae | 24 | #if defined(HAVE_CRYPT_H) && !defined(CRYPT_H_BREAKS_BUILD) |
25 | # include <crypt.h> | |
26 | #endif /* defined(HAVE_CRYPT_H) && !defined(CRYPT_H_BREAKS_BUILD) */ | |
27 | #if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) | |
28 | # include "md5crypt.h" | |
29 | #endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */ | |
caf3bc51 | 30 | |
5260325f | 31 | /* |
32 | * Tries to authenticate the user using password. Returns true if | |
33 | * authentication succeeds. | |
34 | */ | |
35 | int | |
36 | auth_password(struct passwd * pw, const char *password) | |
8efc0c15 | 37 | { |
5260325f | 38 | extern ServerOptions options; |
39 | char *encrypted_password; | |
f498ed15 | 40 | char *pw_password; |
41 | char *salt; | |
b2344d54 | 42 | #ifdef HAVE_SHADOW_H |
5260325f | 43 | struct spwd *spw; |
b2344d54 | 44 | #endif |
8efc0c15 | 45 | |
aa3378df | 46 | if (pw->pw_uid == 0 && options.permit_root_login == 2) |
5260325f | 47 | return 0; |
aa3378df | 48 | if (*password == '\0' && options.permit_empty_passwd == 0) |
5260325f | 49 | return 0; |
5260325f | 50 | /* deny if no user. */ |
51 | if (pw == NULL) | |
52 | return 0; | |
8efc0c15 | 53 | |
8efc0c15 | 54 | #ifdef SKEY |
5260325f | 55 | if (options.skey_authentication == 1) { |
57112b5a | 56 | int ret = auth_skey_password(pw, password); |
57 | if (ret == 1 || ret == 0) | |
58 | return ret; | |
5260325f | 59 | /* Fall back to ordinary passwd authentication. */ |
60 | } | |
8efc0c15 | 61 | #endif |
57112b5a | 62 | #ifdef KRB4 |
63 | if (options.kerberos_authentication == 1) { | |
64 | int ret = auth_krb4_password(pw, password); | |
65 | if (ret == 1 || ret == 0) | |
66 | return ret; | |
5260325f | 67 | /* Fall back to ordinary passwd authentication. */ |
8efc0c15 | 68 | } |
57112b5a | 69 | #endif |
5260325f | 70 | |
71 | /* Check for users with no password. */ | |
aa3378df | 72 | if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0) |
5260325f | 73 | return 1; |
8efc0c15 | 74 | |
f498ed15 | 75 | pw_password = pw->pw_passwd; |
76 | ||
59dd7a31 | 77 | #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) |
5260325f | 78 | spw = getspnam(pw->pw_name); |
f498ed15 | 79 | if (spw == NULL) |
5260325f | 80 | return(0); |
b2344d54 | 81 | |
c9d323f0 | 82 | /* Check for users with no password. */ |
83 | if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0) | |
84 | return 1; | |
85 | ||
f498ed15 | 86 | pw_password = spw->sp_pwdp; |
87 | #endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */ | |
b2344d54 | 88 | |
f498ed15 | 89 | if (pw_password[0] != '\0') |
90 | salt = pw_password; | |
5260325f | 91 | else |
f498ed15 | 92 | salt = "xx"; |
59dd7a31 | 93 | |
94 | #ifdef HAVE_MD5_PASSWORDS | |
f498ed15 | 95 | if (is_md5_salt(salt)) |
96 | encrypted_password = md5_crypt(password, salt); | |
59dd7a31 | 97 | else |
f498ed15 | 98 | encrypted_password = crypt(password, salt); |
59dd7a31 | 99 | #else /* HAVE_MD5_PASSWORDS */ |
f498ed15 | 100 | encrypted_password = crypt(password, salt); |
59dd7a31 | 101 | #endif /* HAVE_MD5_PASSWORDS */ |
b2344d54 | 102 | |
5260325f | 103 | /* Authentication is accepted if the encrypted passwords are identical. */ |
f498ed15 | 104 | return (strcmp(encrypted_password, pw_password) == 0); |
8efc0c15 | 105 | } |
d94aa2ae | 106 | #endif /* !USE_PAM */ |