4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
24 * Copyright 2017 Joyent Inc
25 * Use is subject to license terms.
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
32 * Portions of this source code were derived from Berkeley 4.3 BSD
33 * under license from the Regents of the University of California.
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.
45 #include <sys/param.h>
46 #include <sys/types.h>
48 #include <sys/systm.h>
49 #include <sys/stream.h>
50 #include <sys/stropts.h>
51 #include <sys/strsubr.h>
52 #include <sys/tiuser.h>
53 #include <sys/tihdr.h>
54 #include <sys/t_kuser.h>
55 #include <sys/cmn_err.h>
56 #include <sys/debug.h>
58 #include <rpc/types.h>
62 #include <rpc/rpc_msg.h>
64 #include <rpc/auth_unix.h>
65 #include <rpc/svc_auth.h>
69 * Unix longhand authenticator
72 _svcauth_unix(struct svc_req
*rqst
, struct rpc_msg
*msg
)
74 struct authunix_parms
*aup
;
77 struct authunix_parms area_aup
;
78 char area_machname
[MAX_MACHINE_NAME
+1];
79 gid_t area_gids
[NGRPS
];
82 uint_t str_len
, gid_len
;
85 CTASSERT(sizeof (struct area
) <= RQCRED_SIZE
);
86 /* LINTED pointer alignment */
87 area
= (struct area
*)rqst
->rq_clntcred
;
88 aup
= &area
->area_aup
;
89 aup
->aup_machname
= area
->area_machname
;
90 aup
->aup_gids
= area
->area_gids
;
91 auth_len
= msg
->rm_call
.cb_cred
.oa_length
;
93 return (AUTH_BADCRED
);
95 /* LINTED pointer cast */
96 buf
= (int32_t *)msg
->rm_call
.cb_cred
.oa_base
;
98 aup
->aup_time
= IXDR_GET_INT32(buf
);
99 str_len
= IXDR_GET_U_INT32(buf
);
100 if (str_len
> MAX_MACHINE_NAME
)
101 return (AUTH_BADCRED
);
102 bcopy((caddr_t
)buf
, aup
->aup_machname
, str_len
);
103 aup
->aup_machname
[str_len
] = 0;
104 str_len
= RNDUP(str_len
);
105 buf
+= str_len
/ sizeof (int32_t);
106 aup
->aup_uid
= IXDR_GET_INT32(buf
);
107 aup
->aup_gid
= IXDR_GET_INT32(buf
);
108 gid_len
= IXDR_GET_U_INT32(buf
);
110 return (AUTH_BADCRED
);
111 aup
->aup_len
= gid_len
;
112 for (i
= 0; i
< gid_len
; i
++) {
113 aup
->aup_gids
[i
] = IXDR_GET_INT32(buf
);
116 * five is the smallest unix credentials structure -
117 * timestamp, hostname len (0), uid, gid, and gids len (0).
119 if ((5 + gid_len
) * BYTES_PER_XDR_UNIT
+ str_len
> auth_len
)
120 return (AUTH_BADCRED
);
122 rqst
->rq_xprt
->xp_verf
.oa_flavor
= AUTH_NULL
;
123 rqst
->rq_xprt
->xp_verf
.oa_length
= 0;
130 * Shorthand unix authenticator
131 * Looks up longhand in a cache.
135 _svcauth_short(struct svc_req
*rqst
, struct rpc_msg
*msg
)
137 return (AUTH_REJECTEDCRED
);