]> andersk Git - openssh.git/blob - auth-passwd.c
- Merge HP-UX fixes and TCB support from Ged Lodder <lodder@yacc.com.au>
[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 WITH_AIXAUTHENTICATE
22 # include <login.h>
23 #endif
24 #ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW
25 # include <hpsecurity.h>
26 # include <prot.h>
27 #endif
28 #ifdef HAVE_SHADOW_H
29 # include <shadow.h>
30 #endif
31 #if defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT)
32 # include "md5crypt.h"
33 #endif /* defined(HAVE_MD5_PASSWORDS) && !defined(HAVE_MD5_CRYPT) */
34
35 /*
36  * Tries to authenticate the user using password.  Returns true if
37  * authentication succeeds.
38  */
39 int
40 auth_password(struct passwd * pw, const char *password)
41 {
42         extern ServerOptions options;
43         char *encrypted_password;
44         char *pw_password;
45         char *salt;
46 #ifdef HAVE_SHADOW_H
47         struct spwd *spw;
48 #endif
49 #ifdef WITH_AIXAUTHENTICATE
50         char *authmsg;
51         char *loginmsg;
52         int reenter = 1;
53 #endif
54
55         /* deny if no user. */
56         if (pw == NULL)
57                 return 0;
58         if (pw->pw_uid == 0 && options.permit_root_login == 2)
59                 return 0;
60         if (*password == '\0' && options.permit_empty_passwd == 0)
61                 return 0;
62
63 #ifdef SKEY
64         if (options.skey_authentication == 1) {
65                 int ret = auth_skey_password(pw, password);
66                 if (ret == 1 || ret == 0)
67                         return ret;
68                 /* Fall back to ordinary passwd authentication. */
69         }
70 #endif
71
72 #ifdef WITH_AIXAUTHENTICATE
73         return (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0);
74 #endif
75
76 #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;
81                 /* Fall back to ordinary passwd authentication. */
82         }
83 #endif
84
85         /* Check for users with no password. */
86         if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0)
87                 return 1;
88
89         pw_password = pw->pw_passwd;
90
91 #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW)
92         spw = getspnam(pw->pw_name);
93         if (spw != NULL) 
94         {
95                 /* Check for users with no password. */
96                 if (strcmp(password, "") == 0 && strcmp(spw->sp_pwdp, "") == 0)
97                         return 1;
98
99                 pw_password = spw->sp_pwdp;
100         }
101 #endif /* defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) */
102
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 */    
114 # ifdef HAVE_HPUX_TRUSTED_SYSTEM_PW
115         encrypted_password = bigcrypt(password, salt);
116 # else
117         encrypted_password = crypt(password, salt);
118 # endif /* HAVE_HPUX_TRUSTED_SYSTEM_PW */
119 #endif /* HAVE_MD5_PASSWORDS */    
120
121         /* Authentication is accepted if the encrypted passwords are identical. */
122         return (strcmp(encrypted_password, pw_password) == 0);
123 }
124 #endif /* !USE_PAM */
This page took 0.047951 seconds and 5 git commands to generate.