forward.c revision 1.2 1 1.1 thorpej /*
2 1.1 thorpej * appl/telnet/libtelnet/forward.c
3 1.1 thorpej */
4 1.1 thorpej
5 1.1 thorpej /*
6 1.1 thorpej * Copyright (c) 1983 Regents of the University of California.
7 1.1 thorpej * All rights reserved.
8 1.1 thorpej *
9 1.1 thorpej * Redistribution and use in source and binary forms are permitted
10 1.1 thorpej * provided that the above copyright notice and this paragraph are
11 1.1 thorpej * duplicated in all such forms and that any documentation,
12 1.1 thorpej * advertising materials, and other materials related to such
13 1.1 thorpej * distribution and use acknowledge that the software was developed
14 1.1 thorpej * by the University of California, Berkeley. The name of the
15 1.1 thorpej * University may not be used to endorse or promote products derived
16 1.1 thorpej * from this software without specific prior written permission.
17 1.1 thorpej * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19 1.1 thorpej * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 1.1 thorpej */
21 1.1 thorpej
22 1.1 thorpej
23 1.1 thorpej /* General-purpose forwarding routines. These routines may be put into */
24 1.1 thorpej /* libkrb5.a to allow widespread use */
25 1.1 thorpej
26 1.1 thorpej #if defined(KERBEROS) || defined(KRB5)
27 1.1 thorpej #include <stdio.h>
28 1.1 thorpej #include <netdb.h>
29 1.1 thorpej
30 1.1 thorpej #include "k5-int.h"
31 1.1 thorpej
32 1.1 thorpej extern char *line; /* see sys_term.c */
33 1.1 thorpej
34 1.1 thorpej #ifdef __P
35 1.1 thorpej krb5_error_code rd_and_store_for_creds __P((krb5_context, krb5_auth_context, krb5_data *, krb5_ticket *));
36 1.1 thorpej #endif
37 1.1 thorpej
38 1.1 thorpej /* Decode, decrypt and store the forwarded creds in the local ccache. */
39 1.1 thorpej krb5_error_code
40 1.1 thorpej rd_and_store_for_creds(context, auth_context, inbuf, ticket)
41 1.1 thorpej krb5_context context;
42 1.1 thorpej krb5_auth_context auth_context;
43 1.1 thorpej krb5_data *inbuf;
44 1.1 thorpej krb5_ticket *ticket;
45 1.1 thorpej {
46 1.1 thorpej krb5_creds **creds;
47 1.1 thorpej krb5_error_code retval;
48 1.1 thorpej char ccname[35];
49 1.1 thorpej krb5_ccache ccache = NULL;
50 1.1 thorpej
51 1.1 thorpej if ((retval = krb5_rd_cred(context, auth_context, inbuf, &creds, NULL)) != 0)
52 1.1 thorpej return(retval);
53 1.1 thorpej
54 1.2 itojun snprintf(ccname, sizeof(ccname), "FILE:/tmp/krb5cc_p%d", getpid());
55 1.1 thorpej setenv(KRB5_ENV_CCNAME, ccname, 1);
56 1.1 thorpej
57 1.1 thorpej if ((retval = krb5_cc_resolve(context, ccname, &ccache)) != 0)
58 1.1 thorpej goto cleanup;
59 1.1 thorpej
60 1.1 thorpej if ((retval = krb5_cc_initialize(context, ccache, ticket->enc_part2->client)) != 0)
61 1.1 thorpej goto cleanup;
62 1.1 thorpej
63 1.1 thorpej if ((retval = krb5_cc_store_cred(context, ccache, *creds)) != 0)
64 1.1 thorpej goto cleanup;
65 1.1 thorpej
66 1.1 thorpej cleanup:
67 1.1 thorpej krb5_free_creds(context, *creds);
68 1.1 thorpej return retval;
69 1.1 thorpej }
70 1.1 thorpej
71 1.1 thorpej #endif /* defined(KRB5) && defined(FORWARD) */
72