2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/gssapi/krb5/export_name.c
2N/A *
2N/A * Copyright 1997, 2007 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A *
2N/A */
2N/A/*
2N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include "gssapiP_krb5.h"
2N/A
2N/AOM_uint32 krb5_gss_export_name(OM_uint32 *minor_status,
2N/A const gss_name_t input_name,
2N/A gss_buffer_t exported_name)
2N/A{
2N/A krb5_context context;
2N/A krb5_error_code code;
2N/A size_t length;
2N/A char *str;
2N/A unsigned char *cp;
2N/A
2N/A if (minor_status)
2N/A *minor_status = 0;
2N/A
2N/A code = krb5_gss_init_context(&context);
2N/A if (code) {
2N/A if (minor_status)
2N/A *minor_status = code;
2N/A return GSS_S_FAILURE;
2N/A }
2N/A
2N/A exported_name->length = 0;
2N/A exported_name->value = NULL;
2N/A
2N/A if (! kg_validate_name(input_name)) {
2N/A /* Solaris Kerberos: spruce-up the err msg */
2N/A krb5_principal princ = ((krb5_gss_name_t) input_name)->princ;
2N/A char *s_name = NULL;
2N/A int kret = krb5_unparse_name(context, princ, &s_name);
2N/A if (minor_status)
2N/A *minor_status = (OM_uint32) G_VALIDATE_FAILED;
2N/A if (minor_status && kret == 0) {
2N/A krb5_set_error_message(context, *minor_status,
2N/A "Input name principal '%s' is invalid "
2N/A "(kg_validate_name()) for export_name",
2N/A s_name);
2N/A save_error_info(*minor_status, context);
2N/A krb5_free_unparsed_name(context, s_name);
2N/A }
2N/A krb5_free_context(context);
2N/A return(GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
2N/A }
2N/A
2N/A if ((code = krb5_unparse_name(context, ((krb5_gss_name_t) input_name)->princ,
2N/A &str))) {
2N/A if (minor_status)
2N/A *minor_status = code;
2N/A save_error_info((OM_uint32)code, context);
2N/A krb5_free_context(context);
2N/A return(GSS_S_FAILURE);
2N/A }
2N/A
2N/A krb5_free_context(context);
2N/A length = strlen(str);
2N/A exported_name->length = 10 + length + gss_mech_krb5->length;
2N/A exported_name->value = malloc(exported_name->length);
2N/A if (!exported_name->value) {
2N/A free(str);
2N/A if (minor_status)
2N/A *minor_status = ENOMEM;
2N/A return(GSS_S_FAILURE);
2N/A }
2N/A cp = exported_name->value;
2N/A
2N/A /* Note: we assume the OID will be less than 128 bytes... */
2N/A *cp++ = 0x04; *cp++ = 0x01;
2N/A store_16_be(gss_mech_krb5->length+2, cp);
2N/A cp += 2;
2N/A *cp++ = 0x06;
2N/A *cp++ = (gss_mech_krb5->length) & 0xFF;
2N/A memcpy(cp, gss_mech_krb5->elements, gss_mech_krb5->length);
2N/A cp += gss_mech_krb5->length;
2N/A store_32_be(length, cp);
2N/A cp += 4;
2N/A memcpy(cp, str, length);
2N/A
2N/A free(str);
2N/A
2N/A return(GSS_S_COMPLETE);
2N/A}