=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rdist/docmd.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- src/usr.bin/rdist/docmd.c 2003/05/06 22:13:22 1.15 +++ src/usr.bin/rdist/docmd.c 2003/05/14 01:34:35 1.16 @@ -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 @@ * Functions for rdist that do command (cmd) related activities. */ -#include "defs.h" -#include "y.tab.h" #include #include @@ -71,12 +72,24 @@ 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 @@ * 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 @@ * 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 @@ 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 @@ * 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 @@ * 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 @@ /* * 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 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 @@ * 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 @@ 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 @@ 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 @@ 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 @@ /* * 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 @@ 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 @@ /* * 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 @@ } } -done: /* * Run any commands for the entire cmd */ if (didupdate > 0) { - runcmdspecial(cmd, filev, opts); + runcmdspecial(cmd, opts); didupdate = 0; } @@ -604,8 +631,7 @@ } int -okname(name) - char *name; +okname(char *name) { char *cp = name; int c, isbad; @@ -625,10 +651,8 @@ 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 @@ } 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 @@ ptarget = optarget; *ptarget++ = '/'; cp = dp->d_name; - while ((*ptarget++ = *cp++)) + while ((*ptarget++ = *cp++) != '\0') ; ptarget--; cmptime(target, sbcmds, env); @@ -667,14 +691,11 @@ /* * 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 @@ 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 @@ /* * 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 @@ 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 @@ /* * 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 @@ /* * 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 @@ /* * 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 @@ /* * 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 @@ message(MT_VERBOSE, "updating of %s finished", currenthost); closeconn(); - cleanup(); + cleanup(0); exit(nerrs); } @@ -1092,6 +1108,6 @@ * We're single-threaded so close down current connection */ closeconn(); - cleanup(); + cleanup(0); } }