Sync usage with man page.
[netbsd-mini2440.git] / usr.sbin / sup / source / supcname.c
blob0ef59b0e2921f3827e25f38e0f9305f4ceb020f0
1 /* $NetBSD: supcname.c,v 1.6 2002/07/10 20:19:45 wiz Exp $ */
3 /*
4 * Copyright (c) 1992 Carnegie Mellon University
5 * All Rights Reserved.
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie Mellon
25 * the rights to redistribute these changes.
28 * sup client name server interface
29 **********************************************************************
30 * HISTORY
31 * Revision 1.4 92/08/11 12:07:32 mrt
32 * Added copyright.
33 * [92/08/10 mrt]
35 * 21-Dec-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
36 * Changed to no longer use a name server.
38 * 26-May-87 Doug Philips (dwp) at Carnegie-Mellon University
39 * Changed getnams and added several new routines to change the
40 * way that sup finds nameservers. It now builds a tree of
41 * servers to check. It walks over the tree. At each node, it
42 * tries to contact the name server and get as many names
43 * resolved as it can. It stops after either all collections
44 * have host names, or if some collections don't have host names
45 * but either everyone doesn't know what they are, or after too
46 * many tries, none could be reached.
48 * 25-May-87 Doug Philips (dwp) at Carnegie-Mellon University
49 * Split off from sup.c
51 **********************************************************************
54 #include "supcdefs.h"
55 #include "supextern.h"
57 extern COLLECTION *firstC; /* collection list pointer */
59 /*****************************************
60 *** G E T H O S T N A M E S ***
61 *****************************************/
64 * For each collection that doesn't have a host name specified, read
65 * the file server list for the name of the host for that collection.
66 * It's a fatal error if a collection has no file server.
69 void
70 getnams(void)
72 COLLECTION *c;
73 char buf[STRINGLENGTH];
74 FILE *f;
75 char *p, *q;
77 for (c = firstC; c && c->Chtree != NULL; c = c->Cnext);
78 if (c == NULL)
79 return;
80 (void) sprintf(buf, FILEHOSTS, DEFDIR);
81 f = fopen(buf, "r");
82 if (f == NULL)
83 logquit(1, "Can't open %s", buf);
84 while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
85 if ((q = strchr(p, '\n')) != NULL)
86 *q = '\0';
87 if (strchr("#;:", *p))
88 continue;
89 q = nxtarg(&p, "= \t");
90 p = skipover(p, " \t");
91 if (*p == '=')
92 p++;
93 p = skipover(p, " \t");
94 if (*p == '\0')
95 goaway("error in collection/host file");
96 do {
97 if (strcmp(c->Cname, q) == 0) {
98 do {
99 q = nxtarg(&p, ", \t");
100 p = skipover(p, " \t");
101 if (*p == ',')
102 p++;
103 p = skipover(p, " \t");
104 (void) Tinsert(&c->Chtree, q, FALSE);
105 } while (*p != '\0');
107 while ((c = c->Cnext) != NULL && c->Chtree != NULL);
108 } while (c != NULL);
109 for (c = firstC; c && c->Chtree != NULL; c = c->Cnext);
110 if (c == NULL)
111 break;
113 (void) fclose(f);
114 if (c == NULL)
115 return;
116 do {
117 logerr("Host for collection %s not found", c->Cname);
118 while ((c = c->Cnext) != NULL && c->Chtree != NULL);
119 } while (c);
120 logquit(1, "Hosts not found for all collections");