]> andersk Git - openssh.git/blame - auth-passwd.c
- Merged more OpenBSD CVS changes:
[openssh.git] / auth-passwd.c
CommitLineData
8efc0c15 1/*
2
3auth-passwd.c
4
5Author: Tatu Ylonen <ylo@cs.hut.fi>
6
7Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 All rights reserved
9
10Created: Sat Mar 18 05:11:38 1995 ylo
11
12Password authentication. This file contains the functions to check whether
13the password is valid for the user.
14
15*/
16
17#include "includes.h"
18RCSID("$Id$");
19
20#include "packet.h"
21#include "ssh.h"
22#include "servconf.h"
23#include "xmalloc.h"
24
8efc0c15 25/* Tries to authenticate the user using password. Returns true if
26 authentication succeeds. */
27
28int auth_password(struct passwd *pw, const char *password)
29{
30 extern ServerOptions options;
31 char *encrypted_password;
32
33 if (pw->pw_uid == 0 && options.permit_root_login == 2)
34 {
35 /*packet_send_debug("Server does not permit root login with password.");*/
36 return 0;
37 }
38
39 if (*password == '\0' && options.permit_empty_passwd == 0)
40 {
41 /*packet_send_debug("Server does not permit empty password login.");*/
42 return 0;
43 }
44
45 /* deny if no user. */
46 if (pw == NULL)
47 return 0;
48
8efc0c15 49#ifdef SKEY
50 if (options.skey_authentication == 1) {
51 if (strncasecmp(password, "s/key", 5) == 0) {
52 char *skeyinfo = skey_keyinfo(pw->pw_name);
53 if(skeyinfo == NULL){
54 debug("generating fake skeyinfo for %.100s.", pw->pw_name);
55 skeyinfo = skey_fake_keyinfo(pw->pw_name);
56 }
57 if(skeyinfo != NULL)
58 packet_send_debug(skeyinfo);
59 /* Try again. */
60 return 0;
61 }
62 else if (skey_haskey(pw->pw_name) == 0 &&
63 skey_passcheck(pw->pw_name, (char *)password) != -1) {
64 /* Authentication succeeded. */
65 return 1;
66 }
67 /* Fall back to ordinary passwd authentication. */
68 }
69#endif
70
71#if defined(KRB4)
72 /* Support for Kerberos v4 authentication - Dug Song <dugsong@UMICH.EDU> */
73 if (options.kerberos_authentication)
74 {
75 AUTH_DAT adata;
76 KTEXT_ST tkt;
77 struct hostent *hp;
78 unsigned long faddr;
6a17f9c2 79 char localhost[MAXHOSTNAMELEN];
80 char phost[INST_SZ];
81 char realm[REALM_SZ];
8efc0c15 82 int r;
83
84 /* Try Kerberos password authentication only for non-root
85 users and only if Kerberos is installed. */
86 if (pw->pw_uid != 0 && krb_get_lrealm(realm, 1) == KSUCCESS) {
87
88 /* Set up our ticket file. */
6a17f9c2 89 if (!krb4_init(pw->pw_uid)) {
90 log("Couldn't initialize Kerberos ticket file for %s!", pw->pw_name);
8efc0c15 91 goto kerberos_auth_failure;
92 }
93 /* Try to get TGT using our password. */
94 r = krb_get_pw_in_tkt((char *)pw->pw_name, "", realm, "krbtgt", realm,
95 DEFAULT_TKT_LIFE, (char *)password);
96 if (r != INTK_OK) {
97 packet_send_debug("Kerberos V4 password authentication for %s "
98 "failed: %s", pw->pw_name, krb_err_txt[r]);
99 goto kerberos_auth_failure;
100 }
101 /* Successful authentication. */
6a17f9c2 102 chown(tkt_string(), pw->pw_uid, pw->pw_gid);
8efc0c15 103
104 /* Now that we have a TGT, try to get a local "rcmd" ticket to
105 ensure that we are not talking to a bogus Kerberos server. */
6a17f9c2 106 (void) gethostname(localhost, sizeof(localhost));
107 (void) strlcpy(phost, (char *)krb_get_phost(localhost), INST_SZ);
8efc0c15 108 r = krb_mk_req(&tkt, KRB4_SERVICE_NAME, phost, realm, 33);
109
110 if (r == KSUCCESS) {
111 if (!(hp = gethostbyname(localhost))) {
112 log("Couldn't get local host address!");
113 goto kerberos_auth_failure;
114 }
115 memmove((void *)&faddr, (void *)hp->h_addr, sizeof(faddr));
116
117 /* Verify our "rcmd" ticket. */
118 r = krb_rd_req(&tkt, KRB4_SERVICE_NAME, phost, faddr, &adata, "");
119 if (r == RD_AP_UNDEC) {
120 /* Probably didn't have a srvtab on localhost. Allow login. */
121 log("Kerberos V4 TGT for %s unverifiable, no srvtab installed? "
122 "krb_rd_req: %s", pw->pw_name, krb_err_txt[r]);
123 }
124 else if (r != KSUCCESS) {
125 log("Kerberos V4 %s ticket unverifiable: %s",
126 KRB4_SERVICE_NAME, krb_err_txt[r]);
127 goto kerberos_auth_failure;
128 }
129 }
130 else if (r == KDC_PR_UNKNOWN) {
131 /* Allow login if no rcmd service exists, but log the error. */
132 log("Kerberos V4 TGT for %s unverifiable: %s; %s.%s "
133 "not registered, or srvtab is wrong?", pw->pw_name,
134 krb_err_txt[r], KRB4_SERVICE_NAME, phost);
135 }
136 else {
137 /* TGT is bad, forget it. Possibly spoofed! */
138 packet_send_debug("WARNING: Kerberos V4 TGT possibly spoofed for"
139 "%s: %s", pw->pw_name, krb_err_txt[r]);
140 goto kerberos_auth_failure;
141 }
142
143 /* Authentication succeeded. */
144 return 1;
145
146 kerberos_auth_failure:
6a17f9c2 147 krb4_cleanup_proc(NULL);
148
149 if (!options.kerberos_or_local_passwd)
150 return 0;
8efc0c15 151 }
152 else {
153 /* Logging in as root or no local Kerberos realm. */
154 packet_send_debug("Unable to authenticate to Kerberos.");
155 }
156 /* Fall back to ordinary passwd authentication. */
157 }
158#endif /* KRB4 */
159
160 /* Check for users with no password. */
161 if (strcmp(password, "") == 0 && strcmp(pw->pw_passwd, "") == 0)
162 {
163 packet_send_debug("Login permitted without a password because the account has no password.");
164 return 1; /* The user has no password and an empty password was tried. */
165 }
166
167 /* Encrypt the candidate password using the proper salt. */
168 encrypted_password = crypt(password,
169 (pw->pw_passwd[0] && pw->pw_passwd[1]) ?
170 pw->pw_passwd : "xx");
171
172 /* Authentication is accepted if the encrypted passwords are identical. */
173 return (strcmp(encrypted_password, pw->pw_passwd) == 0);
8efc0c15 174}
This page took 0.282477 seconds and 5 git commands to generate.