1 #pragma ident "%Z%%M% %I% %E% SMI" 2 3 /* 4 * lib/gssapi/krb5/export_name.c 5 * 6 * Copyright 1997 by the Massachusetts Institute of Technology. 7 * All Rights Reserved. 8 * 9 * Export of this software from the United States of America may 10 * require a specific license from the United States Government. 11 * It is the responsibility of any person or organization contemplating 12 * export to obtain such a license before exporting. 13 * 14 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 15 * distribute this software and its documentation for any purpose and 16 * without fee is hereby granted, provided that the above copyright 17 * notice appear in all copies and that both that copyright notice and 18 * this permission notice appear in supporting documentation, and that 19 * the name of M.I.T. not be used in advertising or publicity pertaining 20 * to distribution of the software without specific, written prior 21 * permission. Furthermore if you modify this software you must label 22 * your software as modified software and not distribute it in such a 23 * fashion that it might be confused with the original M.I.T. software. 24 * M.I.T. makes no representations about the suitability of 25 * this software for any purpose. It is provided "as is" without express 26 * or implied warranty. 27 * 28 */ 29 30 #include "gssapiP_krb5.h" 31 32 OM_uint32 krb5_gss_export_name(OM_uint32 *minor_status, 33 const gss_name_t input_name, 34 gss_buffer_t exported_name) 35 { 36 krb5_context context; 37 krb5_error_code code; 38 size_t length; 39 char *str, *cp; 40 41 if (minor_status) 42 *minor_status = 0; 43 44 code = krb5_gss_init_context(&context); 45 if (code) { 46 if (minor_status) 47 *minor_status = code; 48 return GSS_S_FAILURE; 49 } 50 51 exported_name->length = 0; 52 exported_name->value = NULL; 53 54 if (! kg_validate_name(input_name)) { 55 if (minor_status) 56 *minor_status = (OM_uint32) G_VALIDATE_FAILED; 57 krb5_free_context(context); 58 return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME); 59 } 60 61 if ((code = krb5_unparse_name(context, (krb5_principal) input_name, 62 &str))) { 63 if (minor_status) 64 *minor_status = code; 65 krb5_free_context(context); 66 return(GSS_S_FAILURE); 67 } 68 69 krb5_free_context(context); 70 length = strlen(str); 71 exported_name->length = 10 + length + gss_mech_krb5->length; 72 exported_name->value = malloc(exported_name->length); 73 if (!exported_name->value) { 74 free(str); 75 if (minor_status) 76 *minor_status = ENOMEM; 77 return(GSS_S_FAILURE); 78 } 79 cp = exported_name->value; 80 81 /* Note: we assume the OID will be less than 128 bytes... */ 82 *cp++ = 0x04; *cp++ = 0x01; 83 *cp++ = (gss_mech_krb5->length+2) >> 8; 84 *cp++ = (gss_mech_krb5->length+2) & 0xFF; 85 *cp++ = 0x06; 86 *cp++ = (gss_mech_krb5->length) & 0xFF; 87 memcpy(cp, gss_mech_krb5->elements, gss_mech_krb5->length); 88 cp += gss_mech_krb5->length; 89 *cp++ = length >> 24; 90 *cp++ = length >> 16; 91 *cp++ = length >> 8; 92 *cp++ = length & 0xFF; 93 memcpy(cp, str, length); 94 95 free(str); 96 97 return(GSS_S_COMPLETE); 98 } 99