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