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