xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/mech/set_ccache.c (revision 7934:6aeeafc994de)
15053Sgtb /*
2*7934SMark.Phalan@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
35053Sgtb  * Use is subject to license terms.
45053Sgtb  */
55053Sgtb 
60Sstevel@tonic-gate 
75053Sgtb /*
85053Sgtb  * lib/gssapi/krb5/set_ccache.c
95053Sgtb  *
105053Sgtb  * Copyright 1999, 2003 by the Massachusetts Institute of Technology.
115053Sgtb  * All Rights Reserved.
125053Sgtb  *
135053Sgtb  * Export of this software from the United States of America may
145053Sgtb  *   require a specific license from the United States Government.
155053Sgtb  *   It is the responsibility of any person or organization contemplating
165053Sgtb  *   export to obtain such a license before exporting.
175053Sgtb  *
185053Sgtb  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
195053Sgtb  * distribute this software and its documentation for any purpose and
205053Sgtb  * without fee is hereby granted, provided that the above copyright
215053Sgtb  * notice appear in all copies and that both that copyright notice and
225053Sgtb  * this permission notice appear in supporting documentation, and that
235053Sgtb  * the name of M.I.T. not be used in advertising or publicity pertaining
245053Sgtb  * to distribution of the software without specific, written prior
255053Sgtb  * permission.  Furthermore if you modify this software you must label
265053Sgtb  * your software as modified software and not distribute it in such a
275053Sgtb  * fashion that it might be confused with the original M.I.T. software.
285053Sgtb  * M.I.T. makes no representations about the suitability of
295053Sgtb  * this software for any purpose.  It is provided "as is" without express
305053Sgtb  * or implied warranty.
315053Sgtb  *
325053Sgtb  * Set ccache name used by gssapi, and optionally obtain old ccache
335053Sgtb  * name.  Caller should not free returned name.
345053Sgtb  */
350Sstevel@tonic-gate 
365053Sgtb #include <string.h>
375053Sgtb #include "gssapiP_krb5.h"
385053Sgtb #include "gss_libinit.h"
395053Sgtb 
405053Sgtb OM_uint32 KRB5_CALLCONV
gss_krb5_ccache_name(minor_status,name,out_name)410Sstevel@tonic-gate gss_krb5_ccache_name(minor_status, name, out_name)
420Sstevel@tonic-gate 	OM_uint32 *minor_status;
430Sstevel@tonic-gate 	const char *name;
440Sstevel@tonic-gate 	const char **out_name;
450Sstevel@tonic-gate {
465053Sgtb     char *old_name = NULL;
475053Sgtb     OM_uint32 err = 0;
485053Sgtb     OM_uint32 minor = 0;
495053Sgtb     char *gss_out_name;
505053Sgtb 
515053Sgtb     err = gssint_initialize_library();
525053Sgtb     if (err) {
535053Sgtb 	*minor_status = err;
545053Sgtb 	return GSS_S_FAILURE;
555053Sgtb     }
565053Sgtb 
575053Sgtb     gss_out_name = k5_getspecific(K5_KEY_GSS_KRB5_SET_CCACHE_OLD_NAME);
580Sstevel@tonic-gate 
595053Sgtb     if (out_name) {
605053Sgtb         const char *tmp_name = NULL;
615053Sgtb 
625053Sgtb         if (!err) {
635053Sgtb             kg_get_ccache_name (&err, &tmp_name);
645053Sgtb         }
655053Sgtb         if (!err) {
665053Sgtb             old_name = gss_out_name;
67*7934SMark.Phalan@Sun.COM             /* Solaris Kerberos */
685053Sgtb             gss_out_name = (char *)tmp_name;
695053Sgtb         }
705053Sgtb     }
715053Sgtb     /* If out_name was NULL, we keep the same gss_out_name value, and
725053Sgtb        don't free up any storage (leave old_name NULL).  */
730Sstevel@tonic-gate 
745053Sgtb     if (!err)
755053Sgtb         kg_set_ccache_name (&err, name);
765053Sgtb 
775053Sgtb     minor = k5_setspecific(K5_KEY_GSS_KRB5_SET_CCACHE_OLD_NAME, gss_out_name);
785053Sgtb     if (minor) {
795053Sgtb 	/* Um.  Now what?  */
805053Sgtb 	if (err == 0) {
815053Sgtb 	    err = minor;
825053Sgtb 	}
835053Sgtb 	free(gss_out_name);
845053Sgtb 	gss_out_name = NULL;
855053Sgtb     }
860Sstevel@tonic-gate 
875053Sgtb     if (!err) {
885053Sgtb         if (out_name) {
895053Sgtb             *out_name = gss_out_name;
905053Sgtb         }
915053Sgtb     }
925053Sgtb 
935053Sgtb     if (old_name != NULL) {
945053Sgtb         free (old_name);
955053Sgtb     }
965053Sgtb 
975053Sgtb     *minor_status = err;
985053Sgtb     return (*minor_status == 0) ? GSS_S_COMPLETE : GSS_S_FAILURE;
990Sstevel@tonic-gate }
100