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.
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.
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.
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.
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.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
30 #if defined(LIBC_SCCS) && !defined(lint)
31 static char *sccsid2 = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
32 static char *sccsid = "@(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC";
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
39 * Handles UNIX flavor authentication parameters on the service side of rpc.
40 * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
41 * _svcauth_unix does full blown unix style uid,gid+gids auth,
42 * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
43 * Note: the shorthand has been gutted for efficiency.
45 * Copyright (C) 1984, Sun Microsystems, Inc.
48 #include <sys/param.h>
50 #include <sys/mutex.h>
51 #include <sys/systm.h>
52 #include <sys/ucred.h>
56 #include <rpc/rpc_com.h>
58 #define MAX_MACHINE_NAME 255
62 * Unix longhand authenticator
65 _svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg)
73 size_t str_len, gid_len;
76 xcr = rqst->rq_clntcred;
77 auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
78 xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,
80 buf = XDR_INLINE(&xdrs, auth_len);
82 time = IXDR_GET_UINT32(buf);
83 str_len = (size_t)IXDR_GET_UINT32(buf);
84 if (str_len > MAX_MACHINE_NAME) {
88 str_len = RNDUP(str_len);
89 buf += str_len / sizeof (int32_t);
90 xcr->cr_uid = IXDR_GET_UINT32(buf);
91 xcr->cr_groups[0] = IXDR_GET_UINT32(buf);
92 gid_len = (size_t)IXDR_GET_UINT32(buf);
93 if (gid_len > NGRPS) {
97 for (i = 0; i < gid_len; i++) {
98 if (i + 1 < XU_NGROUPS)
99 xcr->cr_groups[i + 1] = IXDR_GET_INT32(buf);
103 if (gid_len + 1 > XU_NGROUPS)
104 xcr->cr_ngroups = XU_NGROUPS;
106 xcr->cr_ngroups = gid_len + 1;
109 * five is the smallest unix credentials structure -
110 * timestamp, hostname len (0), uid, gid, and gids len (0).
112 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
113 (void) printf("bad auth_len gid %ld str %ld auth %u\n",
114 (long)gid_len, (long)str_len, auth_len);
118 } else if (! xdr_authunix_parms(&xdrs, &time, xcr)) {
123 rqst->rq_verf = _null_auth;
133 * Shorthand unix authenticator
134 * Looks up longhand in a cache.
138 _svcauth_short(rqst, msg)
139 struct svc_req *rqst;
142 return (AUTH_REJECTEDCRED);