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