OSDN Git Service

Last portion of libc_hidden_proto removal.
[uclinux-h8/uClibc.git] / libc / inet / rpc / svc_authux.c
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 /*
31  * svc_auth_unix.c
32  * Handles UNIX flavor authentication parameters on the service side of rpc.
33  * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
34  * _svcauth_unix does full blown unix style uid,gid+gids auth,
35  * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
36  * Note: the shorthand has been gutted for efficiency.
37  *
38  * Copyright (C) 1984, Sun Microsystems, Inc.
39  */
40
41 #define __FORCE_GLIBC
42 #include <features.h>
43
44 #include <stdio.h>
45 #include <string.h>
46 #include <rpc/rpc.h>
47 #include <rpc/svc.h>
48
49 /* Experimentally off - libc_hidden_proto(memcpy) */
50 /* libc_hidden_proto(printf) */
51 /* libc_hidden_proto(xdrmem_create) */
52 /* libc_hidden_proto(xdr_authunix_parms) */
53
54 /*
55  * Unix longhand authenticator
56  */
57 enum auth_stat
58 _svcauth_unix (struct svc_req *rqst, struct rpc_msg *msg) attribute_hidden;
59 enum auth_stat
60 _svcauth_unix (struct svc_req *rqst, struct rpc_msg *msg)
61 {
62   enum auth_stat stat;
63   XDR xdrs;
64   struct authunix_parms *aup;
65   int32_t *buf;
66   struct area
67     {
68       struct authunix_parms area_aup;
69       char area_machname[MAX_MACHINE_NAME + 1];
70       gid_t area_gids[NGRPS];
71     }
72    *area;
73   u_int auth_len;
74   u_int str_len, gid_len;
75   u_int i;
76
77   area = (struct area *) rqst->rq_clntcred;
78   aup = &area->area_aup;
79   aup->aup_machname = area->area_machname;
80   aup->aup_gids = area->area_gids;
81   auth_len = (u_int) msg->rm_call.cb_cred.oa_length;
82   xdrmem_create (&xdrs, msg->rm_call.cb_cred.oa_base, auth_len, XDR_DECODE);
83   buf = XDR_INLINE (&xdrs, auth_len);
84   if (buf != NULL)
85     {
86       aup->aup_time = IXDR_GET_LONG (buf);
87       str_len = IXDR_GET_U_INT32 (buf);
88       if (str_len > MAX_MACHINE_NAME)
89         {
90           stat = AUTH_BADCRED;
91           goto done;
92         }
93       memcpy (aup->aup_machname, (caddr_t) buf, (u_int) str_len);
94       aup->aup_machname[str_len] = 0;
95       str_len = RNDUP (str_len);
96       buf = (int32_t *) ((char *) buf + str_len);
97       aup->aup_uid = IXDR_GET_LONG (buf);
98       aup->aup_gid = IXDR_GET_LONG (buf);
99       gid_len = IXDR_GET_U_INT32 (buf);
100       if (gid_len > NGRPS)
101         {
102           stat = AUTH_BADCRED;
103           goto done;
104         }
105       aup->aup_len = gid_len;
106       for (i = 0; i < gid_len; i++)
107         {
108           aup->aup_gids[i] = IXDR_GET_LONG (buf);
109         }
110       /*
111        * five is the smallest unix credentials structure -
112        * timestamp, hostname len (0), uid, gid, and gids len (0).
113        */
114       if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
115         {
116           (void) printf ("bad auth_len gid %d str %d auth %d\n",
117                          gid_len, str_len, auth_len);
118           stat = AUTH_BADCRED;
119           goto done;
120         }
121     }
122   else if (!xdr_authunix_parms (&xdrs, aup))
123     {
124       xdrs.x_op = XDR_FREE;
125       (void) xdr_authunix_parms (&xdrs, aup);
126       stat = AUTH_BADCRED;
127       goto done;
128     }
129
130   /* get the verifier */
131   if ((u_int)msg->rm_call.cb_verf.oa_length)
132     {
133       rqst->rq_xprt->xp_verf.oa_flavor =
134         msg->rm_call.cb_verf.oa_flavor;
135       rqst->rq_xprt->xp_verf.oa_base =
136         msg->rm_call.cb_verf.oa_base;
137       rqst->rq_xprt->xp_verf.oa_length =
138         msg->rm_call.cb_verf.oa_length;
139     }
140   else
141     {
142       rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
143       rqst->rq_xprt->xp_verf.oa_length = 0;
144     }
145   stat = AUTH_OK;
146 done:
147   XDR_DESTROY (&xdrs);
148   return stat;
149 }
150
151
152 /*
153  * Shorthand unix authenticator
154  * Looks up longhand in a cache.
155  */
156 /*ARGSUSED */
157 enum auth_stat
158 _svcauth_short (struct svc_req *rqst attribute_unused, struct rpc_msg *msg attribute_unused) attribute_hidden;
159 enum auth_stat
160 _svcauth_short (struct svc_req *rqst attribute_unused, struct rpc_msg *msg attribute_unused)
161 {
162   return AUTH_REJECTEDCRED;
163 }