1*7f2fe78bSCy Schubert /* @(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert * Copyright (c) 2010, Oracle America, Inc.
4*7f2fe78bSCy Schubert *
5*7f2fe78bSCy Schubert * All rights reserved.
6*7f2fe78bSCy Schubert *
7*7f2fe78bSCy Schubert * Redistribution and use in source and binary forms, with or without
8*7f2fe78bSCy Schubert * modification, are permitted provided that the following conditions are met:
9*7f2fe78bSCy Schubert *
10*7f2fe78bSCy Schubert * * Redistributions of source code must retain the above copyright
11*7f2fe78bSCy Schubert * notice, this list of conditions and the following disclaimer.
12*7f2fe78bSCy Schubert *
13*7f2fe78bSCy Schubert * * Redistributions in binary form must reproduce the above copyright
14*7f2fe78bSCy Schubert * notice, this list of conditions and the following disclaimer in
15*7f2fe78bSCy Schubert * the documentation and/or other materials provided with the
16*7f2fe78bSCy Schubert * distribution.
17*7f2fe78bSCy Schubert *
18*7f2fe78bSCy Schubert * * Neither the name of the "Oracle America, Inc." nor the names of
19*7f2fe78bSCy Schubert * its contributors may be used to endorse or promote products
20*7f2fe78bSCy Schubert * derived from this software without specific prior written permission.
21*7f2fe78bSCy Schubert *
22*7f2fe78bSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23*7f2fe78bSCy Schubert * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24*7f2fe78bSCy Schubert * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25*7f2fe78bSCy Schubert * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26*7f2fe78bSCy Schubert * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27*7f2fe78bSCy Schubert * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28*7f2fe78bSCy Schubert * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29*7f2fe78bSCy Schubert * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30*7f2fe78bSCy Schubert * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31*7f2fe78bSCy Schubert * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32*7f2fe78bSCy Schubert * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*7f2fe78bSCy Schubert */
34*7f2fe78bSCy Schubert #if !defined(lint) && defined(SCCSIDS)
35*7f2fe78bSCy Schubert static char sccsid[] = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
36*7f2fe78bSCy Schubert #endif
37*7f2fe78bSCy Schubert
38*7f2fe78bSCy Schubert /*
39*7f2fe78bSCy Schubert * svc_auth_unix.c
40*7f2fe78bSCy Schubert * Handles UNIX flavor authentication parameters on the service side of rpc.
41*7f2fe78bSCy Schubert * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
42*7f2fe78bSCy Schubert * _svcauth_unix does full blown unix style uid,gid+gids auth,
43*7f2fe78bSCy Schubert * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
44*7f2fe78bSCy Schubert * Note: the shorthand has been gutted for efficiency.
45*7f2fe78bSCy Schubert */
46*7f2fe78bSCy Schubert
47*7f2fe78bSCy Schubert #include <stdio.h>
48*7f2fe78bSCy Schubert #include <string.h>
49*7f2fe78bSCy Schubert #include <gssrpc/rpc.h>
50*7f2fe78bSCy Schubert
51*7f2fe78bSCy Schubert /*
52*7f2fe78bSCy Schubert * Unix longhand authenticator
53*7f2fe78bSCy Schubert */
54*7f2fe78bSCy Schubert enum auth_stat
gssrpc__svcauth_unix(struct svc_req * rqst,struct rpc_msg * msg,bool_t * dispatch)55*7f2fe78bSCy Schubert gssrpc__svcauth_unix(
56*7f2fe78bSCy Schubert struct svc_req *rqst,
57*7f2fe78bSCy Schubert struct rpc_msg *msg,
58*7f2fe78bSCy Schubert bool_t *dispatch)
59*7f2fe78bSCy Schubert {
60*7f2fe78bSCy Schubert enum auth_stat stat;
61*7f2fe78bSCy Schubert XDR xdrs;
62*7f2fe78bSCy Schubert struct authunix_parms *aup;
63*7f2fe78bSCy Schubert rpc_inline_t *buf;
64*7f2fe78bSCy Schubert struct area {
65*7f2fe78bSCy Schubert struct authunix_parms area_aup;
66*7f2fe78bSCy Schubert char area_machname[MAX_MACHINE_NAME+1];
67*7f2fe78bSCy Schubert int area_gids[NGRPS];
68*7f2fe78bSCy Schubert } *area;
69*7f2fe78bSCy Schubert u_int auth_len, str_len, gid_len, i;
70*7f2fe78bSCy Schubert
71*7f2fe78bSCy Schubert rqst->rq_xprt->xp_auth = &svc_auth_none;
72*7f2fe78bSCy Schubert
73*7f2fe78bSCy Schubert area = (struct area *) rqst->rq_clntcred;
74*7f2fe78bSCy Schubert aup = &area->area_aup;
75*7f2fe78bSCy Schubert aup->aup_machname = area->area_machname;
76*7f2fe78bSCy Schubert aup->aup_gids = area->area_gids;
77*7f2fe78bSCy Schubert auth_len = msg->rm_call.cb_cred.oa_length;
78*7f2fe78bSCy Schubert if (auth_len > INT_MAX)
79*7f2fe78bSCy Schubert return AUTH_BADCRED;
80*7f2fe78bSCy Schubert xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
81*7f2fe78bSCy Schubert buf = XDR_INLINE(&xdrs, (int)auth_len);
82*7f2fe78bSCy Schubert if (buf != NULL) {
83*7f2fe78bSCy Schubert aup->aup_time = IXDR_GET_LONG(buf);
84*7f2fe78bSCy Schubert str_len = IXDR_GET_U_LONG(buf);
85*7f2fe78bSCy Schubert if (str_len > MAX_MACHINE_NAME) {
86*7f2fe78bSCy Schubert stat = AUTH_BADCRED;
87*7f2fe78bSCy Schubert goto done;
88*7f2fe78bSCy Schubert }
89*7f2fe78bSCy Schubert memmove(aup->aup_machname, buf, str_len);
90*7f2fe78bSCy Schubert aup->aup_machname[str_len] = 0;
91*7f2fe78bSCy Schubert str_len = RNDUP(str_len);
92*7f2fe78bSCy Schubert buf += str_len / BYTES_PER_XDR_UNIT;
93*7f2fe78bSCy Schubert aup->aup_uid = IXDR_GET_LONG(buf);
94*7f2fe78bSCy Schubert aup->aup_gid = IXDR_GET_LONG(buf);
95*7f2fe78bSCy Schubert gid_len = IXDR_GET_U_LONG(buf);
96*7f2fe78bSCy Schubert if (gid_len > NGRPS) {
97*7f2fe78bSCy Schubert stat = AUTH_BADCRED;
98*7f2fe78bSCy Schubert goto done;
99*7f2fe78bSCy Schubert }
100*7f2fe78bSCy Schubert aup->aup_len = gid_len;
101*7f2fe78bSCy Schubert for (i = 0; i < gid_len; i++) {
102*7f2fe78bSCy Schubert aup->aup_gids[i] = IXDR_GET_LONG(buf);
103*7f2fe78bSCy Schubert }
104*7f2fe78bSCy Schubert /*
105*7f2fe78bSCy Schubert * five is the smallest unix credentials structure -
106*7f2fe78bSCy Schubert * timestamp, hostname len (0), uid, gid, and gids len (0).
107*7f2fe78bSCy Schubert */
108*7f2fe78bSCy Schubert if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
109*7f2fe78bSCy Schubert (void) printf("bad auth_len gid %u str %u auth %u\n",
110*7f2fe78bSCy Schubert gid_len, str_len, auth_len);
111*7f2fe78bSCy Schubert stat = AUTH_BADCRED;
112*7f2fe78bSCy Schubert goto done;
113*7f2fe78bSCy Schubert }
114*7f2fe78bSCy Schubert } else if (! xdr_authunix_parms(&xdrs, aup)) {
115*7f2fe78bSCy Schubert xdrs.x_op = XDR_FREE;
116*7f2fe78bSCy Schubert (void)xdr_authunix_parms(&xdrs, aup);
117*7f2fe78bSCy Schubert stat = AUTH_BADCRED;
118*7f2fe78bSCy Schubert goto done;
119*7f2fe78bSCy Schubert }
120*7f2fe78bSCy Schubert rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
121*7f2fe78bSCy Schubert rqst->rq_xprt->xp_verf.oa_length = 0;
122*7f2fe78bSCy Schubert stat = AUTH_OK;
123*7f2fe78bSCy Schubert done:
124*7f2fe78bSCy Schubert XDR_DESTROY(&xdrs);
125*7f2fe78bSCy Schubert return (stat);
126*7f2fe78bSCy Schubert }
127*7f2fe78bSCy Schubert
128*7f2fe78bSCy Schubert
129*7f2fe78bSCy Schubert /*
130*7f2fe78bSCy Schubert * Shorthand unix authenticator
131*7f2fe78bSCy Schubert * Looks up longhand in a cache.
132*7f2fe78bSCy Schubert */
133*7f2fe78bSCy Schubert /*ARGSUSED*/
134*7f2fe78bSCy Schubert enum auth_stat
gssrpc__svcauth_short(struct svc_req * rqst,struct rpc_msg * msg,bool_t * dispatch)135*7f2fe78bSCy Schubert gssrpc__svcauth_short(
136*7f2fe78bSCy Schubert struct svc_req *rqst,
137*7f2fe78bSCy Schubert struct rpc_msg *msg,
138*7f2fe78bSCy Schubert bool_t *dispatch)
139*7f2fe78bSCy Schubert {
140*7f2fe78bSCy Schubert rqst->rq_xprt->xp_auth = &svc_auth_none;
141*7f2fe78bSCy Schubert return (AUTH_REJECTEDCRED);
142*7f2fe78bSCy Schubert }
143