display_name.c revision 178825
190075Sobrien/*
290075Sobrien * Copyright (c) 1997 - 2003 Kungliga Tekniska H�gskolan
390075Sobrien * (Royal Institute of Technology, Stockholm, Sweden).
490075Sobrien * All rights reserved.
590075Sobrien *
690075Sobrien * Redistribution and use in source and binary forms, with or without
790075Sobrien * modification, are permitted provided that the following conditions
890075Sobrien * are met:
990075Sobrien *
1090075Sobrien * 1. Redistributions of source code must retain the above copyright
1190075Sobrien *    notice, this list of conditions and the following disclaimer.
1290075Sobrien *
1390075Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1490075Sobrien *    notice, this list of conditions and the following disclaimer in the
1590075Sobrien *    documentation and/or other materials provided with the distribution.
1690075Sobrien *
1790075Sobrien * 3. Neither the name of the Institute nor the names of its contributors
1890075Sobrien *    may be used to endorse or promote products derived from this software
1990075Sobrien *    without specific prior written permission.
2090075Sobrien *
2190075Sobrien * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
2290075Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2390075Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2490075Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
2590075Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2690075Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2790075Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2890075Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2990075Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3090075Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3190075Sobrien * SUCH DAMAGE.
3290075Sobrien */
3390075Sobrien
3490075Sobrien#include "ntlm/ntlm.h"
3590075Sobrien
3690075SobrienRCSID("$Id: display_name.c 22373 2007-12-28 18:36:06Z lha $");
3790075Sobrien
3890075SobrienOM_uint32 _gss_ntlm_display_name
3990075Sobrien           (OM_uint32 * minor_status,
4090075Sobrien            const gss_name_t input_name,
4190075Sobrien            gss_buffer_t output_name_buffer,
4290075Sobrien            gss_OID * output_name_type
4390075Sobrien           )
4490075Sobrien{
4590075Sobrien    *minor_status = 0;
4690075Sobrien
4790075Sobrien    if (output_name_type)
4890075Sobrien	*output_name_type = GSS_NTLM_MECHANISM;
4990075Sobrien
5090075Sobrien    if (output_name_buffer) {
5190075Sobrien	ntlm_name n = (ntlm_name)input_name;
5290075Sobrien	char *str;
5390075Sobrien	int len;
5490075Sobrien
5590075Sobrien	output_name_buffer->length = 0;
5690075Sobrien	output_name_buffer->value = NULL;
5790075Sobrien
5890075Sobrien	if (n == NULL) {
5990075Sobrien	    *minor_status = 0;
6090075Sobrien	    return GSS_S_BAD_NAME;
6190075Sobrien	}
6290075Sobrien
6390075Sobrien	len = asprintf(&str, "%s@%s", n->user, n->domain);
6490075Sobrien	if (str == NULL) {
6590075Sobrien	    *minor_status = ENOMEM;
6690075Sobrien	    return GSS_S_FAILURE;
6790075Sobrien	}
6890075Sobrien	output_name_buffer->length = len;
6990075Sobrien	output_name_buffer->value = str;
7090075Sobrien    }
7190075Sobrien    return GSS_S_COMPLETE;
7290075Sobrien}
7390075Sobrien