blob: 93756e9e64ff80b573ed750d508827f254e7d003 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 * 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 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +10009
10#include "includes.h"
Damien Millerdd1c7ba1999-11-19 15:53:20 +110011
Damien Miller6536c7d2000-06-22 21:32:31 +100012RCSID("$OpenBSD: auth-passwd.c,v 1.16 2000/06/20 01:39:38 markus Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
Damien Millerb8c656e2000-06-28 15:22:41 +100014#if !defined(USE_PAM) && !defined(HAVE_OSF_SIA)
15
Damien Millerd4a8b7e1999-10-27 13:42:43 +100016#include "packet.h"
17#include "ssh.h"
18#include "servconf.h"
19#include "xmalloc.h"
Damien Miller2cb210f1999-11-13 15:40:10 +110020
Damien Miller1fa154b2000-01-23 10:32:03 +110021#ifdef WITH_AIXAUTHENTICATE
Damien Miller1bead332000-04-30 00:47:29 +100022# include <login.h>
Damien Miller1fa154b2000-01-23 10:32:03 +110023#endif
Damien Miller1bead332000-04-30 00:47:29 +100024#ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW
25# include <hpsecurity.h>
26# include <prot.h>
27#endif
Damien Miller2cb210f1999-11-13 15:40:10 +110028#ifdef HAVE_SHADOW_H
Damien Millerbeb4ba51999-12-28 15:09:35 +110029# include <shadow.h>
Damien Miller2cb210f1999-11-13 15:40:10 +110030#endif
Damien Millerdfc83f42000-05-20 15:02:59 +100031#ifdef HAVE_GETPWANAM
32# include <sys/label.h>
33# include <sys/audit.h>
34# include <pwdadj.h>
35#endif
Damien Millerbeb4ba51999-12-28 15:09:35 +110036#if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT)
37# include "md5crypt.h"
38#endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */
Damien Millerdd1c7ba1999-11-19 15:53:20 +110039
Damien Miller95def091999-11-25 00:26:21 +110040/*
41 * Tries to authenticate the user using password. Returns true if
42 * authentication succeeds.
43 */
Damien Miller4af51302000-04-16 11:18:38 +100044int
Damien Miller95def091999-11-25 00:26:21 +110045auth_password(struct passwd * pw, const char *password)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100046{
Damien Miller95def091999-11-25 00:26:21 +110047 extern ServerOptions options;
48 char *encrypted_password;
Damien Miller2e1b0821999-12-25 10:11:29 +110049 char *pw_password;
50 char *salt;
Damien Miller2cb210f1999-11-13 15:40:10 +110051#ifdef HAVE_SHADOW_H
Damien Miller95def091999-11-25 00:26:21 +110052 struct spwd *spw;
Damien Miller2cb210f1999-11-13 15:40:10 +110053#endif
Damien Millerdfc83f42000-05-20 15:02:59 +100054#ifdef HAVE_GETPWANAM
55 struct passwd_adjunct *spw;
56#endif
Damien Miller1fa154b2000-01-23 10:32:03 +110057#ifdef WITH_AIXAUTHENTICATE
58 char *authmsg;
59 char *loginmsg;
60 int reenter = 1;
61#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100062
Damien Millerece22a81999-12-30 09:48:15 +110063 /* deny if no user. */
64 if (pw == NULL)
65 return 0;
Damien Miller5428f641999-11-25 11:54:57 +110066 if (pw->pw_uid == 0 && options.permit_root_login == 2)
Damien Miller95def091999-11-25 00:26:21 +110067 return 0;
Damien Miller5428f641999-11-25 11:54:57 +110068 if (*password == '\0' && options.permit_empty_passwd == 0)
Damien Miller95def091999-11-25 00:26:21 +110069 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100070
Damien Millerd4a8b7e1999-10-27 13:42:43 +100071#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +110072 if (options.skey_authentication == 1) {
Damien Milleraae6c611999-12-06 11:47:28 +110073 int ret = auth_skey_password(pw, password);
74 if (ret == 1 || ret == 0)
75 return ret;
Damien Miller95def091999-11-25 00:26:21 +110076 /* Fall back to ordinary passwd authentication. */
77 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +100078#endif
Damien Miller1fa154b2000-01-23 10:32:03 +110079
80#ifdef WITH_AIXAUTHENTICATE
81 return (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0);
82#endif
83
Damien Milleraae6c611999-12-06 11:47:28 +110084#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;
Damien Miller95def091999-11-25 00:26:21 +110089 /* Fall back to ordinary passwd authentication. */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100090 }
Damien Milleraae6c611999-12-06 11:47:28 +110091#endif
Damien Miller95def091999-11-25 00:26:21 +110092
93 /* Check for users with no password. */
Damien Miller5428f641999-11-25 11:54:57 +110094 if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0)
Damien Miller95def091999-11-25 00:26:21 +110095 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100096
Damien Miller2e1b0821999-12-25 10:11:29 +110097 pw_password = pw->pw_passwd;
98
Damien Millercb7e5f91999-12-21 21:03:09 +110099#if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW)
Damien Miller95def091999-11-25 00:26:21 +1100100 spw = getspnam(pw->pw_name);
Damien Miller8eb0fd61999-12-31 08:49:13 +1100101 if (spw != NULL)
102 {
103 /* Check for users with no password. */
104 if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0)
105 return 1;
Damien Miller2cb210f1999-11-13 15:40:10 +1100106
Damien Miller8eb0fd61999-12-31 08:49:13 +1100107 pw_password = spw->sp_pwdp;
108 }
Damien Millercb7e5f91999-12-21 21:03:09 +1100109#endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */
Damien Millerdfc83f42000-05-20 15:02:59 +1000110#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) */
Damien Miller2e1b0821999-12-25 10:11:29 +1100120
121 if (pw_password[0] != '\0')
122 salt = pw_password;
123 else
124 salt = "xx";
125
126#ifdef HAVE_MD5_PASSWORDS
127 if (is_md5_salt(salt))
128 encrypted_password = md5_crypt(password, salt);
129 else
130 encrypted_password = crypt(password, salt);
131#else /* HAVE_MD5_PASSWORDS */
Damien Miller1bead332000-04-30 00:47:29 +1000132# ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW
133 encrypted_password = bigcrypt(password, salt);
134# else
Damien Miller2e1b0821999-12-25 10:11:29 +1100135 encrypted_password = crypt(password, salt);
Damien Miller1bead332000-04-30 00:47:29 +1000136# endif /* HAVE_HPUX_TRUSTED_SYSTEM_PW */
Damien Miller2e1b0821999-12-25 10:11:29 +1100137#endif /* HAVE_MD5_PASSWORDS */
138
139 /* Authentication is accepted if the encrypted passwords are identical. */
140 return (strcmp(encrypted_password, pw_password) == 0);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000141}
Damien Millerb8c656e2000-06-28 15:22:41 +1000142#endif /* !USE_PAM && !HAVE_OSF_SIA */