]>
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 | |
4c40f834 | 21 | #ifdef WITH_AIXAUTHENTICATE |
2b763e31 | 22 | # include <login.h> |
23 | #endif | |
24 | #ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW | |
25 | # include <hpsecurity.h> | |
26 | # include <prot.h> | |
4c40f834 | 27 | #endif |
b2344d54 | 28 | #ifdef HAVE_SHADOW_H |
d94aa2ae | 29 | # include <shadow.h> |
caf3bc51 | 30 | #endif |
a423beaf | 31 | #ifdef HAVE_GETPWANAM |
32 | # include <sys/label.h> | |
33 | # include <sys/audit.h> | |
34 | # include <pwdadj.h> | |
35 | #endif | |
d94aa2ae | 36 | #if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) |
37 | # include "md5crypt.h" | |
38 | #endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */ | |
caf3bc51 | 39 | |
5260325f | 40 | /* |
41 | * Tries to authenticate the user using password. Returns true if | |
42 | * authentication succeeds. | |
43 | */ | |
6ae2364d | 44 | int |
5260325f | 45 | auth_password(struct passwd * pw, const char *password) |
8efc0c15 | 46 | { |
5260325f | 47 | extern ServerOptions options; |
48 | char *encrypted_password; | |
f498ed15 | 49 | char *pw_password; |
50 | char *salt; | |
b2344d54 | 51 | #ifdef HAVE_SHADOW_H |
5260325f | 52 | struct spwd *spw; |
b2344d54 | 53 | #endif |
a423beaf | 54 | #ifdef HAVE_GETPWANAM |
55 | struct passwd_adjunct *spw; | |
56 | #endif | |
4c40f834 | 57 | #ifdef WITH_AIXAUTHENTICATE |
58 | char *authmsg; | |
59 | char *loginmsg; | |
60 | int reenter = 1; | |
61 | #endif | |
8efc0c15 | 62 | |
13f825f4 | 63 | /* deny if no user. */ |
64 | if (pw == NULL) | |
65 | return 0; | |
aa3378df | 66 | if (pw->pw_uid == 0 && options.permit_root_login == 2) |
5260325f | 67 | return 0; |
aa3378df | 68 | if (*password == '\0' && options.permit_empty_passwd == 0) |
5260325f | 69 | return 0; |
8efc0c15 | 70 | |
8efc0c15 | 71 | #ifdef SKEY |
5260325f | 72 | if (options.skey_authentication == 1) { |
57112b5a | 73 | int ret = auth_skey_password(pw, password); |
74 | if (ret == 1 || ret == 0) | |
75 | return ret; | |
5260325f | 76 | /* Fall back to ordinary passwd authentication. */ |
77 | } | |
8efc0c15 | 78 | #endif |
4c40f834 | 79 | |
80 | #ifdef WITH_AIXAUTHENTICATE | |
81 | return (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0); | |
82 | #endif | |
83 | ||
57112b5a | 84 | #ifdef KRB4 |
85 | if (options.kerberos_authentication == 1) { | |
86 | int ret = auth_krb4_password(pw, password); | |
87 | if (ret == 1 || ret == 0) | |
88 | return ret; | |
5260325f | 89 | /* Fall back to ordinary passwd authentication. */ |
8efc0c15 | 90 | } |
57112b5a | 91 | #endif |
5260325f | 92 | |
93 | /* Check for users with no password. */ | |
aa3378df | 94 | if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0) |
5260325f | 95 | return 1; |
8efc0c15 | 96 | |
f498ed15 | 97 | pw_password = pw->pw_passwd; |
98 | ||
59dd7a31 | 99 | #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) |
5260325f | 100 | spw = getspnam(pw->pw_name); |
76b8607f | 101 | if (spw != NULL) |
102 | { | |
103 | /* Check for users with no password. */ | |
104 | if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0) | |
105 | return 1; | |
b2344d54 | 106 | |
76b8607f | 107 | pw_password = spw->sp_pwdp; |
108 | } | |
f498ed15 | 109 | #endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */ |
a423beaf | 110 | #if defined(HAVE_GETPWANAM) && !defined(DISABLE_SHADOW) |
111 | if (issecure() && (spw = getpwanam(pw->pw_name)) != NULL) | |
112 | { | |
113 | /* Check for users with no password. */ | |
114 | if (strcmp(password, "") == 0 && strcmp(spw->pwa_passwd, "") == 0) | |
115 | return 1; | |
116 | ||
117 | pw_password = spw->pwa_passwd; | |
118 | } | |
119 | #endif /* defined(HAVE_GETPWANAM) && !defined(DISABLE_SHADOW) */ | |
b2344d54 | 120 | |
f498ed15 | 121 | if (pw_password[0] != '\0') |
122 | salt = pw_password; | |
5260325f | 123 | else |
f498ed15 | 124 | salt = "xx"; |
59dd7a31 | 125 | |
126 | #ifdef HAVE_MD5_PASSWORDS | |
f498ed15 | 127 | if (is_md5_salt(salt)) |
128 | encrypted_password = md5_crypt(password, salt); | |
59dd7a31 | 129 | else |
f498ed15 | 130 | encrypted_password = crypt(password, salt); |
59dd7a31 | 131 | #else /* HAVE_MD5_PASSWORDS */ |
2b763e31 | 132 | # ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW |
133 | encrypted_password = bigcrypt(password, salt); | |
134 | # else | |
f498ed15 | 135 | encrypted_password = crypt(password, salt); |
2b763e31 | 136 | # endif /* HAVE_HPUX_TRUSTED_SYSTEM_PW */ |
59dd7a31 | 137 | #endif /* HAVE_MD5_PASSWORDS */ |
b2344d54 | 138 | |
5260325f | 139 | /* Authentication is accepted if the encrypted passwords are identical. */ |
f498ed15 | 140 | return (strcmp(encrypted_password, pw_password) == 0); |
8efc0c15 | 141 | } |
d94aa2ae | 142 | #endif /* !USE_PAM */ |