1ab9b2e15Sgtb /*
2159d09a2SMark Phalan  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3ab9b2e15Sgtb  * Use is subject to license terms.
4ab9b2e15Sgtb  */
5ab9b2e15Sgtb 
67c478bd9Sstevel@tonic-gate 
7ab9b2e15Sgtb /*
8ab9b2e15Sgtb  * lib/gssapi/krb5/set_ccache.c
9ab9b2e15Sgtb  *
10ab9b2e15Sgtb  * Copyright 1999, 2003 by the Massachusetts Institute of Technology.
11ab9b2e15Sgtb  * All Rights Reserved.
12ab9b2e15Sgtb  *
13ab9b2e15Sgtb  * Export of this software from the United States of America may
14ab9b2e15Sgtb  *   require a specific license from the United States Government.
15ab9b2e15Sgtb  *   It is the responsibility of any person or organization contemplating
16ab9b2e15Sgtb  *   export to obtain such a license before exporting.
17*55fea89dSDan Cross  *
18ab9b2e15Sgtb  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
19ab9b2e15Sgtb  * distribute this software and its documentation for any purpose and
20ab9b2e15Sgtb  * without fee is hereby granted, provided that the above copyright
21ab9b2e15Sgtb  * notice appear in all copies and that both that copyright notice and
22ab9b2e15Sgtb  * this permission notice appear in supporting documentation, and that
23ab9b2e15Sgtb  * the name of M.I.T. not be used in advertising or publicity pertaining
24ab9b2e15Sgtb  * to distribution of the software without specific, written prior
25ab9b2e15Sgtb  * permission.  Furthermore if you modify this software you must label
26ab9b2e15Sgtb  * your software as modified software and not distribute it in such a
27ab9b2e15Sgtb  * fashion that it might be confused with the original M.I.T. software.
28ab9b2e15Sgtb  * M.I.T. makes no representations about the suitability of
29ab9b2e15Sgtb  * this software for any purpose.  It is provided "as is" without express
30ab9b2e15Sgtb  * or implied warranty.
31ab9b2e15Sgtb  *
32ab9b2e15Sgtb  * Set ccache name used by gssapi, and optionally obtain old ccache
33ab9b2e15Sgtb  * name.  Caller should not free returned name.
34ab9b2e15Sgtb  */
35ab9b2e15Sgtb 
36ab9b2e15Sgtb #include <string.h>
37ab9b2e15Sgtb #include "gssapiP_krb5.h"
38ab9b2e15Sgtb #include "gss_libinit.h"
397c478bd9Sstevel@tonic-gate 
40*55fea89dSDan Cross OM_uint32 KRB5_CALLCONV
gss_krb5_ccache_name(minor_status,name,out_name)417c478bd9Sstevel@tonic-gate gss_krb5_ccache_name(minor_status, name, out_name)
427c478bd9Sstevel@tonic-gate 	OM_uint32 *minor_status;
437c478bd9Sstevel@tonic-gate 	const char *name;
447c478bd9Sstevel@tonic-gate 	const char **out_name;
457c478bd9Sstevel@tonic-gate {
46ab9b2e15Sgtb     char *old_name = NULL;
47ab9b2e15Sgtb     OM_uint32 err = 0;
48ab9b2e15Sgtb     OM_uint32 minor = 0;
49ab9b2e15Sgtb     char *gss_out_name;
50ab9b2e15Sgtb 
51ab9b2e15Sgtb     err = gssint_initialize_library();
52ab9b2e15Sgtb     if (err) {
53ab9b2e15Sgtb 	*minor_status = err;
54ab9b2e15Sgtb 	return GSS_S_FAILURE;
55ab9b2e15Sgtb     }
567c478bd9Sstevel@tonic-gate 
57ab9b2e15Sgtb     gss_out_name = k5_getspecific(K5_KEY_GSS_KRB5_SET_CCACHE_OLD_NAME);
587c478bd9Sstevel@tonic-gate 
59ab9b2e15Sgtb     if (out_name) {
60ab9b2e15Sgtb         const char *tmp_name = NULL;
617c478bd9Sstevel@tonic-gate 
62ab9b2e15Sgtb         if (!err) {
63ab9b2e15Sgtb             kg_get_ccache_name (&err, &tmp_name);
64ab9b2e15Sgtb         }
65ab9b2e15Sgtb         if (!err) {
66ab9b2e15Sgtb             old_name = gss_out_name;
67159d09a2SMark Phalan             /* Solaris Kerberos */
68ab9b2e15Sgtb             gss_out_name = (char *)tmp_name;
69*55fea89dSDan Cross         }
70ab9b2e15Sgtb     }
71ab9b2e15Sgtb     /* If out_name was NULL, we keep the same gss_out_name value, and
72ab9b2e15Sgtb        don't free up any storage (leave old_name NULL).  */
73ab9b2e15Sgtb 
74ab9b2e15Sgtb     if (!err)
75ab9b2e15Sgtb         kg_set_ccache_name (&err, name);
76ab9b2e15Sgtb 
77ab9b2e15Sgtb     minor = k5_setspecific(K5_KEY_GSS_KRB5_SET_CCACHE_OLD_NAME, gss_out_name);
78ab9b2e15Sgtb     if (minor) {
79ab9b2e15Sgtb 	/* Um.  Now what?  */
80ab9b2e15Sgtb 	if (err == 0) {
81ab9b2e15Sgtb 	    err = minor;
827c478bd9Sstevel@tonic-gate 	}
83ab9b2e15Sgtb 	free(gss_out_name);
84ab9b2e15Sgtb 	gss_out_name = NULL;
85ab9b2e15Sgtb     }
86ab9b2e15Sgtb 
87ab9b2e15Sgtb     if (!err) {
88ab9b2e15Sgtb         if (out_name) {
89ab9b2e15Sgtb             *out_name = gss_out_name;
90ab9b2e15Sgtb         }
91ab9b2e15Sgtb     }
92*55fea89dSDan Cross 
93ab9b2e15Sgtb     if (old_name != NULL) {
94ab9b2e15Sgtb         free (old_name);
95ab9b2e15Sgtb     }
96*55fea89dSDan Cross 
97ab9b2e15Sgtb     *minor_status = err;
98ab9b2e15Sgtb     return (*minor_status == 0) ? GSS_S_COMPLETE : GSS_S_FAILURE;
997c478bd9Sstevel@tonic-gate }
100