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