svc_auth_unix.c revision 22993
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#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";*/
32/*static char *sccsid = "from: @(#)svc_auth_unix.c	2.3 88/08/01 4.0 RPCSRC";*/
33static char *rcsid = "$Id$";
34#endif
35
36/*
37 * svc_auth_unix.c
38 * Handles UNIX flavor authentication parameters on the service side of rpc.
39 * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
40 * _svcauth_unix does full blown unix style uid,gid+gids auth,
41 * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
42 * Note: the shorthand has been gutted for efficiency.
43 *
44 * Copyright (C) 1984, Sun Microsystems, Inc.
45 */
46
47#include <stdio.h>
48#include <string.h>
49#include <rpc/rpc.h>
50
51/*
52 * Unix longhand authenticator
53 */
54enum auth_stat
55_svcauth_unix(rqst, msg)
56	register struct svc_req *rqst;
57	register struct rpc_msg *msg;
58{
59	register enum auth_stat stat;
60	XDR xdrs;
61	register struct authunix_parms *aup;
62	register int32_t *buf;
63	struct area {
64		struct authunix_parms area_aup;
65		char area_machname[MAX_MACHINE_NAME+1];
66		int area_gids[NGRPS];
67	} *area;
68	u_int auth_len;
69	int str_len, gid_len;
70	register int i;
71
72	area = (struct area *) rqst->rq_clntcred;
73	aup = &area->area_aup;
74	aup->aup_machname = area->area_machname;
75	aup->aup_gids = area->area_gids;
76	auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
77	xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
78	buf = XDR_INLINE(&xdrs, auth_len);
79	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) {
83			stat = AUTH_BADCRED;
84			goto done;
85		}
86		memcpy(aup->aup_machname, (caddr_t)buf, (u_int)str_len);
87		aup->aup_machname[str_len] = 0;
88		str_len = RNDUP(str_len);
89		buf += str_len / sizeof (int32_t);
90		aup->aup_uid = IXDR_GET_LONG(buf);
91		aup->aup_gid = IXDR_GET_LONG(buf);
92		gid_len = IXDR_GET_U_LONG(buf);
93		if (gid_len > NGRPS) {
94			stat = AUTH_BADCRED;
95			goto done;
96		}
97		aup->aup_len = gid_len;
98		for (i = 0; i < gid_len; i++) {
99			aup->aup_gids[i] = IXDR_GET_LONG(buf);
100		}
101		/*
102		 * five is the smallest unix credentials structure -
103		 * timestamp, hostname len (0), uid, gid, and gids len (0).
104		 */
105		if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
106			(void) printf("bad auth_len gid %d str %d auth %d\n",
107			    gid_len, str_len, auth_len);
108			stat = AUTH_BADCRED;
109			goto done;
110		}
111	} else if (! xdr_authunix_parms(&xdrs, aup)) {
112		xdrs.x_op = XDR_FREE;
113		(void)xdr_authunix_parms(&xdrs, aup);
114		stat = AUTH_BADCRED;
115		goto done;
116	}
117	rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
118	rqst->rq_xprt->xp_verf.oa_length = 0;
119	stat = AUTH_OK;
120done:
121	XDR_DESTROY(&xdrs);
122	return (stat);
123}
124
125
126/*
127 * Shorthand unix authenticator
128 * Looks up longhand in a cache.
129 */
130/*ARGSUSED*/
131enum auth_stat
132_svcauth_short(rqst, msg)
133	struct svc_req *rqst;
134	struct rpc_msg *msg;
135{
136	return (AUTH_REJECTEDCRED);
137}
138