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