summaryrefslogtreecommitdiffstats
path: root/src/lib/gssapi/mechglue/g_mechname.c
blob: 9ade23456702755f8ea52b33d04ffec729e8d9dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
 * g_mechname.c --- registry of mechanism-specific name types
 *
 * This file contains a registry of mechanism-specific name types.  It
 * is used to determine which name types not should be lazy evaluated,
 * but rather evaluated on the spot.
 */

#include "mglueP.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#include <stdio.h>
#include <string.h>
#include <errno.h>

static gss_mech_spec_name name_list = NULL;

/*
 * generic searching helper function.
 */
static gss_mech_spec_name search_mech_spec(name_type)
    gss_OID name_type;
{
    gss_mech_spec_name p;

    for (p = name_list; p; p = p->next) {
	if (g_OID_equal(name_type, p->name_type))
	    return p;
    }
    return NULL;
}

/*
 * Given a name_type, if it is specific to a mechanism, return the
 * mechanism OID.  Otherwise, return NULL.
 */
gss_OID gss_find_mechanism_from_name_type(name_type)
    gss_OID name_type;
{
    gss_mech_spec_name p;

    p = search_mech_spec(name_type);
    if (!p)
	return NULL;
    return p->mech;
}

/*
 * This function adds a (name_type, mechanism) pair to the
 * mechanism-specific name type registry.  If an entry for the
 * name_type already exists, then zero out the mechanism entry.
 * Otherwise, enter the pair into the registry.
 */
OM_uint32
gss_add_mech_name_type(minor_status, name_type, mech)
    OM_uint32	*minor_status;
    gss_OID	name_type;
    gss_OID	mech;
{
    OM_uint32	major_status, tmp;
    gss_mech_spec_name p;

    p = search_mech_spec(name_type);
    if (p) {
	/*
	 * We found an entry for this name type; mark it as not being
	 * a mechanism-specific name type.
	 */
	if (p->mech) {
	    if (!g_OID_equal(mech, p->mech)) {
		generic_gss_release_oid(minor_status, &p->mech);
		p->mech = 0;
	    }
	}
	return GSS_S_COMPLETE;
    }
    p = malloc(sizeof(gss_mech_spec_name_desc));
    if (!p) {
	*minor_status = ENOMEM;
	map_errcode(minor_status);
	goto allocation_failure;
    }
    p->name_type = 0;
    p->mech = 0;
    
    major_status = generic_gss_copy_oid(minor_status, name_type,
					&p->name_type);
    if (major_status) {
	map_errcode(minor_status);
	goto allocation_failure;
    }
    major_status = generic_gss_copy_oid(minor_status, mech,
					&p->mech);
    if (major_status) {
	map_errcode(minor_status);
	goto allocation_failure;
    }

    p->next = name_list;
    p->prev = 0;
    name_list = p;

    return GSS_S_COMPLETE;
    
allocation_failure:
    if (p) {
	if (p->mech)
	    generic_gss_release_oid(&tmp, &p->mech);
	if (p->name_type)
	    generic_gss_release_oid(&tmp, &p->name_type);
	free(p);
    }
    return GSS_S_FAILURE;
}