diff options
-rw-r--r-- | usr.bin/rdist/child.c | 122 | ||||
-rw-r--r-- | usr.bin/rdist/client.c | 490 | ||||
-rw-r--r-- | usr.bin/rdist/common.c | 288 | ||||
-rw-r--r-- | usr.bin/rdist/config-data.h | 4 | ||||
-rw-r--r-- | usr.bin/rdist/config-def.h | 4 | ||||
-rw-r--r-- | usr.bin/rdist/config.h | 10 | ||||
-rw-r--r-- | usr.bin/rdist/defs.h | 291 | ||||
-rw-r--r-- | usr.bin/rdist/distopt.c | 122 | ||||
-rw-r--r-- | usr.bin/rdist/docmd.c | 176 | ||||
-rw-r--r-- | usr.bin/rdist/expand.c | 110 | ||||
-rw-r--r-- | usr.bin/rdist/filesys.h (renamed from usr.bin/rdistd/filesys.h) | 30 | ||||
-rw-r--r-- | usr.bin/rdist/gram.y | 118 | ||||
-rw-r--r-- | usr.bin/rdist/isexec.c | 47 | ||||
-rw-r--r-- | usr.bin/rdist/lookup.c | 35 | ||||
-rw-r--r-- | usr.bin/rdist/message.c | 283 | ||||
-rw-r--r-- | usr.bin/rdist/os-openbsd.h | 30 | ||||
-rw-r--r-- | usr.bin/rdist/pathnames.h | 8 | ||||
-rw-r--r-- | usr.bin/rdist/rdist.1 | 40 | ||||
-rw-r--r-- | usr.bin/rdist/rdist.c | 99 | ||||
-rw-r--r-- | usr.bin/rdist/types.h | 56 | ||||
-rw-r--r-- | usr.bin/rdist/version.h | 11 | ||||
-rw-r--r-- | usr.bin/rdistd/filesys-os.c | 116 | ||||
-rw-r--r-- | usr.bin/rdistd/filesys.c | 104 | ||||
-rw-r--r-- | usr.bin/rdistd/rdistd.c | 34 | ||||
-rw-r--r-- | usr.bin/rdistd/server.c | 751 |
25 files changed, 1782 insertions, 1597 deletions
diff --git a/usr.bin/rdist/child.c b/usr.bin/rdist/child.c index 297fc165770..59a8f2c8c87 100644 --- a/usr.bin/rdist/child.c +++ b/usr.bin/rdist/child.c @@ -1,4 +1,4 @@ -/* $OpenBSD: child.c,v 1.11 2002/06/12 06:07:16 mpech Exp $ */ +/* $OpenBSD: child.c,v 1.12 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,21 @@ * SUCH DAMAGE. */ +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: child.c,v 6.28 1996/02/22 19:30:09 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: child.c,v 1.3 1999/11/01 00:20:55 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: child.c,v 1.11 2002/06/12 06:07:16 mpech Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: child.c,v 1.12 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)docmd.c 5.1 (Berkeley) 6/6/85"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)docmd.c 5.1 (Berkeley) 6/6/85"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ @@ -53,7 +56,6 @@ static char copyright[] = * Functions for rdist related to children */ -#include "defs.h" #include <sys/types.h> #include <sys/wait.h> #if defined(NEED_SYS_SELECT_H) @@ -82,17 +84,25 @@ int activechildren = 0; /* Number of active children */ extern int maxchildren; /* Max active children */ static int needscan = FALSE; /* Need to scan children */ +static void removechild(CHILD *); +static CHILD *copychild(CHILD *); +static void addchild(CHILD *); +static void readchild(CHILD *); +static pid_t waitproc(int *, int); +static void reap(int); +static void childscan(void); + /* * Remove a child that has died (exited) * from the list of active children */ -static void removechild(child) - CHILD *child; +static void +removechild(CHILD *child) { CHILD *pc, *prevpc; - debugmsg(DM_CALL, "removechild(%s, %ld, %d) start", - child->c_name, (long)child->c_pid, child->c_readfd); + debugmsg(DM_CALL, "removechild(%s, %d, %d) start", + child->c_name, child->c_pid, child->c_readfd); /* * Find the child in the list @@ -103,8 +113,8 @@ static void removechild(child) break; if (pc == NULL) - error("RemoveChild called with bad child %s %ld %d", - child->c_name, (long)child->c_pid, child->c_readfd); + error("RemoveChild called with bad child %s %d %d", + child->c_name, child->c_pid, child->c_readfd); else { /* * Remove the child @@ -144,8 +154,8 @@ static void removechild(child) /* * Create a totally new copy of a child. */ -static CHILD *copychild(child) - CHILD *child; +static CHILD * +copychild(CHILD *child) { CHILD *newc; @@ -163,8 +173,8 @@ static CHILD *copychild(child) /* * Add a child to the list of children. */ -static void addchild(child) - CHILD *child; +static void +addchild(CHILD *child) { CHILD *pc; @@ -177,29 +187,28 @@ static void addchild(child) ++activechildren; debugmsg(DM_MISC, - "addchild() created '%s' pid %ld fd %d (active=%d)\n", - child->c_name, (long)child->c_pid, child->c_readfd, - activechildren); + "addchild() created '%s' pid %d fd %d (active=%d)\n", + child->c_name, child->c_pid, child->c_readfd, activechildren); } /* * Read input from a child process. */ -static void readchild(child) - CHILD *child; +static void +readchild(CHILD *child) { char rbuf[BUFSIZ]; int amt; - debugmsg(DM_CALL, "[readchild(%s, %ld, %d) start]", - child->c_name, (long)child->c_pid, child->c_readfd); + debugmsg(DM_CALL, "[readchild(%s, %d, %d) start]", + child->c_name, child->c_pid, child->c_readfd); /* * Check that this is a valid child. */ if (child->c_name == NULL || child->c_readfd <= 0) { - debugmsg(DM_MISC, "[readchild(%s, %ld, %d) bad child]", - child->c_name, (long)child->c_pid, child->c_readfd); + debugmsg(DM_MISC, "[readchild(%s, %d, %d) bad child]", + child->c_name, child->c_pid, child->c_readfd); return; } @@ -208,24 +217,24 @@ static void readchild(child) */ while ((amt = read(child->c_readfd, rbuf, sizeof(rbuf))) > 0) { /* XXX remove these debug calls */ - debugmsg(DM_MISC, "[readchild(%s, %ld, %d) got %d bytes]", - child->c_name, (long)child->c_pid, child->c_readfd, amt); + debugmsg(DM_MISC, "[readchild(%s, %d, %d) got %d bytes]", + child->c_name, child->c_pid, child->c_readfd, amt); (void) xwrite(fileno(stdout), rbuf, amt); - debugmsg(DM_MISC, "[readchild(%s, %ld, %d) write done]", - child->c_name, (long)child->c_pid, child->c_readfd); + debugmsg(DM_MISC, "[readchild(%s, %d, %d) write done]", + child->c_name, child->c_pid, child->c_readfd); } - debugmsg(DM_MISC, "readchild(%s, %ld, %d) done: amt = %d errno = %d\n", - child->c_name, (long)child->c_pid, child->c_readfd, amt, errno); + debugmsg(DM_MISC, "readchild(%s, %d, %d) done: amt = %d errno = %d\n", + child->c_name, child->c_pid, child->c_readfd, amt, errno); /* * See if we've reached EOF */ if (amt == 0) - debugmsg(DM_MISC, "readchild(%s, %ld, %d) at EOF\n", - child->c_name, (long)child->c_pid, child->c_readfd); + debugmsg(DM_MISC, "readchild(%s, %d, %d) at EOF\n", + child->c_name, child->c_pid, child->c_readfd); } /* @@ -234,13 +243,12 @@ static void readchild(child) * a process does exit, then the pointer "statval" is set to the * exit status of the exiting process, if statval is not NULL. */ -static pid_t waitproc(statval, block) - int *statval; - int block; +static pid_t +waitproc(int *statval, int block) { WAIT_ARG_TYPE status; - int exitval; pid_t pid; + int exitval; debugmsg(DM_CALL, "waitproc() %s, active children = %d...\n", (block) ? "blocking" : "nonblocking", activechildren); @@ -262,8 +270,8 @@ static pid_t waitproc(statval, block) if (pid > 0 && exitval != 0) { nerrs++; debugmsg(DM_MISC, - "Child process %ld exited with status %d.\n", - (long)pid, exitval); + "Child process %d exited with status %d.\n", + pid, exitval); } if (statval) @@ -279,7 +287,8 @@ static pid_t waitproc(statval, block) * Check to see if any children have exited, and if so, read any unread * input and then remove the child from the list of children. */ -static void reap() +static void +reap(int dummy) { CHILD *pc; int save_errno = errno; @@ -299,8 +308,8 @@ static void reap() */ pid = waitproc(&status, FALSE); debugmsg(DM_MISC, - "reap() pid = %ld status = %d activechildren=%d\n", - (long)pid, status, activechildren); + "reap() pid = %d status = %d activechildren=%d\n", + pid, status, activechildren); /* * See if a child really exited @@ -337,7 +346,8 @@ static void reap() * Scan the children list to find the child that just exited, * read any unread input, then remove it from the list of active children. */ -static void childscan() +static void +childscan(void) { CHILD *pc, *nextpc; @@ -366,7 +376,8 @@ static void childscan() * #endif */ -extern void waitup() +void +waitup(void) { #if defined(HAVE_SELECT) int count; @@ -446,8 +457,8 @@ extern void waitup() if (pc->c_name && kill(pc->c_pid, 0) < 0 && errno == ESRCH) { debugmsg(DM_MISC, - "waitup() proc %ld (%s) died unexpectedly!", - (long)pc->c_pid, pc->c_name); + "waitup() proc %d (%s) died unexpectedly!", + pc->c_pid, pc->c_name); pc->c_state = PSdead; needscan = TRUE; } @@ -478,9 +489,8 @@ extern void waitup() /* * Spawn (create) a new child process for "cmd". */ -extern int spawn(cmd, cmdlist) - struct cmd *cmd; - struct cmd *cmdlist; +int +spawn(struct cmd *cmd, struct cmd *cmdlist) { pid_t pid; int fildes[2]; @@ -573,9 +583,8 @@ extern int spawn(cmd, cmdlist) #if NBIO_TYPE == NBIO_IOCTL #include <sys/ioctl.h> -int setnonblocking(fd, flag) - int fd; - int flag; +int +setnonblocking(int fd, int flag) { int state; @@ -587,9 +596,8 @@ int setnonblocking(fd, flag) #if NBIO_TYPE == NBIO_FCNTL -int setnonblocking(fd, flag) - int fd; - int flag; +int +setnonblocking(int fd, int flag) { int mode; diff --git a/usr.bin/rdist/client.c b/usr.bin/rdist/client.c index 0d50be51ed7..7455d514d76 100644 --- a/usr.bin/rdist/client.c +++ b/usr.bin/rdist/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.17 2003/05/06 22:10:11 millert Exp $ */ +/* $OpenBSD: client.c,v 1.18 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,22 @@ * SUCH DAMAGE. */ +#include "defs.h" +#include "y.tab.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: client.c,v 6.80 1996/02/28 20:34:27 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: client.c,v 1.13 1999/11/01 00:22:14 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: client.c,v 1.17 2003/05/06 22:10:11 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: client.c,v 1.18 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)client.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)client.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ @@ -53,8 +57,6 @@ static char copyright[] = * Routines used in client mode to communicate with remove server. */ -#include "defs.h" -#include "y.tab.h" /* * Update status @@ -63,7 +65,7 @@ static char copyright[] = #define US_NOENT 1 /* Entry does not exist */ #define US_OUTDATE 2 /* Entry is out of date */ #define US_DOCOMP 3 /* Do a binary comparison */ -#define US_MODE 4 /* Modes of file differ */ +#define US_CHMOG 4 /* Modes or ownership of file differ */ struct linkbuf *ihead = NULL; /* list of files with more than one link */ char buf[BUFSIZ]; /* general purpose buffer */ @@ -74,14 +76,26 @@ char *ptarget; /* pointer to end of target name */ char *Tdest; /* pointer to last T dest*/ struct namelist *updfilelist = NULL; /* List of updated files */ -static int sendit(); +static void runspecial(char *, opt_t, char *, int); +static void addcmdspecialfile(char *, char *, int); +static void freecmdspecialfiles(void); +static struct linkbuf *linkinfo(struct stat *); +static int sendhardlink(opt_t, struct linkbuf *, char *, int); +static int sendfile(char *, opt_t, struct stat *, char *, char *, int); +static int rmchk(opt_t); +static int senddir(char *, opt_t, struct stat *, char *, char *, int); +static int sendlink(char *, opt_t, struct stat *, char *, char *, int); +static int update(char *, opt_t, struct stat *); +static int dostat(char *, struct stat *, opt_t); +static int statupdate(int, char *, opt_t, char *, int, struct stat *, char *, char *); +static int fullupdate(int, char *, opt_t, char *, int, struct stat *, char *, char *); +static int sendit(char *, opt_t, int); /* * return remote file pathname (relative from target) */ -char *remfilename(src, dest, path, rname, destdir) - char *src, *dest, *path, *rname; - int destdir; +char * +remfilename(char *src, char *dest, char *path, char *rname, int destdir) { extern struct namelist *filelist; char *lname, *cp; @@ -109,7 +123,7 @@ char *remfilename(src, dest, path, rname, destdir) if (path && *path) { cp = strrchr(path, '/'); if (cp == NULL) - (void) snprintf(buff, sizeof buff, "%s/%s", dest, path); + (void) snprintf(buff, sizeof(buff), "%s/%s", dest, path); else { srclen = strlen(src); pathlen = strlen(path); @@ -127,14 +141,14 @@ char *remfilename(src, dest, path, rname, destdir) } } if ((*cp != '/') && *cp) - (void) snprintf(buff, sizeof buff, - "%s/%s", dest, cp); + (void) snprintf(buff, sizeof(buff), "%s/%s", + dest, cp); else - (void) snprintf(buff, sizeof buff, - "%s%s", dest, cp); + (void) snprintf(buff, sizeof(buff), "%s%s", + dest, cp); } } else - strlcpy(lname, dest, buf + sizeof buff - lname); + (void) strlcpy(lname, dest, buf + sizeof buff - lname); debugmsg(DM_MISC, "remfilename: remote filename=%s\n", lname); @@ -144,9 +158,8 @@ char *remfilename(src, dest, path, rname, destdir) /* * Return true if name is in the list. */ -int inlist(list, file) - struct namelist *list; - char *file; +int +inlist(struct namelist *list, char *file) { struct namelist *nl; @@ -159,11 +172,8 @@ int inlist(list, file) /* * Run any special commands for this file */ -static void runspecial(starget, opts, rname, destdir) - char *starget; - opt_t opts; - char *rname; - int destdir; +static void +runspecial(char *starget, opt_t opts, char *rname, int destdir) { struct subcmd *sc; extern struct subcmd *subcmds; @@ -195,10 +205,8 @@ static void runspecial(starget, opts, rname, destdir) * If we're doing a target with a "cmdspecial" in it, then * save the name of the file being updated for use with "cmdspecial". */ -static void addcmdspecialfile(starget, rname, destdir) - char *starget; - char *rname; - int destdir; +static void +addcmdspecialfile(char *starget, char *rname, int destdir) { char *rfile; struct namelist *new; @@ -228,7 +236,8 @@ static void addcmdspecialfile(starget, rname, destdir) /* * Free the file list */ -static void freecmdspecialfiles() +static void +freecmdspecialfiles(void) { struct namelist *ptr, *save; @@ -247,10 +256,8 @@ static void freecmdspecialfiles() /* * Run commands for an entire cmd */ -extern void runcmdspecial(cmd, filev, opts) - struct cmd *cmd; - char **filev; - opt_t opts; +void +runcmdspecial(struct cmd *cmd, opt_t opts) { struct subcmd *sc; struct namelist *f; @@ -292,8 +299,8 @@ extern void runcmdspecial(cmd, filev, opts) /* * For security, reject filenames that contains a newline */ -int checkfilename(name) - char *name; +int +checkfilename(char *name) { char *cp; @@ -310,8 +317,8 @@ int checkfilename(name) return(0); } -void freelinkinfo(lp) - struct linkbuf *lp; +void +freelinkinfo(struct linkbuf *lp) { if (lp->pathname) free(lp->pathname); @@ -325,8 +332,8 @@ void freelinkinfo(lp) /* * Save and retrieve hard link info */ -static struct linkbuf *linkinfo(statp) - struct stat *statp; +static struct linkbuf * +linkinfo(struct stat *statp) { struct linkbuf *lp; @@ -356,29 +363,31 @@ static struct linkbuf *linkinfo(statp) /* * Send a hardlink */ -static int sendhardlink(opts, lp, rname, destdir) - opt_t opts; - struct linkbuf *lp; - char *rname; - int destdir; +static int +sendhardlink(opt_t opts, struct linkbuf *lp, char *rname, int destdir) { static char buff[MAXPATHLEN]; + char *lname; /* name of file to link to */ + char ername[MAXPATHLEN*4], elname[MAXPATHLEN*4]; debugmsg(DM_MISC, "sendhardlink: rname='%s' pathname='%s' src='%s' target='%s'\n", - rname, lp->pathname ? lp->pathname : "(null)", lp->src - ? lp->src : "(null)", lp->target ? lp->target : "(null)"); + rname, lp->pathname ? lp->pathname : "", + lp->src ? lp->src : "", lp->target ? lp->target : ""); if (lp->target == NULL) - (void) sendcmd(C_RECVHARDLINK, "%o %s %s", - opts, lp->pathname, rname); + lname = lp->pathname; else { - strlcpy(buff, remfilename(lp->src, lp->target, - lp->pathname, rname, destdir), sizeof buff); - debugmsg(DM_MISC, "sendhardlink: lname=%s\n", buff); - (void) sendcmd(C_RECVHARDLINK, "%o %s %s", - opts, buff, rname); + lname = buff; + strlcpy(lname, remfilename(lp->src, lp->target, + lp->pathname, rname, + destdir), sizeof(buff)); + debugmsg(DM_MISC, "sendhardlink: lname=%s\n", lname); } + ENCODE(elname, lname); + ENCODE(ername, rname); + (void) sendcmd(C_RECVHARDLINK, "%o %s %s", + opts, elname, ername); return(response()); } @@ -386,15 +395,13 @@ static int sendhardlink(opts, lp, rname, destdir) /* * Send a file */ -static int sendfile(rname, opts, stb, user, group, destdir) - char *rname; - opt_t opts; - struct stat *stb; - char *user, *group; - int destdir; +static int +sendfile(char *rname, opt_t opts, struct stat *stb, char *user, + char *group, int destdir) { int goterr, f; off_t i; + char ername[MAXPATHLEN*4]; if (stb->st_nlink > 1) { struct linkbuf *lp; @@ -411,18 +418,20 @@ static int sendfile(rname, opts, stb, user, group, destdir) /* * Send file info */ + ENCODE(ername, rname); + (void) sendcmd(C_RECVREG, "%o %04o %ld %ld %ld %s %s %s", - opts, stb->st_mode & 07777, - (long) stb->st_size, + opts, stb->st_mode & 07777, (long) stb->st_size, stb->st_mtime, stb->st_atime, - user, group, rname); + user, group, ername); if (response() < 0) { (void) close(f); return(-1); } - debugmsg(DM_MISC, "Send file '%s' %d bytes\n", - rname, (long) stb->st_size); + + debugmsg(DM_MISC, "Send file '%s' %ld bytes\n", rname, + (long) stb->st_size); /* * Set remote time out alarm handler. @@ -434,12 +443,12 @@ static int sendfile(rname, opts, stb, user, group, destdir) */ goterr = 0; for (i = 0; i < stb->st_size; i += BUFSIZ) { - int amt = BUFSIZ; + off_t amt = BUFSIZ; (void) alarm(rtimeout); if (i + amt > stb->st_size) amt = stb->st_size - i; - if (read(f, buf, amt) != amt) { + if (read(f, buf, (size_t) amt) != (ssize_t) amt) { error("%s: File changed size", target); err(); ++goterr; @@ -451,8 +460,8 @@ static int sendfile(rname, opts, stb, user, group, destdir) * this situation gracefully. */ } - if (xwrite(rem_w, buf, amt) < 0) { - error("%s: Error writing to client: %s", + if (xwrite(rem_w, buf, (size_t) amt) < 0) { + error("%s: Error writing to client: %s", target, SYSERR); err(); ++goterr; @@ -495,13 +504,14 @@ static int sendfile(rname, opts, stb, user, group, destdir) * Return 0 if nothing happened. * Return > 0 if anything is updated. */ -static int rmchk(opts) - opt_t opts; +static int +rmchk(opt_t opts) { u_char *s; struct stat stb; int didupdate = 0; int n; + char targ[MAXPATHLEN*4]; debugmsg(DM_CALL, "rmchk()\n"); @@ -526,8 +536,15 @@ static int rmchk(opts) * CC_NO -- file exists - DON'T remove. * CC_YES -- file doesn't exist - REMOVE. */ - snprintf(ptarget, target + sizeof(target) - ptarget, - "%s%s", (ptarget[-1] == '/' ? "" : "/"), s); + if (DECODE(targ, (char *) s) == -1) { + error("rmchk: cannot decode file"); + return(-1); + } + (void) snprintf(ptarget, + sizeof(target) - (ptarget - target), + "%s%s", + (ptarget[-1] == '/' ? "" : "/"), + targ); debugmsg(DM_MISC, "check %s\n", target); if (except(target)) (void) sendcmd(CC_NO, NULL); @@ -577,45 +594,44 @@ static int rmchk(opts) * Return 0 if nothing happened. * Return > 0 if anything is updated. */ -static int senddir(rname, opts, stb, user, group, destdir) - char *rname; - opt_t opts; - struct stat *stb; - char *user, *group; - int destdir; +static int +senddir(char *rname, opt_t opts, struct stat *stb, char *user, + char *group, int destdir) { DIRENTRY *dp; DIR *d; char *optarget, *cp; int len; int didupdate = 0; - - /* - * Don't descend into directory - */ - if (IS_ON(opts, DO_NODESCEND)) - return(0); - - if ((d = opendir(target)) == NULL) { - error("%s: opendir failed: %s", target, SYSERR); - return(-1); - } + char ername[MAXPATHLEN*4]; /* * Send recvdir command in recvit() format. */ + ENCODE(ername, rname); (void) sendcmd(C_RECVDIR, "%o %04o 0 0 0 %s %s %s", - opts, stb->st_mode & 07777, user, group, rname); + opts, stb->st_mode & 07777, user, group, ername); if (response() < 0) return(-1); + /* + * Don't descend into directory + */ + if (IS_ON(opts, DO_NODESCEND)) + return(0); + if (IS_ON(opts, DO_REMOVE)) if (rmchk(opts) > 0) ++didupdate; + if ((d = opendir(target)) == NULL) { + error("%s: opendir failed: %s", target, SYSERR); + return(-1); + } + optarget = ptarget; len = ptarget - target; - while ((dp = readdir(d))) { + while ((dp = readdir(d)) != NULL) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; @@ -628,8 +644,8 @@ static int senddir(rname, opts, stb, user, group, destdir) if (ptarget[-1] != '/') *ptarget++ = '/'; cp = dp->d_name; - while ((*ptarget++ = *cp++)) - ; + while ((*ptarget++ = *cp++) != '\0') + continue; ptarget--; if (sendit(dp->d_name, opts, destdir) > 0) didupdate = 1; @@ -648,18 +664,15 @@ static int senddir(rname, opts, stb, user, group, destdir) /* * Send a link */ -static int sendlink(rname, opts, stb, user, group, destdir) - char *rname; - opt_t opts; - struct stat *stb; - char *user; - char *group; - int destdir; +static int +sendlink(char *rname, opt_t opts, struct stat *stb, char *user, + char *group, int destdir) { int f, n; static char tbuf[BUFSIZ]; char lbuf[MAXPATHLEN]; u_char *s; + char ername[MAXPATHLEN*4]; debugmsg(DM_CALL, "sendlink(%s, %x, stb, %d)\n", rname, opts, destdir); @@ -673,11 +686,11 @@ static int sendlink(rname, opts, stb, user, group, destdir) /* * Gather and send basic link info */ + ENCODE(ername, rname); (void) sendcmd(C_RECVSYMLINK, "%o %04o %ld %ld %ld %s %s %s", - opts, stb->st_mode & 07777, - (long) stb->st_size, + opts, stb->st_mode & 07777, (long) stb->st_size, stb->st_mtime, stb->st_atime, - user, group, rname); + user, group, ername); if (response() < 0) return(-1); @@ -690,8 +703,9 @@ static int sendlink(rname, opts, stb, user, group, destdir) error("%s: readlink failed", target); err(); } - (void) snprintf(tbuf, sizeof tbuf, "%.*s", (int) stb->st_size, lbuf); - (void) sendcmd(C_NONE, "%s\n", tbuf); + (void) snprintf(tbuf, sizeof(tbuf), "%.*s", (int) stb->st_size, lbuf); + ENCODE(ername, tbuf); + (void) sendcmd(C_NONE, "%s\n", ername); if (n != stb->st_size) { error("%s: file changed size", target); @@ -765,12 +779,10 @@ static int sendlink(rname, opts, stb, user, group, destdir) * US_NOENT - remote doesn't exist * US_OUTDATE - out of date * US_DOCOMP - comparing binaries to determine if out of date - * US_MODE - File modes do not match + * US_CHMOG - File modes or ownership do not match */ -static int update(rname, opts, statp) - char *rname; - opt_t opts; - struct stat *statp; +static int +update(char *rname, opt_t opts, struct stat *statp) { off_t size; time_t mtime; @@ -779,6 +791,7 @@ static int update(rname, opts, statp) char *owner = NULL, *group = NULL; int done, n; u_char *cp; + char ername[MAXPATHLEN*4]; debugmsg(DM_CALL, "update(%s, 0x%x, 0x%x)\n", rname, opts, statp); @@ -791,7 +804,8 @@ static int update(rname, opts, statp) /* * Check to see if the file exists on the remote machine. */ - (void) sendcmd(C_QUERY, "%s", rname); + ENCODE(ername, rname); + (void) sendcmd(C_QUERY, "%s", ername); for (done = 0; !done;) { n = remline(cp = respbuff, sizeof(respbuff), TRUE); @@ -843,7 +857,7 @@ static int update(rname, opts, statp) /* Goto top of loop */ default: - error("update: unexpected response to query '%s'", cp); + error("update: unexpected response to query '%s'", respbuff); return(US_NOTHING); } } @@ -860,7 +874,7 @@ static int update(rname, opts, statp) /* * Parse size */ - size = strtol(cp, (char **)&cp, 10); + size = (off_t) strtol(cp, (char **)&cp, 10); if (*cp++ != ' ') { error("update: size not delimited"); return(US_NOTHING); @@ -912,8 +926,8 @@ static int update(rname, opts, statp) debugmsg(DM_MISC, "update(%s,) local mode %04o remote mode %04o\n", rname, lmode, rmode); - debugmsg(DM_MISC, "update(%s,) size %d mtime %d owner '%s' grp '%s'\n", - rname, (int) size, mtime, owner, group); + debugmsg(DM_MISC, "update(%s,) size %ld mtime %d owner '%s' grp '%s'\n", + rname, (long) size, mtime, owner, group); if (statp->st_mtime != mtime) { if (statp->st_mtime < mtime && IS_ON(opts, DO_YOUNGER)) { @@ -925,24 +939,18 @@ static int update(rname, opts, statp) return(US_OUTDATE); } - /* - * If the mode of a file does not match the local mode, the - * whole file is updated. This is done both to insure that - * a bogus version of the file has not been installed and to - * avoid having to handle weird cases of chmod'ing symlinks - * and such. - */ + if (statp->st_size != size) { + debugmsg(DM_MISC, "size does not match (%ld != %ld).\n", + (long) statp->st_size, (long) size); + return(US_OUTDATE); + } + if (!IS_ON(opts, DO_NOCHKMODE) && lmode != rmode) { debugmsg(DM_MISC, "modes do not match (%04o != %04o).\n", lmode, rmode); - return(US_OUTDATE); + return(US_CHMOG); } - if (statp->st_size != size) { - debugmsg(DM_MISC, "size does not match (%d != %d).\n", - (int) statp->st_size, size); - return(US_OUTDATE); - } /* * Check ownership @@ -956,20 +964,21 @@ static int update(rname, opts, statp) "owner does not match (%s != %s).\n", getusername(statp->st_uid, target, opts), owner); - return(US_OUTDATE); + return(US_CHMOG); } } else { /* * Check numerically. * Allow negative numbers. */ - while (*owner && !isdigit(*owner) && (*owner != '-')) + while (*owner && !isdigit((unsigned char)*owner) && + (*owner != '-')) ++owner; - if (owner && atoi(owner) != statp->st_uid) { + if (owner && (UID_T) atoi(owner) != statp->st_uid) { debugmsg(DM_MISC, "owner does not match (%d != %s).\n", statp->st_uid, owner); - return(US_OUTDATE); + return(US_CHMOG); } } } @@ -983,18 +992,19 @@ static int update(rname, opts, statp) "group does not match (%s != %s).\n", getgroupname(statp->st_gid, target, opts), group); - return(US_OUTDATE); + return(US_CHMOG); } } else { /* Check numerically */ /* Allow negative gid */ - while (*group && !isdigit(*group) && (*group != '-')) + while (*group && !isdigit((unsigned char) *group) && + (*group != '-')) ++group; - if (group && atoi(group) != statp->st_gid) { + if (group && (UID_T) atoi(group) != statp->st_gid) { debugmsg(DM_MISC, "group does not match (%d != %s).\n", statp->st_gid, group); - return(US_OUTDATE); + return(US_CHMOG); } } } @@ -1005,10 +1015,8 @@ static int update(rname, opts, statp) /* * Stat a file */ -static int dostat(file, statbuf, opts) - char *file; - struct stat *statbuf; - opt_t opts; +static int +dostat(char *file, struct stat *statbuf, opt_t opts) { int s; @@ -1024,6 +1032,96 @@ static int dostat(file, statbuf, opts) } /* + * We need to just change file info. + */ +static int +statupdate(int u, char *target, opt_t opts, char *rname, int destdir, + struct stat *st, char *user, char *group) +{ + int rv = 0; + char ername[MAXPATHLEN*4]; + int lmode = st->st_mode & 07777; + + if (u == US_CHMOG) { + if (IS_ON(opts, DO_VERIFY)) { + message(MT_INFO, + "%s: need to change to perm %04o, owner %s, group %s", + target, lmode, user, group); + runspecial(target, opts, rname, destdir); + } + else { + message(MT_CHANGE, "%s: change to perm %04o, owner %s, group %s", + target, lmode, user, group); + ENCODE(ername, rname); + (void) sendcmd(C_CHMOG, "%o %04o %s %s %s", + opts, lmode, user, group, ername); + (void) response(); + } + rv = 1; + } + return(rv); +} + + +/* + * We need to install/update: + */ +static int +fullupdate(int u, char *target, opt_t opts, char *rname, int destdir, + struct stat *st, char *user, char *group) +{ + /* + * No entry - need to install + */ + if (u == US_NOENT) { + if (IS_ON(opts, DO_VERIFY)) { + message(MT_INFO, "%s: need to install", target); + runspecial(target, opts, rname, destdir); + return(1); + } + if (!IS_ON(opts, DO_QUIET)) + message(MT_CHANGE, "%s: installing", target); + FLAG_OFF(opts, (DO_COMPARE|DO_REMOVE)); + } + + /* + * Handle special file types, including directories and symlinks + */ + if (S_ISDIR(st->st_mode)) { + if (senddir(rname, opts, st, user, group, destdir) > 0) + return(1); + return(0); + } else if (S_ISLNK(st->st_mode)) { + if (u == US_NOENT) + FLAG_ON(opts, DO_COMPARE); + /* + * Since we always send link info to the server + * so the server can determine if the remote link + * is correct, we never get any acknowledge meant + * from the server whether the link was really + * updated or not. + */ + (void) sendlink(rname, opts, st, user, group, destdir); + return(0); + } else if (S_ISREG(st->st_mode)) { + if (u == US_OUTDATE) { + if (IS_ON(opts, DO_VERIFY)) { + message(MT_INFO, "%s: need to update", target); + runspecial(target, opts, rname, destdir); + return(1); + } + if (!IS_ON(opts, DO_QUIET)) + message(MT_CHANGE, "%s: updating", target); + } + return (sendfile(rname, opts, st, user, group, destdir) == 0); + } else { + message(MT_INFO, "%s: unknown file type 0%o", target, + st->st_mode); + return(0); + } +} + +/* * Transfer the file or directory in target[]. * rname is the name of the file on the remote host. * @@ -1031,16 +1129,12 @@ static int dostat(file, statbuf, opts) * Return 0 if nothing happened. * Return > 0 if anything is updated. */ -static int sendit(rname, opts, destdir) - char *rname; - opt_t opts; - int destdir; +static int +sendit(char *rname, opt_t opts, int destdir) { static struct stat stb; - extern struct subcmd *subcmds; char *user, *group; int u, len; - int didupdate = 0; /* * Remove possible accidental newline @@ -1077,80 +1171,28 @@ static int sendit(rname, opts, destdir) return(0); } - /* - * File mode needs changing - */ - if (u == US_MODE) { - if (IS_ON(opts, DO_VERIFY)) { - message(MT_INFO, "%s: need to chmod to %04o", - target, stb.st_mode & 07777); - runspecial(target, opts, rname, destdir); - return(1); - } - message(MT_CHANGE, "%s: chmod to %04o", - target, stb.st_mode & 07777); - (void) sendcmd(C_CHMOD, "%o %04o %s", - opts, stb.st_mode & 07777, rname); - (void) response(); - return(1); - } - user = getusername(stb.st_uid, target, opts); group = getgroupname(stb.st_gid, target, opts); - /* - * No entry - need to install - */ - if (u == US_NOENT) { - if (IS_ON(opts, DO_VERIFY)) { - message(MT_INFO, "%s: need to install", target); - runspecial(target, opts, rname, destdir); - return(1); - } - if (!IS_ON(opts, DO_QUIET)) - message(MT_CHANGE, "%s: installing", target); - FLAG_OFF(opts, (DO_COMPARE|DO_REMOVE)); - } + if (u == US_CHMOG && IS_OFF(opts, DO_UPDATEPERM)) + u = US_OUTDATE; - /* - * Handle special file types, including directories and symlinks - */ - if (S_ISDIR(stb.st_mode)) { - if (senddir(rname, opts, &stb, user, group, destdir) > 0) - didupdate = 1; - } else if (S_ISLNK(stb.st_mode)) { - if (u != US_NOENT) - FLAG_ON(opts, DO_COMPARE); - /* - * Since we always send link info to the server - * so the server can determine if the remote link - * is correct, we never get any acknowledge meant - * from the server whether the link was really - * updated or not. - */ - (void) sendlink(rname, opts, &stb, user, group, destdir); - } else if (S_ISREG(stb.st_mode)) { - if (u == US_OUTDATE) { - if (IS_ON(opts, DO_VERIFY)) { - message(MT_INFO, "%s: need to update", target); - runspecial(target, opts, rname, destdir); - return(1); - } - if (!IS_ON(opts, DO_QUIET)) - message(MT_CHANGE, "%s: updating", target); - } - if (sendfile(rname, opts, &stb, user, group, destdir) == 0) - didupdate = 1; - } else - error("%s: unknown file type", target); + if (u == US_NOENT || u == US_OUTDATE || u == US_DOCOMP) + return(fullupdate(u, target, opts, rname, destdir, &stb, + user, group)); - return(didupdate); + if (u == US_CHMOG) + return(statupdate(u, target, opts, rname, destdir, &stb, + user, group)); + + return(0); } /* * Remove temporary files and do any cleanup operations before exiting. */ -extern void cleanup() +void +cleanup(int dummy) { char *file; #ifdef USE_STATDB @@ -1159,7 +1201,7 @@ extern void cleanup() (void) unlink(statfile); #endif - if ((file = getnotifyfile())) + if ((file = getnotifyfile()) != NULL) (void) unlink(file); } @@ -1172,14 +1214,13 @@ extern void cleanup() * Return 0 if nothing updated. * Return > 0 if something was updated. */ -extern int install(src, dest, ddir, destdir, opts) - char *src, *dest; - int ddir, destdir; - opt_t opts; +int +install(char *src, char *dest, int ddir, int destdir, opt_t opts) { static char destcopy[MAXPATHLEN]; char *rname; int didupdate = 0; + char ername[MAXPATHLEN*4]; debugmsg(DM_CALL, "install(src=%s,dest=%s,ddir=%d,destdir=%d,opts=%d) start\n", @@ -1190,7 +1231,7 @@ extern int install(src, dest, ddir, destdir, opts) if (IS_ON(opts, DO_WHOLE)) source[0] = CNULL; else - (void) strlcpy(source, src, sizeof source); + (void) strlcpy(source, src, sizeof(source)); if (dest == NULL) { FLAG_OFF(opts, DO_WHOLE); /* WHOLE only useful if renaming */ @@ -1205,7 +1246,7 @@ extern int install(src, dest, ddir, destdir, opts) char *cp; cp = getondistoptlist(opts); - (void) snprintf(buff, sizeof buff, "%s%s%s %s %s", + (void) snprintf(buff, sizeof(buff), "%s%s%s %s %s", IS_ON(opts, DO_VERIFY) ? "verify" : "install", (cp) ? " -o" : "", (cp) ? cp : "", src, dest); @@ -1250,10 +1291,11 @@ extern int install(src, dest, ddir, destdir, opts) /* * Pass the destination file/directory name to remote. */ + ENCODE(ername, dest); if (ddir) - (void) sendcmd(C_DIRTARGET, "%o %s", opts, dest); + (void) sendcmd(C_DIRTARGET, "%o %s", opts, ername); else - (void) sendcmd(C_TARGET, "%o %s", opts, dest); + (void) sendcmd(C_TARGET, "%o %s", opts, ername); if (response() < 0) return(-1); @@ -1264,7 +1306,7 @@ extern int install(src, dest, ddir, destdir, opts) * hardlink info. */ if (destdir || (src && dest && strcmp(src, dest))) { - (void) strlcpy(destcopy, dest, sizeof destcopy); + (void) strlcpy(destcopy, dest, sizeof(destcopy)); Tdest = destcopy; } diff --git a/usr.bin/rdist/common.c b/usr.bin/rdist/common.c index f29b246d458..4d2e3f69df0 100644 --- a/usr.bin/rdist/common.c +++ b/usr.bin/rdist/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.19 2003/05/06 21:52:25 millert Exp $ */ +/* $OpenBSD: common.c,v 1.20 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,20 @@ * SUCH DAMAGE. */ +#include "defs.h" #ifndef lint #if 0 -static char RCSid[] = -"$From: common.c,v 6.82 1998/03/23 23:27:33 michaelc Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: common.c,v 1.8 2001/03/12 18:16:36 kim Exp $"; #else -static char RCSid[] = -"$OpenBSD: common.c,v 1.19 2003/05/06 21:52:25 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: common.c,v 1.20 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)common.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)common.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* !lint */ @@ -53,12 +55,11 @@ static char copyright[] = * Things common to both the client and server. */ -#include "defs.h" #if defined(NEED_UTIME_H) #include <utime.h> #endif /* defined(NEED_UTIME_H) */ -#include <sys/socket.h> #include <sys/wait.h> +#include <sys/socket.h> /* * Variables common to both client and server @@ -76,7 +77,7 @@ char *progname = NULL; /* Name of this program */ int rem_r = -1; /* Client file descriptor */ int rem_w = -1; /* Client file descriptor */ struct passwd *pw = NULL; /* Local user's pwd entry */ -int contimedout = FALSE; /* Connection timed out */ +volatile sig_atomic_t contimedout = FALSE; /* Connection timed out */ int proto_version = -1; /* Protocol version */ int rtimeout = RTIMEOUT; /* Response time out */ jmp_buf finish_jmpbuf; /* Finish() jmp buffer */ @@ -84,14 +85,18 @@ int setjmp_ok = FALSE; /* setjmp()/longjmp() status */ char **realargv; /* Real main() argv */ int realargc; /* Real main() argc */ opt_t options = 0; /* Global install options */ +char defowner[64] = "bin"; /* Default owner */ +char defgroup[64] = "bin"; /* Default group */ + +static int sendcmdmsg(int, char *, size_t); +static int remread(int, u_char *, int); +static int remmore(void); /* * Front end to write() that handles partial write() requests. */ -extern WRITE_RETURN_T xwrite(fd, buf, len) - int fd; - void *buf; - WRITE_AMT_T len; +WRITE_RETURN_T +xwrite(int fd, void *buf, WRITE_AMT_T len) { WRITE_AMT_T nleft = len; WRITE_RETURN_T nwritten; @@ -109,39 +114,18 @@ extern WRITE_RETURN_T xwrite(fd, buf, len) } /* - * Set program name - */ -extern void setprogname(argv) - char **argv; -{ - char *cp; - - if (!progname) { - progname = xstrdup(argv[0]); - if ((cp = strrchr(progname, '/'))) - progname = cp + 1; - } -} - -/* * Do run-time initialization */ -extern int init(argc, argv, envp) - /*ARGSUSED*/ - int argc; - char **argv; - char **envp; +int +init(int argc, char **argv, char **envp) { int i; - char *cp; #ifdef SIGSEGV_CHECK if (!isserver) (void) signal(SIGSEGV, sighandler); #endif - setprogname(argv); - /* * Save a copy of our argc and argv before setargs() overwrites them */ @@ -161,14 +145,16 @@ extern int init(argc, argv, envp) return(-1); } - debugmsg(DM_MISC, "UserID = %d pwname = '%s' home = '%s'\n", + debugmsg(DM_MISC, "UserID = %u pwname = '%s' home = '%s'\n", userid, pw->pw_name, pw->pw_dir); homedir = xstrdup(pw->pw_dir); locuser = xstrdup(pw->pw_name); groupid = pw->pw_gid; gethostname(host, sizeof(host)); +#if 0 if ((cp = strchr(host, '.')) != NULL) *cp = CNULL; +#endif /* * If we're not root, disable paranoid ownership checks @@ -185,14 +171,15 @@ extern int init(argc, argv, envp) /* * Finish things up before ending. */ -extern void finish() +void +finish(void) { extern jmp_buf finish_jmpbuf; debugmsg(DM_CALL, "finish() called: do_fork = %d amchild = %d isserver = %d", do_fork, amchild, isserver); - cleanup(); + cleanup(0); /* * There's no valid finish_jmpbuf for the rdist master parent. @@ -219,7 +206,8 @@ extern void finish() /* * Handle lost connections */ -extern void lostconn() +void +lostconn(void) { /* Prevent looping */ (void) signal(SIGPIPE, SIG_IGN); @@ -236,10 +224,11 @@ extern void lostconn() /* * Do a core dump */ -extern void coredump() +void +coredump(void) { - error("Segmentation violation - dumping core [PID = %ld, %s]", - (long)getpid(), + error("Segmentation violation - dumping core [PID = %d, %s]", + getpid(), (isserver) ? "isserver" : ((amchild) ? "amchild" : "parent")); abort(); /*NOTREACHED*/ @@ -250,8 +239,8 @@ extern void coredump() /* * General signal handler */ -extern void sighandler(sig) - int sig; +void +sighandler(int sig) { int save_errno = errno; @@ -296,10 +285,8 @@ extern void sighandler(sig) * Function to actually send the command char and message to the * remote host. */ -static int sendcmdmsg(cmd, msg, msgsize) - char cmd; - char *msg; - size_t msgsize; +static int +sendcmdmsg(int cmd, char *msg, size_t msgsize) { int len; @@ -336,7 +323,8 @@ static int sendcmdmsg(cmd, msg, msgsize) /* * Stdarg frontend to sendcmdmsg() */ -extern int sendcmd(char cmd, char *fmt, ...) +int +sendcmd(char cmd, char *fmt, ...) { static char buf[BUFSIZ]; va_list args; @@ -344,7 +332,7 @@ extern int sendcmd(char cmd, char *fmt, ...) va_start(args, fmt); if (fmt) (void) vsnprintf(buf + (cmd != C_NONE), - sizeof(buf) - (cmd != C_NONE), fmt, args); + sizeof(buf) - (cmd != C_NONE), fmt, args); else buf[1] = CNULL; va_end(args); @@ -357,7 +345,8 @@ extern int sendcmd(char cmd, char *fmt, ...) /* * Varargs frontend to sendcmdmsg() */ -extern int sendcmd(va_alist) +int +sendcmd(va_alist) va_dcl { static char buf[BUFSIZ]; @@ -371,7 +360,7 @@ extern int sendcmd(va_alist) fmt = va_arg(args, char *); if (fmt) (void) vsnprintf(buf + (cmd != C_NONE), - sizeof(buf) - (cmd != C_NONE), fmt, args); + sizeof(buf) - (cmd != C_NONE), fmt, args); else buf[1] = CNULL; va_end(args); @@ -380,28 +369,6 @@ extern int sendcmd(va_alist) } #endif /* ARG_TYPE == ARG_VARARGS */ -#if !defined(ARG_TYPE) -/* - * Stupid frontend to sendcmdmsg() - */ -/*VARARGS2*/ -extern int sendcmd(cmd, fmt, a1, a2, a3, a4, a5, a6, a7, a8) - char cmd; - char *fmt; -{ - static char buf[BUFSIZ]; - - if (fmt) - (void) snprintf(buf + (cmd != C_NONE), - sizeof(buf) - (cmd != C_NONE), - fmt, a1, a2, a3, a4, a5, a6, a7, a8); - else - buf[1] = CNULL; - - return(sendcmdmsg(cmd, buf, sizeof(buf))); -} -#endif /* !ARG_TYPE */ - /* * Internal variables and routines for reading lines from the remote. */ @@ -414,15 +381,14 @@ static int remleft; /* * Back end to remote read() */ -static int remread(fd, buf, bufsiz) - int fd; - u_char *buf; - int bufsiz; +static int +remread(int fd, u_char *buf, int bufsiz) { return(read(fd, (char *)buf, bufsiz)); } -static int remmore() +static int +remmore(void) { (void) signal(SIGALRM, sighandler); (void) alarm(rtimeout); @@ -447,10 +413,8 @@ static int remmore() * errors, call cleanup() or lostconn(). In other words, unless * the third argument is nonzero, this routine never returns failure. */ -extern int remline(buffer, space, doclean) - u_char *buffer; - int space; - int doclean; +int +remline(u_char *buffer, int space, int doclean) { int c, left = space; u_char *p = buffer; @@ -485,7 +449,7 @@ extern int remline(buffer, space, doclean) if (debug) { static char mbuf[BUFSIZ]; - (void) snprintf(mbuf, sizeof mbuf, + (void) snprintf(mbuf, sizeof(mbuf), "<<< Cmd = %c (\\%3.3o) Msg = \"%s\"", buffer[0], buffer[0], buffer + 1); @@ -509,9 +473,7 @@ extern int remline(buffer, space, doclean) * Non-line-oriented remote read. */ int -readrem(p, space) - char *p; - int space; +readrem(char *p, int space) { if (remleft <= 0) { /* @@ -531,7 +493,7 @@ readrem(p, space) if (remleft < space) space = remleft; - bcopy((char *) remptr, p, space); + memcpy(p, remptr, space); remptr += space; remleft -= space; @@ -542,10 +504,8 @@ readrem(p, space) /* * Get the user name for the uid. */ -extern char *getusername(uid, file, opts) - UID_T uid; - char *file; - opt_t opts; +char * +getusername(UID_T uid, char *file, opt_t opts) { static char buf[100]; static UID_T lastuid = (UID_T)-1; @@ -556,7 +516,7 @@ extern char *getusername(uid, file, opts) * do the opts check. */ if (IS_ON(opts, DO_NUMCHKOWNER)) { - (void) snprintf(buf, sizeof buf, ":%u", uid); + (void) snprintf(buf, sizeof(buf), ":%u", uid); return(buf); } @@ -569,11 +529,16 @@ extern char *getusername(uid, file, opts) lastuid = uid; if ((pwd = getpwuid(uid)) == NULL) { - message(MT_WARNING, - "%s: No password entry for uid %u", file, uid); - (void) snprintf(buf, sizeof buf, ":%u", uid); - } else - (void) strlcpy(buf, pwd->pw_name, sizeof buf); + if (IS_ON(opts, DO_DEFOWNER) && !isserver) + (void) strlcpy(buf, defowner, sizeof(buf)); + else { + message(MT_WARNING, + "%s: No password entry for uid %u", file, uid); + (void) snprintf(buf, sizeof(buf), ":%u", uid); + } + } else { + (void) strlcpy(buf, pwd->pw_name, sizeof(buf)); + } return(buf); } @@ -581,10 +546,8 @@ extern char *getusername(uid, file, opts) /* * Get the group name for the gid. */ -extern char *getgroupname(gid, file, opts) - GID_T gid; - char *file; - opt_t opts; +char * +getgroupname(GID_T gid, char *file, opt_t opts) { static char buf[100]; static GID_T lastgid = (GID_T)-1; @@ -595,7 +558,7 @@ extern char *getgroupname(gid, file, opts) * do the opts check. */ if (IS_ON(opts, DO_NUMCHKGROUP)) { - (void) snprintf(buf, sizeof buf, ":%u", gid); + (void) snprintf(buf, sizeof(buf), ":%u", gid); return(buf); } @@ -608,10 +571,15 @@ extern char *getgroupname(gid, file, opts) lastgid = gid; if ((grp = (struct group *)getgrgid(gid)) == NULL) { - message(MT_WARNING, "%s: No name for group %u", file, gid); - (void) snprintf(buf, sizeof buf, ":%u", gid); + if (IS_ON(opts, DO_DEFGROUP) && !isserver) + (void) strlcpy(buf, defgroup, sizeof(buf)); + else { + message(MT_WARNING, "%s: No name for group %u", + file, gid); + (void) snprintf(buf, sizeof(buf), ":%u", gid); + } } else - (void) strlcpy(buf, grp->gr_name, sizeof buf); + (void) strlcpy(buf, grp->gr_name, sizeof(buf)); return(buf); } @@ -619,7 +587,8 @@ extern char *getgroupname(gid, file, opts) /* * Read a response from the remote host. */ -extern int response() +int +response(void) { static u_char resp[BUFSIZ]; u_char *s; @@ -660,6 +629,7 @@ extern int response() if (s) message(MT_FERROR, "%s", s); finish(); + return(-1); } /*NOTREACHED*/ } @@ -672,10 +642,8 @@ extern int response() * user's home directory path name. Return a pointer in buf to the * part corresponding to `file'. */ -extern char *exptilde(ebuf, file, ebufsize) - char *ebuf; - size_t ebufsize; - char *file; +char * +exptilde(char *ebuf, char *file, size_t ebufsize) { char *pw_dir, *rest; size_t len; @@ -728,7 +696,8 @@ notilde: * Set our effective user id to the user running us. * This should be the uid we do most of our work as. */ -extern int becomeuser() +int +becomeuser(void) { int r = 0; @@ -739,7 +708,7 @@ extern int becomeuser() #endif /* HAVE_SAVED_IDS */ if (r < 0) - error("becomeuser %d failed: %s (ruid = %u euid = %u)", + error("becomeuser %u failed: %s (ruid = %u euid = %u)", userid, SYSERR, getuid(), geteuid()); return(r); @@ -750,7 +719,8 @@ extern int becomeuser() /* * Set our effective user id to "root" (uid = 0) */ -extern int becomeroot() +int +becomeroot(void) { int r = 0; @@ -771,10 +741,8 @@ extern int becomeroot() /* * Set access and modify times of a given file */ -extern int setfiletime(file, atime, mtime) - char *file; - time_t atime; - time_t mtime; +int +setfiletime(char *file, time_t atime, time_t mtime) { #if SETFTIME_TYPE == SETFTIME_UTIMES struct timeval tv[2]; @@ -808,11 +776,12 @@ extern int setfiletime(file, atime, mtime) /* * Get version info */ -extern char *getversion() +char * +getversion(void) { static char buff[BUFSIZ]; - (void) snprintf(buff, sizeof buff, + (void) snprintf(buff, sizeof(buff), "Version %s.%d (%s) - Protocol Version %d, Release %s, Patch level %d", DISTVERSION, PATCHLEVEL, DISTSTATUS, VERSION, DISTVERSION, PATCHLEVEL); @@ -824,15 +793,15 @@ extern char *getversion() * Execute a shell command to handle special cases. * This is now common to both server and client */ -void runcommand(cmd) - char *cmd; +void +runcommand(char *cmd) { - int fd[2]; - int status; + ssize_t nread; + pid_t pid, wpid; char *cp, *s; char sbuf[BUFSIZ], buf[BUFSIZ]; - pid_t pid, i; - + int fd[2], status; + if (pipe(fd) < 0) { error("pipe of %s failed: %s", cmd, SYSERR); return; @@ -856,7 +825,7 @@ void runcommand(cmd) (void) close(fd[PIPE_WRITE]); s = sbuf; *s++ = C_LOGMSG; - while ((i = read(fd[PIPE_READ], buf, sizeof(buf))) > 0) { + while ((nread = read(fd[PIPE_READ], buf, sizeof(buf))) > 0) { cp = buf; do { *s++ = *cp++; @@ -879,7 +848,7 @@ void runcommand(cmd) message(MT_INFO, "%s", sbuf+1); } s = &sbuf[1]; - } while (--i); + } while (--nread); } if (s > (char *) &sbuf[1]) { *s++ = '\n'; @@ -890,9 +859,9 @@ void runcommand(cmd) message(MT_INFO, "%s", sbuf+1); } } - while ((i = wait(&status)) != pid && i != -1) + while ((wpid = wait(&status)) != pid && wpid != -1) ; - if (i == -1) + if (wpid == -1) status = -1; (void) close(fd[PIPE_READ]); if (status) @@ -904,11 +873,10 @@ void runcommand(cmd) /* * Malloc with error checking */ -char *xmalloc(amt) - int amt; +char * +xmalloc(size_t amt) { char *ptr; - extern POINTER *malloc(); if ((ptr = (char *)malloc(amt)) == NULL) fatalerr("Cannot malloc %d bytes of memory.", amt); @@ -919,12 +887,10 @@ char *xmalloc(amt) /* * realloc with error checking */ -char *xrealloc(baseptr, amt) - char *baseptr; - unsigned int amt; +char * +xrealloc(char *baseptr, size_t amt) { char *new; - extern POINTER *realloc(); if ((new = (char *)realloc(baseptr, amt)) == NULL) fatalerr("Cannot realloc %d bytes of memory.", amt); @@ -935,12 +901,10 @@ char *xrealloc(baseptr, amt) /* * calloc with error checking */ -char *xcalloc(num, esize) - unsigned int num; - unsigned int esize; +char * +xcalloc(size_t num, size_t esize) { char *ptr; - extern POINTER *calloc(); if ((ptr = (char *)calloc(num, esize)) == NULL) fatalerr("Cannot calloc %d * %d = %d bytes of memory.", @@ -952,26 +916,27 @@ char *xcalloc(num, esize) /* * Strdup with error checking */ -char *xstrdup(str) - char *str; +char * +xstrdup(const char *str) { - char *nstr; + size_t len = strlen(str) + 1; + char *nstr = (char *) malloc(len); - if ((nstr = strdup(str)) == NULL) - fatalerr("Cannot malloc %d bytes of memory.", strlen(str) + 1); + if (nstr == NULL) + fatalerr("Cannot malloc %u bytes of memory.", len); - return(nstr); + return(memcpy(nstr, str, len)); } /* * Private version of basename() */ -extern char *xbasename(path) - char *path; +char * +xbasename(char *path) { char *cp; - if ((cp = strrchr(path, '/'))) + if ((cp = strrchr(path, '/')) != NULL) return(cp+1); else return(path); @@ -982,8 +947,8 @@ extern char *xbasename(path) * search until a component of that path is found and * return the found file name. */ -extern char *searchpath(path) - char *path; +char * +searchpath(char *path) { char *file; char *space; @@ -1003,15 +968,14 @@ extern char *searchpath(path) /* * Set line buffering. */ -extern void -mysetlinebuf(fp) - FILE *fp; +int +mysetlinebuf(FILE *fp) { #if SETBUF_TYPE == SETBUF_SETLINEBUF - setlinebuf(fp); + return(setlinebuf(fp)); #endif /* SETBUF_SETLINEBUF */ #if SETBUF_TYPE == SETBUF_SETVBUF - setvbuf(stdout, NULL, _IOLBF, BUFSIZ); + return(setvbuf(stdout, NULL, _IOLBF, BUFSIZ)); #endif /* SETBUF_SETVBUF */ #if !defined(SETBUF_TYPE) No SETBUF_TYPE is defined! @@ -1022,11 +986,7 @@ mysetlinebuf(fp) * Our interface to system call to get a socket pair. */ int -getsocketpair(domain, type, protocol, sv) - int domain; - int type; - int protocol; - int sv[]; +getsocketpair(int domain, int type, int protocol, int sv[]) { #if SOCKPAIR_TYPE == SOCKPAIR_SOCKETPAIR return(socketpair(domain, type, protocol, sv)); diff --git a/usr.bin/rdist/config-data.h b/usr.bin/rdist/config-data.h index 8c8df3a7ae2..1ead6b745ac 100644 --- a/usr.bin/rdist/config-data.h +++ b/usr.bin/rdist/config-data.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config-data.h,v 1.4 1998/06/26 21:21:02 millert Exp $ */ +/* $OpenBSD: config-data.h,v 1.5 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1993 Michael A. Cooper @@ -35,7 +35,7 @@ */ /* - * $From: config-data.h,v 6.3 1995/12/13 01:55:26 mcooper Exp $ + * $From: config-data.h,v 1.1.1.2 1996/02/15 21:52:02 christos Exp $ * @(#)configdata.h */ diff --git a/usr.bin/rdist/config-def.h b/usr.bin/rdist/config-def.h index eb469f00bd8..5c6bc052170 100644 --- a/usr.bin/rdist/config-def.h +++ b/usr.bin/rdist/config-def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config-def.h,v 1.4 1998/06/26 21:21:03 millert Exp $ */ +/* $OpenBSD: config-def.h,v 1.5 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1993 Michael A. Cooper @@ -35,7 +35,7 @@ */ /* - * $From: config-def.h,v 6.12 1994/03/31 04:30:42 mcooper Exp $ + * $From: config-def.h,v 1.1.1.1 1995/05/20 23:35:17 christos Exp $ * @(#)configdef.h */ diff --git a/usr.bin/rdist/config.h b/usr.bin/rdist/config.h index 453d82c0350..271c4f1bbdf 100644 --- a/usr.bin/rdist/config.h +++ b/usr.bin/rdist/config.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config.h,v 1.6 1998/06/26 21:21:05 millert Exp $ */ +/* $OpenBSD: config.h,v 1.7 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1993 Michael A. Cooper @@ -35,7 +35,7 @@ */ /* - * $From: config.h,v 6.43 1998/03/24 01:05:27 michaelc Exp $ + * $From: config.h,v 1.2 1997/01/05 04:23:35 kim Exp $ * @(#)config.h */ @@ -50,12 +50,12 @@ /* * Include system pathname header file. Usually this is <paths.h>. - * If your system doesn't have such a file, use "paths.h" + * If your system doesn't have such a file, use "mypaths.h" */ #if defined(PATHS_H) # include PATHS_H #else -# include "rdistpaths.h" +# include "mypaths.h" #endif /* @@ -67,7 +67,7 @@ * don't have the old rdist, then uncomment the "#undef" line. */ #ifndef _PATH_OLDRDIST -#define _PATH_OLDRDIST "/usr/bin/oldrdist" /* Enable compat */ +#define _PATH_OLDRDIST "/usr/ucb/oldrdist" /* Enable compat */ #endif /*#undef _PATH_OLDRDIST*/ /* Disable compat */ diff --git a/usr.bin/rdist/defs.h b/usr.bin/rdist/defs.h index c5dabb5d2cb..d6940a253ea 100644 --- a/usr.bin/rdist/defs.h +++ b/usr.bin/rdist/defs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: defs.h,v 1.12 2003/05/06 22:10:11 millert Exp $ */ +/* $OpenBSD: defs.h,v 1.13 2003/05/14 01:34:35 millert Exp $ */ #ifndef __DEFS_H__ #define __DEFS_H__ @@ -36,18 +36,14 @@ */ /* - * $From: defs.h,v 6.82 1998/03/23 23:28:25 michaelc Exp $ + * $From: defs.h,v 1.6 2001/03/12 18:16:30 kim Exp $ * @(#)defs.h 5.2 (Berkeley) 3/20/86 */ -/* - * POSIX settings - */ -#if defined(_POSIX_SOURCE) || defined(__OpenBSD__) #include <unistd.h> #include <stdlib.h> -#endif /* _POSIX_SOURCE */ #include <stdio.h> +#include <string.h> #include <ctype.h> #include <errno.h> #include <pwd.h> @@ -61,12 +57,25 @@ #include <sys/time.h> #include <sys/stat.h> +#ifndef __GNUC__ +# ifndef __attribute__ +# define __attribute__(a) +# endif +#endif + +#ifndef __STDC__ +# ifndef const +# define const +# endif +#endif + #include "version.h" #include "config-def.h" #include "config.h" #include "config-data.h" #include "pathnames.h" #include "types.h" +#include "filesys.h" #include <signal.h> @@ -77,7 +86,6 @@ */ #if defined(SVR4) #define NEED_FCNTL_H -#define NEED_UNISTD_H #define NEED_NETDB_H #endif /* defined(SVR4) */ @@ -90,12 +98,6 @@ #if defined(NEED_LIMITS_H) #include <limits.h> #endif /* NEED_LIMITS_H */ -#if defined(NEED_UNISTD_H) -#include <unistd.h> -#endif /* NEED_UNISTD_H */ -#if defined(NEED_STRING_H) -#include <string.h> -#endif /* NEED_STRING_H */ #if defined(ARG_TYPE) #if ARG_TYPE == ARG_STDARG @@ -204,12 +206,12 @@ #define C_RECVDIR 'D' /* Receive a directory */ #define C_RECVSYMLINK 'K' /* Receive a symbolic link */ #define C_RECVHARDLINK 'k' /* Receive a hard link */ -#define C_END 'E' /* Indicate end of receive/send */ +#define C_END 'E' /* Indicate end of recieve/send */ #define C_CLEAN 'C' /* Clean up */ #define C_QUERY 'Q' /* Query without checking */ #define C_SPECIAL 'S' /* Execute special command */ #define C_CMDSPECIAL 's' /* Execute cmd special command */ -#define C_CHMOD 'M' /* Chmod a file */ +#define C_CHMOG 'M' /* Chown,Chgrp,Chmod a file */ #define ack() (void) sendcmd(C_ACK, (char *)NULL) #define err() (void) sendcmd(C_ERRMSG, (char *)NULL) @@ -229,6 +231,8 @@ #define SC_FREEFILES 'f' /* Set min free files */ #define SC_HOSTNAME 'H' /* Set client hostname */ #define SC_LOGGING 'L' /* Set logging options */ +#define SC_DEFOWNER 'o' /* Set default owner */ +#define SC_DEFGROUP 'g' /* Set default group */ /* * Query commands @@ -313,11 +317,12 @@ extern char *currenthost; /* Name of current host */ extern char *progname; /* Name of this program */ extern char **realargv; /* Real argv */ extern int optind; /* Option index into argv */ -extern int contimedout; /* Connection timed out */ extern int debug; /* Debugging flag */ extern opt_t defoptions; /* Default install options */ extern int do_fork; /* Should we do fork()'ing */ +#ifndef __STDC__ extern int errno; /* System error number */ +#endif extern int isserver; /* Acting as remote server */ extern int nerrs; /* Number of errors seen */ extern int nflag; /* NOP flag, don't execute commands */ @@ -328,94 +333,200 @@ extern int rem_r; /* Remote file descriptor, reading */ extern int rem_w; /* Remote file descriptor, writing */ extern int rtimeout; /* Response time out in seconds */ extern int setjmp_ok; /* setjmp/longjmp flag */ -extern void mysetlinebuf(); /* set line buffering */ extern UID_T userid; /* User ID of rdist user */ extern jmp_buf finish_jmpbuf; /* Setjmp buffer for finish() */ extern struct group *gr; /* pointer to static area used by getgrent */ extern struct linkbuf *ihead; /* list of files with more than one link */ extern struct passwd *pw; /* pointer to static area used by getpwent */ +extern char defowner[64]; /* Default owner */ +extern char defgroup[64]; /* Default group */ +extern volatile sig_atomic_t contimedout; /* Connection timed out */ #ifdef USE_STATDB extern int dostatdb; extern int juststatdb; #endif /* USE_STATDB */ /* - * System function declarations - */ -char *hasmntopt(); -char *strchr(); -char *strdup(); -char *strrchr(); -char *strtok(); - -/* * Our own declarations. */ -char *exptilde(); -char *makestr(); -char *xcalloc(); -char *xmalloc(); -char *xrealloc(); -char *xstrdup(); -extern char *xbasename(); -extern char *getdistoptlist(); -extern char *getgroupname(); -extern char *getnlstr(); -extern char *getnotifyfile(); -extern char *getondistoptlist(); -extern char *getusername(); -extern char *getversion(); -extern char *msgparseopts(); -extern char *searchpath(); -extern int any(); -extern int init(); -extern int install(); -extern int isexec(); -extern int parsedistopts(); -extern int remline(); -extern int setfiletime(); -extern int spawn(); -extern struct subcmd *makesubcmd(); -extern void checkhostname(); -extern void cleanup(); -extern void complain(); -extern void docmds(); -extern void finish(); -extern void log(); -extern void logmsg(); -extern void lostconn(); -extern void markassigned(); -extern void msgprusage(); -extern void note(); -extern void runcmdspecial(); -extern void runcommand(); -extern void server(); -extern void setprogname(); -extern void sighandler(); -extern void waitup(); -struct namelist *expand(); -struct namelist *lookup(); -struct namelist *makenl(); -extern WRITE_RETURN_T xwrite(); - -#if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG -extern void debugmsg(int, char *, ...); -extern void error(char *, ...); -extern void fatalerr(char *, ...); -extern void message(int, char *, ...); -#ifndef HAVE_SETPROCTITLE -extern void setproctitle(char *fmt, ...); + +/* child.c */ +void waitup(void); +int spawn(struct cmd *, struct cmd *); +int setnonblocking(int, int); +int setnonblocking(int, int); + +/* client.c */ +char *remfilename(char *, char *, char *, char *, int); +int inlist(struct namelist *, char *); +void runcmdspecial(struct cmd *, opt_t); +int checkfilename(char *); +void freelinkinfo(struct linkbuf *); +void cleanup(int); +int install(char *, char *, int, int , opt_t); + +/* common.c */ +WRITE_RETURN_T xwrite(int, void *, WRITE_AMT_T); +int init(int, char **, char **); +void finish(void); +void lostconn(void); +void coredump(void); +void sighandler(int); +int sendcmd(char, char *, ...); +int remline(u_char *, int, int); +int readrem(char *, int); +char *getusername(UID_T, char *, opt_t); +char *getgroupname(GID_T, char *, opt_t); +int response(void); +char *exptilde(char *, char *, size_t); +int becomeuser(void); +int becomeroot(void); +int setfiletime(char *, time_t, time_t); +char *getversion(void); +void runcommand(char *); +char *xmalloc(size_t); +char *xrealloc(char *, size_t); +char *xcalloc(size_t, size_t); +char *xstrdup(const char *); +char *xbasename(char *); +char *searchpath(char *); +int mysetlinebuf(FILE *); +int getsocketpair(int, int, int, int[]); + +/* distopt.c */ +DISTOPTINFO *getdistopt(char *, int *); +int parsedistopts(char *, opt_t *, int); +char *getdistoptlist(void); +char *getondistoptlist(opt_t); + +/* docmd.c */ +void markassigned(struct cmd *, struct cmd *); +int okname(char *); +int except(char *); +void docmds(struct namelist *, int, char **); + +/* expand.c */ +struct namelist *expand(struct namelist *, int); +u_char *xstrchr(u_char *, int); +void expstr(u_char *); +void expsh(u_char *); +void matchdir(char *); +int execbrc(u_char *, u_char *); +int match(char *, char *); +int amatch(char *, u_char *); + +/* filesys.c */ +char *find_file(char *, struct stat *, int *); +mntent_t *findmnt(struct stat *, struct mntinfo *); +int isdupmnt(mntent_t *, struct mntinfo *); +void wakeup(int); +struct mntinfo *makemntinfo(struct mntinfo *); +mntent_t *getmntpt(char *, struct stat *, int *); +int is_nfs_mounted(char *, struct stat *, int *); +int is_ro_mounted(char *, struct stat *, int *); +int is_symlinked(char *, struct stat *, int *); +int getfilesysinfo(char *, long *, long *); + +/* gram.c */ +int yylex(void); +int any(int, char *); +void insert(char *, struct namelist *, struct namelist *, struct subcmd *); +void append(char *, struct namelist *, char *, struct subcmd *); +void yyerror(char *); +struct namelist *makenl(char *); +struct subcmd *makesubcmd(int); +int yyparse(void); + +/* hasmntopt.c */ +#ifdef NEED_HASMNTOPT +char *hasmntopt(struct mntent *, char *); #endif -extern void yyerror(char *); -#else -extern void debugmsg(); -extern void error(); -extern void fatalerr(); -extern void message(); -#ifndef HAVE_SETPROCTITLE -extern void setproctitle(); + +/* isexec.c */ +int isexec(char *, struct stat *); + +/* lookup.c */ +void define(char *); +struct namelist *lookup(char *, int, struct namelist *); + +/* message.c */ +void msgprusage(void); +void msgprconfig(void); +char *msgparseopts(char *, int); +void checkhostname(void); +void message(int, char *, ...); +void debugmsg(int, char *, ...); +void error(char *, ...); +void fatalerr(char *, ...); +char *getnotifyfile(void); + +/* rdist.c */ +FILE *opendist(char *); +void docmdargs(int, char *[]); +char *getnlstr(struct namelist *); + +/* rshrcmd.c */ +int rshrcmd(char **, u_short, char *, char *, char *, int *); + +/* server.c */ +void server(void); + +/* setargs.c */ +void setargs_settup(int, char **, char **); +void _setproctitle(char *); +void setproctitle(const char *, ...); + +/* signal.c */ +#ifdef NEED_SIGBLOCK +int sigblock(int); #endif -extern void yyerror(); +#ifdef NEED_SIGMASK +int sigsetmask(int); #endif +/* strcasecmp.c */ +#ifdef NEED_STRCASECMP +int strcasecmp(char *, char *); +int strncasecmp(char *, char *, int); +#endif + +/* strerror.c */ +#ifdef NEED_STRERROR +char *strerror(int); +#endif + +/* strtol.c */ +#ifdef NEED_STRTOL +long strtol(char *, char **, int); +#endif + +/* unvis.c */ +#ifdef NEED_VIS +int unvis(char *, int, int *, int ); +int strunvis(char *, const char *); +#endif + +/* vis.c */ +#ifdef NEED_VIS +char *vis(char *, int, int, int ); +int strvis(char *, const char *, int); +int strvisx(char *, const char *, size_t, int); +#endif + +/* vsnprintf.c */ +#ifdef NEED_VSNPRINTF +int vsnprintf(char *, size_t, const char *, va_list); +int snprintf(char *, size_t, const char *, ...); +#endif + +/* zopen.c */ +int zread(void *, char *, int); +int zwrite(void *, const char *, int); +int z_close(void *); +void *z_open(int, char *, int); + +#include <vis.h> +#define DECODE(a, b) strunvis(a, b) +#define ENCODE(a, b) strvis(a, b, VIS_WHITE) + #endif /* __DEFS_H__ */ diff --git a/usr.bin/rdist/distopt.c b/usr.bin/rdist/distopt.c index ff05900078d..8c29f1bd010 100644 --- a/usr.bin/rdist/distopt.c +++ b/usr.bin/rdist/distopt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: distopt.c,v 1.7 2003/04/05 20:31:58 deraadt Exp $ */ +/* $OpenBSD: distopt.c,v 1.8 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,20 @@ * SUCH DAMAGE. */ +#include "defs.h" #ifndef lint #if 0 -static char RCSid[] = -"$From: distopt.c,v 6.10 1996/01/30 01:52:07 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: distopt.c,v 1.5 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: distopt.c,v 1.7 2003/04/05 20:31:58 deraadt Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: distopt.c,v 1.8 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)distopt.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)distopt.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* !lint */ @@ -53,45 +55,49 @@ static char copyright[] = * Dist Option functions */ -#include "defs.h" /* * Distfile Option Information */ DISTOPTINFO distoptinfo[] = { - { DO_CHKNFS, "chknfs" }, - { DO_CHKREADONLY, "chkreadonly" }, - { DO_CHKSYM, "chksym" }, - { DO_COMPARE, "compare" }, - { DO_FOLLOW, "follow" }, - { DO_IGNLNKS, "ignlnks" }, - { DO_NOCHKGROUP, "nochkgroup" }, - { DO_NOCHKMODE, "nochkmode" }, - { DO_NOCHKOWNER, "nochkowner" }, - { DO_NODESCEND, "nodescend" }, - { DO_NOEXEC, "noexec" }, - { DO_NUMCHKGROUP, "numchkgroup" }, - { DO_NUMCHKOWNER, "numchkowner" }, - { DO_QUIET, "quiet" }, - { DO_REMOVE, "remove" }, - { DO_SAVETARGETS, "savetargets" }, - { DO_SPARSE, "sparse" }, - { DO_VERIFY, "verify" }, - { DO_WHOLE, "whole" }, - { DO_YOUNGER, "younger" }, + { DO_CHKNFS, "chknfs", NULL, 0}, + { DO_CHKREADONLY, "chkreadonly", NULL, 0}, + { DO_CHKSYM, "chksym", NULL, 0}, + { DO_DEFGROUP, "defgroup", defgroup, sizeof(defgroup) }, + { DO_DEFOWNER, "defowner", defowner, sizeof(defowner) }, + { DO_COMPARE, "compare", NULL, 0}, + { DO_FOLLOW, "follow", NULL, 0}, + { DO_HISTORY, "history", NULL, 0}, + { DO_IGNLNKS, "ignlnks", NULL, 0}, + { DO_NOCHKGROUP, "nochkgroup", NULL, 0}, + { DO_NOCHKMODE, "nochkmode", NULL, 0}, + { DO_NOCHKOWNER, "nochkowner", NULL, 0}, + { DO_NODESCEND, "nodescend", NULL, 0}, + { DO_NOEXEC, "noexec", NULL, 0}, + { DO_NUMCHKGROUP, "numchkgroup", NULL, 0}, + { DO_NUMCHKOWNER, "numchkowner", NULL, 0}, + { DO_QUIET, "quiet", NULL, 0}, + { DO_REMOVE, "remove", NULL, 0}, + { DO_SAVETARGETS, "savetargets", NULL, 0}, + { DO_SPARSE, "sparse", NULL, 0}, + { DO_UPDATEPERM, "updateperm", NULL, 0}, + { DO_VERIFY, "verify", NULL, 0}, + { DO_WHOLE, "whole", NULL, 0}, + { DO_YOUNGER, "younger", NULL, 0}, { 0 }, }; /* * Get a Distfile Option entry named "name". */ -extern DISTOPTINFO *getdistopt(name) - char *name; +DISTOPTINFO * +getdistopt(char *name, int *len) { int i; for (i = 0; distoptinfo[i].do_name; ++i) - if (strcasecmp(name, distoptinfo[i].do_name) == 0) + if (strncasecmp(name, distoptinfo[i].do_name, + *len = strlen(distoptinfo[i].do_name)) == 0) return(&distoptinfo[i]); return(NULL); @@ -102,38 +108,33 @@ extern DISTOPTINFO *getdistopt(name) * If doerrs is true, print out own error message. Returns * 0 on success. */ -extern int parsedistopts(str, optptr, doerrs) - char *str; - opt_t *optptr; - int doerrs; +int +parsedistopts(char *str, opt_t *optptr, int doerrs) { char *string, *optstr; DISTOPTINFO *distopt; - int negate; + int len; - /* strtok() is harmful */ + /* strtok() is destructive */ string = xstrdup(str); for (optstr = strtok(string, ","); optstr; optstr = strtok(NULL, ",")) { - if (strncasecmp(optstr, "no", 2) == 0) - negate = TRUE; - else - negate = FALSE; - - /* - * Try looking up option name. If that fails - * and the option starts with "no", strip "no" - * from option and retry lookup. - */ - if ((distopt = getdistopt(optstr))) { + /* Try Yes */ + if ((distopt = getdistopt(optstr, &len)) != NULL) { FLAG_ON(*optptr, distopt->do_value); + if (distopt->do_arg && optstr[len] == '=') + (void) strlcpy(distopt->do_arg, + &optstr[len + 1], distopt->arg_size); continue; } - if (negate && (distopt = getdistopt(optstr+2))) { + + /* Try No */ + if ((distopt = getdistopt(optstr+2, &len)) != NULL) { FLAG_OFF(*optptr, distopt->do_value); continue; } + if (doerrs) error("Dist option \"%s\" is not valid.", optstr); } @@ -147,19 +148,18 @@ extern int parsedistopts(str, optptr, doerrs) /* * Get a list of the Distfile Option Entries. */ -extern char *getdistoptlist() +char * +getdistoptlist(void) { int i; static char buf[1024]; for (i = 0, buf[0] = CNULL; distoptinfo[i].do_name; ++i) { if (buf[0] == CNULL) - (void) strlcpy(buf, distoptinfo[i].do_name, - sizeof buf); + (void) strlcpy(buf, distoptinfo[i].do_name, sizeof buf); else { (void) strlcat(buf, ",", sizeof buf); - (void) strlcat(buf, distoptinfo[i].do_name, - sizeof buf); + (void) strlcat(buf, distoptinfo[i].do_name, sizeof buf); } } @@ -170,8 +170,8 @@ extern char *getdistoptlist() * Get a list of the Distfile Option Entries for each enabled * value in "opts". */ -extern char *getondistoptlist(opts) - opt_t opts; +char * +getondistoptlist(opt_t opts) { int i; static char buf[1024]; @@ -181,12 +181,14 @@ extern char *getondistoptlist(opts) continue; if (buf[0] == CNULL) - (void) strlcpy(buf, distoptinfo[i].do_name, - sizeof buf); + (void) strlcpy(buf, distoptinfo[i].do_name, sizeof buf); else { (void) strlcat(buf, ",", sizeof buf); - (void) strlcat(buf, distoptinfo[i].do_name, - sizeof buf); + (void) strlcat(buf, distoptinfo[i].do_name, sizeof buf); + } + if (distoptinfo[i].do_arg) { + (void) strlcat(buf, "=", sizeof buf); + (void) strlcat(buf, distoptinfo[i].do_arg, sizeof buf); } } diff --git a/usr.bin/rdist/docmd.c b/usr.bin/rdist/docmd.c index f9631ac0bdc..a45d61f89e8 100644 --- a/usr.bin/rdist/docmd.c +++ b/usr.bin/rdist/docmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: docmd.c,v 1.15 2003/05/06 22:13:22 millert Exp $ */ +/* $OpenBSD: docmd.c,v 1.16 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,21 @@ * SUCH DAMAGE. */ +#include "defs.h" +#include "y.tab.h" #ifndef lint #if 0 -static char RCSid[] = -"$From: docmd.c,v 6.86 1996/01/30 02:29:43 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: docmd.c,v 1.8 2001/03/12 18:42:23 kim Exp $"; #else -static char RCSid[] = -"$OpenBSD: docmd.c,v 1.15 2003/05/06 22:13:22 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: docmd.c,v 1.16 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)docmd.c 5.1 (Berkeley) 6/6/85"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)docmd.c 5.1 (Berkeley) 6/6/85"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ @@ -53,8 +56,6 @@ static char copyright[] = * Functions for rdist that do command (cmd) related activities. */ -#include "defs.h" -#include "y.tab.h" #include <sys/socket.h> #include <netdb.h> @@ -71,12 +72,24 @@ extern int maxchildren; extern int amchild; extern char *path_rdistd; -static void cmptime(); +static void closeconn(void); +static void notify(char *, struct namelist *, time_t); +static void checkcmd(struct cmd *); +static void markfailed(struct cmd *, struct cmd *); +static int remotecmd(char *, char *, char *, char *); +static int makeconn(char *); +static void doarrow(struct cmd *, char **); +static void rcmptime(struct stat *, struct subcmd *, char **); +static void cmptime(char *, struct subcmd *, char **); +static void dodcolon(struct cmd *, char **); +static void docmdhost(struct cmd *, char **); +static void docmd(struct cmd *, int, char **); /* * Signal end of connection. */ -static void closeconn() +static void +closeconn(void) { debugmsg(DM_CALL, "closeconn() called\n"); @@ -97,16 +110,16 @@ static void closeconn() * rhost == NULL if we are mailing a list of changes compared to at time * stamp file. */ -static void notify(rhost, to, lmod) - char *rhost; - struct namelist *to; - time_t lmod; +static void +notify(char *rhost, struct namelist *to, time_t lmod) { - int fd, len; - FILE *pf, *popen(); + int fd; + size_t len; + FILE *pf; struct stat stb; static char buf[BUFSIZ]; - char *file; + extern char *locuser; + char *file, *user; if (IS_ON(options, DO_VERIFY) || to == NULL) return; @@ -143,7 +156,7 @@ static void notify(rhost, to, lmod) * Set IFS to avoid possible security problem with users * setting "IFS=/". */ - (void) snprintf(buf, sizeof buf, "IFS=\" \t\"; export IFS; %s -oi -t", + (void) snprintf(buf, sizeof(buf), "IFS=\" \t\"; export IFS; %s -oi -t", _PATH_SENDMAIL); pf = popen(buf, "w"); if (pf == NULL) { @@ -170,17 +183,22 @@ static void notify(rhost, to, lmod) to = to->n_next; } (void) putc('\n', pf); + + if ((user = getlogin()) == NULL) + user = locuser; + if (rhost != NULL) (void) fprintf(pf, - "Subject: files updated by rdist from %s to %s\n", - host, rhost); + "Subject: files updated by %s from %s to %s\n", + locuser, host, rhost); else (void) fprintf(pf, "Subject: files updated after %s\n", ctime(&lmod)); (void) putc('\n', pf); (void) putc('\n', pf); + (void) fprintf(pf, "Options: %s\n\n", getondistoptlist(options)); - while ((len = read(fd, buf, sizeof(buf))) > 0) + while ((len = read(fd, buf, sizeof(buf))) != (size_t)-1) (void) fwrite(buf, 1, len, pf); (void) pclose(pf); @@ -194,8 +212,8 @@ static void notify(rhost, to, lmod) * skipping files that are on an NFS filesystem is * bypassed. We always strip '+' to be consistent. */ -static void checkcmd(cmd) - struct cmd *cmd; +static void +checkcmd(struct cmd *cmd) { int l; @@ -217,9 +235,8 @@ static void checkcmd(cmd) * Mark all other entries for this command (cmd) * as assigned. */ -extern void markassigned(cmd, cmdlist) - struct cmd *cmd; - struct cmd *cmdlist; +void +markassigned(struct cmd *cmd, struct cmd *cmdlist) { struct cmd *pcmd; @@ -234,9 +251,8 @@ extern void markassigned(cmd, cmdlist) /* * Mark the command "cmd" as failed for all commands in list cmdlist. */ -static void markfailed(cmd, cmdlist) - struct cmd *cmd; - struct cmd *cmdlist; +static void +markfailed(struct cmd *cmd, struct cmd *cmdlist) { struct cmd *pc; @@ -255,10 +271,8 @@ static void markfailed(cmd, cmdlist) } } -static int remotecmd(rhost, luser, ruser, cmd) - char *rhost; - char *luser, *ruser; - char *cmd; +static int +remotecmd(char *rhost, char *luser, char *ruser, char *cmd) { int desc; #if defined(DIRECT_RCMD) @@ -307,8 +321,8 @@ static int remotecmd(rhost, luser, ruser, cmd) * Create a connection to the rdist server on the machine rhost. * Return 0 if the connection fails or 1 if it succeeds. */ -static int makeconn(rhost) - char *rhost; +static int +makeconn(char *rhost) { char *ruser, *cp; static char *cur_host = NULL; @@ -316,7 +330,7 @@ static int makeconn(rhost) extern long min_freefiles, min_freespace; extern char *remotemsglist; char tuser[BUFSIZ], buf[BUFSIZ]; - u_char respbuff[BUFSIZ] = ""; + u_char respbuff[BUFSIZ]; int n; debugmsg(DM_CALL, "makeconn(%s)", rhost); @@ -340,7 +354,7 @@ static int makeconn(rhost) char c = *cp; *cp = CNULL; - (void) strncpy((char *)tuser, rhost, sizeof(tuser)-1); + (void) strlcpy((char *)tuser, rhost, sizeof(tuser)); *cp = c; rhost = cp + 1; ruser = tuser; @@ -354,7 +368,8 @@ static int makeconn(rhost) if (!IS_ON(options, DO_QUIET)) message(MT_VERBOSE, "updating host %s", rhost); - (void) snprintf(buf, sizeof buf, "%.*s -S", sizeof(buf)-5, path_rdistd); + (void) snprintf(buf, sizeof(buf), "%.*s -S", + (int)(sizeof(buf)-5), path_rdistd); if ((rem_r = rem_w = remotecmd(rhost, locuser, ruser, buf)) < 0) return(0); @@ -362,9 +377,13 @@ static int makeconn(rhost) /* * First thing received should be S_VERSION */ + respbuff[0] = '\0'; n = remline(respbuff, sizeof(respbuff), TRUE); if (n <= 0 || respbuff[0] != S_VERSION) { - error("Unexpected input from server: \"%s\".", respbuff); + if (n > 0) + error("Unexpected input from server: \"%s\".", respbuff); + else + error("No input from server."); closeconn(); return(0); } @@ -420,6 +439,16 @@ static int makeconn(rhost) if (response() < 0) return(0); } + if (strcmp(defowner, "bin") != 0) { + (void) sendcmd(C_SETCONFIG, "%c%s", SC_DEFOWNER, defowner); + if (response() < 0) + return(0); + } + if (strcmp(defgroup, "bin") != 0) { + (void) sendcmd(C_SETCONFIG, "%c%s", SC_DEFGROUP, defgroup); + if (response() < 0) + return(0); + } return(1); } @@ -427,18 +456,17 @@ static int makeconn(rhost) /* * Process commands for sending files to other machines. */ -static void doarrow(cmd, filev) - struct cmd *cmd; - char **filev; +static void +doarrow(struct cmd *cmd, char **filev) { struct namelist *f; struct subcmd *sc; char **cpp; int n, ddir, destdir; + volatile opt_t opts = options; struct namelist *files; struct subcmd *sbcmds; char *rhost; - volatile int opts = options; volatile int didupdate = 0; if (setjmp_ok) { @@ -569,12 +597,11 @@ static void doarrow(cmd, filev) } } -done: /* * Run any commands for the entire cmd */ if (didupdate > 0) { - runcmdspecial(cmd, filev, opts); + runcmdspecial(cmd, opts); didupdate = 0; } @@ -604,8 +631,7 @@ done: } int -okname(name) - char *name; +okname(char *name) { char *cp = name; int c, isbad; @@ -625,10 +651,8 @@ okname(name) return(1); } -static void rcmptime(st, sbcmds, env) - struct stat *st; - struct subcmd *sbcmds; - char **env; +static void +rcmptime(struct stat *st, struct subcmd *sbcmds, char **env) { DIR *d; DIRENTRY *dp; @@ -644,7 +668,7 @@ static void rcmptime(st, sbcmds, env) } optarget = ptarget; len = ptarget - target; - while ((dp = readdir(d))) { + while ((dp = readdir(d)) != NULL) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; if (len + 1 + (int)strlen(dp->d_name) >= BUFSIZ - 1) { @@ -654,7 +678,7 @@ static void rcmptime(st, sbcmds, env) ptarget = optarget; *ptarget++ = '/'; cp = dp->d_name; - while ((*ptarget++ = *cp++)) + while ((*ptarget++ = *cp++) != '\0') ; ptarget--; cmptime(target, sbcmds, env); @@ -667,14 +691,11 @@ static void rcmptime(st, sbcmds, env) /* * Compare the mtime of file to the list of time stamps. */ -static void cmptime(name, sbcmds, env) - char *name; - struct subcmd *sbcmds; - char **env; +static void +cmptime(char *name, struct subcmd *sbcmds, char **env) { struct subcmd *sc; struct stat stb; - int inlist(); debugmsg(DM_CALL, "cmptime(%s)", name); @@ -717,8 +738,8 @@ static void cmptime(name, sbcmds, env) continue; if (sc->sc_args != NULL && !inlist(sc->sc_args, name)) continue; - (void) snprintf(buf, sizeof buf, "%s=%s;%s", - E_LOCFILE, name, sc->sc_name); + (void) snprintf(buf, sizeof(buf), "%s=%s;%s", + E_LOCFILE, name, sc->sc_name); message(MT_CHANGE, "special \"%s\"", buf); if (*env) { size_t len = strlen(*env) + strlen(name) + 2; @@ -737,9 +758,8 @@ static void cmptime(name, sbcmds, env) /* * Process commands for comparing files to time stamp files. */ -static void dodcolon(cmd, filev) - struct cmd *cmd; - char **filev; +static void +dodcolon(struct cmd *cmd, char **filev) { struct subcmd *sc; struct namelist *f; @@ -767,7 +787,8 @@ static void dodcolon(cmd, filev) for (sc = sbcmds; sc != NULL; sc = sc->sc_next) { if (sc->sc_type == CMDSPECIAL) { env = (char *) xmalloc(sizeof(E_FILES) + 3); - (void) snprintf(env, sizeof(E_FILES) + 3, "%s='", E_FILES); + (void) snprintf(env, sizeof(E_FILES) + 3, + "%s='", E_FILES); break; } } @@ -819,8 +840,8 @@ static void dodcolon(cmd, filev) /* * Return TRUE if file is in the exception list. */ -extern int except(file) - char *file; +int +except(char *file) { struct subcmd *sc; struct namelist *nl; @@ -871,9 +892,8 @@ extern int except(file) /* * Do a specific command for a specific host */ -static void docmdhost(cmd, filev) - struct cmd *cmd; - char **filev; +static void +docmdhost(struct cmd *cmd, char **filev) { checkcmd(cmd); @@ -928,10 +948,8 @@ static void docmdhost(cmd, filev) /* * Do a specific command (cmd) */ -static void docmd(cmd, argc, argv) - struct cmd *cmd; - int argc; - char **argv; +static void +docmd(struct cmd *cmd, int argc, char **argv) { struct namelist *f; int i; @@ -972,10 +990,8 @@ static void docmd(cmd, argc, argv) /* * Do the commands in cmds (initialized by yyparse). */ -extern void docmds(hostlist, argc, argv) - struct namelist *hostlist; - int argc; - char **argv; +void +docmds(struct namelist *hostlist, int argc, char **argv) { struct cmd *c; char *cp; @@ -1074,7 +1090,7 @@ extern void docmds(hostlist, argc, argv) message(MT_VERBOSE, "updating of %s finished", currenthost); closeconn(); - cleanup(); + cleanup(0); exit(nerrs); } @@ -1092,6 +1108,6 @@ extern void docmds(hostlist, argc, argv) * We're single-threaded so close down current connection */ closeconn(); - cleanup(); + cleanup(0); } } diff --git a/usr.bin/rdist/expand.c b/usr.bin/rdist/expand.c index 3ecd9eb8908..e72f25f7725 100644 --- a/usr.bin/rdist/expand.c +++ b/usr.bin/rdist/expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.c,v 1.9 2003/04/19 17:22:29 millert Exp $ */ +/* $OpenBSD: expand.c,v 1.10 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,23 +33,24 @@ * SUCH DAMAGE. */ +#include "defs.h" #ifndef lint #if 0 -static char RCSid[] = -"$From: expand.c,v 6.18 1998/03/24 00:37:10 michaelc Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: expand.c,v 1.4 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: expand.c,v 1.9 2003/04/19 17:22:29 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: expand.c,v 1.10 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)expand.c 5.2 (Berkeley) 3/28/86"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)expand.c 5.2 (Berkeley) 3/28/86"; -char copyright[] = +char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ -#include "defs.h" #define MAXEARGS 2048 #define LC '{' @@ -71,16 +72,15 @@ char *entp; char **sortbase; char *argvbuf[MAXEARGS]; -static int argcmp(); -void expstr(); -void expsh(); -void matchdir(); - #define sort() qsort((char *)sortbase, &eargv[eargc] - sortbase, \ sizeof(*sortbase), argcmp), sortbase = &eargv[eargc] -static void Cat(s1, s2) /* quote in s1 and s2 */ - u_char *s1, *s2; +static void Cat(u_char *, u_char *); +static void addpath(int); +static int argcmp(const void *, const void *); + +static void +Cat(u_char *s1, u_char *s2) /* quote in s1 and s2 */ { char *cp; int len = strlen((char *)s1) + strlen((char *)s2) + 2; @@ -96,16 +96,16 @@ static void Cat(s1, s2) /* quote in s1 and s2 */ do { if (*s1 == QUOTECHAR) s1++; - } while ((*cp++ = *s1++)); + } while ((*cp++ = *s1++) != '\0'); cp--; do { if (*s2 == QUOTECHAR) s2++; - } while ((*cp++ = *s2++)); + } while ((*cp++ = *s2++) != '\0'); } -static void addpath(c) - char c; +static void +addpath(int c) { if (pathp >= lastpathp) { yyerror("Pathname too long"); @@ -126,9 +126,7 @@ static void addpath(c) * Major portions of this were snarfed from csh/sh.glob.c. */ struct namelist * -expand(list, wh) /* quote in list->n_name */ - struct namelist *list; - int wh; +expand(struct namelist *list, int wh) /* quote in list->n_name */ { struct namelist *nl, *prev; int n; @@ -177,9 +175,8 @@ expand(list, wh) /* quote in list->n_name */ * xstrchr() is a version of strchr() that * handles u_char buffers. */ -u_char *xstrchr(str, ch) - u_char *str; - int ch; +u_char * +xstrchr(u_char *str, int ch) { u_char *cp; @@ -190,8 +187,8 @@ u_char *xstrchr(str, ch) return(NULL); } -void expstr(s) - u_char *s; +void +expstr(u_char *s) { u_char *cp, *cp1; struct namelist *tp; @@ -208,7 +205,7 @@ void expstr(s) * Remove quoted characters */ if (IS_ON(which, E_VARS)) { - if ((int)strlen((char *)s) > sizeof(varbuff)) { + if (strlen((char *)s) > sizeof(varbuff)) { yyerror("Variable is too large."); return; } @@ -261,13 +258,13 @@ void expstr(s) *tail = savec; if (tp != NULL) { for (; tp != NULL; tp = tp->n_next) { - (void) snprintf((char *)ebuf, sizeof ebuf, - "%s%s%s", s, tp->n_name, tail); + (void) snprintf((char *)ebuf, sizeof(ebuf), + "%s%s%s", s, tp->n_name, tail); expstr(ebuf); } return; } - (void) snprintf((char *)ebuf, sizeof ebuf, "%s%s", s, tail); + (void) snprintf((char *)ebuf, sizeof(ebuf), "%s%s", s, tail); expstr(ebuf); return; } @@ -292,9 +289,9 @@ void expstr(s) if (pw == NULL || strcmp(pw->pw_name, (char *)ebuf+1) != 0) { if ((pw = getpwnam((char *)ebuf+1)) == NULL) { - strlcat((char *)ebuf, - ": unknown user name", - sizeof(ebuf)); + strlcat((char *)ebuf, + ": unknown user name", + sizeof(ebuf)); yyerror((char *)ebuf+1); return; } @@ -302,8 +299,8 @@ void expstr(s) cp1 = (u_char *)pw->pw_dir; s = cp; } - for (cp = (u_char *)path; (*cp++ = *cp1++); ) - ; + for (cp = (u_char *)path; (*cp++ = *cp1++) != '\0'; ) + continue; tpathp = pathp = (char *)cp - 1; } else { tpathp = pathp = path; @@ -327,9 +324,9 @@ void expstr(s) } static int -argcmp(a1, a2) - char **a1, **a2; +argcmp(const void *v1, const void *v2) { + const char *const *a1 = v1, *const *a2 = v2; return (strcmp(*a1, *a2)); } @@ -338,8 +335,8 @@ argcmp(a1, a2) * If there are any Shell meta characters in the name, * expand into a list, after searching directory */ -void expsh(s) /* quote in s */ - u_char *s; +void +expsh(u_char *s) /* quote in s */ { u_char *cp, *oldcp; char *spathp; @@ -376,8 +373,8 @@ endit: *pathp = CNULL; } -void matchdir(pattern) /* quote in pattern */ - char *pattern; +void +matchdir(char *pattern) /* quote in pattern */ { struct stat stb; DIRENTRY *dp; @@ -389,7 +386,7 @@ void matchdir(pattern) /* quote in pattern */ return; goto patherr2; } - if (fstat(dirp->dd_fd, &stb) < 0) + if (fstat(dirfd(dirp), &stb) < 0) goto patherr1; if (!S_ISDIR(stb.st_mode)) { errno = ENOTDIR; @@ -418,8 +415,7 @@ patherr2: } int -execbrc(p, s) /* quote in p */ - u_char *p, *s; +execbrc(u_char *p, u_char *s) /* quote in p */ { u_char restbuf[BUFSIZ + 2]; u_char *pe, *pm, *pl; @@ -482,9 +478,9 @@ doit: *pm = 0; *lm = 0; (void) strlcat((char *)restbuf, (char *)pl, - sizeof restbuf); + sizeof(restbuf)); (void) strlcat((char *)restbuf, (char *)pe + 1, - sizeof restbuf); + sizeof(restbuf)); *pm = savec; if (s == 0) { spathp = pathp; @@ -512,8 +508,7 @@ doit: } int -match(s, p) /* quote in p */ - char *s, *p; +match(char *s, char *p) /* quote in p */ { int c; char *sentp; @@ -530,9 +525,7 @@ match(s, p) /* quote in p */ } int -amatch(s, p) /* quote in p */ - char *s; - u_char *p; +amatch(char *s, u_char *p) /* quote in p */ { int scc; int ok, lc; @@ -551,7 +544,7 @@ amatch(s, p) /* quote in p */ case '[': ok = 0; lc = 077777; - while ((cc = *p++)) { + while ((cc = *p++) != '\0') { if (cc == ']') { if (ok) break; @@ -605,17 +598,18 @@ slash: while (*s) addpath(*s++); addpath('/'); - if (stat(path, &stb) == 0 && S_ISDIR(stb.st_mode)) + if (stat(path, &stb) == 0 && S_ISDIR(stb.st_mode)) { if (*p == CNULL) { - if (which & E_TILDE) + if (which & E_TILDE) { Cat((u_char *)path, (u_char *)""); - else + } else { Cat((u_char *)tilde, (u_char *)tpathp); - } else { + } + } else expsh(p); - } + } pathp = spathp; *pathp = CNULL; return (0); diff --git a/usr.bin/rdistd/filesys.h b/usr.bin/rdist/filesys.h index 9e54bab4b8e..4192c8810de 100644 --- a/usr.bin/rdistd/filesys.h +++ b/usr.bin/rdist/filesys.h @@ -1,4 +1,4 @@ -/* $OpenBSD: filesys.h,v 1.4 1998/06/26 21:20:49 millert Exp $ */ +/* $OpenBSD: filesys.h,v 1.1 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -34,7 +34,7 @@ */ /* - * $From: filesys.h,v 6.19 1995/12/12 00:46:46 mcooper Exp $ + * $From: filesys.h,v 1.2 1999/08/04 15:57:31 christos Exp $ * @(#)filesys.h */ @@ -97,31 +97,25 @@ * Stat Filesystem */ #if defined(STATFS_TYPE) -#if defined(ultrix) +# if defined(ultrix) typedef struct fs_data statfs_t; # define f_bavail fd_req.bfreen # define f_bsize fd_req.bsize # define f_ffree fd_req.gfree -#else -#if defined(_AIX) || STATFS_TYPE == STATFS_SYSV +# elif defined(_AIX) || STATFS_TYPE == STATFS_SYSV # include <sys/statfs.h> typedef struct statfs statfs_t; # define f_bavail f_bfree -#else -#if defined(SVR4) +# elif defined(SVR4) # include <sys/statvfs.h> typedef struct statvfs statfs_t; # define statfs(mp,sb) statvfs(mp,sb) -#else -#if defined(BSD386) || defined(__bsdi__) || defined(__OpenBSD__) || defined(FREEBSD) || STATFS_TYPE == STATFS_OSF1 +# elif STATFS_TYPE == STATFS_44BSD || STATFS_TYPE == STATFS_OSF1 typedef struct statfs statfs_t; -#else +# else # include <sys/vfs.h> typedef struct statfs statfs_t; -#endif /* BSD386 */ -#endif /* SVR4 */ -#endif /* _AIX */ -#endif /* ultrix */ +# endif #endif /* STATFS_TYPE */ /* @@ -162,9 +156,9 @@ struct mntinfo { /* * Declarations */ -FILE *setmountent(); -mntent_t *getmountent(); -mntent_t *newmountent(); -void endmountent(); +FILE *setmountent(const char *, const char *); +mntent_t *getmountent(FILE *); +mntent_t *newmountent(const mntent_t *); +void endmountent(FILE *); #endif /* __filesys_h__ */ diff --git a/usr.bin/rdist/gram.y b/usr.bin/rdist/gram.y index 463fc0351d1..a4200451012 100644 --- a/usr.bin/rdist/gram.y +++ b/usr.bin/rdist/gram.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: gram.y,v 1.6 2003/05/06 22:10:11 millert Exp $ */ +/* $OpenBSD: gram.y,v 1.7 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1993 Michael A. Cooper @@ -35,32 +35,31 @@ * SUCH DAMAGE. */ +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: gram.y,v 6.29 1994/04/11 23:59:15 mcooper Exp mcooper $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: gram.y,v 1.3 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: gram.y,v 1.6 2003/05/06 22:10:11 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: gram.y,v 1.7 2003/05/14 01:34:35 millert Exp $"; #endif -static char *sccsid = "@(#)gram.y 5.2 (Berkeley) 85/06/21"; +static char *sccsid __attribute__((__unused__)) = +"@(#)gram.y 5.2 (Berkeley) 85/06/21"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ -/* - * Tell defs.h not to include y.tab.h - */ -#ifndef yacc -#define yacc -#endif -#include "defs.h" +static struct namelist *addnl __P((struct namelist *, struct namelist *)); +static struct namelist *subnl __P((struct namelist *, struct namelist *)); +static struct namelist *andnl __P((struct namelist *, struct namelist *)); +static int innl __P((struct namelist *nl, char *p)); -static struct namelist *addnl(), *subnl(), *andnl(); struct cmd *cmds = NULL; struct cmd *last_cmd; struct namelist *last_n; @@ -169,7 +168,7 @@ cmdlist: /* VOID */ { ; cmd: INSTALL options opt_namelist ';' = { - register struct namelist *nl; + struct namelist *nl; $1->sc_options = $2 | options; if ($3 != NULL) { @@ -248,11 +247,12 @@ opt_namelist: /* VOID */ = { int yylineno = 1; extern FILE *fin; -yylex() +int +yylex(void) { static char yytext[INMAX]; - register int c; - register char *cp1, *cp2; + int c; + char *cp1, *cp2; static char quotechars[] = "[]{}*?$"; again: @@ -318,7 +318,7 @@ again: if (c != '"') yyerror("missing closing '\"'\n"); *cp1 = '\0'; - yylval.string = makestr(yytext); + yylval.string = xstrdup(yytext); return(STRING); case ':': /* : or :: */ @@ -360,9 +360,9 @@ again: switch (yytext[1]) { case 'o': if (parsedistopts(&yytext[2], &opt, TRUE)) { - (void) snprintf(ebuf, sizeof ebuf, - "Bad distfile options \"%s\".", - &yytext[2]); + (void) snprintf(ebuf, sizeof(ebuf), + "Bad distfile options \"%s\".", + &yytext[2]); yyerror(ebuf); } break; @@ -385,8 +385,8 @@ again: case 'r': opt = DO_NODESCEND; break; default: - (void) snprintf(ebuf, sizeof ebuf, - "Unknown option \"%s\".", yytext); + (void) snprintf(ebuf, sizeof(ebuf), + "Unknown option \"%s\".", yytext); yyerror(ebuf); } @@ -406,7 +406,7 @@ again: else if (!strcmp(yytext, "cmdspecial")) c = CMDSPECIAL; else { - yylval.string = makestr(yytext); + yylval.string = xstrdup(yytext); return(NAME); } yylval.subcmd = makesubcmd(c); @@ -417,9 +417,7 @@ again: * XXX We should use strchr(), but most versions can't handle * some of the characters we use. */ -extern int any(c, str) - register int c; - register char *str; +int any(int c, char *str) { while (*str) if (c == *str++) @@ -431,13 +429,11 @@ extern int any(c, str) * Insert or append ARROW command to list of hosts to be updated. */ void -insert(label, files, hosts, subcmds) - char *label; - struct namelist *files, *hosts; - struct subcmd *subcmds; +insert(char *label, struct namelist *files, struct namelist *hosts, + struct subcmd *subcmds) { - register struct cmd *c, *prev, *nc; - register struct namelist *h, *lasth; + struct cmd *c, *prev, *nc; + struct namelist *h, *lasth; debugmsg(DM_CALL, "insert(%s, %x, %x, %x) start, files = %s", label == NULL ? "(null)" : label, @@ -486,13 +482,9 @@ insert(label, files, hosts, subcmds) * executed in the order they appear in the distfile. */ void -append(label, files, stamp, subcmds) - char *label; - struct namelist *files; - char *stamp; - struct subcmd *subcmds; +append(char *label, struct namelist *files, char *stamp, struct subcmd *subcmds) { - register struct cmd *c; + struct cmd *c; c = ALLOC(cmd); c->c_type = DCOLON; @@ -513,36 +505,18 @@ append(label, files, stamp, subcmds) * Error printing routine in parser. */ void -yyerror(s) - char *s; +yyerror(char *s) { error("Error in distfile: line %d: %s", yylineno, s); } /* - * Return a copy of the string. - */ -char * -makestr(str) - char *str; -{ - char *cp; - - cp = strdup(str); - if (cp == NULL) - fatalerr("ran out of memory"); - - return(cp); -} - -/* * Allocate a namelist structure. */ struct namelist * -makenl(name) - char *name; +makenl(char *name) { - register struct namelist *nl; + struct namelist *nl; debugmsg(DM_CALL, "makenl(%s)", name == NULL ? "null" : name); @@ -559,9 +533,7 @@ makenl(name) * Is the name p in the namelist nl? */ static int -innl(nl, p) - struct namelist *nl; - char *p; +innl(struct namelist *nl, char *p) { for ( ; nl; nl = nl->n_next) if (!strcmp(p, nl->n_name)) @@ -573,8 +545,7 @@ innl(nl, p) * Join two namelists. */ static struct namelist * -addnl(n1, n2) - struct namelist *n1, *n2; +addnl(struct namelist *n1, struct namelist *n2) { struct namelist *nl, *prev; @@ -597,8 +568,7 @@ addnl(n1, n2) * Copy n1 except for elements that are in n2. */ static struct namelist * -subnl(n1, n2) - struct namelist *n1, *n2; +subnl(struct namelist *n1, struct namelist *n2) { struct namelist *nl, *prev; @@ -617,8 +587,7 @@ subnl(n1, n2) * Copy all items of n1 that are also in n2. */ static struct namelist * -andnl(n1, n2) - struct namelist *n1, *n2; +andnl(struct namelist *n1, struct namelist *n2) { struct namelist *nl, *prev; @@ -636,11 +605,10 @@ andnl(n1, n2) /* * Make a sub command for lists of variables, commands, etc. */ -extern struct subcmd * -makesubcmd(type) - int type; +struct subcmd * +makesubcmd(int type) { - register struct subcmd *sc; + struct subcmd *sc; sc = ALLOC(subcmd); sc->sc_type = type; diff --git a/usr.bin/rdist/isexec.c b/usr.bin/rdist/isexec.c index 251778d85f5..8968ea1722d 100644 --- a/usr.bin/rdist/isexec.c +++ b/usr.bin/rdist/isexec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isexec.c,v 1.5 2002/05/09 19:13:02 millert Exp $ */ +/* $OpenBSD: isexec.c,v 1.6 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -32,24 +32,27 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: isexec.c,v 6.21 1994/04/01 23:44:10 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: isexec.c,v 1.2 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: isexec.c,v 1.5 2002/05/09 19:13:02 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: isexec.c,v 1.6 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)client.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)client.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ - -#include "defs.h" +static int _isexec(int); #if EXE_TYPE == EXE_AOUT /* @@ -57,8 +60,8 @@ static char copyright[] = */ #include <a.out.h> -static int _isexec(fd) - int fd; +static int +_isexec(int fd) { struct exec ehdr; @@ -141,8 +144,8 @@ typedef struct filehdr hdr_t; /* * System V style COFF and System V R4 style ELF */ -static int _isexec(fd) - int fd; +static int +_isexec(int fd) { hdr_t hdr; @@ -187,8 +190,8 @@ static int _isexec(fd) #define FAT_CIGAM 0xbebafeca #endif -static int _isexec(fd) - int fd; +static int +_isexec(int fd) { struct mach_header ehdr; @@ -221,8 +224,8 @@ static int _isexec(fd) #endif /* hp9000s300 */ -static int _isexec(fd) - int fd; +static int +_isexec(int fd) { struct header ehdr; @@ -239,9 +242,8 @@ static int _isexec(fd) /* * Fake _isexec() call for unknown executable formats. */ -static int _isexec(fd) - /*ARGSUSED*/ - int fd; +static int +_isexec(int fd) { return(FALSE); } @@ -250,9 +252,8 @@ static int _isexec(fd) /* * Determine whether 'file' is an executable or not. */ -extern int isexec(file, statp) - char *file; - struct stat *statp; +int +isexec(char *file, struct stat *statp) { int fd, r; diff --git a/usr.bin/rdist/lookup.c b/usr.bin/rdist/lookup.c index 3d5c9560bd6..5b959d3b4a2 100644 --- a/usr.bin/rdist/lookup.c +++ b/usr.bin/rdist/lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lookup.c,v 1.10 2002/05/27 03:14:22 deraadt Exp $ */ +/* $OpenBSD: lookup.c,v 1.11 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,24 +33,25 @@ * SUCH DAMAGE. */ +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: lookup.c,v 6.8 1996/07/19 16:49:55 michaelc Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: lookup.c,v 1.4 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: lookup.c,v 1.10 2002/05/27 03:14:22 deraadt Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: lookup.c,v 1.11 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)lookup.c 5.1 (Berkeley) 6/6/85"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)lookup.c 5.1 (Berkeley) 6/6/85"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ -#include "defs.h" - /* symbol types */ #define VAR 1 #define CONST 2 @@ -68,8 +69,7 @@ static struct syment *hashtab[HASHSIZE]; * Define a variable from a command line argument. */ void -define(name) - char *name; +define(char *name) { char *cp, *s; struct namelist *nl; @@ -132,10 +132,7 @@ define(name) */ struct namelist * -lookup(name, action, value) /* %% in name. Ignore quotas in name */ - char *name; - int action; - struct namelist *value; +lookup(char *name, int action, struct namelist *value) { unsigned int n; char *cp; @@ -155,7 +152,9 @@ lookup(name, action, value) /* %% in name. Ignore quotas in name */ if (action != LOOKUP) { if (action != INSERT || s->s_type != CONST) { (void) snprintf(ebuf, sizeof(ebuf), - "%s redefined", name); + "%.*s redefined", + (int)(sizeof(ebuf) - + sizeof(" redefined")), name); yyerror(ebuf); } } @@ -163,7 +162,9 @@ lookup(name, action, value) /* %% in name. Ignore quotas in name */ } if (action == LOOKUP) { - (void) snprintf(ebuf, sizeof(ebuf), "%s undefined", name); + (void) snprintf(ebuf, sizeof(ebuf), "%.*s undefined", + (int)(sizeof(ebuf) - sizeof(" undefined")), + name); yyerror(ebuf); return(NULL); } diff --git a/usr.bin/rdist/message.c b/usr.bin/rdist/message.c index a0cc941e2f9..542b4f48448 100644 --- a/usr.bin/rdist/message.c +++ b/usr.bin/rdist/message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: message.c,v 1.13 2003/04/19 17:22:29 millert Exp $ */ +/* $OpenBSD: message.c,v 1.14 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,21 @@ * SUCH DAMAGE. */ +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: message.c,v 6.24 1996/07/19 17:00:35 michaelc Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: message.c,v 1.5 1999/11/01 00:21:39 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: message.c,v 1.13 2003/04/19 17:22:29 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: message.c,v 1.14 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)common.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)common.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* !lint */ @@ -53,7 +56,6 @@ static char copyright[] = * Message handling functions for both rdist and rdistd. */ -#include "defs.h" #define MSGBUFSIZ 32*1024 @@ -76,8 +78,10 @@ MSGTYPE msgtypes[] = { { 0 }, }; -static void msgsendstdout(), msgsendfile(), msgsendsyslog(), - msgsendnotify(); +static void msgsendstdout(MSGFACILITY *, int, int, char *); +static void msgsendsyslog(MSGFACILITY *, int, int, char *); +static void msgsendfile(MSGFACILITY *, int, int, char *); +static void msgsendnotify(MSGFACILITY *, int, int, char *); /* * Message Facilities @@ -90,10 +94,19 @@ MSGFACILITY msgfacility[] = { { 0 }, }; +static MSGFACILITY *getmsgfac(char *); +static MSGTYPE *getmsgtype(char *); +static char *setmsgtypes(MSGFACILITY *, char *); +static void _message(int, char *); +static void _debugmsg(int, char *); +static void _error(char *); +static void _fatalerr(char *); + /* * Print message logging usage message */ -extern void msgprusage() +void +msgprusage(void) { int i, x; @@ -116,22 +129,23 @@ extern void msgprusage() /* * Print enabled message logging info */ -extern void msgprconfig() +void +msgprconfig(void) { int i, x; static char buf[MSGBUFSIZ]; debugmsg(DM_MISC, "Current message logging config:"); for (i = 0; msgfacility[i].mf_name; ++i) { - (void) snprintf(buf, sizeof(buf), - " %s=", msgfacility[i].mf_name); + (void) snprintf(buf, sizeof(buf), " %.*s=", + (int)(sizeof(buf) - 7), msgfacility[i].mf_name); for (x = 0; msgtypes[x].mt_name; ++x) if (IS_ON(msgfacility[i].mf_msgtypes, msgtypes[x].mt_type)) { if (x > 0) - (void) strlcat(buf, ",", sizeof buf); + (void) strlcat(buf, ",", sizeof(buf)); (void) strlcat(buf, msgtypes[x].mt_name, - sizeof buf); + sizeof(buf)); } debugmsg(DM_MISC, "%s", buf); } @@ -141,8 +155,8 @@ extern void msgprconfig() /* * Get the Message Facility entry "name" */ -static MSGFACILITY *getmsgfac(name) - char *name; +static MSGFACILITY * +getmsgfac(char *name) { int i; @@ -156,8 +170,8 @@ static MSGFACILITY *getmsgfac(name) /* * Get the Message Type entry named "name" */ -static MSGTYPE *getmsgtype(name) - char *name; +static MSGTYPE * +getmsgtype(char *name) { int i; @@ -172,9 +186,8 @@ static MSGTYPE *getmsgtype(name) * Set Message Type information for Message Facility "msgfac" as * indicated by string "str". */ -static char *setmsgtypes(msgfac, str) - MSGFACILITY *msgfac; - char *str; +static char * +setmsgtypes(MSGFACILITY *msgfac, char *str) { static char ebuf[BUFSIZ]; char *cp; @@ -187,8 +200,8 @@ static char *setmsgtypes(msgfac, str) if (isserver && (msgfac->mf_msgfac != MF_SYSLOG && msgfac->mf_msgfac != MF_FILE)) { (void) snprintf(ebuf, sizeof(ebuf), - "The \"%s\" message facility cannot be used by the server.", - msgfac->mf_name); + "The \"%.*s\" message facility cannot be used by the server.", + 100, msgfac->mf_name); return(ebuf); } @@ -239,11 +252,11 @@ static char *setmsgtypes(msgfac, str) msgfac->mf_msgtypes = 0; /* Start from scratch */ while (strptr) { word = strptr; - if ((cp = strchr(strptr, ','))) + if ((cp = strchr(strptr, ',')) != NULL) *cp++ = CNULL; strptr = cp; - if ((mtp = getmsgtype(word))) { + if ((mtp = getmsgtype(word)) != NULL) { msgfac->mf_msgtypes |= mtp->mt_type; /* * XXX This is really a kludge until we add real @@ -254,8 +267,8 @@ static char *setmsgtypes(msgfac, str) debug = DM_ALL; } else { (void) snprintf(ebuf, sizeof(ebuf), - "Message type \"%s\" is invalid.", - word); + "Message type \"%.*s\" is invalid.", + 100, word); return(ebuf); } } @@ -266,9 +279,8 @@ static char *setmsgtypes(msgfac, str) /* * Parse a message logging option string */ -extern char *msgparseopts(msgstr, doset) - char *msgstr; - int doset; +char * +msgparseopts(char *msgstr, int doset) { static char ebuf[BUFSIZ], msgbuf[MSGBUFSIZ]; char *cp, *optstr; @@ -279,7 +291,7 @@ extern char *msgparseopts(msgstr, doset) return("NULL message string"); /* strtok() is harmful */ - (void) strlcpy(msgbuf, msgstr, sizeof msgbuf); + (void) strlcpy(msgbuf, msgstr, sizeof(msgbuf)); /* * Each <facility>=<types> list is separated by ":". @@ -299,15 +311,15 @@ extern char *msgparseopts(msgstr, doset) if ((msgfac = getmsgfac(word)) == NULL) { (void) snprintf(ebuf, sizeof(ebuf), - "%s is not a valid message facility", - word); + "%.*s is not a valid message facility", + 100, word); return(ebuf); } if (doset) { char *mcp; - if ((mcp = setmsgtypes(msgfac, cp))) + if ((mcp = setmsgtypes(msgfac, cp)) != NULL) return(mcp); } } @@ -324,12 +336,8 @@ extern char *msgparseopts(msgstr, doset) * Send a message to facility "stdout". * For rdistd, this is really the rdist client. */ -static void msgsendstdout(msgfac, mtype, flags, msgbuf) - /*ARGSUSED*/ - MSGFACILITY *msgfac; - int mtype; - int flags; - char *msgbuf; +static void +msgsendstdout(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) { char cmd; @@ -382,12 +390,8 @@ static void msgsendstdout(msgfac, mtype, flags, msgbuf) /* * Send a message to facility "syslog" */ -static void msgsendsyslog(msgfac, mtype, flags, msgbuf) - /*ARGSUSED*/ - MSGFACILITY *msgfac; - int mtype; - int flags; - char *msgbuf; +static void +msgsendsyslog(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) { int syslvl = 0; @@ -427,12 +431,8 @@ static void msgsendsyslog(msgfac, mtype, flags, msgbuf) /* * Send a message to a "file" facility. */ -static void msgsendfile(msgfac, mtype, flags, msgbuf) - /*ARGSUSED*/ - MSGFACILITY *msgfac; - int mtype; - int flags; - char *msgbuf; +static void +msgsendfile(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) { if (msgfac->mf_fptr == NULL) return; @@ -447,12 +447,8 @@ static void msgsendfile(msgfac, mtype, flags, msgbuf) /* * Same method as msgsendfile() */ -static void msgsendnotify(msgfac, mtype, flags, msgbuf) - /*ARGSUSED*/ - MSGFACILITY *msgfac; - int mtype; - int flags; - char *msgbuf; +static void +msgsendnotify(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) { char *tempfile; @@ -465,26 +461,22 @@ static void msgsendnotify(msgfac, mtype, flags, msgbuf) if (!msgfac->mf_fptr) { char *cp; int fd; - char *getenv(); size_t len; /* * Create and open a new temporary file */ - if ((cp = getenv("TMPDIR")) == NULL) + if ((cp = getenv("TMPDIR")) == NULL || *cp == '\0') cp = _PATH_TMP; len = strlen(cp) + 1 + sizeof(_RDIST_TMP); tempfile = (char *) xmalloc(len); (void) snprintf(tempfile, len, "%s/%s", cp, _RDIST_TMP); msgfac->mf_filename = tempfile; - if ((fd = mkstemp(msgfac->mf_filename)) == -1 || - (msgfac->mf_fptr = fdopen(fd, "w")) == NULL) { - if (fd != -1) - close(fd); - fatalerr("Cannot open notify file for writing: %s: %s.", - msgfac->mf_filename, SYSERR); - } + if ((fd = mkstemp(msgfac->mf_filename)) < 0 || + (msgfac->mf_fptr = fdopen(fd, "w")) == NULL) + fatalerr("Cannot open notify file for writing: %s: %s.", + msgfac->mf_filename, SYSERR); debugmsg(DM_MISC, "Created notify temp file '%s'", msgfac->mf_filename); } @@ -499,7 +491,8 @@ static void msgsendnotify(msgfac, mtype, flags, msgbuf) /* * Insure currenthost is set to something reasonable. */ -extern void checkhostname() +void +checkhostname(void) { static char mbuf[MAXHOSTNAMELEN]; char *cp; @@ -517,9 +510,8 @@ extern void checkhostname() /* * Print a message contained in "msgbuf" if a level "lvl" is set. */ -static void _message(flags, msgbuf) - int flags; - char *msgbuf; +static void +_message(int flags, char *msgbuf) { int i, x; char *cp; @@ -529,17 +521,17 @@ static void _message(flags, msgbuf) /* * Ensure no stray newlines are present */ - if ((cp = strchr(msgbuf, '\n'))) + if ((cp = strchr(msgbuf, '\n')) != NULL) *cp = CNULL; checkhostname(); if (strncmp(currenthost, msgbuf, strlen(currenthost)) == 0) - (void) strlcpy(mbuf, msgbuf, sizeof mbuf); + (void) strlcpy(mbuf, msgbuf, sizeof(mbuf)); else - (void) snprintf(mbuf, sizeof mbuf, - "%s: %s", currenthost, msgbuf); + (void) snprintf(mbuf, sizeof(mbuf), + "%s: %s", currenthost, msgbuf); } else - (void) strlcpy(mbuf, "", sizeof mbuf); + mbuf[0] = '\0'; /* * Special case for messages that only get @@ -587,7 +579,8 @@ static void _message(flags, msgbuf) /* * Varargs front-end to _message() */ -extern void message(va_alist) +void +message(va_alist) va_dcl { static char buf[MSGBUFSIZ]; @@ -600,7 +593,7 @@ extern void message(va_alist) fmt = (char *) va_arg(args, char *); va_end(args); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); _message(lvl, buf); } @@ -610,43 +603,25 @@ extern void message(va_alist) /* * Stdarg front-end to _message() */ -extern void message(int lvl, char *fmt, ...) +void +message(int lvl, char *fmt, ...) { static char buf[MSGBUFSIZ]; va_list args; va_start(args, fmt); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _message(lvl, buf); } #endif /* ARG_STDARG */ - -#if !defined(ARG_TYPE) -/* - * Simple front-end to _message() - */ -/*VARARGS2*/ -extern void message(lvl, fmt, a1, a2, a3, a4, a5) - int lvl; - char *fmt; -{ - static char buf[MSGBUFSIZ]; - - (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); - - _message(lvl, buf); -} -#endif /* !ARG_TYPE */ - /* * Display a debugging message */ -static void _debugmsg(lvl, buf) - int lvl; - char *buf; +static void +_debugmsg(int lvl, char *buf) { if (IS_ON(debug, lvl)) _message(MT_DEBUG, buf); @@ -656,7 +631,8 @@ static void _debugmsg(lvl, buf) /* * Varargs front-end to _debugmsg() */ -extern void debugmsg(va_alist) +void +debugmsg(va_alist) va_dcl { static char buf[MSGBUFSIZ]; @@ -669,7 +645,7 @@ extern void debugmsg(va_alist) fmt = (char *) va_arg(args, char *); va_end(args); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); _debugmsg(lvl, buf); } @@ -679,41 +655,25 @@ extern void debugmsg(va_alist) /* * Stdarg front-end to _debugmsg() */ -extern void debugmsg(int lvl, char *fmt, ...) +void +debugmsg(int lvl, char *fmt, ...) { static char buf[MSGBUFSIZ]; va_list args; va_start(args, fmt); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _debugmsg(lvl, buf); } #endif /* ARG_STDARG */ -#if !defined(ARG_TYPE) -/* - * Simple front-end to _debugmsg() - */ -/*VARARGS2*/ -extern void debugmsg(lvl, fmt, a1, a2, a3, a4, a5) - int lvl; - char *fmt; -{ - static char buf[MSGBUFSIZ]; - - (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); - - _debugmsg(lvl, buf); -} -#endif /* ARG_TYPE */ - /* * Print an error message */ -static void _error(msg) - char *msg; +static void +_error(char *msg) { static char buf[MSGBUFSIZ]; @@ -722,9 +682,11 @@ static void _error(msg) if (msg) { if (isserver) - (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg); + (void) snprintf(buf, sizeof(buf), + "REMOTE ERROR: %s", msg); else - (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg); + (void) snprintf(buf, sizeof(buf), + "LOCAL ERROR: %s", msg); } _message(MT_NERROR, (buf[0]) ? buf : NULL); @@ -734,7 +696,8 @@ static void _error(msg) /* * Varargs frontend to _error() */ -extern void error(va_alist) +void +error(va_alist) va_dcl { static char buf[MSGBUFSIZ]; @@ -745,7 +708,7 @@ extern void error(va_alist) va_start(args); fmt = (char *) va_arg(args, char *); if (fmt) - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _error((buf[0]) ? buf : NULL); @@ -756,7 +719,8 @@ extern void error(va_alist) /* * Stdarg frontend to _error() */ -extern void error(char *fmt, ...) +void +error(char *fmt, ...) { static char buf[MSGBUFSIZ]; va_list args; @@ -764,45 +728,27 @@ extern void error(char *fmt, ...) buf[0] = CNULL; va_start(args, fmt); if (fmt) - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _error((buf[0]) ? buf : NULL); } #endif /* ARG_STDARG */ -#if !defined(ARG_TYPE) -/* - * Simple frontend to _error() - */ -/*VARARGS1*/ -extern void error(fmt, a1, a2, a3, a4, a5, a6) - char *fmt; -{ - static char buf[MSGBUFSIZ]; - - buf[0] = CNULL; - if (fmt) - (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5, a6); - - _error((buf[0]) ? buf : NULL); -} -#endif /* ARG_TYPE */ - /* * Display a fatal message */ -static void _fatalerr(msg) - char *msg; +static void +_fatalerr(char *msg) { static char buf[MSGBUFSIZ]; ++nerrs; if (isserver) - (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg); + (void) snprintf(buf, sizeof(buf), "REMOTE ERROR: %s", msg); else - (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg); + (void) snprintf(buf, sizeof(buf), "LOCAL ERROR: %s", msg); _message(MT_FERROR, buf); @@ -813,7 +759,8 @@ static void _fatalerr(msg) /* * Varargs front-end to _fatalerr() */ -extern void fatalerr(va_alist) +void +fatalerr(va_alist) va_dcl { static char buf[MSGBUFSIZ]; @@ -822,7 +769,7 @@ extern void fatalerr(va_alist) va_start(args); fmt = (char *) va_arg(args, char *); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _fatalerr(buf); @@ -833,42 +780,28 @@ extern void fatalerr(va_alist) /* * Stdarg front-end to _fatalerr() */ -extern void fatalerr(char *fmt, ...) +void +fatalerr(char *fmt, ...) { static char buf[MSGBUFSIZ]; va_list args; va_start(args, fmt); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _fatalerr(buf); } #endif /* ARG_STDARG */ -#if !defined(ARG_TYPE) -/* - * Simple front-end to _fatalerr() - */ -/*VARARGS1*/ -extern void fatalerr(fmt, a1, a2, a3, a4, a5) - char *fmt; -{ - static char buf[MSGBUFSIZ]; - - (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); - - _fatalerr(buf); -} -#endif /* !ARG_TYPE */ - /* * Get the name of the file used for notify. * A side effect is that the file pointer to the file * is closed. We assume this function is only called when * we are ready to read the file. */ -extern char *getnotifyfile() +char * +getnotifyfile(void) { int i; diff --git a/usr.bin/rdist/os-openbsd.h b/usr.bin/rdist/os-openbsd.h index a8034a820a7..96c29e9bbd1 100644 --- a/usr.bin/rdist/os-openbsd.h +++ b/usr.bin/rdist/os-openbsd.h @@ -33,11 +33,11 @@ */ /* - * $OpenBSD: os-openbsd.h,v 1.11 2002/05/09 19:13:02 millert Exp $ + * $OpenBSD: os-openbsd.h,v 1.12 2003/05/14 01:34:35 millert Exp $ */ /* - * TEMPLATE os-*.h file + * OpenBSD os-*.h file */ /* @@ -63,9 +63,6 @@ * Determine what routines we have to get filesystem info. */ #define FSI_TYPE FSI_GETFSSTAT -#ifndef FSTYPENAME -#define FSTYPENAME 1 /* use f_fstypename */ -#endif /* * Type of non-blocking I/O. @@ -92,7 +89,12 @@ /* * Select the type of statfs() system call (if any). */ -#define STATFS_TYPE STATFS_BSD +#define STATFS_TYPE STATFS_44BSD + +/* + * Use f_fstypename in struct statfs. + */ +#define HAVE_FSTYPENAME 1 /* * Type of arg functions we have. @@ -128,23 +130,31 @@ typedef void POINTER; /* * Type of set line buffering function available */ -#define SETBUF_TYPE SETLINEBUF +#define SETBUF_TYPE SETBUF_SETLINEBUF /* * Things we have */ #define HAVE_FCHOWN /* Have fchown() */ +#define HAVE_LCHOWN /* Have lchown() */ #define HAVE_FCHMOD /* Have fchmod() */ +#define HAVE_FTRUNCATE /* Have ftruncate() */ #define HAVE_SELECT /* Have select() */ #define HAVE_SAVED_IDS /* Have POSIX style saved [ug]id's */ +#define HAVE_VIS /* Have vis() */ +#define HAVE_VSNPRINTF /* Have vsnprintf() */ #define POSIX_SIGNALS /* Have POSIX signals */ #define HAVE_PATHS_H /* Have <paths.h> */ /* - * Things we need + * Path to old-style rdist command + */ +#define _PATH_OLDRDIST "/usr/bin/oldrdist" + +/* + * Path to remote shell command */ -#define NEED_UNISTD_H /* Need <unistd.h> */ -#define NEED_STRING_H /* Need <string.h> */ +#define _PATH_REMSH "/usr/bin/ssh" /* * Use the system <paths.h> diff --git a/usr.bin/rdist/pathnames.h b/usr.bin/rdist/pathnames.h index 502a20cad13..3546cdd36ab 100644 --- a/usr.bin/rdist/pathnames.h +++ b/usr.bin/rdist/pathnames.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pathnames.h,v 1.6 2002/05/09 19:19:33 millert Exp $ */ +/* $OpenBSD: pathnames.h,v 1.7 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -34,7 +34,7 @@ */ /* - * $From: pathnames.h,v 6.8 1993/01/05 21:27:59 mcooper Exp mcooper $ + * $From: pathnames.h,v 1.1.1.1 1995/05/20 23:35:24 christos Exp $ * @(#)pathnames.h 5.4 (Berkeley) 8/27/90 */ @@ -47,7 +47,3 @@ #if !defined(_PATH_RDISTD) # define _PATH_RDISTD "rdistd" /* Rdist server */ #endif /* _PATH_RDISTD */ - -#if !defined(_PATH_SSH) -# define _PATH_SSH "ssh" /* ssh client */ -#endif /* _PATH_SSH */ diff --git a/usr.bin/rdist/rdist.1 b/usr.bin/rdist/rdist.1 index 22eaeaf39a3..b037a22a84e 100644 --- a/usr.bin/rdist/rdist.1 +++ b/usr.bin/rdist/rdist.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rdist.1,v 1.16 2003/04/25 14:53:03 jmc Exp $ +.\" $OpenBSD: rdist.1,v 1.17 2003/05/14 01:34:35 millert Exp $ .\" .\" Copyright (c) 1983 Regents of the University of California. .\" All rights reserved. @@ -330,6 +330,21 @@ master host, the remote target will be left a symbolic link. This behavior is generally considered a bug in the original version of .Nm rdist , but is present to allow compatibility with older versions. +.It Sy defgroup[=groupname] +If the group of a file to be transferred does not exist on the destination +host, use the specified group instead. +If groupname is not specified, the +.Em bin +group is used. +.It Sy defowner[=owner] +If the owner of a file to be transferred does not exist on the destination +host, use the specified owner instead. +If owner is not specified, the user +.Em bin +is used. +.It Sy updateperm +Do not send the whole file when the size and the modification time match. +Instead, just update the ownership, group, and permissions as necessary. .It Sy quiet Quiet mode. Files that are being modified are normally printed on standard output. @@ -368,6 +383,21 @@ Any target file that is updated is first renamed from .Pa file to .Pa file.OLD . +.It Sy history +When +.Sy savetargets +and +.Sy history +are both defined then the target file that is updated is first renamed from +.Pa file +to +.Pa file.NNN +where NNN increases for each generation update. +The first generation is 001, and the last is 999. +After 999 generations, the counter is reset to 001 and 001 will get +overwritten all the time. +This is undesirable behavior, so some other method needs to be devised +to clean up or limit the number of generations. .It Sy sparse Enable checking for sparse (aka .Dq wholely ) @@ -809,3 +839,11 @@ then .Nm will report missing links. Only one instance of a link should be listed in each target. +.Pp +The +.Sy defowner, +.Sy defgroup, +and +.Sy updateperm +options are extensions to the 6.1.0 protocol and will not work with earlier +versions of rdist 6. diff --git a/usr.bin/rdist/rdist.c b/usr.bin/rdist/rdist.c index 7662a57f54e..40ea1c09e1d 100644 --- a/usr.bin/rdist/rdist.c +++ b/usr.bin/rdist/rdist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdist.c,v 1.15 2003/05/06 22:10:11 millert Exp $ */ +/* $OpenBSD: rdist.c,v 1.16 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,25 +33,27 @@ * SUCH DAMAGE. */ +#include "defs.h" +#include "y.tab.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: rdist.c,v 6.65 1995/12/12 00:20:39 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: rdist.c,v 1.6 2001/03/12 18:16:36 kim Exp $"; #else -static char RCSid[] = -"$OpenBSD: rdist.c,v 1.15 2003/05/06 22:10:11 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: rdist.c,v 1.16 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)main.c 5.1 (Berkeley) 6/6/85"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)main.c 5.1 (Berkeley) 6/6/85"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ -#include "defs.h" -#include "y.tab.h" #include <netdb.h> #include <sys/ioctl.h> @@ -59,29 +61,27 @@ static char copyright[] = * Remote distribution program. */ -void docmdargs(int, char **); -void usage(void); - char *distfile = NULL; /* Name of distfile to use */ int maxchildren = MAXCHILDREN; /* Max no of concurrent PIDs */ int nflag = 0; /* Say without doing */ long min_freespace = 0; /* Min filesys free space */ long min_freefiles = 0; /* Min filesys free # files */ FILE *fin = NULL; /* Input file pointer */ -struct group *gr = NULL; /* Static area for getgrent */ char localmsglist[] = "stdout=all:notify=all:syslog=nerror,ferror"; char *remotemsglist = NULL; char optchars[] = "A:a:bcd:DFf:hil:L:M:m:NnOo:p:P:qRrst:Vvwxy"; -FILE *opendist(); char *path_rdistd = _PATH_RDISTD; char *path_remsh = NULL; +static void addhostlist(char *, struct namelist **); +static void usage(void); +int main(int, char **, char **); + /* * Add a hostname to the host list */ -static void addhostlist(name, hostlist) - char *name; - struct namelist **hostlist; +static void +addhostlist(char *name, struct namelist **hostlist) { struct namelist *ptr, *new; @@ -102,29 +102,30 @@ static void addhostlist(name, hostlist) } int -main(argc, argv, envp) - int argc; - char *argv[]; - char **envp; +main(int argc, char **argv, char **envp) { + extern char *__progname; struct namelist *hostlist = NULL; int x; char *cp; int cmdargs = 0; int c; - /* - * We initialize progname here instead of init() because - * things in msgparseopts() need progname set. - */ - setprogname(argv); + progname = __progname; - if ((cp = msgparseopts(localmsglist, TRUE))) { + if ((cp = msgparseopts(localmsglist, TRUE)) != NULL) { error("Bad builtin log option (%s): %s.", localmsglist, cp); usage(); } + if ((cp = getenv("RDIST_OPTIONS")) != NULL) + if (parsedistopts(cp, &options, TRUE)) { + error("Bad dist option environment string \"%s\".", + cp); + exit(1); + } + if (init(argc, argv, envp) < 0) exit(1); @@ -163,7 +164,7 @@ main(argc, argv, envp) while ((c = getopt(argc, argv, optchars)) != -1) switch (c) { case 'l': - if ((cp = msgparseopts(optarg, TRUE))) { + if ((cp = msgparseopts(optarg, TRUE)) != NULL) { error("Bad log option \"%s\": %s.", optarg,cp); usage(); } @@ -177,7 +178,7 @@ main(argc, argv, envp) case 'a': case 'M': case 't': - if (!isdigit(*optarg)) { + if (!isdigit((unsigned char)*optarg)) { error("\"%s\" is not a number.", optarg); usage(); } @@ -211,7 +212,8 @@ main(argc, argv, envp) case 'D': debug = DM_ALL; - if ((cp = msgparseopts("stdout=all,debug", TRUE))) { + if ((cp = msgparseopts("stdout=all,debug", + TRUE)) != NULL) { error("Enable debug messages failed: %s.", cp); usage(); } @@ -250,7 +252,7 @@ main(argc, argv, envp) error("No path specified to \"-P\"."); usage(); } - if ((cp = searchpath(optarg))) + if ((cp = searchpath(optarg)) != NULL) path_remsh = xstrdup(cp); else { error("No component of path \"%s\" exists.", @@ -295,7 +297,7 @@ main(argc, argv, envp) if ((cp = getenv("RSH")) != NULL && *cp != '\0') path_remsh = cp; else - path_remsh = _PATH_SSH; + path_remsh = _PATH_REMSH; } /* @@ -325,8 +327,8 @@ main(argc, argv, envp) /* * Open a distfile */ -FILE *opendist(distfile) - char *distfile; +FILE * +opendist(char *distfile) { char *file = NULL; FILE *fp; @@ -360,8 +362,8 @@ FILE *opendist(distfile) /* * Print usage message and exit. */ -void -usage() +static void +usage(void) { char *sopts = "cDFnv"; @@ -393,9 +395,7 @@ usage() * rcp like interface for distributing files. */ void -docmdargs(nargs, args) - int nargs; - char *args[]; +docmdargs(int nargs, char **args) { struct namelist *nl, *prev; char *cp; @@ -442,19 +442,19 @@ docmdargs(nargs, args) debugmsg(DM_MISC, "host = %s", getnlstr(hosts)); insert(NULL, files, hosts, cmds); - docmds(0, NULL, 0, (char **)NULL); + docmds(NULL, 0, NULL); } /* * Get a list of NAME blocks (mostly for debugging). */ -extern char *getnlstr(nl) - struct namelist *nl; +char * +getnlstr(struct namelist *nl) { static char buf[16384]; - int count = 0, len = 0; + size_t len = 0; - (void) snprintf(buf, sizeof buf, "("); + (void) snprintf(buf, sizeof(buf), "("); while (nl != NULL) { if (nl->n_name == NULL) @@ -462,17 +462,16 @@ extern char *getnlstr(nl) len += strlen(nl->n_name) + 2; if (len >= sizeof(buf)) { (void) strlcpy(buf, - "getnlstr() Buffer not large enough", - sizeof buf); + "getnlstr() Buffer not large enough", + sizeof(buf)); return(buf); } - ++count; - (void) strlcat(buf, " ", sizeof buf); - (void) strlcat(buf, nl->n_name, sizeof buf); + (void) strlcat(buf, " ", sizeof(buf)); + (void) strlcat(buf, nl->n_name, sizeof(buf)); nl = nl->n_next; } - (void) strlcat(buf, " )", sizeof buf); + (void) strlcat(buf, " )", sizeof(buf)); return(buf); } diff --git a/usr.bin/rdist/types.h b/usr.bin/rdist/types.h index d98322ebdc8..f11a86b2c6a 100644 --- a/usr.bin/rdist/types.h +++ b/usr.bin/rdist/types.h @@ -1,10 +1,10 @@ -/* $OpenBSD: types.h,v 1.4 1998/06/26 21:21:22 millert Exp $ */ +/* $OpenBSD: types.h,v 1.5 2003/05/14 01:34:35 millert Exp $ */ #ifndef __myTYPES_H__ #define __myTYPES_H__ /* - * $From: types.h,v 1.2 1996/01/30 01:52:24 mcooper Exp $ + * $From: types.h,v 1.5 1999/08/04 15:57:31 christos Exp $ */ /* @@ -12,26 +12,30 @@ * * WARNING: This values are used by the server (rdistd) */ -#define DO_VERIFY 0x000001 -#define DO_WHOLE 0x000002 -#define DO_YOUNGER 0x000004 -#define DO_COMPARE 0x000008 -#define DO_REMOVE 0x000010 -#define DO_FOLLOW 0x000020 -#define DO_IGNLNKS 0x000040 -#define DO_QUIET 0x000100 -#define DO_CHKNFS 0x000200 -#define DO_CHKREADONLY 0x000400 -#define DO_NOEXEC 0x000800 -#define DO_SAVETARGETS 0x001000 -#define DO_NODESCEND 0x002000 -#define DO_NOCHKOWNER 0x004000 -#define DO_NOCHKMODE 0x008000 -#define DO_NOCHKGROUP 0x010000 -#define DO_CHKSYM 0x020000 -#define DO_NUMCHKGROUP 0x040000 -#define DO_NUMCHKOWNER 0x080000 -#define DO_SPARSE 0x100000 +#define DO_VERIFY 0x0000001 +#define DO_WHOLE 0x0000002 +#define DO_YOUNGER 0x0000004 +#define DO_COMPARE 0x0000008 +#define DO_REMOVE 0x0000010 +#define DO_FOLLOW 0x0000020 +#define DO_IGNLNKS 0x0000040 +#define DO_QUIET 0x0000100 +#define DO_CHKNFS 0x0000200 +#define DO_CHKREADONLY 0x0000400 +#define DO_NOEXEC 0x0000800 +#define DO_SAVETARGETS 0x0001000 +#define DO_NODESCEND 0x0002000 +#define DO_NOCHKOWNER 0x0004000 +#define DO_NOCHKMODE 0x0008000 +#define DO_NOCHKGROUP 0x0010000 +#define DO_CHKSYM 0x0020000 +#define DO_NUMCHKGROUP 0x0040000 +#define DO_NUMCHKOWNER 0x0080000 +#define DO_HISTORY 0x0100000 +#define DO_UPDATEPERM 0x0200000 +#define DO_DEFGROUP 0x0400000 +#define DO_DEFOWNER 0x0800000 +#define DO_SPARSE 0x1000000 /* XXX not implemented */ /* * Dist option information @@ -40,6 +44,8 @@ typedef long opt_t; struct _distoptinfo { opt_t do_value; char *do_name; + char *do_arg; + size_t arg_size; }; typedef struct _distoptinfo DISTOPTINFO; @@ -81,17 +87,19 @@ typedef struct _msgtype MSGTYPE; /* * Description of message facilities */ +typedef struct _msgfacility MSGFACILITY; + struct _msgfacility { /* compile time initialized data */ int mf_msgfac; /* One of MF_* from below */ char *mf_name; /* Name of this facility */ - void (*mf_sendfunc)(); /* Function to send msg */ + void (*mf_sendfunc) /* Function to send msg */ + (MSGFACILITY *, int, int, char *); /* run time initialized data */ int mf_msgtypes; /* Bitmask of MT_* from above*/ char *mf_filename; /* Name of file */ FILE *mf_fptr; /* File pointer to output to */ }; -typedef struct _msgfacility MSGFACILITY; /* * Message Facilities diff --git a/usr.bin/rdist/version.h b/usr.bin/rdist/version.h index f0e0c1206a9..cda63122476 100644 --- a/usr.bin/rdist/version.h +++ b/usr.bin/rdist/version.h @@ -1,4 +1,4 @@ -/* $OpenBSD: version.h,v 1.5 1998/06/26 21:21:24 millert Exp $ */ +/* $OpenBSD: version.h,v 1.6 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -34,7 +34,7 @@ */ /* - * $From: version.h,v 6.31 1998/03/15 22:25:55 mcooper Exp $ + * $From: version.h,v 1.2 1999/11/01 00:19:36 christos Exp $ */ /* @@ -46,15 +46,16 @@ /* * Distribution version. The major distribution number should match * the protocol version number (VERSION) defined above. + * This is not true anymore for freerdist */ -#define DISTVERSION "6.1" +#define DISTVERSION "0.92" /* * Patch level */ -#define PATCHLEVEL 4 +#define PATCHLEVEL 0 /* * Distribution status */ -#define DISTSTATUS "RELEASE" +#define DISTSTATUS "BETA" diff --git a/usr.bin/rdistd/filesys-os.c b/usr.bin/rdistd/filesys-os.c index 449dd124f4d..cef5e5e1d0e 100644 --- a/usr.bin/rdistd/filesys-os.c +++ b/usr.bin/rdistd/filesys-os.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filesys-os.c,v 1.7 2003/04/05 20:31:58 deraadt Exp $ */ +/* $OpenBSD: filesys-os.c,v 1.8 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,20 @@ * SUCH DAMAGE. */ +#include "defs.h" #ifndef lint #if 0 -static char RCSid[] = -"$From: filesys-os.c,v 6.17 1996/01/17 21:02:45 mcooper Exp mcooper $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: filesys-os.c,v 1.5 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: filesys-os.c,v 1.7 2003/04/05 20:31:58 deraadt Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: filesys-os.c,v 1.8 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)filesys-os.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)filesys-os.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ @@ -53,16 +55,8 @@ static char copyright[] = * OS specific file system routines */ -#include "defs.h" -#include "filesys.h" - #if FSI_TYPE == FSI_GETFSSTAT static struct statfs *mnt = NULL; -#if FSTYPENAME -#define f_type_eq(a, b) (! strcmp (((struct statfs *) (a))->f_fstypename, (b))) -#else /* !FSTYPENAME */ -#define f_type_eq(a, b) (((struct statfs *) a)->f_type == (b)) -#endif /* !FSTYPENAME */ #endif /* FSI_GETFSSTAT */ #if FSI_TYPE == FSI_MNTCTL @@ -78,10 +72,8 @@ static int entries_left; /* * AIX version of setmountent() */ -FILE *setmountent(file, mode) - /*ARGSUSED*/ - char *file; - char *mode; +FILE * +setmountent(const char *file, const char *mode) { ulong size; @@ -104,10 +96,8 @@ FILE *setmountent(file, mode) /* * getfsstat() version of get mount info routines. */ -FILE *setmountent(file, mode) - /*ARGSUSED*/ - char *file; - char *mode; +FILE * +setmountent(const char *file, const char *mode) { long size; @@ -137,9 +127,8 @@ FILE *setmountent(file, mode) /* * Iterate over mount entries */ -mntent_t *getmountent(fptr) - /*ARGSUSED*/ - FILE *fptr; +mntent_t * +getmountent(FILE *fptr) { static mntent_t mntstruct; @@ -172,9 +161,8 @@ mntent_t *getmountent(fptr) /* * getfsstat() version of getmountent() */ -mntent_t *getmountent(fptr) - /*ARGSUSED*/ - FILE *fptr; +mntent_t * +getmountent(FILE *fptr) { static mntent_t mntstruct; static char remote_dev[MAXHOSTNAMELEN+MAXPATHLEN+1]; @@ -192,9 +180,14 @@ mntent_t *getmountent(fptr) if (mnt->f_flags & M_RDONLY) mntstruct.me_flags |= MEFLAG_READONLY; #endif - if (f_type_eq(mnt, MOUNT_NFS)) { - (void) snprintf(remote_dev, sizeof remote_dev, - "%s", mnt->f_mntfromname); + +#ifdef HAVE_FSTYPENAME + if (strcmp(mnt->f_fstypename, "nfs") == 0) +#else + if (mnt->f_type == MOUNT_NFS) +#endif /* HAVE_FSTYPENAME */ + { + strlcpy(remote_dev, mnt->f_mntfromname, sizeof(remote_dev)); mntstruct.me_path = remote_dev; mntstruct.me_type = METYPE_NFS; } else { @@ -213,9 +206,8 @@ mntent_t *getmountent(fptr) /* * Done with iterations */ -void endmountent(fptr) - /*ARGSUSED*/ - FILE *fptr; +void +endmountent(FILE *fptr) { mnt = NULL; @@ -230,10 +222,8 @@ void endmountent(fptr) /* * Prepare to iterate over mounted filesystem list */ -FILE *setmountent(file, mode) - /*ARGSUSED*/ - char *file; - char *mode; +FILE * +setmountent(const char *file, const char *mode) { return(fopen(file, mode)); } @@ -241,9 +231,8 @@ FILE *setmountent(file, mode) /* * Done with iteration */ -void endmountent(fptr) - /*ARGSUSED*/ - FILE *fptr; +void +endmountent(FILE *fptr) { fclose(fptr); } @@ -251,8 +240,8 @@ void endmountent(fptr) /* * Iterate over mount entries */ -mntent_t *getmountent(fptr) - FILE *fptr; +mntent_t * +getmountent(FILE *fptr) { static mntent_t me; static struct mnttab mntent; @@ -288,10 +277,8 @@ mntent_t *getmountent(fptr) /* * Prepare to iterate over mounted filesystem list */ -FILE *setmountent(file, mode) - /*ARGSUSED*/ - char *file; - char *mode; +FILE * +setmountent(const char *file, const char *mode) { return(setmntent(file, mode)); } @@ -299,9 +286,8 @@ FILE *setmountent(file, mode) /* * Done with iteration */ -void endmountent(fptr) - /*ARGSUSED*/ - FILE *fptr; +void +endmountent(FILE *fptr) { endmntent(fptr); } @@ -309,15 +295,15 @@ void endmountent(fptr) /* * Iterate over mount entries */ -mntent_t *getmountent(fptr) - FILE *fptr; +mntent_t * +getmountent(FILE *fptr) { static mntent_t me; struct mntent *mntent; bzero((char *)&me, sizeof(mntent_t)); - if (mntent = getmntent(fptr)) { + if ((mntent = getmntent(fptr)) != NULL) { me.me_path = mntent->mnt_dir; me.me_type = mntent->mnt_type; if (mntent->mnt_opts && hasmntopt(mntent, MNTOPT_RO)) @@ -347,18 +333,15 @@ mntent_t *getmountent(fptr) static int startmounts = 0; -FILE *setmountent(file, mode) - /*ARGSUSED*/ - char *file; - char *mode; +FILE * +setmountent(const char *file, const char *mode) { startmounts = 0; - return(stdin); /* XXX - need to return something! */ + return((FILE *) 1); } -void endmountent(fptr) - /*ARGSUSED*/ - FILE *fptr; +void +endmountent(FILE *fptr) { /* NOOP */ } @@ -366,9 +349,8 @@ void endmountent(fptr) /* * Iterate over mounted filesystems using getmnt() */ -mntent_t *getmountent(fptr) - /*ARGSUSED*/ - FILE *fptr; +mntent_t * +getmountent(FILE *fptr) { struct fs_data fs_data; static mntent_t me; @@ -394,8 +376,8 @@ mntent_t *getmountent(fptr) /* * Make a new (copy) of a mntent structure. */ -mntent_t *newmountent(old) - mntent_t *old; +mntent_t * +newmountent(const mntent_t *old) { mntent_t *new; diff --git a/usr.bin/rdistd/filesys.c b/usr.bin/rdistd/filesys.c index 4ec9c0c56b2..74d3739d2af 100644 --- a/usr.bin/rdistd/filesys.c +++ b/usr.bin/rdistd/filesys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filesys.c,v 1.8 2003/04/05 20:31:58 deraadt Exp $ */ +/* $OpenBSD: filesys.c,v 1.9 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,21 @@ * SUCH DAMAGE. */ +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: filesys.c,v 6.24 1996/01/30 01:57:07 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: filesys.c,v 1.2 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: filesys.c,v 1.8 2003/04/05 20:31:58 deraadt Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: filesys.c,v 1.9 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)filesys.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)filesys.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ @@ -54,8 +57,6 @@ static char copyright[] = * about mounted filesystems. */ -#include "defs.h" -#include "filesys.h" jmp_buf env; @@ -63,10 +64,8 @@ jmp_buf env; * Given a pathname, find the fullest component that exists. * If statbuf is not NULL, set it to point at our stat buffer. */ -char *find_file(pathname, statbuf, isvalid) - char *pathname; - struct stat *statbuf; - int *isvalid; +char * +find_file(char *pathname, struct stat *statbuf, int *isvalid) { static char last_pathname[MAXPATHLEN]; static char file[MAXPATHLEN + 3]; @@ -92,7 +91,7 @@ char *find_file(pathname, statbuf, isvalid) return(file); } - if ((int)strlen(pathname) > sizeof(file)+3) { + if (strlen(pathname) > sizeof(file) + 3) { error("%s: Name to large for buffer.", pathname); return(NULL); } @@ -100,18 +99,18 @@ char *find_file(pathname, statbuf, isvalid) /* * Save for next time */ - (void) strlcpy(last_pathname, pathname, sizeof last_pathname); + (void) strlcpy(last_pathname, pathname, sizeof(last_pathname)); if (*pathname == '/') - (void) strlcpy(file, pathname, sizeof file); + (void) strlcpy(file, pathname, sizeof(file)); else { /* * Ensure we have a directory (".") in our path * so we have something to stat in case the file * does not exist. */ - (void) strlcpy(file, "./", sizeof file); - (void) strlcat(file, pathname, sizeof file); + (void) strlcpy(file, "./", sizeof(file)); + (void) strlcat(file, pathname, sizeof(file)); } while (lstat(file, &filestat) != 0) { @@ -124,12 +123,12 @@ char *find_file(pathname, statbuf, isvalid) * Normally we want to change /dir1/dir2/file * into "/dir1/dir2/." */ - if ((p = (char *) strrchr(file, '/'))) { + if ((p = (char *) strrchr(file, '/')) != NULL) { if (strcmp(p, "/.") == 0) { - *p = CNULL; + *p = CNULL; } else { - *++p = '.'; - *++p = CNULL; + *++p = '.'; + *++p = CNULL; } } else { /* @@ -182,9 +181,8 @@ char *find_file(pathname, statbuf, isvalid) /* * Find the device that "filest" is on in the "mntinfo" linked list. */ -mntent_t *findmnt(filest, mntinfo) - struct stat *filest; - struct mntinfo *mntinfo; +mntent_t * +findmnt(struct stat *filest, struct mntinfo *mntinfo) { struct mntinfo *mi; @@ -201,9 +199,8 @@ mntent_t *findmnt(filest, mntinfo) /* * Is "mnt" a duplicate of any of the mntinfo->mi_mnt elements? */ -int isdupmnt(mnt, mntinfo) - mntent_t *mnt; - struct mntinfo *mntinfo; +int +isdupmnt(mntent_t *mnt, struct mntinfo *mntinfo) { struct mntinfo *m; @@ -217,7 +214,8 @@ int isdupmnt(mnt, mntinfo) /* * Alarm clock */ -void wakeup() +void +wakeup(int dummy) { debugmsg(DM_CALL, "wakeup() in filesys.c called"); longjmp(env, 1); @@ -227,8 +225,8 @@ void wakeup() * Make a linked list of mntinfo structures. * Use "mi" as the base of the list if it's non NULL. */ -struct mntinfo *makemntinfo(mi) - struct mntinfo *mi; +struct mntinfo * +makemntinfo(struct mntinfo *mi) { FILE *mfp; static struct mntinfo *mntinfo; @@ -251,7 +249,7 @@ struct mntinfo *makemntinfo(mi) } mntinfo = mi; - while ((mnt = getmountent(mfp))) { + while ((mnt = getmountent(mfp)) != NULL) { debugmsg(DM_MISC, "mountent = '%s' (%s)", mnt->me_path, mnt->me_type); @@ -284,7 +282,8 @@ struct mntinfo *makemntinfo(mi) * Add entry to list */ if (mntinfo) { - for (m = mntinfo; m->mi_nxt; m = m->mi_nxt); + for (m = mntinfo; m->mi_nxt; m = m->mi_nxt) + continue; m->mi_nxt = newmi; } else mntinfo = newmi; @@ -303,10 +302,8 @@ struct mntinfo *makemntinfo(mi) * If "statbuf" is not NULL it is used as the stat buffer too avoid * stat()'ing the file again back in server.c. */ -mntent_t *getmntpt(pathname, statbuf, isvalid) - char *pathname; - struct stat *statbuf; - int *isvalid; +mntent_t * +getmntpt(char *pathname, struct stat *statbuf, int *isvalid) { static struct mntinfo *mntinfo = NULL; static struct stat filestat; @@ -334,16 +331,16 @@ mntent_t *getmntpt(pathname, statbuf, isvalid) /* * Find the mnt that pathname is on. */ - if ((mnt = findmnt(pstat, mntinfo))) + if ((mnt = findmnt(pstat, mntinfo)) != NULL) return(mnt); /* * We failed to find correct mnt, so maybe it's a newly * mounted filesystem. We rebuild mntinfo and try again. */ - if ((tmpmi = makemntinfo(mntinfo))) { + if ((tmpmi = makemntinfo(mntinfo)) != NULL) { mntinfo = tmpmi; - if ((mnt = findmnt(pstat, mntinfo))) + if ((mnt = findmnt(pstat, mntinfo)) != NULL) return(mnt); } @@ -357,10 +354,8 @@ mntent_t *getmntpt(pathname, statbuf, isvalid) /* * Is "path" NFS mounted? Return 1 if it is, 0 if not, or -1 on error. */ -int is_nfs_mounted(path, statbuf, isvalid) - char *path; - struct stat *statbuf; - int *isvalid; +int +is_nfs_mounted(char *path, struct stat *statbuf, int *isvalid) { mntent_t *mnt; @@ -383,10 +378,8 @@ int is_nfs_mounted(path, statbuf, isvalid) * Is "path" on a read-only mounted filesystem? * Return 1 if it is, 0 if not, or -1 on error. */ -int is_ro_mounted(path, statbuf, isvalid) - char *path; - struct stat *statbuf; - int *isvalid; +int +is_ro_mounted(char *path, struct stat *statbuf, int *isvalid) { mntent_t *mnt; @@ -404,11 +397,8 @@ int is_ro_mounted(path, statbuf, isvalid) * Is "path" a symlink? * Return 1 if it is, 0 if not, or -1 on error. */ -int is_symlinked(path, statbuf, isvalid) - /*ARGSUSED*/ - char *path; - struct stat *statbuf; - int *isvalid; +int +is_symlinked(char *path, struct stat *statbuf, int *isvalid) { static struct stat stb; @@ -432,10 +422,8 @@ int is_symlinked(path, statbuf, isvalid) * Filesystem values < 0 indicate unsupported or unavailable * information. */ -int getfilesysinfo(file, freespace, freefiles) - char *file; - long *freespace; - long *freefiles; +int +getfilesysinfo(char *file, long *freespace, long *freefiles) { #if defined(STATFS_TYPE) static statfs_t statfsbuf; @@ -457,7 +445,7 @@ int getfilesysinfo(file, freespace, freefiles) #if STATFS_TYPE == STATFS_SYSV r = statfs(mntpt, &statfsbuf, sizeof(statfs_t), 0); #endif -#if STATFS_TYPE == STATFS_BSD +#if STATFS_TYPE == STATFS_BSD || STATFS_TYPE == STATFS_44BSD r = statfs(mntpt, &statfsbuf); #endif #if STATFS_TYPE == STATFS_OSF1 diff --git a/usr.bin/rdistd/rdistd.c b/usr.bin/rdistd/rdistd.c index cfe201c2591..d582a7d7e0a 100644 --- a/usr.bin/rdistd/rdistd.c +++ b/usr.bin/rdistd/rdistd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdistd.c,v 1.4 1998/06/26 21:20:51 millert Exp $ */ +/* $OpenBSD: rdistd.c,v 1.5 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,29 +33,33 @@ * SUCH DAMAGE. */ +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: rdistd.c,v 6.22 1995/12/11 23:37:35 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: rdistd.c,v 1.2 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: rdistd.c,v 1.4 1998/06/26 21:20:51 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: rdistd.c,v 1.5 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)rdistd.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)rdistd.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ - -#include "defs.h" +int main(int, char **, char **); +static void usage(void); /* * Print usage message */ -static void usage() +static void +usage(void) { fprintf(stderr, "usage: %s -S [ -DV ]\n", progname); exit(1); @@ -67,14 +71,14 @@ char localmsglist[] = "syslog=ferror"; * The Beginning */ int -main(argc, argv, envp) - int argc; - char **argv; - char **envp; +main(int argc, char **argv, char **envp) { + extern char *__progname; char *cp; int c; + progname = __progname; + if (init(argc, argv, envp) < 0) exit(1); @@ -108,7 +112,7 @@ main(argc, argv, envp) rem_w = fileno(stdout); /* Set logging */ - if ((cp = msgparseopts(localmsglist, TRUE))) + if ((cp = msgparseopts(localmsglist, TRUE)) != NULL) fatalerr("Bad message logging option (%s): %s", localmsglist, cp); diff --git a/usr.bin/rdistd/server.c b/usr.bin/rdistd/server.c index 23001b6e78e..9454f590562 100644 --- a/usr.bin/rdistd/server.c +++ b/usr.bin/rdistd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.13 2003/04/19 17:22:30 millert Exp $ */ +/* $OpenBSD: server.c,v 1.14 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -32,18 +32,21 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: server.c,v 6.85 1996/03/12 22:55:38 mcooper Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: server.c,v 1.10 1999/08/04 15:57:33 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: server.c,v 1.13 2003/04/19 17:22:30 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: server.c,v 1.14 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)server.c 5.3 (Berkeley) 6/7/86"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)server.c 5.3 (Berkeley) 6/7/86"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ @@ -52,8 +55,6 @@ static char copyright[] = * Server routines */ -#include "defs.h" - char tempname[sizeof _RDIST_TMP + 1]; /* Tmp file name */ char buf[BUFSIZ]; /* general purpose buffer */ char target[MAXPATHLEN]; /* target/source directory name */ @@ -65,11 +66,32 @@ static long min_freespace = 0; /* Minimium free space on a filesystem */ static long min_freefiles = 0; /* Minimium free # files on a filesystem */ int oumask; /* Old umask */ +static int cattarget(char *); +static int setownership(char *, int, UID_T, GID_T, int); +static int setfilemode(char *, int, int, int); +static int fchog(int, char *, char *, char *, int); +static int removefile(struct stat *, int); +static void doclean(char *); +static void clean(char *); +static void dospecial(char *); +static void docmdspecial(void); +static void query(char *); +static int chkparent(char *, opt_t); +static char *savetarget(char *, opt_t); +static void recvfile(char *, opt_t, int, char *, char *, time_t, time_t, off_t); +static void recvdir(opt_t, int, char *, char *); +static void recvlink(char *, opt_t, int, off_t); +static void hardlink(char *); +static void setconfig(char *); +static void recvit(char *, int); +static void dochmog(char *); +static void settarget(char *, int); + /* * Cat "string" onto the target buffer with error checking. */ -static int cattarget(string) - char *string; +static int +cattarget(char *string) { if (strlen(string) + strlen(target) + 2 > sizeof(target)) { message(MT_INFO, "target buffer is not large enough."); @@ -80,8 +102,8 @@ static int cattarget(string) return(-10); } - (void) snprintf(ptarget, target + sizeof(target) - ptarget, - "/%s", string); + (void) snprintf(ptarget, sizeof(target) - (ptarget - target), + "/%s", string); return(0); } @@ -89,47 +111,47 @@ static int cattarget(string) /* * Set uid and gid ownership of a file. */ -static int setownership(file, fd, uid, gid) - char *file; - int fd; - UID_T uid; - GID_T gid; +static int +setownership(char *file, int fd, UID_T uid, GID_T gid, int link) { int status = -1; /* * We assume only the Superuser can change uid ownership. */ - if (getuid() == 0) { -#if defined(HAVE_FCHOWN) - if (fd != -1) - status = fchown(fd, (CHOWN_UID_T) uid, - (CHOWN_GID_T) gid); + if (getuid() != 0) + uid = -1; + + /* + * If we are dealing with a symlink, only try to change it if + * we have lchown, if we don't leave it alone. + */ +#if defined(HAVE_LCHOWN) + if (link) + status = lchown(file, (CHOWN_UID_T) uid, + (CHOWN_GID_T) gid); +#else + if (link) + return 0; #endif - if (status < 0) - status = chown(file, (CHOWN_UID_T) uid, - (CHOWN_GID_T) gid); - - if (status < 0) { - message(MT_NOTICE, "%s: chown %d:%d failed: %s", - target, (UID_T) uid, (GID_T) gid, SYSERR); - return(-1); - } - } else { + #if defined(HAVE_FCHOWN) - if (fd != -1) - status = fchown(fd, (CHOWN_UID_T) -1, - (CHOWN_GID_T) gid); + if (fd != -1 && !link) + status = fchown(fd, (CHOWN_UID_T) uid, + (CHOWN_GID_T) gid); #endif - if (status < 0) - status = chown(file, (CHOWN_UID_T) -1, - (CHOWN_GID_T) gid); + if (status < 0 && !link) + status = chown(file, (CHOWN_UID_T) uid, + (CHOWN_GID_T) gid); - if (status < 0) { + if (status < 0) { + if (uid == (UID_T) -1) message(MT_NOTICE, "%s: chgrp %d failed: %s", - target, (GID_T) gid, SYSERR); - return(-1); - } + target, gid, SYSERR); + else + message(MT_NOTICE, "%s: chown %d.%d failed: %s", + target, uid, gid, SYSERR); + return(-1); } return(0); @@ -138,22 +160,32 @@ static int setownership(file, fd, uid, gid) /* * Set mode of a file */ -static int setfilemode(file, fd, mode) - char *file; - int fd; - int mode; +static int +setfilemode(char *file, int fd, int mode, int link) { int status = -1; if (mode == -1) return(0); + /* + * If we are dealing with a symlink, only try to change it if + * we have lchown, if we don't leave it alone. + */ +#if defined(HAVE_LCHMOD) + if (link) + status = lchmod(file, mode); +#else + if (link) + return 0; +#endif + #if defined(HAVE_FCHMOD) - if (fd != -1) + if (fd != -1 && !link) status = fchmod(fd, mode); #endif - if (status < 0) + if (status < 0 && !link) status = chmod(file, mode); if (status < 0) { @@ -163,41 +195,16 @@ static int setfilemode(file, fd, mode) return(0); } - -/* - * Get group entry. This routine takes a string argument (name). - * If name is of form ":N" a lookup for gid N is done. - * Otherwise a lookup by name is done. - */ -static struct group *mygetgroup(name) - char *name; -{ - struct group *gr; - - if (*name == ':') - gr = getgrgid(atoi(name + 1)); - else - gr = getgrnam(name); - - return(gr); -} - /* * Change owner, group and mode of file. */ -static int fchog(fd, file, owner, group, mode) - int fd; - char *file, *owner, *group; - int mode; +static int +fchog(int fd, char *file, char *owner, char *group, int mode) { - struct group *gr = NULL; - static char last_group[128]; - static char last_owner[128]; - static GID_T last_gid = (GID_T)-2; - static UID_T last_uid = (UID_T)-2; - static GID_T last_primegid; + static struct group *gr = NULL; extern char *locuser; int i; + struct stat st; UID_T uid; GID_T gid; GID_T primegid = (GID_T)-2; @@ -206,8 +213,7 @@ static int fchog(fd, file, owner, group, mode) if (userid == 0) { /* running as root; take anything */ if (*owner == ':') { uid = (UID_T) atoi(owner + 1); - } else if (last_uid == (UID_T)-2 || - strcmp(owner, last_owner) != 0) { + } else if (pw == NULL || strcmp(owner, pw->pw_name) != 0) { if ((pw = getpwnam(owner)) == NULL) { if (mode != -1 && IS_ON(mode, S_ISUID)) { message(MT_NOTICE, @@ -219,14 +225,11 @@ static int fchog(fd, file, owner, group, mode) message(MT_NOTICE, "%s: unknown login name \"%s\"", target, owner); - } else { - uid = last_uid = pw->pw_uid; - primegid = last_primegid = pw->pw_gid; - strlcpy(last_owner, owner, sizeof last_owner); - } + } else + uid = pw->pw_uid; } else { - uid = last_uid; - primegid = last_primegid; + uid = pw->pw_uid; + primegid = pw->pw_gid; } if (*group == ':') { gid = (GID_T) atoi(group + 1); @@ -248,14 +251,10 @@ static int fchog(fd, file, owner, group, mode) } gid = (GID_T) -1; - if (last_gid < (GID_T)0 || strcmp(group, last_group) != 0) { - /* - * Invalid cached values so we need to do a new lookup. - */ - if ((gr = mygetgroup(group))) { - last_gid = gid = gr->gr_gid; - strlcpy(last_group, gr->gr_name, sizeof last_group); - } else { + if (gr == NULL || strcmp(group, gr->gr_name) != 0) { + if ((*group == ':' && + (getgrgid(gid = atoi(group + 1)) == NULL)) + || ((gr = (struct group *)getgrnam(group)) == NULL)) { if (mode != -1 && IS_ON(mode, S_ISGID)) { message(MT_NOTICE, "%s: unknown group \"%s\", clearing setgid", @@ -265,24 +264,15 @@ static int fchog(fd, file, owner, group, mode) message(MT_NOTICE, "%s: unknown group \"%s\"", target, group); - } - } else { - /* - * Use the cached values. - */ - gid = last_gid; - } + } else + gid = gr->gr_gid; + } else + gid = gr->gr_gid; - /* - * We need to check non-root users to make sure they're a member - * of the group. If they are not, we don't set that gid ownership. - */ if (userid && gid >= 0 && gid != primegid) { - if (!gr) - gr = mygetgroup(group); if (gr) for (i = 0; gr->gr_mem[i] != NULL; i++) - if (strcmp(locuser, gr->gr_mem[i]) == 0) + if (strcmp(locuser, gr->gr_mem[i]) == 0) goto ok; if (mode != -1 && IS_ON(mode, S_ISGID)) { message(MT_NOTICE, @@ -293,12 +283,16 @@ static int fchog(fd, file, owner, group, mode) gid = (GID_T) -1; } ok: + if (stat(file, &st) == -1) { + error("%s: Stat failed %s", file, SYSERR); + return -1; + } /* * Set uid and gid ownership. If that fails, strip setuid and * setgid bits from mode. Once ownership is set, successful * or otherwise, set the new file mode. */ - if (setownership(file, fd, uid, gid) < 0) { + if (setownership(file, fd, uid, gid, S_ISLNK(st.st_mode)) < 0) { if (mode != -1 && IS_ON(mode, S_ISUID)) { message(MT_NOTICE, "%s: chown failed, clearing setuid", target); @@ -310,7 +304,7 @@ ok: mode &= ~S_ISGID; } } - (void) setfilemode(file, fd, mode); + (void) setfilemode(file, fd, mode, S_ISLNK(st.st_mode)); return(0); @@ -320,8 +314,8 @@ ok: * Remove a file or directory (recursively) and send back an acknowledge * or an error message. */ -static int removefile(statb) - struct stat *statb; +static int +removefile(struct stat *statb, int silent) { DIR *d; static DIRENTRY *dp; @@ -333,11 +327,20 @@ static int removefile(statb) switch (statb->st_mode & S_IFMT) { case S_IFREG: case S_IFLNK: + case S_IFCHR: + case S_IFBLK: +#ifdef S_IFSOCK + case S_IFSOCK: +#endif +#ifdef S_IFIFO + case S_IFIFO: +#endif if (unlink(target) < 0) { if (errno == ETXTBSY) { - message(MT_REMOTE|MT_NOTICE, - "%s: unlink failed: %s", - target, SYSERR); + if (!silent) + message(MT_REMOTE|MT_NOTICE, + "%s: unlink failed: %s", + target, SYSERR); return(0); } else { error("%s: unlink failed: %s", target, SYSERR); @@ -362,29 +365,33 @@ static int removefile(statb) optarget = ptarget; len = ptarget - target; - while ((dp = readdir(d))) { + while ((dp = readdir(d)) != NULL) { if ((D_NAMLEN(dp) == 1 && dp->d_name[0] == '.') || (D_NAMLEN(dp) == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')) continue; if (len + 1 + (int)strlen(dp->d_name) >= MAXPATHLEN - 1) { - message(MT_REMOTE|MT_WARNING, "%s/%s: Name too long", - target, dp->d_name); + if (!silent) + message(MT_REMOTE|MT_WARNING, + "%s/%s: Name too long", + target, dp->d_name); continue; } ptarget = optarget; *ptarget++ = '/'; cp = dp->d_name;; - while ((*ptarget++ = *cp++)) - ; + while ((*ptarget++ = *cp++) != '\0') + continue; ptarget--; if (lstat(target, &stb) < 0) { - message(MT_REMOTE|MT_WARNING, "%s: lstat failed: %s", - target, SYSERR); + if (!silent) + message(MT_REMOTE|MT_WARNING, + "%s: lstat failed: %s", + target, SYSERR); continue; } - if (removefile(&stb) < 0) + if (removefile(&stb, 0) < 0) ++failures; } (void) closedir(d); @@ -399,6 +406,10 @@ static int removefile(statb) return(-1); } removed: +#if NEWWAY + if (!silent) + message(MT_CHANGE|MT_REMOTE, "%s: removed", target); +#else /* * We use MT_NOTICE instead of MT_CHANGE because this function is * sometimes called by other functions that are suppose to return a @@ -406,6 +417,7 @@ removed: * the Rdist protocol is re-done. Sigh. */ message(MT_NOTICE|MT_REMOTE, "%s: removed", target); +#endif return(0); } @@ -413,8 +425,8 @@ removed: * Check the current directory (initialized by the 'T' command to server()) * for extraneous files and remove them. */ -static void doclean(cp) - char *cp; +static void +doclean(char *cp) { DIR *d; DIRENTRY *dp; @@ -422,6 +434,7 @@ static void doclean(cp) char *optarget, *ep; int len; opt_t opts; + char targ[MAXPATHLEN*4]; opts = strtol(cp, &ep, 8); if (*ep != CNULL) { @@ -436,7 +449,7 @@ static void doclean(cp) optarget = ptarget; len = ptarget - target; - while ((dp = readdir(d))) { + while ((dp = readdir(d)) != NULL) { if ((D_NAMLEN(dp) == 1 && dp->d_name[0] == '.') || (D_NAMLEN(dp) == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.')) @@ -450,8 +463,8 @@ static void doclean(cp) ptarget = optarget; *ptarget++ = '/'; cp = dp->d_name;; - while ((*ptarget++ = *cp++)) - ; + while ((*ptarget++ = *cp++) != '\0') + continue; ptarget--; if (lstat(target, &stb) < 0) { message(MT_REMOTE|MT_WARNING, "%s: lstat failed: %s", @@ -459,7 +472,8 @@ static void doclean(cp) continue; } - (void) sendcmd(CC_QUERY, "%s", dp->d_name); + ENCODE(targ, dp->d_name); + (void) sendcmd(CC_QUERY, "%s", targ); (void) remline(cp = buf, sizeof(buf), TRUE); if (*cp != CC_YES) @@ -469,7 +483,7 @@ static void doclean(cp) message(MT_REMOTE|MT_INFO, "%s: need to remove", target); else - (void) removefile(&stb); + (void) removefile(&stb, 0); } (void) closedir(d); @@ -480,8 +494,8 @@ static void doclean(cp) /* * Frontend to doclean(). */ -static void clean(cp) - char *cp; +static void +clean(char *cp) { doclean(cp); (void) sendcmd(CC_END, NULL); @@ -493,9 +507,14 @@ static void clean(cp) * We can't really set an alarm timeout here since we * have no idea how long the command should take. */ -static void dospecial(cmd) - char *cmd; +static void +dospecial(char *xcmd) { + char cmd[BUFSIZ]; + if (DECODE(cmd, xcmd) == -1) { + error("dospecial: Cannot decode command."); + return; + } runcommand(cmd); } @@ -507,7 +526,8 @@ static void dospecial(cmd) * E_FILES. When an RC_COMMAND is finally received, the E_FILES variable * is stuffed into our environment and a normal dospecial() command is run. */ -static void docmdspecial() +static void +docmdspecial(void) { char *cp; char *cmd, *env = NULL; @@ -576,11 +596,17 @@ static void docmdspecial() * QC_YES - exists and its a directory or symbolic link * QC_ERRMSGmessage - error message */ -static void query(name) - char *name; +static void +query(char *xname) { static struct stat stb; int s = -1, stbvalid = 0; + char name[MAXPATHLEN]; + + if (DECODE(name, xname) == -1) { + error("query: Cannot decode filename"); + return; + } if (catname && cattarget(name) < 0) return; @@ -641,9 +667,18 @@ static void query(name) case S_IFLNK: case S_IFDIR: case S_IFREG: +#ifdef notyet + case S_IFCHR: + case S_IFBLK: +#ifdef S_IFSOCK + case S_IFSOCK: +#endif +#ifdef S_IFIFO + case S_IFIFO: +#endif +#endif (void) sendcmd(QC_YES, "%ld %ld %o %s %s", - (long) stb.st_size, - stb.st_mtime, + (long) stb.st_size, stb.st_mtime, stb.st_mode & 07777, getusername(stb.st_uid, target, options), getgroupname(stb.st_gid, target, options)); @@ -659,9 +694,8 @@ static void query(name) /* * Check to see if parent directory exists and create one if not. */ -static int chkparent(name, opts) - char *name; - opt_t opts; +static int +chkparent(char *name, opt_t opts) { char *cp; struct stat stb; @@ -697,8 +731,8 @@ static int chkparent(name, opts) /* * Save a copy of 'file' by renaming it. */ -static char *savetarget(file) - char *file; +static char * +savetarget(char *file, opt_t opts) { static char savefile[MAXPATHLEN]; @@ -707,11 +741,38 @@ static char *savetarget(file) return(NULL); } - (void) snprintf(savefile, sizeof savefile, "%s%s", file, SAVE_SUFFIX); + if (IS_ON(opts, DO_HISTORY)) { + int i; + struct stat st; + /* + * There is a race here, but the worst that can happen + * is to lose a version of the file + */ + for (i = 1; i < 1000; i++) { + (void) snprintf(savefile, sizeof(savefile), + "%s;%.3d", file, i); + if (stat(savefile, &st) == -1 && errno == ENOENT) + break; + + } + if (i == 1000) { + message(MT_NOTICE, + "%s: More than 1000 versions for %s; reusing 1\n", + savefile, SYSERR); + i = 1; + (void) snprintf(savefile, sizeof(savefile), + "%s;%.3d", file, i); + } + } + else { + (void) snprintf(savefile, sizeof(savefile), "%s%s", + file, SAVE_SUFFIX); - if (unlink(savefile) != 0 && errno != ENOENT) { - message(MT_NOTICE, "%s: remove failed: %s", savefile, SYSERR); - return(NULL); + if (unlink(savefile) != 0 && errno != ENOENT) { + message(MT_NOTICE, "%s: remove failed: %s", + savefile, SYSERR); + return(NULL); + } } if (rename(file, savefile) != 0 && errno != ENOENT) { @@ -724,37 +785,13 @@ static char *savetarget(file) } /* - * See if buf is all zeros (sparse check) - */ -static int iszeros (buf, size) - char *buf; - off_t size; -{ - while (size > 0) { - if (*buf != CNULL) - return(0); - buf++; - size--; - } - - return(1); -} - - -/* * Receive a file */ -static void recvfile(new, opts, mode, owner, group, mtime, atime, size) - /*ARGSUSED*/ - char *new; - opt_t opts; - int mode; - char *owner, *group; - time_t mtime; - time_t atime; - off_t size; +static void +recvfile(char *new, opt_t opts, int mode, char *owner, char *group, + time_t mtime, time_t atime, off_t size) { - int f, wrerr, olderrno, lastwashole = 0, wassparse = 0; + int f, wrerr, olderrno; off_t i; char *cp; char *savefile = NULL; @@ -801,31 +838,7 @@ static void recvfile(new, opts, mode, owner, group, mtime, atime, size) amt = BUFSIZ; if (i + amt > size) amt = size - i; - if (IS_ON(opts, DO_SPARSE) && iszeros(buf, amt)) { - if (lseek (f, amt, SEEK_CUR) < 0L) { - olderrno = errno; - wrerr++; - } - lastwashole = 1; - wassparse++; - } else { - if (wrerr == 0 && xwrite(f, buf, amt) != amt) { - olderrno = errno; - wrerr++; - } - lastwashole = 0; - } - } - - if (lastwashole) { -#if defined(HAVE_FTRUNCATE) - if (write (f, "", 1) != 1 || ftruncate (f, size) < 0) -#else - /* Seek backwards one character and write a null. */ - if (lseek (f, (off_t) -1, SEEK_CUR) < 0L - || write (f, "", 1) != 1) -#endif - { + if (wrerr == 0 && xwrite(f, buf, amt) != amt) { olderrno = errno; wrerr++; } @@ -861,6 +874,7 @@ static void recvfile(new, opts, mode, owner, group, mtime, atime, size) errno = 0; if ((f2 = fopen(new, "r")) == NULL) { error("%s: open for read failed: %s", new, SYSERR); + (void) fclose(f1); (void) close(f); (void) unlink(new); return; @@ -916,7 +930,7 @@ static void recvfile(new, opts, mode, owner, group, mtime, atime, size) * Try to save target file from being over-written */ if (IS_ON(opts, DO_SAVETARGETS)) - if ((savefile = savetarget(target)) == NULL) { + if ((savefile = savetarget(target, opts)) == NULL) { (void) unlink(new); return; } @@ -929,7 +943,7 @@ static void recvfile(new, opts, mode, owner, group, mtime, atime, size) char *saveptr = ptarget; ptarget = &target[strlen(target)]; - removefile(&statbuff); + removefile(&statbuff, 0); ptarget = saveptr; } @@ -937,37 +951,60 @@ static void recvfile(new, opts, mode, owner, group, mtime, atime, size) * Install new (temporary) file as the actual target */ if (rename(new, target) < 0) { + static char fmt[] = "%s -> %s: rename failed: %s"; + struct stat stb; /* * If the rename failed due to "Text file busy", then * try to rename the target file and retry the rename. */ - if (errno == ETXTBSY) { + switch (errno) { + case ETXTBSY: /* Save the target */ - if ((savefile = savetarget(target)) != NULL) { + if ((savefile = savetarget(target, opts)) != NULL) { /* Retry installing new file as target */ if (rename(new, target) < 0) { - error("%s -> %s: rename failed: %s", - new, target, SYSERR); + error(fmt, new, target, SYSERR); /* Try to put back save file */ if (rename(savefile, target) < 0) - error( - "%s -> %s: rename failed: %s", - savefile, target, - SYSERR); + error(fmt, + savefile, target, SYSERR); + (void) unlink(new); } else message(MT_NOTICE, "%s: renamed to %s", target, savefile); + /* + * XXX: We should remove the savefile here. + * But we are nice to nfs clients and + * we keep it. + */ } - } else { - error("%s -> %s: rename failed: %s", - new, target, SYSERR); + break; + case EISDIR: + /* + * See if target is a directory and remove it if it is + */ + if (lstat(target, &stb) == 0) { + if (S_ISDIR(stb.st_mode)) { + char *optarget = ptarget; + for (ptarget = target; *ptarget; + ptarget++); + /* If we failed to remove, we'll catch + it later */ + (void) removefile(&stb, 1); + ptarget = optarget; + } + } + if (rename(new, target) >= 0) + break; + /*FALLTHROUGH*/ + + default: + error(fmt, new, target, SYSERR); (void) unlink(new); + break; } } - if (wassparse) - message (MT_NOTICE, "%s: was sparse", target); - if (IS_ON(opts, DO_COMPARE)) message(MT_REMOTE|MT_CHANGE, "%s: updated", target); else @@ -977,10 +1014,8 @@ static void recvfile(new, opts, mode, owner, group, mtime, atime, size) /* * Receive a directory */ -static void recvdir(opts, mode, owner, group) - opt_t opts; - int mode; - char *owner, *group; +static void +recvdir(opt_t opts, int mode, char *owner, char *group) { static char lowner[100], lgroup[100]; char *cp; @@ -1040,20 +1075,22 @@ static void recvdir(opts, mode, owner, group) o = (owner[0] == ':') ? opts & DO_NUMCHKOWNER : opts; - if ((cp = getusername(stb.st_uid, target, o))) + if ((cp = getusername(stb.st_uid, target, o)) + != NULL) if (strcmp(owner, cp)) (void) strlcpy(lowner, cp, - sizeof lowner); + sizeof(lowner)); } if (!IS_ON(opts, DO_NOCHKGROUP) && group) { int o; o = (group[0] == ':') ? opts & DO_NUMCHKGROUP : opts; - if ((cp = getgroupname(stb.st_gid, target, o))) + if ((cp = getgroupname(stb.st_gid, target, o)) + != NULL) if (strcmp(group, cp)) (void) strlcpy(lgroup, cp, - sizeof lgroup); + sizeof(lgroup)); } /* @@ -1065,12 +1102,12 @@ static void recvdir(opts, mode, owner, group) (cp = getusername(stb.st_uid, target, opts))) (void) strlcpy(lowner, cp, - sizeof lowner); + sizeof(lowner)); if (lgroup[0] == CNULL && (cp = getgroupname(stb.st_gid, target, opts))) (void) strlcpy(lgroup, cp, - sizeof lgroup); + sizeof(lgroup)); if (IS_ON(opts, DO_VERIFY)) message(MT_NOTICE, @@ -1128,14 +1165,13 @@ static void recvdir(opts, mode, owner, group) /* * Receive a link */ -static void recvlink(new, opts, mode, size) - char *new; - opt_t opts; - int mode; - off_t size; +static void +recvlink(char *new, opt_t opts, int mode, off_t size) { + char tbuf[MAXPATHLEN]; struct stat stb; char *optarget; + int uptodate; off_t i; /* @@ -1149,6 +1185,27 @@ static void recvlink(new, opts, mode, size) return; } + uptodate = 0; + if ((i = readlink(target, tbuf, sizeof(tbuf))) != -1) { + tbuf[i] = '\0'; + if (i == size && strncmp(buf, tbuf, (int) size) == 0) + uptodate = 1; + } + mode &= 0777; + + if (IS_ON(opts, DO_VERIFY) || uptodate) { + if (uptodate) + message(MT_REMOTE|MT_INFO, ""); + else + message(MT_REMOTE|MT_INFO, "%s: need to update", + target); + if (IS_ON(opts, DO_COMPARE)) + return; + (void) sendcmd(C_END, NULL); + (void) response(); + return; + } + /* * Make new symlink using a temporary name */ @@ -1162,37 +1219,13 @@ static void recvlink(new, opts, mode, size) } /* - * Do comparison of what link is pointing to if enabled - */ - mode &= 0777; - if (IS_ON(opts, DO_COMPARE)) { - char tbuf[MAXPATHLEN]; - - if ((i = readlink(target, tbuf, sizeof(tbuf)-1)) != -1) - tbuf[i] = '\0'; - if (i != -1 && i == size && strncmp(buf, tbuf, (size_t) size) == 0) { - (void) unlink(new); - ack(); - return; - } - if (IS_ON(opts, DO_VERIFY)) { - (void) unlink(new); - message(MT_REMOTE|MT_INFO, "%s: need to update", - target); - (void) sendcmd(C_END, NULL); - (void) response(); - return; - } - } - - /* * See if target is a directory and remove it if it is */ if (lstat(target, &stb) == 0) { if (S_ISDIR(stb.st_mode)) { optarget = ptarget; for (ptarget = target; *ptarget; ptarget++); - if (removefile(&stb) < 0) { + if (removefile(&stb, 0) < 0) { ptarget = optarget; (void) unlink(new); (void) sendcmd(C_END, NULL); @@ -1215,10 +1248,7 @@ static void recvlink(new, opts, mode, size) return; } - if (IS_ON(opts, DO_COMPARE)) - message(MT_REMOTE|MT_CHANGE, "%s: updated", target); - else - ack(); + message(MT_REMOTE|MT_CHANGE, "%s: updated", target); /* * Indicate end of receive operation @@ -1230,14 +1260,15 @@ static void recvlink(new, opts, mode, size) /* * Creat a hard link to existing file. */ -static void hardlink(cmd) - char *cmd; +static void +hardlink(char *cmd) { struct stat stb; int exists = 0; - char *oldname, *newname; + char *xoldname, *xnewname; char *cp = cmd; static char expbuf[BUFSIZ]; + char oldname[BUFSIZ], newname[BUFSIZ]; /* Skip over opts */ (void) strtol(cp, &cp, 8); @@ -1246,23 +1277,32 @@ static void hardlink(cmd) return; } - oldname = strtok(cp, " "); - if (oldname == NULL) { + xoldname = strtok(cp, " "); + if (xoldname == NULL) { error("hardlink: oldname name not delimited"); return; } - newname = strtok(NULL, " "); - if (newname == NULL) { + if (DECODE(oldname, xoldname) == -1) { + error("hardlink: Cannot decode oldname"); + return; + } + + xnewname = strtok(NULL, " "); + if (xnewname == NULL) { error("hardlink: new name not specified"); return; } + if (DECODE(newname, xnewname) == -1) { + error("hardlink: Cannot decode newname"); + return; + } + if (exptilde(expbuf, oldname, sizeof(expbuf)) == NULL) { error("hardlink: tilde expansion failed"); return; } - oldname = expbuf; if (catname && cattarget(newname) < 0) { error("Cannot set newname target."); @@ -1287,7 +1327,7 @@ static void hardlink(cmd) error("%s: unlink failed: %s", target, SYSERR); return; } - if (link(oldname, target) < 0) { + if (link(expbuf, target) < 0) { error("%s: cannot link to %s: %s", target, oldname, SYSERR); return; } @@ -1302,8 +1342,8 @@ static void hardlink(cmd) * SC_FREESPACE - Set minimium free space of filesystem * SC_FREEFILES - Set minimium free number of files of filesystem */ -static void setconfig(cmd) - char *cmd; +static void +setconfig(char *cmd) { char *cp = cmd; char *estr; @@ -1315,7 +1355,7 @@ static void setconfig(cmd) */ if (!fromhost) { fromhost = xstrdup(cp); - message(MT_SYSLOG, "startup for %s", fromhost); + message(MT_SYSLOG, "startup for %s", fromhost); #if defined(SETARGS) || defined(HAVE_SETPROCTITLE) setproctitle("serving %s", cp); #endif /* SETARGS || HAVE_SETPROCTITLE */ @@ -1323,7 +1363,7 @@ static void setconfig(cmd) break; case SC_FREESPACE: /* Minimium free space */ - if (!isdigit(*cp)) { + if (!isdigit((unsigned char)*cp)) { fatalerr("Expected digit, got '%s'.", cp); return; } @@ -1331,7 +1371,7 @@ static void setconfig(cmd) break; case SC_FREEFILES: /* Minimium free files */ - if (!isdigit(*cp)) { + if (!isdigit((unsigned char)*cp)) { fatalerr("Expected digit, got '%s'.", cp); return; } @@ -1339,13 +1379,21 @@ static void setconfig(cmd) break; case SC_LOGGING: /* Logging options */ - if ((estr = msgparseopts(cp, TRUE))) { + if ((estr = msgparseopts(cp, TRUE)) != NULL) { fatalerr("Bad message option string (%s): %s", cp, estr); return; } break; + case SC_DEFOWNER: + (void) strlcpy(defowner, cp, sizeof(defowner)); + break; + + case SC_DEFGROUP: + (void) strlcpy(defgroup, cp, sizeof(defgroup)); + break; + default: message(MT_NOTICE, "Unknown config command \"%s\".", cp-1); return; @@ -1355,9 +1403,8 @@ static void setconfig(cmd) /* * Receive something */ -static void recvit(cmd, type) - char *cmd; - int type; +static void +recvit(char *cmd, int type) { int mode; opt_t opts; @@ -1365,6 +1412,7 @@ static void recvit(cmd, type) time_t mtime, atime; char *owner, *group, *file; char new[MAXPATHLEN]; + char fileb[MAXPATHLEN]; long freespace = -1, freefiles = -1; char *cp = cmd; @@ -1432,14 +1480,19 @@ static void recvit(cmd, type) } /* - * Get file name. Can't use strtok() since there could + * Get file name. Can't use strtok() since there could * be white space in the file name. */ - file = group + strlen(group) + 1; - if (file == NULL) { + if (DECODE(fileb, group + strlen(group) + 1) == -1) { + error("recvit: Cannot decode file name"); + return; + } + + if (fileb[0] == '\0') { error("recvit: no file name"); return; } + file = fileb; debugmsg(DM_MISC, "recvit: opts = %04o mode = %04o size = %d mtime = %d", @@ -1449,15 +1502,15 @@ static void recvit(cmd, type) owner, group, file, catname, (type == S_IFDIR) ? 1 : 0); if (type == S_IFDIR) { - if (catname >= sizeof(sptarget)) { + if ((size_t) catname >= sizeof(sptarget)) { error("%s: too many directory levels", target); return; } sptarget[catname] = ptarget; if (catname++) { *ptarget++ = '/'; - while ((*ptarget++ = *file++)) - ; + while ((*ptarget++ = *file++) != '\0') + continue; ptarget--; } } else { @@ -1470,12 +1523,13 @@ static void recvit(cmd, type) } file = strrchr(target, '/'); if (file == NULL) - (void) strlcpy(new, tempname, sizeof new); + (void) strlcpy(new, tempname, sizeof(new)); else if (file == target) - (void) snprintf(new, sizeof new, "/%s", tempname); + (void) snprintf(new, sizeof(new), "/%s", tempname); else { *file = CNULL; - (void) snprintf(new, sizeof new, "%s/%s", target, tempname); + (void) snprintf(new, sizeof(new), "%s/%s", target, + tempname); *file = '/'; } (void) mktemp(new); @@ -1535,14 +1589,93 @@ static void recvit(cmd, type) } /* + * Chmog something + */ +static void +dochmog(char *cmd) +{ + int mode; + opt_t opts; + char *owner, *group, *file; + char *cp = cmd; + char fileb[MAXPATHLEN]; + + /* + * Get rdist option flags + */ + opts = strtol(cp, &cp, 8); + if (*cp++ != ' ') { + error("dochmog: options not delimited"); + return; + } + + /* + * Get file mode + */ + mode = strtol(cp, &cp, 8); + if (*cp++ != ' ') { + error("dochmog: mode not delimited"); + return; + } + + /* + * Get file owner name + */ + owner = strtok(cp, " "); + if (owner == NULL) { + error("dochmog: owner name not delimited"); + return; + } + + /* + * Get file group name + */ + group = strtok(NULL, " "); + if (group == NULL) { + error("dochmog: group name not delimited"); + return; + } + + /* + * Get file name. Can't use strtok() since there could + * be white space in the file name. + */ + if (DECODE(fileb, group + strlen(group) + 1) == -1) { + error("dochmog: Cannot decode file name"); + return; + } + + if (fileb[0] == '\0') { + error("dochmog: no file name"); + return; + } + file = fileb; + + debugmsg(DM_MISC, + "dochmog: opts = %04o mode = %04o", opts, mode); + debugmsg(DM_MISC, + "dochmog: owner = '%s' group = '%s' file = '%s' catname = %d", + owner, group, file, catname); + + if (catname && cattarget(file) < 0) { + error("Cannot set newname target."); + return; + } + + (void) fchog(-1, target, owner, group, mode); + + ack(); +} + +/* * Set target information */ -static void settarget(cmd, isdir) - char *cmd; - int isdir; +static void +settarget(char *cmd, int isdir) { char *cp = cmd; opt_t opts; + char file[BUFSIZ]; catname = isdir; @@ -1556,6 +1689,11 @@ static void settarget(cmd, isdir) } options = opts; + if (DECODE(file, cp) == -1) { + error("settarget: Cannot decode target name"); + return; + } + /* * Handle target */ @@ -1571,7 +1709,8 @@ static void settarget(cmd, isdir) /* * Cleanup in preparation for exiting. */ -extern void cleanup() +void +cleanup(int dummy) { /* We don't need to do anything */ } @@ -1579,25 +1718,23 @@ extern void cleanup() /* * Server routine to read requests and process them. */ -extern void server() +void +server(void) { static char cmdbuf[BUFSIZ]; char *cp; int n; extern jmp_buf finish_jmpbuf; - if (setjmp(finish_jmpbuf)) { - setjmp_ok = FALSE; + if (setjmp(finish_jmpbuf)) return; - } - setjmp_ok = TRUE; (void) signal(SIGHUP, sighandler); (void) signal(SIGINT, sighandler); (void) signal(SIGQUIT, sighandler); (void) signal(SIGTERM, sighandler); (void) signal(SIGPIPE, sighandler); (void) umask(oumask = umask(0)); - (void) strlcpy(tempname, _RDIST_TMP, sizeof tempname); + (void) strlcpy(tempname, _RDIST_TMP, sizeof(tempname)); if (fromhost) { message(MT_SYSLOG, "Startup for %s", fromhost); #if defined(SETARGS) @@ -1611,20 +1748,17 @@ extern void server() (void) sendcmd(S_VERSION, NULL); if (remline(cmdbuf, sizeof(cmdbuf), TRUE) < 0) { - setjmp_ok = FALSE; error("server: expected control record"); return; } - if (cmdbuf[0] != S_VERSION || !isdigit(cmdbuf[1])) { - setjmp_ok = FALSE; + if (cmdbuf[0] != S_VERSION || !isdigit((unsigned char)cmdbuf[1])) { error("Expected version command, received: \"%s\".", cmdbuf); return; } proto_version = atoi(&cmdbuf[1]); if (proto_version != VERSION) { - setjmp_ok = FALSE; error("Protocol version %d is not supported.", proto_version); return; } @@ -1637,10 +1771,8 @@ extern void server() */ for ( ; ; ) { n = remline(cp = cmdbuf, sizeof(cmdbuf), TRUE); - if (n == -1) { /* EOF */ - setjmp_ok = FALSE; + if (n == -1) /* EOF */ return; - } if (n == 0) { error("server: expected control record"); continue; @@ -1703,11 +1835,9 @@ extern void server() docmdspecial(); continue; -#ifdef DOCHMOD - case C_CHMOD: /* Set mode */ - dochmod(cp); + case C_CHMOG: /* Set owner, group, mode */ + dochmog(cp); continue; -#endif /* DOCHMOD */ case C_ERRMSG: /* Normal error message */ if (cp && *cp) @@ -1717,7 +1847,6 @@ extern void server() case C_FERRMSG: /* Fatal error message */ if (cp && *cp) message(MT_FERROR|MT_NOREMOTE, "%s", cp); - setjmp_ok = FALSE; return; default: |