2002-08-09 15:06:43 +04:00
|
|
|
/* $NetBSD: supcmeat.c,v 1.26 2002/08/09 11:06:43 soren 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 "meat" 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.16 92/09/09 22:04:51 mrt
|
2002-07-11 00:19:38 +04:00
|
|
|
* Really added bww's recvone changes this time.
|
1993-05-21 18:52:16 +04:00
|
|
|
* Added code to support non-crypting version of sup.
|
|
|
|
* [92/09/01 mrt]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.15 92/08/11 12:07:09 mrt
|
|
|
|
* Added support to add release to FILEWHEN name.
|
|
|
|
* Updated variable arguemnt list usage - bww
|
|
|
|
* Updated recvone() to take a va_list - bww
|
|
|
|
* Changed conditional for rpausing code from CMUCS to MACH
|
|
|
|
* [92/07/24 mrt]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.14 92/02/08 18:24:12 mja
|
|
|
|
* Only apply "keep" mode when local file is strictly newer
|
|
|
|
* otherwise allow update as before if necessary.
|
|
|
|
* [92/02/08 18:09:00 mja]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Added support for -k (keep) option to needone(). Rewrote and
|
|
|
|
* commented other parts of needone().
|
|
|
|
* [92/01/17 vdelvecc]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.13 91/05/16 14:49:41 ern
|
|
|
|
* Add timestap to fileserver.
|
|
|
|
* Drop day of the week from 5 messages.
|
|
|
|
* [91/05/16 14:47:53 ern]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.12 89/08/23 14:55:44 gm0w
|
|
|
|
* Changed msgf routines to msg routines.
|
|
|
|
* [89/08/23 gm0w]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.11 89/08/03 19:49:10 mja
|
|
|
|
* Updated to use v*printf() in place of _doprnt().
|
|
|
|
* [89/04/19 mja]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.10 89/06/18 14:41:27 gm0w
|
|
|
|
* Fixed up some notify messages of errors to use "SUP:" prefix.
|
|
|
|
* [89/06/18 gm0w]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.9 89/06/10 15:12:17 gm0w
|
|
|
|
* Changed to always use rename to install targets. This breaks hard
|
|
|
|
* links and recreates those known to sup, other links will be orphaned.
|
|
|
|
* [89/06/10 gm0w]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.8 89/05/24 15:04:23 gm0w
|
|
|
|
* Added code to check for EINVAL from FSPARAM ioctl for disk
|
|
|
|
* space check failures when the ioctl is not implemented.
|
|
|
|
* [89/05/24 gm0w]
|
2002-07-11 00:19:38 +04:00
|
|
|
*
|
1993-05-21 18:52:16 +04:00
|
|
|
* Revision 1.7 89/01/16 18:22:28 gm0w
|
|
|
|
* Changed needone() to check that mode of files match before
|
|
|
|
* setting update if times also match.
|
|
|
|
* [89/01/16 gm0w]
|
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.
|
|
|
|
*
|
|
|
|
* 27-Dec-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
|
|
|
|
* Added crosspatch support.
|
|
|
|
*
|
|
|
|
* 09-Sep-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
|
|
|
|
* Added code to be less verbose when updating files that have
|
|
|
|
* already been successfully upgraded.
|
|
|
|
*
|
|
|
|
* 28-Jun-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
|
|
|
|
* Added code for "release" support.
|
|
|
|
*
|
|
|
|
* 26-May-87 Doug Philips (dwp) at Carnegie-Mellon University
|
|
|
|
* Converted to end connection with more information.
|
|
|
|
* Added done routine. Modified goaway routine to free old
|
|
|
|
* goawayreason.
|
|
|
|
*
|
|
|
|
* 26-May-87 Doug Philips (dwp) at Carnegie-Mellon University
|
|
|
|
* Use computeBackoff from scm instead of doing it ourselves.
|
|
|
|
*
|
|
|
|
* 25-May-87 Doug Philips (dwp) at Carnegie-Mellon University
|
|
|
|
* Split off from sup.c and reindented goaway calls.
|
|
|
|
*
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "supcdefs.h"
|
1996-12-23 22:42:01 +03:00
|
|
|
#include "supextern.h"
|
1998-10-12 09:19:48 +04:00
|
|
|
#include <sys/param.h>
|
1993-05-21 18:52:16 +04:00
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
TREE *lastT; /* last filenames in collection */
|
|
|
|
jmp_buf sjbuf; /* jump location for network errors */
|
|
|
|
int dontjump; /* flag to void sjbuf */
|
|
|
|
int cancompress = FALSE; /* Can we do compression? */
|
|
|
|
int docompress = FALSE; /* Do we do compression? */
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
extern COLLECTION *thisC; /* collection list pointer */
|
|
|
|
extern int rpauseflag; /* don't disable resource pausing */
|
|
|
|
extern int portdebug; /* network debugging ports */
|
|
|
|
extern int noutime; /* don't set utimes */
|
1993-05-21 18:52:16 +04:00
|
|
|
|
|
|
|
/*************************************************
|
|
|
|
*** U P G R A D E C O L L E C T I O N ***
|
|
|
|
*************************************************/
|
|
|
|
|
2002-07-10 22:53:56 +04:00
|
|
|
static int needone(TREE *, void *);
|
|
|
|
static int recvone(TREE *, va_list);
|
|
|
|
static int denyone(TREE *, void *);
|
|
|
|
static int deleteone(TREE *, void *);
|
|
|
|
static int linkone(TREE *, void *);
|
|
|
|
static int execone(TREE *, void *);
|
|
|
|
static int finishone(TREE *, void *);
|
1996-12-23 22:42:01 +03:00
|
|
|
|
|
|
|
|
1993-05-21 18:52:16 +04:00
|
|
|
/* The next two routines define the fsm to support multiple fileservers
|
|
|
|
* per collection.
|
|
|
|
*/
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
getonehost(TREE * t, void *v)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
1996-12-23 22:42:01 +03:00
|
|
|
long *state = v;
|
1993-05-21 18:52:16 +04:00
|
|
|
if (t->Tflags != *state)
|
|
|
|
return (SCMOK);
|
|
|
|
if (*state != 0 && t->Tmode == SCMEOF) {
|
|
|
|
t->Tflags = 0;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
if (*state == 2)
|
|
|
|
t->Tflags--;
|
|
|
|
else
|
|
|
|
t->Tflags++;
|
|
|
|
thisC->Chost = t;
|
|
|
|
return (SCMEOF);
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
TREE *
|
|
|
|
getcollhost(int *tout, int *backoff, long int *state, int *nhostsp)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
1996-12-23 22:42:01 +03:00
|
|
|
static long laststate = 0;
|
1993-05-21 18:52:16 +04:00
|
|
|
static int nhosts = 0;
|
|
|
|
|
|
|
|
if (*state != laststate) {
|
|
|
|
*nhostsp = nhosts;
|
|
|
|
laststate = *state;
|
|
|
|
nhosts = 0;
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (Tprocess(thisC->Chtree, getonehost, state) == SCMEOF) {
|
|
|
|
if (*state != 0 && nhosts == 0 && !dobackoff(tout, backoff))
|
1993-05-21 18:52:16 +04:00
|
|
|
return (NULL);
|
|
|
|
nhosts++;
|
|
|
|
return (thisC->Chost);
|
|
|
|
}
|
|
|
|
if (nhosts == 0)
|
|
|
|
return (NULL);
|
|
|
|
if (*state == 2)
|
|
|
|
(*state)--;
|
|
|
|
else
|
|
|
|
(*state)++;
|
2002-07-11 00:19:38 +04:00
|
|
|
return (getcollhost(tout, backoff, state, nhostsp));
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
/* Upgrade a collection from the file server on the appropriate
|
|
|
|
* host machine.
|
|
|
|
*/
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
void
|
|
|
|
getcoll(void)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
TREE *t;
|
|
|
|
int x;
|
|
|
|
int tout, backoff, nhosts;
|
1996-12-23 22:42:01 +03:00
|
|
|
long state;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
|
|
|
collname = thisC->Cname;
|
|
|
|
tout = thisC->Ctimeout;
|
|
|
|
lastT = NULL;
|
|
|
|
backoff = 2;
|
|
|
|
state = 0;
|
|
|
|
nhosts = 0;
|
|
|
|
for (;;) {
|
2002-07-11 00:19:38 +04:00
|
|
|
t = getcollhost(&tout, &backoff, &state, &nhosts);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (t == NULL) {
|
2002-07-11 00:19:38 +04:00
|
|
|
finishup(SCMEOF);
|
|
|
|
notify((char *) NULL);
|
1993-05-21 18:52:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
t->Tmode = SCMEOF;
|
|
|
|
dontjump = FALSE;
|
2002-07-11 00:19:38 +04:00
|
|
|
if (!setjmp(sjbuf) && !signon(t, nhosts, &tout) && !setup(t))
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) requestend();
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
dontjump = FALSE;
|
2002-07-11 00:19:38 +04:00
|
|
|
if (setjmp(sjbuf))
|
1993-05-21 18:52:16 +04:00
|
|
|
x = SCMERR;
|
|
|
|
else {
|
2002-07-11 00:19:38 +04:00
|
|
|
suplogin();
|
|
|
|
listfiles();
|
|
|
|
recvfiles();
|
1993-05-21 18:52:16 +04:00
|
|
|
x = SCMOK;
|
|
|
|
}
|
|
|
|
if (thisC->Clockfd >= 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) close(thisC->Clockfd);
|
1993-05-21 18:52:16 +04:00
|
|
|
thisC->Clockfd = -1;
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
finishup(x);
|
|
|
|
notify((char *) NULL);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
/*** Sign on to file server ***/
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
signon(TREE * t, int nhosts, int *tout)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
int x;
|
1993-05-21 18:52:16 +04:00
|
|
|
int timeout;
|
1996-12-31 21:08:00 +03:00
|
|
|
time_t tloc;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFLOCAL) == 0 && thishost(thisC->Chost->Tname)) {
|
|
|
|
vnotify("SUP: Skipping local collection %s\n", collname);
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tmode = SCMEOF;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
if (nhosts == 1)
|
|
|
|
timeout = *tout;
|
|
|
|
else
|
|
|
|
timeout = 0;
|
2002-07-11 00:19:38 +04:00
|
|
|
x = request(portdebug ? DEBUGFPORT : FILEPORT,
|
|
|
|
thisC->Chost->Tname, &timeout);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (nhosts == 1)
|
|
|
|
*tout = timeout;
|
|
|
|
if (x != SCMOK) {
|
|
|
|
if (nhosts) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Can't connect to host %s\n",
|
|
|
|
thisC->Chost->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tmode = SCMEOF;
|
|
|
|
} else
|
|
|
|
t->Tmode = SCMOK;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
xpatch = FALSE;
|
2002-07-11 00:19:38 +04:00
|
|
|
x = msgsignon(); /* signon to fileserver */
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error sending signon request to fileserver");
|
|
|
|
x = msgsignonack(); /* receive signon ack from fileserver */
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error reading signon reply from fileserver");
|
|
|
|
tloc = time((time_t *) NULL);
|
|
|
|
vnotify("SUP Fileserver %d.%d (%s) %d on %s at %.8s\n",
|
|
|
|
protver, pgmver, scmver, fspid, remotehost(), ctime(&tloc) + 11);
|
|
|
|
free(scmver);
|
1993-05-21 18:52:16 +04:00
|
|
|
scmver = NULL;
|
|
|
|
if (protver < 4) {
|
|
|
|
dontjump = TRUE;
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Fileserver sup protocol version is obsolete.");
|
|
|
|
notify("SUP: This version of sup can only communicate with a fileserver using at least\n");
|
|
|
|
notify("SUP: version 4 of the sup network protocol. You should either run a newer\n");
|
|
|
|
notify("SUP: version of the sup fileserver or find an older version of sup.\n");
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tmode = SCMEOF;
|
|
|
|
return (TRUE);
|
|
|
|
}
|
1993-08-04 21:46:14 +04:00
|
|
|
/* If protocol is > 7 then try compression */
|
|
|
|
if (protver > 7) {
|
|
|
|
cancompress = TRUE;
|
|
|
|
}
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
/*** Tell file server what to connect to ***/
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
setup(TREE * t)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
|
|
|
char relsufix[STRINGLENGTH];
|
2002-07-11 00:19:38 +04:00
|
|
|
int x;
|
1993-05-21 18:52:16 +04:00
|
|
|
struct stat sbuf;
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if (chdir(thisC->Cbase) < 0)
|
|
|
|
goaway("Can't change to base directory %s", thisC->Cbase);
|
|
|
|
if (stat("sup", &sbuf) < 0) {
|
|
|
|
(void) mkdir("sup", 0755);
|
|
|
|
if (stat("sup", &sbuf) < 0)
|
|
|
|
goaway("Can't create directory %s/sup", thisC->Cbase);
|
|
|
|
vnotify("SUP Created directory %s/sup\n", thisC->Cbase);
|
|
|
|
}
|
|
|
|
if (thisC->Cprefix && chdir(thisC->Cprefix) < 0)
|
|
|
|
goaway("Can't change to %s from base directory %s",
|
|
|
|
thisC->Cprefix, thisC->Cbase);
|
|
|
|
if (stat(".", &sbuf) < 0)
|
|
|
|
goaway("Can't stat %s directory %s",
|
|
|
|
thisC->Cprefix ? "prefix" : "base",
|
|
|
|
thisC->Cprefix ? thisC->Cprefix : thisC->Cbase);
|
|
|
|
if (thisC->Cprefix)
|
|
|
|
(void) chdir(thisC->Cbase);
|
1993-05-21 18:52:16 +04:00
|
|
|
/* read time of last upgrade from when file */
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFURELSUF) && thisC->Crelease)
|
|
|
|
(void) sprintf(relsufix, ".%s", thisC->Crelease);
|
1993-05-21 18:52:16 +04:00
|
|
|
else
|
|
|
|
relsufix[0] = '\0';
|
2002-07-11 00:19:38 +04:00
|
|
|
lasttime = getwhen(collname, relsufix);
|
1993-05-21 18:52:16 +04:00
|
|
|
/* setup for msgsetup */
|
|
|
|
basedir = thisC->Chbase;
|
|
|
|
basedev = sbuf.st_dev;
|
|
|
|
baseino = sbuf.st_ino;
|
2002-07-11 00:19:38 +04:00
|
|
|
listonly = (thisC->Cflags & CFLIST);
|
|
|
|
newonly = ((thisC->Cflags & (CFALL | CFDELETE | CFOLD)) == 0);
|
1993-05-21 18:52:16 +04:00
|
|
|
release = thisC->Crelease;
|
2002-07-11 00:19:38 +04:00
|
|
|
x = msgsetup();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error sending setup request to file server");
|
|
|
|
x = msgsetupack();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error reading setup reply from file server");
|
1993-05-21 18:52:16 +04:00
|
|
|
if (setupack == FSETUPOK) {
|
|
|
|
/* Test encryption */
|
2002-07-11 00:19:38 +04:00
|
|
|
if (netcrypt(thisC->Ccrypt) != SCMOK)
|
|
|
|
goaway("Running non-crypting sup");
|
1993-05-21 18:52:16 +04:00
|
|
|
crypttest = CRYPTTEST;
|
2002-07-11 00:19:38 +04:00
|
|
|
x = msgcrypt();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error sending encryption test request");
|
|
|
|
x = msgcryptok();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x == SCMEOF)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Data encryption test failed");
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error reading encryption test reply");
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
switch (setupack) {
|
|
|
|
case FSETUPSAME:
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Attempt to upgrade from same host to same directory\n");
|
|
|
|
done(FDONESRVERROR, "Overwrite error");
|
1993-05-21 18:52:16 +04:00
|
|
|
case FSETUPHOST:
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: This host has no permission to access %s\n",
|
|
|
|
collname);
|
|
|
|
done(FDONESRVERROR, "Permission denied");
|
1993-05-21 18:52:16 +04:00
|
|
|
case FSETUPOLD:
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: This version of SUP is too old for the fileserver\n");
|
|
|
|
done(FDONESRVERROR, "Obsolete client");
|
1993-05-21 18:52:16 +04:00
|
|
|
case FSETUPRELEASE:
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Invalid release %s for collection %s\n",
|
|
|
|
release == NULL ? DEFRELEASE : release, collname);
|
|
|
|
done(FDONESRVERROR, "Invalid release");
|
1993-05-21 18:52:16 +04:00
|
|
|
case FSETUPBUSY:
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Fileserver is currently busy\n");
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tmode = SCMOK;
|
|
|
|
doneack = FDONESRVERROR;
|
|
|
|
donereason = "Fileserver is busy";
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) netcrypt((char *) NULL);
|
|
|
|
(void) msgdone();
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
default:
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Unrecognized file server setup status %d", setupack);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
1996-12-23 22:42:01 +03:00
|
|
|
return FALSE;
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
/*** Tell file server what account to use ***/
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
void
|
|
|
|
suplogin(void)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
|
|
|
char buf[STRINGLENGTH];
|
2002-07-11 00:19:38 +04:00
|
|
|
int f, x;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
|
|
|
/* lock collection if desired */
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) sprintf(buf, FILELOCK, collname);
|
|
|
|
f = open(buf, O_RDONLY, 0);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (f >= 0) {
|
1996-09-05 20:50:01 +04:00
|
|
|
|
|
|
|
#if defined(LOCK_EX)
|
2002-07-11 00:19:38 +04:00
|
|
|
#define TESTLOCK(f) flock(f, LOCK_EX|LOCK_NB)
|
|
|
|
#define SHARELOCK(f) flock(f, LOCK_SH|LOCK_NB)
|
|
|
|
#define WAITLOCK(f) flock(f, LOCK_EX)
|
1996-09-05 20:50:01 +04:00
|
|
|
#elif defined(F_LOCK)
|
2002-07-11 00:19:38 +04:00
|
|
|
#define TESTLOCK(f) lockf(f, F_TLOCK, 0)
|
|
|
|
#define SHARELOCK(f) 1
|
|
|
|
#define WAITLOCK(f) lockf(f, F_LOCK, 0)
|
1996-09-05 20:50:01 +04:00
|
|
|
#else
|
2002-07-11 00:19:38 +04:00
|
|
|
#define TESTLOCK(f) (close(f), f = -1, 1)
|
|
|
|
#define SHARELOCK(f) 1
|
|
|
|
#define WAITLOCK(f) 1
|
1996-09-05 20:50:01 +04:00
|
|
|
#endif
|
|
|
|
if (TESTLOCK(f) < 0) {
|
|
|
|
if (errno != EWOULDBLOCK && errno != EAGAIN) {
|
|
|
|
(void) close(f);
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Can't lock collection %s", collname);
|
1996-09-05 20:50:01 +04:00
|
|
|
}
|
|
|
|
if (SHARELOCK(f) < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) close(f);
|
|
|
|
if (errno == EWOULDBLOCK && errno != EAGAIN)
|
|
|
|
goaway("Collection %s is locked by another sup", collname);
|
|
|
|
goaway("Can't lock collection %s", collname);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Waiting for exclusive access lock\n");
|
1996-09-05 20:50:01 +04:00
|
|
|
if (WAITLOCK(f) < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) close(f);
|
|
|
|
goaway("Can't lock collection %s", collname);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
thisC->Clockfd = f;
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Locked collection %s for exclusive access\n", collname);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
logcrypt = (char *) NULL;
|
|
|
|
loguser = thisC->Clogin;
|
|
|
|
logpswd = thisC->Cpswd;
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
#ifndef CRYPTING /* Define CRYPTING for backwards compatibility
|
|
|
|
* with old supfileservers */
|
|
|
|
if (thisC->Clogin != (char *) NULL) /* othewise we only encrypt if
|
|
|
|
* there is a login id */
|
|
|
|
#endif /* CRYPTING */
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
|
|
|
logcrypt = CRYPTTEST;
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) netcrypt(PSWDCRYPT); /* encrypt password data */
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
x = msglogin();
|
1993-05-21 18:52:16 +04:00
|
|
|
#ifndef CRYPTING
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Clogin != (char *) NULL)
|
1993-05-21 18:52:16 +04:00
|
|
|
#endif
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) netcrypt((char *) NULL); /* turn off encryption */
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error sending login request to file server");
|
|
|
|
x = msglogack();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error reading login reply from file server");
|
1993-05-21 18:52:16 +04:00
|
|
|
if (logack == FLOGNG) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: %s\n", logerror);
|
|
|
|
free(logerror);
|
1993-05-21 18:52:16 +04:00
|
|
|
logerror = NULL;
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Improper login to %s account",
|
|
|
|
thisC->Clogin ? thisC->Clogin : "default");
|
|
|
|
done(FDONESRVERROR, "Improper login");
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (netcrypt(thisC->Ccrypt) != SCMOK) /* restore encryption */
|
1993-05-21 18:52:16 +04:00
|
|
|
goaway("Running non-crypting sup");
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* send list of files that we are not interested in. receive list of
|
|
|
|
* files that are on the repository that could be upgraded. Find the
|
|
|
|
* ones that we need. Receive the list of files that the server could
|
|
|
|
* not access. Delete any files that have been upgraded in the past
|
|
|
|
* which are no longer on the repository.
|
|
|
|
*/
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
void
|
|
|
|
listfiles(void)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
|
|
|
char buf[STRINGLENGTH];
|
|
|
|
char relsufix[STRINGLENGTH];
|
2002-07-11 00:19:38 +04:00
|
|
|
char *p, *q;
|
|
|
|
FILE *f;
|
|
|
|
int x;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFURELSUF) && release)
|
|
|
|
(void) sprintf(relsufix, ".%s", release);
|
1993-05-21 18:52:16 +04:00
|
|
|
else
|
|
|
|
relsufix[0] = '\0';
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) sprintf(buf, FILELAST, collname, relsufix);
|
|
|
|
f = fopen(buf, "r");
|
1993-05-21 18:52:16 +04:00
|
|
|
if (f) {
|
2002-07-11 00:19:38 +04:00
|
|
|
while ((p = fgets(buf, STRINGLENGTH, f))) {
|
|
|
|
if ((q = index(p, '\n')))
|
|
|
|
*q = '\0';
|
|
|
|
if (index("#;:", *p))
|
|
|
|
continue;
|
|
|
|
(void) Tinsert(&lastT, p, FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) fclose(f);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
refuseT = NULL;
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) sprintf(buf, FILEREFUSE, collname);
|
|
|
|
f = fopen(buf, "r");
|
1993-05-21 18:52:16 +04:00
|
|
|
if (f) {
|
2002-07-11 00:19:38 +04:00
|
|
|
while ((p = fgets(buf, STRINGLENGTH, f))) {
|
|
|
|
if ((q = index(p, '\n')))
|
|
|
|
*q = '\0';
|
|
|
|
if (index("#;:", *p))
|
|
|
|
continue;
|
|
|
|
(void) Tinsert(&refuseT, p, FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) fclose(f);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Requesting changes since %s", ctime(&lasttime) + 4);
|
|
|
|
x = msgrefuse();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error sending refuse list to file server");
|
1993-05-21 18:52:16 +04:00
|
|
|
listT = NULL;
|
2002-07-11 00:19:38 +04:00
|
|
|
x = msglist();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error reading file list from file server");
|
|
|
|
if (thisC->Cprefix)
|
|
|
|
(void) chdir(thisC->Cprefix);
|
1993-05-21 18:52:16 +04:00
|
|
|
needT = NULL;
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) Tprocess(listT, needone, NULL);
|
|
|
|
Tfree(&listT);
|
|
|
|
x = msgneed();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error sending needed files list to file server");
|
|
|
|
Tfree(&needT);
|
1993-05-21 18:52:16 +04:00
|
|
|
denyT = NULL;
|
2002-07-11 00:19:38 +04:00
|
|
|
x = msgdeny();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error reading denied files list from file server");
|
|
|
|
if (thisC->Cflags & CFVERBOSE)
|
|
|
|
(void) Tprocess(denyT, denyone, NULL);
|
|
|
|
Tfree(&denyT);
|
|
|
|
if (thisC->Cflags & (CFALL | CFDELETE | CFOLD))
|
|
|
|
(void) Trprocess(lastT, deleteone, NULL);
|
|
|
|
Tfree(&refuseT);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
static int
|
|
|
|
needone(TREE * t, void *dummy)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
TREE *newt;
|
|
|
|
int exists, fetch;
|
1993-05-21 18:52:16 +04:00
|
|
|
struct stat sbuf;
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
newt = Tinsert(&lastT, t->Tname, TRUE);
|
1993-05-21 18:52:16 +04:00
|
|
|
newt->Tflags |= FUPDATE;
|
|
|
|
fetch = TRUE;
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFALL) == 0) {
|
|
|
|
if ((t->Tflags & FNEW) == 0 && (thisC->Cflags & CFOLD) == 0)
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
1997-10-19 23:53:54 +04:00
|
|
|
if (S_ISLNK(t->Tmode))
|
2002-07-11 00:19:38 +04:00
|
|
|
exists = (lstat(t->Tname, &sbuf) == 0);
|
1993-05-21 18:52:16 +04:00
|
|
|
else
|
2002-07-11 00:19:38 +04:00
|
|
|
exists = (stat(t->Tname, &sbuf) == 0);
|
|
|
|
/* This is moderately complicated: If the file is the wrong
|
|
|
|
* type or doesn't exist, we need to fetch the whole file. If
|
|
|
|
* the file is a special file, we rely solely on the server:
|
|
|
|
* if the file changed, we do an update; otherwise nothing. If
|
|
|
|
* the file is a normal file, we check timestamps. If we are
|
|
|
|
* in "keep" mode, we fetch if the file on the server is
|
|
|
|
* newer, and do nothing otherwise. Otherwise, we fetch if the
|
|
|
|
* timestamp is wrong; if the file changed on the server but
|
|
|
|
* the timestamp is right, we do an update. (Update refers to
|
|
|
|
* updating stat information, i.e. timestamp, owner, mode
|
|
|
|
* bits, etc.) */
|
|
|
|
if (exists && (sbuf.st_mode & S_IFMT) == (t->Tmode & S_IFMT)) {
|
1997-10-19 23:53:54 +04:00
|
|
|
if (!S_ISREG(t->Tmode))
|
2002-07-11 00:19:38 +04:00
|
|
|
if (t->Tflags & FNEW)
|
1993-05-21 18:52:16 +04:00
|
|
|
fetch = FALSE;
|
2002-07-11 00:19:38 +04:00
|
|
|
else
|
|
|
|
return (SCMOK);
|
|
|
|
else if ((thisC->Cflags & CFKEEP) &&
|
|
|
|
sbuf.st_mtime > t->Tmtime)
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
1998-08-28 00:31:00 +04:00
|
|
|
else if (sbuf.st_mtime == t->Tmtime) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (t->Tflags & FNEW)
|
1993-05-21 18:52:16 +04:00
|
|
|
fetch = FALSE;
|
2002-07-11 00:19:38 +04:00
|
|
|
else
|
|
|
|
return (SCMOK);
|
1998-08-28 00:31:00 +04:00
|
|
|
}
|
|
|
|
}
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
/* If we get this far, we're either doing an update or a full fetch. */
|
2002-07-11 00:19:38 +04:00
|
|
|
newt = Tinsert(&needT, t->Tname, TRUE);
|
1997-10-19 23:53:54 +04:00
|
|
|
if (!fetch && S_ISREG(t->Tmode))
|
1993-05-21 18:52:16 +04:00
|
|
|
newt->Tflags |= FUPDATE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
static int
|
|
|
|
denyone(TREE * t, void *v)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP: Access denied to %s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
static int
|
|
|
|
deleteone(TREE * t, void *v)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
1998-10-12 09:19:48 +04:00
|
|
|
struct stat sbuf, pbuf;
|
2002-07-11 00:19:38 +04:00
|
|
|
int x;
|
|
|
|
char *name = t->Tname;
|
1998-10-12 09:19:48 +04:00
|
|
|
char pname[MAXPATHLEN];
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if (t->Tflags & FUPDATE)/* in current upgrade list */
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
2002-07-11 00:19:38 +04:00
|
|
|
if (lstat(name, &sbuf) < 0) /* doesn't exist */
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
/* is it a symbolic link ? */
|
1997-10-19 23:53:54 +04:00
|
|
|
if (S_ISLNK(sbuf.st_mode)) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (Tlookup(refuseT, name)) {
|
|
|
|
vnotify("SUP Would not delete symbolic link %s\n",
|
|
|
|
name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would delete symbolic link %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFDELETE) == 0) {
|
|
|
|
notify("SUP Please delete symbolic link %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tflags |= FUPDATE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
x = unlink(name);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Unable to delete symbolic link %s\n",
|
|
|
|
name);
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tflags |= FUPDATE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Deleted symbolic link %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
/* is it a directory ? */
|
1997-10-19 23:53:54 +04:00
|
|
|
if (S_ISDIR(sbuf.st_mode)) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (Tlookup(refuseT, name)) {
|
|
|
|
vnotify("SUP Would not delete directory %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would delete directory %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFDELETE) == 0) {
|
|
|
|
notify("SUP Please delete directory %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tflags |= FUPDATE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (rmdir(name) < 0) {
|
|
|
|
(void) chmod(name, sbuf.st_mode | S_IRWXU);
|
1998-10-12 09:19:48 +04:00
|
|
|
if (strlen(name) < MAXPATHLEN - 3) {
|
2002-07-11 00:19:38 +04:00
|
|
|
sprintf(pname, "%s/..", name);
|
|
|
|
if (stat(pname, &pbuf) == 0)
|
|
|
|
(void) chmod(pname, pbuf.st_mode | S_IRWXU);
|
1998-10-12 09:19:48 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
runp("rm", "rm", "-rf", name, 0);
|
1998-09-12 11:36:49 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (lstat(name, &sbuf) == 0) {
|
|
|
|
notify("SUP: Unable to delete directory %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tflags |= FUPDATE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Deleted directory %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
/* it is a file */
|
2002-07-11 00:19:38 +04:00
|
|
|
if (Tlookup(refuseT, name)) {
|
|
|
|
vnotify("SUP Would not delete file %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would delete file %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFDELETE) == 0) {
|
|
|
|
notify("SUP Please delete file %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tflags |= FUPDATE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
x = unlink(name);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Unable to delete file %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
t->Tflags |= FUPDATE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Deleted file %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
/***************************************
|
|
|
|
*** R E C E I V E F I L E S ***
|
|
|
|
***************************************/
|
|
|
|
|
|
|
|
/* Note for these routines, return code SCMOK generally means
|
|
|
|
* NETWORK communication is OK; it does not mean that the current
|
|
|
|
* file was correctly received and stored. If a file gets messed
|
|
|
|
* up, too bad, just print a message and go on to the next one;
|
|
|
|
* but if the network gets messed up, the whole sup program loses
|
|
|
|
* badly and best just stop the program as soon as possible.
|
|
|
|
*/
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
void
|
|
|
|
recvfiles(void)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
int x;
|
1993-05-21 18:52:16 +04:00
|
|
|
int recvmore;
|
|
|
|
|
1993-08-04 21:46:14 +04:00
|
|
|
/* Does the protocol support compression */
|
|
|
|
if (cancompress) {
|
|
|
|
/* Check for compression on sending files */
|
2002-07-11 00:19:38 +04:00
|
|
|
docompress = (thisC->Cflags & CFCOMPRESS);
|
1993-08-04 21:46:14 +04:00
|
|
|
x = msgcompress();
|
2002-07-11 00:19:38 +04:00
|
|
|
if (x != SCMOK)
|
|
|
|
goaway("Error sending compression check to server");
|
1993-08-04 21:46:14 +04:00
|
|
|
if (docompress)
|
|
|
|
vnotify("SUP Using compressed file transfer\n");
|
|
|
|
}
|
1993-05-21 18:52:16 +04:00
|
|
|
recvmore = TRUE;
|
|
|
|
upgradeT = NULL;
|
|
|
|
do {
|
2002-07-11 00:19:38 +04:00
|
|
|
x = msgsend();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error sending receive file request to file server");
|
|
|
|
(void) Tinsert(&upgradeT, (char *) NULL, FALSE);
|
|
|
|
x = msgrecv(recvone, &recvmore);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Error receiving file from file server");
|
|
|
|
Tfree(&upgradeT);
|
1993-05-21 18:52:16 +04:00
|
|
|
} while (recvmore);
|
|
|
|
}
|
|
|
|
/* prepare the target, if necessary */
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
prepare(char *name, int mode, int *newp, struct stat * statp)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
char *type;
|
1998-10-12 09:19:48 +04:00
|
|
|
char pname[MAXPATHLEN];
|
|
|
|
struct stat pbuf;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
|
|
|
if (mode == S_IFLNK)
|
2002-07-11 00:19:38 +04:00
|
|
|
*newp = (lstat(name, statp) < 0);
|
1993-05-21 18:52:16 +04:00
|
|
|
else
|
2002-07-11 00:19:38 +04:00
|
|
|
*newp = (stat(name, statp) < 0);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (*newp) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST)
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
2002-07-11 00:19:38 +04:00
|
|
|
if (establishdir(name))
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (mode == (statp->st_mode & S_IFMT))
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
*newp = TRUE;
|
2002-07-11 00:19:38 +04:00
|
|
|
switch (statp->st_mode & S_IFMT) {
|
1993-05-21 18:52:16 +04:00
|
|
|
case S_IFDIR:
|
|
|
|
type = "directory";
|
|
|
|
break;
|
|
|
|
case S_IFLNK:
|
|
|
|
type = "symbolic link";
|
|
|
|
break;
|
|
|
|
case S_IFREG:
|
|
|
|
type = "regular file";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "unknown file";
|
|
|
|
break;
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would remove %s %s\n", type, name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
1997-10-19 23:53:54 +04:00
|
|
|
if (S_ISDIR(statp->st_mode)) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (rmdir(name) < 0) {
|
|
|
|
(void) chmod(name, statp->st_mode | S_IRWXU);
|
1998-10-12 09:19:48 +04:00
|
|
|
if (strlen(name) < MAXPATHLEN - 3) {
|
2002-07-11 00:19:38 +04:00
|
|
|
sprintf(pname, "%s/..", name);
|
|
|
|
if (stat(pname, &pbuf) == 0)
|
|
|
|
(void) chmod(pname, pbuf.st_mode | S_IRWXU);
|
1998-10-12 09:19:48 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
runp("rm", "rm", "-rf", name, 0);
|
1998-10-12 09:19:48 +04:00
|
|
|
}
|
1993-05-21 18:52:16 +04:00
|
|
|
} else
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) unlink(name);
|
|
|
|
if (stat(name, statp) < 0) {
|
|
|
|
vnotify("SUP Removed %s %s\n", type, name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Couldn't remove %s %s\n", type, name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
1996-12-31 21:08:00 +03:00
|
|
|
static int
|
2002-07-11 00:19:38 +04:00
|
|
|
recvone(TREE * t, va_list ap)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
1996-12-23 22:42:01 +03:00
|
|
|
int x = 0;
|
1993-05-21 18:52:16 +04:00
|
|
|
int new;
|
|
|
|
struct stat sbuf;
|
1996-12-31 21:08:00 +03:00
|
|
|
int *recvmore;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
1996-12-31 21:08:00 +03:00
|
|
|
recvmore = va_arg(ap, int *);
|
1993-05-21 18:52:16 +04:00
|
|
|
/* check for end of file list */
|
|
|
|
if (t == NULL) {
|
|
|
|
*recvmore = FALSE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
/* check for failed access at fileserver */
|
|
|
|
if (t->Tmode == 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: File server unable to transfer file %s\n",
|
|
|
|
t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
thisC->Cnogood = TRUE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (prepare(t->Tname, t->Tmode & S_IFMT, &new, &sbuf)) {
|
|
|
|
notify("SUP: Can't prepare path for %s\n", t->Tname);
|
1997-10-19 23:53:54 +04:00
|
|
|
if (S_ISREG(t->Tmode)) {
|
2002-07-11 00:19:38 +04:00
|
|
|
x = readskip(); /* skip over file */
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Can't skip file transfer");
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
thisC->Cnogood = TRUE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
/* make file mode specific changes */
|
2002-07-11 00:19:38 +04:00
|
|
|
switch (t->Tmode & S_IFMT) {
|
1993-05-21 18:52:16 +04:00
|
|
|
case S_IFDIR:
|
2002-07-11 00:19:38 +04:00
|
|
|
x = recvdir(t, new, &sbuf);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case S_IFLNK:
|
2002-07-11 00:19:38 +04:00
|
|
|
x = recvsym(t, new, &sbuf);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
case S_IFREG:
|
2002-07-11 00:19:38 +04:00
|
|
|
x = recvreg(t, new, &sbuf);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
default:
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Unknown file type %o\n", t->Tmode & S_IFMT);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
if (x) {
|
|
|
|
thisC->Cnogood = TRUE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
1997-10-19 23:53:54 +04:00
|
|
|
if (S_ISREG(t->Tmode))
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) Tprocess(t->Tlink, linkone, t->Tname);
|
|
|
|
(void) Tprocess(t->Texec, execone, NULL);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
recvdir(TREE * t, int new, struct stat * statp)
|
|
|
|
{ /* receive directory from network */
|
1993-05-21 18:52:16 +04:00
|
|
|
struct timeval tbuf[2];
|
|
|
|
|
|
|
|
if (new) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would create directory %s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
1997-06-18 19:23:52 +04:00
|
|
|
if (makedir(t->Tname, 0755, statp) == -1) {
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP: Can't create directory %s\n", t->Tname);
|
1997-06-18 19:23:52 +04:00
|
|
|
return TRUE;
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((t->Tflags & FNOACCT) == 0) {
|
1993-05-21 18:52:16 +04:00
|
|
|
/* convert user and group names to local ids */
|
2002-07-11 00:19:38 +04:00
|
|
|
ugconvert(t->Tuser, t->Tgroup, &t->Tuid, &t->Tgid, &t->Tmode);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (!new && (t->Tflags & FNEW) == 0 && statp->st_mtime == t->Tmtime) {
|
|
|
|
if (t->Tflags & FNOACCT)
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
if (statp->st_uid == t->Tuid && statp->st_gid == t->Tgid)
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would update directory %s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((t->Tflags & FNOACCT) == 0) {
|
|
|
|
(void) chown(t->Tname, t->Tuid, t->Tgid);
|
|
|
|
(void) chmod(t->Tname, t->Tmode & S_IMODE);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
tbuf[0].tv_sec = time((time_t *) NULL);
|
|
|
|
tbuf[0].tv_usec = 0;
|
|
|
|
tbuf[1].tv_sec = t->Tmtime;
|
|
|
|
tbuf[1].tv_usec = 0;
|
1999-06-17 09:11:47 +04:00
|
|
|
if (!noutime)
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) utimes(t->Tname, tbuf);
|
|
|
|
vnotify("SUP %s directory %s\n", new ? "Created" : "Updated", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
recvsym(TREE * t, int new, struct stat * statp)
|
|
|
|
{ /* receive symbolic link */
|
1993-05-21 18:52:16 +04:00
|
|
|
char buf[STRINGLENGTH];
|
|
|
|
int n;
|
2002-07-11 00:19:38 +04:00
|
|
|
char *linkname;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
|
|
|
if (t->Tlink == NULL || t->Tlink->Tname == NULL) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Missing linkname for symbolic link %s\n",
|
|
|
|
t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
linkname = t->Tlink->Tname;
|
2002-07-11 00:19:38 +04:00
|
|
|
if (!new && (t->Tflags & FNEW) == 0 &&
|
|
|
|
(n = readlink(t->Tname, buf, sizeof(buf))) >= 0 &&
|
|
|
|
(n == strlen(linkname)) && (strncmp(linkname, buf, n) == 0))
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would %s symbolic link %s to %s\n",
|
|
|
|
new ? "create" : "update", t->Tname, linkname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
if (!new)
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) unlink(t->Tname);
|
|
|
|
if (symlink(linkname, t->Tname) < 0 || lstat(t->Tname, statp) < 0) {
|
|
|
|
notify("SUP: Unable to create symbolic link %s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Created symbolic link %s to %s\n", t->Tname, linkname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
recvreg(TREE * t, int new, struct stat * statp)
|
|
|
|
{ /* receive file from network */
|
|
|
|
FILE *fin, *fout;
|
|
|
|
char dirpart[STRINGLENGTH], filepart[STRINGLENGTH];
|
|
|
|
char filename[STRINGLENGTH], buf[STRINGLENGTH];
|
1993-05-21 18:52:16 +04:00
|
|
|
struct timeval tbuf[2];
|
2002-07-11 00:19:38 +04:00
|
|
|
int x;
|
|
|
|
char *p;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if (t->Tflags & FUPDATE) {
|
|
|
|
if ((t->Tflags & FNOACCT) == 0) {
|
1993-05-21 18:52:16 +04:00
|
|
|
/* convert user and group names to local ids */
|
2002-07-11 00:19:38 +04:00
|
|
|
ugconvert(t->Tuser, t->Tgroup, &t->Tuid, &t->Tgid,
|
|
|
|
&t->Tmode);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (!new && (t->Tflags & FNEW) == 0 &&
|
1993-05-21 18:52:16 +04:00
|
|
|
statp->st_mtime == t->Tmtime) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (t->Tflags & FNOACCT)
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
if (statp->st_uid == t->Tuid &&
|
|
|
|
statp->st_gid == t->Tgid)
|
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would update file %s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Updating file %s\n", t->Tname);
|
|
|
|
if ((t->Tflags & FNOACCT) == 0) {
|
|
|
|
(void) chown(t->Tname, t->Tuid, t->Tgid);
|
|
|
|
(void) chmod(t->Tname, t->Tmode & S_IMODE);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
tbuf[0].tv_sec = time((time_t *) NULL);
|
|
|
|
tbuf[0].tv_usec = 0;
|
|
|
|
tbuf[1].tv_sec = t->Tmtime;
|
|
|
|
tbuf[1].tv_usec = 0;
|
1999-06-17 09:11:47 +04:00
|
|
|
if (!noutime)
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) utimes(t->Tname, tbuf);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
1993-05-21 18:52:16 +04:00
|
|
|
if (new)
|
|
|
|
p = "create";
|
|
|
|
else if (statp->st_mtime < t->Tmtime)
|
|
|
|
p = "receive new";
|
|
|
|
else if (statp->st_mtime > t->Tmtime)
|
|
|
|
p = "receive old";
|
|
|
|
else
|
|
|
|
p = "receive";
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Would %s file %s\n", p, t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Receiving file %s\n", t->Tname);
|
1997-10-19 23:53:54 +04:00
|
|
|
if (!new && S_ISREG(t->Tmode) &&
|
2002-07-11 00:19:38 +04:00
|
|
|
(t->Tflags & FBACKUP) && (thisC->Cflags & CFBACKUP)) {
|
|
|
|
fin = fopen(t->Tname, "r"); /* create backup */
|
1993-05-21 18:52:16 +04:00
|
|
|
if (fin == NULL) {
|
2002-07-11 00:19:38 +04:00
|
|
|
x = readskip(); /* skip over file */
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Can't skip file transfer");
|
|
|
|
notify("SUP: Can't open %s to create backup\n",
|
|
|
|
t->Tname);
|
|
|
|
return (TRUE); /* mark upgrade as nogood */
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
path(t->Tname, dirpart, filepart);
|
|
|
|
(void) sprintf(filename, FILEBACKUP, dirpart, filepart);
|
|
|
|
fout = fopen(filename, "w");
|
1993-05-21 18:52:16 +04:00
|
|
|
if (fout == NULL) {
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) sprintf(buf, FILEBKDIR, dirpart);
|
|
|
|
(void) mkdir(buf, 0755);
|
|
|
|
fout = fopen(filename, "w");
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
if (fout == NULL) {
|
2002-07-11 00:19:38 +04:00
|
|
|
x = readskip(); /* skip over file */
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Can't skip file transfer");
|
|
|
|
notify("SUP: Can't create %s for backup\n", filename);
|
|
|
|
(void) fclose(fin);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
ffilecopy(fin, fout);
|
|
|
|
(void) fclose(fin);
|
|
|
|
(void) fclose(fout);
|
|
|
|
vnotify("SUP Backup of %s created\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
x = copyfile(t->Tname, (char *) NULL);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x)
|
|
|
|
return (TRUE);
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((t->Tflags & FNOACCT) == 0) {
|
1993-05-21 18:52:16 +04:00
|
|
|
/* convert user and group names to local ids */
|
2002-07-11 00:19:38 +04:00
|
|
|
ugconvert(t->Tuser, t->Tgroup, &t->Tuid, &t->Tgid, &t->Tmode);
|
|
|
|
(void) chown(t->Tname, t->Tuid, t->Tgid);
|
|
|
|
(void) chmod(t->Tname, t->Tmode & S_IMODE);
|
|
|
|
}
|
|
|
|
tbuf[0].tv_sec = time((time_t *) NULL);
|
|
|
|
tbuf[0].tv_usec = 0;
|
|
|
|
tbuf[1].tv_sec = t->Tmtime;
|
|
|
|
tbuf[1].tv_usec = 0;
|
1999-06-17 09:11:47 +04:00
|
|
|
if (!noutime)
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) utimes(t->Tname, tbuf);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
static int
|
|
|
|
linkone(TREE * t, void *fv)
|
|
|
|
{ /* link to file already received */
|
|
|
|
char *fname = fv;
|
|
|
|
struct stat fbuf, sbuf;
|
|
|
|
char *name = t->Tname;
|
|
|
|
int new, x;
|
1993-05-21 18:52:16 +04:00
|
|
|
char *type;
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if (stat(fname, &fbuf) < 0) { /* source file */
|
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would link %s to %s\n", name, fname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Can't link %s to missing file %s\n", name, fname);
|
1993-05-21 18:52:16 +04:00
|
|
|
thisC->Cnogood = TRUE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (prepare(name, S_IFREG, &new, &sbuf)) {
|
|
|
|
notify("SUP: Can't prepare path for link %s\n", name);
|
1993-05-21 18:52:16 +04:00
|
|
|
thisC->Cnogood = TRUE;
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (!new && (t->Tflags & FNEW) == 0 &&
|
1993-05-21 18:52:16 +04:00
|
|
|
fbuf.st_dev == sbuf.st_dev && fbuf.st_ino == sbuf.st_ino)
|
|
|
|
return (SCMOK);
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would link %s to %s\n", name, fname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) unlink(name);
|
1993-05-21 18:52:16 +04:00
|
|
|
type = "";
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((x = link(fname, name)) < 0) {
|
1993-05-21 18:52:16 +04:00
|
|
|
type = "symbolic ";
|
2002-07-11 00:19:38 +04:00
|
|
|
x = symlink(fname, name);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (x < 0 || lstat(name, &sbuf) < 0) {
|
|
|
|
notify("SUP: Unable to create %slink %s\n", type, name);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Created %slink %s to %s\n", type, name, fname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
static int
|
|
|
|
execone(TREE * t, void *v)
|
|
|
|
{ /* execute command for file */
|
1996-09-05 20:50:01 +04:00
|
|
|
int w;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
vnotify("SUP Would execute %s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFEXECUTE) == 0) {
|
|
|
|
notify("SUP Please execute %s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
vnotify("SUP Executing %s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
w = system(t->Tname);
|
1996-09-05 20:50:01 +04:00
|
|
|
if (WIFEXITED(w) && WEXITSTATUS(w) != 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Execute command returned failure status %#o\n",
|
|
|
|
WEXITSTATUS(w));
|
1993-05-21 18:52:16 +04:00
|
|
|
thisC->Cnogood = TRUE;
|
|
|
|
} else if (WIFSIGNALED(w)) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Execute command killed by signal %d\n",
|
|
|
|
WTERMSIG(w));
|
1993-05-21 18:52:16 +04:00
|
|
|
thisC->Cnogood = TRUE;
|
|
|
|
} else if (WIFSTOPPED(w)) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Execute command stopped by signal %d\n",
|
|
|
|
WSTOPSIG(w));
|
1993-05-21 18:52:16 +04:00
|
|
|
thisC->Cnogood = TRUE;
|
|
|
|
}
|
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
|
2002-07-11 01:28:13 +04:00
|
|
|
/* from will be 0 if reading from network */
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
copyfile(char *to, char *from)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
int fromf, tof, istemp, x;
|
|
|
|
char dpart[STRINGLENGTH], fpart[STRINGLENGTH];
|
1993-05-21 18:52:16 +04:00
|
|
|
char tname[STRINGLENGTH];
|
2002-07-11 01:28:13 +04:00
|
|
|
static int returntrue = 1;
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
static int thispid = 0; /* process id # */
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if (from) { /* reading file */
|
|
|
|
fromf = open(from, O_RDONLY, 0);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (fromf < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Can't open %s to copy to %s: %s\n",
|
|
|
|
from, to, errmsg(-1));
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
} else /* reading network */
|
1993-05-21 18:52:16 +04:00
|
|
|
fromf = -1;
|
2002-07-11 00:19:38 +04:00
|
|
|
istemp = TRUE; /* try to create temp file */
|
|
|
|
lockout(TRUE); /* block interrupts */
|
|
|
|
if (thispid == 0)
|
|
|
|
thispid = getpid();
|
1993-05-21 18:52:16 +04:00
|
|
|
/* Now try hard to find a temp file name. Try VERY hard. */
|
|
|
|
for (;;) {
|
2002-07-11 00:19:38 +04:00
|
|
|
/* try destination directory */
|
|
|
|
path(to, dpart, fpart);
|
|
|
|
(void) sprintf(tname, "%s/#%d.sup", dpart, thispid);
|
|
|
|
tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC), 0600);
|
|
|
|
if (tof >= 0)
|
|
|
|
break;
|
|
|
|
/* try sup directory */
|
|
|
|
if (thisC->Cprefix)
|
|
|
|
(void) chdir(thisC->Cbase);
|
|
|
|
(void) sprintf(tname, "sup/#%d.sup", thispid);
|
|
|
|
tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC), 0600);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (tof >= 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cprefix)
|
|
|
|
(void) chdir(thisC->Cprefix);
|
1993-05-21 18:52:16 +04:00
|
|
|
break;
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
/* try base directory */
|
|
|
|
(void) sprintf(tname, "#%d.sup", thispid);
|
|
|
|
tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC), 0600);
|
|
|
|
if (thisC->Cprefix)
|
|
|
|
(void) chdir(thisC->Cprefix);
|
|
|
|
if (tof >= 0)
|
|
|
|
break;
|
1993-05-24 22:57:48 +04:00
|
|
|
#ifdef VAR_TMP
|
2002-07-11 00:19:38 +04:00
|
|
|
/* try /var/tmp */
|
|
|
|
(void) sprintf(tname, "/var/tmp/#%d.sup", thispid);
|
|
|
|
tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC), 0600);
|
|
|
|
if (tof >= 0)
|
|
|
|
break;
|
1993-05-24 22:57:48 +04:00
|
|
|
#else
|
2002-07-11 00:19:38 +04:00
|
|
|
/* try /usr/tmp */
|
|
|
|
(void) sprintf(tname, "/usr/tmp/#%d.sup", thispid);
|
|
|
|
tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC), 0600);
|
|
|
|
if (tof >= 0)
|
|
|
|
break;
|
1993-05-24 22:57:48 +04:00
|
|
|
#endif
|
2002-07-11 00:19:38 +04:00
|
|
|
/* try /tmp */
|
|
|
|
(void) sprintf(tname, "/tmp/#%d.sup", thispid);
|
|
|
|
tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC), 0600);
|
|
|
|
if (tof >= 0)
|
|
|
|
break;
|
1993-05-21 18:52:16 +04:00
|
|
|
istemp = FALSE;
|
2002-07-11 00:19:38 +04:00
|
|
|
/* give up: try to create output file */
|
1993-08-04 21:46:14 +04:00
|
|
|
if (!docompress)
|
2002-07-11 00:19:38 +04:00
|
|
|
tof = open(to, (O_WRONLY | O_CREAT | O_TRUNC), 0600);
|
|
|
|
if (tof >= 0)
|
|
|
|
break;
|
|
|
|
/* no luck */
|
|
|
|
notify("SUP: Can't create %s or temp file for it\n", to);
|
|
|
|
lockout(FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (fromf >= 0)
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) close(fromf);
|
1993-05-21 18:52:16 +04:00
|
|
|
else {
|
2002-07-11 00:19:38 +04:00
|
|
|
x = readskip();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Can't skip file transfer");
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 01:28:13 +04:00
|
|
|
if (returntrue)
|
1996-12-23 22:42:01 +03:00
|
|
|
return (TRUE);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (fromf >= 0) { /* read file */
|
|
|
|
x = filecopy(fromf, tof);
|
|
|
|
(void) close(fromf);
|
|
|
|
(void) close(tof);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Error in copying %s to %s\n", from, to);
|
|
|
|
if (istemp)
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
} else { /* read network */
|
1993-05-21 18:52:16 +04:00
|
|
|
#if MACH
|
|
|
|
if (!rpauseflag) {
|
|
|
|
int fsize;
|
|
|
|
struct fsparam fsp;
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
x = prereadcount(&fsize);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (istemp)
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
|
|
|
x = readskip();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Can't skip file transfer");
|
|
|
|
goaway("Error in server space check");
|
|
|
|
logquit(1, "Error in server space check");
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
errno = 0;
|
2002-07-11 00:19:38 +04:00
|
|
|
if (ioctl(tof, FIOCFSPARAM, (char *) &fsp) < 0 &&
|
1993-05-21 18:52:16 +04:00
|
|
|
errno != EINVAL) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (istemp)
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
|
|
|
x = readskip();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Can't skip file transfer");
|
|
|
|
goaway("Error in disk space check");
|
|
|
|
logquit(1, "Error in disk space check");
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
if (errno == 0) {
|
|
|
|
fsize = (fsize + 1023) / 1024;
|
2002-07-11 00:19:38 +04:00
|
|
|
x = fsp.fsp_size * MAX(fsp.fsp_minfree, 1) / 100;
|
1993-05-21 18:52:16 +04:00
|
|
|
fsp.fsp_free -= x;
|
2002-07-11 00:19:38 +04:00
|
|
|
if (fsize > MAX(fsp.fsp_free, 0)) {
|
|
|
|
if (istemp)
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
|
|
|
x = readskip();
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Can't skip file transfer");
|
|
|
|
goaway("No disk space for file %s", to);
|
|
|
|
logquit(1, "No disk space for file %s", to);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
#endif /* MACH */
|
|
|
|
x = readfile(tof);
|
|
|
|
(void) close(tof);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK) {
|
2002-07-11 00:19:38 +04:00
|
|
|
if (istemp)
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
|
|
|
goaway("Error in receiving %s\n", to);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (!istemp) { /* no temp file used */
|
|
|
|
lockout(FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
1997-07-15 22:15:55 +04:00
|
|
|
/*
|
|
|
|
** If the file is compressed, uncompress it in place. We open the
|
|
|
|
** temp file for reading, unlink the file, and then open the same
|
2002-07-11 00:19:38 +04:00
|
|
|
** file again for writing. Then we pipe through gzip. When
|
1997-07-15 22:15:55 +04:00
|
|
|
** finished the temp file contains the uncompressed version and we
|
|
|
|
** can continue as before.
|
|
|
|
**
|
|
|
|
** Since sup prefers to write close to the original file the
|
|
|
|
** benefits of atomic updates probably outweigh the cost of the
|
|
|
|
** extra filecopy which occurs when the temp file is on a different
|
|
|
|
** filesystem from the original.
|
|
|
|
*/
|
1993-08-04 21:46:14 +04:00
|
|
|
if (docompress) {
|
1995-06-24 20:21:33 +04:00
|
|
|
char *av[4];
|
2002-07-11 00:19:38 +04:00
|
|
|
int ac = 0;
|
|
|
|
int infd = -1;
|
|
|
|
int outfd = -1;
|
1995-06-24 20:21:33 +04:00
|
|
|
av[ac++] = "gzip";
|
|
|
|
av[ac++] = "-d";
|
|
|
|
av[ac++] = NULL;
|
2002-08-09 15:06:43 +04:00
|
|
|
if ((infd = open(tname, O_RDONLY, 0)) == -1 ||
|
2002-07-11 00:19:38 +04:00
|
|
|
unlink(tname) == -1 ||
|
|
|
|
(outfd = open(tname, O_WRONLY | O_CREAT | O_TRUNC)) == -1 ||
|
|
|
|
runiofd(av, infd, outfd, 2) != 0) {
|
1997-07-15 22:15:55 +04:00
|
|
|
notify("SUP: Error in uncompressing file %s (%s)\n",
|
2002-07-11 00:19:38 +04:00
|
|
|
to, tname);
|
|
|
|
(void) unlink(tname);
|
|
|
|
if (infd != -1)
|
|
|
|
(void) close(infd);
|
|
|
|
if (outfd != -1)
|
|
|
|
(void) close(outfd);
|
1997-07-15 22:15:55 +04:00
|
|
|
lockout(FALSE);
|
2002-07-11 00:19:38 +04:00
|
|
|
return (TRUE);
|
1993-08-04 21:46:14 +04:00
|
|
|
}
|
1997-07-15 22:15:55 +04:00
|
|
|
(void) close(infd);
|
|
|
|
(void) close(outfd);
|
1993-08-04 21:46:14 +04:00
|
|
|
}
|
1993-05-21 18:52:16 +04:00
|
|
|
/* move to destination */
|
2002-07-11 00:19:38 +04:00
|
|
|
if (rename(tname, to) == 0) {
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (FALSE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
fromf = open(tname, O_RDONLY, 0);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (fromf < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Error in moving temp file to %s: %s\n",
|
|
|
|
to, errmsg(-1));
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
tof = open(to, (O_WRONLY | O_CREAT | O_TRUNC), 0600);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (tof < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) close(fromf);
|
|
|
|
notify("SUP: Can't create %s from temp file: %s\n",
|
|
|
|
to, errmsg(-1));
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
x = filecopy(fromf, tof);
|
|
|
|
(void) close(fromf);
|
|
|
|
(void) close(tof);
|
|
|
|
(void) unlink(tname);
|
|
|
|
lockout(FALSE);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x < 0) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Error in storing data in %s\n", to);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
/*** Finish connection with file server ***/
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
void
|
|
|
|
finishup(int x)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
2002-07-11 00:19:38 +04:00
|
|
|
char tname[STRINGLENGTH], fname[STRINGLENGTH];
|
1993-05-21 18:52:16 +04:00
|
|
|
char relsufix[STRINGLENGTH];
|
|
|
|
char collrelname[STRINGLENGTH];
|
1996-12-31 21:08:00 +03:00
|
|
|
time_t tloc;
|
2002-07-11 00:19:38 +04:00
|
|
|
FILE *finishfile; /* record of all filenames */
|
1993-05-21 18:52:16 +04:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFURELSUF) && release) {
|
|
|
|
(void) sprintf(relsufix, ".%s", release);
|
|
|
|
(void) sprintf(collrelname, "%s-%s", collname, release);
|
1993-05-21 18:52:16 +04:00
|
|
|
} else {
|
|
|
|
relsufix[0] = '\0';
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) strcpy(collrelname, collname);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
dontjump = TRUE; /* once here, no more longjmp */
|
|
|
|
(void) netcrypt((char *) NULL);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (protver < 6) {
|
|
|
|
/* done with server */
|
|
|
|
if (x == SCMOK)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway((char *) NULL);
|
|
|
|
(void) requestend();
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
tloc = time((time_t *) NULL);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (x != SCMOK) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Upgrade of %s aborted at %s",
|
|
|
|
collrelname, ctime(&tloc) + 4);
|
|
|
|
Tfree(&lastT);
|
|
|
|
if (protver < 6)
|
|
|
|
return;
|
1993-05-21 18:52:16 +04:00
|
|
|
/* if we've not been blown off, make sure he is! */
|
|
|
|
if (x != SCMEOF)
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway("Aborted");
|
|
|
|
(void) requestend();
|
1993-05-21 18:52:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (thisC->Cnogood) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Upgrade of %s completed with errors at %s",
|
|
|
|
collrelname, ctime(&tloc) + 4);
|
|
|
|
notify("SUP: Upgrade time will not be updated\n");
|
|
|
|
Tfree(&lastT);
|
|
|
|
if (protver < 6)
|
|
|
|
return;
|
|
|
|
done(FDONEUSRERROR, "Completed with errors");
|
|
|
|
(void) requestend();
|
1993-05-21 18:52:16 +04:00
|
|
|
return;
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
if (thisC->Cprefix)
|
|
|
|
(void) chdir(thisC->Cbase);
|
|
|
|
vnotify("SUP Upgrade of %s completed at %s",
|
|
|
|
collrelname, ctime(&tloc) + 4);
|
|
|
|
if (thisC->Cflags & CFLIST) {
|
|
|
|
Tfree(&lastT);
|
|
|
|
if (protver < 6)
|
|
|
|
return;
|
|
|
|
done(FDONEDONTLOG, "List only");
|
|
|
|
(void) requestend();
|
1993-05-21 18:52:16 +04:00
|
|
|
return;
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) sprintf(fname, FILEWHEN, collname, relsufix);
|
|
|
|
if (establishdir(fname)) {
|
|
|
|
notify("SUP: Can't create directory for upgrade timestamp\n");
|
|
|
|
Tfree(&lastT);
|
|
|
|
if (protver < 6)
|
|
|
|
return;
|
|
|
|
done(FDONEUSRERROR, "Couldn't timestamp");
|
|
|
|
(void) requestend();
|
1993-05-21 18:52:16 +04:00
|
|
|
return;
|
|
|
|
}
|
1995-06-04 01:21:48 +04:00
|
|
|
if (!putwhen(fname, scantime)) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Can't record current time in %s: %s\n",
|
|
|
|
fname, errmsg(-1));
|
|
|
|
Tfree(&lastT);
|
|
|
|
if (protver < 6)
|
|
|
|
return;
|
|
|
|
done(FDONEUSRERROR, "Couldn't timestamp");
|
|
|
|
(void) requestend();
|
1993-05-21 18:52:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (protver >= 6) {
|
|
|
|
/* At this point we have let the server go */
|
|
|
|
/* "I'm sorry, we've had to let you go" */
|
2002-07-11 00:19:38 +04:00
|
|
|
done(FDONESUCCESS, "Success");
|
|
|
|
(void) requestend();
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) sprintf(tname, FILELASTTEMP, collname, relsufix);
|
|
|
|
finishfile = fopen(tname, "w");
|
1993-05-21 18:52:16 +04:00
|
|
|
if (finishfile == NULL) {
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: Can't record list of all files in %s\n", tname);
|
|
|
|
Tfree(&lastT);
|
1993-05-21 18:52:16 +04:00
|
|
|
return;
|
|
|
|
}
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) Tprocess(lastT, finishone, finishfile);
|
|
|
|
(void) fclose(finishfile);
|
|
|
|
(void) sprintf(fname, FILELAST, collname, relsufix);
|
|
|
|
if (rename(tname, fname) < 0)
|
|
|
|
notify("SUP: Can't change %s to %s\n", tname, fname);
|
|
|
|
(void) unlink(tname);
|
|
|
|
Tfree(&lastT);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
int
|
|
|
|
finishone(TREE * t, void *fv)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
1996-12-23 22:42:01 +03:00
|
|
|
FILE *finishfile = fv;
|
2002-07-11 00:19:38 +04:00
|
|
|
if ((thisC->Cflags & CFDELETE) == 0 || (t->Tflags & FUPDATE))
|
|
|
|
fprintf(finishfile, "%s\n", t->Tname);
|
1993-05-21 18:52:16 +04:00
|
|
|
return (SCMOK);
|
|
|
|
}
|
|
|
|
|
1996-12-23 22:42:01 +03:00
|
|
|
void
|
2002-07-11 00:19:38 +04:00
|
|
|
done(int value, char *fmt, ...)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
|
|
|
char buf[STRINGLENGTH];
|
|
|
|
va_list ap;
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
va_start(ap, fmt);
|
|
|
|
(void) netcrypt((char *) NULL);
|
1996-12-23 22:42:01 +03:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
if (fmt)
|
1993-05-21 18:52:16 +04:00
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
if (protver < 6) {
|
|
|
|
if (goawayreason)
|
2002-07-11 00:19:38 +04:00
|
|
|
free(goawayreason);
|
|
|
|
goawayreason = (fmt) ? salloc(buf) : (char *) NULL;
|
|
|
|
(void) msggoaway();
|
|
|
|
} else {
|
1993-05-21 18:52:16 +04:00
|
|
|
doneack = value;
|
2002-07-11 00:19:38 +04:00
|
|
|
donereason = (fmt) ? buf : (char *) NULL;
|
|
|
|
(void) msgdone();
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
|
|
|
if (!dontjump)
|
2002-07-11 00:19:38 +04:00
|
|
|
longjmp(sjbuf, TRUE);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|
1996-12-23 22:42:01 +03:00
|
|
|
|
|
|
|
void
|
2002-07-11 00:19:38 +04:00
|
|
|
goaway(char *fmt, ...)
|
1993-05-21 18:52:16 +04:00
|
|
|
{
|
|
|
|
char buf[STRINGLENGTH];
|
|
|
|
va_list ap;
|
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
va_start(ap, fmt);
|
1996-12-23 22:42:01 +03:00
|
|
|
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) netcrypt((char *) NULL);
|
1993-05-21 18:52:16 +04:00
|
|
|
if (fmt) {
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
goawayreason = buf;
|
|
|
|
} else
|
|
|
|
goawayreason = NULL;
|
|
|
|
va_end(ap);
|
2002-07-11 00:19:38 +04:00
|
|
|
(void) msggoaway();
|
1998-08-28 00:31:00 +04:00
|
|
|
if (fmt) {
|
1993-05-21 18:52:16 +04:00
|
|
|
if (thisC)
|
2002-07-11 00:19:38 +04:00
|
|
|
notify("SUP: %s\n", buf);
|
1993-05-21 18:52:16 +04:00
|
|
|
else
|
2002-07-11 00:19:38 +04:00
|
|
|
printf("SUP: %s\n", buf);
|
1998-08-28 00:31:00 +04:00
|
|
|
}
|
1993-05-21 18:52:16 +04:00
|
|
|
if (!dontjump)
|
2002-07-11 00:19:38 +04:00
|
|
|
longjmp(sjbuf, TRUE);
|
1993-05-21 18:52:16 +04:00
|
|
|
}
|