2 * Copyright (c) 2008 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
34 #include <sys/malloc.h>
35 #include <sys/mutex.h>
38 #include <rpc/rpcsec_gss.h>
40 #include "rpcsec_gss_int.h"
43 rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret)
45 gss_OID oid = kgss_find_mech_by_name(mech);
51 _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
56 rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret)
58 const char *name = kgss_find_mech_by_oid(oid);
64 _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
69 rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret)
72 if (!strcmp(qop, "default")) {
73 *num_ret = GSS_C_QOP_DEFAULT;
76 _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
81 _rpc_gss_num_to_qop(const char *mech, u_int num)
84 if (num == GSS_C_QOP_DEFAULT)
91 rpc_gss_get_mechanisms(void)
93 static const char **mech_names = NULL;
101 LIST_FOREACH(km, &kgss_mechs, km_link) {
106 mech_names = malloc(count * sizeof(const char *), M_RPC, M_WAITOK);
108 LIST_FOREACH(km, &kgss_mechs, km_link) {
109 mech_names[count++] = km->km_mech_name;
111 mech_names[count++] = NULL;
118 rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service)
120 struct mech_info *info;
122 _rpc_gss_load_mech();
124 SLIST_FOREACH(info, &mechs, link) {
125 if (!strcmp(mech, info->name)) {
127 * I'm not sure what to do with service
128 * here. The Solaris manpages are not clear on
129 * the subject and the OpenSolaris code just
130 * sets it to rpc_gss_svc_privacy
131 * unconditionally with a comment noting that
134 *service = rpc_gss_svc_privacy;
139 _rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);
145 rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo)
154 rpc_gss_is_installed(const char *mech)
156 gss_OID oid = kgss_find_mech_by_name(mech);