mknetid.c revision 1.1 1 1.1 thorpej /* $NetBSD: mknetid.c,v 1.1 1996/08/09 10:14:55 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 1996 Mats O Jansson <moj (at) stacken.kth.se>
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
16 1.1 thorpej * must display the following acknowledgement:
17 1.1 thorpej * This product includes software developed by Mats O Jansson
18 1.1 thorpej * 4. The name of the author may not be used to endorse or promote products
19 1.1 thorpej * derived from this software without specific prior written permission.
20 1.1 thorpej *
21 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 1.1 thorpej * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 1.1 thorpej * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 1.1 thorpej * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 thorpej * SUCH DAMAGE.
32 1.1 thorpej */
33 1.1 thorpej
34 1.1 thorpej /*
35 1.1 thorpej * Originally written by Mats O Jansson <moj (at) stacken.kth.se>
36 1.1 thorpej * Simplified a bit by Jason R. Thorpe <thorpej (at) NetBSD.ORG>
37 1.1 thorpej */
38 1.1 thorpej
39 1.1 thorpej #include <sys/param.h>
40 1.1 thorpej #include <sys/queue.h>
41 1.1 thorpej #include <ctype.h>
42 1.1 thorpej #include <err.h>
43 1.1 thorpej #include <grp.h>
44 1.1 thorpej #include <limits.h>
45 1.1 thorpej #include <netdb.h>
46 1.1 thorpej #include <pwd.h>
47 1.1 thorpej #include <stdio.h>
48 1.1 thorpej #include <string.h>
49 1.1 thorpej #include <stdlib.h>
50 1.1 thorpej #include <unistd.h>
51 1.1 thorpej
52 1.1 thorpej #include "protos.h"
53 1.1 thorpej
54 1.1 thorpej struct user {
55 1.1 thorpej char *usr_name; /* user name */
56 1.1 thorpej int usr_uid; /* user uid */
57 1.1 thorpej int usr_gid; /* user gid */
58 1.1 thorpej int gid_count; /* number of gids */
59 1.1 thorpej int gid[NGROUPS]; /* additional gids */
60 1.1 thorpej TAILQ_ENTRY(user) read; /* links in read order */
61 1.1 thorpej TAILQ_ENTRY(user) hash; /* links in hash order */
62 1.1 thorpej };
63 1.1 thorpej
64 1.1 thorpej #ifdef HOSTS
65 1.1 thorpej char *HostFile = HOSTS;
66 1.1 thorpej #else
67 1.1 thorpej char *HostFile = _PATH_HOSTS;
68 1.1 thorpej #endif
69 1.1 thorpej
70 1.1 thorpej #ifdef PASSWD
71 1.1 thorpej char *PasswdFile = PASSWD;
72 1.1 thorpej #else
73 1.1 thorpej char *PasswdFile = _PATH_PASSWD;
74 1.1 thorpej #endif
75 1.1 thorpej
76 1.1 thorpej #ifdef GROUP
77 1.1 thorpej char *GroupFile = GROUP;
78 1.1 thorpej #else
79 1.1 thorpej char *GroupFile = _PATH_GROUP;
80 1.1 thorpej #endif
81 1.1 thorpej
82 1.1 thorpej #ifdef NETID
83 1.1 thorpej char *NetidFile = NETID;
84 1.1 thorpej #else
85 1.1 thorpej char *NetidFile = "/etc/netid";
86 1.1 thorpej #endif
87 1.1 thorpej
88 1.1 thorpej #define HASHMAX 55
89 1.1 thorpej
90 1.1 thorpej void print_passwd_group __P((int, char *));
91 1.1 thorpej void print_hosts __P((FILE *, char *, char *));
92 1.1 thorpej void print_netid __P((FILE *, char *));
93 1.1 thorpej void add_user __P((char *, char *, char *));
94 1.1 thorpej void add_group __P((char *, char *));
95 1.1 thorpej void read_passwd __P((FILE *, char *));
96 1.1 thorpej void read_group __P((FILE *, char *));
97 1.1 thorpej void usage __P((void));
98 1.1 thorpej int hashidx __P((char));
99 1.1 thorpej int isgsep __P((char));
100 1.1 thorpej
101 1.1 thorpej TAILQ_HEAD(user_list, user);
102 1.1 thorpej struct user_list root;
103 1.1 thorpej struct user_list hroot[HASHMAX];
104 1.1 thorpej
105 1.1 thorpej extern char *__progname; /* from crt0.s */
106 1.1 thorpej extern char *optarg;
107 1.1 thorpej extern int optind;
108 1.1 thorpej
109 1.1 thorpej int
110 1.1 thorpej main(argc, argv)
111 1.1 thorpej int argc;
112 1.1 thorpej char **argv;
113 1.1 thorpej {
114 1.1 thorpej int qflag, ch;
115 1.1 thorpej char *domain;
116 1.1 thorpej FILE *pfile, *gfile, *hfile, *mfile;
117 1.1 thorpej
118 1.1 thorpej TAILQ_INIT(&root);
119 1.1 thorpej for (ch = 0; ch < HASHMAX; ch++)
120 1.1 thorpej TAILQ_INIT((&hroot[ch]));
121 1.1 thorpej
122 1.1 thorpej qflag = 0;
123 1.1 thorpej domain = NULL;
124 1.1 thorpej
125 1.1 thorpej while ((ch = getopt(argc, argv, "d:g:h:m:p:q")) != -1) {
126 1.1 thorpej switch (ch) {
127 1.1 thorpej case 'd':
128 1.1 thorpej domain = optarg;
129 1.1 thorpej break;
130 1.1 thorpej
131 1.1 thorpej case 'g':
132 1.1 thorpej GroupFile = optarg;
133 1.1 thorpej break;
134 1.1 thorpej
135 1.1 thorpej case 'h':
136 1.1 thorpej HostFile = optarg;
137 1.1 thorpej break;
138 1.1 thorpej
139 1.1 thorpej case 'm':
140 1.1 thorpej NetidFile = optarg;
141 1.1 thorpej break;
142 1.1 thorpej
143 1.1 thorpej case 'p':
144 1.1 thorpej PasswdFile = optarg;
145 1.1 thorpej break;
146 1.1 thorpej
147 1.1 thorpej case 'q':
148 1.1 thorpej qflag++;
149 1.1 thorpej break;
150 1.1 thorpej
151 1.1 thorpej default:
152 1.1 thorpej usage();
153 1.1 thorpej }
154 1.1 thorpej }
155 1.1 thorpej argc -= optind; argv += optind;
156 1.1 thorpej
157 1.1 thorpej if (argc != 0)
158 1.1 thorpej usage();
159 1.1 thorpej
160 1.1 thorpej if (domain == NULL)
161 1.1 thorpej if (yp_get_default_domain(&domain))
162 1.1 thorpej errx(1, "can't get YP domain name");
163 1.1 thorpej
164 1.1 thorpej if ((pfile = fopen(PasswdFile, "r")) == NULL)
165 1.1 thorpej err(1, "%s", PasswdFile);
166 1.1 thorpej
167 1.1 thorpej if ((gfile = fopen(GroupFile, "r")) == NULL)
168 1.1 thorpej err(1, "%s", GroupFile);
169 1.1 thorpej
170 1.1 thorpej if ((hfile = fopen(HostFile, "r")) == NULL)
171 1.1 thorpej err(1, "%s", HostFile);
172 1.1 thorpej
173 1.1 thorpej mfile = fopen(NetidFile, "r");
174 1.1 thorpej
175 1.1 thorpej read_passwd(pfile, PasswdFile);
176 1.1 thorpej read_group(gfile, GroupFile);
177 1.1 thorpej
178 1.1 thorpej print_passwd_group(qflag, domain);
179 1.1 thorpej print_hosts(hfile, HostFile, domain);
180 1.1 thorpej
181 1.1 thorpej if (mfile != NULL)
182 1.1 thorpej print_netid(mfile, NetidFile);
183 1.1 thorpej
184 1.1 thorpej exit (0);
185 1.1 thorpej }
186 1.1 thorpej
187 1.1 thorpej int
188 1.1 thorpej hashidx(key)
189 1.1 thorpej char key;
190 1.1 thorpej {
191 1.1 thorpej if (key < 'A')
192 1.1 thorpej return(0);
193 1.1 thorpej
194 1.1 thorpej if (key <= 'Z')
195 1.1 thorpej return(1 + key - 'A');
196 1.1 thorpej
197 1.1 thorpej if (key < 'a')
198 1.1 thorpej return(27);
199 1.1 thorpej
200 1.1 thorpej if (key <= 'z')
201 1.1 thorpej return(28 + key - 'a');
202 1.1 thorpej
203 1.1 thorpej return(54);
204 1.1 thorpej }
205 1.1 thorpej
206 1.1 thorpej void
207 1.1 thorpej add_user(username, uid, gid)
208 1.1 thorpej char *username, *uid, *gid;
209 1.1 thorpej {
210 1.1 thorpej struct user *u;
211 1.1 thorpej int idx;
212 1.1 thorpej
213 1.1 thorpej idx = hashidx(username[0]);
214 1.1 thorpej
215 1.1 thorpej u = (struct user *)malloc(sizeof(struct user));
216 1.1 thorpej if (u == NULL)
217 1.1 thorpej err(1, "can't allocate user");
218 1.1 thorpej memset(u, 0, sizeof(struct user));
219 1.1 thorpej
220 1.1 thorpej u->usr_name = (char *)malloc(strlen(username) + 1);
221 1.1 thorpej if (u->usr_name == NULL)
222 1.1 thorpej err(1, "can't allocate user name");
223 1.1 thorpej strcpy(u->usr_name, username);
224 1.1 thorpej
225 1.1 thorpej u->usr_uid = atoi(uid);
226 1.1 thorpej u->usr_gid = atoi(gid);
227 1.1 thorpej u->gid_count = -1;
228 1.1 thorpej
229 1.1 thorpej TAILQ_INSERT_TAIL(&root, u, read);
230 1.1 thorpej TAILQ_INSERT_TAIL((&hroot[idx]), u, hash);
231 1.1 thorpej }
232 1.1 thorpej
233 1.1 thorpej void
234 1.1 thorpej add_group(username, gid)
235 1.1 thorpej char *username, *gid;
236 1.1 thorpej {
237 1.1 thorpej struct user *u;
238 1.1 thorpej int g, idx;
239 1.1 thorpej
240 1.1 thorpej g = atoi(gid);
241 1.1 thorpej idx = hashidx(username[0]);
242 1.1 thorpej
243 1.1 thorpej for (u = hroot[idx].tqh_first;
244 1.1 thorpej u != NULL; u = u->hash.tqe_next) {
245 1.1 thorpej if (strcmp(username, u->usr_name) == 0) {
246 1.1 thorpej if (g != u->usr_gid) {
247 1.1 thorpej u->gid_count++;
248 1.1 thorpej if (u->gid_count < NGROUPS)
249 1.1 thorpej u->gid[u->gid_count] = g;
250 1.1 thorpej }
251 1.1 thorpej return;
252 1.1 thorpej }
253 1.1 thorpej }
254 1.1 thorpej }
255 1.1 thorpej
256 1.1 thorpej void
257 1.1 thorpej read_passwd(pfile, fname)
258 1.1 thorpej FILE *pfile;
259 1.1 thorpej char *fname;
260 1.1 thorpej {
261 1.1 thorpej char line[_POSIX2_LINE_MAX];
262 1.1 thorpej int line_no = 0, len, colon;
263 1.1 thorpej char *p, *k, *u, *g;
264 1.1 thorpej
265 1.1 thorpej while (read_line(pfile, line, sizeof(line))) {
266 1.1 thorpej line_no++;
267 1.1 thorpej len = strlen(line);
268 1.1 thorpej
269 1.1 thorpej if (len > 1) {
270 1.1 thorpej if (line[0] == '#') {
271 1.1 thorpej continue;
272 1.1 thorpej }
273 1.1 thorpej } else
274 1.1 thorpej continue;
275 1.1 thorpej
276 1.1 thorpej /*
277 1.1 thorpej * Check if we have the whole line
278 1.1 thorpej */
279 1.1 thorpej if (line[len - 1] != '\n') {
280 1.1 thorpej warnx("%s line %d: line to long, skipping",
281 1.1 thorpej fname, line_no);
282 1.1 thorpej continue;
283 1.1 thorpej } else
284 1.1 thorpej line[len - 1] = '\0';
285 1.1 thorpej
286 1.1 thorpej p = line;
287 1.1 thorpej
288 1.1 thorpej for (k = p, colon = 0; *k != '\0'; k++)
289 1.1 thorpej if (*k == ':')
290 1.1 thorpej colon++;
291 1.1 thorpej
292 1.1 thorpej if (colon > 0) {
293 1.1 thorpej /* terminate key */
294 1.1 thorpej for (k = p; *p != ':'; p++);
295 1.1 thorpej *p++ = '\0';
296 1.1 thorpej
297 1.1 thorpej /* If it's a YP entry, skip it. */
298 1.1 thorpej if (strlen(k) == 1)
299 1.1 thorpej if (*k == '+' || *k == '-')
300 1.1 thorpej continue;
301 1.1 thorpej }
302 1.1 thorpej
303 1.1 thorpej if (colon < 4) {
304 1.1 thorpej warnx("%s line %d: syntax error",
305 1.1 thorpej fname, line_no);
306 1.1 thorpej continue;
307 1.1 thorpej }
308 1.1 thorpej
309 1.1 thorpej /* terminate password */
310 1.1 thorpej for (; *p != ':'; p++);
311 1.1 thorpej *p++ = '\0';
312 1.1 thorpej
313 1.1 thorpej /* terminate uid */
314 1.1 thorpej for (u = p; *p != ':'; p++);
315 1.1 thorpej *p++ = '\0';
316 1.1 thorpej
317 1.1 thorpej /* terminate gid */
318 1.1 thorpej for (g = p; *p != ':'; p++);
319 1.1 thorpej *p++ = '\0';
320 1.1 thorpej
321 1.1 thorpej add_user(k, u, g);
322 1.1 thorpej }
323 1.1 thorpej }
324 1.1 thorpej
325 1.1 thorpej int
326 1.1 thorpej isgsep(ch)
327 1.1 thorpej char ch;
328 1.1 thorpej {
329 1.1 thorpej
330 1.1 thorpej switch (ch) {
331 1.1 thorpej case ',':
332 1.1 thorpej case ' ':
333 1.1 thorpej case '\t':
334 1.1 thorpej case '\0':
335 1.1 thorpej return (1);
336 1.1 thorpej }
337 1.1 thorpej
338 1.1 thorpej return (0);
339 1.1 thorpej }
340 1.1 thorpej
341 1.1 thorpej void
342 1.1 thorpej read_group(gfile, fname)
343 1.1 thorpej FILE *gfile;
344 1.1 thorpej char *fname;
345 1.1 thorpej {
346 1.1 thorpej char line[_POSIX2_LINE_MAX];
347 1.1 thorpej int line_no = 0, len, colon;
348 1.1 thorpej char *p, *k, *u, *g;
349 1.1 thorpej
350 1.1 thorpej while (read_line(gfile, line, sizeof(line))) {
351 1.1 thorpej line_no++;
352 1.1 thorpej len = strlen(line);
353 1.1 thorpej
354 1.1 thorpej if (len > 1) {
355 1.1 thorpej if (line[0] == '#') {
356 1.1 thorpej continue;
357 1.1 thorpej }
358 1.1 thorpej } else
359 1.1 thorpej continue;
360 1.1 thorpej
361 1.1 thorpej /*
362 1.1 thorpej * Check if we have the whole line
363 1.1 thorpej */
364 1.1 thorpej if (line[len - 1] != '\n') {
365 1.1 thorpej warnx("%s line %d: line to long, skipping",
366 1.1 thorpej fname, line_no);
367 1.1 thorpej continue;
368 1.1 thorpej } else
369 1.1 thorpej line[len - 1] = '\0';
370 1.1 thorpej
371 1.1 thorpej p = line;
372 1.1 thorpej
373 1.1 thorpej for (k = p, colon = 0; *k != '\0'; k++)
374 1.1 thorpej if (*k == ':')
375 1.1 thorpej colon++;
376 1.1 thorpej
377 1.1 thorpej if (colon > 0) {
378 1.1 thorpej /* terminate key */
379 1.1 thorpej for (k = p; *p != ':'; p++);
380 1.1 thorpej *p++ = '\0';
381 1.1 thorpej
382 1.1 thorpej /* If it's a YP entry, skip it. */
383 1.1 thorpej if (strlen(k) == 1)
384 1.1 thorpej if (*k == '+' || *k == '-')
385 1.1 thorpej continue;
386 1.1 thorpej }
387 1.1 thorpej
388 1.1 thorpej if (colon < 3) {
389 1.1 thorpej warnx("%s line %d: syntax error",
390 1.1 thorpej fname, line_no);
391 1.1 thorpej continue;
392 1.1 thorpej }
393 1.1 thorpej
394 1.1 thorpej /* terminate password */
395 1.1 thorpej for (; *p != ':'; p++);
396 1.1 thorpej *p++ = '\0';
397 1.1 thorpej
398 1.1 thorpej /* terminate gid */
399 1.1 thorpej for (g = p; *p != ':'; p++);
400 1.1 thorpej *p++ = '\0';
401 1.1 thorpej
402 1.1 thorpej /* get the group list */
403 1.1 thorpej for (u = p; *u != '\0'; u = p) {
404 1.1 thorpej /* find separator */
405 1.1 thorpej for (; isgsep(*p) == 0; p++);
406 1.1 thorpej
407 1.1 thorpej if (*p != '\0') {
408 1.1 thorpej *p = '\0';
409 1.1 thorpej if (u != p)
410 1.1 thorpej add_group(u, g);
411 1.1 thorpej p++;
412 1.1 thorpej } else if (u != p)
413 1.1 thorpej add_group(u, g);
414 1.1 thorpej }
415 1.1 thorpej }
416 1.1 thorpej }
417 1.1 thorpej
418 1.1 thorpej void
419 1.1 thorpej print_passwd_group(qflag, domain)
420 1.1 thorpej int qflag;
421 1.1 thorpej char *domain;
422 1.1 thorpej {
423 1.1 thorpej struct user *u, *p;
424 1.1 thorpej int i;
425 1.1 thorpej
426 1.1 thorpej for (u = root.tqh_first; u != NULL; u = u->read.tqe_next) {
427 1.1 thorpej for (p = root.tqh_first; p->usr_uid != u->usr_uid;
428 1.1 thorpej p = p->read.tqe_next)
429 1.1 thorpej /* empty */ ;
430 1.1 thorpej if (p != u) {
431 1.1 thorpej if (!qflag) {
432 1.1 thorpej warnx("unix.%d@%s %s", u->usr_uid, domain,
433 1.1 thorpej "multiply defined, ignoring duplicate");
434 1.1 thorpej }
435 1.1 thorpej } else {
436 1.1 thorpej printf("unix.%d@%s %d:%d", u->usr_uid, domain,
437 1.1 thorpej u->usr_uid, u->usr_gid);
438 1.1 thorpej if (u->gid_count >= 0)
439 1.1 thorpej for (i = 0; i <= u->gid_count; i++)
440 1.1 thorpej printf(",%d", u->gid[i]);
441 1.1 thorpej printf("\n");
442 1.1 thorpej }
443 1.1 thorpej }
444 1.1 thorpej }
445 1.1 thorpej
446 1.1 thorpej void
447 1.1 thorpej print_hosts(pfile, fname, domain)
448 1.1 thorpej FILE *pfile;
449 1.1 thorpej char *fname, *domain;
450 1.1 thorpej {
451 1.1 thorpej char line[_POSIX2_LINE_MAX];
452 1.1 thorpej int line_no = 0, len, colon;
453 1.1 thorpej char *p, *k, *u;
454 1.1 thorpej
455 1.1 thorpej while (read_line(pfile, line, sizeof(line))) {
456 1.1 thorpej line_no++;
457 1.1 thorpej len = strlen(line);
458 1.1 thorpej
459 1.1 thorpej if (len > 1) {
460 1.1 thorpej if (line[0] == '#') {
461 1.1 thorpej continue;
462 1.1 thorpej }
463 1.1 thorpej } else
464 1.1 thorpej continue;
465 1.1 thorpej
466 1.1 thorpej /*
467 1.1 thorpej * Check if we have the whole line
468 1.1 thorpej */
469 1.1 thorpej if (line[len - 1] != '\n') {
470 1.1 thorpej warnx("%s line %d: line to long, skipping",
471 1.1 thorpej fname, line_no);
472 1.1 thorpej continue;
473 1.1 thorpej } else
474 1.1 thorpej line[len - 1] = '\0';
475 1.1 thorpej
476 1.1 thorpej p = line;
477 1.1 thorpej
478 1.1 thorpej /* Find the key, replace trailing whitespace will <NUL> */
479 1.1 thorpej for (k = p; isspace(*p) == 0; p++);
480 1.1 thorpej while (isspace(*p))
481 1.1 thorpej *p++ = '\0';
482 1.1 thorpej
483 1.1 thorpej /* Get first hostname. */
484 1.1 thorpej for (u = p; ; ) {
485 1.1 thorpej /* Check for EOL */
486 1.1 thorpej if (*p == '\0')
487 1.1 thorpej break;
488 1.1 thorpej
489 1.1 thorpej if (isspace(*p) == 0)
490 1.1 thorpej p++;
491 1.1 thorpej else {
492 1.1 thorpej /* Got it. */
493 1.1 thorpej *p = '\0';
494 1.1 thorpej break;
495 1.1 thorpej }
496 1.1 thorpej }
497 1.1 thorpej
498 1.1 thorpej printf("unix.%s@%s 0:%s\n", u, domain, u);
499 1.1 thorpej }
500 1.1 thorpej }
501 1.1 thorpej
502 1.1 thorpej void
503 1.1 thorpej print_netid(mfile, fname)
504 1.1 thorpej FILE *mfile;
505 1.1 thorpej char *fname;
506 1.1 thorpej {
507 1.1 thorpej char line[_POSIX2_LINE_MAX];
508 1.1 thorpej int line_no = 0, len, colon;
509 1.1 thorpej char *p, *k, *u;
510 1.1 thorpej
511 1.1 thorpej while (read_line(mfile, line, sizeof(line))) {
512 1.1 thorpej line_no++;
513 1.1 thorpej len = strlen(line);
514 1.1 thorpej
515 1.1 thorpej if (len > 1)
516 1.1 thorpej if (line[0] == '#')
517 1.1 thorpej continue;
518 1.1 thorpej else
519 1.1 thorpej continue;
520 1.1 thorpej
521 1.1 thorpej /*
522 1.1 thorpej * Check if we have the while line
523 1.1 thorpej */
524 1.1 thorpej if (line[len - 1] != '\n') {
525 1.1 thorpej warnx("%s line %d: line to long, skipping",
526 1.1 thorpej fname, line_no);
527 1.1 thorpej continue;
528 1.1 thorpej } else
529 1.1 thorpej line[len - 1] = '\0';
530 1.1 thorpej
531 1.1 thorpej p = line;
532 1.1 thorpej
533 1.1 thorpej /* Find the key, replace trailing whitespace will <NUL> */
534 1.1 thorpej for (k = p; isspace(*p) == 0; p++);
535 1.1 thorpej while (isspace(*p))
536 1.1 thorpej *p++ = '\0';
537 1.1 thorpej
538 1.1 thorpej /* Get netid entry. */
539 1.1 thorpej for (u = p; ; ) {
540 1.1 thorpej /* Check for EOL */
541 1.1 thorpej if (*p == '\0')
542 1.1 thorpej break;
543 1.1 thorpej
544 1.1 thorpej if (isspace(*p) == 0)
545 1.1 thorpej p++;
546 1.1 thorpej else {
547 1.1 thorpej /* Got it. */
548 1.1 thorpej *p = '\0';
549 1.1 thorpej break;
550 1.1 thorpej }
551 1.1 thorpej }
552 1.1 thorpej
553 1.1 thorpej printf("%s %s\n", k, u);
554 1.1 thorpej }
555 1.1 thorpej }
556 1.1 thorpej
557 1.1 thorpej void
558 1.1 thorpej usage()
559 1.1 thorpej {
560 1.1 thorpej
561 1.1 thorpej fprintf(stderr, "usage %s: %s %s\n", __progname,
562 1.1 thorpej "[-d domain] [-q] [-p passwdfile] [-g groupfile]");
563 1.1 thorpej fprintf(stderr, " %s",
564 1.1 thorpej "[-g groupfile] [-h hostfile] [-m netidfile]");
565 1.1 thorpej }
566