(modules): Add CSN_369103, CWI, DEC-MCS, ECMA-CYRILLIC, GOST_19768-74, GREEK-CCITT...
[glibc.git] / sunrpc / svc_authux.c
blob627b7e3faf5f1cad213889b7bc7561fb24985ccd
1 /* @(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */
2 /*
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
30 #if !defined(lint) && defined(SCCSIDS)
31 static char sccsid[] = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
32 #endif
35 * svc_auth_unix.c
36 * Handles UNIX flavor authentication parameters on the service side of rpc.
37 * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
38 * _svcauth_unix does full blown unix style uid,gid+gids auth,
39 * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
40 * Note: the shorthand has been gutted for efficiency.
42 * Copyright (C) 1984, Sun Microsystems, Inc.
45 #include <stdio.h>
46 #include <string.h>
47 #include <rpc/rpc.h>
48 #include <rpc/svc.h>
51 * Unix longhand authenticator
53 enum auth_stat
54 _svcauth_unix (struct svc_req *rqst, struct rpc_msg *msg)
56 enum auth_stat stat;
57 XDR xdrs;
58 struct authunix_parms *aup;
59 long *buf;
60 struct area
62 struct authunix_parms area_aup;
63 char area_machname[MAX_MACHINE_NAME + 1];
64 gid_t area_gids[NGRPS];
66 *area;
67 u_int auth_len;
68 u_int str_len, gid_len;
69 u_int i;
71 area = (struct area *) rqst->rq_clntcred;
72 aup = &area->area_aup;
73 aup->aup_machname = area->area_machname;
74 aup->aup_gids = area->area_gids;
75 auth_len = (u_int) msg->rm_call.cb_cred.oa_length;
76 xdrmem_create (&xdrs, msg->rm_call.cb_cred.oa_base, auth_len, XDR_DECODE);
77 buf = XDR_INLINE (&xdrs, auth_len);
78 if (buf != NULL)
80 aup->aup_time = IXDR_GET_LONG (buf);
81 str_len = IXDR_GET_U_LONG (buf);
82 if (str_len > MAX_MACHINE_NAME)
84 stat = AUTH_BADCRED;
85 goto done;
87 bcopy ((caddr_t) buf, aup->aup_machname, (u_int) str_len);
88 aup->aup_machname[str_len] = 0;
89 str_len = RNDUP (str_len);
90 buf = (u_long *) ((char *) buf + str_len);
91 aup->aup_uid = IXDR_GET_LONG (buf);
92 aup->aup_gid = IXDR_GET_LONG (buf);
93 gid_len = IXDR_GET_U_LONG (buf);
94 if (gid_len > NGRPS)
96 stat = AUTH_BADCRED;
97 goto done;
99 aup->aup_len = gid_len;
100 for (i = 0; i < gid_len; i++)
102 aup->aup_gids[i] = IXDR_GET_LONG (buf);
105 * five is the smallest unix credentials structure -
106 * timestamp, hostname len (0), uid, gid, and gids len (0).
108 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len)
110 (void) printf ("bad auth_len gid %d str %d auth %d\n",
111 gid_len, str_len, auth_len);
112 stat = AUTH_BADCRED;
113 goto done;
116 else if (!xdr_authunix_parms (&xdrs, aup))
118 xdrs.x_op = XDR_FREE;
119 (void) xdr_authunix_parms (&xdrs, aup);
120 stat = AUTH_BADCRED;
121 goto done;
124 /* get the verifier */
125 if ((u_int)msg->rm_call.cb_verf.oa_length)
127 rqst->rq_xprt->xp_verf.oa_flavor =
128 msg->rm_call.cb_verf.oa_flavor;
129 rqst->rq_xprt->xp_verf.oa_base =
130 msg->rm_call.cb_verf.oa_base;
131 rqst->rq_xprt->xp_verf.oa_length =
132 msg->rm_call.cb_verf.oa_length;
134 else
136 rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
137 rqst->rq_xprt->xp_verf.oa_length = 0;
139 stat = AUTH_OK;
140 done:
141 XDR_DESTROY (&xdrs);
142 return stat;
147 * Shorthand unix authenticator
148 * Looks up longhand in a cache.
150 /*ARGSUSED */
151 enum auth_stat
152 _svcauth_short (struct svc_req *rqst, struct rpc_msg *msg)
154 return AUTH_REJECTEDCRED;