35 #include "gss-extra.h"
55 state->
context = GSS_C_NO_CONTEXT;
68 const char *input,
size_t input_len,
69 char **output,
size_t *output_len)
74 gss_buffer_desc bufdesc, bufdesc2;
75 gss_buffer_t buf = GSS_C_NO_BUFFER;
76 OM_uint32 maj_stat, min_stat;
95 bufdesc.length = strlen (
service) + 1 + strlen (hostname) + 1;
96 bufdesc.value = malloc (bufdesc.length);
97 if (bufdesc.value == NULL)
100 sprintf (bufdesc.value,
"%s@%s",
service, hostname);
102 maj_stat = gss_import_name (&min_stat, &bufdesc,
103 GSS_C_NT_HOSTBASED_SERVICE,
105 free (bufdesc.value);
106 if (GSS_ERROR (maj_stat))
113 bufdesc.length = input_len;
114 bufdesc.value = (
void *) input;
120 bufdesc2.value = NULL;
121 maj_stat = gss_init_sec_context (&min_stat,
128 GSS_C_SEQUENCE_FLAG |
132 GSS_C_NO_CHANNEL_BINDINGS,
133 buf, NULL, &bufdesc2, NULL, NULL);
134 if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED)
137 if (bufdesc2.length > 0 && bufdesc2.value == NULL)
140 *output_len = bufdesc2.length;
141 *output = malloc (*output_len);
145 memcpy (*output, bufdesc2.value, bufdesc2.length);
147 if (maj_stat == GSS_S_COMPLETE)
152 maj_stat = gss_release_buffer (&min_stat, &bufdesc2);
153 if (maj_stat != GSS_S_COMPLETE)
175 bufdesc.length = input_len;
176 bufdesc.value = (
void *) input;
177 maj_stat = gss_unwrap (&min_stat, state->
context, &bufdesc,
178 &bufdesc2, &conf_state, &serverqop);
179 if (GSS_ERROR (maj_stat))
182 if (bufdesc2.length != 4)
185 memcpy (clientwrap, bufdesc2.value, 4);
187 maj_stat = gss_release_buffer (&min_stat, &bufdesc2);
188 if (GSS_ERROR (maj_stat))
194 state->
qop = cb_qop (sctx, serverqop);
196 if ((state->
qop & serverqop) == 0)
207 bufdesc.length = 4 + strlen (p);
208 bufdesc.value = malloc (bufdesc.length);
213 char *q = bufdesc.value;
215 memcpy (q + 1, clientwrap + 1, 3);
216 memcpy (q + 4, p, strlen (p));
219 maj_stat = gss_wrap (&min_stat, state->
context, 0, GSS_C_QOP_DEFAULT,
220 &bufdesc, &conf_state, &bufdesc2);
221 free (bufdesc.value);
222 if (GSS_ERROR (maj_stat))
225 *output_len = bufdesc2.length;
226 *output = malloc (bufdesc2.length);
230 memcpy (*output, bufdesc2.value, bufdesc2.length);
232 maj_stat = gss_release_buffer (&min_stat, &bufdesc2);
233 if (GSS_ERROR (maj_stat))
252 OM_uint32 maj_stat, min_stat;
257 if (state->
service != GSS_C_NO_NAME)
258 maj_stat = gss_release_name (&min_stat, &state->
service);
259 if (state->
context != GSS_C_NO_CONTEXT)
260 maj_stat = gss_delete_sec_context (&min_stat, &state->
context,
269 const char *input,
size_t input_len,
270 char **output,
size_t *output_len)
273 OM_uint32 min_stat, maj_stat;
275 gss_buffer_t input_message_buffer = &foo;
276 gss_buffer_desc output_message_buffer;
278 foo.length = input_len;
279 foo.value = (
void *) input;
281 if (state && state->
step == 3 &&
284 maj_stat = gss_wrap (&min_stat,
288 input_message_buffer,
289 NULL, &output_message_buffer);
290 if (GSS_ERROR (maj_stat))
292 *output_len = output_message_buffer.length;
293 *output = malloc (output_message_buffer.length);
296 maj_stat = gss_release_buffer (&min_stat, &output_message_buffer);
299 memcpy (*output, output_message_buffer.value,
300 output_message_buffer.length);
302 maj_stat = gss_release_buffer (&min_stat, &output_message_buffer);
303 if (GSS_ERROR (maj_stat))
311 *output_len = input_len;
312 *output = malloc (input_len);
315 memcpy (*output, input, input_len);
324 const char *input,
size_t input_len,
325 char **output,
size_t *output_len)
328 OM_uint32 min_stat, maj_stat;
330 gss_buffer_t input_message_buffer = &foo;
331 gss_buffer_desc output_message_buffer;
333 foo.length = input_len;
334 foo.value = (
void *) input;
336 if (state && state->
step == 3 &&
339 maj_stat = gss_unwrap (&min_stat,
341 input_message_buffer,
342 &output_message_buffer, NULL, NULL);
343 if (GSS_ERROR (maj_stat))
345 *output_len = output_message_buffer.length;
346 *output = malloc (output_message_buffer.length);
349 maj_stat = gss_release_buffer (&min_stat, &output_message_buffer);
352 memcpy (*output, output_message_buffer.value,
353 output_message_buffer.length);
355 maj_stat = gss_release_buffer (&min_stat, &output_message_buffer);
356 if (GSS_ERROR (maj_stat))
364 *output_len = input_len;
365 *output = malloc (input_len);
368 memcpy (*output, input, input_len);
@ GSASL_GSSAPI_UNWRAP_ERROR
@ GSASL_GSSAPI_IMPORT_NAME_ERROR
@ GSASL_GSSAPI_RELEASE_BUFFER_ERROR
@ GSASL_MECHANISM_CALLED_TOO_MANY_TIMES
@ GSASL_GSSAPI_WRAP_ERROR
@ GSASL_MECHANISM_PARSE_ERROR
@ GSASL_GSSAPI_INIT_SEC_CONTEXT_ERROR
@ GSASL_GSSAPI_UNSUPPORTED_PROTECTION_ERROR
_GSASL_API const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
void _gsasl_gssapi_client_finish(Gsasl_session *sctx, void *mech_data)
int _gsasl_gssapi_client_encode(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)
int _gsasl_gssapi_client_start(Gsasl_session *sctx, void **mech_data)
int _gsasl_gssapi_client_decode(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)
int _gsasl_gssapi_client_step(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)