1226031Sstas/*
2226031Sstas * Copyright (c) 2006 Kungliga Tekniska H��gskolan
3226031Sstas * (Royal Institute of Technology, Stockholm, Sweden).
4226031Sstas * All rights reserved.
5226031Sstas *
6226031Sstas * Redistribution and use in source and binary forms, with or without
7226031Sstas * modification, are permitted provided that the following conditions
8226031Sstas * are met:
9226031Sstas *
10226031Sstas * 1. Redistributions of source code must retain the above copyright
11226031Sstas *    notice, this list of conditions and the following disclaimer.
12226031Sstas *
13226031Sstas * 2. Redistributions in binary form must reproduce the above copyright
14226031Sstas *    notice, this list of conditions and the following disclaimer in the
15226031Sstas *    documentation and/or other materials provided with the distribution.
16226031Sstas *
17226031Sstas * 3. Neither the name of the Institute nor the names of its contributors
18226031Sstas *    may be used to endorse or promote products derived from this software
19226031Sstas *    without specific prior written permission.
20226031Sstas *
21226031Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24226031Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31226031Sstas * SUCH DAMAGE.
32226031Sstas */
33226031Sstas
34226031Sstas#include "mech_locl.h"
35226031Sstas
36226031SstasGSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL
37226031Sstasgss_oid_to_str(OM_uint32 *minor_status, gss_OID oid, gss_buffer_t oid_str)
38226031Sstas{
39226031Sstas    int ret;
40226031Sstas    size_t size;
41226031Sstas    heim_oid o;
42226031Sstas    char *p;
43226031Sstas
44226031Sstas    _mg_buffer_zero(oid_str);
45226031Sstas
46226031Sstas    if (oid == GSS_C_NULL_OID)
47226031Sstas	return GSS_S_FAILURE;
48226031Sstas
49226031Sstas    ret = der_get_oid (oid->elements, oid->length, &o, &size);
50226031Sstas    if (ret) {
51226031Sstas	*minor_status = ret;
52226031Sstas	return GSS_S_FAILURE;
53226031Sstas    }
54226031Sstas
55226031Sstas    ret = der_print_heim_oid(&o, ' ', &p);
56226031Sstas    der_free_oid(&o);
57226031Sstas    if (ret) {
58226031Sstas	*minor_status = ret;
59226031Sstas	return GSS_S_FAILURE;
60226031Sstas    }
61226031Sstas
62226031Sstas    oid_str->value = p;
63226031Sstas    oid_str->length = strlen(p);
64226031Sstas
65226031Sstas    *minor_status = 0;
66226031Sstas    return GSS_S_COMPLETE;
67226031Sstas}
68226031Sstas
69226031SstasGSSAPI_LIB_FUNCTION const char * GSSAPI_LIB_CALL
70226031Sstasgss_oid_to_name(gss_const_OID oid)
71226031Sstas{
72226031Sstas    size_t i;
73226031Sstas
74226031Sstas    for (i = 0; _gss_ont_mech[i].oid; i++) {
75226031Sstas	if (gss_oid_equal(oid, _gss_ont_mech[i].oid))
76226031Sstas	    return _gss_ont_mech[i].name;
77226031Sstas    }
78226031Sstas    return NULL;
79226031Sstas}
80226031Sstas
81226031SstasGSSAPI_LIB_FUNCTION gss_OID GSSAPI_LIB_CALL
82226031Sstasgss_name_to_oid(const char *name)
83226031Sstas{
84226031Sstas    size_t i, partial = (size_t)-1;
85226031Sstas
86226031Sstas    for (i = 0; _gss_ont_mech[i].oid; i++) {
87226031Sstas	if (strcasecmp(name, _gss_ont_mech[i].short_desc) == 0)
88226031Sstas	    return _gss_ont_mech[i].oid;
89226031Sstas	if (strncasecmp(name, _gss_ont_mech[i].short_desc, strlen(name)) == 0) {
90226031Sstas	    if (partial != (size_t)-1)
91226031Sstas		return NULL;
92226031Sstas	    partial = i;
93226031Sstas	}
94226031Sstas    }
95226031Sstas    if (partial != (size_t)-1)
96226031Sstas	return _gss_ont_mech[partial].oid;
97226031Sstas    return NULL;
98226031Sstas}
99