xref: /openbsd/usr.bin/rdist/client.h (revision 73471bf0)
1 /*	$OpenBSD: client.h,v 1.4 2021/06/22 20:19:28 jmc Exp $	*/
2 
3 #ifndef __CLIENT_H__
4 #define __CLIENT_H__
5 /*
6  * Copyright (c) 1983 Regents of the University of California.
7  * All rights reserved.
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.
17  * 3. Neither the name of the University nor the names of its contributors
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 
34 /*
35  * $From: defs.h,v 1.6 2001/03/12 18:16:30 kim Exp $
36  * @(#)defs.h      5.2 (Berkeley) 3/20/86
37  */
38 
39 #include <sys/stat.h>
40 #include <regex.h>
41 #include <stdio.h>
42 
43 #include "defs.h"
44 
45 	/* lexical definitions */
46 #define	QUOTECHAR	160U	/* quote next character */
47 
48 	/* table sizes */
49 #define HASHSIZE	1021
50 #define INMAX		3500
51 
52 	/* expand type definitions */
53 #define E_VARS		0x1
54 #define E_SHELL		0x2
55 #define E_TILDE		0x4
56 #define E_ALL		0x7
57 
58 	/* actions for lookup() */
59 #define LOOKUP		0
60 #define INSERT		1
61 #define REPLACE		2
62 
63 #define ALLOC(x) 	xmalloc(sizeof(struct x))
64 #define A(s)		((s) ? s : "<null>")
65 
66 
67 #define COMMENT_CHAR	'#'		/* Config file comment char */
68 
69 
70 /*
71  * Name list
72  */
73 struct namelist {		/* for making lists of strings */
74 	char	*n_name;
75 	regex_t	*n_regex;
76 	struct	namelist *n_next;
77 };
78 
79 /*
80  * Sub command structure
81  */
82 struct subcmd {
83 	short	sc_type;	/* type - INSTALL,NOTIFY,EXCEPT,SPECIAL */
84 	opt_t	sc_options;
85 	char	*sc_name;
86 	struct	namelist *sc_args;
87 	struct	subcmd *sc_next;
88 };
89 
90 /*
91  * Cmd flags
92  */
93 #define CMD_ASSIGNED	0x01	/* This entry has been assigned */
94 #define CMD_CONNFAILED	0x02	/* Connection failed */
95 #define CMD_NOCHKNFS	0x04	/* Disable NFS checks */
96 
97 /*
98  * General command structure
99  */
100 struct cmd {
101 	int	c_type;		/* type - ARROW,DCOLON */
102 	int	c_flags;	/* flags - CMD_USED,CMD_FAILED */
103 	char	*c_name;	/* hostname or time stamp file name */
104 	char	*c_label;	/* label for partial update */
105 	struct	namelist *c_files;
106 	struct	subcmd *c_cmds;
107 	struct	cmd *c_next;
108 };
109 
110 /*
111  * Hard link buffer information
112  */
113 struct linkbuf {
114 	ino_t	inum;
115 	dev_t	devnum;
116 	int	count;
117 	char	*pathname;
118 	char	*src;
119 	char	*target;
120 	struct	linkbuf *nextp;
121 };
122 
123 extern char	       *path_remsh;	/* Remote shell command */
124 extern char 		host[];		/* Host name of master copy */
125 extern char 	      **realargv;	/* Real argv */
126 extern char	       *homedir;	/* User's $HOME */
127 extern int 		do_fork;	/* Should we do fork()'ing */
128 extern int 		nflag;		/* NOP flag, don't execute commands */
129 extern int 		realargc;	/* Real argc */
130 extern int		setjmp_ok;	/* setjmp/longjmp flag */
131 extern int		maxchildren;	/* Max active children */
132 extern int64_t		min_freespace;	/* Min filesys free space */
133 extern int64_t		min_freefiles;	/* Min filesys free # files */
134 extern struct linkbuf  *ihead;	/* list of files with more than one link */
135 extern struct subcmd   *subcmds;/* list of sub-commands for current cmd */
136 extern struct namelist *filelist;	/* list of source files */
137 extern struct cmd      *cmds;		/* Initialized by yyparse() */
138 
139 extern char 		target[BUFSIZ];	/* target/source directory name */
140 extern char 	       *ptarget;	/* pointer to end of target name */
141 extern int		activechildren;	/* Number of active children */
142 extern int		amchild;	/* This PID is a child */
143 extern char	       *path_rdistd;
144 extern char	       *remotemsglist;
145 
146 /*
147  * Our own declarations.
148  */
149 
150 /* child.c */
151 void waitup(void);
152 int spawn(struct cmd *, struct cmd *);
153 
154 /* client.c */
155 char *remfilename(char *, char *, char *, char *, int);
156 int inlist(struct namelist *, char *);
157 void runcmdspecial(struct cmd *, opt_t);
158 int checkfilename(char *);
159 void freelinkinfo(struct linkbuf *);
160 int install(char *, char *, int, int , opt_t);
161 
162 /* distopt.c */
163 int parsedistopts(char *, opt_t *, int);
164 char *getondistoptlist(opt_t);
165 
166 /* docmd.c */
167 void markassigned(struct cmd *, struct cmd *);
168 int okname(char *);
169 int except(char *);
170 void docmds(struct namelist *, int, char **);
171 
172 /* expand.c */
173 struct namelist *expand(struct namelist *, int);
174 u_char *xstrchr(u_char *, int);
175 void expstr(u_char *);
176 void expsh(u_char *);
177 void matchdir(char *);
178 int execbrc(u_char *, u_char *);
179 int match(char *, char *);
180 int amatch(char *, u_char *);
181 
182 /* gram.c */
183 int yylex(void);
184 int any(int, char *);
185 void insert(char *, struct namelist *, struct namelist *, struct subcmd *);
186 void append(char *, struct namelist *, char *, struct subcmd *);
187 void yyerror(char *);
188 struct namelist *makenl(char *);
189 struct subcmd *makesubcmd(int);
190 int yyparse(void);
191 
192 /* isexec.c */
193 int isexec(char *, struct stat *);
194 
195 /* lookup.c */
196 void define(char *);
197 struct namelist *lookup(char *, int, struct namelist *);
198 
199 /* rdist.c */
200 FILE *opendist(char *);
201 void docmdargs(int, char *[]);
202 char *getnlstr(struct namelist *);
203 
204 #endif	/* __CLIENT_H__ */
205