source: rtems-libbsd/freebsd/sys/rpc/svc_auth.c @ c6dbc96

6-freebsd-12
Last change on this file since c6dbc96 was c6dbc96, checked in by Chris Johns <chrisj@…>, on 07/29/21 at 03:24:49

kern/sys: Add the kernel RPC and XDR support

Updates #4475

  • Property mode set to 100644
File size: 5.5 KB
Line 
1#include <machine/rtems-bsd-kernel-space.h>
2
3/*      $NetBSD: svc_auth.c,v 1.12 2000/07/06 03:10:35 christos Exp $   */
4
5/*-
6 * SPDX-License-Identifier: BSD-3-Clause
7 *
8 * Copyright (c) 2009, Sun Microsystems, Inc.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright notice,
14 *   this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 *   this list of conditions and the following disclaimer in the documentation
17 *   and/or other materials provided with the distribution.
18 * - Neither the name of Sun Microsystems, Inc. nor the names of its
19 *   contributors may be used to endorse or promote products derived
20 *   from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34/*
35 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
36 */
37
38#if defined(LIBC_SCCS) && !defined(lint)
39#ident  "@(#)svc_auth.c 1.16    94/04/24 SMI"
40static char sccsid[] = "@(#)svc_auth.c 1.26 89/02/07 Copyr 1984 Sun Micro";
41#endif
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD$");
44
45/*
46 * svc_auth.c, Server-side rpc authenticator interface.
47 *
48 */
49
50#include <sys/param.h>
51#include <sys/lock.h>
52#include <sys/mutex.h>
53#include <sys/systm.h>
54#include <sys/jail.h>
55#include <sys/ucred.h>
56
57#include <rpc/rpc.h>
58
59static enum auth_stat (*_svcauth_rpcsec_gss)(struct svc_req *,
60    struct rpc_msg *) = NULL;
61static int (*_svcauth_rpcsec_gss_getcred)(struct svc_req *,
62    struct ucred **, int *);
63
64static struct svc_auth_ops svc_auth_null_ops;
65
66/*
67 * The call rpc message, msg has been obtained from the wire.  The msg contains
68 * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
69 * if the msg is successfully authenticated.  If AUTH_OK then the routine also
70 * does the following things:
71 * set rqst->rq_xprt->verf to the appropriate response verifier;
72 * sets rqst->rq_client_cred to the "cooked" form of the credentials.
73 *
74 * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
75 * its length is set appropriately.
76 *
77 * The caller still owns and is responsible for msg->u.cmb.cred and
78 * msg->u.cmb.verf.  The authentication system retains ownership of
79 * rqst->rq_client_cred, the cooked credentials.
80 *
81 * There is an assumption that any flavour less than AUTH_NULL is
82 * invalid.
83 */
84enum auth_stat
85_authenticate(struct svc_req *rqst, struct rpc_msg *msg)
86{
87        int cred_flavor;
88        enum auth_stat dummy;
89
90        rqst->rq_cred = msg->rm_call.cb_cred;
91        rqst->rq_auth.svc_ah_ops = &svc_auth_null_ops;
92        rqst->rq_auth.svc_ah_private = NULL;
93        cred_flavor = rqst->rq_cred.oa_flavor;
94        switch (cred_flavor) {
95        case AUTH_NULL:
96                dummy = _svcauth_null(rqst, msg);
97                return (dummy);
98        case AUTH_SYS:
99                dummy = _svcauth_unix(rqst, msg);
100                return (dummy);
101        case AUTH_SHORT:
102                dummy = _svcauth_short(rqst, msg);
103                return (dummy);
104        case RPCSEC_GSS:
105                if (!_svcauth_rpcsec_gss)
106                        return (AUTH_REJECTEDCRED);
107                dummy = _svcauth_rpcsec_gss(rqst, msg);
108                return (dummy);
109        default:
110                break;
111        }
112
113        return (AUTH_REJECTEDCRED);
114}
115
116/*
117 * A set of null auth methods used by any authentication protocols
118 * that don't need to inspect or modify the message body.
119 */
120static bool_t
121svcauth_null_wrap(SVCAUTH *auth, struct mbuf **mp)
122{
123
124        return (TRUE);
125}
126
127static bool_t
128svcauth_null_unwrap(SVCAUTH *auth, struct mbuf **mp)
129{
130
131        return (TRUE);
132}
133
134static void
135svcauth_null_release(SVCAUTH *auth)
136{
137
138}
139
140static struct svc_auth_ops svc_auth_null_ops = {
141        svcauth_null_wrap,
142        svcauth_null_unwrap,
143        svcauth_null_release,
144};
145
146/*ARGSUSED*/
147enum auth_stat
148_svcauth_null(struct svc_req *rqst, struct rpc_msg *msg)
149{
150
151        rqst->rq_verf = _null_auth;
152        return (AUTH_OK);
153}
154
155int
156svc_auth_reg(int flavor,
157    enum auth_stat (*svcauth)(struct svc_req *, struct rpc_msg *),
158    int (*getcred)(struct svc_req *, struct ucred **, int *))
159{
160
161        if (flavor == RPCSEC_GSS) {
162                _svcauth_rpcsec_gss = svcauth;
163                _svcauth_rpcsec_gss_getcred = getcred;
164        }
165        return (TRUE);
166}
167
168int
169svc_getcred(struct svc_req *rqst, struct ucred **crp, int *flavorp)
170{
171        struct ucred *cr = NULL;
172        int flavor;
173        struct xucred *xcr;
174
175        flavor = rqst->rq_cred.oa_flavor;
176        if (flavorp)
177                *flavorp = flavor;
178
179        switch (flavor) {
180        case AUTH_UNIX:
181                xcr = (struct xucred *) rqst->rq_clntcred;
182                cr = crget();
183                cr->cr_uid = cr->cr_ruid = cr->cr_svuid = xcr->cr_uid;
184                crsetgroups(cr, xcr->cr_ngroups, xcr->cr_groups);
185                cr->cr_rgid = cr->cr_svgid = cr->cr_groups[0];
186#ifndef __rtems__
187                cr->cr_prison = &prison0;
188                prison_hold(cr->cr_prison);
189#endif /* __rtems__ */
190                *crp = cr;
191                return (TRUE);
192
193        case RPCSEC_GSS:
194                if (!_svcauth_rpcsec_gss_getcred)
195                        return (FALSE);
196                return (_svcauth_rpcsec_gss_getcred(rqst, crp, flavorp));
197
198        default:
199                return (FALSE);
200        }
201}
Note: See TracBrowser for help on using the repository browser.