17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*2e9d26a4Srmesta * Common Development and Distribution License (the "License").
6*2e9d26a4Srmesta * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*2e9d26a4Srmesta * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * sec_svc.c, Server-side rpc security interface.
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate #ifdef _KERNEL
327c478bd9Sstevel@tonic-gate #include <sys/param.h>
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/debug.h>
357c478bd9Sstevel@tonic-gate #include <sys/systm.h>
367c478bd9Sstevel@tonic-gate #include <rpc/types.h>
377c478bd9Sstevel@tonic-gate #include <netinet/in.h>
387c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
397c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
407c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
417c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
427c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
437c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
447c478bd9Sstevel@tonic-gate #include <sys/t_kuser.h>
457c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
467c478bd9Sstevel@tonic-gate #include <rpc/auth_des.h>
477c478bd9Sstevel@tonic-gate #include <rpc/auth_sys.h>
487c478bd9Sstevel@tonic-gate #include <rpc/rpcsec_gss.h>
497c478bd9Sstevel@tonic-gate #include <rpc/svc_auth.h>
507c478bd9Sstevel@tonic-gate #include <rpc/svc.h>
517c478bd9Sstevel@tonic-gate #else
527c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate enum auth_stat _svcauth_null(struct svc_req *, struct rpc_msg *);
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate * NO-OP server wrap/unwrap svc_authany_ops using no-op svc_authany_wrap().
607c478bd9Sstevel@tonic-gate */
617c478bd9Sstevel@tonic-gate /* ARGSUSED */
627c478bd9Sstevel@tonic-gate static int
svc_authany_wrap(SVCAUTH * auth,XDR * xdrs,xdrproc_t xfunc,caddr_t xwhere)637c478bd9Sstevel@tonic-gate svc_authany_wrap(SVCAUTH *auth, XDR *xdrs, xdrproc_t xfunc, caddr_t xwhere)
647c478bd9Sstevel@tonic-gate {
657c478bd9Sstevel@tonic-gate return (*xfunc)(xdrs, xwhere);
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate struct svc_auth_ops svc_authany_ops = {
697c478bd9Sstevel@tonic-gate svc_authany_wrap,
707c478bd9Sstevel@tonic-gate svc_authany_wrap
717c478bd9Sstevel@tonic-gate };
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate * The call rpc message, msg has been obtained from the wire. The msg contains
767c478bd9Sstevel@tonic-gate * the raw form of credentials and verifiers. authenticate returns AUTH_OK
777c478bd9Sstevel@tonic-gate * if the msg is successfully authenticated. If AUTH_OK then the routine also
787c478bd9Sstevel@tonic-gate * does the following things:
797c478bd9Sstevel@tonic-gate * set rqst->rq_xprt->verf to the appropriate response verifier;
807c478bd9Sstevel@tonic-gate * sets rqst->rq_client_cred to the "cooked" form of the credentials.
817c478bd9Sstevel@tonic-gate *
827c478bd9Sstevel@tonic-gate * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
837c478bd9Sstevel@tonic-gate * its length is set appropriately.
847c478bd9Sstevel@tonic-gate *
857c478bd9Sstevel@tonic-gate * The caller still owns and is responsible for msg->u.cmb.cred and
867c478bd9Sstevel@tonic-gate * msg->u.cmb.verf. The authentication system retains ownership of
877c478bd9Sstevel@tonic-gate * rqst->rq_client_cred, the cooked credentials.
887c478bd9Sstevel@tonic-gate *
897c478bd9Sstevel@tonic-gate * There is an assumption that any flavor less than AUTH_NULL is
907c478bd9Sstevel@tonic-gate * invalid.
917c478bd9Sstevel@tonic-gate */
927c478bd9Sstevel@tonic-gate enum auth_stat
sec_svc_msg(struct svc_req * rqst,struct rpc_msg * msg,bool_t * no_dispatch)937c478bd9Sstevel@tonic-gate sec_svc_msg(struct svc_req *rqst, struct rpc_msg *msg, bool_t *no_dispatch)
947c478bd9Sstevel@tonic-gate {
957c478bd9Sstevel@tonic-gate int cred_flavor;
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate rqst->rq_cred = msg->rm_call.cb_cred;
987c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
997c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_verf.oa_length = 0;
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate * Init the xp_auth to be no-op for all the flavors.
1027c478bd9Sstevel@tonic-gate * Flavor specific routines will revise this when appropriate.
1037c478bd9Sstevel@tonic-gate */
1047c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_auth.svc_ah_ops = svc_authany_ops;
1057c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_auth.svc_ah_private = NULL;
1067c478bd9Sstevel@tonic-gate *no_dispatch = FALSE;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate cred_flavor = rqst->rq_cred.oa_flavor;
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate switch (cred_flavor) {
1117c478bd9Sstevel@tonic-gate case AUTH_NULL:
1127c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_cookie = (void *) AUTH_NULL;
1137c478bd9Sstevel@tonic-gate return (_svcauth_null(rqst, msg));
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate case AUTH_UNIX:
1167c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_cookie = (void *) AUTH_UNIX;
1177c478bd9Sstevel@tonic-gate return (_svcauth_unix(rqst, msg));
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate case AUTH_SHORT:
1207c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_cookie = (void *) AUTH_SHORT;
1217c478bd9Sstevel@tonic-gate return (_svcauth_short(rqst, msg));
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate case AUTH_DES:
1247c478bd9Sstevel@tonic-gate rqst->rq_xprt->xp_cookie = (void *) AUTH_DES;
1257c478bd9Sstevel@tonic-gate return (_svcauth_des(rqst, msg));
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate case RPCSEC_GSS:
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate * RPCSEC_GSS flavor routine takes an additional
1307c478bd9Sstevel@tonic-gate * boolean parameter that gets set to TRUE when
1317c478bd9Sstevel@tonic-gate * the call is not to be dispatched to the server.
1327c478bd9Sstevel@tonic-gate */
1337c478bd9Sstevel@tonic-gate return (__svcrpcsec_gss(rqst, msg, no_dispatch));
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate return (AUTH_REJECTEDCRED);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate * sec_svc_getcred() gets unix cred of incoming security rpc requests.
1407c478bd9Sstevel@tonic-gate * It also returns the prinicipal name and a cookie which is application
1417c478bd9Sstevel@tonic-gate * dependent e.g. for nfs, it is the pseudo flavor.
1427c478bd9Sstevel@tonic-gate *
1437c478bd9Sstevel@tonic-gate * return 0 on failure
1447c478bd9Sstevel@tonic-gate */
1457c478bd9Sstevel@tonic-gate int
sec_svc_getcred(struct svc_req * req,cred_t * cr,caddr_t * principal,int * secmod)1467c478bd9Sstevel@tonic-gate sec_svc_getcred(struct svc_req *req, cred_t *cr, caddr_t *principal,
1477c478bd9Sstevel@tonic-gate int *secmod)
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate struct authunix_parms *aup;
1507c478bd9Sstevel@tonic-gate struct authdes_cred *adc;
1517c478bd9Sstevel@tonic-gate int flavor, stat;
1527c478bd9Sstevel@tonic-gate rpc_gss_rawcred_t *rcred;
1537c478bd9Sstevel@tonic-gate rpc_gss_ucred_t *ucred;
1547c478bd9Sstevel@tonic-gate void *cookie;
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate stat = 1;
1577c478bd9Sstevel@tonic-gate flavor = req->rq_cred.oa_flavor;
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate *principal = NULL;
1607c478bd9Sstevel@tonic-gate switch (flavor) {
1617c478bd9Sstevel@tonic-gate case AUTH_UNIX:
1627c478bd9Sstevel@tonic-gate *secmod = AUTH_UNIX;
1637c478bd9Sstevel@tonic-gate aup = (struct authunix_parms *)req->rq_clntcred;
164*2e9d26a4Srmesta if (crsetugid(cr, aup->aup_uid, aup->aup_gid) != 0)
165*2e9d26a4Srmesta (void) crsetugid(cr, UID_NOBODY, GID_NOBODY);
166*2e9d26a4Srmesta if (crsetgroups(cr, aup->aup_len, aup->aup_gids) != 0)
167*2e9d26a4Srmesta (void) crsetgroups(cr, 0, NULL);
1687c478bd9Sstevel@tonic-gate break;
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate case AUTH_NONE:
1717c478bd9Sstevel@tonic-gate *secmod = AUTH_NONE;
1727c478bd9Sstevel@tonic-gate break;
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate case AUTH_DES:
1757c478bd9Sstevel@tonic-gate *secmod = AUTH_DES;
1767c478bd9Sstevel@tonic-gate adc = (struct authdes_cred *)req->rq_clntcred;
1777c478bd9Sstevel@tonic-gate stat = kauthdes_getucred(adc, cr);
1787c478bd9Sstevel@tonic-gate *principal = adc->adc_fullname.name;
1797c478bd9Sstevel@tonic-gate break;
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate case RPCSEC_GSS:
1827c478bd9Sstevel@tonic-gate stat = rpc_gss_getcred(req, &rcred, &ucred, &cookie);
1837c478bd9Sstevel@tonic-gate *secmod = (int)(uintptr_t)cookie; /* XX64 */
1847c478bd9Sstevel@tonic-gate if (ucred != NULL) {
1857c478bd9Sstevel@tonic-gate if (crsetugid(cr, ucred->uid, ucred->gid) != 0 ||
1867c478bd9Sstevel@tonic-gate crsetgroups(cr, ucred->gidlen, ucred->gidlist) != 0)
1877c478bd9Sstevel@tonic-gate stat = 0;
1887c478bd9Sstevel@tonic-gate } else {
1897c478bd9Sstevel@tonic-gate (void) crsetugid(cr, UID_NOBODY, GID_NOBODY);
1907c478bd9Sstevel@tonic-gate (void) crsetgroups(cr, 0, NULL);
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate *principal = (caddr_t)rcred->client_principal;
1937c478bd9Sstevel@tonic-gate break;
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate default:
1967c478bd9Sstevel@tonic-gate stat = 0;
1977c478bd9Sstevel@tonic-gate break;
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate return (stat);
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /* ARGSUSED */
2057c478bd9Sstevel@tonic-gate enum auth_stat
_svcauth_null(struct svc_req * rqst,struct rpc_msg * msg)2067c478bd9Sstevel@tonic-gate _svcauth_null(struct svc_req *rqst, struct rpc_msg *msg)
2077c478bd9Sstevel@tonic-gate {
2087c478bd9Sstevel@tonic-gate return (AUTH_OK);
2097c478bd9Sstevel@tonic-gate }
2107c478bd9Sstevel@tonic-gate
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate /*
2137c478bd9Sstevel@tonic-gate * Load root principal names from user space to kernel space.
2147c478bd9Sstevel@tonic-gate *
2157c478bd9Sstevel@tonic-gate * flavor - security flavor
2167c478bd9Sstevel@tonic-gate * count - number of principal names to be loaded
2177c478bd9Sstevel@tonic-gate * proots - address of the array of root names.
2187c478bd9Sstevel@tonic-gate * input is the array address in the user space,
2197c478bd9Sstevel@tonic-gate * output is the kernel address.
2207c478bd9Sstevel@tonic-gate *
2217c478bd9Sstevel@tonic-gate * return 0 on failure.
2227c478bd9Sstevel@tonic-gate */
2237c478bd9Sstevel@tonic-gate int
sec_svc_loadrootnames(int flavor,int count,caddr_t ** proots,model_t model)2247c478bd9Sstevel@tonic-gate sec_svc_loadrootnames(int flavor, int count, caddr_t **proots, model_t model)
2257c478bd9Sstevel@tonic-gate {
2267c478bd9Sstevel@tonic-gate caddr_t *roots, *oroots, root;
2277c478bd9Sstevel@tonic-gate char netname[MAXNETNAMELEN+1];
2287c478bd9Sstevel@tonic-gate struct rpc_gss_principal gsstmp, *gssname;
2297c478bd9Sstevel@tonic-gate uint_t i, j;
2307c478bd9Sstevel@tonic-gate size_t len, allocsz, oallocsz;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate #ifdef lint
2337c478bd9Sstevel@tonic-gate model = model;
2347c478bd9Sstevel@tonic-gate #endif
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate * Get list of names from user space
2387c478bd9Sstevel@tonic-gate */
2397c478bd9Sstevel@tonic-gate allocsz = count * sizeof (caddr_t);
2407c478bd9Sstevel@tonic-gate oallocsz = count * SIZEOF_PTR(model);
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate /*
2437c478bd9Sstevel@tonic-gate * And now copy each individual principal name
2447c478bd9Sstevel@tonic-gate */
2457c478bd9Sstevel@tonic-gate switch (flavor) {
2467c478bd9Sstevel@tonic-gate case AUTH_DES:
2477c478bd9Sstevel@tonic-gate roots = kmem_zalloc(allocsz, KM_SLEEP);
2487c478bd9Sstevel@tonic-gate oroots = kmem_alloc(oallocsz, KM_SLEEP);
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate if (copyin(*proots, oroots, oallocsz))
2517c478bd9Sstevel@tonic-gate goto done;
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) {
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate * copyinstr copies the complete string (including the
2567c478bd9Sstevel@tonic-gate * NULL) and returns the len with the NULL byte
2577c478bd9Sstevel@tonic-gate * included in the calculation as long as the max
2587c478bd9Sstevel@tonic-gate * length is not exceeded.
2597c478bd9Sstevel@tonic-gate */
2607c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
2617c478bd9Sstevel@tonic-gate if (model != DATAMODEL_NATIVE) {
2627c478bd9Sstevel@tonic-gate caddr32_t *tmp;
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate tmp = (caddr32_t *)oroots;
2657c478bd9Sstevel@tonic-gate root = (caddr_t)(uintptr_t)tmp[i];
2667c478bd9Sstevel@tonic-gate } else
2677c478bd9Sstevel@tonic-gate #endif
2687c478bd9Sstevel@tonic-gate root = oroots[i];
2697c478bd9Sstevel@tonic-gate if (copyinstr(root, netname, sizeof (netname), &len)) {
2707c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) {
2717c478bd9Sstevel@tonic-gate if (roots[j] != NULL)
2727c478bd9Sstevel@tonic-gate kmem_free(roots[j],
2737c478bd9Sstevel@tonic-gate strlen(roots[j]) + 1);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate goto done;
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate roots[i] = kmem_alloc(len, KM_SLEEP);
2787c478bd9Sstevel@tonic-gate bcopy(netname, roots[i], len);
2797c478bd9Sstevel@tonic-gate }
2807c478bd9Sstevel@tonic-gate kmem_free(oroots, oallocsz);
2817c478bd9Sstevel@tonic-gate *proots = roots;
2827c478bd9Sstevel@tonic-gate return (1);
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate case RPCSEC_GSS:
2857c478bd9Sstevel@tonic-gate roots = kmem_alloc(allocsz, KM_SLEEP);
2867c478bd9Sstevel@tonic-gate oroots = kmem_alloc(oallocsz, KM_SLEEP);
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate if (copyin(*proots, oroots, oallocsz))
2897c478bd9Sstevel@tonic-gate goto done;
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) {
2927c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL
2937c478bd9Sstevel@tonic-gate if (model != DATAMODEL_NATIVE) {
2947c478bd9Sstevel@tonic-gate caddr32_t *tmp;
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate tmp = (caddr32_t *)oroots;
2977c478bd9Sstevel@tonic-gate root = (caddr_t)(uintptr_t)tmp[i];
2987c478bd9Sstevel@tonic-gate } else
2997c478bd9Sstevel@tonic-gate #endif
3007c478bd9Sstevel@tonic-gate root = oroots[i];
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate if (copyin(root, &gsstmp, sizeof (gsstmp))) {
3037c478bd9Sstevel@tonic-gate kmem_free(oroots, oallocsz);
3047c478bd9Sstevel@tonic-gate goto gssfreeup;
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate len = sizeof (gsstmp.len) + gsstmp.len;
3077c478bd9Sstevel@tonic-gate gssname = kmem_alloc(len, KM_SLEEP);
3087c478bd9Sstevel@tonic-gate if (copyin(root, gssname, len)) {
3097c478bd9Sstevel@tonic-gate kmem_free(gssname, len);
3107c478bd9Sstevel@tonic-gate kmem_free(oroots, oallocsz);
3117c478bd9Sstevel@tonic-gate goto gssfreeup;
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate roots[i] = (caddr_t)gssname;
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate kmem_free(oroots, oallocsz);
3167c478bd9Sstevel@tonic-gate *proots = roots;
3177c478bd9Sstevel@tonic-gate return (1);
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate default:
3207c478bd9Sstevel@tonic-gate return (0);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate gssfreeup:
3247c478bd9Sstevel@tonic-gate for (j = 0; j < i; j++) {
3257c478bd9Sstevel@tonic-gate if (roots[j] != NULL) {
3267c478bd9Sstevel@tonic-gate gssname = (rpc_gss_principal_t)roots[j];
3277c478bd9Sstevel@tonic-gate kmem_free(roots[j], gssname->len +
3287c478bd9Sstevel@tonic-gate sizeof (gssname->len));
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate done:
3327c478bd9Sstevel@tonic-gate kmem_free(roots, allocsz);
3337c478bd9Sstevel@tonic-gate return (0);
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate * Figure out everything we allocated in a root principal name list in
3397c478bd9Sstevel@tonic-gate * order to free it up.
3407c478bd9Sstevel@tonic-gate */
3417c478bd9Sstevel@tonic-gate void
sec_svc_freerootnames(int flavor,int count,caddr_t * proots)3427c478bd9Sstevel@tonic-gate sec_svc_freerootnames(int flavor, int count, caddr_t *proots)
3437c478bd9Sstevel@tonic-gate {
3447c478bd9Sstevel@tonic-gate int i;
3457c478bd9Sstevel@tonic-gate rpc_gss_principal_t gssname;
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate switch (flavor) {
3487c478bd9Sstevel@tonic-gate case AUTH_DES:
3497c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++)
3507c478bd9Sstevel@tonic-gate if (proots[i] != NULL)
3517c478bd9Sstevel@tonic-gate kmem_free(proots[i], strlen(proots[i]) + 1);
3527c478bd9Sstevel@tonic-gate break;
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate case RPCSEC_GSS:
3557c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) {
3567c478bd9Sstevel@tonic-gate if (proots[i] == NULL)
3577c478bd9Sstevel@tonic-gate continue;
3587c478bd9Sstevel@tonic-gate gssname = (rpc_gss_principal_t)proots[i];
3597c478bd9Sstevel@tonic-gate kmem_free(proots[i], gssname->len + sizeof (int));
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate break;
3627c478bd9Sstevel@tonic-gate
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate kmem_free(proots, count * sizeof (caddr_t));
3657c478bd9Sstevel@tonic-gate }
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate /*
3687c478bd9Sstevel@tonic-gate * Check if the given principal name is in the root principal list
3697c478bd9Sstevel@tonic-gate */
3707c478bd9Sstevel@tonic-gate bool_t
sec_svc_inrootlist(int flavor,caddr_t rootname,int count,caddr_t * roots)3717c478bd9Sstevel@tonic-gate sec_svc_inrootlist(int flavor, caddr_t rootname, int count, caddr_t *roots)
3727c478bd9Sstevel@tonic-gate {
3737c478bd9Sstevel@tonic-gate int i, tmp_len;
3747c478bd9Sstevel@tonic-gate rpc_gss_principal_t gssp, tmp_gssp;
3757c478bd9Sstevel@tonic-gate size_t namelen;
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate switch (flavor) {
3787c478bd9Sstevel@tonic-gate case AUTH_DES:
3797c478bd9Sstevel@tonic-gate namelen = strlen(rootname) + 1;
3807c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++)
3817c478bd9Sstevel@tonic-gate if (bcmp(rootname, roots[i], namelen) == 0)
3827c478bd9Sstevel@tonic-gate return (TRUE);
3837c478bd9Sstevel@tonic-gate break;
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate case RPCSEC_GSS:
3867c478bd9Sstevel@tonic-gate gssp = (rpc_gss_principal_t)rootname;
3877c478bd9Sstevel@tonic-gate namelen = gssp->len;
3887c478bd9Sstevel@tonic-gate for (i = 0; i < count; i++) {
3897c478bd9Sstevel@tonic-gate tmp_gssp = (rpc_gss_principal_t)roots[i];
3907c478bd9Sstevel@tonic-gate tmp_len = tmp_gssp->len;
3917c478bd9Sstevel@tonic-gate if ((namelen == tmp_len) &&
3927c478bd9Sstevel@tonic-gate (bcmp(&gssp->name[0],
3937c478bd9Sstevel@tonic-gate &tmp_gssp->name[0], namelen) == 0))
3947c478bd9Sstevel@tonic-gate return (TRUE);
3957c478bd9Sstevel@tonic-gate }
3967c478bd9Sstevel@tonic-gate break;
3977c478bd9Sstevel@tonic-gate }
3987c478bd9Sstevel@tonic-gate return (FALSE);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate /*
4027c478bd9Sstevel@tonic-gate * Miscellaneout "control" functions manipulating global RPC security
4037c478bd9Sstevel@tonic-gate * attributes for server applications.
4047c478bd9Sstevel@tonic-gate */
4057c478bd9Sstevel@tonic-gate bool_t
sec_svc_control(uint_t cmd,void * argp)4067c478bd9Sstevel@tonic-gate sec_svc_control(uint_t cmd, void *argp)
4077c478bd9Sstevel@tonic-gate {
4087c478bd9Sstevel@tonic-gate bool_t result = FALSE; /* be paranoid */
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate switch (cmd) {
4117c478bd9Sstevel@tonic-gate case RPC_SVC_SET_GSS_CALLBACK:
4127c478bd9Sstevel@tonic-gate result = rpc_gss_set_callback((rpc_gss_callback_t *)argp);
4137c478bd9Sstevel@tonic-gate break;
4147c478bd9Sstevel@tonic-gate default:
4157c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "sec_svc_control: bad command (%d)", cmd);
4167c478bd9Sstevel@tonic-gate result = FALSE;
4177c478bd9Sstevel@tonic-gate break;
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate
4207c478bd9Sstevel@tonic-gate return (result);
4217c478bd9Sstevel@tonic-gate }
422