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