1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  *
14  * Copyright (c) 1998, by Sun Microsystems, Inc.
15  * All rights reserved.
16  */
17 #pragma ident	"%Z%%M%	%I%	%E% SMI"
18 
19 #include <stdio.h>
20 #include <ctype.h>
21 #include <errno.h>
22 #include <pwd.h>
23 #include <grp.h>
24 #include <dirent.h>
25 #include <sys/types.h>
26 #include <sys/param.h>
27 #include <sys/stat.h>
28 #include <sys/time.h>
29 #include <netinet/in.h>
30 
31 #ifdef SYSV
32 #define rindex  strrchr
33 #define index   strchr
34 #endif /* SYSV */
35 
36 /*
37  * The version number should be changed whenever the protocol changes.
38  */
39 #define VERSION	 3
40 
41 #define	MAILCMD	 "/usr/lib/sendmail -oi -t"
42 
43 	/* defines for yacc */
44 #define EQUAL	1
45 #define LP	2
46 #define RP	3
47 #define SM	4
48 #define ARROW	5
49 #define COLON	6
50 #define DCOLON	7
51 #define NAME	8
52 #define STRING	9
53 #define INSTALL	10
54 #define NOTIFY	11
55 #define EXCEPT	12
56 #define PATTERN	13
57 #define SPECIAL	14
58 #define OPTION	15
59 
60 	/* lexical definitions */
61 #define	QUOTE 	0200		/* used internally for quoted characters */
62 #define	TRIM	0177		/* Mask to strip quote bit */
63 
64 	/* table sizes */
65 #define HASHSIZE	1021
66 #define INMAX	3500
67 #define	LINESIZE	BUFSIZ
68 
69 	/* option flags */
70 #define VERIFY	0x1
71 #define WHOLE	0x2
72 #define YOUNGER	0x4
73 #define COMPARE	0x8
74 #define REMOVE	0x10
75 #define FOLLOW	0x20
76 #define IGNLNKS	0x40
77 #define	OBITS "\020\1VERIFY\2WHOLE\3YOUNGER\4COMPARE\5REMOVE\6FOLLOW\7IGNLNKS"
78 
79 	/* expand type definitions */
80 #define E_VARS	0x1
81 #define E_SHELL	0x2
82 #define E_TILDE	0x4
83 #define E_ALL	0x7
84 
85 	/* actions for lookup() */
86 #define LOOKUP	0
87 #define INSERT	1
88 #define REPLACE	2
89 
90 #define ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
91 
92 #define ALLOC(x) (struct x *) malloc(sizeof(struct x))
93 
94 struct namelist {	/* for making lists of strings */
95 	char	*n_name;
96 	struct	namelist *n_next;
97 };
98 
99 struct subcmd {
100 	short	sc_type;	/* type - INSTALL,NOTIFY,EXCEPT,SPECIAL */
101 	short	sc_options;
102 	char	*sc_name;
103 	struct	namelist *sc_args;
104 	struct	subcmd *sc_next;
105 };
106 
107 struct cmd {
108 	int	c_type;		/* type - ARROW,DCOLON */
109 	char	*c_name;	/* hostname or time stamp file name */
110 	char	*c_label;	/* label for partial update */
111 	struct	namelist *c_files;
112 	struct	subcmd *c_cmds;
113 	struct	cmd *c_next;
114 };
115 
116 struct linkbuf {
117 	ino_t	inum;
118 	dev_t	devnum;
119 	int	count;
120 	char	pathname[LINESIZE];
121 	char	target[LINESIZE];
122 	struct	linkbuf *nextp;
123 };
124 
125 extern int debug;		/* debugging flag */
126 extern int nflag;		/* NOP flag, don't execute commands */
127 extern int qflag;		/* Quiet. don't print messages */
128 extern int options;		/* global options */
129 
130 extern int nerrs;		/* number of errors seen */
131 extern int rem;			/* remote file descriptor */
132 extern int iamremote;		/* acting as remote server */
133 extern char Tmpfile[];		/* file name for logging changes */
134 extern struct linkbuf *ihead;	/* list of files with more than one link */
135 extern struct passwd *pw;	/* pointer to static area used by getpwent */
136 extern struct group *gr;	/* pointer to static area used by getgrent */
137 extern char host[];		/* host name of master copy */
138 extern char buf[];		/* general purpose buffer */
139 extern int errno;		/* system error number */
140 extern char *sys_errlist[];
141 
142 char *makestr();
143 struct namelist *makenl();
144 struct subcmd *makesubcmd();
145 struct namelist *lookup();
146 struct namelist *expand();
147 char *exptilde();
148 char *rindex();
149 char *index();
150 char *printb();
151 void sendrem();
152