1 /*
2  * Copyright (c) 1992-1998 Michael A. Cooper.
3  * This software may be freely used and distributed provided it is not
4  * sold for profit or used in part or in whole for commercial gain
5  * without prior written agreement, and the author is credited
6  * appropriately.
7  */
8 
9 /*
10  * $Id: defs.h,v 6.84 1998/11/10 04:23:54 mcooper Exp $
11  * @(#)defs.h      5.2 (Berkeley) 3/20/86
12  */
13 
14 #ifndef __DEFS_H__
15 #define __DEFS_H__
16 
17 /*
18  * POSIX settings
19  */
20 #include <unistd.h>
21 #include <stdlib.h>
22 #include <libgen.h>
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <errno.h>
26 #include <pwd.h>
27 #include <grp.h>
28 #include <syslog.h>
29 #include <setjmp.h>
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/file.h>
33 #include <sys/time.h>
34 #include <sys/stat.h>
35 
36 #include "version.h"
37 #include "config-def.h"
38 #include "config.h"
39 #include "config-data.h"
40 #include "pathnames.h"
41 #include "types.h"
42 
43 #if	!defined(yacc)
44 #include "y.tab.h"
45 #endif	/* yacc */
46 
47 #include <signal.h>
48 
49 /*
50  * This belongs in os-svr4.h but many SVR4 OS's
51  * define SVR4 externel to Rdist so we put this
52  * check here.
53  */
54 #if	defined(SVR4)
55 #define NEED_FCNTL_H
56 #define NEED_UNISTD_H
57 #define NEED_NETDB_H
58 #endif	/* defined(SVR4) */
59 
60 #if	defined(NEED_NETDB_H)
61 #include <netdb.h>
62 #endif	/* NEED_NETDB_H */
63 #if	defined(NEED_FCNTL_H)
64 #include <fcntl.h>
65 #endif	/* NEED_FCNTL_H */
66 #if	defined(NEED_LIMITS_H)
67 #include <limits.h>
68 #endif	/* NEED_LIMITS_H */
69 #if	defined(NEED_UNISTD_H)
70 #include <unistd.h>
71 #endif	/* NEED_UNISTD_H */
72 #if	defined(NEED_STRING_H)
73 #include <string.h>
74 #endif	/* NEED_STRING_H */
75 
76 #if defined(ARG_TYPE)
77 #if	ARG_TYPE == ARG_STDARG
78 #include <stdarg.h>
79 #endif
80 #if	ARG_TYPE == ARG_VARARGS
81 #include <varargs.h>
82 #endif
83 #endif	/* ARG_TYPE */
84 
85 	/* boolean truth */
86 #ifndef TRUE
87 #define TRUE		1
88 #endif
89 #ifndef FALSE
90 #define FALSE		0
91 #endif
92 
93 	/* file modes */
94 #ifndef S_IXUSR
95 #define S_IXUSR		0000100
96 #endif
97 #ifndef S_IXGRP
98 #define S_IXGRP		0000010
99 #endif
100 #ifndef S_IXOTH
101 #define S_IXOTH		0000001
102 #endif
103 
104 	/* lexical definitions */
105 #define	QUOTECHAR	160	/* quote next character */
106 
107 	/* table sizes */
108 #define HASHSIZE	1021
109 #define INMAX		3500
110 
111 	/* expand type definitions */
112 #define E_VARS		0x1
113 #define E_SHELL		0x2
114 #define E_TILDE		0x4
115 #define E_ALL		0x7
116 
117 	/* actions for lookup() */
118 #define LOOKUP		0
119 #define INSERT		1
120 #define REPLACE		2
121 
122 	/* Bit flag test macros */
123 #define IS_ON(b,f)	(b > 0 && (b & f))
124 #define IS_OFF(b,f)	!(IS_ON(b,f))
125 #define FLAG_ON(b,f)	b |= f
126 #define FLAG_OFF(b,f)	b &= ~(f)
127 
128 /*
129  * POSIX systems should already have S_* defined.
130  */
131 #ifndef S_ISDIR
132 #define S_ISDIR(m) 	(((m) & S_IFMT) == S_IFDIR)
133 #endif
134 #ifndef S_ISREG
135 #define S_ISREG(m) 	(((m) & S_IFMT) == S_IFREG)
136 #endif
137 #ifndef S_ISLNK
138 #define S_ISLNK(m) 	(((m) & S_IFMT) == S_IFLNK)
139 #endif
140 
141 #define ALLOC(x) 	(struct x *) xmalloc(sizeof(struct x))
142 #define A(s)		((s) ? s : "<null>")
143 
144 /*
145  * Environment variable names
146  */
147 #define E_FILES		"FILES"			/* List of files */
148 #define E_LOCFILE	"FILE"			/* Local Filename  */
149 #define E_REMFILE	"REMFILE"		/* Remote Filename */
150 #define E_BASEFILE	"BASEFILE"		/* basename of Remote File */
151 
152 /*
153  * Suffix to use when saving files
154  */
155 #ifndef SAVE_SUFFIX
156 #define SAVE_SUFFIX	".OLD"
157 #endif
158 
159 /*
160  * Get system error string
161  */
162 #define SYSERR 		strerror(errno)
163 
164 #define COMMENT_CHAR	'#'		/* Config file comment char */
165 #define CNULL		'\0'		/* NULL character */
166 
167 /*
168  * These are the top level protocol commands.
169  */
170 #define C_NONE		'='		/* No command - pass cleanly */
171 #define C_ERRMSG	'\1'		/* Log an error message */
172 #define C_FERRMSG	'\2'		/* Log a fatal error message */
173 #define C_NOTEMSG	'\3'		/* Log a note message */
174 #define C_LOGMSG	'\4'		/* Log a message */
175 #define C_ACK		'\5'		/* Acknowledge */
176 #define C_SETCONFIG	'c'		/* Set configuration parameters */
177 #define C_DIRTARGET	'T'		/* Set target directory name */
178 #define C_TARGET	't'		/* Set target file name */
179 #define C_RECVREG	'R'		/* Receive a regular file */
180 #define C_RECVDIR	'D'		/* Receive a directory */
181 #define C_RECVSYMLINK	'K'		/* Receive a symbolic link */
182 #define C_RECVHARDLINK	'k'		/* Receive a hard link */
183 #define C_END		'E'		/* Indicate end of recieve/send */
184 #define C_CLEAN		'C'		/* Clean up */
185 #define C_QUERY		'Q'		/* Query without checking */
186 #define C_SPECIAL	'S'		/* Execute special command */
187 #define C_CMDSPECIAL	's'		/* Execute cmd special command */
188 #define C_CHMOD		'M'		/* Chmod a file */
189 
190 #define	ack() 		(void) sendcmd(C_ACK, (char *)NULL)
191 #define	err() 		(void) sendcmd(C_ERRMSG, (char *)NULL)
192 
193 /*
194  * Session startup commands.
195  */
196 #define S_VERSION	'V'		/* Version number */
197 #define S_REMOTEUSER	'R'		/* Remote user name */
198 #define S_LOCALUSER	'L'		/* Local user name */
199 #define S_END		'E'		/* End of session startup commands */
200 
201 /*
202  * These are the commands for "set config".
203  */
204 #define SC_FREESPACE	's'		/* Set min free space */
205 #define SC_FREEFILES	'f'		/* Set min free files */
206 #define SC_HOSTNAME	'H'		/* Set client hostname */
207 #define SC_LOGGING	'L'		/* Set logging options */
208 
209 /*
210  * Query commands
211  */
212 #define QC_ONNFS	'F'		/* File exists & is on a NFS */
213 #define QC_ONRO		'O'		/* File exists & is on a readonly fs */
214 #define QC_NO		'N'		/* File does not exist */
215 #define QC_SYM		'l'		/* File exists & is a symlink */
216 #define QC_YES		'Y'		/* File does exist */
217 
218 /*
219  * Clean commands
220  */
221 #define CC_QUERY	'Q'		/* Query if file should be rm'ed */
222 #define CC_END		'E'		/* End of cleaning */
223 #define CC_YES		'Y'		/* File doesn't exist - remove */
224 #define CC_NO		'N'		/* File does exist - don't remove */
225 
226 /*
227  * Run Command commands
228  */
229 #define RC_FILE		'F'		/* Name of a target file */
230 #define RC_COMMAND	'C'		/* Command to run */
231 
232 /*
233  * Name list
234  */
235 struct namelist {		/* for making lists of strings */
236 	char	*n_name;
237 	struct	namelist *n_next;
238 };
239 
240 /*
241  * Sub command structure
242  */
243 struct subcmd {
244 	short	sc_type;	/* type - INSTALL,NOTIFY,EXCEPT,SPECIAL */
245 	opt_t	sc_options;
246 	char	*sc_name;
247 	struct	namelist *sc_args;
248 	struct	subcmd *sc_next;
249 };
250 
251 /*
252  * Cmd flags
253  */
254 #define CMD_ASSIGNED	0x01	/* This entry has been assigned */
255 #define CMD_CONNFAILED	0x02	/* Connection failed */
256 #define CMD_NOCHKNFS	0x04	/* Disable NFS checks */
257 
258 /*
259  * General command structure
260  */
261 struct cmd {
262 	int	c_type;		/* type - ARROW,DCOLON */
263 	int	c_flags;	/* flags - CMD_USED,CMD_FAILED */
264 	char	*c_name;	/* hostname or time stamp file name */
265 	char	*c_label;	/* label for partial update */
266 	struct	namelist *c_files;
267 	struct	subcmd *c_cmds;
268 	struct	cmd *c_next;
269 };
270 
271 /*
272  * Hard link buffer information
273  */
274 struct linkbuf {
275 	ino_t	inum;
276 	dev_t	devnum;
277 	int	count;
278 	char	pathname[BUFSIZ];
279 	char	src[BUFSIZ];
280 	char	target[BUFSIZ];
281 	struct	linkbuf *nextp;
282 };
283 
284 extern char	       *optarg;		/* Option argument */
285 extern char	       *path_remsh;	/* Remote shell command */
286 extern char 		buf[];		/* General purpose buffer */
287 extern char 		host[];		/* Host name of master copy */
288 extern char 	       *currenthost;	/* Name of current host */
289 extern char 	       *progname;	/* Name of this program */
290 extern char 	      **realargv;	/* Real argv */
291 extern int		optind;		/* Option index into argv */
292 extern int 		contimedout;	/* Connection timed out */
293 extern int 		debug;		/* Debugging flag */
294 extern opt_t 		defoptions;	/* Default install options */
295 extern int 		do_fork;	/* Should we do fork()'ing */
296 extern int 		errno;		/* System error number */
297 extern int 		isserver;	/* Acting as remote server */
298 extern int 		nerrs;		/* Number of errors seen */
299 extern int 		nflag;		/* NOP flag, don't execute commands */
300 extern opt_t 		options;	/* Global options */
301 extern int 		proto_version;	/* Protocol version number */
302 extern int 		realargc;	/* Real argc */
303 extern int		rem_r;		/* Remote file descriptor, reading */
304 extern int 		rem_w;		/* Remote file descriptor, writing */
305 extern int 		rtimeout;	/* Response time out in seconds */
306 extern int		setjmp_ok;	/* setjmp/longjmp flag */
307 extern void		mysetlinebuf();	/* set line buffering */
308 extern UID_T 		userid;		/* User ID of rdist user */
309 extern jmp_buf 		finish_jmpbuf;	/* Setjmp buffer for finish() */
310 extern struct group    *gr;	/* pointer to static area used by getgrent */
311 extern struct linkbuf  *ihead;	/* list of files with more than one link */
312 extern struct passwd   *pw;	/* pointer to static area used by getpwent */
313 #ifdef USE_STATDB
314 extern int 		dostatdb;
315 extern int 		juststatdb;
316 #endif /* USE_STATDB */
317 
318 /*
319  * System function declarations
320  */
321 char 			       *hasmntopt();
322 char			       *strchr();
323 char		 	       *strdup();
324 char		 	       *strrchr();
325 char 			       *strtok();
326 
327 /*
328  * Our own declarations.
329  */
330 char			       *exptilde();
331 char			       *makestr();
332 char	       		       *xcalloc();
333 char	       		       *xmalloc();
334 char	       		       *xrealloc();
335 extern char		       *xbasename();
336 extern char		       *getdistoptlist();
337 extern char		       *getgroupname();
338 extern char		       *getnlstr();
339 extern char		       *getnotifyfile();
340 extern char		       *getondistoptlist();
341 extern char		       *getusername();
342 extern char		       *getversion();
343 extern char		       *msgparseopts();
344 extern char		       *searchpath();
345 extern int			any();
346 extern int			init();
347 extern int			install();
348 extern int			isexec();
349 extern int			parsedistopts();
350 extern int			remline();
351 extern int			setfiletime();
352 extern int			spawn();
353 extern struct subcmd 	       *makesubcmd();
354 extern void			checkhostname();
355 extern void			cleanup();
356 extern void			complain();
357 extern void			docmds();
358 extern void			finish();
359 extern void			logmsg();
360 extern void			lostconn();
361 extern void			markassigned();
362 extern void			msgprusage();
363 extern void			note();
364 extern void			runcmdspecial();
365 extern void			runcommand();
366 extern void			server();
367 extern void			sighandler();
368 extern void			waitup();
369 struct namelist		       *expand();
370 struct namelist		       *lookup();
371 struct namelist		       *makenl();
372 extern WRITE_RETURN_T		xwrite();
373 
374 #if	defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
375 extern void			debugmsg(int, char *, ...);
376 extern void			error(char *, ...);
377 extern void			fatalerr(char *, ...);
378 extern void			message(int, char *, ...);
379 #ifndef HAVE_SETPROCTITLE
380 extern void			setproctitle(char *fmt, ...);
381 #endif
382 #else
383 extern void			debugmsg();
384 extern void			error();
385 extern void			fatalerr();
386 extern void			message();
387 extern void			setproctitle();
388 #endif
389 
390 #endif	/* __DEFS_H__ */
391