2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008 Doug Rabson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
36 #include <sys/malloc.h>
37 #include <sys/mutex.h>
40 #include <rpc/rpcsec_gss.h>
42 #include "rpcsec_gss_int.h"
45 rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret)
47 gss_OID oid = kgss_find_mech_by_name(mech);
53 _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
58 rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret)
60 const char *name = kgss_find_mech_by_oid(oid);
66 _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
71 rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret)
74 if (!strcmp(qop, "default")) {
75 *num_ret = GSS_C_QOP_DEFAULT;
78 _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
83 _rpc_gss_num_to_qop(const char *mech, u_int num)
86 if (num == GSS_C_QOP_DEFAULT)
93 rpc_gss_get_mechanisms(void)
95 static const char **mech_names = NULL;
103 LIST_FOREACH(km, &kgss_mechs, km_link) {
108 mech_names = malloc(count * sizeof(const char *), M_RPC, M_WAITOK);
110 LIST_FOREACH(km, &kgss_mechs, km_link) {
111 mech_names[count++] = km->km_mech_name;
113 mech_names[count++] = NULL;
120 rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service)
122 struct mech_info *info;
124 _rpc_gss_load_mech();
126 SLIST_FOREACH(info, &mechs, link) {
127 if (!strcmp(mech, info->name)) {
129 * I'm not sure what to do with service
130 * here. The Solaris manpages are not clear on
131 * the subject and the OpenSolaris code just
132 * sets it to rpc_gss_svc_privacy
133 * unconditionally with a comment noting that
136 *service = rpc_gss_svc_privacy;
141 _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
147 rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo)
156 rpc_gss_is_installed(const char *mech)
158 gss_OID oid = kgss_find_mech_by_name(mech);