2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (c) 1996,1999 by Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #if defined(LIBC_SCCS) && !defined(lint)
19 static const char rcsid[] = "$Id: util.c,v 1.2.18.1 2005/04/27 05:01:05 sra Exp $";
22 #include "port_before.h"
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
27 #include <arpa/nameser.h>
38 #include "port_after.h"
43 # define SPRINTF(x) strlen(sprintf/**/x)
45 # define SPRINTF(x) sprintf x
49 map_v4v6_address(const char *src, char *dst) {
50 u_char *p = (u_char *)dst;
51 char tmp[NS_INADDRSZ];
54 /* Stash a temporary copy so our caller can update in place. */
55 memcpy(tmp, src, NS_INADDRSZ);
56 /* Mark this ipv6 addr as a mapped ipv4. */
57 for (i = 0; i < 10; i++)
61 /* Retrieve the saved copy and we're done. */
62 memcpy((void*)p, tmp, NS_INADDRSZ);
66 make_group_list(struct irs_gr *this, const char *name,
67 gid_t basegid, gid_t *groups, int *ngroups)
77 * When installing primary group, duplicate it;
78 * the first element of groups is the effective gid
79 * and will be overwritten when a setgid file is executed.
83 groups[ng++] = basegid;
86 groups[ng++] = basegid;
88 * Scan the group file to find additional groups.
90 (*this->rewind)(this);
91 while ((grp = (*this->next)(this)) != NULL) {
92 if ((gid_t)grp->gr_gid == basegid)
94 for (i = 0; grp->gr_mem[i]; i++) {
95 if (!strcmp(grp->gr_mem[i], name)) {
98 groups[ng++] = grp->gr_gid;