source: rtems-libbsd/services/librpc/src/rpc/svc_auth.c @ e599318

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since e599318 was e599318, checked in by Sebastian Huber <sebastian.huber@…>, on 10/09/13 at 20:52:54

Update files to match FreeBSD layout

Add compatibility with Newlib header files. Some FreeBSD header files
are mapped by the translation script:

o rtems/bsd/sys/_types.h
o rtems/bsd/sys/errno.h
o rtems/bsd/sys/lock.h
o rtems/bsd/sys/param.h
o rtems/bsd/sys/resource.h
o rtems/bsd/sys/time.h
o rtems/bsd/sys/timespec.h
o rtems/bsd/sys/types.h
o rtems/bsd/sys/unistd.h

It is now possible to include <sys/socket.h> directly for example.

Generate one Makefile which builds everything including tests.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part.  Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
12 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
16 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
20 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 */
29/*
30 * Copyright (c) 1986-1991 by Sun Microsystems Inc.
31 */
32
33/* #ident       "@(#)svc_auth.c 1.16    94/04/24 SMI" */
34
35#if !defined(lint) && defined(SCCSIDS)
36#if 0
37static char sccsid[] = "@(#)svc_auth.c 1.26 89/02/07 Copyr 1984 Sun Micro";
38#else
39static const char rcsid[] =
40 "$FreeBSD: src/lib/libc/rpc/svc_auth.c,v 1.7 1999/12/29 05:04:16 peter Exp $";
41#endif
42#endif
43
44/*
45 * svc_auth.c, Server-side rpc authenticator interface.
46 *
47 */
48
49#ifdef HAVE_CONFIG_H
50#include "config.h"
51#endif
52
53#ifdef _KERNEL
54#include <sys/param.h>
55#include <rpc/types.h>
56#include <rpc/xdr.h>
57#include <rpc/auth.h>
58#include <rpc/clnt.h>
59#include <rpc/rpc_msg.h>
60#include <rpc/svc.h>
61#include <rpc/svc_auth.h>
62#else
63#include <stdlib.h>
64#include <rpc/rpc.h>
65#endif
66#include <sys/types.h>
67#ifdef __rtems__
68        /* XXX in rpc.h in old .. not new */
69        #include <rpc/rpc_rtems.h>
70#endif
71
72/*
73 * svcauthsw is the bdevsw of server side authentication.
74 *
75 * Server side authenticators are called from authenticate by
76 * using the client auth struct flavor field to index into svcauthsw.
77 * The server auth flavors must implement a routine that looks
78 * like:
79 *
80 *      enum auth_stat
81 *      flavorx_auth(rqst, msg)
82 *              register struct svc_req *rqst;
83 *              register struct rpc_msg *msg;
84 *
85 */
86
87enum auth_stat _svcauth_null(struct svc_req *rqst, struct rpc_msg *msg);        /* no authentication */
88enum auth_stat _svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg);                /* (system) unix style (uid, gids) */
89enum auth_stat _svcauth_short(struct svc_req *rqst, struct rpc_msg *msg);       /* short hand unix style */
90enum auth_stat _svcauth_des(struct svc_req *rqst, struct rpc_msg *msg);         /* des style */
91
92/* declarations to allow servers to specify new authentication flavors */
93struct authsvc {
94        int     flavor;
95        enum    auth_stat (*handler)(struct svc_req *rqst, struct rpc_msg *msg);
96        struct  authsvc   *next;
97};
98#define Auths (rtems_rpc_task_variables->svc_auths_Auths)
99
100/*
101 * The call rpc message, msg has been obtained from the wire.  The msg contains
102 * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
103 * if the msg is successfully authenticated.  If AUTH_OK then the routine also
104 * does the following things:
105 * set rqst->rq_xprt->verf to the appropriate response verifier;
106 * sets rqst->rq_client_cred to the "cooked" form of the credentials.
107 *
108 * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
109 * its length is set appropriately.
110 *
111 * The caller still owns and is responsible for msg->u.cmb.cred and
112 * msg->u.cmb.verf.  The authentication system retains ownership of
113 * rqst->rq_client_cred, the cooked credentials.
114 *
115 * There is an assumption that any flavour less than AUTH_NULL is
116 * invalid.
117 */
118enum auth_stat
119_authenticate(
120        struct svc_req *rqst,
121        struct rpc_msg *msg )
122{
123        register int cred_flavor;
124        register struct authsvc *asp;
125
126        rqst->rq_cred = msg->rm_call.cb_cred;
127        rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
128        rqst->rq_xprt->xp_verf.oa_length = 0;
129        cred_flavor = rqst->rq_cred.oa_flavor;
130        switch (cred_flavor) {
131        case AUTH_NULL:
132                return(_svcauth_null(rqst, msg));
133        case AUTH_UNIX:
134                return(_svcauth_unix(rqst, msg));
135        case AUTH_SHORT:
136                return(_svcauth_short(rqst, msg));
137        /*
138         * We leave AUTH_DES turned off by default because svcauth_des()
139         * needs getpublickey(), which is in librpcsvc, not libc. If we
140         * included AUTH_DES as a built-in flavor, programs that don't
141         * have -lrpcsvc in their Makefiles wouldn't link correctly, even
142         * though they don't use AUTH_DES. And I'm too lazy to go through
143         * the tree looking for all of them.
144         */
145#ifdef DES_BUILTIN
146        case AUTH_DES:
147                return(_svcauth_des(rqst, msg));
148#endif
149        }
150
151        /* flavor doesn't match any of the builtin types, so try new ones */
152        for (asp = Auths; asp; asp = asp->next) {
153                if (asp->flavor == cred_flavor) {
154                        enum auth_stat as;
155
156                        as = (*asp->handler)(rqst, msg);
157                        return (as);
158                }
159        }
160
161        return (AUTH_REJECTEDCRED);
162}
163
164/*ARGSUSED*/
165enum auth_stat
166_svcauth_null(
167        struct svc_req *rqst,
168        struct rpc_msg *msg)
169{
170        return (AUTH_OK);
171}
172
173/*
174 *  Allow the rpc service to register new authentication types that it is
175 *  prepared to handle.  When an authentication flavor is registered,
176 *  the flavor is checked against already registered values.  If not
177 *  registered, then a new Auths entry is added on the list.
178 *
179 *  There is no provision to delete a registration once registered.
180 *
181 *  This routine returns:
182 *       0 if registration successful
183 *       1 if flavor already registered
184 *      -1 if can't register (errno set)
185 */
186
187int
188svc_auth_reg(
189        int cred_flavor,
190        enum auth_stat (*handler)(struct svc_req *rqst, struct rpc_msg *msg))
191{
192        register struct authsvc *asp;
193
194        switch (cred_flavor) {
195            case AUTH_NULL:
196            case AUTH_UNIX:
197            case AUTH_SHORT:
198#ifdef DES_BUILTIN
199            case AUTH_DES:
200#endif
201                /* already registered */
202                return (1);
203
204            default:
205                for (asp = Auths; asp; asp = asp->next) {
206                        if (asp->flavor == cred_flavor) {
207                                /* already registered */
208                                return (1);
209                        }
210                }
211
212                /* this is a new one, so go ahead and register it */
213                asp = (struct authsvc *)mem_alloc(sizeof (*asp));
214                if (asp == NULL) {
215                        return (-1);
216                }
217                asp->flavor = cred_flavor;
218                asp->handler = handler;
219                asp->next = Auths;
220                Auths = asp;
221                break;
222        }
223        return (0);
224}
Note: See TracBrowser for help on using the repository browser.