2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
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.
21 #ifdef WITH_AIXAUTHENTICATE
24 #ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW
25 # include <hpsecurity.h>
31 #if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT)
32 # include "md5crypt.h"
33 #endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */
36 * Tries to authenticate the user using password. Returns true if
37 * authentication succeeds.
40 auth_password(struct passwd * pw, const char *password)
42 extern ServerOptions options;
43 char *encrypted_password;
49 #ifdef WITH_AIXAUTHENTICATE
55 /* deny if no user. */
58 if (pw->pw_uid == 0 && options.permit_root_login == 2)
60 if (*password == '\0' && options.permit_empty_passwd == 0)
64 if (options.skey_authentication == 1) {
65 int ret = auth_skey_password(pw, password);
66 if (ret == 1 || ret == 0)
68 /* Fall back to ordinary passwd authentication. */
72 #ifdef WITH_AIXAUTHENTICATE
73 return (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0);
77 if (options.kerberos_authentication == 1) {
78 int ret = auth_krb4_password(pw, password);
79 if (ret == 1 || ret == 0)
81 /* Fall back to ordinary passwd authentication. */
85 /* Check for users with no password. */
86 if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0)
89 pw_password = pw->pw_passwd;
91 #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW)
92 spw = getspnam(pw->pw_name);
95 /* Check for users with no password. */
96 if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0)
99 pw_password = spw->sp_pwdp;
101 #endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */
103 if (pw_password[0] != '\0')
108 #ifdef HAVE_MD5_PASSWORDS
109 if (is_md5_salt(salt))
110 encrypted_password = md5_crypt(password, salt);
112 encrypted_password = crypt(password, salt);
113 #else /* HAVE_MD5_PASSWORDS */
114 # ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW
115 encrypted_password = bigcrypt(password, salt);
117 encrypted_password = crypt(password, salt);
118 # endif /* HAVE_HPUX_TRUSTED_SYSTEM_PW */
119 #endif /* HAVE_MD5_PASSWORDS */
121 /* Authentication is accepted if the encrypted passwords are identical. */
122 return (strcmp(encrypted_password, pw_password) == 0);
124 #endif /* !USE_PAM */