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.
24 #if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT)
25 # include "md5crypt.h"
26 #endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */
29 * Tries to authenticate the user using password. Returns true if
30 * authentication succeeds.
33 auth_password(struct passwd * pw, const char *password)
35 extern ServerOptions options;
36 char *encrypted_password;
43 /* deny if no user. */
46 if (pw->pw_uid == 0 && options.permit_root_login == 2)
48 if (*password == '\0' && options.permit_empty_passwd == 0)
52 if (options.skey_authentication == 1) {
53 int ret = auth_skey_password(pw, password);
54 if (ret == 1 || ret == 0)
56 /* Fall back to ordinary passwd authentication. */
60 if (options.kerberos_authentication == 1) {
61 int ret = auth_krb4_password(pw, password);
62 if (ret == 1 || ret == 0)
64 /* Fall back to ordinary passwd authentication. */
68 /* Check for users with no password. */
69 if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0)
72 pw_password = pw->pw_passwd;
74 #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW)
75 spw = getspnam(pw->pw_name);
78 /* Check for users with no password. */
79 if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0)
82 pw_password = spw->sp_pwdp;
84 #endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */
86 if (pw_password[0] != '\0')
91 #ifdef HAVE_MD5_PASSWORDS
92 if (is_md5_salt(salt))
93 encrypted_password = md5_crypt(password, salt);
95 encrypted_password = crypt(password, salt);
96 #else /* HAVE_MD5_PASSWORDS */
97 encrypted_password = crypt(password, salt);
98 #endif /* HAVE_MD5_PASSWORDS */
100 /* Authentication is accepted if the encrypted passwords are identical. */
101 return (strcmp(encrypted_password, pw_password) == 0);
103 #endif /* !USE_PAM */