2 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #if defined(LIBC_SCCS) && !defined(lint)
30 static char *sccsid2 = "@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
31 static char *sccsid = "@(#)svc_auth_unix.c 2.3 88/08/01 4.0 RPCSRC";
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
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.
44 * Copyright (C) 1984, Sun Microsystems, Inc.
47 #include <sys/param.h>
49 #include <sys/mutex.h>
50 #include <sys/systm.h>
51 #include <sys/ucred.h>
55 #include <rpc/rpc_com.h>
57 #define MAX_MACHINE_NAME 255
61 * Unix longhand authenticator
64 _svcauth_unix(struct svc_req *rqst, struct rpc_msg *msg)
72 size_t str_len, gid_len;
75 xcr = rqst->rq_clntcred;
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,
79 buf = XDR_INLINE(&xdrs, auth_len);
81 time = IXDR_GET_UINT32(buf);
82 str_len = (size_t)IXDR_GET_UINT32(buf);
83 if (str_len > MAX_MACHINE_NAME) {
87 str_len = RNDUP(str_len);
88 buf += str_len / sizeof (int32_t);
89 xcr->cr_uid = IXDR_GET_UINT32(buf);
90 xcr->cr_groups[0] = IXDR_GET_UINT32(buf);
91 gid_len = (size_t)IXDR_GET_UINT32(buf);
92 if (gid_len > NGRPS) {
96 for (i = 0; i < gid_len; i++) {
97 if (i + 1 < XU_NGROUPS)
98 xcr->cr_groups[i + 1] = IXDR_GET_INT32(buf);
102 if (gid_len + 1 > XU_NGROUPS)
103 xcr->cr_ngroups = XU_NGROUPS;
105 xcr->cr_ngroups = gid_len + 1;
108 * five is the smallest unix credentials structure -
109 * timestamp, hostname len (0), uid, gid, and gids len (0).
111 if ((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len > auth_len) {
112 (void) printf("bad auth_len gid %ld str %ld auth %u\n",
113 (long)gid_len, (long)str_len, auth_len);
117 } else if (! xdr_authunix_parms(&xdrs, &time, xcr)) {
122 rqst->rq_verf = _null_auth;
132 * Shorthand unix authenticator
133 * Looks up longhand in a cache.
137 _svcauth_short(rqst, msg)
138 struct svc_req *rqst;
141 return (AUTH_REJECTEDCRED);