10Sstevel@tonic-gate /* 2*11038SRao.Shoaib@Sun.COM * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 30Sstevel@tonic-gate * Copyright (c) 1996,1999 by Internet Software Consortium. 40Sstevel@tonic-gate * 50Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this software for any 60Sstevel@tonic-gate * purpose with or without fee is hereby granted, provided that the above 70Sstevel@tonic-gate * copyright notice and this permission notice appear in all copies. 80Sstevel@tonic-gate * 9*11038SRao.Shoaib@Sun.COM * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 10*11038SRao.Shoaib@Sun.COM * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*11038SRao.Shoaib@Sun.COM * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 12*11038SRao.Shoaib@Sun.COM * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*11038SRao.Shoaib@Sun.COM * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*11038SRao.Shoaib@Sun.COM * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 15*11038SRao.Shoaib@Sun.COM * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 160Sstevel@tonic-gate */ 170Sstevel@tonic-gate 180Sstevel@tonic-gate #if defined(LIBC_SCCS) && !defined(lint) 19*11038SRao.Shoaib@Sun.COM static const char rcsid[] = "$Id: util.c,v 1.3 2005/04/27 04:56:34 sra Exp $"; 200Sstevel@tonic-gate #endif 210Sstevel@tonic-gate 220Sstevel@tonic-gate #include "port_before.h" 230Sstevel@tonic-gate 240Sstevel@tonic-gate #include <sys/types.h> 250Sstevel@tonic-gate #include <sys/socket.h> 260Sstevel@tonic-gate #include <netinet/in.h> 270Sstevel@tonic-gate #include <arpa/nameser.h> 280Sstevel@tonic-gate #include <resolv.h> 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <ctype.h> 310Sstevel@tonic-gate #include <errno.h> 320Sstevel@tonic-gate #include <stdio.h> 330Sstevel@tonic-gate #include <string.h> 340Sstevel@tonic-gate #include <stdlib.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <irs.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include "port_after.h" 390Sstevel@tonic-gate 400Sstevel@tonic-gate #include "irs_p.h" 410Sstevel@tonic-gate 420Sstevel@tonic-gate #ifdef SPRINTF_CHAR 430Sstevel@tonic-gate # define SPRINTF(x) strlen(sprintf/**/x) 440Sstevel@tonic-gate #else 450Sstevel@tonic-gate # define SPRINTF(x) sprintf x 460Sstevel@tonic-gate #endif 470Sstevel@tonic-gate 480Sstevel@tonic-gate void 490Sstevel@tonic-gate map_v4v6_address(const char *src, char *dst) { 500Sstevel@tonic-gate u_char *p = (u_char *)dst; 510Sstevel@tonic-gate char tmp[NS_INADDRSZ]; 520Sstevel@tonic-gate int i; 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* Stash a temporary copy so our caller can update in place. */ 550Sstevel@tonic-gate memcpy(tmp, src, NS_INADDRSZ); 560Sstevel@tonic-gate /* Mark this ipv6 addr as a mapped ipv4. */ 570Sstevel@tonic-gate for (i = 0; i < 10; i++) 580Sstevel@tonic-gate *p++ = 0x00; 590Sstevel@tonic-gate *p++ = 0xff; 600Sstevel@tonic-gate *p++ = 0xff; 610Sstevel@tonic-gate /* Retrieve the saved copy and we're done. */ 620Sstevel@tonic-gate memcpy((void*)p, tmp, NS_INADDRSZ); 630Sstevel@tonic-gate } 640Sstevel@tonic-gate 650Sstevel@tonic-gate int 660Sstevel@tonic-gate make_group_list(struct irs_gr *this, const char *name, 670Sstevel@tonic-gate gid_t basegid, gid_t *groups, int *ngroups) 680Sstevel@tonic-gate { 690Sstevel@tonic-gate struct group *grp; 700Sstevel@tonic-gate int i, ng; 710Sstevel@tonic-gate int ret, maxgroups; 720Sstevel@tonic-gate 730Sstevel@tonic-gate ret = -1; 740Sstevel@tonic-gate ng = 0; 750Sstevel@tonic-gate maxgroups = *ngroups; 760Sstevel@tonic-gate /* 770Sstevel@tonic-gate * When installing primary group, duplicate it; 780Sstevel@tonic-gate * the first element of groups is the effective gid 790Sstevel@tonic-gate * and will be overwritten when a setgid file is executed. 800Sstevel@tonic-gate */ 810Sstevel@tonic-gate if (ng >= maxgroups) 820Sstevel@tonic-gate goto done; 830Sstevel@tonic-gate groups[ng++] = basegid; 840Sstevel@tonic-gate if (ng >= maxgroups) 850Sstevel@tonic-gate goto done; 860Sstevel@tonic-gate groups[ng++] = basegid; 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * Scan the group file to find additional groups. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate (*this->rewind)(this); 910Sstevel@tonic-gate while ((grp = (*this->next)(this)) != NULL) { 920Sstevel@tonic-gate if ((gid_t)grp->gr_gid == basegid) 930Sstevel@tonic-gate continue; 940Sstevel@tonic-gate for (i = 0; grp->gr_mem[i]; i++) { 950Sstevel@tonic-gate if (!strcmp(grp->gr_mem[i], name)) { 960Sstevel@tonic-gate if (ng >= maxgroups) 970Sstevel@tonic-gate goto done; 980Sstevel@tonic-gate groups[ng++] = grp->gr_gid; 990Sstevel@tonic-gate break; 1000Sstevel@tonic-gate } 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate } 1030Sstevel@tonic-gate ret = 0; 1040Sstevel@tonic-gate done: 1050Sstevel@tonic-gate *ngroups = ng; 1060Sstevel@tonic-gate return (ret); 1070Sstevel@tonic-gate } 108*11038SRao.Shoaib@Sun.COM 109*11038SRao.Shoaib@Sun.COM /*! \file */ 110