From e06ba6779e10d29d6c233e03dbbf2408bc89da66 Mon Sep 17 00:00:00 2001 From: guenther Date: Tue, 20 Jan 2015 09:00:16 +0000 Subject: [PATCH] Split out from rdist/defs.h the client-only and server-only bits into rdist/client.h and rdistd/server.h Only put #includes in .h files that are necessary for the .h to be used; all other #includes go in the .c files Move all extern variable declarations to the .h files, renaming local variables to avoid shadowing Replace me_type member of mntent_t with an "is NFS?" flag bit --- usr.bin/rdist/child.c | 13 +- usr.bin/rdist/client.c | 16 +- usr.bin/rdist/client.h | 205 ++++++++++++++++++ usr.bin/rdist/common.c | 24 ++- usr.bin/rdist/defs.h | 213 ++----------------- usr.bin/rdist/distopt.c | 7 +- usr.bin/rdist/docmd.c | 29 +-- usr.bin/rdist/expand.c | 10 +- usr.bin/rdist/gram.y | 14 +- usr.bin/rdist/isexec.c | 9 +- usr.bin/rdist/lookup.c | 6 +- usr.bin/rdist/message.c | 11 +- usr.bin/rdist/rdist.c | 26 ++- usr.bin/rdistd/filesys-os.c | 13 +- usr.bin/rdistd/filesys.c | 18 +- usr.bin/rdistd/rdistd.c | 8 +- usr.bin/rdistd/server.c | 20 +- usr.bin/{rdist/filesys.h => rdistd/server.h} | 58 ++--- 18 files changed, 391 insertions(+), 309 deletions(-) create mode 100644 usr.bin/rdist/client.h rename usr.bin/{rdist/filesys.h => rdistd/server.h} (68%) diff --git a/usr.bin/rdist/child.c b/usr.bin/rdist/child.c index 1ba56ebe1d3..a23599d5b3c 100644 --- a/usr.bin/rdist/child.c +++ b/usr.bin/rdist/child.c @@ -1,4 +1,4 @@ -/* $OpenBSD: child.c,v 1.24 2015/01/20 03:55:18 guenther Exp $ */ +/* $OpenBSD: child.c,v 1.25 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,8 +29,6 @@ * SUCH DAMAGE. */ -#include "defs.h" - /* * Functions for rdist related to children */ @@ -39,6 +37,14 @@ #include #include +#include +#include +#include +#include +#include + +#include "client.h" + typedef enum _PROCSTATE { PSrunning, PSdead @@ -58,7 +64,6 @@ typedef struct _child CHILD; static CHILD *childlist = NULL; /* List of children */ 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 *); diff --git a/usr.bin/rdist/client.c b/usr.bin/rdist/client.c index 47dbad804c9..c5081cc8eae 100644 --- a/usr.bin/rdist/client.c +++ b/usr.bin/rdist/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.32 2015/01/16 06:40:11 deraadt Exp $ */ +/* $OpenBSD: client.c,v 1.33 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,9 +29,16 @@ * SUCH DAMAGE. */ +#include #include - -#include "defs.h" +#include +#include +#include +#include +#include +#include + +#include "client.h" #include "y.tab.h" /* @@ -78,7 +85,6 @@ static int sendit(char *, opt_t, int); char * remfilename(char *src, char *dest, char *path, char *rname, int destdir) { - extern struct namelist *filelist; char *lname, *cp; static char buff[BUFSIZ]; int srclen, pathlen; @@ -157,7 +163,6 @@ static void runspecial(char *starget, opt_t opts, char *rname, int destdir) { struct subcmd *sc; - extern struct subcmd *subcmds; char *rfile; rfile = remfilename(source, Tdest, target, rname, destdir); @@ -192,7 +197,6 @@ addcmdspecialfile(char *starget, char *rname, int destdir) char *rfile; struct namelist *new; struct subcmd *sc; - extern struct subcmd *subcmds; int isokay = 0; rfile = remfilename(source, Tdest, target, rname, destdir); diff --git a/usr.bin/rdist/client.h b/usr.bin/rdist/client.h new file mode 100644 index 00000000000..9b51bd07e4e --- /dev/null +++ b/usr.bin/rdist/client.h @@ -0,0 +1,205 @@ +/* $OpenBSD: client.h,v 1.1 2015/01/20 09:00:16 guenther Exp $ */ + +#ifndef __CLIENT_H__ +#define __CLIENT_H__ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * $From: defs.h,v 1.6 2001/03/12 18:16:30 kim Exp $ + * @(#)defs.h 5.2 (Berkeley) 3/20/86 + */ + +#include +#include +#include + +#include "defs.h" + + /* lexical definitions */ +#define QUOTECHAR 160 /* quote next character */ + + /* table sizes */ +#define HASHSIZE 1021 +#define INMAX 3500 + + /* expand type definitions */ +#define E_VARS 0x1 +#define E_SHELL 0x2 +#define E_TILDE 0x4 +#define E_ALL 0x7 + + /* actions for lookup() */ +#define LOOKUP 0 +#define INSERT 1 +#define REPLACE 2 + +#define ALLOC(x) (struct x *) xmalloc(sizeof(struct x)) +#define A(s) ((s) ? s : "") + + +#define COMMENT_CHAR '#' /* Config file comment char */ + + +/* + * Name list + */ +struct namelist { /* for making lists of strings */ + char *n_name; + regex_t *n_regex; + struct namelist *n_next; +}; + +/* + * Sub command structure + */ +struct subcmd { + short sc_type; /* type - INSTALL,NOTIFY,EXCEPT,SPECIAL */ + opt_t sc_options; + char *sc_name; + struct namelist *sc_args; + struct subcmd *sc_next; +}; + +/* + * Cmd flags + */ +#define CMD_ASSIGNED 0x01 /* This entry has been assigned */ +#define CMD_CONNFAILED 0x02 /* Connection failed */ +#define CMD_NOCHKNFS 0x04 /* Disable NFS checks */ + +/* + * General command structure + */ +struct cmd { + int c_type; /* type - ARROW,DCOLON */ + int c_flags; /* flags - CMD_USED,CMD_FAILED */ + char *c_name; /* hostname or time stamp file name */ + char *c_label; /* label for partial update */ + struct namelist *c_files; + struct subcmd *c_cmds; + struct cmd *c_next; +}; + +/* + * Hard link buffer information + */ +struct linkbuf { + ino_t inum; + dev_t devnum; + int count; + char *pathname; + char *src; + char *target; + struct linkbuf *nextp; +}; + +extern char *path_remsh; /* Remote shell command */ +extern char host[]; /* Host name of master copy */ +extern char **realargv; /* Real argv */ +extern char *homedir; /* User's $HOME */ +extern int do_fork; /* Should we do fork()'ing */ +extern int nflag; /* NOP flag, don't execute commands */ +extern int realargc; /* Real argc */ +extern int setjmp_ok; /* setjmp/longjmp flag */ +extern int maxchildren; /* Max active children */ +extern int64_t min_freespace; /* Min filesys free space */ +extern int64_t min_freefiles; /* Min filesys free # files */ +extern struct linkbuf *ihead; /* list of files with more than one link */ +extern struct subcmd *subcmds;/* list of sub-commands for current cmd */ +extern struct namelist *filelist; /* list of source files */ +extern struct cmd *cmds; /* Initialized by yyparse() */ + +extern char target[BUFSIZ]; /* target/source directory name */ +extern char *ptarget; /* pointer to end of target name */ +extern int activechildren; /* Number of active children */ +extern int amchild; /* This PID is a child */ +extern char *path_rdistd; +extern char *remotemsglist; + +/* + * Our own declarations. + */ + +/* child.c */ +void waitup(void); +int spawn(struct cmd *, struct cmd *); + +/* 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 *); +int install(char *, char *, int, int , opt_t); + +/* distopt.c */ +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 *); + +/* 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); + +/* isexec.c */ +int isexec(char *, struct stat *); + +/* lookup.c */ +void define(char *); +struct namelist *lookup(char *, int, struct namelist *); + +/* rdist.c */ +FILE *opendist(char *); +void docmdargs(int, char *[]); +char *getnlstr(struct namelist *); + +#endif /* __CLIENT_H__ */ diff --git a/usr.bin/rdist/common.c b/usr.bin/rdist/common.c index e198bfd6115..0da2b0c8ed8 100644 --- a/usr.bin/rdist/common.c +++ b/usr.bin/rdist/common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: common.c,v 1.35 2015/01/20 04:45:43 guenther Exp $ */ +/* $OpenBSD: common.c,v 1.36 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,15 +29,27 @@ * SUCH DAMAGE. */ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "defs.h" /* * Things common to both the client and server. */ -#include -#include - /* * Variables common to both client and server */ @@ -55,7 +67,6 @@ int rem_r = -1; /* Client file descriptor */ int rem_w = -1; /* Client file descriptor */ struct passwd *pw = NULL; /* Local user's pwd entry */ 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 */ int setjmp_ok = FALSE; /* setjmp()/longjmp() status */ @@ -142,8 +153,6 @@ init(int argc, char **argv, char **envp) void finish(void) { - extern jmp_buf finish_jmpbuf; - debugmsg(DM_CALL, "finish() called: do_fork = %d amchild = %d isserver = %d", do_fork, amchild, isserver); @@ -565,7 +574,6 @@ exptilde(char *ebuf, char *file, size_t ebufsize) { char *pw_dir, *rest; size_t len; - extern char *homedir; if (*file != '~') { notilde: diff --git a/usr.bin/rdist/defs.h b/usr.bin/rdist/defs.h index 4e1a9af36b0..c25725f9b6f 100644 --- a/usr.bin/rdist/defs.h +++ b/usr.bin/rdist/defs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: defs.h,v 1.34 2015/01/20 06:02:30 guenther Exp $ */ +/* $OpenBSD: defs.h,v 1.35 2015/01/20 09:00:16 guenther Exp $ */ #ifndef __DEFS_H__ #define __DEFS_H__ @@ -36,24 +36,9 @@ * @(#)defs.h 5.2 (Berkeley) 3/20/86 */ -#include -#include -#include -#include -#include -#include -#include #include -#include -#include #include #include -#include -#include -#include -#include -#include -#include #ifndef __GNUC__ # ifndef __attribute__ @@ -65,7 +50,6 @@ #include "config.h" #include "pathnames.h" #include "types.h" -#include "filesys.h" /* * Define the read and write values for the file descriptor array @@ -82,33 +66,12 @@ #define FALSE 0 #endif - /* lexical definitions */ -#define QUOTECHAR 160 /* quote next character */ - - /* table sizes */ -#define HASHSIZE 1021 -#define INMAX 3500 - - /* expand type definitions */ -#define E_VARS 0x1 -#define E_SHELL 0x2 -#define E_TILDE 0x4 -#define E_ALL 0x7 - - /* actions for lookup() */ -#define LOOKUP 0 -#define INSERT 1 -#define REPLACE 2 - /* Bit flag test macros */ #define IS_ON(b,f) (b > 0 && (b & f)) #define IS_OFF(b,f) !(IS_ON(b,f)) #define FLAG_ON(b,f) b |= f #define FLAG_OFF(b,f) b &= ~(f) -#define ALLOC(x) (struct x *) xmalloc(sizeof(struct x)) -#define A(s) ((s) ? s : "") - /* * Environment variable names */ @@ -117,19 +80,11 @@ #define E_REMFILE "REMFILE" /* Remote Filename */ #define E_BASEFILE "BASEFILE" /* basename of Remote File */ -/* - * Suffix to use when saving files - */ -#ifndef SAVE_SUFFIX -#define SAVE_SUFFIX ".OLD" -#endif - /* * Get system error string */ -#define SYSERR strerror(errno) +#define SYSERR strerror(errno) -#define COMMENT_CHAR '#' /* Config file comment char */ #define CNULL '\0' /* NULL character */ /* @@ -155,8 +110,8 @@ #define C_CMDSPECIAL 's' /* Execute cmd special command */ #define C_CHMOG 'M' /* Chown,Chgrp,Chmod a file */ -#define ack() (void) sendcmd(C_ACK, NULL) -#define err() (void) sendcmd(C_ERRMSG, NULL) +#define ack() (void) sendcmd(C_ACK, NULL) +#define err() (void) sendcmd(C_ERRMSG, NULL) /* * Session startup commands. @@ -199,104 +154,29 @@ #define RC_FILE 'F' /* Name of a target file */ #define RC_COMMAND 'C' /* Command to run */ -/* - * Name list - */ -struct namelist { /* for making lists of strings */ - char *n_name; - regex_t *n_regex; - struct namelist *n_next; -}; - -/* - * Sub command structure - */ -struct subcmd { - short sc_type; /* type - INSTALL,NOTIFY,EXCEPT,SPECIAL */ - opt_t sc_options; - char *sc_name; - struct namelist *sc_args; - struct subcmd *sc_next; -}; - -/* - * Cmd flags - */ -#define CMD_ASSIGNED 0x01 /* This entry has been assigned */ -#define CMD_CONNFAILED 0x02 /* Connection failed */ -#define CMD_NOCHKNFS 0x04 /* Disable NFS checks */ - -/* - * General command structure - */ -struct cmd { - int c_type; /* type - ARROW,DCOLON */ - int c_flags; /* flags - CMD_USED,CMD_FAILED */ - char *c_name; /* hostname or time stamp file name */ - char *c_label; /* label for partial update */ - struct namelist *c_files; - struct subcmd *c_cmds; - struct cmd *c_next; -}; - -/* - * Hard link buffer information - */ -struct linkbuf { - ino_t inum; - dev_t devnum; - int count; - char *pathname; - char *src; - char *target; - struct linkbuf *nextp; -}; -extern char *optarg; /* Option argument */ -extern char *path_remsh; /* Remote shell command */ -extern char host[]; /* Host name of master copy */ -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 debug; /* Debugging flag */ -extern opt_t defoptions; /* Default install options */ -extern int do_fork; /* Should we do fork()'ing */ -extern int isserver; /* Acting as remote server */ -extern int nerrs; /* Number of errors seen */ -extern int nflag; /* NOP flag, don't execute commands */ -extern opt_t options; /* Global options */ -extern int proto_version; /* Protocol version number */ -extern int realargc; /* Real argc */ +extern char *currenthost; /* Name of current host */ +extern char *progname; /* Name of this program */ +extern char *locuser; /* Local User's name */ +extern int debug; /* Debugging flag */ +extern int isserver; /* Acting as remote server */ +extern int nerrs; /* Number of errors seen */ +extern opt_t options; /* Global options */ 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 uid_t userid; /* User ID of rdist user */ -extern jmp_buf finish_jmpbuf; /* Setjmp buffer for finish() */ -extern struct linkbuf *ihead; /* list of files with more than one link */ +extern int rem_w; /* Remote file descriptor, writing */ +extern int rtimeout; /* Response time out in seconds */ +extern uid_t userid; /* User ID of rdist user */ +extern jmp_buf finish_jmpbuf; /* Setjmp buffer for finish() */ 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 */ + /* - * Our own declarations. + * Declarations for files shared between rdist and rdistd */ -/* child.c */ -void waitup(void); -int spawn(struct cmd *, struct cmd *); - -/* 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 */ ssize_t xwrite(int, void *, size_t); int init(int, char **, char **); @@ -323,56 +203,6 @@ char *xstrdup(const char *); char *xbasename(char *); char *searchpath(char *); -/* distopt.c */ -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 *, int64_t *, int64_t *); - -/* 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); - -/* 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); @@ -384,13 +214,8 @@ void error(const char *, ...) __attribute__((format (printf, 1, 2))); void fatalerr(const char *, ...) __attribute__((format (printf, 1, 2))); char *getnotifyfile(void); -/* rdist.c */ -FILE *opendist(char *); -void docmdargs(int, char *[]); -char *getnlstr(struct namelist *); - -/* server.c */ -void server(void); +/* client.c or server.c */ +void cleanup(int); #include #define DECODE(a, b) strunvis(a, b) diff --git a/usr.bin/rdist/distopt.c b/usr.bin/rdist/distopt.c index 64b054f8f43..9604ee83412 100644 --- a/usr.bin/rdist/distopt.c +++ b/usr.bin/rdist/distopt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: distopt.c,v 1.12 2015/01/20 06:02:30 guenther Exp $ */ +/* $OpenBSD: distopt.c,v 1.13 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,7 +29,10 @@ * SUCH DAMAGE. */ -#include "defs.h" +#include +#include + +#include "client.h" /* * Dist Option functions diff --git a/usr.bin/rdist/docmd.c b/usr.bin/rdist/docmd.c index fe41ac2a555..0e92c7c3ea5 100644 --- a/usr.bin/rdist/docmd.c +++ b/usr.bin/rdist/docmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: docmd.c,v 1.31 2014/07/12 03:48:04 guenther Exp $ */ +/* $OpenBSD: docmd.c,v 1.32 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,11 +29,16 @@ * SUCH DAMAGE. */ -#include +#include #include -#include - -#include "defs.h" +#include +#include +#include +#include +#include +#include + +#include "client.h" #include "y.tab.h" /* @@ -43,16 +48,8 @@ struct subcmd *subcmds; /* list of sub-commands for current cmd */ struct namelist *filelist; /* list of source files */ -extern struct cmd *cmds; /* Initialized by yyparse() */ time_t lastmod; /* Last modify time */ -extern char target[BUFSIZ]; -extern char *ptarget; -extern int activechildren; -extern int maxchildren; -extern int amchild; -extern char *path_rdistd; - static void closeconn(void); static void notify(char *, struct namelist *, time_t); static void checkcmd(struct cmd *); @@ -99,7 +96,6 @@ notify(char *rhost, struct namelist *to, time_t lmod) FILE *pf; struct stat stb; static char buf[BUFSIZ]; - extern char *locuser; char *file, *user; if (IS_ON(options, DO_VERIFY) || to == NULL) @@ -287,9 +283,6 @@ makeconn(char *rhost) { char *ruser, *cp; static char *cur_host = NULL; - extern char *locuser; - extern int64_t min_freefiles, min_freespace; - extern char *remotemsglist; char tuser[BUFSIZ], buf[BUFSIZ]; u_char respbuff[BUFSIZ]; int n; @@ -366,7 +359,7 @@ makeconn(char *rhost) /* * The server sent it's version number to us */ - proto_version = atoi(&respbuff[1]); + int proto_version = atoi(&respbuff[1]); if (proto_version != VERSION) { fatalerr( "Server version (%d) is not the same as local version (%d).", diff --git a/usr.bin/rdist/expand.c b/usr.bin/rdist/expand.c index efc1a9e2d0f..8a1e5e36c61 100644 --- a/usr.bin/rdist/expand.c +++ b/usr.bin/rdist/expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expand.c,v 1.14 2014/07/05 06:45:00 guenther Exp $ */ +/* $OpenBSD: expand.c,v 1.15 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -30,8 +30,13 @@ */ #include +#include +#include +#include +#include +#include -#include "defs.h" +#include "client.h" #define MAXEARGS 2048 #define LC '{' @@ -177,7 +182,6 @@ expstr(u_char *s) u_char ebuf[BUFSIZ]; u_char varbuff[BUFSIZ]; int savec, oeargc; - extern char *homedir; if (s == NULL || *s == CNULL) return; diff --git a/usr.bin/rdist/gram.y b/usr.bin/rdist/gram.y index d791687b983..14a03b994ef 100644 --- a/usr.bin/rdist/gram.y +++ b/usr.bin/rdist/gram.y @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: gram.y,v 1.11 2014/06/07 15:28:21 deraadt Exp $ */ +/* $OpenBSD: gram.y,v 1.12 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1993 Michael A. Cooper @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -#include "defs.h" +#include "client.h" static struct namelist *addnl(struct namelist *, struct namelist *); static struct namelist *subnl(struct namelist *, struct namelist *); @@ -408,14 +408,14 @@ int any(int c, char *str) */ void insert(char *label, struct namelist *files, struct namelist *hosts, - struct subcmd *subcmds) + struct subcmd *scmds) { struct cmd *c, *prev, *nc; struct namelist *h, *lasth; debugmsg(DM_CALL, "insert(%s, %p, %p, %p) start, files = %s", label == NULL ? "(null)" : label, - files, hosts, subcmds, getnlstr(files)); + files, hosts, scmds, getnlstr(files)); files = expand(files, E_VARS|E_SHELL); hosts = expand(hosts, E_ALL); @@ -442,7 +442,7 @@ insert(char *label, struct namelist *files, struct namelist *hosts, nc->c_name = h->n_name; nc->c_label = label; nc->c_files = files; - nc->c_cmds = subcmds; + nc->c_cmds = scmds; nc->c_flags = 0; nc->c_next = c; if (prev == NULL) @@ -460,7 +460,7 @@ insert(char *label, struct namelist *files, struct namelist *hosts, * executed in the order they appear in the distfile. */ void -append(char *label, struct namelist *files, char *stamp, struct subcmd *subcmds) +append(char *label, struct namelist *files, char *stamp, struct subcmd *scmds) { struct cmd *c; @@ -469,7 +469,7 @@ append(char *label, struct namelist *files, char *stamp, struct subcmd *subcmds) c->c_name = stamp; c->c_label = label; c->c_files = expand(files, E_ALL); - c->c_cmds = subcmds; + c->c_cmds = scmds; c->c_next = NULL; if (cmds == NULL) cmds = last_cmd = c; diff --git a/usr.bin/rdist/isexec.c b/usr.bin/rdist/isexec.c index 6086d16c8aa..e6d125a61f2 100644 --- a/usr.bin/rdist/isexec.c +++ b/usr.bin/rdist/isexec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isexec.c,v 1.9 2014/07/05 05:31:35 guenther Exp $ */ +/* $OpenBSD: isexec.c,v 1.10 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,9 +29,12 @@ * SUCH DAMAGE. */ -#include "defs.h" - +#include #include +#include +#include + +#include "client.h" /* * Determine whether 'file' is a binary executable or not. diff --git a/usr.bin/rdist/lookup.c b/usr.bin/rdist/lookup.c index 71f0d7b33e5..983808e1cda 100644 --- a/usr.bin/rdist/lookup.c +++ b/usr.bin/rdist/lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lookup.c,v 1.14 2012/11/12 01:14:41 guenther Exp $ */ +/* $OpenBSD: lookup.c,v 1.15 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,7 +29,9 @@ * SUCH DAMAGE. */ -#include "defs.h" +#include + +#include "client.h" /* symbol types */ #define VAR 1 diff --git a/usr.bin/rdist/message.c b/usr.bin/rdist/message.c index 9c4271469e1..bc397918c58 100644 --- a/usr.bin/rdist/message.c +++ b/usr.bin/rdist/message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: message.c,v 1.26 2015/01/20 07:03:21 guenther Exp $ */ +/* $OpenBSD: message.c,v 1.27 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,7 +29,16 @@ * SUCH DAMAGE. */ +#include +#include +#include +#include +#include +#include +#include #include +#include + #include "defs.h" /* diff --git a/usr.bin/rdist/rdist.c b/usr.bin/rdist/rdist.c index f6b7caf2f77..f15924ac3dc 100644 --- a/usr.bin/rdist/rdist.c +++ b/usr.bin/rdist/rdist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdist.c,v 1.28 2014/07/12 03:32:00 guenther Exp $ */ +/* $OpenBSD: rdist.c,v 1.29 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,11 +29,17 @@ * SUCH DAMAGE. */ -#include "defs.h" +#include +#include +#include +#include +#include +#include +#include + +#include "client.h" #include "y.tab.h" -#include -#include /* * Remote distribution program. @@ -357,7 +363,7 @@ docmdargs(int nargs, char **args) struct namelist *nl, *prev; char *cp; struct namelist *files, *hosts; - struct subcmd *cmds; + struct subcmd *scmds; char *dest; static struct namelist tnl; int i; @@ -388,17 +394,17 @@ docmdargs(int nargs, char **args) exit(1); if (dest == NULL || *dest == '\0') - cmds = NULL; + scmds = NULL; else { - cmds = makesubcmd(INSTALL); - cmds->sc_options = options; - cmds->sc_name = dest; + scmds = makesubcmd(INSTALL); + scmds->sc_options = options; + scmds->sc_name = dest; } debugmsg(DM_MISC, "docmdargs()\nfiles = %s", getnlstr(files)); debugmsg(DM_MISC, "host = %s", getnlstr(hosts)); - insert(NULL, files, hosts, cmds); + insert(NULL, files, hosts, scmds); docmds(NULL, 0, NULL); } diff --git a/usr.bin/rdistd/filesys-os.c b/usr.bin/rdistd/filesys-os.c index 1707afdfe23..230015c9588 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.12 2015/01/16 06:40:11 deraadt Exp $ */ +/* $OpenBSD: filesys-os.c,v 1.13 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -31,8 +31,10 @@ #include #include +#include +#include -#include "defs.h" +#include "server.h" /* * OS specific file system routines @@ -84,11 +86,9 @@ getmountent(void) if (strcmp(mnt->f_fstypename, "nfs") == 0) { strlcpy(remote_dev, mnt->f_mntfromname, sizeof(remote_dev)); mntstruct.me_path = remote_dev; - mntstruct.me_type = METYPE_NFS; - } else { + mntstruct.me_flags |= MEFLAG_NFS; + } else mntstruct.me_path = mnt->f_mntonname; - mntstruct.me_type = METYPE_OTHER; - } mnt++; entries_left--; @@ -116,7 +116,6 @@ newmountent(const mntent_t *old) new = xmalloc(sizeof *new); new->me_path = xstrdup(old->me_path); - new->me_type = xstrdup(old->me_type); new->me_flags = old->me_flags; return (new); diff --git a/usr.bin/rdistd/filesys.c b/usr.bin/rdistd/filesys.c index fc25fb75b7e..61351815f42 100644 --- a/usr.bin/rdistd/filesys.c +++ b/usr.bin/rdistd/filesys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filesys.c,v 1.17 2015/01/16 06:40:11 deraadt Exp $ */ +/* $OpenBSD: filesys.c,v 1.18 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -31,8 +31,11 @@ #include #include +#include +#include +#include -#include "defs.h" +#include "server.h" /* * This file contains functions dealing with getting info @@ -230,8 +233,7 @@ makemntinfo(struct mntinfo *mi) mntinfo = mi; while ((mnt = getmountent()) != NULL) { - debugmsg(DM_MISC, "mountent = '%s' (%s)", - mnt->me_path, mnt->me_type); + debugmsg(DM_MISC, "mountent = '%s'", mnt->me_path); /* * Make sure we don't already have it for some reason @@ -339,14 +341,10 @@ is_nfs_mounted(char *path, struct stat *statbuf, int *isvalid) { mntent_t *mnt; - if ((mnt = (mntent_t *) getmntpt(path, statbuf, isvalid)) == NULL) + if ((mnt = getmntpt(path, statbuf, isvalid)) == NULL) return(-1); - /* - * We treat "cachefs" just like NFS - */ - if ((strcmp(mnt->me_type, METYPE_NFS) == 0) || - (strcmp(mnt->me_type, "cachefs") == 0)) + if (mnt->me_flags & MEFLAG_NFS) return(1); return(0); diff --git a/usr.bin/rdistd/rdistd.c b/usr.bin/rdistd/rdistd.c index 16774aabcf9..8c3abe51576 100644 --- a/usr.bin/rdistd/rdistd.c +++ b/usr.bin/rdistd/rdistd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdistd.c,v 1.8 2009/10/27 23:59:42 deraadt Exp $ */ +/* $OpenBSD: rdistd.c,v 1.9 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,7 +29,11 @@ * SUCH DAMAGE. */ -#include "defs.h" +#include +#include +#include + +#include "server.h" int main(int, char **, char **); static void usage(void); diff --git a/usr.bin/rdistd/server.c b/usr.bin/rdistd/server.c index d5973fadf49..dcad7801897 100644 --- a/usr.bin/rdistd/server.c +++ b/usr.bin/rdistd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.34 2015/01/16 06:40:11 deraadt Exp $ */ +/* $OpenBSD: server.c,v 1.35 2015/01/20 09:00:16 guenther Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -29,9 +29,19 @@ * SUCH DAMAGE. */ +#include #include - -#include "defs.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "server.h" /* * Server routines @@ -160,7 +170,6 @@ static int fchog(int fd, char *file, char *owner, char *group, int mode) { static struct group *gr = NULL; - extern char *locuser; int i; struct stat st; uid_t uid; @@ -1666,8 +1675,7 @@ server(void) { static char cmdbuf[BUFSIZ]; char *cp; - int n; - extern jmp_buf finish_jmpbuf; + int n, proto_version; if (setjmp(finish_jmpbuf)) return; diff --git a/usr.bin/rdist/filesys.h b/usr.bin/rdistd/server.h similarity index 68% rename from usr.bin/rdist/filesys.h rename to usr.bin/rdistd/server.h index cad4bef9e21..26c7c900a22 100644 --- a/usr.bin/rdist/filesys.h +++ b/usr.bin/rdistd/server.h @@ -1,5 +1,7 @@ -/* $OpenBSD: filesys.h,v 1.4 2014/07/05 10:21:24 guenther Exp $ */ +/* $OpenBSD: server.h,v 1.1 2015/01/20 09:00:16 guenther Exp $ */ +#ifndef __SERVER_H__ +#define __SERVER_H__ /* * Copyright (c) 1983 Regents of the University of California. * All rights reserved. @@ -30,42 +32,33 @@ */ /* - * $From: filesys.h,v 1.2 1999/08/04 15:57:31 christos Exp $ - * @(#)filesys.h + * $From: defs.h,v 1.6 2001/03/12 18:16:30 kim Exp $ + * @(#)defs.h 5.2 (Berkeley) 3/20/86 */ -#ifndef __filesys_h__ -#define __filesys_h__ +#include -/* - * File System information - */ +#include "defs.h" /* - * Mount Entry definetions + * Suffix to use when saving files */ -#ifndef METYPE_OTHER -#define METYPE_OTHER "other" -#endif -#ifndef METYPE_NFS -#define METYPE_NFS "nfs" +#ifndef SAVE_SUFFIX +#define SAVE_SUFFIX ".OLD" #endif -#ifndef MEFLAG_READONLY + + #define MEFLAG_READONLY 0x01 -#endif -#ifndef MEFLAG_IGNORE #define MEFLAG_IGNORE 0x02 -#endif +#define MEFLAG_NFS 0x04 /* * Our internal mount entry type */ -struct _mntent { +typedef struct { char *me_path; /* Mounted path */ - char *me_type; /* Type of mount */ int me_flags; /* Mount flags */ -}; -typedef struct _mntent mntent_t; +} mntent_t; /* * Internal mount information type @@ -76,12 +69,25 @@ struct mntinfo { struct mntinfo *mi_nxt; }; -/* - * Declarations - */ +/* filesys-os.c */ int setmountent(void); mntent_t *getmountent(void); mntent_t *newmountent(const mntent_t *); void endmountent(void); -#endif /* __filesys_h__ */ +/* 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 *, int64_t *, int64_t *); + +/* server.c */ +void server(void); + +#endif /* __SERVER_H__ */ -- 2.20.1