xref: /netbsd-src/crypto/external/bsd/openssh/dist/gss-serv.c (revision 8db691be9054b79fe6a8cb4febe9efe24dae371d)
1*8db691beSchristos /*	$NetBSD: gss-serv.c,v 1.15 2020/05/28 17:05:49 christos Exp $	*/
2*8db691beSchristos /* $OpenBSD: gss-serv.c,v 1.32 2020/03/13 03:17:07 djm Exp $ */
3ca32bd8dSchristos 
4ca32bd8dSchristos /*
5ca32bd8dSchristos  * Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
6ca32bd8dSchristos  *
7ca32bd8dSchristos  * Redistribution and use in source and binary forms, with or without
8ca32bd8dSchristos  * modification, are permitted provided that the following conditions
9ca32bd8dSchristos  * are met:
10ca32bd8dSchristos  * 1. Redistributions of source code must retain the above copyright
11ca32bd8dSchristos  *    notice, this list of conditions and the following disclaimer.
12ca32bd8dSchristos  * 2. Redistributions in binary form must reproduce the above copyright
13ca32bd8dSchristos  *    notice, this list of conditions and the following disclaimer in the
14ca32bd8dSchristos  *    documentation and/or other materials provided with the distribution.
15ca32bd8dSchristos  *
16ca32bd8dSchristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
17ca32bd8dSchristos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18ca32bd8dSchristos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19ca32bd8dSchristos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20ca32bd8dSchristos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21ca32bd8dSchristos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22ca32bd8dSchristos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23ca32bd8dSchristos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24ca32bd8dSchristos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25ca32bd8dSchristos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26ca32bd8dSchristos  */
27ca32bd8dSchristos 
28313c6c94Schristos #include "includes.h"
29*8db691beSchristos __RCSID("$NetBSD: gss-serv.c,v 1.15 2020/05/28 17:05:49 christos Exp $");
304054ffb0Schristos 
314054ffb0Schristos #include <sys/param.h>
32ca32bd8dSchristos #include <sys/types.h>
33ca32bd8dSchristos #include <sys/queue.h>
34ca32bd8dSchristos 
35ca32bd8dSchristos #ifdef GSSAPI
36ca32bd8dSchristos 
37ca32bd8dSchristos #include <string.h>
38313c6c94Schristos #include <unistd.h>
398a4530f9Schristos #include <netdb.h>
40e4d43b82Schristos #include <limits.h>
41ed75d7a8Schristos #include <stdarg.h>
42ca32bd8dSchristos 
43ca32bd8dSchristos #include "xmalloc.h"
4455a4608bSchristos #include "sshkey.h"
45ca32bd8dSchristos #include "hostfile.h"
46ca32bd8dSchristos #include "auth.h"
47ca32bd8dSchristos #include "log.h"
48ca32bd8dSchristos #include "channels.h"
49ca32bd8dSchristos #include "session.h"
50ca32bd8dSchristos #include "misc.h"
514054ffb0Schristos #include "servconf.h"
52ca32bd8dSchristos 
53ca32bd8dSchristos #include "ssh-gss.h"
54ca32bd8dSchristos 
554054ffb0Schristos extern ServerOptions options;
564054ffb0Schristos 
57ca32bd8dSchristos static ssh_gssapi_client gssapi_client =
58ca32bd8dSchristos     { GSS_C_EMPTY_BUFFER, GSS_C_EMPTY_BUFFER,
59185c8f97Schristos     GSS_C_NO_CREDENTIAL, NULL, {NULL, NULL, NULL, NULL}};
60ca32bd8dSchristos 
61ca32bd8dSchristos ssh_gssapi_mech gssapi_null_mech =
62ca32bd8dSchristos     { NULL, NULL, {0, NULL}, NULL, NULL, NULL, NULL};
63ca32bd8dSchristos 
64ca32bd8dSchristos #ifdef KRB5
65ca32bd8dSchristos extern ssh_gssapi_mech gssapi_kerberos_mech;
66ca32bd8dSchristos #endif
67ca32bd8dSchristos 
68ca32bd8dSchristos ssh_gssapi_mech* supported_mechs[]= {
69ca32bd8dSchristos #ifdef KRB5
70ca32bd8dSchristos 	&gssapi_kerberos_mech,
71ca32bd8dSchristos #endif
72ca32bd8dSchristos 	&gssapi_null_mech,
73ca32bd8dSchristos };
74ca32bd8dSchristos 
758a4530f9Schristos /*
768a4530f9Schristos  * ssh_gssapi_supported_oids() can cause sandbox violations, so prepare the
778a4530f9Schristos  * list of supported mechanisms before privsep is set up.
788a4530f9Schristos  */
798a4530f9Schristos static gss_OID_set supported_oids;
808a4530f9Schristos 
818a4530f9Schristos void
ssh_gssapi_prepare_supported_oids(void)828a4530f9Schristos ssh_gssapi_prepare_supported_oids(void)
838a4530f9Schristos {
848a4530f9Schristos 	ssh_gssapi_supported_oids(&supported_oids);
858a4530f9Schristos }
868a4530f9Schristos 
878a4530f9Schristos OM_uint32
ssh_gssapi_test_oid_supported(OM_uint32 * ms,gss_OID member,int * present)888a4530f9Schristos ssh_gssapi_test_oid_supported(OM_uint32 *ms, gss_OID member, int *present)
898a4530f9Schristos {
908a4530f9Schristos 	if (supported_oids == NULL)
918a4530f9Schristos 		ssh_gssapi_prepare_supported_oids();
928a4530f9Schristos 	return gss_test_oid_set_member(ms, member, supported_oids, present);
938a4530f9Schristos }
94ca32bd8dSchristos 
95ca32bd8dSchristos /*
96ca32bd8dSchristos  * Acquire credentials for a server running on the current host.
97ca32bd8dSchristos  * Requires that the context structure contains a valid OID
98ca32bd8dSchristos  */
99ca32bd8dSchristos 
100ca32bd8dSchristos /* Returns a GSSAPI error code */
101ca32bd8dSchristos /* Privileged (called from ssh_gssapi_server_ctx) */
102ca32bd8dSchristos static OM_uint32
ssh_gssapi_acquire_cred(Gssctxt * ctx)103ca32bd8dSchristos ssh_gssapi_acquire_cred(Gssctxt *ctx)
104ca32bd8dSchristos {
105ca32bd8dSchristos 	OM_uint32 status;
1068a4530f9Schristos 	char lname[NI_MAXHOST];
107ca32bd8dSchristos 	gss_OID_set oidset;
108ca32bd8dSchristos 
1094054ffb0Schristos 	if (options.gss_strict_acceptor) {
110ca32bd8dSchristos 		gss_create_empty_oid_set(&status, &oidset);
111ca32bd8dSchristos 		gss_add_oid_set_member(&status, ctx->oid, &oidset);
112ca32bd8dSchristos 
1134054ffb0Schristos 		if (gethostname(lname, MAXHOSTNAMELEN)) {
114ca32bd8dSchristos 			gss_release_oid_set(&status, &oidset);
115ca32bd8dSchristos 			return (-1);
116ca32bd8dSchristos 		}
117ca32bd8dSchristos 
118ca32bd8dSchristos 		if (GSS_ERROR(ssh_gssapi_import_name(ctx, lname))) {
119ca32bd8dSchristos 			gss_release_oid_set(&status, &oidset);
120ca32bd8dSchristos 			return (ctx->major);
121ca32bd8dSchristos 		}
122ca32bd8dSchristos 
123ca32bd8dSchristos 		if ((ctx->major = gss_acquire_cred(&ctx->minor,
1244054ffb0Schristos 		    ctx->name, 0, oidset, GSS_C_ACCEPT, &ctx->creds,
1254054ffb0Schristos 		    NULL, NULL)))
126ca32bd8dSchristos 			ssh_gssapi_error(ctx);
127ca32bd8dSchristos 
128ca32bd8dSchristos 		gss_release_oid_set(&status, &oidset);
129ca32bd8dSchristos 		return (ctx->major);
1304054ffb0Schristos 	} else {
1314054ffb0Schristos 		ctx->name = GSS_C_NO_NAME;
1324054ffb0Schristos 		ctx->creds = GSS_C_NO_CREDENTIAL;
1334054ffb0Schristos 	}
1344054ffb0Schristos 	return GSS_S_COMPLETE;
135ca32bd8dSchristos }
136ca32bd8dSchristos 
137ca32bd8dSchristos /* Privileged */
138ca32bd8dSchristos OM_uint32
ssh_gssapi_server_ctx(Gssctxt ** ctx,gss_OID oid)139ca32bd8dSchristos ssh_gssapi_server_ctx(Gssctxt **ctx, gss_OID oid)
140ca32bd8dSchristos {
141ca32bd8dSchristos 	if (*ctx)
142ca32bd8dSchristos 		ssh_gssapi_delete_ctx(ctx);
143ca32bd8dSchristos 	ssh_gssapi_build_ctx(ctx);
144ca32bd8dSchristos 	ssh_gssapi_set_oid(*ctx, oid);
145ca32bd8dSchristos 	return (ssh_gssapi_acquire_cred(*ctx));
146ca32bd8dSchristos }
147ca32bd8dSchristos 
148ca32bd8dSchristos /* Unprivileged */
149ca32bd8dSchristos void
ssh_gssapi_supported_oids(gss_OID_set * oidset)150ca32bd8dSchristos ssh_gssapi_supported_oids(gss_OID_set *oidset)
151ca32bd8dSchristos {
152ca32bd8dSchristos 	int i = 0;
153ca32bd8dSchristos 	OM_uint32 min_status;
154ca32bd8dSchristos 	int present;
155ca32bd8dSchristos 	gss_OID_set supported;
156ca32bd8dSchristos 
157ca32bd8dSchristos 	gss_create_empty_oid_set(&min_status, oidset);
158ca32bd8dSchristos 	gss_indicate_mechs(&min_status, &supported);
159ca32bd8dSchristos 
160ca32bd8dSchristos 	while (supported_mechs[i]->name != NULL) {
161ca32bd8dSchristos 		if (GSS_ERROR(gss_test_oid_set_member(&min_status,
162ca32bd8dSchristos 		    &supported_mechs[i]->oid, supported, &present)))
163ca32bd8dSchristos 			present = 0;
164ca32bd8dSchristos 		if (present)
165ca32bd8dSchristos 			gss_add_oid_set_member(&min_status,
166ca32bd8dSchristos 			    &supported_mechs[i]->oid, oidset);
167ca32bd8dSchristos 		i++;
168ca32bd8dSchristos 	}
169ca32bd8dSchristos 
170ca32bd8dSchristos 	gss_release_oid_set(&min_status, &supported);
171ca32bd8dSchristos }
172ca32bd8dSchristos 
173ca32bd8dSchristos 
174ca32bd8dSchristos /* Wrapper around accept_sec_context
175ca32bd8dSchristos  * Requires that the context contains:
176ca32bd8dSchristos  *    oid
177ca32bd8dSchristos  *    credentials	(from ssh_gssapi_acquire_cred)
178ca32bd8dSchristos  */
179ca32bd8dSchristos /* Privileged */
180ca32bd8dSchristos OM_uint32
ssh_gssapi_accept_ctx(Gssctxt * ctx,gss_buffer_desc * recv_tok,gss_buffer_desc * send_tok,OM_uint32 * flags)181ca32bd8dSchristos ssh_gssapi_accept_ctx(Gssctxt *ctx, gss_buffer_desc *recv_tok,
182ca32bd8dSchristos     gss_buffer_desc *send_tok, OM_uint32 *flags)
183ca32bd8dSchristos {
184ca32bd8dSchristos 	OM_uint32 status;
185ca32bd8dSchristos 	gss_OID mech;
186ca32bd8dSchristos 
187ca32bd8dSchristos 	ctx->major = gss_accept_sec_context(&ctx->minor,
188ca32bd8dSchristos 	    &ctx->context, ctx->creds, recv_tok,
189ca32bd8dSchristos 	    GSS_C_NO_CHANNEL_BINDINGS, &ctx->client, &mech,
190ca32bd8dSchristos 	    send_tok, flags, NULL, &ctx->client_creds);
191ca32bd8dSchristos 
192ca32bd8dSchristos 	if (GSS_ERROR(ctx->major))
193ca32bd8dSchristos 		ssh_gssapi_error(ctx);
194ca32bd8dSchristos 
195ca32bd8dSchristos 	if (ctx->client_creds)
196ca32bd8dSchristos 		debug("Received some client credentials");
197ca32bd8dSchristos 	else
198ca32bd8dSchristos 		debug("Got no client credentials");
199ca32bd8dSchristos 
200ca32bd8dSchristos 	status = ctx->major;
201ca32bd8dSchristos 
202ca32bd8dSchristos 	/* Now, if we're complete and we have the right flags, then
203ca32bd8dSchristos 	 * we flag the user as also having been authenticated
204ca32bd8dSchristos 	 */
205ca32bd8dSchristos 
206ca32bd8dSchristos 	if (((flags == NULL) || ((*flags & GSS_C_MUTUAL_FLAG) &&
207ca32bd8dSchristos 	    (*flags & GSS_C_INTEG_FLAG))) && (ctx->major == GSS_S_COMPLETE)) {
208ca32bd8dSchristos 		if (ssh_gssapi_getclient(ctx, &gssapi_client))
209ca32bd8dSchristos 			fatal("Couldn't convert client name");
210ca32bd8dSchristos 	}
211ca32bd8dSchristos 
212ca32bd8dSchristos 	return (status);
213ca32bd8dSchristos }
214ca32bd8dSchristos 
215ca32bd8dSchristos /*
216ca32bd8dSchristos  * This parses an exported name, extracting the mechanism specific portion
217ca32bd8dSchristos  * to use for ACL checking. It verifies that the name belongs the mechanism
218ca32bd8dSchristos  * originally selected.
219ca32bd8dSchristos  */
220ca32bd8dSchristos static OM_uint32
ssh_gssapi_parse_ename(Gssctxt * ctx,gss_buffer_t ename,gss_buffer_t name)221ca32bd8dSchristos ssh_gssapi_parse_ename(Gssctxt *ctx, gss_buffer_t ename, gss_buffer_t name)
222ca32bd8dSchristos {
223ca32bd8dSchristos 	u_char *tok;
224ca32bd8dSchristos 	OM_uint32 offset;
225ca32bd8dSchristos 	OM_uint32 oidl;
226ca32bd8dSchristos 
227ca32bd8dSchristos 	tok = ename->value;
228ca32bd8dSchristos 
229ca32bd8dSchristos 	/*
230ca32bd8dSchristos 	 * Check that ename is long enough for all of the fixed length
231ca32bd8dSchristos 	 * header, and that the initial ID bytes are correct
232ca32bd8dSchristos 	 */
233ca32bd8dSchristos 
234ca32bd8dSchristos 	if (ename->length < 6 || memcmp(tok, "\x04\x01", 2) != 0)
235ca32bd8dSchristos 		return GSS_S_FAILURE;
236ca32bd8dSchristos 
237ca32bd8dSchristos 	/*
238ca32bd8dSchristos 	 * Extract the OID, and check it. Here GSSAPI breaks with tradition
239ca32bd8dSchristos 	 * and does use the OID type and length bytes. To confuse things
240ca32bd8dSchristos 	 * there are two lengths - the first including these, and the
241ca32bd8dSchristos 	 * second without.
242ca32bd8dSchristos 	 */
243ca32bd8dSchristos 
244ca32bd8dSchristos 	oidl = get_u16(tok+2); /* length including next two bytes */
245ca32bd8dSchristos 	oidl = oidl-2; /* turn it into the _real_ length of the variable OID */
246ca32bd8dSchristos 
247ca32bd8dSchristos 	/*
248ca32bd8dSchristos 	 * Check the BER encoding for correct type and length, that the
249ca32bd8dSchristos 	 * string is long enough and that the OID matches that in our context
250ca32bd8dSchristos 	 */
251ca32bd8dSchristos 	if (tok[4] != 0x06 || tok[5] != oidl ||
252ca32bd8dSchristos 	    ename->length < oidl+6 ||
253ca32bd8dSchristos 	    !ssh_gssapi_check_oid(ctx, tok+6, oidl))
254ca32bd8dSchristos 		return GSS_S_FAILURE;
255ca32bd8dSchristos 
256ca32bd8dSchristos 	offset = oidl+6;
257ca32bd8dSchristos 
258ca32bd8dSchristos 	if (ename->length < offset+4)
259ca32bd8dSchristos 		return GSS_S_FAILURE;
260ca32bd8dSchristos 
261ca32bd8dSchristos 	name->length = get_u32(tok+offset);
262ca32bd8dSchristos 	offset += 4;
263ca32bd8dSchristos 
2646f47b660Schristos 	if (UINT_MAX - offset < name->length)
2656f47b660Schristos 		return GSS_S_FAILURE;
266ca32bd8dSchristos 	if (ename->length < offset+name->length)
267ca32bd8dSchristos 		return GSS_S_FAILURE;
268ca32bd8dSchristos 
269ca32bd8dSchristos 	name->value = xmalloc(name->length+1);
270ca32bd8dSchristos 	memcpy(name->value, tok+offset, name->length);
271ca32bd8dSchristos 	((char *)name->value)[name->length] = 0;
272ca32bd8dSchristos 
273ca32bd8dSchristos 	return GSS_S_COMPLETE;
274ca32bd8dSchristos }
275ca32bd8dSchristos 
276ca32bd8dSchristos /* Extract the client details from a given context. This can only reliably
277ca32bd8dSchristos  * be called once for a context */
278ca32bd8dSchristos 
279ca32bd8dSchristos /* Privileged (called from accept_secure_ctx) */
280ca32bd8dSchristos OM_uint32
ssh_gssapi_getclient(Gssctxt * ctx,ssh_gssapi_client * client)281ca32bd8dSchristos ssh_gssapi_getclient(Gssctxt *ctx, ssh_gssapi_client *client)
282ca32bd8dSchristos {
283ca32bd8dSchristos 	int i = 0;
284ca32bd8dSchristos 
285ca32bd8dSchristos 	gss_buffer_desc ename;
286ca32bd8dSchristos 
287ca32bd8dSchristos 	client->mech = NULL;
288ca32bd8dSchristos 
289ca32bd8dSchristos 	while (supported_mechs[i]->name != NULL) {
290ca32bd8dSchristos 		if (supported_mechs[i]->oid.length == ctx->oid->length &&
291ca32bd8dSchristos 		    (memcmp(supported_mechs[i]->oid.elements,
292ca32bd8dSchristos 		    ctx->oid->elements, ctx->oid->length) == 0))
293ca32bd8dSchristos 			client->mech = supported_mechs[i];
294ca32bd8dSchristos 		i++;
295ca32bd8dSchristos 	}
296ca32bd8dSchristos 
297ca32bd8dSchristos 	if (client->mech == NULL)
298ca32bd8dSchristos 		return GSS_S_FAILURE;
299ca32bd8dSchristos 
300ca32bd8dSchristos 	if ((ctx->major = gss_display_name(&ctx->minor, ctx->client,
301ca32bd8dSchristos 	    &client->displayname, NULL))) {
302ca32bd8dSchristos 		ssh_gssapi_error(ctx);
303ca32bd8dSchristos 		return (ctx->major);
304ca32bd8dSchristos 	}
305ca32bd8dSchristos 
306ca32bd8dSchristos 	if ((ctx->major = gss_export_name(&ctx->minor, ctx->client,
307ca32bd8dSchristos 	    &ename))) {
308ca32bd8dSchristos 		ssh_gssapi_error(ctx);
309ca32bd8dSchristos 		return (ctx->major);
310ca32bd8dSchristos 	}
311ca32bd8dSchristos 
312ca32bd8dSchristos 	if ((ctx->major = ssh_gssapi_parse_ename(ctx,&ename,
313ca32bd8dSchristos 	    &client->exportedname))) {
314ca32bd8dSchristos 		return (ctx->major);
315ca32bd8dSchristos 	}
316ca32bd8dSchristos 
317ca32bd8dSchristos 	/* We can't copy this structure, so we just move the pointer to it */
318ca32bd8dSchristos 	client->creds = ctx->client_creds;
319ca32bd8dSchristos 	ctx->client_creds = GSS_C_NO_CREDENTIAL;
320ca32bd8dSchristos 	return (ctx->major);
321ca32bd8dSchristos }
322ca32bd8dSchristos 
323ca32bd8dSchristos /* As user - called on fatal/exit */
324ca32bd8dSchristos void
ssh_gssapi_cleanup_creds(void)325ca32bd8dSchristos ssh_gssapi_cleanup_creds(void)
326ca32bd8dSchristos {
327ca32bd8dSchristos 	if (gssapi_client.store.filename != NULL) {
328ca32bd8dSchristos 		/* Unlink probably isn't sufficient */
329ca32bd8dSchristos 		debug("removing gssapi cred file\"%s\"",
330ca32bd8dSchristos 		    gssapi_client.store.filename);
331ca32bd8dSchristos 		unlink(gssapi_client.store.filename);
332ca32bd8dSchristos 	}
333ca32bd8dSchristos }
334ca32bd8dSchristos 
335ca32bd8dSchristos /* As user */
336ca32bd8dSchristos void
ssh_gssapi_storecreds(void)337ca32bd8dSchristos ssh_gssapi_storecreds(void)
338ca32bd8dSchristos {
339ca32bd8dSchristos 	if (gssapi_client.mech && gssapi_client.mech->storecreds) {
340ca32bd8dSchristos 		(*gssapi_client.mech->storecreds)(&gssapi_client);
341ca32bd8dSchristos 	} else
342ca32bd8dSchristos 		debug("ssh_gssapi_storecreds: Not a GSSAPI mechanism");
343ca32bd8dSchristos }
344ca32bd8dSchristos 
345*8db691beSchristos /* This allows GSSAPI methods to do things to the child's environment based
346ca32bd8dSchristos  * on the passed authentication process and credentials.
347ca32bd8dSchristos  */
348ca32bd8dSchristos /* As user */
349ca32bd8dSchristos void
ssh_gssapi_do_child(char *** envp,u_int * envsizep)350ca32bd8dSchristos ssh_gssapi_do_child(char ***envp, u_int *envsizep)
351ca32bd8dSchristos {
352ca32bd8dSchristos 
353ca32bd8dSchristos 	if (gssapi_client.store.envvar != NULL &&
354ca32bd8dSchristos 	    gssapi_client.store.envval != NULL) {
355ca32bd8dSchristos 		debug("Setting %s to %s", gssapi_client.store.envvar,
356ca32bd8dSchristos 		    gssapi_client.store.envval);
357ca32bd8dSchristos 		child_set_env(envp, envsizep, gssapi_client.store.envvar,
358ca32bd8dSchristos 		    gssapi_client.store.envval);
359ca32bd8dSchristos 	}
360ca32bd8dSchristos }
361ca32bd8dSchristos 
362ca32bd8dSchristos /* Privileged */
363ca32bd8dSchristos int
ssh_gssapi_userok(char * user)364ca32bd8dSchristos ssh_gssapi_userok(char *user)
365ca32bd8dSchristos {
366ca32bd8dSchristos 	OM_uint32 lmin;
367ca32bd8dSchristos 
368ca32bd8dSchristos 	if (gssapi_client.exportedname.length == 0 ||
369ca32bd8dSchristos 	    gssapi_client.exportedname.value == NULL) {
370ca32bd8dSchristos 		debug("No suitable client data");
371ca32bd8dSchristos 		return 0;
372ca32bd8dSchristos 	}
373ca32bd8dSchristos 	if (gssapi_client.mech && gssapi_client.mech->userok)
374ca32bd8dSchristos 		if ((*gssapi_client.mech->userok)(&gssapi_client, user))
375ca32bd8dSchristos 			return 1;
376ca32bd8dSchristos 		else {
377ca32bd8dSchristos 			/* Destroy delegated credentials if userok fails */
378ca32bd8dSchristos 			gss_release_buffer(&lmin, &gssapi_client.displayname);
379ca32bd8dSchristos 			gss_release_buffer(&lmin, &gssapi_client.exportedname);
380ca32bd8dSchristos 			gss_release_cred(&lmin, &gssapi_client.creds);
3818a4530f9Schristos 			explicit_bzero(&gssapi_client,
3828a4530f9Schristos 			    sizeof(ssh_gssapi_client));
383ca32bd8dSchristos 			return 0;
384ca32bd8dSchristos 		}
385ca32bd8dSchristos 	else
386ca32bd8dSchristos 		debug("ssh_gssapi_userok: Unknown GSSAPI mechanism");
387ca32bd8dSchristos 	return (0);
388ca32bd8dSchristos }
389ca32bd8dSchristos 
390ca32bd8dSchristos /* Privileged */
391ca32bd8dSchristos OM_uint32
ssh_gssapi_checkmic(Gssctxt * ctx,gss_buffer_t gssbuf,gss_buffer_t gssmic)392ca32bd8dSchristos ssh_gssapi_checkmic(Gssctxt *ctx, gss_buffer_t gssbuf, gss_buffer_t gssmic)
393ca32bd8dSchristos {
394ca32bd8dSchristos 	ctx->major = gss_verify_mic(&ctx->minor, ctx->context,
395ca32bd8dSchristos 	    gssbuf, gssmic, NULL);
396ca32bd8dSchristos 
397ca32bd8dSchristos 	return (ctx->major);
398ca32bd8dSchristos }
399ca32bd8dSchristos 
4007a183406Schristos /* Privileged */
ssh_gssapi_displayname(void)4017a183406Schristos const char *ssh_gssapi_displayname(void)
4027a183406Schristos {
4037a183406Schristos 	if (gssapi_client.displayname.length == 0 ||
4047a183406Schristos 	    gssapi_client.displayname.value == NULL)
4057a183406Schristos 		return NULL;
4067a183406Schristos 	return (char *)gssapi_client.displayname.value;
4077a183406Schristos }
4087a183406Schristos 
409ca32bd8dSchristos #endif
410