]> andersk Git - openssh.git/blob - auth-passwd.c
- Fix password support on systems with a mixture of shadowed and
[openssh.git] / auth-passwd.c
1 /*
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  */
9
10 #include "includes.h"
11
12 #ifndef USE_PAM
13
14 RCSID("$Id$");
15
16 #include "packet.h"
17 #include "ssh.h"
18 #include "servconf.h"
19 #include "xmalloc.h"
20
21 #ifdef HAVE_SHADOW_H
22 # include <shadow.h>
23 #endif
24 #if defined(HAVE_CRYPT_H) && !defined(CRYPT_H_BREAKS_BUILD)
25 # include <crypt.h>
26 #endif /* defined(HAVE_CRYPT_H) && !defined(CRYPT_H_BREAKS_BUILD) */
27 #if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT)
28 # include "md5crypt.h"
29 #endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */
30
31 /*
32  * Tries to authenticate the user using password.  Returns true if
33  * authentication succeeds.
34  */
35 int 
36 auth_password(struct passwd * pw, const char *password)
37 {
38         extern ServerOptions options;
39         char *encrypted_password;
40         char *pw_password;
41         char *salt;
42 #ifdef HAVE_SHADOW_H
43         struct spwd *spw;
44 #endif
45
46         /* deny if no user. */
47         if (pw == NULL)
48                 return 0;
49         if (pw->pw_uid == 0 && options.permit_root_login == 2)
50                 return 0;
51         if (*password == '\0' && options.permit_empty_passwd == 0)
52                 return 0;
53
54 #ifdef SKEY
55         if (options.skey_authentication == 1) {
56                 int ret = auth_skey_password(pw, password);
57                 if (ret == 1 || ret == 0)
58                         return ret;
59                 /* Fall back to ordinary passwd authentication. */
60         }
61 #endif
62 #ifdef KRB4
63         if (options.kerberos_authentication == 1) {
64                 int ret = auth_krb4_password(pw, password);
65                 if (ret == 1 || ret == 0)
66                         return ret;
67                 /* Fall back to ordinary passwd authentication. */
68         }
69 #endif
70
71         /* Check for users with no password. */
72         if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0)
73                 return 1;
74
75         pw_password = pw->pw_passwd;
76
77 #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW)
78         spw = getspnam(pw->pw_name);
79         if (spw != NULL) 
80         {
81                 /* Check for users with no password. */
82                 if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0)
83                         return 1;
84
85                 pw_password = spw->sp_pwdp;
86         }
87 #endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */
88
89         if (pw_password[0] != '\0')
90                 salt = pw_password;
91         else
92                 salt = "xx";
93
94 #ifdef HAVE_MD5_PASSWORDS
95         if (is_md5_salt(salt))
96                 encrypted_password = md5_crypt(password, salt);
97         else
98                 encrypted_password = crypt(password, salt);
99 #else /* HAVE_MD5_PASSWORDS */    
100         encrypted_password = crypt(password, salt);
101 #endif /* HAVE_MD5_PASSWORDS */    
102
103         /* Authentication is accepted if the encrypted passwords are identical. */
104         return (strcmp(encrypted_password, pw_password) == 0);
105 }
106 #endif /* !USE_PAM */
This page took 0.605043 seconds and 5 git commands to generate.