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