Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / crypto / kerberosIV / appl / telnet / libtelnet / kerberos.c
CommitLineData
984263bc
MD
1/*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33/* $FreeBSD: src/crypto/kerberosIV/appl/telnet/libtelnet/kerberos.c,v 1.2.2.2 2003/02/13 21:34:35 nectar Exp $ */
1de703da 34/* $DragonFly: src/crypto/kerberosIV/appl/telnet/libtelnet/Attic/kerberos.c,v 1.2 2003/06/17 04:24:36 dillon Exp $ */
984263bc
MD
35
36/*
37 * Copyright (C) 1990 by the Massachusetts Institute of Technology
38 *
39 * Export of this software from the United States of America is assumed
40 * to require a specific license from the United States Government.
41 * It is the responsibility of any person or organization contemplating
42 * export to obtain such a license before exporting.
43 *
44 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
45 * distribute this software and its documentation for any purpose and
46 * without fee is hereby granted, provided that the above copyright
47 * notice appear in all copies and that both that copyright notice and
48 * this permission notice appear in supporting documentation, and that
49 * the name of M.I.T. not be used in advertising or publicity pertaining
50 * to distribution of the software without specific, written prior
51 * permission. M.I.T. makes no representations about the suitability of
52 * this software for any purpose. It is provided "as is" without express
53 * or implied warranty.
54 */
55
56#ifdef HAVE_CONFIG_H
57#include <config.h>
58#endif
59
60RCSID("$Id: kerberos.c,v 1.46 1999/09/16 20:41:33 assar Exp $");
61
62#ifdef KRB4
63#ifdef HAVE_SYS_TYPES_H
64#include <sys/types.h>
65#endif
66#ifdef HAVE_ARPA_TELNET_H
67#include <arpa/telnet.h>
68#endif
69#include <stdio.h>
70#define OPENSSL_DES_LIBDES_COMPATIBILITY
71#include <openssl/des.h> /* BSD wont include this in krb.h, so we do it here */
72#include <krb.h>
73#include <pwd.h>
74#include <stdlib.h>
75#include <string.h>
76#include <roken.h>
77#ifdef SOCKS
78#include <socks.h>
79#endif
80
81
82#include "encrypt.h"
83#include "auth.h"
84#include "misc.h"
85
86int kerberos4_cksum (unsigned char *, int);
87extern int auth_debug_mode;
88
89static unsigned char str_data[2048] = { IAC, SB, TELOPT_AUTHENTICATION, 0,
90 AUTHTYPE_KERBEROS_V4, };
91
92#define KRB_AUTH 0 /* Authentication data follows */
93#define KRB_REJECT 1 /* Rejected (reason might follow) */
94#define KRB_ACCEPT 2 /* Accepted */
95#define KRB_CHALLENGE 3 /* Challenge for mutual auth. */
96#define KRB_RESPONSE 4 /* Response for mutual auth. */
97
98#define KRB_FORWARD 5 /* */
99#define KRB_FORWARD_ACCEPT 6 /* */
100#define KRB_FORWARD_REJECT 7 /* */
101
102#define KRB_SERVICE_NAME "rcmd"
103
104static KTEXT_ST auth;
105static char name[ANAME_SZ];
106static AUTH_DAT adat;
107static des_cblock session_key;
108static des_cblock cred_session;
109static des_key_schedule sched;
110static des_cblock challenge;
111static int auth_done; /* XXX */
112
113static int pack_cred(CREDENTIALS *cred, unsigned char *buf);
114static int unpack_cred(unsigned char *buf, int len, CREDENTIALS *cred);
115
116
117static int
118Data(Authenticator *ap, int type, const void *d, int c)
119{
120 unsigned char *p = str_data + 4;
121 const unsigned char *cd = (const unsigned char *)d;
122
123 if (c == -1)
124 c = strlen((const char *)cd);
125
126 if (auth_debug_mode) {
127 printf("%s:%d: [%d] (%d)",
128 str_data[3] == TELQUAL_IS ? ">>>IS" : ">>>REPLY",
129 str_data[3],
130 type, c);
131 printd(d, c);
132 printf("\r\n");
133 }
134 *p++ = ap->type;
135 *p++ = ap->way;
136 *p++ = type;
137 while (c-- > 0) {
138 if ((*p++ = *cd++) == IAC)
139 *p++ = IAC;
140 }
141 *p++ = IAC;
142 *p++ = SE;
143 if (str_data[3] == TELQUAL_IS)
144 printsub('>', &str_data[2], p - (&str_data[2]));
145 return(telnet_net_write(str_data, p - str_data));
146}
147
148int
149kerberos4_init(Authenticator *ap, int server)
150{
151 FILE *fp;
152
153 if (server) {
154 str_data[3] = TELQUAL_REPLY;
155 if ((fp = fopen(KEYFILE, "r")) == NULL)
156 return(0);
157 fclose(fp);
158 } else {
159 str_data[3] = TELQUAL_IS;
160 }
161 return(1);
162}
163
164char dst_realm_buf[REALM_SZ], *dest_realm = NULL;
165int dst_realm_sz = REALM_SZ;
166
167static int
168kerberos4_send(char *name, Authenticator *ap)
169{
170 KTEXT_ST auth;
171 char instance[INST_SZ];
172 char *realm;
173 CREDENTIALS cred;
174 int r;
175
176 printf("[ Trying %s ... ]\r\n", name);
177 if (!UserNameRequested) {
178 if (auth_debug_mode) {
179 printf("Kerberos V4: no user name supplied\r\n");
180 }
181 return(0);
182 }
183
184 memset(instance, 0, sizeof(instance));
185
186 strlcpy (instance,
187 krb_get_phost(RemoteHostName),
188 INST_SZ);
189
190 realm = dest_realm ? dest_realm : krb_realmofhost(RemoteHostName);
191
192 if (!realm) {
193 printf("Kerberos V4: no realm for %s\r\n", RemoteHostName);
194 return(0);
195 }
196 r = krb_mk_req(&auth, KRB_SERVICE_NAME, instance, realm, 0L);
197 if (r) {
198 printf("mk_req failed: %s\r\n", krb_get_err_text(r));
199 return(0);
200 }
201 r = krb_get_cred(KRB_SERVICE_NAME, instance, realm, &cred);
202 if (r) {
203 printf("get_cred failed: %s\r\n", krb_get_err_text(r));
204 return(0);
205 }
206 if (!auth_sendname(UserNameRequested, strlen(UserNameRequested))) {
207 if (auth_debug_mode)
208 printf("Not enough room for user name\r\n");
209 return(0);
210 }
211 if (auth_debug_mode)
212 printf("Sent %d bytes of authentication data\r\n", auth.length);
213 if (!Data(ap, KRB_AUTH, (void *)auth.dat, auth.length)) {
214 if (auth_debug_mode)
215 printf("Not enough room for authentication data\r\n");
216 return(0);
217 }
218#ifdef ENCRYPTION
219 /* create challenge */
220 if ((ap->way & AUTH_HOW_MASK)==AUTH_HOW_MUTUAL) {
221 int i;
222
223 des_key_sched(&cred.session, sched);
224 memcpy (&cred_session, &cred.session, sizeof(cred_session));
225 des_init_random_number_generator(&cred.session);
226 des_new_random_key(&session_key);
227 des_ecb_encrypt(&session_key, &session_key, sched, 0);
228 des_ecb_encrypt(&session_key, &challenge, sched, 0);
229
230 /*
231 old code
232 Some CERT Advisory thinks this is a bad thing...
233
234 des_init_random_number_generator(&cred.session);
235 des_new_random_key(&challenge);
236 des_ecb_encrypt(&challenge, &session_key, sched, 1);
237 */
238
239 /*
240 * Increment the challenge by 1, and encrypt it for
241 * later comparison.
242 */
243 for (i = 7; i >= 0; --i)
244 if(++challenge[i] != 0) /* No carry! */
245 break;
246 des_ecb_encrypt(&challenge, &challenge, sched, 1);
247 }
248
249#endif
250
251 if (auth_debug_mode) {
252 printf("CK: %d:", kerberos4_cksum(auth.dat, auth.length));
253 printd(auth.dat, auth.length);
254 printf("\r\n");
255 printf("Sent Kerberos V4 credentials to server\r\n");
256 }
257 return(1);
258}
259int
260kerberos4_send_mutual(Authenticator *ap)
261{
262 return kerberos4_send("mutual KERBEROS4", ap);
263}
264
265int
266kerberos4_send_oneway(Authenticator *ap)
267{
268 return kerberos4_send("KERBEROS4", ap);
269}
270
271void
272kerberos4_is(Authenticator *ap, unsigned char *data, int cnt)
273{
274 struct sockaddr_in addr;
275 char realm[REALM_SZ];
276 char instance[INST_SZ];
277 int r;
278 int addr_len;
279
280 if (cnt-- < 1)
281 return;
282 switch (*data++) {
283 case KRB_AUTH:
284 if (krb_get_lrealm(realm, 1) != KSUCCESS) {
285 Data(ap, KRB_REJECT, (void *)"No local V4 Realm.", -1);
286 auth_finished(ap, AUTH_REJECT);
287 if (auth_debug_mode)
288 printf("No local realm\r\n");
289 return;
290 }
291 memmove(auth.dat, data, auth.length = cnt);
292 if (auth_debug_mode) {
293 printf("Got %d bytes of authentication data\r\n", cnt);
294 printf("CK: %d:", kerberos4_cksum(auth.dat, auth.length));
295 printd(auth.dat, auth.length);
296 printf("\r\n");
297 }
298 k_getsockinst(0, instance, sizeof(instance));
299 addr_len = sizeof(addr);
300 if(getpeername(0, (struct sockaddr *)&addr, &addr_len) < 0) {
301 if(auth_debug_mode)
302 printf("getpeername failed\r\n");
303 Data(ap, KRB_REJECT, "getpeername failed", -1);
304 auth_finished(ap, AUTH_REJECT);
305 return;
306 }
307 if (addr.sin_family != AF_INET) {
308 if (auth_debug_mode)
309 printf("unknown address family: %d\r\n", addr.sin_family);
310 Data(ap, KRB_REJECT, "bad address family", -1);
311 auth_finished(ap, AUTH_REJECT);
312 return;
313 }
314
315 r = krb_rd_req(&auth, KRB_SERVICE_NAME,
316 instance, addr.sin_addr.s_addr, &adat, "");
317 if (r) {
318 if (auth_debug_mode)
319 printf("Kerberos failed him as %s\r\n", name);
320 Data(ap, KRB_REJECT, (void *)krb_get_err_text(r), -1);
321 auth_finished(ap, AUTH_REJECT);
322 return;
323 }
324 /* save the session key */
325 memmove(session_key, adat.session, sizeof(adat.session));
326 krb_kntoln(&adat, name);
327
328 if (UserNameRequested && !kuserok(&adat, UserNameRequested)){
329 char ts[MaxPathLen];
330 struct passwd *pw = getpwnam(UserNameRequested);
331
332 if(pw){
333 snprintf(ts, sizeof(ts),
334 "%s%u",
335 TKT_ROOT,
336 (unsigned)pw->pw_uid);
337 setenv("KRBTKFILE", ts, 1);
338
339 if (pw->pw_uid == 0)
340 syslog(LOG_INFO|LOG_AUTH,
341 "ROOT Kerberos login from %s on %s\n",
342 krb_unparse_name_long(adat.pname,
343 adat.pinst,
344 adat.prealm),
345 RemoteHostName);
346 }
347 Data(ap, KRB_ACCEPT, NULL, 0);
348 } else {
349 char *msg;
350
351 asprintf (&msg, "user `%s' is not authorized to "
352 "login as `%s'",
353 krb_unparse_name_long(adat.pname,
354 adat.pinst,
355 adat.prealm),
356 UserNameRequested ? UserNameRequested : "<nobody>");
357 if (msg == NULL)
358 Data(ap, KRB_REJECT, NULL, 0);
359 else {
360 Data(ap, KRB_REJECT, (void *)msg, -1);
361 free(msg);
362 }
363 }
364 auth_finished(ap, AUTH_USER);
365 break;
366
367 case KRB_CHALLENGE:
368#ifndef ENCRYPTION
369 Data(ap, KRB_RESPONSE, NULL, 0);
370#else
371 if(!VALIDKEY(session_key)){
372 Data(ap, KRB_RESPONSE, NULL, 0);
373 break;
374 }
375 des_key_sched(&session_key, sched);
376 {
377 des_cblock d_block;
378 int i;
379 Session_Key skey;
380
381 memmove(d_block, data, sizeof(d_block));
382
383 /* make a session key for encryption */
384 des_ecb_encrypt(&d_block, &session_key, sched, 1);
385 skey.type=SK_DES;
386 skey.length=8;
387 skey.data=session_key;
388 encrypt_session_key(&skey, 1);
389
390 /* decrypt challenge, add one and encrypt it */
391 des_ecb_encrypt(&d_block, &challenge, sched, 0);
392 for (i = 7; i >= 0; i--)
393 if(++challenge[i] != 0)
394 break;
395 des_ecb_encrypt(&challenge, &challenge, sched, 1);
396 Data(ap, KRB_RESPONSE, (void *)challenge, sizeof(challenge));
397 }
398#endif
399 break;
400
401 case KRB_FORWARD:
402 {
403 des_key_schedule ks;
404 unsigned char netcred[sizeof(CREDENTIALS)];
405 CREDENTIALS cred;
406 int ret;
407 if(cnt > sizeof(cred))
408 abort();
409
410 memcpy (session_key, adat.session, sizeof(session_key));
411 des_set_key(&session_key, ks);
412 des_pcbc_encrypt((void*)data, (void*)netcred, cnt,
413 ks, &session_key, DES_DECRYPT);
414 unpack_cred(netcred, cnt, &cred);
415 {
416 if(strcmp(cred.service, KRB_TICKET_GRANTING_TICKET) ||
417 strncmp(cred.instance, cred.realm, sizeof(cred.instance)) ||
418 cred.lifetime < 0 || cred.lifetime > 255 ||
419 cred.kvno < 0 || cred.kvno > 255 ||
420 cred.issue_date < 0 ||
421 cred.issue_date > time(0) + CLOCK_SKEW ||
422 strncmp(cred.pname, adat.pname, sizeof(cred.pname)) ||
423 strncmp(cred.pinst, adat.pinst, sizeof(cred.pinst))){
424 Data(ap, KRB_FORWARD_REJECT, "Bad credentials", -1);
425 }else{
426 if((ret = tf_setup(&cred,
427 cred.pname,
428 cred.pinst)) == KSUCCESS){
429 struct passwd *pw = getpwnam(UserNameRequested);
430
431 if (pw)
432 chown(tkt_string(), pw->pw_uid, pw->pw_gid);
433 Data(ap, KRB_FORWARD_ACCEPT, 0, 0);
434 } else{
435 Data(ap, KRB_FORWARD_REJECT,
436 krb_get_err_text(ret), -1);
437 }
438 }
439 }
440 memset(data, 0, cnt);
441 memset(ks, 0, sizeof(ks));
442 memset(&cred, 0, sizeof(cred));
443 }
444
445 break;
446
447 default:
448 if (auth_debug_mode)
449 printf("Unknown Kerberos option %d\r\n", data[-1]);
450 Data(ap, KRB_REJECT, 0, 0);
451 break;
452 }
453}
454
455void
456kerberos4_reply(Authenticator *ap, unsigned char *data, int cnt)
457{
458 Session_Key skey;
459
460 if (cnt-- < 1)
461 return;
462 switch (*data++) {
463 case KRB_REJECT:
464 if(auth_done){ /* XXX Ick! */
465 printf("[ Kerberos V4 received unknown opcode ]\r\n");
466 }else{
467 printf("[ Kerberos V4 refuses authentication ");
468 if (cnt > 0)
469 printf("because %.*s ", cnt, data);
470 printf("]\r\n");
471 auth_send_retry();
472 }
473 return;
474 case KRB_ACCEPT:
475 printf("[ Kerberos V4 accepts you ]\r\n");
476 auth_done = 1;
477 if ((ap->way & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) {
478 /*
479 * Send over the encrypted challenge.
480 */
481 Data(ap, KRB_CHALLENGE, session_key,
482 sizeof(session_key));
483 des_ecb_encrypt(&session_key, &session_key, sched, 1);
484 skey.type = SK_DES;
485 skey.length = 8;
486 skey.data = session_key;
487 encrypt_session_key(&skey, 0);
488#if 0
489 kerberos4_forward(ap, &cred_session);
490#endif
491 return;
492 }
493 auth_finished(ap, AUTH_USER);
494 return;
495 case KRB_RESPONSE:
496 /* make sure the response is correct */
497 if ((cnt != sizeof(des_cblock)) ||
498 (memcmp(data, challenge, sizeof(challenge)))){
499 printf("[ Kerberos V4 challenge failed!!! ]\r\n");
500 auth_send_retry();
501 return;
502 }
503 printf("[ Kerberos V4 challenge successful ]\r\n");
504 auth_finished(ap, AUTH_USER);
505 break;
506 case KRB_FORWARD_ACCEPT:
507 printf("[ Kerberos V4 accepted forwarded credentials ]\r\n");
508 break;
509 case KRB_FORWARD_REJECT:
510 printf("[ Kerberos V4 rejected forwarded credentials: `%.*s']\r\n",
511 cnt, data);
512 break;
513 default:
514 if (auth_debug_mode)
515 printf("Unknown Kerberos option %d\r\n", data[-1]);
516 return;
517 }
518}
519
520int
521kerberos4_status(Authenticator *ap, char *name, size_t name_sz, int level)
522{
523 if (level < AUTH_USER)
524 return(level);
525
526 if (UserNameRequested && !kuserok(&adat, UserNameRequested)) {
527 strlcpy(name, UserNameRequested, name_sz);
528 return(AUTH_VALID);
529 } else
530 return(AUTH_USER);
531}
532
533#define BUMP(buf, len) while (*(buf)) {++(buf), --(len);}
534#define ADDC(buf, len, c) if ((len) > 0) {*(buf)++ = (c); --(len);}
535
536void
537kerberos4_printsub(unsigned char *data, int cnt, unsigned char *buf, int buflen)
538{
539 int i;
540
541 buf[buflen-1] = '\0'; /* make sure its NULL terminated */
542 buflen -= 1;
543
544 switch(data[3]) {
545 case KRB_REJECT: /* Rejected (reason might follow) */
546 strlcpy((char *)buf, " REJECT ", buflen);
547 goto common;
548
549 case KRB_ACCEPT: /* Accepted (name might follow) */
550 strlcpy((char *)buf, " ACCEPT ", buflen);
551 common:
552 BUMP(buf, buflen);
553 if (cnt <= 4)
554 break;
555 ADDC(buf, buflen, '"');
556 for (i = 4; i < cnt; i++)
557 ADDC(buf, buflen, data[i]);
558 ADDC(buf, buflen, '"');
559 ADDC(buf, buflen, '\0');
560 break;
561
562 case KRB_AUTH: /* Authentication data follows */
563 strlcpy((char *)buf, " AUTH", buflen);
564 goto common2;
565
566 case KRB_CHALLENGE:
567 strlcpy((char *)buf, " CHALLENGE", buflen);
568 goto common2;
569
570 case KRB_RESPONSE:
571 strlcpy((char *)buf, " RESPONSE", buflen);
572 goto common2;
573
574 default:
575 snprintf(buf, buflen, " %d (unknown)", data[3]);
576 common2:
577 BUMP(buf, buflen);
578 for (i = 4; i < cnt; i++) {
579 snprintf(buf, buflen, " %d", data[i]);
580 BUMP(buf, buflen);
581 }
582 break;
583 }
584}
585
586int
587kerberos4_cksum(unsigned char *d, int n)
588{
589 int ck = 0;
590
591 /*
592 * A comment is probably needed here for those not
593 * well versed in the "C" language. Yes, this is
594 * supposed to be a "switch" with the body of the
595 * "switch" being a "while" statement. The whole
596 * purpose of the switch is to allow us to jump into
597 * the middle of the while() loop, and then not have
598 * to do any more switch()s.
599 *
600 * Some compilers will spit out a warning message
601 * about the loop not being entered at the top.
602 */
603 switch (n&03)
604 while (n > 0) {
605 case 0:
606 ck ^= (int)*d++ << 24;
607 --n;
608 case 3:
609 ck ^= (int)*d++ << 16;
610 --n;
611 case 2:
612 ck ^= (int)*d++ << 8;
613 --n;
614 case 1:
615 ck ^= (int)*d++;
616 --n;
617 }
618 return(ck);
619}
620
621static int
622pack_cred(CREDENTIALS *cred, unsigned char *buf)
623{
624 unsigned char *p = buf;
625
626 memcpy (p, cred->service, ANAME_SZ);
627 p += ANAME_SZ;
628 memcpy (p, cred->instance, INST_SZ);
629 p += INST_SZ;
630 memcpy (p, cred->realm, REALM_SZ);
631 p += REALM_SZ;
632 memcpy(p, cred->session, 8);
633 p += 8;
634 p += KRB_PUT_INT(cred->lifetime, p, 4, 4);
635 p += KRB_PUT_INT(cred->kvno, p, 4, 4);
636 p += KRB_PUT_INT(cred->ticket_st.length, p, 4, 4);
637 memcpy(p, cred->ticket_st.dat, cred->ticket_st.length);
638 p += cred->ticket_st.length;
639 p += KRB_PUT_INT(0, p, 4, 4);
640 p += KRB_PUT_INT(cred->issue_date, p, 4, 4);
641 memcpy (p, cred->pname, ANAME_SZ);
642 p += ANAME_SZ;
643 memcpy (p, cred->pinst, INST_SZ);
644 p += INST_SZ;
645 return p - buf;
646}
647
648static int
649unpack_cred(unsigned char *buf, int len, CREDENTIALS *cred)
650{
651 unsigned char *p = buf;
652 u_int32_t tmp;
653
654 strncpy (cred->service, p, ANAME_SZ);
655 cred->service[ANAME_SZ - 1] = '\0';
656 p += ANAME_SZ;
657 strncpy (cred->instance, p, INST_SZ);
658 cred->instance[INST_SZ - 1] = '\0';
659 p += INST_SZ;
660 strncpy (cred->realm, p, REALM_SZ);
661 cred->realm[REALM_SZ - 1] = '\0';
662 p += REALM_SZ;
663
664 memcpy(cred->session, p, 8);
665 p += 8;
666 p += krb_get_int(p, &tmp, 4, 0);
667 cred->lifetime = tmp;
668 p += krb_get_int(p, &tmp, 4, 0);
669 cred->kvno = tmp;
670
671 p += krb_get_int(p, &cred->ticket_st.length, 4, 0);
672 memcpy(cred->ticket_st.dat, p, cred->ticket_st.length);
673 p += cred->ticket_st.length;
674 p += krb_get_int(p, &tmp, 4, 0);
675 cred->ticket_st.mbz = 0;
676 p += krb_get_int(p, (u_int32_t *)&cred->issue_date, 4, 0);
677
678 strncpy (cred->pname, p, ANAME_SZ);
679 cred->pname[ANAME_SZ - 1] = '\0';
680 p += ANAME_SZ;
681 strncpy (cred->pinst, p, INST_SZ);
682 cred->pinst[INST_SZ - 1] = '\0';
683 p += INST_SZ;
684 return 0;
685}
686
687
688int
689kerberos4_forward(Authenticator *ap, void *v)
690{
691 des_cblock *key = (des_cblock *)v;
692 CREDENTIALS cred;
693 char *realm;
694 des_key_schedule ks;
695 int len;
696 unsigned char netcred[sizeof(CREDENTIALS)];
697 int ret;
698
699 realm = krb_realmofhost(RemoteHostName);
700 if(realm == NULL)
701 return -1;
702 memset(&cred, 0, sizeof(cred));
703 ret = krb_get_cred(KRB_TICKET_GRANTING_TICKET,
704 realm,
705 realm,
706 &cred);
707 if(ret)
708 return ret;
709 des_set_key(key, ks);
710 len = pack_cred(&cred, netcred);
711 des_pcbc_encrypt((void*)netcred, (void*)netcred, len,
712 ks, key, DES_ENCRYPT);
713 memset(ks, 0, sizeof(ks));
714 Data(ap, KRB_FORWARD, netcred, len);
715 memset(netcred, 0, sizeof(netcred));
716 return 0;
717}
718
719#endif /* KRB4 */
720