xref: /freebsd/sys/kgssapi/gss_release_name.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1a9148abdSDoug Rabson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
34de8ade9SPedro F. Giffuni  *
4a9148abdSDoug Rabson  * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
5a9148abdSDoug Rabson  * Authors: Doug Rabson <dfr@rabson.org>
6a9148abdSDoug Rabson  * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
7a9148abdSDoug Rabson  *
8a9148abdSDoug Rabson  * Redistribution and use in source and binary forms, with or without
9a9148abdSDoug Rabson  * modification, are permitted provided that the following conditions
10a9148abdSDoug Rabson  * are met:
11a9148abdSDoug Rabson  * 1. Redistributions of source code must retain the above copyright
12a9148abdSDoug Rabson  *    notice, this list of conditions and the following disclaimer.
13a9148abdSDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
14a9148abdSDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
15a9148abdSDoug Rabson  *    documentation and/or other materials provided with the distribution.
16a9148abdSDoug Rabson  *
17a9148abdSDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18a9148abdSDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a9148abdSDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a9148abdSDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21a9148abdSDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a9148abdSDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a9148abdSDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a9148abdSDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a9148abdSDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a9148abdSDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a9148abdSDoug Rabson  * SUCH DAMAGE.
28a9148abdSDoug Rabson  */
29a9148abdSDoug Rabson 
30a9148abdSDoug Rabson #include <sys/param.h>
312894c8c9SRick Macklem #include <sys/jail.h>
32a9148abdSDoug Rabson #include <sys/kernel.h>
33a9148abdSDoug Rabson #include <sys/kobj.h>
3413870d5dSRick Macklem #include <sys/lock.h>
35a9148abdSDoug Rabson #include <sys/malloc.h>
3613870d5dSRick Macklem #include <sys/mutex.h>
37a9148abdSDoug Rabson 
38a9148abdSDoug Rabson #include <kgssapi/gssapi.h>
39a9148abdSDoug Rabson #include <kgssapi/gssapi_impl.h>
40a9148abdSDoug Rabson 
41a9148abdSDoug Rabson #include "gssd.h"
42a9148abdSDoug Rabson 
43a9148abdSDoug Rabson OM_uint32
gss_release_name(OM_uint32 * minor_status,gss_name_t * input_name)44a9148abdSDoug Rabson gss_release_name(OM_uint32 *minor_status, gss_name_t *input_name)
45a9148abdSDoug Rabson {
46a9148abdSDoug Rabson 	struct release_name_res res;
47a9148abdSDoug Rabson 	struct release_name_args args;
48a9148abdSDoug Rabson 	enum clnt_stat stat;
49a9148abdSDoug Rabson 	gss_name_t name;
5013870d5dSRick Macklem 	CLIENT *cl;
5113870d5dSRick Macklem 
5213870d5dSRick Macklem 	*minor_status = 0;
53a9148abdSDoug Rabson 
542894c8c9SRick Macklem 	KGSS_CURVNET_SET_QUIET(KGSS_TD_TO_VNET(curthread));
552894c8c9SRick Macklem 	if (!KGSS_VNET(kgss_gssd_handle)) {
562894c8c9SRick Macklem 		KGSS_CURVNET_RESTORE();
57a9148abdSDoug Rabson 		return (GSS_S_FAILURE);
582894c8c9SRick Macklem 	}
592894c8c9SRick Macklem 	KGSS_CURVNET_RESTORE();
60a9148abdSDoug Rabson 
61a9148abdSDoug Rabson 	if (*input_name) {
62a9148abdSDoug Rabson 		name = *input_name;
63a9148abdSDoug Rabson 		args.input_name = name->handle;
64a9148abdSDoug Rabson 
6513870d5dSRick Macklem 		cl = kgss_gssd_client();
6613870d5dSRick Macklem 		if (cl == NULL)
6713870d5dSRick Macklem 			return (GSS_S_FAILURE);
6813870d5dSRick Macklem 		stat = gssd_release_name_1(&args, &res, cl);
6913870d5dSRick Macklem 		CLNT_RELEASE(cl);
70a9148abdSDoug Rabson 		if (stat != RPC_SUCCESS) {
71a9148abdSDoug Rabson 			*minor_status = stat;
72a9148abdSDoug Rabson 			return (GSS_S_FAILURE);
73a9148abdSDoug Rabson 		}
74a9148abdSDoug Rabson 
75a9148abdSDoug Rabson 		free(name, M_GSSAPI);
76a9148abdSDoug Rabson 		*input_name = NULL;
77a9148abdSDoug Rabson 
78a9148abdSDoug Rabson 		if (res.major_status != GSS_S_COMPLETE) {
79a9148abdSDoug Rabson 			*minor_status = res.minor_status;
80a9148abdSDoug Rabson 			return (res.major_status);
81a9148abdSDoug Rabson 		}
82a9148abdSDoug Rabson 	}
83a9148abdSDoug Rabson 
84a9148abdSDoug Rabson 	return (GSS_S_COMPLETE);
85a9148abdSDoug Rabson }
86