diff options
Diffstat (limited to 'auth-krb4.c')
-rw-r--r-- | auth-krb4.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/auth-krb4.c b/auth-krb4.c index 031dcd301..f7a144f9d 100644 --- a/auth-krb4.c +++ b/auth-krb4.c | |||
@@ -23,7 +23,7 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "includes.h" | 25 | #include "includes.h" |
26 | RCSID("$OpenBSD: auth-krb4.c,v 1.24 2001/06/26 16:15:22 dugsong Exp $"); | 26 | RCSID("$OpenBSD: auth-krb4.c,v 1.25 2001/12/19 07:18:56 deraadt Exp $"); |
27 | 27 | ||
28 | #include "ssh.h" | 28 | #include "ssh.h" |
29 | #include "ssh1.h" | 29 | #include "ssh1.h" |
@@ -49,7 +49,7 @@ krb4_init(void *context) | |||
49 | const char *tkt_root = TKT_ROOT; | 49 | const char *tkt_root = TKT_ROOT; |
50 | struct stat st; | 50 | struct stat st; |
51 | int fd; | 51 | int fd; |
52 | 52 | ||
53 | if (!authctxt->krb4_ticket_file) { | 53 | if (!authctxt->krb4_ticket_file) { |
54 | /* Set unique ticket string manually since we're still root. */ | 54 | /* Set unique ticket string manually since we're still root. */ |
55 | authctxt->krb4_ticket_file = xmalloc(MAXPATHLEN); | 55 | authctxt->krb4_ticket_file = xmalloc(MAXPATHLEN); |
@@ -79,13 +79,13 @@ krb4_init(void *context) | |||
79 | } | 79 | } |
80 | /* Failure - cancel cleanup function, leaving ticket for inspection. */ | 80 | /* Failure - cancel cleanup function, leaving ticket for inspection. */ |
81 | log("WARNING: bad ticket file %s", authctxt->krb4_ticket_file); | 81 | log("WARNING: bad ticket file %s", authctxt->krb4_ticket_file); |
82 | 82 | ||
83 | fatal_remove_cleanup(krb4_cleanup_proc, authctxt); | 83 | fatal_remove_cleanup(krb4_cleanup_proc, authctxt); |
84 | cleanup_registered = 0; | 84 | cleanup_registered = 0; |
85 | 85 | ||
86 | xfree(authctxt->krb4_ticket_file); | 86 | xfree(authctxt->krb4_ticket_file); |
87 | authctxt->krb4_ticket_file = NULL; | 87 | authctxt->krb4_ticket_file = NULL; |
88 | 88 | ||
89 | return (0); | 89 | return (0); |
90 | } | 90 | } |
91 | 91 | ||
@@ -103,10 +103,10 @@ auth_krb4_password(Authctxt *authctxt, const char *password) | |||
103 | char localhost[MAXHOSTNAMELEN], phost[INST_SZ], realm[REALM_SZ]; | 103 | char localhost[MAXHOSTNAMELEN], phost[INST_SZ], realm[REALM_SZ]; |
104 | u_int32_t faddr; | 104 | u_int32_t faddr; |
105 | int r; | 105 | int r; |
106 | 106 | ||
107 | if ((pw = authctxt->pw) == NULL) | 107 | if ((pw = authctxt->pw) == NULL) |
108 | return (0); | 108 | return (0); |
109 | 109 | ||
110 | /* | 110 | /* |
111 | * Try Kerberos password authentication only for non-root | 111 | * Try Kerberos password authentication only for non-root |
112 | * users and only if Kerberos is installed. | 112 | * users and only if Kerberos is installed. |
@@ -128,7 +128,7 @@ auth_krb4_password(Authctxt *authctxt, const char *password) | |||
128 | } | 128 | } |
129 | /* Successful authentication. */ | 129 | /* Successful authentication. */ |
130 | chown(tkt_string(), pw->pw_uid, pw->pw_gid); | 130 | chown(tkt_string(), pw->pw_uid, pw->pw_gid); |
131 | 131 | ||
132 | /* | 132 | /* |
133 | * Now that we have a TGT, try to get a local | 133 | * Now that we have a TGT, try to get a local |
134 | * "rcmd" ticket to ensure that we are not talking | 134 | * "rcmd" ticket to ensure that we are not talking |
@@ -138,7 +138,7 @@ auth_krb4_password(Authctxt *authctxt, const char *password) | |||
138 | strlcpy(phost, (char *)krb_get_phost(localhost), | 138 | strlcpy(phost, (char *)krb_get_phost(localhost), |
139 | sizeof(phost)); | 139 | sizeof(phost)); |
140 | r = krb_mk_req(&tkt, KRB4_SERVICE_NAME, phost, realm, 33); | 140 | r = krb_mk_req(&tkt, KRB4_SERVICE_NAME, phost, realm, 33); |
141 | 141 | ||
142 | if (r == KSUCCESS) { | 142 | if (r == KSUCCESS) { |
143 | if ((hp = gethostbyname(localhost)) == NULL) { | 143 | if ((hp = gethostbyname(localhost)) == NULL) { |
144 | log("Couldn't get local host address!"); | 144 | log("Couldn't get local host address!"); |
@@ -146,7 +146,7 @@ auth_krb4_password(Authctxt *authctxt, const char *password) | |||
146 | } | 146 | } |
147 | memmove((void *)&faddr, (void *)hp->h_addr, | 147 | memmove((void *)&faddr, (void *)hp->h_addr, |
148 | sizeof(faddr)); | 148 | sizeof(faddr)); |
149 | 149 | ||
150 | /* Verify our "rcmd" ticket. */ | 150 | /* Verify our "rcmd" ticket. */ |
151 | r = krb_rd_req(&tkt, KRB4_SERVICE_NAME, phost, | 151 | r = krb_rd_req(&tkt, KRB4_SERVICE_NAME, phost, |
152 | faddr, &adata, ""); | 152 | faddr, &adata, ""); |
@@ -186,13 +186,13 @@ auth_krb4_password(Authctxt *authctxt, const char *password) | |||
186 | } else | 186 | } else |
187 | /* Logging in as root or no local Kerberos realm. */ | 187 | /* Logging in as root or no local Kerberos realm. */ |
188 | debug("Unable to authenticate to Kerberos."); | 188 | debug("Unable to authenticate to Kerberos."); |
189 | 189 | ||
190 | failure: | 190 | failure: |
191 | krb4_cleanup_proc(authctxt); | 191 | krb4_cleanup_proc(authctxt); |
192 | 192 | ||
193 | if (!options.kerberos_or_local_passwd) | 193 | if (!options.kerberos_or_local_passwd) |
194 | return (0); | 194 | return (0); |
195 | 195 | ||
196 | /* Fall back to ordinary passwd authentication. */ | 196 | /* Fall back to ordinary passwd authentication. */ |
197 | return (-1); | 197 | return (-1); |
198 | } | 198 | } |
@@ -220,9 +220,9 @@ auth_krb4(Authctxt *authctxt, KTEXT auth, char **client) | |||
220 | socklen_t slen; | 220 | socklen_t slen; |
221 | u_int cksum; | 221 | u_int cksum; |
222 | int r, s; | 222 | int r, s; |
223 | 223 | ||
224 | s = packet_get_connection_in(); | 224 | s = packet_get_connection_in(); |
225 | 225 | ||
226 | slen = sizeof(local); | 226 | slen = sizeof(local); |
227 | memset(&local, 0, sizeof(local)); | 227 | memset(&local, 0, sizeof(local)); |
228 | if (getsockname(s, (struct sockaddr *) & local, &slen) < 0) | 228 | if (getsockname(s, (struct sockaddr *) & local, &slen) < 0) |
@@ -235,7 +235,7 @@ auth_krb4(Authctxt *authctxt, KTEXT auth, char **client) | |||
235 | } | 235 | } |
236 | instance[0] = '*'; | 236 | instance[0] = '*'; |
237 | instance[1] = 0; | 237 | instance[1] = 0; |
238 | 238 | ||
239 | /* Get the encrypted request, challenge, and session key. */ | 239 | /* Get the encrypted request, challenge, and session key. */ |
240 | if ((r = krb_rd_req(auth, KRB4_SERVICE_NAME, instance, | 240 | if ((r = krb_rd_req(auth, KRB4_SERVICE_NAME, instance, |
241 | 0, &adat, ""))) { | 241 | 0, &adat, ""))) { |
@@ -243,11 +243,11 @@ auth_krb4(Authctxt *authctxt, KTEXT auth, char **client) | |||
243 | return (0); | 243 | return (0); |
244 | } | 244 | } |
245 | des_key_sched((des_cblock *) adat.session, schedule); | 245 | des_key_sched((des_cblock *) adat.session, schedule); |
246 | 246 | ||
247 | *client = xmalloc(MAX_K_NAME_SZ); | 247 | *client = xmalloc(MAX_K_NAME_SZ); |
248 | (void) snprintf(*client, MAX_K_NAME_SZ, "%s%s%s@%s", adat.pname, | 248 | (void) snprintf(*client, MAX_K_NAME_SZ, "%s%s%s@%s", adat.pname, |
249 | *adat.pinst ? "." : "", adat.pinst, adat.prealm); | 249 | *adat.pinst ? "." : "", adat.pinst, adat.prealm); |
250 | 250 | ||
251 | /* Check ~/.klogin authorization now. */ | 251 | /* Check ~/.klogin authorization now. */ |
252 | if (kuserok(&adat, authctxt->user) != KSUCCESS) { | 252 | if (kuserok(&adat, authctxt->user) != KSUCCESS) { |
253 | log("Kerberos v4 .klogin authorization failed for %s to " | 253 | log("Kerberos v4 .klogin authorization failed for %s to " |
@@ -259,7 +259,7 @@ auth_krb4(Authctxt *authctxt, KTEXT auth, char **client) | |||
259 | session key. */ | 259 | session key. */ |
260 | cksum = adat.checksum + 1; | 260 | cksum = adat.checksum + 1; |
261 | cksum = htonl(cksum); | 261 | cksum = htonl(cksum); |
262 | 262 | ||
263 | /* If we can't successfully encrypt the checksum, we send back an | 263 | /* If we can't successfully encrypt the checksum, we send back an |
264 | empty message, admitting our failure. */ | 264 | empty message, admitting our failure. */ |
265 | if ((r = krb_mk_priv((u_char *) & cksum, reply.dat, sizeof(cksum) + 1, | 265 | if ((r = krb_mk_priv((u_char *) & cksum, reply.dat, sizeof(cksum) + 1, |
@@ -269,10 +269,10 @@ auth_krb4(Authctxt *authctxt, KTEXT auth, char **client) | |||
269 | reply.length = 0; | 269 | reply.length = 0; |
270 | } else | 270 | } else |
271 | reply.length = r; | 271 | reply.length = r; |
272 | 272 | ||
273 | /* Clear session key. */ | 273 | /* Clear session key. */ |
274 | memset(&adat.session, 0, sizeof(&adat.session)); | 274 | memset(&adat.session, 0, sizeof(&adat.session)); |
275 | 275 | ||
276 | packet_start(SSH_SMSG_AUTH_KERBEROS_RESPONSE); | 276 | packet_start(SSH_SMSG_AUTH_KERBEROS_RESPONSE); |
277 | packet_put_string((char *) reply.dat, reply.length); | 277 | packet_put_string((char *) reply.dat, reply.length); |
278 | packet_send(); | 278 | packet_send(); |
@@ -287,19 +287,19 @@ auth_krb4_tgt(Authctxt *authctxt, const char *string) | |||
287 | { | 287 | { |
288 | CREDENTIALS creds; | 288 | CREDENTIALS creds; |
289 | struct passwd *pw; | 289 | struct passwd *pw; |
290 | 290 | ||
291 | if ((pw = authctxt->pw) == NULL) | 291 | if ((pw = authctxt->pw) == NULL) |
292 | goto failure; | 292 | goto failure; |
293 | 293 | ||
294 | temporarily_use_uid(pw); | 294 | temporarily_use_uid(pw); |
295 | 295 | ||
296 | if (!radix_to_creds(string, &creds)) { | 296 | if (!radix_to_creds(string, &creds)) { |
297 | log("Protocol error decoding Kerberos v4 TGT"); | 297 | log("Protocol error decoding Kerberos v4 TGT"); |
298 | goto failure; | 298 | goto failure; |
299 | } | 299 | } |
300 | if (strncmp(creds.service, "", 1) == 0) /* backward compatibility */ | 300 | if (strncmp(creds.service, "", 1) == 0) /* backward compatibility */ |
301 | strlcpy(creds.service, "krbtgt", sizeof creds.service); | 301 | strlcpy(creds.service, "krbtgt", sizeof creds.service); |
302 | 302 | ||
303 | if (strcmp(creds.service, "krbtgt")) { | 303 | if (strcmp(creds.service, "krbtgt")) { |
304 | log("Kerberos v4 TGT (%s%s%s@%s) rejected for %s", | 304 | log("Kerberos v4 TGT (%s%s%s@%s) rejected for %s", |
305 | creds.pname, creds.pinst[0] ? "." : "", creds.pinst, | 305 | creds.pname, creds.pinst[0] ? "." : "", creds.pinst, |
@@ -308,10 +308,10 @@ auth_krb4_tgt(Authctxt *authctxt, const char *string) | |||
308 | } | 308 | } |
309 | if (!krb4_init(authctxt)) | 309 | if (!krb4_init(authctxt)) |
310 | goto failure; | 310 | goto failure; |
311 | 311 | ||
312 | if (in_tkt(creds.pname, creds.pinst) != KSUCCESS) | 312 | if (in_tkt(creds.pname, creds.pinst) != KSUCCESS) |
313 | goto failure; | 313 | goto failure; |
314 | 314 | ||
315 | if (save_credentials(creds.service, creds.instance, creds.realm, | 315 | if (save_credentials(creds.service, creds.instance, creds.realm, |
316 | creds.session, creds.lifetime, creds.kvno, &creds.ticket_st, | 316 | creds.session, creds.lifetime, creds.kvno, &creds.ticket_st, |
317 | creds.issue_date) != KSUCCESS) { | 317 | creds.issue_date) != KSUCCESS) { |
@@ -320,20 +320,20 @@ auth_krb4_tgt(Authctxt *authctxt, const char *string) | |||
320 | } | 320 | } |
321 | /* Successful authentication, passed all checks. */ | 321 | /* Successful authentication, passed all checks. */ |
322 | chown(tkt_string(), pw->pw_uid, pw->pw_gid); | 322 | chown(tkt_string(), pw->pw_uid, pw->pw_gid); |
323 | 323 | ||
324 | debug("Kerberos v4 TGT accepted (%s%s%s@%s)", | 324 | debug("Kerberos v4 TGT accepted (%s%s%s@%s)", |
325 | creds.pname, creds.pinst[0] ? "." : "", creds.pinst, creds.realm); | 325 | creds.pname, creds.pinst[0] ? "." : "", creds.pinst, creds.realm); |
326 | memset(&creds, 0, sizeof(creds)); | 326 | memset(&creds, 0, sizeof(creds)); |
327 | 327 | ||
328 | restore_uid(); | 328 | restore_uid(); |
329 | 329 | ||
330 | return (1); | 330 | return (1); |
331 | 331 | ||
332 | failure: | 332 | failure: |
333 | krb4_cleanup_proc(authctxt); | 333 | krb4_cleanup_proc(authctxt); |
334 | memset(&creds, 0, sizeof(creds)); | 334 | memset(&creds, 0, sizeof(creds)); |
335 | restore_uid(); | 335 | restore_uid(); |
336 | 336 | ||
337 | return (0); | 337 | return (0); |
338 | } | 338 | } |
339 | 339 | ||
@@ -343,22 +343,22 @@ auth_afs_token(Authctxt *authctxt, const char *token_string) | |||
343 | CREDENTIALS creds; | 343 | CREDENTIALS creds; |
344 | struct passwd *pw; | 344 | struct passwd *pw; |
345 | uid_t uid; | 345 | uid_t uid; |
346 | 346 | ||
347 | if ((pw = authctxt->pw) == NULL) | 347 | if ((pw = authctxt->pw) == NULL) |
348 | return (0); | 348 | return (0); |
349 | 349 | ||
350 | if (!radix_to_creds(token_string, &creds)) { | 350 | if (!radix_to_creds(token_string, &creds)) { |
351 | log("Protocol error decoding AFS token"); | 351 | log("Protocol error decoding AFS token"); |
352 | return (0); | 352 | return (0); |
353 | } | 353 | } |
354 | if (strncmp(creds.service, "", 1) == 0) /* backward compatibility */ | 354 | if (strncmp(creds.service, "", 1) == 0) /* backward compatibility */ |
355 | strlcpy(creds.service, "afs", sizeof creds.service); | 355 | strlcpy(creds.service, "afs", sizeof creds.service); |
356 | 356 | ||
357 | if (strncmp(creds.pname, "AFS ID ", 7) == 0) | 357 | if (strncmp(creds.pname, "AFS ID ", 7) == 0) |
358 | uid = atoi(creds.pname + 7); | 358 | uid = atoi(creds.pname + 7); |
359 | else | 359 | else |
360 | uid = pw->pw_uid; | 360 | uid = pw->pw_uid; |
361 | 361 | ||
362 | if (kafs_settoken(creds.realm, uid, &creds)) { | 362 | if (kafs_settoken(creds.realm, uid, &creds)) { |
363 | log("AFS token (%s@%s) rejected for %s", | 363 | log("AFS token (%s@%s) rejected for %s", |
364 | creds.pname, creds.realm, pw->pw_name); | 364 | creds.pname, creds.realm, pw->pw_name); |
@@ -367,7 +367,7 @@ auth_afs_token(Authctxt *authctxt, const char *token_string) | |||
367 | } | 367 | } |
368 | debug("AFS token accepted (%s@%s)", creds.pname, creds.realm); | 368 | debug("AFS token accepted (%s@%s)", creds.pname, creds.realm); |
369 | memset(&creds, 0, sizeof(creds)); | 369 | memset(&creds, 0, sizeof(creds)); |
370 | 370 | ||
371 | return (1); | 371 | return (1); |
372 | } | 372 | } |
373 | #endif /* AFS */ | 373 | #endif /* AFS */ |