1 /* 2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 #pragma ident "%Z%%M% %I% %E% SMI" 7 8 /* 9 * lib/gssapi/krb5/set_ccache.c 10 * 11 * Copyright 1999, 2003 by the Massachusetts Institute of Technology. 12 * All Rights Reserved. 13 * 14 * Export of this software from the United States of America may 15 * require a specific license from the United States Government. 16 * It is the responsibility of any person or organization contemplating 17 * export to obtain such a license before exporting. 18 * 19 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 20 * distribute this software and its documentation for any purpose and 21 * without fee is hereby granted, provided that the above copyright 22 * notice appear in all copies and that both that copyright notice and 23 * this permission notice appear in supporting documentation, and that 24 * the name of M.I.T. not be used in advertising or publicity pertaining 25 * to distribution of the software without specific, written prior 26 * permission. Furthermore if you modify this software you must label 27 * your software as modified software and not distribute it in such a 28 * fashion that it might be confused with the original M.I.T. software. 29 * M.I.T. makes no representations about the suitability of 30 * this software for any purpose. It is provided "as is" without express 31 * or implied warranty. 32 * 33 * Set ccache name used by gssapi, and optionally obtain old ccache 34 * name. Caller should not free returned name. 35 */ 36 37 #include <string.h> 38 #include "gssapiP_krb5.h" 39 #include "gss_libinit.h" 40 41 OM_uint32 KRB5_CALLCONV 42 gss_krb5_ccache_name(minor_status, name, out_name) 43 OM_uint32 *minor_status; 44 const char *name; 45 const char **out_name; 46 { 47 char *old_name = NULL; 48 OM_uint32 err = 0; 49 OM_uint32 minor = 0; 50 char *gss_out_name; 51 52 err = gssint_initialize_library(); 53 if (err) { 54 *minor_status = err; 55 return GSS_S_FAILURE; 56 } 57 58 gss_out_name = k5_getspecific(K5_KEY_GSS_KRB5_SET_CCACHE_OLD_NAME); 59 60 if (out_name) { 61 const char *tmp_name = NULL; 62 63 if (!err) { 64 kg_get_ccache_name (&err, &tmp_name); 65 } 66 if (!err) { 67 old_name = gss_out_name; 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