summaryrefslogtreecommitdiffstats
path: root/proxy/src/mechglue/gpp_misc.c
blob: f76c53b4584ee09145ed37b1ca09d2634b762cca (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
   GSS-PROXY

   Copyright (C) 2012 Red Hat, Inc.
   Copyright (C) 2012 Simo Sorce <simo.sorce@redhat.com>

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   DEALINGS IN THE SOFTWARE.
*/

#include "gss_plugin.h"

OM_uint32 gssi_mech_invoke(OM_uint32 *minor_status,
                           const gss_OID desired_mech,
                           const gss_OID desired_object,
                           gss_buffer_t value)
{
    enum gpp_behavior behavior;
    OM_uint32 maj, min;

    GSSI_TRACE();

    /* FIXME: implement remote invoke mech, only local for now */
    behavior = gpp_get_behavior();
    if (behavior == GPP_REMOTE_ONLY) {
        return GSS_S_UNAVAILABLE;
    }

    maj = gssspi_mech_invoke(&min, gpp_special_mech(desired_mech),
                             desired_object, value);

    *minor_status = gpp_map_error(min);
    return maj;
}

/* NOTE: This call is currently useful only for the Spnego mech which we
 * never interpose */
#if 0
OM_uint32 gssi_set_neg_mechs(OM_uint32 *minor_status,
                             gss_cred_id_t cred_handle,
                             const gss_OID_set mech_set);
#endif

/* NOTE: I know of no mechanism that uses this yet, although NTLM might */
#if 0
OM_uint32 gssi_complete_auth_token(OM_uint32 *minor_status,
                                   const gss_ctx_id_t context_handle,
                                   gss_buffer_t input_message_buffer);
#endif

OM_uint32 gssi_localname(OM_uint32 *minor_status, const gss_name_t name,
                         gss_OID mech_type, gss_buffer_t localname)
{
    struct gpp_name_handle *gpname;
    OM_uint32 maj, min;

    GSSI_TRACE();

    *minor_status = 0;
    if (name == GSS_C_NO_NAME) {
        return GSS_S_CALL_INACCESSIBLE_READ;
    }

    /* FIXME: implement remote localname lookup ? Only local for now */
    gpname = (struct gpp_name_handle *)name;
    if (gpname->remote && !gpname->local) {
        maj = gpp_name_to_local(&min, gpname->remote,
                                mech_type, &gpname->local);
        if (maj) {
            goto done;
        }
    }

    maj = gss_localname(&min, gpname->local,
                        gpp_special_mech(mech_type),
                        localname);

done:
    *minor_status = gpp_map_error(min);
    return maj;
}

OM_uint32 gssi_authorize_localname(OM_uint32 *minor_status,
                                   const gss_name_t name,
                                   gss_buffer_t local_user,
                                   gss_OID local_nametype)
{
    struct gpp_name_handle *gpname;
    gss_name_t username = GSS_C_NO_NAME;
    OM_uint32 maj, min;

    GSSI_TRACE();

    *minor_status = 0;
    if (name == GSS_C_NO_NAME) {
        return GSS_S_CALL_INACCESSIBLE_READ;
    }

    /* FIXME: implement remote localname lookup ? Only local for now */
    gpname = (struct gpp_name_handle *)name;
    if (gpname->remote && !gpname->local) {
        maj = gpp_name_to_local(&min, gpname->remote,
                                gpname->mech_type, &gpname->local);
        if (maj != GSS_S_COMPLETE) {
            goto done;
        }
    }

    maj = gss_import_name(&min, local_user, local_nametype, &username);
    if (maj != GSS_S_COMPLETE) {
        goto done;
    }

    maj = gss_authorize_localname(&min, gpname->local, username);

done:
    *minor_status = gpp_map_error(min);
    (void)gss_release_name(&min, &username);
    return maj;
}

OM_uint32 gssi_map_name_to_any(OM_uint32 *minor_status, gss_name_t name,
                               int authenticated, gss_buffer_t type_id,
                               gss_any_t *output)
{
    struct gpp_name_handle *gpname;
    OM_uint32 maj, min;

    GSSI_TRACE();

    *minor_status = 0;
    if (name == GSS_C_NO_NAME) {
        return GSS_S_CALL_INACCESSIBLE_READ;
    }

    /* FIXME: implement remote localname lookup ? Only local for now */
    gpname = (struct gpp_name_handle *)name;
    if (gpname->remote && !gpname->local) {
        maj = gpp_name_to_local(&min, gpname->remote,
                                gpname->mech_type, &gpname->local);
        if (maj != GSS_S_COMPLETE) {
            goto done;
        }
    }

    maj = gss_map_name_to_any(&min, gpname->local,
                              authenticated, type_id, output);

done:
    *minor_status = gpp_map_error(min);
    return maj;
}

OM_uint32 gssi_release_any_name_mapping(OM_uint32 *minor_status,
                                        gss_name_t name,
                                        gss_buffer_t type_id,
                                        gss_any_t *input)
{
    struct gpp_name_handle *gpname;
    OM_uint32 maj, min;

    GSSI_TRACE();

    *minor_status = 0;
    if (name == GSS_C_NO_NAME) {
        return GSS_S_CALL_INACCESSIBLE_READ;
    }

    /* FIXME: implement remote localname lookup ? Only local for now */
    gpname = (struct gpp_name_handle *)name;
    if (!gpname->local) {
        return GSS_S_UNAVAILABLE;
    }

    maj = gss_release_any_name_mapping(&min, gpname->local, type_id, input);

    *minor_status = gpp_map_error(min);
    return maj;

}