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