blob: e64e6568214c900a23ad3c94fd10673c953fc32e [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 Millerbeb4ba51999-12-28 15:09:35 +110012#ifndef USE_PAM
Damien Millerdd1c7ba1999-11-19 15:53:20 +110013
Damien Miller1bead332000-04-30 00:47:29 +100014RCSID("$Id: auth-passwd.c,v 1.19 2000/04/29 14:47:29 damien Exp $");
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
16#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 Millerbeb4ba51999-12-28 15:09:35 +110031#if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT)
32# include "md5crypt.h"
33#endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */
Damien Millerdd1c7ba1999-11-19 15:53:20 +110034
Damien Miller95def091999-11-25 00:26:21 +110035/*
36 * Tries to authenticate the user using password. Returns true if
37 * authentication succeeds.
38 */
Damien Miller4af51302000-04-16 11:18:38 +100039int
Damien Miller95def091999-11-25 00:26:21 +110040auth_password(struct passwd * pw, const char *password)
Damien Millerd4a8b7e1999-10-27 13:42:43 +100041{
Damien Miller95def091999-11-25 00:26:21 +110042 extern ServerOptions options;
43 char *encrypted_password;
Damien Miller2e1b0821999-12-25 10:11:29 +110044 char *pw_password;
45 char *salt;
Damien Miller2cb210f1999-11-13 15:40:10 +110046#ifdef HAVE_SHADOW_H
Damien Miller95def091999-11-25 00:26:21 +110047 struct spwd *spw;
Damien Miller2cb210f1999-11-13 15:40:10 +110048#endif
Damien Miller1fa154b2000-01-23 10:32:03 +110049#ifdef WITH_AIXAUTHENTICATE
50 char *authmsg;
51 char *loginmsg;
52 int reenter = 1;
53#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100054
Damien Millerece22a81999-12-30 09:48:15 +110055 /* deny if no user. */
56 if (pw == NULL)
57 return 0;
Damien Miller5428f641999-11-25 11:54:57 +110058 if (pw->pw_uid == 0 && options.permit_root_login == 2)
Damien Miller95def091999-11-25 00:26:21 +110059 return 0;
Damien Miller5428f641999-11-25 11:54:57 +110060 if (*password == '\0' && options.permit_empty_passwd == 0)
Damien Miller95def091999-11-25 00:26:21 +110061 return 0;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100062
Damien Millerd4a8b7e1999-10-27 13:42:43 +100063#ifdef SKEY
Damien Miller95def091999-11-25 00:26:21 +110064 if (options.skey_authentication == 1) {
Damien Milleraae6c611999-12-06 11:47:28 +110065 int ret = auth_skey_password(pw, password);
66 if (ret == 1 || ret == 0)
67 return ret;
Damien Miller95def091999-11-25 00:26:21 +110068 /* Fall back to ordinary passwd authentication. */
69 }
Damien Millerd4a8b7e1999-10-27 13:42:43 +100070#endif
Damien Miller1fa154b2000-01-23 10:32:03 +110071
72#ifdef WITH_AIXAUTHENTICATE
73 return (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0);
74#endif
75
Damien Milleraae6c611999-12-06 11:47:28 +110076#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;
Damien Miller95def091999-11-25 00:26:21 +110081 /* Fall back to ordinary passwd authentication. */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100082 }
Damien Milleraae6c611999-12-06 11:47:28 +110083#endif
Damien Miller95def091999-11-25 00:26:21 +110084
85 /* Check for users with no password. */
Damien Miller5428f641999-11-25 11:54:57 +110086 if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0)
Damien Miller95def091999-11-25 00:26:21 +110087 return 1;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100088
Damien Miller2e1b0821999-12-25 10:11:29 +110089 pw_password = pw->pw_passwd;
90
Damien Millercb7e5f91999-12-21 21:03:09 +110091#if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW)
Damien Miller95def091999-11-25 00:26:21 +110092 spw = getspnam(pw->pw_name);
Damien Miller8eb0fd61999-12-31 08:49:13 +110093 if (spw != NULL)
94 {
95 /* Check for users with no password. */
96 if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0)
97 return 1;
Damien Miller2cb210f1999-11-13 15:40:10 +110098
Damien Miller8eb0fd61999-12-31 08:49:13 +110099 pw_password = spw->sp_pwdp;
100 }
Damien Millercb7e5f91999-12-21 21:03:09 +1100101#endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */
Damien Miller2e1b0821999-12-25 10:11:29 +1100102
103 if (pw_password[0] != '\0')
104 salt = pw_password;
105 else
106 salt = "xx";
107
108#ifdef HAVE_MD5_PASSWORDS
109 if (is_md5_salt(salt))
110 encrypted_password = md5_crypt(password, salt);
111 else
112 encrypted_password = crypt(password, salt);
113#else /* HAVE_MD5_PASSWORDS */
Damien Miller1bead332000-04-30 00:47:29 +1000114# ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW
115 encrypted_password = bigcrypt(password, salt);
116# else
Damien Miller2e1b0821999-12-25 10:11:29 +1100117 encrypted_password = crypt(password, salt);
Damien Miller1bead332000-04-30 00:47:29 +1000118# endif /* HAVE_HPUX_TRUSTED_SYSTEM_PW */
Damien Miller2e1b0821999-12-25 10:11:29 +1100119#endif /* HAVE_MD5_PASSWORDS */
120
121 /* Authentication is accepted if the encrypted passwords are identical. */
122 return (strcmp(encrypted_password, pw_password) == 0);
Damien Millerd4a8b7e1999-10-27 13:42:43 +1000123}
Damien Millerbeb4ba51999-12-28 15:09:35 +1100124#endif /* !USE_PAM */