Annotation of src/usr.bin/rdist/defs.h, Revision 1.28
1.28 ! guenther 1: /* $OpenBSD: defs.h,v 1.27 2014/07/12 03:25:03 guenther Exp $ */
1.8 millert 2:
1.2 dm 3: #ifndef __DEFS_H__
4: #define __DEFS_H__
1.1 deraadt 5: /*
1.2 dm 6: * Copyright (c) 1983 Regents of the University of California.
7: * All rights reserved.
1.1 deraadt 8: *
9: * Redistribution and use in source and binary forms, with or without
10: * modification, are permitted provided that the following conditions
11: * are met:
12: * 1. Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in the
16: * documentation and/or other materials provided with the distribution.
1.14 millert 17: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: */
33:
1.2 dm 34: /*
1.13 millert 35: * $From: defs.h,v 1.6 2001/03/12 18:16:30 kim Exp $
1.2 dm 36: * @(#)defs.h 5.2 (Berkeley) 3/20/86
37: */
1.1 deraadt 38:
1.21 guenther 39: #include <sys/types.h>
40: #include <sys/param.h>
41: #include <sys/file.h>
42: #include <sys/time.h>
43: #include <sys/stat.h>
1.2 dm 44: #include <ctype.h>
1.1 deraadt 45: #include <errno.h>
1.21 guenther 46: #include <grp.h>
1.1 deraadt 47: #include <pwd.h>
1.28 ! guenther 48: #include <paths.h>
1.12 millert 49: #include <regex.h>
1.21 guenther 50: #include <setjmp.h>
51: #include <signal.h>
52: #include <stdarg.h>
53: #include <stdio.h>
54: #include <stdlib.h>
55: #include <string.h>
1.2 dm 56: #include <syslog.h>
1.21 guenther 57: #include <unistd.h>
1.2 dm 58:
1.13 millert 59: #ifndef __GNUC__
60: # ifndef __attribute__
61: # define __attribute__(a)
62: # endif
63: #endif
64:
1.2 dm 65: #include "version.h"
66: #include "config-def.h"
67: #include "config.h"
68: #include "config-data.h"
1.1 deraadt 69: #include "pathnames.h"
1.2 dm 70: #include "types.h"
1.13 millert 71: #include "filesys.h"
1.2 dm 72:
1.1 deraadt 73:
74: /*
1.2 dm 75: * This belongs in os-svr4.h but many SVR4 OS's
76: * define SVR4 externel to Rdist so we put this
77: * check here.
1.1 deraadt 78: */
1.2 dm 79: #if defined(SVR4)
80: #define NEED_FCNTL_H
81: #define NEED_NETDB_H
82: #endif /* defined(SVR4) */
83:
84: #if defined(NEED_NETDB_H)
85: #include <netdb.h>
86: #endif /* NEED_NETDB_H */
87: #if defined(NEED_FCNTL_H)
88: #include <fcntl.h>
89: #endif /* NEED_FCNTL_H */
90: #if defined(NEED_LIMITS_H)
91: #include <limits.h>
92: #endif /* NEED_LIMITS_H */
1.1 deraadt 93:
1.2 dm 94: /* boolean truth */
95: #ifndef TRUE
96: #define TRUE 1
97: #endif
98: #ifndef FALSE
99: #define FALSE 0
100: #endif
101:
1.1 deraadt 102: /* lexical definitions */
1.2 dm 103: #define QUOTECHAR 160 /* quote next character */
1.1 deraadt 104:
105: /* table sizes */
106: #define HASHSIZE 1021
1.2 dm 107: #define INMAX 3500
1.1 deraadt 108:
109: /* expand type definitions */
1.2 dm 110: #define E_VARS 0x1
111: #define E_SHELL 0x2
112: #define E_TILDE 0x4
113: #define E_ALL 0x7
1.1 deraadt 114:
115: /* actions for lookup() */
1.2 dm 116: #define LOOKUP 0
117: #define INSERT 1
118: #define REPLACE 2
119:
120: /* Bit flag test macros */
121: #define IS_ON(b,f) (b > 0 && (b & f))
122: #define IS_OFF(b,f) !(IS_ON(b,f))
123: #define FLAG_ON(b,f) b |= f
124: #define FLAG_OFF(b,f) b &= ~(f)
125:
126: #define ALLOC(x) (struct x *) xmalloc(sizeof(struct x))
127: #define A(s) ((s) ? s : "<null>")
128:
129: /*
130: * Environment variable names
131: */
132: #define E_FILES "FILES" /* List of files */
133: #define E_LOCFILE "FILE" /* Local Filename */
134: #define E_REMFILE "REMFILE" /* Remote Filename */
135: #define E_BASEFILE "BASEFILE" /* basename of Remote File */
136:
137: /*
138: * Suffix to use when saving files
139: */
140: #ifndef SAVE_SUFFIX
141: #define SAVE_SUFFIX ".OLD"
142: #endif
1.1 deraadt 143:
1.2 dm 144: /*
145: * Get system error string
146: */
147: #define SYSERR strerror(errno)
148:
149: #define COMMENT_CHAR '#' /* Config file comment char */
150: #define CNULL '\0' /* NULL character */
151:
152: /*
153: * These are the top level protocol commands.
154: */
155: #define C_NONE '=' /* No command - pass cleanly */
156: #define C_ERRMSG '\1' /* Log an error message */
157: #define C_FERRMSG '\2' /* Log a fatal error message */
158: #define C_NOTEMSG '\3' /* Log a note message */
159: #define C_LOGMSG '\4' /* Log a message */
160: #define C_ACK '\5' /* Acknowledge */
161: #define C_SETCONFIG 'c' /* Set configuration parameters */
162: #define C_DIRTARGET 'T' /* Set target directory name */
163: #define C_TARGET 't' /* Set target file name */
164: #define C_RECVREG 'R' /* Receive a regular file */
165: #define C_RECVDIR 'D' /* Receive a directory */
166: #define C_RECVSYMLINK 'K' /* Receive a symbolic link */
167: #define C_RECVHARDLINK 'k' /* Receive a hard link */
1.15 jmc 168: #define C_END 'E' /* Indicate end of receive/send */
1.2 dm 169: #define C_CLEAN 'C' /* Clean up */
170: #define C_QUERY 'Q' /* Query without checking */
171: #define C_SPECIAL 'S' /* Execute special command */
172: #define C_CMDSPECIAL 's' /* Execute cmd special command */
1.13 millert 173: #define C_CHMOG 'M' /* Chown,Chgrp,Chmod a file */
1.2 dm 174:
1.21 guenther 175: #define ack() (void) sendcmd(C_ACK, NULL)
176: #define err() (void) sendcmd(C_ERRMSG, NULL)
1.2 dm 177:
178: /*
179: * Session startup commands.
180: */
181: #define S_VERSION 'V' /* Version number */
182: #define S_REMOTEUSER 'R' /* Remote user name */
183: #define S_LOCALUSER 'L' /* Local user name */
184: #define S_END 'E' /* End of session startup commands */
1.1 deraadt 185:
1.2 dm 186: /*
187: * These are the commands for "set config".
188: */
189: #define SC_FREESPACE 's' /* Set min free space */
190: #define SC_FREEFILES 'f' /* Set min free files */
191: #define SC_HOSTNAME 'H' /* Set client hostname */
192: #define SC_LOGGING 'L' /* Set logging options */
1.13 millert 193: #define SC_DEFOWNER 'o' /* Set default owner */
194: #define SC_DEFGROUP 'g' /* Set default group */
1.2 dm 195:
196: /*
197: * Query commands
198: */
199: #define QC_ONNFS 'F' /* File exists & is on a NFS */
200: #define QC_ONRO 'O' /* File exists & is on a readonly fs */
201: #define QC_NO 'N' /* File does not exist */
202: #define QC_SYM 'l' /* File exists & is a symlink */
203: #define QC_YES 'Y' /* File does exist */
1.1 deraadt 204:
1.2 dm 205: /*
206: * Clean commands
207: */
208: #define CC_QUERY 'Q' /* Query if file should be rm'ed */
209: #define CC_END 'E' /* End of cleaning */
210: #define CC_YES 'Y' /* File doesn't exist - remove */
211: #define CC_NO 'N' /* File does exist - don't remove */
212:
213: /*
214: * Run Command commands
215: */
216: #define RC_FILE 'F' /* Name of a target file */
217: #define RC_COMMAND 'C' /* Command to run */
218:
219: /*
220: * Name list
221: */
222: struct namelist { /* for making lists of strings */
1.1 deraadt 223: char *n_name;
1.12 millert 224: regex_t *n_regex;
1.1 deraadt 225: struct namelist *n_next;
226: };
227:
1.2 dm 228: /*
229: * Sub command structure
230: */
1.1 deraadt 231: struct subcmd {
232: short sc_type; /* type - INSTALL,NOTIFY,EXCEPT,SPECIAL */
1.2 dm 233: opt_t sc_options;
1.1 deraadt 234: char *sc_name;
235: struct namelist *sc_args;
236: struct subcmd *sc_next;
237: };
238:
1.2 dm 239: /*
240: * Cmd flags
241: */
242: #define CMD_ASSIGNED 0x01 /* This entry has been assigned */
243: #define CMD_CONNFAILED 0x02 /* Connection failed */
244: #define CMD_NOCHKNFS 0x04 /* Disable NFS checks */
245:
246: /*
247: * General command structure
248: */
1.1 deraadt 249: struct cmd {
250: int c_type; /* type - ARROW,DCOLON */
1.2 dm 251: int c_flags; /* flags - CMD_USED,CMD_FAILED */
1.1 deraadt 252: char *c_name; /* hostname or time stamp file name */
253: char *c_label; /* label for partial update */
254: struct namelist *c_files;
255: struct subcmd *c_cmds;
256: struct cmd *c_next;
257: };
258:
1.2 dm 259: /*
260: * Hard link buffer information
261: */
1.1 deraadt 262: struct linkbuf {
263: ino_t inum;
264: dev_t devnum;
265: int count;
1.10 millert 266: char *pathname;
267: char *src;
268: char *target;
1.1 deraadt 269: struct linkbuf *nextp;
270: };
271:
1.2 dm 272: extern char *optarg; /* Option argument */
273: extern char *path_remsh; /* Remote shell command */
274: extern char host[]; /* Host name of master copy */
275: extern char *currenthost; /* Name of current host */
276: extern char *progname; /* Name of this program */
277: extern char **realargv; /* Real argv */
278: extern int optind; /* Option index into argv */
279: extern int debug; /* Debugging flag */
280: extern opt_t defoptions; /* Default install options */
281: extern int do_fork; /* Should we do fork()'ing */
282: extern int isserver; /* Acting as remote server */
283: extern int nerrs; /* Number of errors seen */
284: extern int nflag; /* NOP flag, don't execute commands */
285: extern opt_t options; /* Global options */
286: extern int proto_version; /* Protocol version number */
287: extern int realargc; /* Real argc */
288: extern int rem_r; /* Remote file descriptor, reading */
289: extern int rem_w; /* Remote file descriptor, writing */
290: extern int rtimeout; /* Response time out in seconds */
1.3 dm 291: extern int setjmp_ok; /* setjmp/longjmp flag */
1.22 guenther 292: extern uid_t userid; /* User ID of rdist user */
1.2 dm 293: extern jmp_buf finish_jmpbuf; /* Setjmp buffer for finish() */
294: extern struct linkbuf *ihead; /* list of files with more than one link */
295: extern struct passwd *pw; /* pointer to static area used by getpwent */
1.13 millert 296: extern char defowner[64]; /* Default owner */
297: extern char defgroup[64]; /* Default group */
298: extern volatile sig_atomic_t contimedout; /* Connection timed out */
1.2 dm 299: #ifdef USE_STATDB
300: extern int dostatdb;
301: extern int juststatdb;
302: #endif /* USE_STATDB */
303:
304: /*
1.13 millert 305: * Our own declarations.
1.2 dm 306: */
307:
1.13 millert 308: /* child.c */
309: void waitup(void);
310: int spawn(struct cmd *, struct cmd *);
311:
312: /* client.c */
313: char *remfilename(char *, char *, char *, char *, int);
314: int inlist(struct namelist *, char *);
315: void runcmdspecial(struct cmd *, opt_t);
316: int checkfilename(char *);
317: void freelinkinfo(struct linkbuf *);
318: void cleanup(int);
319: int install(char *, char *, int, int , opt_t);
320:
321: /* common.c */
1.23 guenther 322: ssize_t xwrite(int, void *, size_t);
1.13 millert 323: int init(int, char **, char **);
324: void finish(void);
325: void lostconn(void);
326: void coredump(void);
327: void sighandler(int);
1.21 guenther 328: int sendcmd(char, const char *, ...) __attribute__((__format__ (printf, 2, 3)));
1.13 millert 329: int remline(u_char *, int, int);
1.17 krw 330: ssize_t readrem(char *, ssize_t);
1.22 guenther 331: char *getusername(uid_t, char *, opt_t);
332: char *getgroupname(gid_t, char *, opt_t);
1.13 millert 333: int response(void);
334: char *exptilde(char *, char *, size_t);
335: int becomeuser(void);
336: int becomeroot(void);
337: int setfiletime(char *, time_t, time_t);
338: char *getversion(void);
339: void runcommand(char *);
1.20 guenther 340: void *xmalloc(size_t);
341: void *xrealloc(void *, size_t);
342: void *xcalloc(size_t, size_t);
1.13 millert 343: char *xstrdup(const char *);
344: char *xbasename(char *);
345: char *searchpath(char *);
346:
347: /* distopt.c */
348: DISTOPTINFO *getdistopt(char *, int *);
349: int parsedistopts(char *, opt_t *, int);
350: char *getdistoptlist(void);
351: char *getondistoptlist(opt_t);
352:
353: /* docmd.c */
354: void markassigned(struct cmd *, struct cmd *);
355: int okname(char *);
356: int except(char *);
357: void docmds(struct namelist *, int, char **);
358:
359: /* expand.c */
360: struct namelist *expand(struct namelist *, int);
361: u_char *xstrchr(u_char *, int);
362: void expstr(u_char *);
363: void expsh(u_char *);
364: void matchdir(char *);
365: int execbrc(u_char *, u_char *);
366: int match(char *, char *);
367: int amatch(char *, u_char *);
368:
369: /* filesys.c */
370: char *find_file(char *, struct stat *, int *);
371: mntent_t *findmnt(struct stat *, struct mntinfo *);
372: int isdupmnt(mntent_t *, struct mntinfo *);
373: void wakeup(int);
374: struct mntinfo *makemntinfo(struct mntinfo *);
375: mntent_t *getmntpt(char *, struct stat *, int *);
376: int is_nfs_mounted(char *, struct stat *, int *);
377: int is_ro_mounted(char *, struct stat *, int *);
378: int is_symlinked(char *, struct stat *, int *);
1.17 krw 379: int getfilesysinfo(char *, int64_t *, int64_t *);
1.13 millert 380:
381: /* gram.c */
382: int yylex(void);
383: int any(int, char *);
384: void insert(char *, struct namelist *, struct namelist *, struct subcmd *);
385: void append(char *, struct namelist *, char *, struct subcmd *);
386: void yyerror(char *);
387: struct namelist *makenl(char *);
388: struct subcmd *makesubcmd(int);
389: int yyparse(void);
390:
391: /* isexec.c */
392: int isexec(char *, struct stat *);
393:
394: /* lookup.c */
395: void define(char *);
396: struct namelist *lookup(char *, int, struct namelist *);
397:
398: /* message.c */
399: void msgprusage(void);
400: void msgprconfig(void);
401: char *msgparseopts(char *, int);
402: void checkhostname(void);
1.19 guenther 403: void message(int, const char *, ...) __attribute__((format (printf, 2, 3)));
404: void debugmsg(int, const char *, ...) __attribute__((format (printf, 2, 3)));
405: void error(const char *, ...) __attribute__((format (printf, 1, 2)));
406: void fatalerr(const char *, ...) __attribute__((format (printf, 1, 2)));
1.13 millert 407: char *getnotifyfile(void);
408:
409: /* rdist.c */
410: FILE *opendist(char *);
411: void docmdargs(int, char *[]);
412: char *getnlstr(struct namelist *);
413:
414: /* server.c */
415: void server(void);
416:
417: #include <vis.h>
418: #define DECODE(a, b) strunvis(a, b)
419: #define ENCODE(a, b) strvis(a, b, VIS_WHITE)
1.2 dm 420:
421: #endif /* __DEFS_H__ */