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