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