1/*	$OpenBSD: defs.h,v 1.40 2024/05/21 05:00:48 jsg Exp $	*/
2
3#ifndef __DEFS_H__
4#define __DEFS_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 <pwd.h>
40#include <setjmp.h>
41#include <signal.h>
42
43#ifndef __GNUC__
44# ifndef __attribute__
45#  define __attribute__(a)
46# endif
47#endif
48
49#include "version.h"
50#include "config.h"
51#include "pathnames.h"
52#include "types.h"
53
54/*
55 * Define the read and write values for the file descriptor array
56 * used by pipe().
57 */
58#define PIPE_READ		0
59#define PIPE_WRITE		1
60
61	/* boolean truth */
62#ifndef TRUE
63#define TRUE		1
64#endif
65#ifndef FALSE
66#define FALSE		0
67#endif
68
69	/* Bit flag test macros */
70#define IS_ON(b,f)	(b & f)
71#define IS_OFF(b,f)	!(IS_ON(b,f))
72#define FLAG_ON(b,f)	b |= f
73#define FLAG_OFF(b,f)	b &= ~(f)
74
75/*
76 * Environment variable names
77 */
78#define E_FILES		"FILES"			/* List of files */
79#define E_LOCFILE	"FILE"			/* Local Filename  */
80#define E_REMFILE	"REMFILE"		/* Remote Filename */
81#define E_BASEFILE	"BASEFILE"		/* basename of Remote File */
82
83/*
84 * Get system error string
85 */
86#define SYSERR		strerror(errno)
87
88#define CNULL		'\0'		/* NULL character */
89
90/*
91 * These are the top level protocol commands.
92 */
93#define C_NONE		'='		/* No command - pass cleanly */
94#define C_ERRMSG	'\1'		/* Log an error message */
95#define C_FERRMSG	'\2'		/* Log a fatal error message */
96#define C_NOTEMSG	'\3'		/* Log a note message */
97#define C_LOGMSG	'\4'		/* Log a message */
98#define C_ACK		'\5'		/* Acknowledge */
99#define C_SETCONFIG	'c'		/* Set configuration parameters */
100#define C_DIRTARGET	'T'		/* Set target directory name */
101#define C_TARGET	't'		/* Set target file name */
102#define C_RECVREG	'R'		/* Receive a regular file */
103#define C_RECVDIR	'D'		/* Receive a directory */
104#define C_RECVSYMLINK	'K'		/* Receive a symbolic link */
105#define C_RECVHARDLINK	'k'		/* Receive a hard link */
106#define C_END		'E'		/* Indicate end of receive/send */
107#define C_CLEAN		'C'		/* Clean up */
108#define C_QUERY		'Q'		/* Query without checking */
109#define C_SPECIAL	'S'		/* Execute special command */
110#define C_CMDSPECIAL	's'		/* Execute cmd special command */
111#define C_CHMOG		'M'		/* Chown,Chgrp,Chmod a file */
112
113#define	ack()		(void) sendcmd(C_ACK, NULL)
114#define	err()		(void) sendcmd(C_ERRMSG, NULL)
115
116/*
117 * Session startup commands.
118 */
119#define S_VERSION	'V'		/* Version number */
120#define S_REMOTEUSER	'R'		/* Remote user name */
121#define S_LOCALUSER	'L'		/* Local user name */
122#define S_END		'E'		/* End of session startup commands */
123
124/*
125 * These are the commands for "set config".
126 */
127#define SC_FREESPACE	's'		/* Set min free space */
128#define SC_FREEFILES	'f'		/* Set min free files */
129#define SC_HOSTNAME	'H'		/* Set client hostname */
130#define SC_LOGGING	'L'		/* Set logging options */
131#define SC_DEFOWNER	'o'		/* Set default owner */
132#define SC_DEFGROUP	'g'		/* Set default group */
133
134/*
135 * Query commands
136 */
137#define QC_ONNFS	'F'		/* File exists & is on a NFS */
138#define QC_ONRO		'O'		/* File exists & is on a readonly fs */
139#define QC_NO		'N'		/* File does not exist */
140#define QC_SYM		'l'		/* File exists & is a symlink */
141#define QC_YES		'Y'		/* File does exist */
142
143/*
144 * Clean commands
145 */
146#define CC_QUERY	'Q'		/* Query if file should be rm'ed */
147#define CC_END		'E'		/* End of cleaning */
148#define CC_YES		'Y'		/* File doesn't exist - remove */
149#define CC_NO		'N'		/* File does exist - don't remove */
150
151/*
152 * Run Command commands
153 */
154#define RC_FILE		'F'		/* Name of a target file */
155#define RC_COMMAND	'C'		/* Command to run */
156
157
158extern char	       *currenthost;	/* Name of current host */
159extern char	       *progname;	/* Name of this program */
160extern char	       *locuser;	/* Local User's name */
161extern int		debug;		/* Debugging flag */
162extern int		isserver;	/* Acting as remote server */
163extern int		nerrs;		/* Number of errors seen */
164extern opt_t		options;	/* Global options */
165extern int		rem_r;		/* Remote file descriptor, reading */
166extern int		rem_w;		/* Remote file descriptor, writing */
167extern int		rtimeout;	/* Response time out in seconds */
168extern uid_t		userid;		/* User ID of rdist user */
169extern gid_t		groupid;	/* Group ID of rdist user */
170extern gid_t	        gidset[];	/* List of group IDs of rdist user */
171extern int		gidsetlen;	/* Number of group IDs in list */
172extern jmp_buf		finish_jmpbuf;	/* Setjmp buffer for finish() */
173extern char defowner[64];		/* Default owner */
174extern char defgroup[64];		/* Default group */
175extern volatile sig_atomic_t contimedout; /* Connection timed out */
176
177
178/*
179 * Declarations for files shared between rdist and rdistd
180 */
181
182/* common.c */
183ssize_t xwrite(int, void *, size_t);
184int init(int, char **, char **);
185void finish(void);
186void lostconn(void);
187void sighandler(int);
188int sendcmd(char, const char *, ...) __attribute__((__format__ (printf, 2, 3)));
189int remline(u_char *, int, int);
190ssize_t readrem(char *, ssize_t);
191char *getusername(uid_t, char *, opt_t);
192char *getgroupname(gid_t, char *, opt_t);
193int response(void);
194char *exptilde(char *, char *, size_t);
195int setfiletime(char *, time_t, time_t);
196char *getversion(void);
197void runcommand(char *);
198void *xmalloc(size_t);
199void *xrealloc(void *, size_t);
200void *xcalloc(size_t, size_t);
201char *xstrdup(const char *);
202char *xbasename(char *);
203char *searchpath(char *);
204
205/* message.c */
206void msgprconfig(void);
207char *msgparseopts(char *, int);
208void checkhostname(void);
209void message(int, const char *, ...) __attribute__((format (printf, 2, 3)));
210void debugmsg(int, const char *, ...) __attribute__((format (printf, 2, 3)));
211void error(const char *, ...) __attribute__((format (printf, 1, 2)));
212void fatalerr(const char *, ...) __attribute__((format (printf, 1, 2)));
213char *getnotifyfile(void);
214
215/* client.c or server.c */
216void cleanup(int);
217
218#include <vis.h>
219#define DECODE(a, b)	strunvis(a, b)
220#define ENCODE(a, b)	strvis(a, b, VIS_WHITE)
221
222#endif	/* __DEFS_H__ */
223