2002-07-11 03:55:06 +04:00
|
|
|
/* $NetBSD: supcparse.c,v 1.12 2002/07/10 23:55:06 wiz Exp $ */
|
1997-06-17 22:56:02 +04:00
|
|
|
|
1993-05-21 18:52:16 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992 Carnegie Mellon University
|
|
|
|
* All Rights Reserved.
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Permission to use, copy, modify and distribute this software and its
|
|
|
|
* documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
|
|
|
|
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
1999-04-13 00:48:07 +04:00
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
1993-05-21 18:52:16 +04:00
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie Mellon
|
|
|
|
* the rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* sup collection parsing routines
|
|
|
|
**********************************************************************
|
|
|
|
* HISTORY
|
1993-08-04 21:46:14 +04:00
|
|
|
*
|
|
|
|
* 7-July-93 Nate Williams at Montana State University
|
|
|
|
* Modified SUP to use gzip based compression when sending files
|
|
|
|
* across the network to save BandWidth
|
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.6 92/08/11 12:07:38 mrt
|
|
|
|
* Added use-rel-suffix option corresponding to -u switch.
|
|
|
|
* [92/07/26 mrt]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.5 92/02/08 18:24:19 mja
|
|
|
|
* Added "keep" supfile option, corresponding to -k switch.
|
|
|
|
* [92/01/17 vdelvecc]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.4 91/05/16 14:49:50 ern
|
2002-07-11 00:19:38 +04:00
|
|
|
* Change default timeout from none to 3 hours so we don't accumalute
|
1993-05-21 18:52:16 +04:00
|
|
|
* processes running sups to dead hosts especially for users.
|
|
|
|
* [91/05/16 14:49:21 ern]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
*
|
|
|
|
* 10-Feb-88 Glenn Marcy (gm0w) at Carnegie-Mellon University
|
|
|
|
* Added timeout to backoff.
|
|
|
|
*
|
|
|
|
* 28-Jun-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
|
|
|
|
* Added code for "release" support. Removed obsolete options.
|
|
|
|
*
|
|
|
|
* 25-May-87 Doug Philips (dwp) at Carnegie-Mellon University
|
|
|
|
* Split off from sup.c
|
|
|
|
*
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "supcdefs.h"
|
1996-12-23 22:42:01 +03:00
|
|
|
#include "supextern.h"
|
1993-05-21 18:52:16 +04:00
|
|
|
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
extern char _argbreak; /* break character from nxtarg */
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
typedef enum { /* supfile options */
|
1993-05-21 18:52:16 +04:00
|
|
|
OHOST, OBASE, OHOSTBASE, OPREFIX, ORELEASE,
|
|
|
|
ONOTIFY, OLOGIN, OPASSWORD, OCRYPT,
|
1993-08-04 21:46:14 +04:00
|
|
|
OBACKUP, ODELETE, OEXECUTE, OOLD, OTIMEOUT, OKEEP, OURELSUF,
|
|
|
|
OCOMPRESS
|
2002-07-11 00:19:38 +04:00
|
|
|
} OPTION;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
|
|
|
struct option {
|
|
|
|
char *op_name;
|
|
|
|
OPTION op_enum;
|
2002-07-11 00:19:38 +04:00
|
|
|
} options[] = {
|
|
|
|
{ "host", OHOST },
|
|
|
|
{ "base", OBASE },
|
|
|
|
{ "hostbase", OHOSTBASE },
|
|
|
|
{ "prefix", OPREFIX },
|
|
|
|
{ "release", ORELEASE },
|
|
|
|
{ "notify", ONOTIFY },
|
|
|
|
{ "login", OLOGIN },
|
|
|
|
{ "password", OPASSWORD },
|
|
|
|
{ "crypt", OCRYPT },
|
|
|
|
{ "backup", OBACKUP },
|
|
|
|
{ "delete", ODELETE },
|
|
|
|
{ "execute", OEXECUTE },
|
|
|
|
{ "old", OOLD },
|
|
|
|
{ "timeout", OTIMEOUT },
|
|
|
|
{ "keep", OKEEP },
|
1996-12-23 22:42:01 +03:00
|
|
|
{ "use-rel-suffix", OURELSUF },
|
2002-07-11 00:19:38 +04:00
|
|
|
{ "compress", OCOMPRESS }
|
1993-05-21 18:52:16 +04:00
|
|
|
};
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
static void passdelim(char **, char);
|
1996-12-23 22:42:01 +03:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
static void
|
|
|
|
passdelim(char **ptr, char delim)
|
|
|
|
{ /* skip over delimiter */
|
|
|
|
*ptr = skipover(*ptr, " \t");
|
1993-05-21 18:52:16 +04:00
|
|
|
if (_argbreak != delim && **ptr == delim) {
|
|
|
|
(*ptr)++;
|
2002-07-11 00:19:38 +04:00
|
|
|
*ptr = skipover(*ptr, " \t");
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
parsecoll(COLLECTION * c, char *collname, char *args)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
char *arg, *p;
|
|
|
|
OPTION option;
|
1993-05-21 18:52:16 +04:00
|
|
|
int opno;
|
|
|
|
|
|
|
|
c->Cnext = NULL;
|
2002-07-11 00:19:38 +04:00
|
|
|
c->Cname = salloc(collname);
|
1993-05-21 18:52:16 +04:00
|
|
|
c->Chost = NULL;
|
|
|
|
c->Chtree = NULL;
|
|
|
|
c->Cbase = NULL;
|
|
|
|
c->Chbase = NULL;
|
|
|
|
c->Cprefix = NULL;
|
|
|
|
c->Crelease = NULL;
|
|
|
|
c->Cnotify = NULL;
|
|
|
|
c->Clogin = NULL;
|
|
|
|
c->Cpswd = NULL;
|
|
|
|
c->Ccrypt = NULL;
|
2002-07-11 00:19:38 +04:00
|
|
|
c->Ctimeout = 3 * 60 * 60; /* default to 3 hours instead of no
|
|
|
|
* timeout */
|
1993-05-21 18:52:16 +04:00
|
|
|
c->Cflags = 0;
|
|
|
|
c->Cnogood = FALSE;
|
|
|
|
c->Clockfd = -1;
|
2002-07-11 00:19:38 +04:00
|
|
|
args = skipover(args, " \t");
|
|
|
|
while (*(arg = nxtarg(&args, " \t="))) {
|
1993-05-21 18:52:16 +04:00
|
|
|
for (opno = 0; opno < sizeofA(options); opno++)
|
2002-07-11 00:19:38 +04:00
|
|
|
if (strcmp(arg, options[opno].op_name) == 0)
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
if (opno == sizeofA(options)) {
|
2002-07-11 00:19:38 +04:00
|
|
|
logerr("Invalid supfile option %s for collection %s",
|
|
|
|
arg, c->Cname);
|
|
|
|
return (-1);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
option = options[opno].op_enum;
|
|
|
|
switch (option) {
|
|
|
|
case OHOST:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
1993-05-21 18:52:16 +04:00
|
|
|
do {
|
2002-07-11 00:19:38 +04:00
|
|
|
arg = nxtarg(&args, ", \t");
|
|
|
|
(void) Tinsert(&c->Chtree, arg, FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
arg = args;
|
2002-07-11 00:19:38 +04:00
|
|
|
p = skipover(args, " \t");
|
|
|
|
if (*p++ == ',')
|
|
|
|
args = p;
|
1993-05-21 18:52:16 +04:00
|
|
|
} while (arg != args);
|
|
|
|
break;
|
|
|
|
case OBASE:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Cbase = salloc(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case OHOSTBASE:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Chbase = salloc(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case OPREFIX:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Cprefix = salloc(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case ORELEASE:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Crelease = salloc(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case ONOTIFY:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Cnotify = salloc(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case OLOGIN:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Clogin = salloc(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case OPASSWORD:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Cpswd = salloc(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case OCRYPT:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Ccrypt = salloc(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case OBACKUP:
|
|
|
|
c->Cflags |= CFBACKUP;
|
|
|
|
break;
|
|
|
|
case ODELETE:
|
|
|
|
c->Cflags |= CFDELETE;
|
|
|
|
break;
|
|
|
|
case OEXECUTE:
|
|
|
|
c->Cflags |= CFEXECUTE;
|
|
|
|
break;
|
|
|
|
case OOLD:
|
|
|
|
c->Cflags |= CFOLD;
|
|
|
|
break;
|
|
|
|
case OKEEP:
|
|
|
|
c->Cflags |= CFKEEP;
|
|
|
|
break;
|
|
|
|
case OURELSUF:
|
|
|
|
c->Cflags |= CFURELSUF;
|
|
|
|
break;
|
1993-08-04 21:46:14 +04:00
|
|
|
case OCOMPRESS:
|
|
|
|
c->Cflags |= CFCOMPRESS;
|
|
|
|
break;
|
1993-05-21 18:52:16 +04:00
|
|
|
case OTIMEOUT:
|
2002-07-11 00:19:38 +04:00
|
|
|
passdelim(&args, '=');
|
|
|
|
arg = nxtarg(&args, " \t");
|
|
|
|
c->Ctimeout = atoi(arg);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
return (0);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
1995-06-04 01:21:48 +04:00
|
|
|
|
|
|
|
|
1996-12-31 21:08:00 +03:00
|
|
|
time_t
|
2002-07-11 00:19:38 +04:00
|
|
|
getwhen(char *collection, char *relsuffix)
|
1995-06-04 01:21:48 +04:00
|
|
|
{
|
|
|
|
char buf[STRINGLENGTH];
|
|
|
|
char *ep;
|
|
|
|
FILE *fp;
|
1996-12-31 21:08:00 +03:00
|
|
|
time_t tstamp;
|
1995-06-04 01:21:48 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) sprintf(buf, FILEWHEN, collection, relsuffix);
|
1995-06-04 01:21:48 +04:00
|
|
|
|
|
|
|
if ((fp = fopen(buf, "r")) == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (fgets(buf, sizeof(buf), fp) == NULL) {
|
|
|
|
(void) fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
(void) fclose(fp);
|
|
|
|
|
|
|
|
if ((tstamp = strtol(buf, &ep, 0)) == -1 || *ep != '\n')
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return tstamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-07-11 00:19:38 +04:00
|
|
|
putwhen(char *fname, time_t tstamp)
|
1995-06-04 01:21:48 +04:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
if ((fp = fopen(fname, "w")) == NULL)
|
|
|
|
return 0;
|
2002-07-11 00:19:38 +04:00
|
|
|
if (fprintf(fp, "%lu\n", (u_long) tstamp) < 0)
|
1995-06-04 01:21:48 +04:00
|
|
|
return 0;
|
|
|
|
if (fclose(fp) != 0)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|