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
32extern char *line;		/* see sys_term.c */
33
34krb5_error_code rd_and_store_for_creds(krb5_context, krb5_auth_context, krb5_data *, krb5_ticket *);
35
36/* Decode, decrypt and store the forwarded creds in the local ccache. */
37krb5_error_code
38rd_and_store_for_creds(context, auth_context, inbuf, ticket)
39    krb5_context context;
40    krb5_auth_context auth_context;
41    krb5_data *inbuf;
42    krb5_ticket *ticket;
43{
44    krb5_creds **creds;
45    krb5_error_code retval;
46    char ccname[35];
47    krb5_ccache ccache = NULL;
48
49    if ((retval = krb5_rd_cred(context, auth_context, inbuf, &creds, NULL)) != 0)
50	return(retval);
51
52    snprintf(ccname, sizeof(ccname), "FILE:/tmp/krb5cc_p%d", getpid());
53    setenv(KRB5_ENV_CCNAME, ccname, 1);
54
55    if ((retval = krb5_cc_resolve(context, ccname, &ccache)) != 0)
56	goto cleanup;
57
58    if ((retval = krb5_cc_initialize(context, ccache, ticket->enc_part2->client)) != 0)
59	goto cleanup;
60
61    if ((retval = krb5_cc_store_cred(context, ccache, *creds)) != 0)
62	goto cleanup;
63
64cleanup:
65    krb5_free_creds(context, *creds);
66    return retval;
67}
68
69#endif /* defined(KRB5) && defined(FORWARD) */
70