35 #include <attribute.h>
37 #include "gss-extra.h"
49 struct gss_channel_bindings_struct
cb;
58 OM_uint32 maj_stat, min_stat;
59 gss_buffer_desc bufdesc;
63 gss_OID_set_desc oid_set;
64 gss_OID_set actual_mechs;
72 bufdesc.length = asprintf ((
char **) &bufdesc.value,
"%s@%s",
74 if (bufdesc.length <= 0 || bufdesc.value == NULL)
77 maj_stat = gss_import_name (&min_stat, &bufdesc,
78 GSS_C_NT_HOSTBASED_SERVICE, &server);
80 if (GSS_ERROR (maj_stat))
88 maj_stat = gss_acquire_cred (&min_stat, server, 0,
89 &oid_set, GSS_C_ACCEPT,
90 &state->
cred, &actual_mechs, NULL);
91 gss_release_name (&min_stat, &server);
92 if (GSS_ERROR (maj_stat))
98 maj_stat = gss_test_oid_set_member (&min_stat, state->
mech_oid,
99 actual_mechs, &present);
100 if (GSS_ERROR (maj_stat))
102 gss_release_oid_set (&min_stat, &actual_mechs);
106 maj_stat = gss_release_oid_set (&min_stat, &actual_mechs);
107 if (GSS_ERROR (maj_stat))
136 state->
context = GSS_C_NO_CONTEXT;
137 state->
cred = GSS_C_NO_CREDENTIAL;
143 state->
cb.initiator_addrtype = 0;
144 state->
cb.initiator_address.length = 0;
145 state->
cb.initiator_address.value = NULL;
146 state->
cb.acceptor_addrtype = 0;
147 state->
cb.acceptor_address.length = 0;
148 state->
cb.acceptor_address.value = NULL;
149 state->
cb.application_data.length = 0;
150 state->
cb.application_data.value = NULL;
164 const char *input,
size_t input_len,
165 char **output,
size_t *output_len)
168 gss_buffer_desc bufdesc1, bufdesc2;
169 OM_uint32 maj_stat, min_stat;
170 gss_buffer_desc client_name;
174 int free_bufdesc1 = 0;
178 bufdesc1.value = (
char *) input;
179 bufdesc1.length = input_len;
184 res = gs2_get_cred (sctx, state);
201 &authzid, &headerlen);
213 state->
cb.application_data.value = (
char *) input;
214 state->
cb.application_data.length = headerlen;
216 bufdesc2.value = (
char *) input + headerlen;
217 bufdesc2.length = input_len - headerlen;
219 maj_stat = gss_encapsulate_token (&bufdesc2, state->
mech_oid,
221 if (GSS_ERROR (maj_stat))
232 gss_release_name (&min_stat, &state->
client);
233 state->
client = GSS_C_NO_NAME;
236 maj_stat = gss_accept_sec_context (&min_stat,
243 &bufdesc2, &ret_flags, NULL, NULL);
244 if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED)
247 if (maj_stat == GSS_S_COMPLETE)
251 if (!(ret_flags & GSS_C_MUTUAL_FLAG))
254 maj_stat = gss_display_name (&min_stat, state->
client,
255 &client_name, &mech_type);
256 if (GSS_ERROR (maj_stat))
272 maj_stat = gss_release_buffer (&min_stat, &bufdesc1);
273 if (GSS_ERROR (maj_stat))
277 *output = malloc (bufdesc2.length);
280 memcpy (*output, bufdesc2.value, bufdesc2.length);
281 *output_len = bufdesc2.length;
283 maj_stat = gss_release_buffer (&min_stat, &bufdesc2);
284 if (GSS_ERROR (maj_stat))
308 if (state->
context != GSS_C_NO_CONTEXT)
309 gss_delete_sec_context (&min_stat, &state->
context, GSS_C_NO_BUFFER);
311 if (state->
cred != GSS_C_NO_CREDENTIAL)
312 gss_release_cred (&min_stat, &state->
cred);
314 if (state->
client != GSS_C_NO_NAME)
315 gss_release_name (&min_stat, &state->
client);
int gsasl_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
int _gsasl_gs2_server_start(Gsasl_session *sctx, void **mech_data)
int _gsasl_gs2_server_step(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)
void _gsasl_gs2_server_finish(Gsasl_session *sctx, void *mech_data)
int gs2_get_oid(Gsasl_session *sctx, gss_OID *mech_oid)
@ GSASL_GSSAPI_IMPORT_NAME_ERROR
@ GSASL_GSSAPI_RELEASE_OID_SET_ERROR
@ GSASL_GSSAPI_RELEASE_BUFFER_ERROR
@ GSASL_GSSAPI_ACCEPT_SEC_CONTEXT_ERROR
@ GSASL_GSSAPI_TEST_OID_SET_MEMBER_ERROR
@ GSASL_GSSAPI_DISPLAY_NAME_ERROR
@ GSASL_GSSAPI_ENCAPSULATE_TOKEN_ERROR
@ GSASL_GSSAPI_ACQUIRE_CRED_ERROR
@ GSASL_MECHANISM_CALLED_TOO_MANY_TIMES
@ GSASL_MECHANISM_PARSE_ERROR
_GSASL_API int gsasl_property_set_raw(Gsasl_session *sctx, Gsasl_property prop, const char *data, size_t len)
_GSASL_API int gsasl_property_set(Gsasl_session *sctx, Gsasl_property prop, const char *data)
_GSASL_API const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
@ GSASL_GSSAPI_DISPLAY_NAME
struct gss_channel_bindings_struct cb