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