diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-05-02 22:56:55 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-05-02 22:56:55 +0000 |
commit | 9416d16e426d5f2f30f1f276fa0b4ffa6e776f9e (patch) | |
tree | 5d18654a85a57b6a946712a6a2935428d77ea9b2 | |
parent | ba1421ed3da4e432319f58cbf77df34d7e959f68 (diff) |
Sync with NetBSD. Notable changes:
o Add libwrap support to supfilesrv, conditioned by #ifdef LIBWRAP
(on by default). <bouyer@netbsd.org>
o Renamed '-l' (the 'live' mode) to '-d' and '-l' is now used to
enable logging of successfull connections. <bouyer@netbsd.org>
o Don't botch varargs: the are not always an array of void * in the stack...
Write a separate function to convert a list of function parameters to
explain why execv failed. <christos@netbsd.org>
o When in compress mode, don't overwrite the destination file directly,
write a temp file and use rename when it is done. (From James Mathiesen
<james@deshaw.com>)
o Rename errno variable to error to avoid collision with errno.h and remove
explicit extern of errno (we get it from errno.h) <mycroft@netbsd.org>
o Cleanup unsigned char vs. char
o Add -u flag, that prevents sup from attempting to restore a and m times
on the received files.
o Replace the provided read_line function with calls to the fparseln function
in libutil. Maintain compatibility on machines without fparseln through
the NEED_READ_LINE define.
o Rename login() to suplogin() to avoid name collition in util.h
o If rmdir() fails, chmod the path to have r/w/x perms and run "rm -rf"
o avoid last.temp filename collision by using rel-suffix
o When creating directories, make sure you remove previous non-directories
before doing so, otherwise sup fails.
o Add -q flag to supscan for quiet operation.
28 files changed, 634 insertions, 204 deletions
diff --git a/usr.bin/sup/Makefile.inc b/usr.bin/sup/Makefile.inc index 85cde2eb6bf..206b1f6a5e8 100644 --- a/usr.bin/sup/Makefile.inc +++ b/usr.bin/sup/Makefile.inc @@ -1,5 +1,5 @@ -# $OpenBSD: Makefile.inc,v 1.3 2000/08/20 18:42:41 millert Exp $ +# $OpenBSD: Makefile.inc,v 1.4 2001/05/02 22:56:52 millert Exp $ CFLAGS+=-UCMUCS -UCMU -UMACH -DVAR_TMP -DHAS_DAEMON -DHAS_POSIX_DIR \ - -DHAS_LOGIN_CAP + -DHAS_LOGIN_CAP -DLIBWRAP -DHAS_FPARSELN diff --git a/usr.bin/sup/src/errmsg.c b/usr.bin/sup/src/errmsg.c index fff4ca0bda9..d8e3e97fbb3 100644 --- a/usr.bin/sup/src/errmsg.c +++ b/usr.bin/sup/src/errmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: errmsg.c,v 1.5 2001/04/29 18:12:37 millert Exp $ */ +/* $OpenBSD: errmsg.c,v 1.6 2001/05/02 22:56:52 millert Exp $ */ /* * Copyright (c) 1991 Carnegie Mellon University @@ -50,7 +50,7 @@ unsigned n; } #endif -char *errmsg(cod) +const char *errmsg(cod) int cod; { #if !defined(__NetBSD__) && !defined(__OpenBSD__) diff --git a/usr.bin/sup/src/libc.h b/usr.bin/sup/src/libc.h index 94df059080b..502ed694da5 100644 --- a/usr.bin/sup/src/libc.h +++ b/usr.bin/sup/src/libc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libc.h,v 1.5 2001/04/29 21:52:14 millert Exp $ */ +/* $OpenBSD: libc.h,v 1.6 2001/05/02 22:56:52 millert Exp $ */ /* * Copyright (c) 1991 Carnegie Mellon University @@ -145,6 +145,7 @@ extern unsigned int gethex(const char*, unsigned int, unsigned int, extern unsigned int hexarg(const char**, const char*, const char*, unsigned int, unsigned int, unsigned int); extern unsigned int atoh(const char*); +extern char *salloc(const char*); extern char *concat(const char*, int, ...); #else /* __STDC__ */ extern char *foldup(), *folddown(); @@ -164,11 +165,11 @@ extern char *concat(); #if defined(__STDC__) extern char *getname(int); extern char *pathof(char *); -extern char *errmsg(int); +extern const char *errmsg(int); #else /* __STDC__ */ extern char *getname(); extern char *pathof(); -extern char *errmsg(); +extern const char *errmsg(); #endif /* __STDC__ */ /* CMU time additions */ diff --git a/usr.bin/sup/src/log.c b/usr.bin/sup/src/log.c index 5bebec22499..0a7be487cb3 100644 --- a/usr.bin/sup/src/log.c +++ b/usr.bin/sup/src/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.5 2001/04/29 21:52:14 millert Exp $ */ +/* $OpenBSD: log.c,v 1.6 2001/05/02 22:56:52 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -154,3 +154,82 @@ va_dcl printf ("%s\n",buf); (void) fflush (stdout); } + +#ifdef LIBWRAP +#include <tcpd.h> +#ifndef LIBWRAP_ALLOW_FACILITY +# define LIBWRAP_ALLOW_FACILITY LOG_AUTH +#endif +#ifndef LIBWRAP_ALLOW_SEVERITY +# define LIBWRAP_ALLOW_SEVERITY LOG_INFO +#endif +#ifndef LIBWRAP_DENY_FACILITY +# define LIBWRAP_DENY_FACILITY LOG_AUTH +#endif +#ifndef LIBWRAP_DENY_SEVERITY +# define LIBWRAP_DENY_SEVERITY LOG_WARNING +#endif +int allow_severity = LIBWRAP_ALLOW_FACILITY|LIBWRAP_ALLOW_SEVERITY; +int deny_severity = LIBWRAP_DENY_FACILITY|LIBWRAP_DENY_SEVERITY; + +void +#ifdef __STDC__ +logdeny(char *fmt,...) +#else +/*VARARGS*//*ARGSUSED*/ +logdeny(va_alist) +va_dcl +#endif +{ + char buf[STRINGLENGTH]; + va_list ap; + +#ifdef __STDC__ + va_start(ap,fmt); +#else + char *fmt; + + va_start(ap); + fmt = va_arg(ap,char *); +#endif + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + if (opened) { + syslog (deny_severity, "%s", buf); + return; + } + printf ("%s\n",buf); + (void) fflush (stdout); +} + +void +#ifdef __STDC__ +logallow(char *fmt,...) +#else +/*VARARGS*//*ARGSUSED*/ +logallow(va_alist) +va_dcl +#endif +{ + char buf[STRINGLENGTH]; + va_list ap; + +#ifdef __STDC__ + va_start(ap,fmt); +#else + char *fmt; + + va_start(ap); + fmt = va_arg(ap,char *); +#endif + vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + if (opened) { + syslog (allow_severity, "%s", buf); + return; + } + printf ("%s\n",buf); + (void) fflush (stdout); +} + +#endif /* LIBWRAP */ diff --git a/usr.bin/sup/src/netcryptvoid.c b/usr.bin/sup/src/netcryptvoid.c index 833bb7cd8d0..cf455b4ce4e 100644 --- a/usr.bin/sup/src/netcryptvoid.c +++ b/usr.bin/sup/src/netcryptvoid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: netcryptvoid.c,v 1.4 2001/04/29 21:52:14 millert Exp $ */ +/* $OpenBSD: netcryptvoid.c,v 1.5 2001/05/02 22:56:52 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -53,7 +53,7 @@ *** G L O B A L V A R I A B L E S *** *********************************************/ -int cryptflag = 0; /* whether to encrypt/decrypt data */ +int cryptflag; /* whether to encrypt/decrypt data */ char *cryptbuf; /* buffer for data encryption/decryption */ int netcrypt (pword) @@ -66,14 +66,13 @@ char *pword; } return (SCMERR); } + int getcryptbuf (x) int x; { - static int cryptsize = 0; /* size of current cryptbuf */ - - if (cryptflag == 0) { + if (cryptflag == 0) return(SCMOK); - } else + else return (SCMERR); } diff --git a/usr.bin/sup/src/nxtarg.c b/usr.bin/sup/src/nxtarg.c index 147cdf7e1fb..9847826607b 100644 --- a/usr.bin/sup/src/nxtarg.c +++ b/usr.bin/sup/src/nxtarg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nxtarg.c,v 1.3 1997/04/01 07:35:12 todd Exp $ */ +/* $OpenBSD: nxtarg.c,v 1.4 2001/05/02 22:56:52 millert Exp $ */ /* * Copyright (c) 1991 Carnegie Mellon University @@ -68,7 +68,7 @@ char **q,*brk; while (*front && (*front == ' ' || *front == '\t')) front++; /* find break character at end */ if (brk == 0) brk = " "; - back = skipto ((unsigned char *) front,(unsigned char *) brk); + back = skipto (front, brk); _argbreak = *back; *q = (*back ? back+1 : back); /* next arg start loc */ /* elim trailing blanks and tabs */ diff --git a/usr.bin/sup/src/read_line.c b/usr.bin/sup/src/read_line.c new file mode 100644 index 00000000000..f96f9837aa7 --- /dev/null +++ b/usr.bin/sup/src/read_line.c @@ -0,0 +1,110 @@ +/* $OpennBSD$ */ + +/* + * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef lint +static char rcsid[] = "$OpenBSD: read_line.c,v 1.1 2001/05/02 22:56:52 millert Exp $"; +#endif /* not lint */ + +#include <sys/param.h> +#include <err.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "supcdefs.h" +#include "supextern.h" + +/* read_line(): + * Read a line from a file, parsing continuations ending in \ + * and eliminating trailing newlines. + * Returns a pointer to an internal buffer that is reused upon + * next invocation. + */ +char * +read_line(fp, size, lineno, delim, flags) + FILE *fp; + size_t *size; + size_t *lineno; + const char delim[3]; /* unused */ + int flags; /* unused */ +{ + static char *buf; +#ifdef HAS_FPARSELN + + if (buf != NULL) + free(buf); + return (buf = fparseln(fp, size, lineno, delim, flags)); +#else + static int buflen; + + size_t s, len; + char *ptr; + int cnt; + + len = 0; + cnt = 1; + while (cnt) { + if (lineno != NULL) + (*lineno)++; + if ((ptr = fgetln(fp, &s)) == NULL) { + if (size != NULL) + *size = len; + if (len == 0) + return NULL; + else + return buf; + } + if (ptr[s - 1] == '\n') /* the newline may be missing at EOF */ + s--; /* forget newline */ + if (!s) + cnt = 0; + else { + if ((cnt = (ptr[s - 1] == '\\')) != 0) + s--; /* forget \\ */ + } + + if (len + s + 1 > buflen) { + buflen = len + s + 1; + buf = realloc(buf, buflen); + } + if (buf == NULL) + err(1, "can't realloc"); + memcpy(buf + len, ptr, s); + len += s; + buf[len] = '\0'; + } + if (size != NULL) + *size = len; + return buf; +#endif /* HAS_FPARSELN */ +} diff --git a/usr.bin/sup/src/run.c b/usr.bin/sup/src/run.c index 7658d4fb03f..d2d6bbea65d 100644 --- a/usr.bin/sup/src/run.c +++ b/usr.bin/sup/src/run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: run.c,v 1.6 2001/04/29 21:52:15 millert Exp $ */ +/* $OpenBSD: run.c,v 1.7 2001/05/02 22:56:52 millert Exp $ */ /* * Copyright (c) 1991 Carnegie Mellon University @@ -102,6 +102,27 @@ #endif static int dorun __P((char *, char **, int)); +static char **makearglist __P((va_list)); + +static char ** +makearglist(ap) + va_list ap; +{ + static size_t ns = 0; + static char **np = NULL; + int i = 0; + + do { + if (i >= ns) { + ns += 20; + if ((np = realloc(np, ns)) == NULL) + return NULL; + } + np[i] = va_arg(ap, char *); + } + while (np[i++] != NULL); + return np; +} int #ifdef __STDC__ @@ -123,7 +144,8 @@ va_dcl name = va_arg(ap, char *); #endif - argv = va_arg(ap, char **); + if ((argv = makearglist(ap)) == NULL) + return -1; val = runv (name, argv); va_end(ap); return(val); @@ -155,7 +177,8 @@ va_dcl name = va_arg(ap, char *); #endif - argv = va_arg(ap, char **); + if ((argv = makearglist(ap)) == NULL) + return -1; val = runvp (name, argv); va_end(ap); return (val); @@ -189,7 +212,8 @@ int usepath; execvp(name,argv); else execv(name,argv); - fprintf (stderr,"run: can't exec %s\n",name); + fprintf (stderr,"run: can't exec %s: %s\n",name, + strerror(errno)); _exit (0377); } @@ -260,7 +284,39 @@ runio(argv, infile, outfile, errfile) if (fd != 2) (void) dup2(fd, 2); } + execvp(argv[0], argv); + exit(1); + /*NOTREACHED*/ + return 0; + + default: + if (waitpid(pid, &status, 0) == -1) + return -1; + return status; + } +} +/* + * Like runio, but works with filedescriptors instead of filenames + */ +int +runiofd(argv, infile, outfile, errfile) + char *const argv[]; + const int infile; + const int outfile; + const int errfile; +{ + pid_t pid; + int status; + + switch ((pid = fork())) { + case -1: + return -1; + + case 0: + if (infile != 0) dup2(infile, 0); + if (outfile != 1) dup2(outfile,1); + if (errfile != 2) dup2(errfile,2); execvp(argv[0], argv); exit(1); /*NOTREACHED*/ diff --git a/usr.bin/sup/src/salloc.c b/usr.bin/sup/src/salloc.c index 0fa988545ea..62b4a8ec547 100644 --- a/usr.bin/sup/src/salloc.c +++ b/usr.bin/sup/src/salloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: salloc.c,v 1.3 1997/04/01 07:35:18 todd Exp $ */ +/* $OpenBSD: salloc.c,v 1.4 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1991 Carnegie Mellon University @@ -40,7 +40,7 @@ char *salloc(p) -char *p; +const char *p; { register char *q; register int l; diff --git a/usr.bin/sup/src/scm.c b/usr.bin/sup/src/scm.c index c2402624b19..3ba5083b65d 100644 --- a/usr.bin/sup/src/scm.c +++ b/usr.bin/sup/src/scm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scm.c,v 1.10 2001/04/29 21:52:15 millert Exp $ */ +/* $OpenBSD: scm.c,v 1.11 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -192,7 +192,6 @@ #define INADDR_LOOPBACK (u_long)0x7f000001 /* 127.0.0.1 */ #endif - char scmversion[] = "4.3 BSD"; extern int silent; @@ -519,9 +518,8 @@ char *myhost () /* find my host name */ struct hostent *h; static char name[MAXHOSTNAMELEN]; - if (name[0] == '\0') { - if (gethostname (name,MAXHOSTNAMELEN) < 0) + if (gethostname (name,sizeof name) < 0) return (NULL); if ((h = gethostbyname (name)) == NULL) return (NULL); @@ -552,7 +550,7 @@ register char *host; char *name; if ((name = myhost ()) == NULL) - logquit (1,"Can't find my host entry"); + logquit (1,"Can't find my host entry '%s'", myhost()); h = gethostbyname (host); if (h == NULL) return (0); return (strcasecmp (name,h->h_name) == 0); @@ -617,7 +615,7 @@ char *name; } #ifdef __STDC__ -int scmerr (int errno,char *fmt,...) +int scmerr (int error,char *fmt,...) #else /*VARARGS*//*ARGSUSED*/ int scmerr (va_alist) @@ -628,11 +626,11 @@ va_dcl #ifdef __STDC__ va_start(ap,fmt); #else - int errno; + int error; char *fmt; va_start(ap); - errno = va_arg(ap,int); + error = va_arg(ap,int); fmt = va_arg(ap,char *); #endif @@ -644,8 +642,8 @@ va_dcl vfprintf(stderr, fmt, ap); va_end(ap); - if (errno >= 0) - fprintf (stderr,": %s\n",errmsg(errno)); + if (error >= 0) + fprintf (stderr,": %s\n",errmsg(error)); else fprintf (stderr,"\n"); (void) fflush (stderr); diff --git a/usr.bin/sup/src/scmio.c b/usr.bin/sup/src/scmio.c index 27733faa72b..74cfc67b9c5 100644 --- a/usr.bin/sup/src/scmio.c +++ b/usr.bin/sup/src/scmio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scmio.c,v 1.5 2001/04/29 21:52:15 millert Exp $ */ +/* $OpenBSD: scmio.c,v 1.6 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -165,7 +165,6 @@ #include "supextern.h" #include "supmsg.h" - /************************* *** M A C R O S *** *************************/ diff --git a/usr.bin/sup/src/skipto.c b/usr.bin/sup/src/skipto.c index 0cabbf7864a..6df89b8903e 100644 --- a/usr.bin/sup/src/skipto.c +++ b/usr.bin/sup/src/skipto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: skipto.c,v 1.3 1997/04/01 07:35:26 todd Exp $ */ +/* $NetBSD: skipto.c,v 1.4 1997/06/17 21:38:25 christos Exp $ */ /* * Copyright (c) 1991 Carnegie Mellon University @@ -58,26 +58,32 @@ static char tab[256] = { 0}; -char *skipto (string,charset) +char *skipto (string, charset) char *string, *charset; { - register unsigned char *setp,*strp; + char *setp, *strp; tab[0] = 1; /* Stop on a null, too. */ - for (setp=charset; *setp; setp++) tab[*setp]=1; - for (strp=string; tab[*strp]==0; strp++) ; - for (setp=charset; *setp; setp++) tab[*setp]=0; - return ((char *)strp); + for (setp = charset; *setp; setp++) + tab[(unsigned char) *setp] = 1; + for (strp = string; tab[(unsigned char) *strp]==0; strp++) + continue; + for (setp = charset; *setp; setp++) + tab[(unsigned char) *setp] = 0; + return strp; } -char *skipover (string,charset) +char *skipover (string, charset) char *string, *charset; { - register unsigned char *setp,*strp; + char *setp, *strp; tab[0] = 0; /* Do not skip over nulls. */ - for (setp=charset; *setp; setp++) tab[*setp]=1; - for (strp=string; tab[*strp]; strp++) ; - for (setp=charset; *setp; setp++) tab[*setp]=0; - return ((char *)strp); + for (setp = charset; *setp; setp++) + tab[(unsigned char) *setp] = 1; + for (strp = string; tab[(unsigned char) *strp]; strp++) + continue; + for (setp = charset; *setp; setp++) + tab[(unsigned char) *setp] = 0; + return strp; } diff --git a/usr.bin/sup/src/sup.1 b/usr.bin/sup/src/sup.1 index 6bb92ebbd13..273188cee50 100644 --- a/usr.bin/sup/src/sup.1 +++ b/usr.bin/sup/src/sup.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sup.1,v 1.10 2001/04/20 22:28:03 espie Exp $ +.\" $OpenBSD: sup.1,v 1.11 2001/05/02 22:56:53 millert Exp $ .\" .\" Copyright (c) 1992 Carnegie Mellon University .\" All Rights Reserved. @@ -24,60 +24,8 @@ .\" the rights to redistribute these changes. .\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .\" HISTORY -.\" $Log: sup.1,v $ -.\" Revision 1.10 2001/04/20 22:28:03 espie -.\" typo -.\" -.\" Revision 1.9 2000/03/14 21:31:42 aaron -.\" Suffix "i.e." and "e.g." with a comma. Just another really picky man page -.\" commit, as we want our documentation to be as consistently formatted as -.\" possible (it's getting there :-)). -.\" -.\" Revision 1.8 1999/09/23 04:12:09 alex -.\" Typo fixes. -.\" -.\" Revision 1.7 1999/06/05 01:21:41 aaron -.\" - remove trailing white space -.\" - remove arguments from .Os macros -.\" - remove arguments from .Nm macros, where appropriate -.\" - some more Dq/Sq/Ql insanity -.\" - still lots to do in the usr.bin tree... :/ -.\" -.\" Revision 1.6 1999/05/12 13:26:52 aaron -.\" grammar police: do not hyphenate compound words that act as adjectives if the -.\" first word ends in -ly -.\" -.\" i.e., fully-qualified, newly-created, globally-visible, etc. are wrong -.\" -.\" Revision 1.5 1998/09/05 17:41:47 deraadt -.\" more man page repairs; aaron@ug.cs.dal.ca -.\" -.\" Revision 1.4 1998/09/01 16:38:25 deraadt -.\" more man page fixes; aaron@ug.cs.dal.ca -.\" -.\" Revision 1.3 1998/08/29 21:11:13 deraadt -.\" man page repairs; aaron@ug.cs.dal.ca -.\" -.\" Revision 1.2 1996/06/26 05:39:49 deraadt -.\" rcsid -.\" -.\" Revision 1.1 1995/12/16 11:46:54 deraadt -.\" add sup to the tree -.\" -.\" Revision 1.3 1995/06/03 21:21:53 christos -.\" Changes to write ascii timestamps in the when files. -.\" Looked into making it 64 bit clean, but it is hopeless. -.\" Added little program to convert from the old timestamp files -.\" into the new ones. -.\" -.\" Revision 1.2 1993/08/04 17:46:14 brezak -.\" Changes from nate for gzip'ed sup -.\" -.\" Revision 1.1.1.1 1993/05/21 14:52:16 cgd -.\" initial import of CMU's SUP to NetBSD -.\" + .\" Revision 1.4 92/08/11 12:08:40 mrt -.\" .TP .\" Add description of releases and use-rel-suffix .\" [92/07/31 mrt] .\" @@ -161,6 +109,15 @@ will print the time that each collection was last upgraded, rather than performing actual upgrades. .TP +.B -u +When this flag is given, +.I sup +will not try to restore the user access and modified times of files in +the collections from the server. +.TP +.B -S +Operate silently printing messages only on errors. +.TP .B -N .I Sup will trace network messages sent and received that implement the diff --git a/usr.bin/sup/src/sup.h b/usr.bin/sup/src/sup.h index e64538f180f..d7ef1efa751 100644 --- a/usr.bin/sup/src/sup.h +++ b/usr.bin/sup/src/sup.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sup.h,v 1.6 2001/04/29 21:52:15 millert Exp $ */ +/* $OpenBSD: sup.h,v 1.7 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -128,7 +128,7 @@ extern char scmversion[]; /* string version of scm */ #define FILEBKDIR "%s/BACKUP" #define FILEBACKUP "%s/BACKUP/%s" #define FILELAST "sup/%s/last%s" -#define FILELASTTEMP "sup/%s/last.temp%s" +#define FILELASTTEMP "sup/%s/last%s.temp" #define FILELOCK "sup/%s/lock" /* also supfilesrv */ #define FILEREFUSE "sup/%s/refuse" #define FILEWHEN "sup/%s/when%s" diff --git a/usr.bin/sup/src/supcdefs.h b/usr.bin/sup/src/supcdefs.h index 0193d808f69..f80f3c14cc0 100644 --- a/usr.bin/sup/src/supcdefs.h +++ b/usr.bin/sup/src/supcdefs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: supcdefs.h,v 1.5 2001/04/29 21:52:16 millert Exp $ */ +/* $OpenBSD: supcdefs.h,v 1.6 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -55,6 +55,7 @@ ********************************************************************** */ +#include <errno.h> #include <libc.h> #include <netdb.h> #include <signal.h> @@ -68,16 +69,17 @@ #include <sys/stat.h> #include <sys/time.h> #include <sys/file.h> -#include <sys/errno.h> #if MACH /* used by resource pausing code only */ #include <sys/ioctl.h> #include <sys/resource.h> #endif /* MACH */ +#ifdef HAS_FPARSELN +#include <util.h> +#endif /* HAS_FPARSELN */ #include <c.h> #include "sup.h" #include "supmsg.h" -extern int errno; extern int PGMVERSION; /******************************************* diff --git a/usr.bin/sup/src/supcmain.c b/usr.bin/sup/src/supcmain.c index dc70da713ef..05ba179f51c 100644 --- a/usr.bin/sup/src/supcmain.c +++ b/usr.bin/sup/src/supcmain.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supcmain.c,v 1.9 2001/04/29 21:52:16 millert Exp $ */ +/* $OpenBSD: supcmain.c,v 1.10 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -45,6 +45,11 @@ * that each collection was last upgraded, rather than * performing actual upgrades. * + * -u "utimes" flag + * When this flag is given sup will not attempt to + * restore access and modification files on the + * collection files from the server. + * * -R "resource pause" flag * Sup will not disable resource pausing and will not * make filesystem space checks. @@ -331,9 +336,10 @@ COLLECTION *firstC,*thisC; /* collection list pointer */ extern int dontjump; /* disable longjmp */ extern int scmdebug; /* SCM debugging flag */ -int silent; /* Silent run, print only errors */ +int silent; /* silent run, print only errors */ int sysflag; /* system upgrade flag */ int timeflag; /* print times flag */ +int noutime; /* don't preserve utimes */ #if MACH int rpauseflag; /* don't disable resource pausing */ #endif /* MACH */ @@ -555,6 +561,9 @@ int *oflagsp,*aflagsp; oflags &= ~CFOLD; aflags |= CFOLD; break; + case 'u': + noutime = TRUE; + break; case 'v': oflags |= CFVERBOSE; break; @@ -637,9 +646,9 @@ char **argv; --argc; argv++; } - if ((p = (char *)getlogin()) || + if ((p = getlogin()) || ((pw = getpwuid ((int)getuid())) && (p = pw->pw_name))) { - (void) strncpy (username,p, sizeof username-1); + (void) strncpy (username, p, sizeof username-1); username[sizeof username-1] = '\0'; } else *username = '\0'; @@ -652,10 +661,9 @@ char **argv; firstC = NULL; lastC = NULL; bogus = FALSE; - while ((p = fgets (buf,STRINGLENGTH,f)) != NULL) { - q = strchr (p,'\n'); - if (q) *q = '\0'; - if (strchr ("#;:",*p)) continue; + while ((p = read_line(f, NULL, NULL, NULL, 0)) != NULL) { + if (strchr ("#;:", *p)) + continue; arg = nxtarg (&p," \t"); if (*arg == '\0') { logerr ("Missing collection name in supfile"); diff --git a/usr.bin/sup/src/supcmeat.c b/usr.bin/sup/src/supcmeat.c index 09243dedefa..033942a9707 100644 --- a/usr.bin/sup/src/supcmeat.c +++ b/usr.bin/sup/src/supcmeat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supcmeat.c,v 1.12 2001/04/29 22:45:12 millert Exp $ */ +/* $OpenBSD: supcmeat.c,v 1.13 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -115,6 +115,7 @@ #include "supcdefs.h" #include "supextern.h" +#include <sys/param.h> #include <sys/wait.h> TREE *lastT; /* last filenames in collection */ @@ -126,6 +127,7 @@ int docompress=FALSE; /* Do we do compression? */ 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 */ /************************************************* *** U P G R A D E C O L L E C T I O N *** @@ -223,7 +225,7 @@ void getcoll (void) if (setjmp (sjbuf)) x = SCMERR; else { - login (); + suplogin (); listfiles (); recvfiles (); x = SCMOK; @@ -390,7 +392,7 @@ register TREE *t; /*** Tell file server what account to use ***/ -void login (void) +void suplogin (void) { char buf[STRINGLENGTH]; register int f,x; @@ -599,9 +601,10 @@ static int deleteone (t, v) TREE *t; void *v; { - struct stat sbuf; + struct stat sbuf, pbuf; register int x; register char *name = t->Tname; + char pname[MAXPATHLEN]; if (t->Tflags&FUPDATE) /* in current upgrade list */ return (SCMOK); @@ -648,7 +651,15 @@ void *v; t->Tflags |= FUPDATE; return (SCMOK); } - (void) rmdir (name); + if (rmdir (name) < 0) { + (void) chmod (name,sbuf.st_mode|S_IRWXU); + if (strlen(name) < MAXPATHLEN - 3) { + sprintf (pname,"%s/..",name); + if (stat (pname,&pbuf) == 0) + (void) chmod (pname,pbuf.st_mode|S_IRWXU); + } + runp ("rm","rm","-rf",name,0); + } if (lstat(name,&sbuf) == 0) { notify ("SUP: Unable to delete directory %s\n",name); t->Tflags |= FUPDATE; @@ -729,6 +740,8 @@ int mode,*newp; struct stat *statp; { register char *type; + char pname[MAXPATHLEN]; + struct stat pbuf; if (mode == S_IFLNK) *newp = (lstat (name,statp) < 0); @@ -763,8 +776,15 @@ struct stat *statp; return (FALSE); } if (S_ISDIR(statp->st_mode)) { - if (rmdir (name) < 0) + if (rmdir (name) < 0) { + (void) chmod (name,statp->st_mode|S_IRWXU); + if (strlen(name) < MAXPATHLEN - 3) { + sprintf(pname,"%s/..",name); + if (stat(pname,&pbuf) == 0) + (void) chmod (pname,pbuf.st_mode|S_IRWXU); + } runp ("rm","rm","-rf",name,0); + } } else (void) unlink (name); if (stat (name,statp) < 0) { @@ -845,10 +865,9 @@ register struct stat *statp; vnotify ("SUP Would create directory %s\n",t->Tname); return (FALSE); } - (void) mkdir (t->Tname,0755); - if (stat (t->Tname,statp) < 0) { - notify ("SUP: Can't create directory %s\n",t->Tname); - return (TRUE); + if (makedir(t->Tname, 0755, statp) == -1) { + vnotify ("SUP: Can't create directory %s\n", t->Tname); + return TRUE; } } if ((t->Tflags&FNOACCT) == 0) { @@ -871,7 +890,8 @@ register struct stat *statp; } tbuf[0].tv_sec = time((time_t *)NULL); tbuf[0].tv_usec = 0; tbuf[1].tv_sec = t->Tmtime; tbuf[1].tv_usec = 0; - (void) utimes (t->Tname,tbuf); + if (!noutime) + (void) utimes (t->Tname,tbuf); vnotify ("SUP %s directory %s\n",new?"Created":"Updated",t->Tname); return (FALSE); } @@ -948,7 +968,8 @@ register struct stat *statp; } tbuf[0].tv_sec = time((time_t *)NULL); tbuf[0].tv_usec = 0; tbuf[1].tv_sec = t->Tmtime; tbuf[1].tv_usec = 0; - (void) utimes (t->Tname,tbuf); + if (!noutime) + (void) utimes (t->Tname,tbuf); return (FALSE); } if (thisC->Cflags&CFLIST) { @@ -1008,7 +1029,8 @@ register struct stat *statp; } tbuf[0].tv_sec = time((time_t *)NULL); tbuf[0].tv_usec = 0; tbuf[1].tv_sec = t->Tmtime; tbuf[1].tv_usec = 0; - (void) utimes (t->Tname,tbuf); + if (!noutime) + (void) utimes (t->Tname,tbuf); return (FALSE); } @@ -1237,26 +1259,40 @@ char *from; /* 0 if reading from network */ lockout (FALSE); return (FALSE); } - /* uncompress it first */ + /* + ** If the file is compressed, uncompress it in place. We open the + ** temp file for reading, unlink the file, and then open the same + ** file again for writing. Then we pipe through gzip. When + ** 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. + */ if (docompress) { char *av[4]; int ac = 0; + int infd = -1; + int outfd = -1; av[ac++] = "gzip"; av[ac++] = "-d"; av[ac++] = NULL; - if (runio(av, tname, to, NULL) != 0) { - /* Uncompress it onto the destination */ - notify ("SUP: Error in uncompressing file %s\n", - to); + if ( (infd = open(tname, O_RDONLY)) == -1 || + unlink(tname) == -1 || + (outfd = open(tname, O_WRONLY|O_CREAT|O_TRUNC)) == -1 || + runiofd( av, infd, outfd, 2 ) != 0 ) { + notify("SUP: Error in uncompressing file %s (%s)\n", + to, tname ); (void) unlink (tname); - /* Just in case */ - (void) unlink (to); - lockout (FALSE); - return (TRUE); + if ( infd != -1 ) (void) close (infd); + if ( outfd != -1 ) (void) close (outfd); + lockout(FALSE); + return(TRUE); } - (void) unlink (tname); - lockout (FALSE); - return (FALSE); + (void) close(infd); + (void) close(outfd); } /* move to destination */ if (rename (tname,to) == 0) { @@ -1475,11 +1511,12 @@ va_dcl goawayreason = NULL; va_end(ap); (void) msggoaway (); - if (fmt) + if (fmt) { if (thisC) notify ("SUP: %s\n",buf); else printf ("SUP: %s\n",buf); + } if (!dontjump) longjmp (sjbuf,TRUE); } diff --git a/usr.bin/sup/src/supcmisc.c b/usr.bin/sup/src/supcmisc.c index 7268cd2e8aa..ca7dd331811 100644 --- a/usr.bin/sup/src/supcmisc.c +++ b/usr.bin/sup/src/supcmisc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supcmisc.c,v 1.7 2001/04/29 21:52:16 millert Exp $ */ +/* $OpenBSD: supcmisc.c,v 1.8 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -91,10 +91,11 @@ prtime () logerr ("Can't change to base directory %s for collection %s", thisC->Cbase,thisC->Cname); twhen = getwhen(thisC->Cname,relsufix); - (void) strncpy (buf,ctime (&twhen), sizeof buf-1); - buf[sizeof buf-1] = '\0'; - loginfo ("Last update occurred at %s for collection %s", - buf,thisC->Cname); + buf[0] = '\0'; + (void) strncat (buf,ctime (&twhen), sizeof buf-1); + buf[strlen(buf)-1] = '\0'; + loginfo ("Last update occurred at %s for collection %s%s", + buf,thisC->Cname,relsufix); } int establishdir (fname) @@ -105,6 +106,23 @@ char *fname; return (estabd (fname,dpart)); } +int makedir(fname, mode, statp) +char *fname; +int mode; +struct stat *statp; +{ + if (lstat(fname, statp) != -1 && !S_ISDIR(statp->st_mode)) { + if (unlink(fname) == -1) { + notify ("SUP: Can't delete %s\n", fname); + return -1; + } + } + + (void) mkdir (fname, 0755); + + return stat (fname, statp); +} + int estabd (fname,dname) char *fname,*dname; { @@ -120,10 +138,9 @@ char *fname,*dname; } x = estabd (fname,dpart); if (x) return (TRUE); - (void) mkdir (dname,0755); - if (stat (dname,&sbuf) < 0) { /* didn't work */ - notify ("SUP: Can't create directory %s for %s\n",dname,fname); - return (TRUE); + if (makedir(dname, 0755, &sbuf) < 0) { + vnotify ("SUP: Can't create directory %s for %s\n",dname,fname); + return TRUE; } vnotify ("SUP Created directory %s for %s\n",dname,fname); return (FALSE); diff --git a/usr.bin/sup/src/supcparse.c b/usr.bin/sup/src/supcparse.c index 2818dc5333b..62705aee1ea 100644 --- a/usr.bin/sup/src/supcparse.c +++ b/usr.bin/sup/src/supcparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supcparse.c,v 1.5 2001/04/29 21:52:16 millert Exp $ */ +/* $OpenBSD: supcparse.c,v 1.6 2001/05/02 22:56:53 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -264,7 +264,7 @@ putwhen(fname, tstamp) FILE *fp; if ((fp = fopen(fname, "w")) == NULL) return 0; - if (fprintf(fp, "%ld\n", tstamp) < 0) + if (fprintf(fp, "%u\n", tstamp) < 0) return 0; if (fclose(fp) != 0) return 0; diff --git a/usr.bin/sup/src/supextern.h b/usr.bin/sup/src/supextern.h index 50f4d82d9ef..a4af1e154b8 100644 --- a/usr.bin/sup/src/supextern.h +++ b/usr.bin/sup/src/supextern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: supextern.h,v 1.2 1997/09/16 11:01:22 deraadt Exp $ */ +/* $OpenBSD: supextern.h,v 1.3 2001/05/02 22:56:53 millert Exp $ */ #ifndef __P #ifdef __STDC__ @@ -17,7 +17,7 @@ int ci __P((char *, FILE *, int, CIENTRY *, char *, char *)); #endif /* errmsg.c */ -char *errmsg __P((int)); +const char *errmsg __P((int)); /* expand.c */ int expand __P((char *, char **, int)); @@ -33,6 +33,10 @@ void logopen __P((char *)); void logquit __P((int, char *, ...)); void logerr __P((char *, ...)); void loginfo __P((char *, ...)); +#ifdef LIBWRAP +void logdeny __P((char *, ...)); +void logallow __P((char *, ...)); +#endif /* netcryptvoid.c */ int netcrypt __P((char *)); @@ -49,15 +53,19 @@ void path __P((char *, char *, char *, int)); /* quit.c */ void quit __P((int, char *, ...)); +/* read_line.c */ +char *read_line __P((FILE *, size_t *, size_t *, const char[3], int)); + /* run.c */ int run __P((char *, ...)); int runv __P((char *, char **)); int runp __P((char *, ...)); int runvp __P((char *, char **)); int runio __P((char *const[], const char *, const char *, const char *)); +int runiofd __P((char *const[], const int, const int, const int)); /* salloc.c */ -char *salloc __P((char *)); +char *salloc __P((const char *)); /* scan.c */ int getrelease __P((char *)); @@ -122,7 +130,7 @@ TREE *getcollhost __P((int *, int *, long *, int *)); void getcoll __P((void)); int signon __P((TREE *, int, int *)); int setup __P((TREE *)); -void login __P((void)); +void suplogin __P((void)); void listfiles __P((void)); void recvfiles __P((void)); int prepare __P((char *, int, int *, struct stat *)); @@ -137,6 +145,7 @@ void goaway __P((char *, ...)); /* supcmisc.c */ void prtime __P((void)); int establishdir __P((char *)); +int makedir __P((char *, int, struct stat *)); int estabd __P((char *, char *)); void ugconvert __P((char *, char *, int *, int *, int *)); void notify __P((char *, ...)); @@ -172,7 +181,11 @@ int msgxpatch __P((void)); int msgcompress __P((void)); /* vprintf.c */ +/* XXX already in system headers included already - but with different + argument declarations! */ +#if 0 int vprintf __P((const char *, va_list)); int vfprintf __P((FILE *, const char *, va_list)); int vsprintf __P((char *, const char *, va_list)); int vsnprintf __P((char *, size_t, const char *, va_list)); +#endif diff --git a/usr.bin/sup/src/supfilesrv.c b/usr.bin/sup/src/supfilesrv.c index 12551ecfbae..a9d436e2fb7 100644 --- a/usr.bin/sup/src/supfilesrv.c +++ b/usr.bin/sup/src/supfilesrv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supfilesrv.c,v 1.20 2001/04/29 18:16:19 millert Exp $ */ +/* $OpenBSD: supfilesrv.c,v 1.21 2001/05/02 22:56:54 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -16,7 +16,7 @@ * * Carnegie Mellon requests users of this software to return to * - * Software Distribution Coordinator or Software_Distribution@CS.CMU.EDU + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 @@ -28,16 +28,19 @@ /* * supfilesrv -- SUP File Server * - * Usage: supfilesrv [-l] [-P] [-N] [-R] [-S] [-O] - * -l "live" -- don't fork daemon + * Usage: supfilesrv [-d] [-l] [-P] [-N] [-R] [-S] + * -d "debug" -- don't fork daemon + * -l "log" -- print successull connects (when compiled with libwrap) * -P "debug ports" -- use debugging network ports * -N "debug network" -- print debugging messages for network i/o * -R "RCS mode" -- if file is an rcs file, use co to get contents * -S "Operate silently" -- Only print error messages - * -O "One Connection" -- Reject servicing multiple connections * ********************************************************************** * HISTORY + * 2-Aug-99 Manuel Bouyer at LIP6 + * Added libwrap support + * * 13-Sep-92 Mary Thompson (mrt) at Carnegie-Mellon University * Changed name of sup program in xpatch from /usr/cs/bin/sup to * /usr/bin/sup for exported version of sup. @@ -46,6 +49,76 @@ * Modified SUP to use gzip based compression when sending files * across the network to save BandWidth * + * Revision 1.20 92/09/09 22:05:00 mrt + * Added Brad's change to make sendfile take a va_list. + * Added support in login to accept an non-encrypted login + * message if no user or password is being sent. This supports + * a non-crypting version of sup. Also fixed to skip leading + * white space from crypts in host files. + * [92/09/01 mrt] + * + * Revision 1.19 92/08/11 12:07:59 mrt + * Made maxchildren a patchable variable, which can be set by the + * command line switch -C or else defaults to the MAXCHILDREN + * defined in sup.h. Added most of Brad's STUMP changes. + * Increased PGMVERSION to 12 to reflect substantial changes. + * [92/07/28 mrt] + * + * Revision 1.18 90/12/25 15:15:39 ern + * Yet another rewrite of the logging code. Make up the text we will write + * and then get in, write it and get out. + * Also set error on write-to-full-disk if the logging is for recording + * server is busy. + * [90/12/25 15:15:15 ern] + * + * Revision 1.17 90/05/07 09:31:13 dlc + * Sigh, some more fixes to the new "crypt" file handling code. First, + * just because the "crypt" file is in a local file system does not mean + * it can be trusted. We have to check for hard links to root owned + * files whose contents could be interpretted as a crypt key. For + * checking this fact, the new routine stat_info_ok() was added. This + * routine also makes other sanity checks, such as owner only permission, + * the file is a regular file, etc. Also, even if the uid/gid of th + * "crypt" file is not going to be used, still use its contents in order + * to cause fewer surprises to people supping out of a shared file system + * such as AFS. + * [90/05/07 dlc] + * + * Revision 1.16 90/04/29 04:21:08 dlc + * Fixed logic bug in docrypt() which would not get the stat information + * from the crypt file if the crypt key had already been set from a + * "host" file. + * [90/04/29 dlc] + * + * Revision 1.15 90/04/18 19:51:27 dlc + * Added the new routines local_file(), link_nofollow() for use in + * dectecting whether a file is located in a local file system. These + * routines probably should have been in another module, but only + * supfilesrv needs to do the check and none of its other modules seemed + * appropriate. Note, the implementation should be changed once we have + * direct kernel support, for example the fstatfs(2) system call, for + * detecting the type of file system a file resides. Also, I changed + * the routines which read the crosspatch crypt file or collection crypt + * file to save the uid and gid from the stat information obtained via + * the local_file() call (when the file is local) at the same time the + * crypt key is read. This change disallows non-local files for the + * crypt key to plug a security hole involving the usage of the uid/gid + * of the crypt file to define who the the file server should run as. If + * the saved uid/gid are both valid, then the server will set its uid/gid + * to these values. + * [90/04/18 dlc] + * + * Revision 1.14 89/08/23 14:56:15 gm0w + * Changed msgf routines to msg routines. + * [89/08/23 gm0w] + * + * Revision 1.13 89/08/03 19:57:33 mja + * Remove setaid() call. + * + * Revision 1.12 89/08/03 19:49:24 mja + * Updated to use v*printf() in place of _doprnt(). + * [89/04/19 mja] + * * 11-Sep-88 Glenn Marcy (gm0w) at Carnegie-Mellon University * Added code to record release name in logfile. * @@ -186,6 +259,10 @@ # include <sys/statvfs.h> #endif +#ifdef LIBWRAP +# include <tcpd.h> +#endif + #ifdef HAS_LOGIN_CAP # include <login_cap.h> #endif @@ -239,9 +316,12 @@ int progpid = -1; /* and process id */ jmp_buf sjbuf; /* jump location for network errors */ TREELIST *listTL; /* list of trees to upgrade */ -char *oneconnect = NULL; /* -O flag */ +char *oneconnect = NULL; /* -O flag */ int silent; /* -S flag */ -int live; /* -l flag */ +#ifdef LIBWRAP +int clog; /* -l flag */ +#endif +int live; /* -d flag */ int dbgportsq; /* -P flag */ extern int scmdebug; /* -N flag */ extern int netfile; @@ -315,6 +395,9 @@ char **argv; sigset_t nset, oset; struct sigaction chld,ign; time_t tloc; +#ifdef LIBWRAP + struct request_info req; +#endif /* initialize global variables */ pgmversion = PGMVERSION; /* export version number */ @@ -348,8 +431,23 @@ char **argv; PROTOVERSION,PGMVERSION,scmversion,fmttime (tloc)); if (live) { x = service (); + if (x != SCMOK) logquit (1,"Can't connect to network"); +#ifdef LIBWRAP + request_init(&req, RQ_DAEMON, "supfilesrv", RQ_FILE, netfile, + NULL); + fromhost(&req); + if (hosts_access(&req) == 0) { + logdeny("refused connection from %.500s", + eval_client(&req)); + servicekill(); + exit(1); + } + if (clog) { + logallow("connection from %.500s", eval_client(&req)); + } +#endif answer (); (void) serviceend (); exit (0); @@ -378,6 +476,21 @@ char **argv; sigaddset(&nset, SIGCHLD); sigprocmask(SIG_BLOCK, &nset, &oset); if ((pid = fork()) == 0) { /* server process */ +#ifdef LIBWRAP + request_init(&req, RQ_DAEMON, "supfilesrv", RQ_FILE, + netfile, NULL); + fromhost(&req); + if (hosts_access(&req) == 0) { + logdeny("refused connection from %.500s", + eval_client(&req)); + servicekill(); + exit(1); + } + if (clog) { + logallow("connection from %.500s", + eval_client(&req)); + } +#endif (void) serviceprep (); answer (); (void) serviceend (); @@ -411,7 +524,11 @@ chldsig(snum) void usage () { - quit (1,"Usage: supfilesrv [ -l | -P | -N | -C <max children> | -H <host> <user> <cryptfile> <supargs> ]\n"); +#ifdef LIBWRAP + quit (1,"Usage: supfilesrv [ -l | -d | -P | -N | -C <max children> | -H <host> <user> <cryptfile> <supargs> ]\n"); +#else + quit (1,"Usage: supfilesrv [ -d | -P | -N | -C <max children> | -H <host> <user> <cryptfile> <supargs> ]\n"); +#endif } void @@ -431,6 +548,9 @@ char **argv; candorcs = FALSE; #endif live = FALSE; +#ifdef LIBWRAP + clog = FALSE; +#endif dbgportsq = FALSE; scmdebug = 0; clienthost = NULL; @@ -444,7 +564,12 @@ char **argv; case 'S': silent = TRUE; break; +#ifdef LIBWRAP case 'l': + clog = TRUE; + break; +#endif + case 'd': live = TRUE; break; case 'P': @@ -702,7 +827,7 @@ srvsetup () setupack = FSETUPSAME; (void) msgsetupack (); if (protver >= 6) longjmp (sjbuf,TRUE); - goaway ("User `%s' not found",xuser); + goaway ("User `%s' not found", xuser); } (void) free (xuser); xuser = salloc (pw->pw_dir); @@ -1062,7 +1187,7 @@ void *v; } switch (t->Tmode&S_IFMT) { case S_IFLNK: - if ((x = readlink (name,slinkname,STRINGLENGTH-1)) <= 0) { + if ((x = readlink (name,slinkname,sizeof slinkname-1)) <= 0) { (void) Tinsert (&denyT,name,FALSE); return (SCMOK); } @@ -1120,12 +1245,12 @@ sendfiles () } } #endif - (void) Tprocess (tl->TLtree,sendone,NULL); + (void) Tprocess (tl->TLtree,sendone, NULL); } /* send directories in reverse order */ for (tl = listTL; tl != NULL; tl = tl->TLnext) { cdprefix (tl->TLprefix); - (void) Trprocess (tl->TLtree,senddir,NULL); + (void) Trprocess (tl->TLtree,senddir, NULL); } x = msgsend (); if (x != SCMOK) @@ -1201,8 +1326,8 @@ void *v; } else { #if 0 - logerr("rcs command failed = %d\n", - WEXITSTATUS(status)); + logerr("rcs command failed = %d\n", + WEXITSTATUS(status)); #endif t->Tflags |= FUPDATE; } @@ -1283,9 +1408,9 @@ void *v; } int -sendfile (t, ap) -TREE *t; -va_list ap; +sendfile(t, ap) + TREE *t; + va_list ap; { register int x, fd; @@ -1345,6 +1470,10 @@ time_t starttime; logerr ("Reason %d: %s",doneack,donereason); goawayreason = donereason; cdprefix ((char *)NULL); + if (collname == NULL) { + logerr ("NULL collection in svrfinishup"); + return; + } (void) snprintf (lognam,sizeof lognam,FILELOGFILE,collname); if ((logfd = open(lognam,O_APPEND|O_WRONLY,0644)) < 0) return; /* can not open file up...error */ @@ -1359,8 +1488,7 @@ time_t starttime; if ((releasename = release) == NULL) releasename = "UNKNOWN"; (void) snprintf (p,sizeof tmpbuf-(p-tmpbuf),"%s %s %d %s\n", - remotehost(),releasename, - FDONESUCCESS-doneack,donereason); + remotehost(),releasename, FDONESUCCESS-doneack,donereason); p += strlen(p); #if MACH /* if we are busy dont get stuck updating the disk if full */ diff --git a/usr.bin/sup/src/supmsg.c b/usr.bin/sup/src/supmsg.c index 5800c2774aa..dff41cddcf0 100644 --- a/usr.bin/sup/src/supmsg.c +++ b/usr.bin/sup/src/supmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supmsg.c,v 1.5 2001/04/29 21:52:16 millert Exp $ */ +/* $OpenBSD: supmsg.c,v 1.6 2001/05/02 22:56:54 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -156,11 +156,12 @@ int msgsetup () if (x == SCMOK) x = readint (&baseino); if (x == SCMOK) x = readint (&listonly); if (x == SCMOK) x = readint (&newonly); - if (x == SCMOK) + if (x == SCMOK) { if (protver < 6) release = (char *)NULL; else x = readstring (&release); + } if (x == SCMOK) x = readmend (); } else { x = writemsg (MSGSETUP); diff --git a/usr.bin/sup/src/supscan.c b/usr.bin/sup/src/supscan.c index c1a1968e06e..b35b2eb8c45 100644 --- a/usr.bin/sup/src/supscan.c +++ b/usr.bin/sup/src/supscan.c @@ -1,4 +1,4 @@ -/* $OpenBSD: supscan.c,v 1.9 2001/04/29 21:52:17 millert Exp $ */ +/* $OpenBSD: supscan.c,v 1.10 2001/05/02 22:56:54 millert Exp $ */ /* * Copyright (c) 1992 Carnegie Mellon University @@ -144,6 +144,7 @@ typedef struct scan_collstruct SCAN_COLLECTION; *********************************************/ int trace; /* -v flag */ +int quiet; /* -q flag */ SCAN_COLLECTION *firstC; /* collection list pointer */ char *collname; /* collection name */ @@ -187,18 +188,22 @@ char **argv; prefix = c->Cprefix; (void) chdir (basedir); scantime = time ((time_t *)NULL); - printf ("SUP Scan for %s starting at %s",collname, - ctime (&scantime)); + if (!quiet) + printf ("SUP Scan for %s starting at %s",collname, + ctime (&scantime)); (void) fflush (stdout); if (!setjmp (sjbuf)) { makescanlists (); /* record names in scan files */ scantime = time ((time_t *)NULL); - printf ("SUP Scan for %s completed at %s",collname, - ctime (&scantime)); + if (!quiet) + printf ("SUP Scan for %s completed at %s", + collname, ctime (&scantime)); } else - printf ("SUP: Scan for %s aborted at %s",collname, + fprintf(stderr, + "SUP: Scan for %s aborted at %s",collname, ctime (&scantime)); - (void) fflush (stdout); + if (!quiet) + (void) fflush (stdout); } while ((c = firstC) != NULL) { firstC = firstC->Cnext; @@ -217,9 +222,9 @@ char **argv; void usage () { - fprintf (stderr,"Usage: supscan [ -v ] collection [ basedir ]\n"); - fprintf (stderr," supscan [ -v ] -f dirfile\n"); - fprintf (stderr," supscan [ -v ] -s\n"); + fprintf (stderr,"Usage: supscan [ -vq ] collection [ basedir ]\n"); + fprintf (stderr," supscan [ -vq ] -f dirfile\n"); + fprintf (stderr," supscan [ -vq ] -s\n"); exit (1); } @@ -234,6 +239,7 @@ char **argv; int fflag,sflag; char *filename = NULL; + quiet = FALSE; trace = FALSE; fflag = FALSE; sflag = FALSE; @@ -247,6 +253,9 @@ char **argv; argv++; filename = argv[1]; break; + case 'q': + quiet = TRUE; + break; case 'v': trace = TRUE; break; @@ -254,7 +263,8 @@ char **argv; sflag = TRUE; break; default: - fprintf (stderr,"supscan: Invalid flag %s ignored\n",argv[1]); + fprintf (stderr,"supscan: Invalid flag %s ignored\n", + argv[1]); (void) fflush (stderr); } --argc; @@ -399,7 +409,7 @@ va_dcl int localhost (host) register char *host; { - static char myhost[STRINGLENGTH]; + static char myhost[MAXHOSTNAMELEN]; static int myhostlen; register int hostlen; diff --git a/usr.bin/sup/src/supservers.8 b/usr.bin/sup/src/supservers.8 index 32b0e169a5f..c831584379a 100644 --- a/usr.bin/sup/src/supservers.8 +++ b/usr.bin/sup/src/supservers.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: supservers.8,v 1.6 1999/06/05 01:21:41 aaron Exp $ +.\" $OpenBSD: supservers.8,v 1.7 2001/05/02 22:56:54 millert Exp $ .\" .\" Copyright (c) 1992 Carnegie Mellon University .\" All Rights Reserved. @@ -37,6 +37,9 @@ supfilesrv, supscan \- sup server processes supfilesrv [ .I +-d +] [ +.I -l ] [ .I @@ -106,7 +109,7 @@ Supfilesrv generally runs as a network server process that listens for connections, and for each connection (double-)forks a process to handle the interaction with the client. -However, with the -l flag, no forking will take place: +However, with the -d flag, no forking will take place: the server will listen for a network connection, handle it, and exit. This is useful for debugging the servers in "live" mode rather than as daemons. @@ -125,6 +128,10 @@ on To suppress log messages, the -q "quiet" flag can be used. +.I supfilesrv +uses libwrap style access control (the /etc/hosts.allow and /etc/hosts.deny +files) with service name "supfilesrv". The -l "log" flag turn on loggin of +accepted connections (denied connections are always logged). Normally the .I supfilesrv @@ -197,10 +204,10 @@ collection whose base directory is not the default. /usr default base directory for a collection .TP -/usr/cs/lib/supfiles/coll.dir +/usr/lib/supfiles/coll.dir directory list file for file server .TP -/usr/cs/lib/supfiles/coll.host +/usr/lib/supfiles/coll.host host list file for system sups. .TP <base-directory>/sup/<collection>/* diff --git a/usr.bin/sup/src/sysent.h b/usr.bin/sup/src/sysent.h index 31a2538fdfc..b5fa0732640 100644 --- a/usr.bin/sup/src/sysent.h +++ b/usr.bin/sup/src/sysent.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysent.h,v 1.4 2001/04/29 21:52:17 millert Exp $ */ +/* $OpenBSD: sysent.h,v 1.5 2001/05/02 22:56:54 millert Exp $ */ /* * Copyright (c) 1991 Carnegie Mellon University @@ -77,7 +77,7 @@ extern gid_t getegid(void); extern int getgroups(int, int *); extern long gethostid(void); extern int sethostid(long); -extern int gethostname(char *, int); +extern int gethostname(char *, size_t); extern int sethostname(const char *, int); extern int getpagesize(void); extern int getpgrp(int); @@ -134,7 +134,7 @@ extern int iwrite(int, int, int, int, void *, int); extern int pioctl(const char *, unsigned long, struct ViceIoctl *, int); extern int setpag(void); #endif -#else defined(__STDC__) +#else /* defined(__STDC__) */ extern gid_t getgid(); extern gid_t getegid(); extern long gethostid(); diff --git a/usr.bin/sup/src/vprintf.c b/usr.bin/sup/src/vprintf.c index 88d40115bfe..5ab180da60f 100644 --- a/usr.bin/sup/src/vprintf.c +++ b/usr.bin/sup/src/vprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vprintf.c,v 1.6 2001/04/29 21:52:17 millert Exp $ */ +/* $OpenBSD: vprintf.c,v 1.7 2001/05/02 22:56:54 millert Exp $ */ /* * Copyright (c) 1991 Carnegie Mellon University @@ -103,7 +103,8 @@ vsprintf(s, fmt, args) FILE fakebuf; fakebuf._flag = STRFLAG; - fakebuf._ptr = s; + fakebuf._base = (void *) s; + fakebuf._ptr = (void *) s; fakebuf._cnt = 32767; _doprnt(fmt, args, &fakebuf); putc('\0', &fakebuf); @@ -120,7 +121,8 @@ vsnprintf(s, n, fmt, args) FILE fakebuf; fakebuf._flag = STRFLAG; - fakebuf._base = fakebuf._ptr = s; + fakebuf._base = (void *) s; + fakebuf._ptr = (void *) s; fakebuf._cnt = n-1; fakebuf._file = -1; _doprnt(fmt, args, &fakebuf); diff --git a/usr.bin/sup/sup/Makefile b/usr.bin/sup/sup/Makefile index 1043cb010ff..bda875745b4 100644 --- a/usr.bin/sup/sup/Makefile +++ b/usr.bin/sup/sup/Makefile @@ -1,12 +1,12 @@ -# $OpenBSD: Makefile,v 1.3 1996/06/26 05:40:01 deraadt Exp $ +# $OpenBSD: Makefile,v 1.4 2001/05/02 22:56:54 millert Exp $ PROG= sup MAN= sup.1 SRCS= supcmain.c supcvers.c supcparse.c supcname.c supcmisc.c supcmeat.c \ - scm.c scmio.c stree.c log.c supmsg.c \ + scm.c scmio.c stree.c log.c supmsg.c read_line.c \ atoo.c errmsg.c expand.c ffilecopy.c filecopy.c nxtarg.c \ path.c quit.c run.c salloc.c skipto.c vprintf.c netcryptvoid.c -LDADDR+=-lutil +LDADD+=-lutil DPADD+= ${LIBUTIL} BINOWN= root BINGRP= daemon diff --git a/usr.bin/sup/supfilesrv/Makefile b/usr.bin/sup/supfilesrv/Makefile index 4c7c8523a98..8cf6245a224 100644 --- a/usr.bin/sup/supfilesrv/Makefile +++ b/usr.bin/sup/supfilesrv/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.7 1997/03/26 00:35:38 deraadt Exp $ +# $OpenBSD: Makefile,v 1.8 2001/05/02 22:56:54 millert Exp $ PROG= supfilesrv MAN= supservers.8 @@ -7,8 +7,8 @@ MLINKS+=supservers.8 supscan.8 SRCS= supfilesrv.c scan.c scm.c scmio.c stree.c log.c supmsg.c \ atoo.c errmsg.c expand.c ffilecopy.c filecopy.c nxtarg.c \ path.c quit.c run.c salloc.c skipto.c vprintf.c netcryptvoid.c -LDADD+= -lutil -DPADD+= ${LIBUTIL} +LDADD+= -lutil -lwrap +DPADD+= ${LIBUTIL} ${LIBWRAP} BINOWN= root BINGRP= daemon BINMODE=555 |