]>
git.saurik.com Git - apple/network_cmds.git/blob - revnetgroup.tproj/revnetgroup.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 /* $OpenBSD: revnetgroup.c,v 1.1 1997/04/15 22:06:15 maja Exp $ */
27 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by Bill Paul.
40 * 4. Neither the name of the author nor the names of any co-contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * reverse netgroup map generator program
58 * Written by Bill Paul <wpaul@ctr.columbia.edu>
59 * Center for Telecommunications Research
60 * Columbia University, New York City
62 * $FreeBSD: revnetgroup.c,v 1.7 1997/03/28 15:48:15 imp Exp $
73 static const char rcsid
[] = "$OpenBSD: revnetgroup.c,v 1.1 1997/04/15 22:06:15 maja Exp $";
76 /* Default location of netgroup file. */
77 char *netgroup
= "/etc/netgroup";
79 /* Stored hash table version of 'forward' netgroup database. */
80 struct group_entry
*gtable
[TABLESIZE
];
83 * Stored hash table of 'reverse' netgroup member database
84 * which we will construct.
86 struct member_entry
*mtable
[TABLESIZE
];
91 fprintf (stderr
,"usage: %s -u|-h [-f netgroup file]\n",prog
);
103 char readbuf
[LINSIZ
];
104 struct group_entry
*gcur
;
105 struct member_entry
*mcur
;
106 char *host
, *user
, *domain
;
108 char *key
= NULL
, *data
= NULL
;
114 while ((ch
= getopt(argc
, argv
, "uhf:")) != -1) {
118 warnx("please use only one of -u or -h");
125 warnx("please use only one of -u or -h");
142 if (strcmp(netgroup
, "-")) {
143 if ((fp
= fopen(netgroup
, "r")) == NULL
) {
150 /* Stuff all the netgroup names and members into a hash table. */
151 while (fgets(readbuf
, LINSIZ
, fp
)) {
152 if (readbuf
[0] == '#')
154 /* handle backslash line continuations */
155 while(readbuf
[strlen(readbuf
) - 2] == '\\') {
156 fgets((char *)&readbuf
[strlen(readbuf
) - 2],
157 sizeof(readbuf
) - strlen(readbuf
), fp
);
160 if ((data
= (char *)(strpbrk(readbuf
, " \t") + 1)) < (char *)2)
162 key
= (char *)&readbuf
;
164 store(gtable
, key
, data
);
170 * Find all members of each netgroup and keep track of which
171 * group they belong to.
173 for (i
= 0; i
< TABLESIZE
; i
++) {
176 __setnetgrent(gcur
->key
);
177 while(__getnetgrent(&host
, &user
, &domain
) != NULL
) {
179 if (!(host
&& !strcmp(host
,"-"))) {
183 domain
? domain
: "*");
186 if (!(user
&& !strcmp(user
,"-"))) {
190 domain
? domain
: "*");
198 /* Release resources used by the netgroup parser code. */
201 /* Spew out the results. */
202 for (i
= 0; i
< TABLESIZE
; i
++) {
205 struct grouplist
*tmp
;
206 printf ("%s.%s\t", mcur
->key
, mcur
->domain
);
209 printf ("%s", tmp
->groupname
);
219 /* Let the OS free all our resources. */