d9d2004544602ce873646722c621ad4a49f8d465
[shibboleth/cpp-sp.git] / oncrpc / svc_autu.c
1 /*********************************************************************
2  * RPC for the Windows NT Operating System
3  * 1993 by Martin F. Gergeleit
4  * Users may use, copy or modify Sun RPC for the Windows NT Operating 
5  * System according to the Sun copyright below.
6  *
7  * RPC for the Windows NT Operating System COMES WITH ABSOLUTELY NO 
8  * WARRANTY, NOR WILL I BE LIABLE FOR ANY DAMAGES INCURRED FROM THE 
9  * USE OF. USE ENTIRELY AT YOUR OWN RISK!!!
10  *********************************************************************/
11
12 /* @(#)svc_auth_unix.c  2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */
13 /*
14  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
15  * unrestricted use provided that this legend is included on all tape
16  * media and as a part of the software program in whole or part.  Users
17  * may copy or modify Sun RPC without charge, but are not authorized
18  * to license or distribute it to anyone else except as part of a product or
19  * program developed by the user.
20  * 
21  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
22  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
24  * 
25  * Sun RPC is provided with no support and without any obligation on the
26  * part of Sun Microsystems, Inc. to assist in its use, correction,
27  * modification or enhancement.
28  * 
29  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
30  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
31  * OR ANY PART THEREOF.
32  * 
33  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
34  * or profits or other special, indirect and consequential damages, even if
35  * Sun has been advised of the possibility of such damages.
36  * 
37  * Sun Microsystems, Inc.
38  * 2550 Garcia Avenue
39  * Mountain View, California  94043
40  */
41 #if !defined(lint) && defined(SCCSIDS)
42 static char sccsid[] = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
43 #endif
44
45 /*
46  * svc_auth_unix.c
47  * Handles UNIX flavor authentication parameters on the service side of rpc.
48  * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
49  * _svcauth_unix does full blown unix style uid,gid+gids auth,
50  * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
51  * Note: the shorthand has been gutted for efficiency.
52  *
53  * Copyright (C) 1984, Sun Microsystems, Inc.
54  */
55
56 #include <stdio.h>
57 #include <rpc/rpc.h>
58
59 /*
60  * Unix longhand authenticator
61  */
62 enum auth_stat
63 _svcauth_unix(rqst, msg)
64         register struct svc_req *rqst;
65         register struct rpc_msg *msg;
66 {
67         register enum auth_stat stat;
68         XDR xdrs;
69         register struct authunix_parms *aup;
70         register long *buf;
71         struct area {
72                 struct authunix_parms area_aup;
73                 char area_machname[MAX_MACHINE_NAME+1];
74                 int area_gids[NGRPS];
75         } *area;
76         u_int auth_len;
77         int str_len, gid_len;
78         register int i;
79
80         area = (struct area *) rqst->rq_clntcred;
81         aup = &area->area_aup;
82         aup->aup_machname = area->area_machname;
83         aup->aup_gids = area->area_gids;
84         auth_len = (u_int)msg->rm_call.cb_cred.oa_length;
85         xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,XDR_DECODE);
86         buf = XDR_INLINE(&xdrs, auth_len);
87         if (buf != NULL) {
88                 aup->aup_time = IXDR_GET_LONG(buf);
89                 str_len = IXDR_GET_U_LONG(buf);
90                 if (str_len > MAX_MACHINE_NAME) {
91                         stat = AUTH_BADCRED;
92                         goto done;
93                 }
94                 bcopy((caddr_t)buf, aup->aup_machname, (u_int)str_len);
95                 aup->aup_machname[str_len] = 0;
96                 str_len = RNDUP(str_len);
97                 buf += str_len / sizeof (long);
98                 aup->aup_uid = IXDR_GET_LONG(buf);
99                 aup->aup_gid = IXDR_GET_LONG(buf);
100                 gid_len = IXDR_GET_U_LONG(buf);
101                 if (gid_len > NGRPS) {
102                         stat = AUTH_BADCRED;
103                         goto done;
104                 }
105                 aup->aup_len = gid_len;
106                 for (i = 0; i < gid_len; i++) {
107                         aup->aup_gids[i] = IXDR_GET_LONG(buf);
108                 }
109                 /*
110                  * five is the smallest unix credentials structure -
111                  * timestamp, hostname len (0), uid, gid, and gids len (0).
112                  */
113                 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
114 #ifdef WIN32
115                         char str[256];
116                         sprintf(str, "bad auth_len gid %d str %d auth %d\n",
117                             gid_len, str_len, auth_len);
118                         nt_rpc_report(str);
119 #else
120                         (void) printf("bad auth_len gid %d str %d auth %d\n",
121                             gid_len, str_len, auth_len);
122 #endif
123                         stat = AUTH_BADCRED;
124                         goto done;
125                 }
126         } else if (! xdr_authunix_parms(&xdrs, aup)) {
127                 xdrs.x_op = XDR_FREE;
128                 (void)xdr_authunix_parms(&xdrs, aup);
129                 stat = AUTH_BADCRED;
130                 goto done;
131         }
132         rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
133         rqst->rq_xprt->xp_verf.oa_length = 0;
134         stat = AUTH_OK;
135 done:
136         XDR_DESTROY(&xdrs);
137         return (stat);
138 }
139
140
141 /*
142  * Shorthand unix authenticator
143  * Looks up longhand in a cache.
144  */
145 /*ARGSUSED*/
146 enum auth_stat 
147 _svcauth_short(rqst, msg)
148         struct svc_req *rqst;
149         struct rpc_msg *msg;
150 {
151         return (AUTH_REJECTEDCRED);
152 }