xref: /onnv-gate/usr/src/uts/common/rpc/sec/authu_prot.c (revision 11134:8aa0c4ca6639)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*11134SCasper.Dik@Sun.COM  * Common Development and Distribution License (the "License").
6*11134SCasper.Dik@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11134SCasper.Dik@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
310Sstevel@tonic-gate  * under license from the Regents of the University of California.
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate /*
350Sstevel@tonic-gate  * authunix_prot.c
360Sstevel@tonic-gate  * XDR for UNIX style authentication parameters for RPC
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <sys/param.h>
400Sstevel@tonic-gate #include <sys/time.h>
410Sstevel@tonic-gate #include <sys/cred.h>
420Sstevel@tonic-gate #include <sys/proc.h>
430Sstevel@tonic-gate #include <sys/user.h>
440Sstevel@tonic-gate #include <sys/utsname.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #include <rpc/types.h>
470Sstevel@tonic-gate #include <rpc/rpc_sztypes.h>
480Sstevel@tonic-gate #include <rpc/xdr.h>
490Sstevel@tonic-gate #include <rpc/auth.h>
500Sstevel@tonic-gate #include <rpc/auth_unix.h>
510Sstevel@tonic-gate #include <rpc/clnt.h>
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * XDR for unix authentication parameters.
550Sstevel@tonic-gate  */
560Sstevel@tonic-gate bool_t
xdr_authunix_parms(XDR * xdrs,struct authunix_parms * p)570Sstevel@tonic-gate xdr_authunix_parms(XDR *xdrs, struct authunix_parms *p)
580Sstevel@tonic-gate {
590Sstevel@tonic-gate 	if (xdr_u_int(xdrs, &p->aup_time) &&
600Sstevel@tonic-gate 	    xdr_string(xdrs, &p->aup_machname, MAX_MACHINE_NAME) &&
610Sstevel@tonic-gate 	    xdr_int(xdrs, (int *)&(p->aup_uid)) &&
620Sstevel@tonic-gate 	    xdr_int(xdrs, (int *)&(p->aup_gid)) &&
630Sstevel@tonic-gate 	    xdr_array(xdrs, (caddr_t *)&(p->aup_gids),
64*11134SCasper.Dik@Sun.COM 	    &(p->aup_len), NGRPS, sizeof (int),
65*11134SCasper.Dik@Sun.COM 	    (xdrproc_t)xdr_int)) {
660Sstevel@tonic-gate 		return (TRUE);
670Sstevel@tonic-gate 	}
680Sstevel@tonic-gate 	return (FALSE);
690Sstevel@tonic-gate }
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * XDR user id types (uid_t)
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate bool_t
xdr_uid_t(XDR * xdrs,uid_t * ip)750Sstevel@tonic-gate xdr_uid_t(XDR *xdrs, uid_t *ip)
760Sstevel@tonic-gate {
770Sstevel@tonic-gate #ifdef lint
780Sstevel@tonic-gate 	(void) (xdr_short(xdrs, (short *)ip));
790Sstevel@tonic-gate 	return (xdr_int32(xdrs, (int32_t *)ip));
800Sstevel@tonic-gate #else
810Sstevel@tonic-gate 	if (sizeof (uid_t) == sizeof (int32_t)) {
820Sstevel@tonic-gate 		return (xdr_int(xdrs, (int32_t *)ip));
830Sstevel@tonic-gate 	} else {
840Sstevel@tonic-gate 		return (xdr_short(xdrs, (short *)ip));
850Sstevel@tonic-gate 	}
860Sstevel@tonic-gate #endif
870Sstevel@tonic-gate }
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * XDR group id types (gid_t)
910Sstevel@tonic-gate  */
920Sstevel@tonic-gate bool_t
xdr_gid_t(XDR * xdrs,gid_t * ip)930Sstevel@tonic-gate xdr_gid_t(XDR *xdrs, gid_t *ip)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate #ifdef lint
960Sstevel@tonic-gate 	(void) (xdr_short(xdrs, (short *)ip));
970Sstevel@tonic-gate 	return (xdr_int32(xdrs, (int32_t *)ip));
980Sstevel@tonic-gate #else
990Sstevel@tonic-gate 	if (sizeof (gid_t) == sizeof (int32_t)) {
1000Sstevel@tonic-gate 		return (xdr_int32(xdrs, (int32_t *)ip));
1010Sstevel@tonic-gate 	} else {
1020Sstevel@tonic-gate 		return (xdr_short(xdrs, (short *)ip));
1030Sstevel@tonic-gate 	}
1040Sstevel@tonic-gate #endif
1050Sstevel@tonic-gate }
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate /*
1080Sstevel@tonic-gate  * XDR kernel unix auth parameters.
1090Sstevel@tonic-gate  * Goes out of the u struct directly.
1100Sstevel@tonic-gate  * NOTE: this is an XDR_ENCODE only routine.
1110Sstevel@tonic-gate  */
1120Sstevel@tonic-gate bool_t
xdr_authkern(XDR * xdrs)1130Sstevel@tonic-gate xdr_authkern(XDR *xdrs)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate 	uid_t uid;
1160Sstevel@tonic-gate 	gid_t gid;
1170Sstevel@tonic-gate 	uint_t len;
1180Sstevel@tonic-gate 	caddr_t groups;
1190Sstevel@tonic-gate 	char *name = uts_nodename();
1200Sstevel@tonic-gate 	struct cred *cr;
1210Sstevel@tonic-gate 	time_t now;
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate 	if (xdrs->x_op != XDR_ENCODE)
1240Sstevel@tonic-gate 		return (FALSE);
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	cr = CRED();
1270Sstevel@tonic-gate 	uid = crgetuid(cr);
1280Sstevel@tonic-gate 	gid = crgetgid(cr);
1290Sstevel@tonic-gate 	len = crgetngroups(cr);
130*11134SCasper.Dik@Sun.COM 
131*11134SCasper.Dik@Sun.COM 	if (len > NGRPS)
132*11134SCasper.Dik@Sun.COM 		len = NGRPS;
133*11134SCasper.Dik@Sun.COM 
1340Sstevel@tonic-gate 	groups = (caddr_t)crgetgroups(cr);
1350Sstevel@tonic-gate 	now = gethrestime_sec();
1360Sstevel@tonic-gate 	if (xdr_uint32(xdrs, (uint32_t *)&now) &&
1370Sstevel@tonic-gate 	    xdr_string(xdrs, &name, MAX_MACHINE_NAME) &&
1380Sstevel@tonic-gate 	    xdr_uid_t(xdrs, &uid) &&
1390Sstevel@tonic-gate 	    xdr_gid_t(xdrs, &gid) &&
1400Sstevel@tonic-gate 	    xdr_array(xdrs, &groups, &len, NGRPS, sizeof (int),
1410Sstevel@tonic-gate 	    (xdrproc_t)xdr_int))
1420Sstevel@tonic-gate 		return (TRUE);
1430Sstevel@tonic-gate 	return (FALSE);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * XDR loopback unix auth parameters.
1480Sstevel@tonic-gate  * NOTE: this is an XDR_ENCODE only routine.
1490Sstevel@tonic-gate  */
1500Sstevel@tonic-gate bool_t
xdr_authloopback(XDR * xdrs)1510Sstevel@tonic-gate xdr_authloopback(XDR *xdrs)
1520Sstevel@tonic-gate {
1530Sstevel@tonic-gate 	uid_t uid;
1540Sstevel@tonic-gate 	gid_t gid;
1550Sstevel@tonic-gate 	int len;
1560Sstevel@tonic-gate 	caddr_t groups;
1570Sstevel@tonic-gate 	char *name = uts_nodename();
1580Sstevel@tonic-gate 	struct cred *cr;
1590Sstevel@tonic-gate 	time_t now;
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	if (xdrs->x_op != XDR_ENCODE)
1620Sstevel@tonic-gate 		return (FALSE);
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	cr = CRED();
1650Sstevel@tonic-gate 	uid = crgetuid(cr);
1660Sstevel@tonic-gate 	gid = crgetgid(cr);
1670Sstevel@tonic-gate 	len = crgetngroups(cr);
1680Sstevel@tonic-gate 	groups = (caddr_t)crgetgroups(cr);
1690Sstevel@tonic-gate 	now = gethrestime_sec();
1700Sstevel@tonic-gate 	if (xdr_uint32(xdrs, (uint32_t *)&now) &&
1710Sstevel@tonic-gate 	    xdr_string(xdrs, &name, MAX_MACHINE_NAME) &&
1720Sstevel@tonic-gate 	    xdr_uid_t(xdrs, &uid) &&
1730Sstevel@tonic-gate 	    xdr_gid_t(xdrs, &gid) &&
1740Sstevel@tonic-gate 	    xdr_array(xdrs, &groups, (uint_t *)&len, NGRPS_LOOPBACK,
1750Sstevel@tonic-gate 	    sizeof (int), (xdrproc_t)xdr_int))
1760Sstevel@tonic-gate 		return (TRUE);
1770Sstevel@tonic-gate 	return (FALSE);
1780Sstevel@tonic-gate }
179