15c099b14Sthorpej /*
25c099b14Sthorpej * appl/telnet/libtelnet/forward.c
35c099b14Sthorpej */
45c099b14Sthorpej
55c099b14Sthorpej /*
65c099b14Sthorpej * Copyright (c) 1983 Regents of the University of California.
75c099b14Sthorpej * All rights reserved.
85c099b14Sthorpej *
95c099b14Sthorpej * Redistribution and use in source and binary forms are permitted
105c099b14Sthorpej * provided that the above copyright notice and this paragraph are
115c099b14Sthorpej * duplicated in all such forms and that any documentation,
125c099b14Sthorpej * advertising materials, and other materials related to such
135c099b14Sthorpej * distribution and use acknowledge that the software was developed
145c099b14Sthorpej * by the University of California, Berkeley. The name of the
155c099b14Sthorpej * University may not be used to endorse or promote products derived
165c099b14Sthorpej * from this software without specific prior written permission.
175c099b14Sthorpej * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
185c099b14Sthorpej * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
195c099b14Sthorpej * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
205c099b14Sthorpej */
215c099b14Sthorpej
225c099b14Sthorpej
235c099b14Sthorpej /* General-purpose forwarding routines. These routines may be put into */
245c099b14Sthorpej /* libkrb5.a to allow widespread use */
255c099b14Sthorpej
265c099b14Sthorpej #if defined(KERBEROS) || defined(KRB5)
275c099b14Sthorpej #include <stdio.h>
285c099b14Sthorpej #include <netdb.h>
295c099b14Sthorpej
305c099b14Sthorpej #include "k5-int.h"
315c099b14Sthorpej
325c099b14Sthorpej extern char *line; /* see sys_term.c */
335c099b14Sthorpej
34*4fcf8685Sperry krb5_error_code rd_and_store_for_creds(krb5_context, krb5_auth_context, krb5_data *, krb5_ticket *);
355c099b14Sthorpej
365c099b14Sthorpej /* Decode, decrypt and store the forwarded creds in the local ccache. */
375c099b14Sthorpej krb5_error_code
rd_and_store_for_creds(context,auth_context,inbuf,ticket)385c099b14Sthorpej rd_and_store_for_creds(context, auth_context, inbuf, ticket)
395c099b14Sthorpej krb5_context context;
405c099b14Sthorpej krb5_auth_context auth_context;
415c099b14Sthorpej krb5_data *inbuf;
425c099b14Sthorpej krb5_ticket *ticket;
435c099b14Sthorpej {
445c099b14Sthorpej krb5_creds **creds;
455c099b14Sthorpej krb5_error_code retval;
465c099b14Sthorpej char ccname[35];
475c099b14Sthorpej krb5_ccache ccache = NULL;
485c099b14Sthorpej
495c099b14Sthorpej if ((retval = krb5_rd_cred(context, auth_context, inbuf, &creds, NULL)) != 0)
505c099b14Sthorpej return(retval);
515c099b14Sthorpej
52fabed9f7Sitojun snprintf(ccname, sizeof(ccname), "FILE:/tmp/krb5cc_p%d", getpid());
535c099b14Sthorpej setenv(KRB5_ENV_CCNAME, ccname, 1);
545c099b14Sthorpej
555c099b14Sthorpej if ((retval = krb5_cc_resolve(context, ccname, &ccache)) != 0)
565c099b14Sthorpej goto cleanup;
575c099b14Sthorpej
585c099b14Sthorpej if ((retval = krb5_cc_initialize(context, ccache, ticket->enc_part2->client)) != 0)
595c099b14Sthorpej goto cleanup;
605c099b14Sthorpej
615c099b14Sthorpej if ((retval = krb5_cc_store_cred(context, ccache, *creds)) != 0)
625c099b14Sthorpej goto cleanup;
635c099b14Sthorpej
645c099b14Sthorpej cleanup:
655c099b14Sthorpej krb5_free_creds(context, *creds);
665c099b14Sthorpej return retval;
675c099b14Sthorpej }
685c099b14Sthorpej
695c099b14Sthorpej #endif /* defined(KRB5) && defined(FORWARD) */
70