Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / sup / source / supcparse.c
blob962c7eac09eb5a5288a435c4d1a46d65e7b825a7
1 /* $NetBSD: supcparse.c,v 1.13 2006/03/22 16:54:26 christos 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 collection parsing routines
29 **********************************************************************
30 * HISTORY
32 * 7-July-93 Nate Williams at Montana State University
33 * Modified SUP to use gzip based compression when sending files
34 * across the network to save BandWidth
36 * Revision 1.6 92/08/11 12:07:38 mrt
37 * Added use-rel-suffix option corresponding to -u switch.
38 * [92/07/26 mrt]
40 * Revision 1.5 92/02/08 18:24:19 mja
41 * Added "keep" supfile option, corresponding to -k switch.
42 * [92/01/17 vdelvecc]
44 * Revision 1.4 91/05/16 14:49:50 ern
45 * Change default timeout from none to 3 hours so we don't accumalute
46 * processes running sups to dead hosts especially for users.
47 * [91/05/16 14:49:21 ern]
50 * 10-Feb-88 Glenn Marcy (gm0w) at Carnegie-Mellon University
51 * Added timeout to backoff.
53 * 28-Jun-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
54 * Added code for "release" support. Removed obsolete options.
56 * 25-May-87 Doug Philips (dwp) at Carnegie-Mellon University
57 * Split off from sup.c
59 **********************************************************************
62 #include "supcdefs.h"
63 #include "supextern.h"
66 extern char _argbreak; /* break character from nxtarg */
68 typedef enum { /* supfile options */
69 OHOST, OBASE, OHOSTBASE, OPREFIX, ORELEASE,
70 ONOTIFY, OLOGIN, OPASSWORD, OCRYPT,
71 OBACKUP, ODELETE, OEXECUTE, OOLD, OTIMEOUT, OKEEP, OURELSUF,
72 OCOMPRESS
73 } OPTION;
75 struct option {
76 char *op_name;
77 OPTION op_enum;
78 } options[] = {
79 { "host", OHOST },
80 { "base", OBASE },
81 { "hostbase", OHOSTBASE },
82 { "prefix", OPREFIX },
83 { "release", ORELEASE },
84 { "notify", ONOTIFY },
85 { "login", OLOGIN },
86 { "password", OPASSWORD },
87 { "crypt", OCRYPT },
88 { "backup", OBACKUP },
89 { "delete", ODELETE },
90 { "execute", OEXECUTE },
91 { "old", OOLD },
92 { "timeout", OTIMEOUT },
93 { "keep", OKEEP },
94 { "use-rel-suffix", OURELSUF },
95 { "compress", OCOMPRESS }
98 static void passdelim(char **, char);
100 static void
101 passdelim(char **ptr, char delim)
102 { /* skip over delimiter */
103 *ptr = skipover(*ptr, " \t");
104 if (_argbreak != delim && **ptr == delim) {
105 (*ptr)++;
106 *ptr = skipover(*ptr, " \t");
110 int
111 parsecoll(COLLECTION * c, char *collname, char *args)
113 char *arg, *p;
114 OPTION option;
115 int opno;
117 c->Cnext = NULL;
118 c->Cname = estrdup(collname);
119 c->Chost = NULL;
120 c->Chtree = NULL;
121 c->Cbase = NULL;
122 c->Chbase = NULL;
123 c->Cprefix = NULL;
124 c->Crelease = NULL;
125 c->Cnotify = NULL;
126 c->Clogin = NULL;
127 c->Cpswd = NULL;
128 c->Ccrypt = NULL;
129 c->Ctimeout = 3 * 60 * 60; /* default to 3 hours instead of no
130 * timeout */
131 c->Cflags = 0;
132 c->Cnogood = FALSE;
133 c->Clockfd = -1;
134 args = skipover(args, " \t");
135 while (*(arg = nxtarg(&args, " \t="))) {
136 for (opno = 0; opno < sizeofA(options); opno++)
137 if (strcmp(arg, options[opno].op_name) == 0)
138 break;
139 if (opno == sizeofA(options)) {
140 logerr("Invalid supfile option %s for collection %s",
141 arg, c->Cname);
142 return (-1);
144 option = options[opno].op_enum;
145 switch (option) {
146 case OHOST:
147 passdelim(&args, '=');
148 do {
149 arg = nxtarg(&args, ", \t");
150 (void) Tinsert(&c->Chtree, arg, FALSE);
151 arg = args;
152 p = skipover(args, " \t");
153 if (*p++ == ',')
154 args = p;
155 } while (arg != args);
156 break;
157 case OBASE:
158 passdelim(&args, '=');
159 arg = nxtarg(&args, " \t");
160 c->Cbase = estrdup(arg);
161 break;
162 case OHOSTBASE:
163 passdelim(&args, '=');
164 arg = nxtarg(&args, " \t");
165 c->Chbase = estrdup(arg);
166 break;
167 case OPREFIX:
168 passdelim(&args, '=');
169 arg = nxtarg(&args, " \t");
170 c->Cprefix = estrdup(arg);
171 break;
172 case ORELEASE:
173 passdelim(&args, '=');
174 arg = nxtarg(&args, " \t");
175 c->Crelease = estrdup(arg);
176 break;
177 case ONOTIFY:
178 passdelim(&args, '=');
179 arg = nxtarg(&args, " \t");
180 c->Cnotify = estrdup(arg);
181 break;
182 case OLOGIN:
183 passdelim(&args, '=');
184 arg = nxtarg(&args, " \t");
185 c->Clogin = estrdup(arg);
186 break;
187 case OPASSWORD:
188 passdelim(&args, '=');
189 arg = nxtarg(&args, " \t");
190 c->Cpswd = estrdup(arg);
191 break;
192 case OCRYPT:
193 passdelim(&args, '=');
194 arg = nxtarg(&args, " \t");
195 c->Ccrypt = estrdup(arg);
196 break;
197 case OBACKUP:
198 c->Cflags |= CFBACKUP;
199 break;
200 case ODELETE:
201 c->Cflags |= CFDELETE;
202 break;
203 case OEXECUTE:
204 c->Cflags |= CFEXECUTE;
205 break;
206 case OOLD:
207 c->Cflags |= CFOLD;
208 break;
209 case OKEEP:
210 c->Cflags |= CFKEEP;
211 break;
212 case OURELSUF:
213 c->Cflags |= CFURELSUF;
214 break;
215 case OCOMPRESS:
216 c->Cflags |= CFCOMPRESS;
217 break;
218 case OTIMEOUT:
219 passdelim(&args, '=');
220 arg = nxtarg(&args, " \t");
221 c->Ctimeout = atoi(arg);
222 break;
225 return (0);
229 time_t
230 getwhen(char *collection, char *relsuffix)
232 char buf[STRINGLENGTH];
233 char *ep;
234 FILE *fp;
235 time_t tstamp;
237 (void) sprintf(buf, FILEWHEN, collection, relsuffix);
239 if ((fp = fopen(buf, "r")) == NULL)
240 return 0;
242 if (fgets(buf, sizeof(buf), fp) == NULL) {
243 (void) fclose(fp);
244 return 0;
246 (void) fclose(fp);
248 if ((tstamp = strtol(buf, &ep, 0)) == -1 || *ep != '\n')
249 return 0;
251 return tstamp;
255 putwhen(char *fname, time_t tstamp)
257 FILE *fp;
258 if ((fp = fopen(fname, "w")) == NULL)
259 return 0;
260 if (fprintf(fp, "%lu\n", (u_long) tstamp) < 0) {
261 (void) fclose(fp);
262 return 0;
264 if (fclose(fp) != 0)
265 return 0;
266 return 1;