17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 567dbe2beSCasper H.S. Dik * Common Development and Distribution License (the "License"). 667dbe2beSCasper H.S. Dik * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 2267dbe2beSCasper H.S. Dik * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 317c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate /* 357c478bd9Sstevel@tonic-gate * authunix_prot.c 367c478bd9Sstevel@tonic-gate * XDR for UNIX style authentication parameters for RPC 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/param.h> 407c478bd9Sstevel@tonic-gate #include <sys/time.h> 417c478bd9Sstevel@tonic-gate #include <sys/cred.h> 427c478bd9Sstevel@tonic-gate #include <sys/proc.h> 437c478bd9Sstevel@tonic-gate #include <sys/user.h> 447c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #include <rpc/types.h> 477c478bd9Sstevel@tonic-gate #include <rpc/rpc_sztypes.h> 487c478bd9Sstevel@tonic-gate #include <rpc/xdr.h> 497c478bd9Sstevel@tonic-gate #include <rpc/auth.h> 507c478bd9Sstevel@tonic-gate #include <rpc/auth_unix.h> 517c478bd9Sstevel@tonic-gate #include <rpc/clnt.h> 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * XDR for unix authentication parameters. 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate bool_t 577c478bd9Sstevel@tonic-gate xdr_authunix_parms(XDR *xdrs, struct authunix_parms *p) 587c478bd9Sstevel@tonic-gate { 597c478bd9Sstevel@tonic-gate if (xdr_u_int(xdrs, &p->aup_time) && 607c478bd9Sstevel@tonic-gate xdr_string(xdrs, &p->aup_machname, MAX_MACHINE_NAME) && 617c478bd9Sstevel@tonic-gate xdr_int(xdrs, (int *)&(p->aup_uid)) && 627c478bd9Sstevel@tonic-gate xdr_int(xdrs, (int *)&(p->aup_gid)) && 637c478bd9Sstevel@tonic-gate xdr_array(xdrs, (caddr_t *)&(p->aup_gids), 647c478bd9Sstevel@tonic-gate &(p->aup_len), NGRPS, sizeof (int), 657c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_int)) { 667c478bd9Sstevel@tonic-gate return (TRUE); 677c478bd9Sstevel@tonic-gate } 687c478bd9Sstevel@tonic-gate return (FALSE); 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * XDR user id types (uid_t) 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate bool_t 757c478bd9Sstevel@tonic-gate xdr_uid_t(XDR *xdrs, uid_t *ip) 767c478bd9Sstevel@tonic-gate { 777c478bd9Sstevel@tonic-gate #ifdef lint 787c478bd9Sstevel@tonic-gate (void) (xdr_short(xdrs, (short *)ip)); 797c478bd9Sstevel@tonic-gate return (xdr_int32(xdrs, (int32_t *)ip)); 807c478bd9Sstevel@tonic-gate #else 817c478bd9Sstevel@tonic-gate if (sizeof (uid_t) == sizeof (int32_t)) { 827c478bd9Sstevel@tonic-gate return (xdr_int(xdrs, (int32_t *)ip)); 837c478bd9Sstevel@tonic-gate } else { 847c478bd9Sstevel@tonic-gate return (xdr_short(xdrs, (short *)ip)); 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate #endif 877c478bd9Sstevel@tonic-gate } 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * XDR group id types (gid_t) 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate bool_t 937c478bd9Sstevel@tonic-gate xdr_gid_t(XDR *xdrs, gid_t *ip) 947c478bd9Sstevel@tonic-gate { 957c478bd9Sstevel@tonic-gate #ifdef lint 967c478bd9Sstevel@tonic-gate (void) (xdr_short(xdrs, (short *)ip)); 977c478bd9Sstevel@tonic-gate return (xdr_int32(xdrs, (int32_t *)ip)); 987c478bd9Sstevel@tonic-gate #else 997c478bd9Sstevel@tonic-gate if (sizeof (gid_t) == sizeof (int32_t)) { 1007c478bd9Sstevel@tonic-gate return (xdr_int32(xdrs, (int32_t *)ip)); 1017c478bd9Sstevel@tonic-gate } else { 1027c478bd9Sstevel@tonic-gate return (xdr_short(xdrs, (short *)ip)); 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate #endif 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * XDR kernel unix auth parameters. 1097c478bd9Sstevel@tonic-gate * Goes out of the u struct directly. 1107c478bd9Sstevel@tonic-gate * NOTE: this is an XDR_ENCODE only routine. 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate bool_t 113*0e91b739SMarcel Telka xdr_authkern(XDR *xdrs, cred_t *cr) 1147c478bd9Sstevel@tonic-gate { 1157c478bd9Sstevel@tonic-gate uid_t uid; 1167c478bd9Sstevel@tonic-gate gid_t gid; 1177c478bd9Sstevel@tonic-gate uint_t len; 1187c478bd9Sstevel@tonic-gate caddr_t groups; 1197c478bd9Sstevel@tonic-gate char *name = uts_nodename(); 1207c478bd9Sstevel@tonic-gate time_t now; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate if (xdrs->x_op != XDR_ENCODE) 1237c478bd9Sstevel@tonic-gate return (FALSE); 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate uid = crgetuid(cr); 1267c478bd9Sstevel@tonic-gate gid = crgetgid(cr); 1277c478bd9Sstevel@tonic-gate len = crgetngroups(cr); 12867dbe2beSCasper H.S. Dik 12967dbe2beSCasper H.S. Dik if (len > NGRPS) 13067dbe2beSCasper H.S. Dik len = NGRPS; 13167dbe2beSCasper H.S. Dik 1327c478bd9Sstevel@tonic-gate groups = (caddr_t)crgetgroups(cr); 1337c478bd9Sstevel@tonic-gate now = gethrestime_sec(); 1347c478bd9Sstevel@tonic-gate if (xdr_uint32(xdrs, (uint32_t *)&now) && 1357c478bd9Sstevel@tonic-gate xdr_string(xdrs, &name, MAX_MACHINE_NAME) && 1367c478bd9Sstevel@tonic-gate xdr_uid_t(xdrs, &uid) && 1377c478bd9Sstevel@tonic-gate xdr_gid_t(xdrs, &gid) && 138*0e91b739SMarcel Telka xdr_array(xdrs, &groups, &len, NGRPS, sizeof (gid_t), xdr_gid_t)) 1397c478bd9Sstevel@tonic-gate return (TRUE); 1407c478bd9Sstevel@tonic-gate return (FALSE); 1417c478bd9Sstevel@tonic-gate } 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* 1447c478bd9Sstevel@tonic-gate * XDR loopback unix auth parameters. 1457c478bd9Sstevel@tonic-gate * NOTE: this is an XDR_ENCODE only routine. 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate bool_t 148*0e91b739SMarcel Telka xdr_authloopback(XDR *xdrs, cred_t *cr) 1497c478bd9Sstevel@tonic-gate { 1507c478bd9Sstevel@tonic-gate uid_t uid; 1517c478bd9Sstevel@tonic-gate gid_t gid; 152*0e91b739SMarcel Telka uint_t len; 1537c478bd9Sstevel@tonic-gate caddr_t groups; 1547c478bd9Sstevel@tonic-gate char *name = uts_nodename(); 1557c478bd9Sstevel@tonic-gate time_t now; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate if (xdrs->x_op != XDR_ENCODE) 1587c478bd9Sstevel@tonic-gate return (FALSE); 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate uid = crgetuid(cr); 1617c478bd9Sstevel@tonic-gate gid = crgetgid(cr); 1627c478bd9Sstevel@tonic-gate len = crgetngroups(cr); 1637c478bd9Sstevel@tonic-gate groups = (caddr_t)crgetgroups(cr); 1647c478bd9Sstevel@tonic-gate now = gethrestime_sec(); 1657c478bd9Sstevel@tonic-gate if (xdr_uint32(xdrs, (uint32_t *)&now) && 1667c478bd9Sstevel@tonic-gate xdr_string(xdrs, &name, MAX_MACHINE_NAME) && 1677c478bd9Sstevel@tonic-gate xdr_uid_t(xdrs, &uid) && 1687c478bd9Sstevel@tonic-gate xdr_gid_t(xdrs, &gid) && 169*0e91b739SMarcel Telka xdr_array(xdrs, &groups, &len, NGROUPS_UMAX, sizeof (gid_t), 170*0e91b739SMarcel Telka xdr_gid_t)) 1717c478bd9Sstevel@tonic-gate return (TRUE); 1727c478bd9Sstevel@tonic-gate return (FALSE); 1737c478bd9Sstevel@tonic-gate } 174