Path: blob/main/sys/rpc/rpcsec_gss/rpcsec_gss_conf.c
39483 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2008 Doug Rabson4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <sys/systm.h>30#include <sys/kobj.h>31#include <sys/lock.h>32#include <sys/malloc.h>33#include <sys/mutex.h>3435#include <rpc/rpc.h>36#include <rpc/rpcsec_gss.h>3738#include "rpcsec_gss_int.h"3940bool_t41rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret)42{43gss_OID oid = kgss_find_mech_by_name(mech);4445if (oid) {46*oid_ret = oid;47return (TRUE);48}49_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);50return (FALSE);51}5253bool_t54rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret)55{56const char *name = kgss_find_mech_by_oid(oid);5758if (name) {59*mech_ret = name;60return (TRUE);61}62_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);63return (FALSE);64}6566bool_t67rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret)68{6970if (!strcmp(qop, "default")) {71*num_ret = GSS_C_QOP_DEFAULT;72return (TRUE);73}74_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);75return (FALSE);76}7778const char *79_rpc_gss_num_to_qop(const char *mech, u_int num)80{8182if (num == GSS_C_QOP_DEFAULT)83return "default";8485return (NULL);86}8788const char **89rpc_gss_get_mechanisms(void)90{91static const char **mech_names = NULL;92struct kgss_mech *km;93int count;9495if (mech_names)96return (mech_names);9798count = 0;99LIST_FOREACH(km, &kgss_mechs, km_link) {100count++;101}102count++;103104mech_names = malloc(count * sizeof(const char *), M_RPC, M_WAITOK);105count = 0;106LIST_FOREACH(km, &kgss_mechs, km_link) {107mech_names[count++] = km->km_mech_name;108}109mech_names[count++] = NULL;110111return (mech_names);112}113114#if 0115const char **116rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service)117{118struct mech_info *info;119120_rpc_gss_load_mech();121_rpc_gss_load_qop();122SLIST_FOREACH(info, &mechs, link) {123if (!strcmp(mech, info->name)) {124/*125* I'm not sure what to do with service126* here. The Solaris manpages are not clear on127* the subject and the OpenSolaris code just128* sets it to rpc_gss_svc_privacy129* unconditionally with a comment noting that130* it is bogus.131*/132*service = rpc_gss_svc_privacy;133return info->qops;134}135}136137_rpc_gss_set_error(RPC_GSS_ER_SYSTEMERROR, ENOENT);138return (NULL);139}140#endif141142bool_t143rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo)144{145146*vers_hi = 1;147*vers_lo = 1;148return (TRUE);149}150151bool_t152rpc_gss_is_installed(const char *mech)153{154gss_OID oid = kgss_find_mech_by_name(mech);155156if (oid)157return (TRUE);158else159return (FALSE);160}161162163164