configuration parsing and loading code for rsyncd. This is based
[rsync/rsync.git] / rsync.h
CommitLineData
c627d613
AT
1/*
2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#define BLOCK_SIZE 700
21#define RSYNC_RSH_ENV "RSYNC_RSH"
7b8356d0 22
c627d613 23#define RSYNC_NAME "rsync"
f0fca04e
AT
24#define RSYNCD_CONF "/etc/rsyncd.conf"
25#define RSYNCD_LOG "/var/adm/rsyncd.log"
26
c627d613
AT
27#define BACKUP_SUFFIX "~"
28
1b01b295
AT
29/* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is
30 imcompatible with older versions :-( */
31#define CHAR_OFFSET 0
32
33
3333ffbd 34#define FLAG_DELETE (1<<0)
4fe159a8 35#define SAME_MODE (1<<1)
dc5ddbcc 36#define SAME_RDEV (1<<2)
4fe159a8
AT
37#define SAME_UID (1<<3)
38#define SAME_GID (1<<4)
39#define SAME_DIR (1<<5)
40#define SAME_NAME SAME_DIR
41#define LONG_NAME (1<<6)
42#define SAME_TIME (1<<7)
43
c627d613 44/* update this if you make incompatible changes */
6ba9279f 45#define PROTOCOL_VERSION 17
3ec4dd97 46#define MIN_PROTOCOL_VERSION 11
6ba9279f 47#define MAX_PROTOCOL_VERSION 30
c627d613 48
9486289c
AT
49#define RSYNC_PORT 873
50
d867229b 51#define SPARSE_WRITE_SIZE (1024)
dc5ddbcc 52#define WRITE_SIZE (32*1024)
34ccb63e 53#define CHUNK_SIZE (32*1024)
d9bea2dd 54#define MAX_MAP_SIZE (4*1024*1024)
c627d613 55
f0fca04e
AT
56#define MAX_ARGS 100
57
58d433ab
AT
58#define BLOCKING_TIMEOUT 10
59
9486289c
AT
60#define FERROR 1
61#define FINFO 2
7bec6a5c 62
c627d613
AT
63#include "config.h"
64
24d95c03
AT
65#if HAVE_REMSH
66#define RSYNC_RSH "remsh"
67#else
68#define RSYNC_RSH "rsh"
69#endif
70
c627d613
AT
71#include <sys/types.h>
72#ifdef HAVE_UNISTD_H
73#include <unistd.h>
74#endif
75#include <stdio.h>
76
77#ifdef HAVE_SYS_PARAM_H
78#include <sys/param.h>
79#endif
80
d7b305fd
AT
81#ifdef HAVE_STDLIB_H
82#include <stdlib.h>
83#endif
84
fdd71e17
AT
85#ifdef HAVE_SYS_SOCKET_H
86#include <sys/socket.h>
87#endif
88
d7b305fd
AT
89#ifdef HAVE_STRING_H
90#include <string.h>
c627d613
AT
91#endif
92
93#ifdef HAVE_COMPAT_H
94#include <compat.h>
95#endif
96
97#ifdef HAVE_MALLOC_H
98#include <malloc.h>
99#endif
100
101#ifdef TIME_WITH_SYS_TIME
102#include <sys/time.h>
103#include <time.h>
104#else
105#ifdef HAVE_SYS_TIME_H
106#include <sys/time.h>
107#else
108#include <time.h>
109#endif
110#endif
111
112#ifdef HAVE_FCNTL_H
113#include <fcntl.h>
114#else
115#ifdef HAVE_SYS_FCNTL_H
116#include <sys/fcntl.h>
117#endif
118#endif
119
120#include <sys/stat.h>
121
94481d91
AT
122#ifdef HAVE_SYS_IOCTL_H
123#include <sys/ioctl.h>
124#endif
125
126#ifdef HAVE_SYS_FILIO_H
127#include <sys/filio.h>
128#endif
129
c627d613
AT
130#include <signal.h>
131#ifdef HAVE_SYS_WAIT_H
132#include <sys/wait.h>
133#endif
134#ifdef HAVE_CTYPE_H
135#include <ctype.h>
136#endif
137#ifdef HAVE_GRP_H
138#include <grp.h>
139#endif
140#include <errno.h>
141
7bec6a5c 142#ifdef HAVE_MMAP
c627d613 143#include <sys/mman.h>
7bec6a5c
AT
144#endif
145
c627d613
AT
146#ifdef HAVE_UTIME_H
147#include <utime.h>
148#endif
149
8bf73749
AT
150#ifdef HAVE_SYS_SELECT_H
151#include <sys/select.h>
152#endif
153
773f2bd4
AT
154#ifdef HAVE_SYS_MODE_H
155/* apparently AIX needs this for S_ISLNK */
05a6556d 156#ifndef S_ISLNK
773f2bd4
AT
157#include <sys/mode.h>
158#endif
05a6556d 159#endif
773f2bd4 160
c627d613
AT
161#ifdef HAVE_FNMATCH
162#include <fnmatch.h>
163#else
164#include "lib/fnmatch.h"
165#endif
166
167#ifdef HAVE_GETOPT_LONG
168#include <getopt.h>
169#else
170#include "lib/getopt.h"
171#endif
172
f6c34742
AT
173/* these are needed for the uid/gid mapping code */
174#include <pwd.h>
175#include <grp.h>
176
9486289c 177#include <stdarg.h>
f0fca04e
AT
178#include <netinet/in.h>
179#include <arpa/inet.h>
180#include <netdb.h>
9486289c 181
cbbe4892
AT
182#ifndef S_IFLNK
183#define S_IFLNK 0120000
184#endif
c627d613
AT
185
186#ifndef S_ISLNK
187#define S_ISLNK(mode) (((mode) & S_IFLNK) == S_IFLNK)
188#endif
189
f0fca04e
AT
190#define BOOL int
191
c627d613
AT
192#ifndef uchar
193#define uchar unsigned char
194#endif
195
debb4505
AT
196#if HAVE_UNSIGNED_CHAR
197#define schar signed char
198#else
199#define schar char
200#endif
201
c627d613
AT
202#ifndef int32
203#if (SIZEOF_INT == 4)
204#define int32 int
205#elif (SIZEOF_LONG == 4)
206#define int32 long
207#elif (SIZEOF_SHORT == 4)
208#define int32 short
209#endif
210#endif
211
212#ifndef uint32
213#define uint32 unsigned int32
214#endif
215
bcacc18b
AT
216#if HAVE_OFF64_T
217#define OFF_T off64_t
218#define STRUCT_STAT struct stat64
219#else
220#define OFF_T off_t
221#define STRUCT_STAT struct stat
222#endif
223
224#if HAVE_OFF64_T
225#define int64 off64_t
226#elif (SIZEOF_LONG == 8)
3bee6733
AT
227#define int64 long
228#elif (SIZEOF_INT == 8)
229#define int64 int
230#elif HAVE_LONGLONG
71c46176
AT
231#define int64 long long
232#else
233#define int64 off_t
3bee6733 234#define NO_INT64
71c46176 235#endif
c627d613
AT
236
237#ifndef MIN
238#define MIN(a,b) ((a)<(b)?(a):(b))
239#endif
240
241#ifndef MAX
242#define MAX(a,b) ((a)>(b)?(a):(b))
243#endif
244
245/* the length of the md4 checksum */
ebb0a6f6 246#define MD4_SUM_LENGTH 16
c627d613
AT
247#define SUM_LENGTH 16
248
249#ifndef MAXPATHLEN
250#define MAXPATHLEN 1024
251#endif
252
253struct file_struct {
3333ffbd 254 unsigned flags;
3ec4dd97 255 time_t modtime;
bcacc18b 256 OFF_T length;
3ec4dd97
AT
257 mode_t mode;
258 ino_t inode;
259 dev_t dev;
260 dev_t rdev;
261 uid_t uid;
262 gid_t gid;
263 char *basename;
264 char *dirname;
265 char *basedir;
266 char *link;
2d0bb8eb 267 char *sum;
c627d613
AT
268};
269
270struct file_list {
271 int count;
272 int malloced;
3ec4dd97 273 struct file_struct **files;
c627d613
AT
274};
275
276struct sum_buf {
bcacc18b 277 OFF_T offset; /* offset in file of this chunk */
c627d613
AT
278 int len; /* length of chunk of file */
279 int i; /* index of this chunk */
280 uint32 sum1; /* simple checksum */
ebb0a6f6 281 char sum2[SUM_LENGTH]; /* checksum */
c627d613
AT
282};
283
284struct sum_struct {
bcacc18b 285 OFF_T flength; /* total file length */
c627d613
AT
286 int count; /* how many chunks */
287 int remainder; /* flength % block_length */
288 int n; /* block_length */
289 struct sum_buf *sums; /* points to info for each chunk */
290};
291
c6e7fcb4 292struct map_struct {
0b910560
AT
293 char *map,*p;
294 int fd,p_size,p_len;
bcacc18b 295 OFF_T size, p_offset;
c6e7fcb4 296};
c627d613 297
3b3a2fbc
AT
298/* we need this function because of the silly way in which duplicate
299 entries are handled in the file lists - we can't change this
300 without breaking existing versions */
71c46176 301static inline int flist_up(struct file_list *flist, int i)
3b3a2fbc 302{
3ec4dd97 303 while (!flist->files[i]->basename) i++;
3b3a2fbc
AT
304 return i;
305}
306
d6e6ecbd
AT
307#if HAVE_DIRENT_H
308# include <dirent.h>
309#else
310# define dirent direct
311# if HAVE_SYS_NDIR_H
312# include <sys/ndir.h>
313# endif
314# if HAVE_SYS_DIR_H
315# include <sys/dir.h>
316# endif
317# if HAVE_NDIR_H
318# include <ndir.h>
319# endif
320#endif
3b3a2fbc 321
c627d613
AT
322#include "byteorder.h"
323#include "version.h"
324#include "proto.h"
325#include "md4.h"
326
327#if !HAVE_STRERROR
328extern char *sys_errlist[];
329#define strerror(i) sys_errlist[i]
330#endif
331
332#ifndef HAVE_STRCHR
333# define strchr index
334# define strrchr rindex
335#endif
336
c627d613
AT
337#ifndef HAVE_ERRNO_DECL
338extern int errno;
339#endif
340
341#ifndef HAVE_BCOPY
342#define bcopy(src,dest,n) memcpy(dest,src,n)
343#endif
344
345#ifndef HAVE_BZERO
346#define bzero(buf,n) memset(buf,0,n)
347#endif
348
cbbe4892 349#define SUPPORT_LINKS HAVE_READLINK
dc5ddbcc 350#define SUPPORT_HARD_LINKS HAVE_LINK
c627d613 351
8bf73749
AT
352#ifndef HAVE_LCHOWN
353#define lchown chown
354#endif
355
ac1eb754 356#define SIGNAL_CAST (RETSIGTYPE (*)())
720b47f2
AT
357
358#ifndef EWOULDBLOCK
359#define EWOULDBLOCK EAGAIN
360#endif
182dca5c 361
7b8356d0
AT
362#ifndef STDIN_FILENO
363#define STDIN_FILENO 0
364#endif
365
366#ifndef STDOUT_FILENO
367#define STDOUT_FILENO 1
368#endif
369
370#ifndef STDERR_FILENO
371#define STDERR_FILENO 2
372#endif
373
374#ifndef S_IWUSR
375#define S_IWUSR 0200
376#endif
377
1e9f155a
AT
378#ifndef S_ISBLK
379#define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
380#endif
381
382#ifndef S_ISCHR
383#define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
384#endif
385
a0b65b18
AT
386#ifndef S_ISSOCK
387#ifdef _S_IFSOCK
388#define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
389#else
390#define S_ISSOCK(mode) (0)
391#endif
392#endif
393
394#ifndef S_ISFIFO
395#ifdef _S_IFIFO
396#define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
397#else
398#define S_ISFIFO(mode) (0)
399#endif
400#endif
401
1e9f155a
AT
402#ifndef S_ISDIR
403#define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
404#endif
405
406#ifndef S_ISREG
407#define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
408#endif
409
a0b65b18
AT
410
411#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) || S_ISFIFO(mode))
7bec6a5c 412