Path: blob/main/crypto/heimdal/lib/gssapi/ntlm/import_name.c
34914 views
/*1* Copyright (c) 1997 - 2003 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "ntlm.h"3435OM_uint32 GSSAPI_CALLCONV36_gss_ntlm_import_name37(OM_uint32 * minor_status,38const gss_buffer_t input_name_buffer,39const gss_OID input_name_type,40gss_name_t * output_name41)42{43char *name, *p, *p2;44int is_hostnamed;45int is_username;46ntlm_name n;4748*minor_status = 0;4950if (output_name == NULL)51return GSS_S_CALL_INACCESSIBLE_WRITE;5253*output_name = GSS_C_NO_NAME;5455is_hostnamed = gss_oid_equal(input_name_type, GSS_C_NT_HOSTBASED_SERVICE);56is_username = gss_oid_equal(input_name_type, GSS_C_NT_USER_NAME);5758if (!is_hostnamed && !is_username)59return GSS_S_BAD_NAMETYPE;6061name = malloc(input_name_buffer->length + 1);62if (name == NULL) {63*minor_status = ENOMEM;64return GSS_S_FAILURE;65}66memcpy(name, input_name_buffer->value, input_name_buffer->length);67name[input_name_buffer->length] = '\0';6869/* find "domain" part of the name and uppercase it */70p = strchr(name, '@');71if (p == NULL) {72free(name);73return GSS_S_BAD_NAME;74}75p[0] = '\0';76p++;77p2 = strchr(p, '.');78if (p2 && p2[1] != '\0') {79if (is_hostnamed) {80p = p2 + 1;81p2 = strchr(p, '.');82}83if (p2)84*p2 = '\0';85}86strupr(p);8788n = calloc(1, sizeof(*n));89if (n == NULL) {90free(name);91*minor_status = ENOMEM;92return GSS_S_FAILURE;93}9495n->user = strdup(name);96n->domain = strdup(p);9798free(name);99100if (n->user == NULL || n->domain == NULL) {101free(n->user);102free(n->domain);103free(n);104*minor_status = ENOMEM;105return GSS_S_FAILURE;106}107108*output_name = (gss_name_t)n;109110return GSS_S_COMPLETE;111}112113114