2 * Copyright (C) 1996, 2000 Andrew Tridgell
3 * Copyright (C) 1996 Paul Mackerras
4 * Copyright (C) 2001, 2002 Martin Pool <mbp@samba.org>
5 * Copyright (C) 2003-2022 Wayne Davison
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, visit the http://fsf.org website.
23 #define Unset (-1) /* Our BOOL values are always an int. */
25 #define BLOCK_SIZE 700
26 #define RSYNC_RSH_ENV "RSYNC_RSH"
27 #define RSYNC_RSH_IO_ENV "RSYNC_RSH_IO"
29 #define RSYNC_NAME "rsync"
30 /* RSYNCD_SYSCONF is now set in config.h */
31 #define RSYNCD_USERCONF "rsyncd.conf"
33 #define DEFAULT_LOCK_FILE "/var/run/rsyncd.lock"
34 #define URL_PREFIX "rsync://"
36 #define SYMLINK_PREFIX "/rsyncd-munged/" /* This MUST have a trailing slash! */
37 #define SYMLINK_PREFIX_LEN ((int)sizeof SYMLINK_PREFIX - 1)
39 #define BACKUP_SUFFIX "~"
41 /* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is
42 incompatible with older versions :-( */
45 /* These flags are only used during the flist transfer. */
47 #define XMIT_TOP_DIR (1<<0)
48 #define XMIT_SAME_MODE (1<<1)
49 #define XMIT_SAME_RDEV_pre28 (1<<2) /* protocols 20 - 27 */
50 #define XMIT_EXTENDED_FLAGS (1<<2) /* protocols 28 - now */
51 #define XMIT_SAME_UID (1<<3)
52 #define XMIT_SAME_GID (1<<4)
53 #define XMIT_SAME_NAME (1<<5)
54 #define XMIT_LONG_NAME (1<<6)
55 #define XMIT_SAME_TIME (1<<7)
57 #define XMIT_SAME_RDEV_MAJOR (1<<8) /* protocols 28 - now (devices only) */
58 #define XMIT_NO_CONTENT_DIR (1<<8) /* protocols 30 - now (dirs only) */
59 #define XMIT_HLINKED (1<<9) /* protocols 28 - now (non-dirs) */
60 #define XMIT_SAME_DEV_pre30 (1<<10) /* protocols 28 - 29 */
61 #define XMIT_USER_NAME_FOLLOWS (1<<10) /* protocols 30 - now */
62 #define XMIT_RDEV_MINOR_8_pre30 (1<<11) /* protocols 28 - 29 */
63 #define XMIT_GROUP_NAME_FOLLOWS (1<<11) /* protocols 30 - now */
64 #define XMIT_HLINK_FIRST (1<<12) /* protocols 30 - now (HLINKED files only) */
65 #define XMIT_IO_ERROR_ENDLIST (1<<12) /* protocols 31*- now (w/XMIT_EXTENDED_FLAGS) (also protocol 30 w/'f' compat flag) */
66 #define XMIT_MOD_NSEC (1<<13) /* protocols 31 - now */
67 #define XMIT_SAME_ATIME (1<<14) /* any protocol - restricted by command-line option */
68 #define XMIT_UNUSED_15 (1<<15) /* unused flag bit */
70 /* The following XMIT flags require an rsync that uses a varint for the flag values */
72 #define XMIT_RESERVED_16 (1<<16) /* reserved for future fileflags use */
73 #define XMIT_CRTIME_EQ_MTIME (1<<17) /* any protocol - restricted by command-line option */
75 /* These flags are used in the live flist data. */
77 #define FLAG_TOP_DIR (1<<0) /* sender/receiver/generator */
78 #define FLAG_OWNED_BY_US (1<<0) /* generator: set by make_file() for aux flists only */
79 #define FLAG_FILE_SENT (1<<1) /* sender/receiver/generator */
80 #define FLAG_DIR_CREATED (1<<1) /* generator */
81 #define FLAG_CONTENT_DIR (1<<2) /* sender/receiver/generator */
82 #define FLAG_MOUNT_DIR (1<<3) /* sender/generator (dirs only) */
83 #define FLAG_SKIP_HLINK (1<<3) /* receiver/generator (w/FLAG_HLINKED) */
84 #define FLAG_DUPLICATE (1<<4) /* sender */
85 #define FLAG_MISSING_DIR (1<<4) /* generator */
86 #define FLAG_HLINKED (1<<5) /* receiver/generator (checked on all types) */
87 #define FLAG_HLINK_FIRST (1<<6) /* receiver/generator (w/FLAG_HLINKED) */
88 #define FLAG_IMPLIED_DIR (1<<6) /* sender/receiver/generator (dirs only) */
89 #define FLAG_HLINK_LAST (1<<7) /* receiver/generator */
90 #define FLAG_HLINK_DONE (1<<8) /* receiver/generator (checked on all types) */
91 #define FLAG_LENGTH64 (1<<9) /* sender/receiver/generator */
92 #define FLAG_SKIP_GROUP (1<<10) /* receiver/generator */
93 #define FLAG_TIME_FAILED (1<<11)/* generator */
94 #define FLAG_MOD_NSEC (1<<12) /* sender/receiver/generator */
96 /* These flags are passed to functions but not stored. */
98 #define FLAG_DIVERT_DIRS (1<<16) /* sender, but must be unique */
99 #define FLAG_PERHAPS_DIR (1<<17) /* generator */
101 /* These flags are for get_dirlist(). */
102 #define GDL_IGNORE_FILTER_RULES (1<<0)
103 #define GDL_PERHAPS_DIR (1<<1)
105 /* Some helper macros for matching bits. */
106 #define BITS_SET(val,bits) (((val) & (bits)) == (bits))
107 #define BITS_SETnUNSET(val,onbits,offbits) (((val) & ((onbits)|(offbits))) == (onbits))
108 #define BITS_EQUAL(b1,b2,mask) (((unsigned)(b1) & (unsigned)(mask)) \
109 == ((unsigned)(b2) & (unsigned)(mask)))
111 /* Update this if you make incompatible changes and ALSO update the
112 * SUBPROTOCOL_VERSION if it is not a final (official) release. */
113 #define PROTOCOL_VERSION 31
115 /* This is used when working on a new protocol version or for any unofficial
116 * protocol tweaks. It should be a non-zero value for each pre-release repo
117 * change that affects the protocol. The official pre-release versions should
118 * start with 1 (after incrementing the PROTOCOL_VERSION) and go up by 1 for
119 * each new protocol change. For unofficial changes, pick a fairly large
120 * random number that will hopefully not collide with anyone else's unofficial
121 * protocol. It must ALWAYS be 0 when the protocol goes final (and official)
122 * and NEVER before! When rsync negotiates a protocol match, it will only
123 * allow the newest protocol to be used if the SUBPROTOCOL_VERSION matches.
124 * All older protocol versions MUST be compatible with the final, official
125 * release of the protocol, so don't tweak the code to change the protocol
126 * behavior for an older protocol version. */
127 #define SUBPROTOCOL_VERSION 0
129 /* We refuse to interoperate with versions that are not in this range.
130 * Note that we assume we'll work with later versions: the onus is on
131 * people writing them to make sure that they don't send us anything
132 * we won't understand.
134 * Interoperation with old but supported protocol versions
135 * should cause a warning to be printed. At a future date
136 * the old protocol will become the minimum and
137 * compatibility code removed.
139 * There are two possible explanations for the limit at
140 * MAX_PROTOCOL_VERSION: either to allow new major-rev versions that
141 * do not interoperate with us, and (more likely) so that we can
142 * detect an attempt to connect rsync to a non-rsync server, which is
143 * unlikely to begin by sending a byte between MIN_PROTOCL_VERSION and
144 * MAX_PROTOCOL_VERSION. */
146 #define MIN_PROTOCOL_VERSION 20
147 #define OLD_PROTOCOL_VERSION 25
148 #define MAX_PROTOCOL_VERSION 40
150 #define MIN_FILECNT_LOOKAHEAD 1000
151 #define MAX_FILECNT_LOOKAHEAD 10000
153 #define RSYNC_PORT 873
155 #define SPARSE_WRITE_SIZE (1024)
156 #define WRITE_SIZE (32*1024)
157 #define CHUNK_SIZE (32*1024)
158 #define MAX_MAP_SIZE (256*1024)
159 #define IO_BUFFER_SIZE (32*1024)
160 #define MAX_BLOCK_SIZE ((int32)1 << 17)
162 /* For compatibility with older rsyncs */
163 #define OLD_MAX_BLOCK_SIZE ((int32)1 << 29)
165 #define ROUND_UP_1024(siz) ((siz) & (1024-1) ? ((siz) | (1024-1)) + 1 : (siz))
167 #define IOERR_GENERAL (1<<0) /* For backward compatibility, this must == 1 */
168 #define IOERR_VANISHED (1<<1)
169 #define IOERR_DEL_LIMIT (1<<2)
171 #define MAX_ARGS 1000
172 #define MAX_BASIS_DIRS 20
173 #define MAX_SERVER_ARGS (MAX_BASIS_DIRS*2 + 100)
175 #define COMPARE_DEST 1
182 #define SERVER_FILTERS 1
183 #define ALL_FILTERS 2
185 #define XFLG_FATAL_ERRORS (1<<0)
186 #define XFLG_OLD_PREFIXES (1<<1)
187 #define XFLG_ANCHORED2ABS (1<<2) /* leading slash indicates absolute */
188 #define XFLG_ABS_IF_SLASH (1<<3) /* leading or interior slash is absolute */
189 #define XFLG_DIR2WILD3 (1<<4) /* dir/ match gets trailing *** added */
191 #define ATTRS_REPORT (1<<0)
192 #define ATTRS_SKIP_MTIME (1<<1)
193 #define ATTRS_ACCURATE_TIME (1<<2)
194 #define ATTRS_SKIP_ATIME (1<<3)
195 #define ATTRS_SKIP_CRTIME (1<<5)
199 #define NORMAL_FLUSH 0
201 #define PDIR_CREATE 1
202 #define PDIR_DELETE 0
204 /* Note: 0x00 - 0x7F are used for basis_dir[] indexes! */
205 #define FNAMECMP_BASIS_DIR_LOW 0x00 /* Must remain 0! */
206 #define FNAMECMP_BASIS_DIR_HIGH 0x7F
207 #define FNAMECMP_FNAME 0x80
208 #define FNAMECMP_PARTIAL_DIR 0x81
209 #define FNAMECMP_BACKUP 0x82
210 #define FNAMECMP_FUZZY 0x83
212 /* For use by the itemize_changes code */
213 #define ITEM_REPORT_ATIME (1<<0)
214 #define ITEM_REPORT_CHANGE (1<<1)
215 #define ITEM_REPORT_SIZE (1<<2) /* regular files only */
216 #define ITEM_REPORT_TIMEFAIL (1<<2) /* symlinks only */
217 #define ITEM_REPORT_TIME (1<<3)
218 #define ITEM_REPORT_PERMS (1<<4)
219 #define ITEM_REPORT_OWNER (1<<5)
220 #define ITEM_REPORT_GROUP (1<<6)
221 #define ITEM_REPORT_ACL (1<<7)
222 #define ITEM_REPORT_XATTR (1<<8)
223 #define ITEM_REPORT_CRTIME (1<<10)
224 #define ITEM_BASIS_TYPE_FOLLOWS (1<<11)
225 #define ITEM_XNAME_FOLLOWS (1<<12)
226 #define ITEM_IS_NEW (1<<13)
227 #define ITEM_LOCAL_CHANGE (1<<14)
228 #define ITEM_TRANSFER (1<<15)
229 /* These are outside the range of the transmitted flags. */
230 #define ITEM_MISSING_DATA (1<<16) /* used by log_formatted() */
231 #define ITEM_DELETED (1<<17) /* used by log_formatted() */
232 #define ITEM_MATCHED (1<<18) /* used by itemize() */
234 #define SIGNIFICANT_ITEM_FLAGS (~(\
235 ITEM_BASIS_TYPE_FOLLOWS | ITEM_XNAME_FOLLOWS | ITEM_LOCAL_CHANGE))
237 #define CFN_KEEP_DOT_DIRS (1<<0)
238 #define CFN_KEEP_TRAILING_SLASH (1<<1)
239 #define CFN_DROP_TRAILING_DOT_DIR (1<<2)
240 #define CFN_COLLAPSE_DOT_DOT_DIRS (1<<3)
241 #define CFN_REFUSE_DOT_DOT_DIRS (1<<4)
244 #define SP_KEEP_DOT_DIRS (1<<0)
247 #define CD_SKIP_CHDIR 1
249 /* Log-message categories. FLOG only goes to the log file, not the client;
250 * FCLIENT is the opposite. */
252 FNONE
=0, /* never sent */
253 FERROR_XFER
=1, FINFO
=2, /* sent over socket for any protocol */
254 FERROR
=3, FWARNING
=4, /* sent over socket for protocols >= 30 */
255 FERROR_SOCKET
=5, FLOG
=6, /* only sent via receiver -> generator pipe */
256 FERROR_UTF8
=8, /* only sent via receiver -> generator pipe */
257 FCLIENT
=7 /* never transmitted (e.g. server converts to FINFO) */
260 /* Messages types that are sent over the message channel. The logcode
261 * values must all be present here with identical numbers. */
263 MSG_DATA
=0, /* raw data on the multiplexed stream */
264 MSG_ERROR_XFER
=FERROR_XFER
, MSG_INFO
=FINFO
, /* remote logging */
265 MSG_ERROR
=FERROR
, MSG_WARNING
=FWARNING
, /* protocol-30 remote logging */
266 MSG_ERROR_SOCKET
=FERROR_SOCKET
, /* sibling logging */
267 MSG_ERROR_UTF8
=FERROR_UTF8
, /* sibling logging */
268 MSG_LOG
=FLOG
, MSG_CLIENT
=FCLIENT
, /* sibling logging */
269 MSG_REDO
=9, /* reprocess indicated flist index */
270 MSG_STATS
=10, /* message has stats data for generator */
271 MSG_IO_ERROR
=22,/* the sending side had an I/O error */
272 MSG_IO_TIMEOUT
=33,/* tell client about a daemon's timeout value */
273 MSG_NOOP
=42, /* a do-nothing message (legacy protocol-30 only) */
274 MSG_ERROR_EXIT
=86, /* synchronize an error exit (siblings and protocol >= 31) */
275 MSG_SUCCESS
=100,/* successfully updated indicated flist index */
276 MSG_DELETED
=101,/* successfully deleted a file on receiving side */
277 MSG_NO_SEND
=102,/* sender failed to open a file we wanted */
281 FT_UNSUPPORTED
, FT_REG
, FT_DIR
, FT_SYMLINK
, FT_SPECIAL
, FT_DEVICE
285 #define NDX_FLIST_EOF -2
286 #define NDX_DEL_STATS -3
287 #define NDX_FLIST_OFFSET -101
289 /* For calling delete_item() and delete_dir_contents(). */
290 #define DEL_NO_UID_WRITE (1<<0) /* file/dir has our uid w/o write perm */
291 #define DEL_RECURSE (1<<1) /* if dir, delete all contents */
292 #define DEL_DIR_IS_EMPTY (1<<2) /* internal delete_FUNCTIONS use only */
293 #define DEL_FOR_FILE (1<<3) /* making room for a replacement file */
294 #define DEL_FOR_DIR (1<<4) /* making room for a replacement dir */
295 #define DEL_FOR_SYMLINK (1<<5) /* making room for a replacement symlink */
296 #define DEL_FOR_DEVICE (1<<6) /* making room for a replacement device */
297 #define DEL_FOR_SPECIAL (1<<7) /* making room for a replacement special */
298 #define DEL_FOR_BACKUP (1<<8) /* the delete is for a backup operation */
300 #define DEL_MAKE_ROOM (DEL_FOR_FILE|DEL_FOR_DIR|DEL_FOR_SYMLINK|DEL_FOR_DEVICE|DEL_FOR_SPECIAL)
303 DR_SUCCESS
= 0, DR_FAILURE
, DR_AT_LIMIT
, DR_NOT_EMPTY
306 /* Defines for make_path() */
307 #define MKP_DROP_NAME (1<<0) /* drop trailing filename or trailing slash */
308 #define MKP_SKIP_SLASH (1<<1) /* skip one or more leading slashes */
310 /* Defines for maybe_send_keepalive() */
311 #define MSK_ALLOW_FLUSH (1<<0)
312 #define MSK_ACTIVE_RECEIVER (1<<1)
318 /* The default RSYNC_RSH is always set in config.h. */
321 #ifdef HAVE_SYS_TYPES_H
322 # include <sys/types.h>
324 #ifdef HAVE_SYS_STAT_H
325 # include <sys/stat.h>
331 # ifdef HAVE_STDLIB_H
336 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
341 #ifdef HAVE_BSD_STRING_H
342 # include <bsd/string.h>
344 #ifdef HAVE_STRINGS_H
345 # include <strings.h>
347 #ifdef HAVE_INTTYPES_H
348 # include <inttypes.h>
357 #ifdef HAVE_SYS_PARAM_H
358 #include <sys/param.h>
361 #if defined HAVE_MALLOC_H && (defined HAVE_MALLINFO || !defined HAVE_STDLIB_H)
365 #ifdef HAVE_SYS_SOCKET_H
366 #include <sys/socket.h>
369 #ifdef HAVE_SYS_TIME_H
370 #include <sys/time.h>
377 #ifdef HAVE_SYS_FCNTL_H
378 #include <sys/fcntl.h>
382 #ifdef HAVE_SYS_IOCTL_H
383 #include <sys/ioctl.h>
386 #ifdef HAVE_SYS_FILIO_H
387 #include <sys/filio.h>
391 #ifdef HAVE_SYS_WAIT_H
392 #include <sys/wait.h>
406 #if defined HAVE_UTIMENSAT || defined HAVE_LUTIMES || defined HAVE_SETATTRLIST
407 #define CAN_SET_SYMLINK_TIMES 1
410 #if defined HAVE_LCHOWN || defined CHOWN_MODIFIES_SYMLINK
411 #define CAN_CHOWN_SYMLINK 1
414 #if defined HAVE_LCHMOD || defined HAVE_SETATTRLIST
415 #define CAN_CHMOD_SYMLINK 1
418 #if defined HAVE_UTIMENSAT || defined HAVE_SETATTRLIST
419 #define CAN_SET_NSEC 1
423 #ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
424 #define ST_MTIME_NSEC st_mtim.tv_nsec
425 #define ST_ATIME_NSEC st_atim.tv_nsec
426 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
427 #define ST_MTIME_NSEC st_mtimensec
428 #define ST_ATIME_NSEC st_atimensec
429 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
430 #define ST_MTIME_NSEC st_mtimespec.tv_nsec
431 #define ST_ATIME_NSEC st_atimespec.tv_nsec
435 #ifdef HAVE_SYS_SELECT_H
436 #include <sys/select.h>
439 #ifdef HAVE_SYS_MODE_H
440 /* apparently AIX needs this for S_ISLNK */
442 #include <sys/mode.h>
446 /* these are needed for the uid/gid mapping code */
451 #include <netinet/in.h>
452 #include <arpa/inet.h>
457 #ifdef HAVE_SYS_FILE_H
458 #include <sys/file.h>
464 # define dirent direct
465 # ifdef HAVE_SYS_NDIR_H
466 # include <sys/ndir.h>
468 # ifdef HAVE_SYS_DIR_H
469 # include <sys/dir.h>
476 #ifdef MAJOR_IN_MKDEV
477 #include <sys/mkdev.h>
478 # if !defined makedev && (defined mkdev || defined _WIN32 || defined __WIN32__)
479 # define makedev mkdev
481 #elif defined MAJOR_IN_SYSMACROS
482 #include <sys/sysmacros.h>
485 #ifdef MAKEDEV_TAKES_3_ARGS
486 #define MAKEDEV(devmajor,devminor) makedev(0,devmajor,devminor)
489 #define MAKEDEV(devmajor,devminor) makedev(devmajor,devminor)
491 # define major DEV_TO_MAJOR
492 # define minor DEV_TO_MINOR
493 # define MAKEDEV MAJORMINOR_TO_DEV
498 # include <floss.h(floss_read,floss_write,floss_fork,floss_execvp)>
499 # include <floss.h(floss_getpwuid,floss_select,floss_seteuid)>
500 # define S_IEXEC S_IXUSR
501 # define ROOT_UID 65535
514 #if defined USE_ICONV_OPEN && defined HAVE_ICONV_H
534 #include "lib/pool_alloc.h"
537 typedef unsigned int id_t
;
543 typedef unsigned int mode_t
;
548 #define SIZEOF_OFF_T SIZEOF_LONG
551 typedef unsigned int size_t;
557 #define uchar unsigned char
560 #ifdef SIGNED_CHAR_OK
561 #define schar signed char
567 #if SIZEOF_INT16_T == 2
568 # define int16 int16_t
575 #if SIZEOF_UINT16_T == 2
576 # define uint16 uint16_t
578 # define uint16 unsigned int16
582 #if !defined __APPLE__ || defined HAVE_GETATTRLIST
583 #define SUPPORT_ATIMES 1
586 #if defined HAVE_GETATTRLIST || defined __CYGWIN__
587 #define SUPPORT_CRTIMES 1
590 /* Find a variable that is either exactly 32-bits or longer.
591 * If some code depends on 32-bit truncation, it will need to
592 * take special action in a "#if SIZEOF_INT32 > 4" section. */
594 #if SIZEOF_INT32_T == 4
595 # define int32 int32_t
596 # define SIZEOF_INT32 4
597 #elif SIZEOF_INT == 4
599 # define SIZEOF_INT32 4
600 #elif SIZEOF_LONG == 4
602 # define SIZEOF_INT32 4
603 #elif SIZEOF_SHORT == 4
605 # define SIZEOF_INT32 4
608 # define SIZEOF_INT32 SIZEOF_INT
609 #elif SIZEOF_LONG > 4
611 # define SIZEOF_INT32 SIZEOF_LONG
613 # error Could not find a 32-bit integer variable
616 # define SIZEOF_INT32 4
620 #if SIZEOF_UINT32_T == 4
621 # define uint32 uint32_t
623 # define uint32 unsigned int32
627 #if SIZEOF_OFF_T == 8 || !SIZEOF_OFF64_T || !defined HAVE_STRUCT_STAT64
629 #define STRUCT_STAT struct stat
630 #define SIZEOF_CAPITAL_OFF_T SIZEOF_OFF_T
632 #define OFF_T off64_t
633 #define STRUCT_STAT struct stat64
634 #define USE_STAT64_FUNCS 1
635 #define SIZEOF_CAPITAL_OFF_T SIZEOF_OFF64_T
638 /* CAVEAT: on some systems, int64 will really be a 32-bit integer IFF
639 * that's the maximum size the file system can handle and there is no
640 * 64-bit type available. The rsync source must therefore take steps
641 * to ensure that any code that really requires a 64-bit integer has
642 * it (e.g. the checksum code uses two 32-bit integers for its 64-bit
644 #if SIZEOF_INT64_T == 8
645 # define int64 int64_t
646 # define SIZEOF_INT64 8
647 #elif SIZEOF_LONG == 8
649 # define SIZEOF_INT64 8
650 #elif SIZEOF_INT == 8
652 # define SIZEOF_INT64 8
653 #elif SIZEOF_LONG_LONG == 8
654 # define int64 long long
655 # define SIZEOF_INT64 8
656 #elif SIZEOF_OFF64_T == 8
657 # define int64 off64_t
658 # define SIZEOF_INT64 8
659 #elif SIZEOF_OFF_T == 8
661 # define SIZEOF_INT64 8
664 # define SIZEOF_INT64 SIZEOF_INT
665 #elif SIZEOF_LONG > 8
667 # define SIZEOF_INT64 SIZEOF_LONG
668 #elif SIZEOF_LONG_LONG > 8
669 # define int64 long long
670 # define SIZEOF_INT64 SIZEOF_LONG_LONG
672 /* As long as it gets... */
674 # define SIZEOF_INT64 SIZEOF_OFF_T
687 struct ht_int32_node
{
692 struct ht_int64_node
{
697 #define HT_NODE(tbl, bkts, i) ((void*)((char*)(bkts) + (i)*(tbl)->node_size))
698 #define HT_KEY(node, k64) ((k64)? ((struct ht_int64_node*)(node))->key \
699 : (int64)((struct ht_int32_node*)(node))->key)
702 #define MIN(a,b) ((a)<(b)?(a):(b))
706 #define MAX(a,b) ((a)>(b)?(a):(b))
709 #ifndef MAXHOSTNAMELEN
710 #define MAXHOSTNAMELEN 256
713 #define SUM_LENGTH 16
714 #define SHORT_SUM_LENGTH 2
715 #define BLOCKSUM_BIAS 10
718 #define MAXPATHLEN 1024
721 /* We want a roomy line buffer that can hold more than MAXPATHLEN,
722 * and significantly more than an overly short MAXPATHLEN. */
723 #if MAXPATHLEN < 4096
724 #define BIGPATHBUFLEN (4096+1024)
726 #define BIGPATHBUFLEN (MAXPATHLEN+1024)
734 #define SIZE_MAX ((size_t)-1)
738 #define INADDR_NONE 0xffffffff
741 #ifndef IN_LOOPBACKNET
742 #define IN_LOOPBACKNET 127
745 #if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
746 #define ACLS_NEED_MASK 1
749 #if defined HAVE_FALLOCATE || HAVE_SYS_FALLOCATE
750 #ifdef HAVE_LINUX_FALLOC_H
751 #include <linux/falloc.h>
753 #ifdef FALLOC_FL_KEEP_SIZE
754 #define SUPPORT_PREALLOCATION 1
755 #elif defined HAVE_FTRUNCATE
756 #define SUPPORT_PREALLOCATION 1
757 #define PREALLOCATE_NEEDS_TRUNCATE 1
759 #else /* !fallocate */
760 #if defined HAVE_EFFICIENT_POSIX_FALLOCATE && defined HAVE_FTRUNCATE
761 #define SUPPORT_PREALLOCATION 1
762 #define PREALLOCATE_NEEDS_TRUNCATE 1
766 #if SIZEOF_CHARP == 4
767 # define PTRS_ARE_32 1
768 # define PTR_EXTRA_CNT 1
769 #elif SIZEOF_CHARP == 8
770 # define PTRS_ARE_64 1
771 # define PTR_EXTRA_CNT EXTRA64_CNT
773 # error Character pointers are not 4 or 8 bytes.
776 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
777 #define USE_FLEXIBLE_ARRAY 1
778 #define SIZE_T_FMT_MOD "z" /* printf supports %zd */
779 #define SIZE_T_FMT_CAST size_t
781 #define SIZE_T_FMT_MOD "l" /* printf supports %ld */
782 #define SIZE_T_FMT_CAST long
793 union file_extras64
{
801 const char *dirname
; /* The dir info inside the transfer */
802 time_t modtime
; /* When the item was last modified */
803 uint32 len32
; /* Lowest 32 bits of the file's length */
804 uint16 mode
; /* The item's type and permissions */
805 uint16 flags
; /* The FLAG_* bits for this item */
806 #ifdef USE_FLEXIBLE_ARRAY
807 const char basename
[]; /* The basename (AKA filename) follows */
809 const char basename
[1]; /* A kluge that should work like a flexible array */
813 extern int file_extra_cnt
;
814 extern int inc_recurse
;
815 extern int atimes_ndx
;
816 extern int crtimes_ndx
;
817 extern int pathname_ndx
;
818 extern int depth_ndx
;
822 extern int xattrs_ndx
;
823 extern int file_sum_extra_cnt
;
825 #ifdef USE_FLEXIBLE_ARRAY
826 #define FILE_STRUCT_LEN (sizeof (struct file_struct))
828 #define FILE_STRUCT_LEN (offsetof(struct file_struct, basename))
830 #define EXTRA_LEN (sizeof (union file_extras))
831 #define DEV_EXTRA_CNT 2
832 #define DIRNODE_EXTRA_CNT 3
833 #define EXTRA64_CNT ((sizeof (union file_extras64) + EXTRA_LEN - 1) / EXTRA_LEN)
834 #define SUM_EXTRA_CNT file_sum_extra_cnt
836 #define REQ_EXTRA(f,ndx) ((union file_extras*)(f) - (ndx))
837 #define OPT_EXTRA(f,bump) ((union file_extras*)(f) - file_extra_cnt - 1 - (bump))
839 /* These are guaranteed to be allocated first in the array so that they
840 * are aligned for direct int64-pointer access. */
841 #define REQ_EXTRA64(f,ndx) ((union file_extras64*)REQ_EXTRA(f,ndx))
843 #define NSEC_BUMP(f) ((f)->flags & FLAG_MOD_NSEC ? 1 : 0)
844 #define LEN64_BUMP(f) ((f)->flags & FLAG_LENGTH64 ? 1 : 0)
845 #define START_BUMP(f) (NSEC_BUMP(f) + LEN64_BUMP(f))
846 #define HLINK_BUMP(f) ((f)->flags & (FLAG_HLINKED|FLAG_HLINK_DONE) ? inc_recurse+1 : 0)
847 #define ACL_BUMP(f) (acls_ndx ? 1 : 0)
849 /* The length applies to all items. */
851 #define F_LENGTH(f) ((int64)(f)->len32)
853 #define F_HIGH_LEN(f) (OPT_EXTRA(f, NSEC_BUMP(f))->unum)
854 #define F_LENGTH(f) ((int64)(f)->len32 + ((f)->flags & FLAG_LENGTH64 ? (int64)F_HIGH_LEN(f) << 32 : 0))
857 #define F_MOD_NSEC(f) OPT_EXTRA(f, 0)->unum
858 #define F_MOD_NSEC_or_0(f) ((f)->flags & FLAG_MOD_NSEC ? F_MOD_NSEC(f) : 0)
860 /* If there is a symlink string, it is always right after the basename */
861 #define F_SYMLINK(f) ((f)->basename + strlen((f)->basename) + 1)
863 /* The sending side always has this available: */
865 #define F_PATHNAME(f) REQ_EXTRA(f, pathname_ndx)->ptr
867 #define F_PATHNAME(f) REQ_EXTRA64(f, pathname_ndx)->ptr
870 /* The receiving side always has this available: */
871 #define F_DEPTH(f) REQ_EXTRA(f, depth_ndx)->num
873 /* When the associated option is on, all entries will have these present: */
874 #define F_OWNER(f) REQ_EXTRA(f, uid_ndx)->unum
875 #define F_GROUP(f) REQ_EXTRA(f, gid_ndx)->unum
876 #define F_ACL(f) REQ_EXTRA(f, acls_ndx)->num
877 #define F_XATTR(f) REQ_EXTRA(f, xattrs_ndx)->num
878 #define F_NDX(f) REQ_EXTRA(f, unsort_ndx)->num
879 #define F_ATIME(f) REQ_EXTRA64(f, atimes_ndx)->num
880 #define F_CRTIME(f) REQ_EXTRA64(f, crtimes_ndx)->num
882 /* These items are per-entry optional: */
883 #define F_HL_GNUM(f) OPT_EXTRA(f, START_BUMP(f))->num /* non-dirs */
884 #define F_HL_PREV(f) OPT_EXTRA(f, START_BUMP(f)+inc_recurse)->num /* non-dirs */
885 #define F_DIR_NODE_P(f) (&OPT_EXTRA(f, START_BUMP(f) \
886 + DIRNODE_EXTRA_CNT - 1)->num) /* sender dirs */
887 #define F_DIR_RELNAMES_P(f) (&OPT_EXTRA(f, START_BUMP(f) + DIRNODE_EXTRA_CNT \
888 + PTR_EXTRA_CNT - 1)->num) /* sender dirs */
889 #define F_DIR_DEFACL(f) OPT_EXTRA(f, START_BUMP(f))->unum /* receiver dirs */
890 #define F_DIR_DEV_P(f) (&OPT_EXTRA(f, START_BUMP(f) + ACL_BUMP(f) \
891 + DEV_EXTRA_CNT - 1)->unum) /* receiver dirs */
893 /* This optional item might follow an F_HL_*() item. */
894 #define F_RDEV_P(f) (&OPT_EXTRA(f, START_BUMP(f) + HLINK_BUMP(f) + DEV_EXTRA_CNT - 1)->unum)
896 /* The sum is only present on regular files. */
897 #define F_SUM(f) ((char*)OPT_EXTRA(f, START_BUMP(f) + HLINK_BUMP(f) \
898 + SUM_EXTRA_CNT - 1))
900 /* Some utility defines: */
901 #define F_IS_ACTIVE(f) (f)->basename[0]
902 #define F_IS_HLINKED(f) ((f)->flags & FLAG_HLINKED)
904 #define F_HLINK_NOT_FIRST(f) BITS_SETnUNSET((f)->flags, FLAG_HLINKED, FLAG_HLINK_FIRST)
905 #define F_HLINK_NOT_LAST(f) BITS_SETnUNSET((f)->flags, FLAG_HLINKED, FLAG_HLINK_LAST)
907 /* These access the F_DIR_DEV_P() and F_RDEV_P() values: */
908 #define DEV_MAJOR(a) (a)[0]
909 #define DEV_MINOR(a) (a)[1]
911 /* These access the F_DIRS_NODE_P() values: */
912 #define DIR_PARENT(a) (a)[0]
913 #define DIR_FIRST_CHILD(a) (a)[1]
914 #define DIR_NEXT_SIBLING(a) (a)[2]
916 #define IS_MISSING_FILE(statbuf) ((statbuf).st_mode == 0)
919 * Start the flist array at FLIST_START entries and grow it
920 * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
922 #define FLIST_START (32)
923 #define FLIST_START_LARGE (32 * 1024)
924 #define FLIST_LINEAR (FLIST_START_LARGE * 512)
927 * Extent size for allocation pools: A minimum size of 128KB
928 * is needed to mmap them so that freeing will release the
931 * Larger sizes reduce leftover fragments and speed free calls
932 * (when they happen). Smaller sizes increase the chance of
933 * freed allocations freeing whole extents.
935 #define NORMAL_EXTENT (256 * 1024)
936 #define SMALL_EXTENT (128 * 1024)
938 #define FLIST_TEMP (1<<1)
941 struct file_list
*next
, *prev
;
942 struct file_struct
**files
, **sorted
;
943 alloc_pool_t file_pool
;
946 int low
, high
; /* 0-relative index values excluding empties */
947 int ndx_start
; /* the start offset for inc_recurse mode */
948 int flist_num
; /* 1-relative file_list number or 0 */
949 int parent_ndx
; /* dir_flist index of parent directory */
950 int in_progress
, to_redo
;
953 #define SUMFLG_SAME_OFFSET (1<<0)
956 OFF_T offset
; /**< offset in file of this chunk */
957 int32 len
; /**< length of chunk of file */
958 uint32 sum1
; /**< simple checksum */
959 int32 chain
; /**< next hash-table collision */
960 short flags
; /**< flag bits */
964 OFF_T flength
; /**< total file length */
965 struct sum_buf
*sums
; /**< points to info for each chunk */
966 char *sum2_array
; /**< checksums of length xfer_sum_len */
967 int32 count
; /**< how many chunks */
968 int32 blength
; /**< block_length */
969 int32 remainder
; /**< flength % block_length */
970 int s2length
; /**< sum2_length */
974 OFF_T file_size
; /* File size (from stat) */
975 OFF_T p_offset
; /* Window start */
976 OFF_T p_fd_offset
; /* offset of cursor in fd ala lseek */
977 char *p
; /* Window pointer */
978 int32 p_size
; /* Largest window size we allocated */
979 int32 p_len
; /* Latest (rounded) window size */
980 int32 def_window_size
; /* Default window size */
981 int fd
; /* File Descriptor */
982 int status
; /* first errno from read errors */
985 #define sum2_at(s, i) ((s)->sum2_array + ((size_t)(i) * xfer_sum_len))
987 #define NAME_IS_FILE (0) /* filter name as a file */
988 #define NAME_IS_DIR (1<<0) /* filter name as a dir */
989 #define NAME_IS_XATTR (1<<2) /* filter name as an xattr */
991 #define FILTRULE_WILD (1<<0) /* pattern has '*', '[', and/or '?' */
992 #define FILTRULE_WILD2 (1<<1) /* pattern has '**' */
993 #define FILTRULE_WILD2_PREFIX (1<<2) /* pattern starts with "**" */
994 #define FILTRULE_WILD3_SUFFIX (1<<3) /* pattern ends with "***" */
995 #define FILTRULE_ABS_PATH (1<<4) /* path-match on absolute path */
996 #define FILTRULE_INCLUDE (1<<5) /* this is an include, not an exclude */
997 #define FILTRULE_DIRECTORY (1<<6) /* this matches only directories */
998 #define FILTRULE_WORD_SPLIT (1<<7) /* split rules on whitespace */
999 #define FILTRULE_NO_INHERIT (1<<8) /* don't inherit these rules */
1000 #define FILTRULE_NO_PREFIXES (1<<9) /* parse no prefixes from patterns */
1001 #define FILTRULE_MERGE_FILE (1<<10)/* specifies a file to merge */
1002 #define FILTRULE_PERDIR_MERGE (1<<11)/* merge-file is searched per-dir */
1003 #define FILTRULE_EXCLUDE_SELF (1<<12)/* merge-file name should be excluded */
1004 #define FILTRULE_FINISH_SETUP (1<<13)/* per-dir merge file needs setup */
1005 #define FILTRULE_NEGATE (1<<14)/* rule matches when pattern does not */
1006 #define FILTRULE_CVS_IGNORE (1<<15)/* rule was -C or :C */
1007 #define FILTRULE_SENDER_SIDE (1<<16)/* rule applies to the sending side */
1008 #define FILTRULE_RECEIVER_SIDE (1<<17)/* rule applies to the receiving side */
1009 #define FILTRULE_CLEAR_LIST (1<<18)/* this item is the "!" token */
1010 #define FILTRULE_PERISHABLE (1<<19)/* perishable if parent dir goes away */
1011 #define FILTRULE_XATTR (1<<20)/* rule only applies to xattr names */
1013 #define FILTRULES_SIDES (FILTRULE_SENDER_SIDE | FILTRULE_RECEIVER_SIDE)
1015 typedef struct filter_struct
{
1016 struct filter_struct
*next
;
1021 struct filter_list_struct
*mergelist
;
1026 typedef struct filter_list_struct
{
1034 int64 total_transferred_size
;
1035 int64 total_written
;
1039 int64 flist_buildtime
;
1040 int64 flist_xfertime
;
1042 int num_files
, num_dirs
, num_symlinks
, num_devices
, num_specials
;
1043 int created_files
, created_dirs
, created_symlinks
, created_devices
, created_specials
;
1044 int deleted_files
, deleted_dirs
, deleted_symlinks
, deleted_devices
, deleted_specials
;
1048 struct chmod_mode_struct
;
1050 struct flist_ndx_item
{
1051 struct flist_ndx_item
*next
;
1056 struct flist_ndx_item
*head
, *tail
;
1059 #define EMPTY_ITEM_LIST {NULL, 0, 0}
1067 #define EXPAND_ITEM_LIST(lp, type, incr) \
1068 (type*)expand_item_list(lp, sizeof (type), #type, incr)
1070 #define EMPTY_XBUF {NULL, 0, 0, 0}
1074 size_t pos
; /* pos = read pos in the buf */
1075 size_t len
; /* len = chars following pos */
1076 size_t size
; /* size = total space in buf */
1079 #define INIT_XBUF(xb, str, ln, sz) (xb).buf = (str), (xb).len = (ln), (xb).size = (sz), (xb).pos = 0
1080 #define INIT_XBUF_STRLEN(xb, str) (xb).buf = (str), (xb).len = strlen((xb).buf), (xb).size = (size_t)-1, (xb).pos = 0
1081 /* This one is used to make an output xbuf based on a char[] buffer: */
1082 #define INIT_CONST_XBUF(xb, bf) (xb).buf = (bf), (xb).size = sizeof (bf), (xb).len = (xb).pos = 0
1084 #define ICB_EXPAND_OUT (1<<0)
1085 #define ICB_INCLUDE_BAD (1<<1)
1086 #define ICB_INCLUDE_INCOMPLETE (1<<2)
1087 #define ICB_CIRCULAR_OUT (1<<3)
1088 #define ICB_INIT (1<<4)
1090 #define IOBUF_KEEP_BUFS 0
1091 #define IOBUF_FREE_BUFS 1
1093 #define MPLX_SWITCHING IOBUF_KEEP_BUFS
1094 #define MPLX_ALL_DONE IOBUF_FREE_BUFS
1095 #define MPLX_TO_BUFFERED 2
1097 #define RL_EOL_NULLS (1<<0)
1098 #define RL_DUMP_COMMENTS (1<<1)
1099 #define RL_CONVERT (1<<2)
1103 #ifdef USE_FLEXIBLE_ARRAY
1104 char fname
[]; /* has variable size */
1106 char fname
[1]; /* A kluge that should work like a flexible array */
1110 #ifdef USE_FLEXIBLE_ARRAY
1111 #define RELNAMECACHE_LEN (sizeof (relnamecache))
1113 #define RELNAMECACHE_LEN (offsetof(relnamecache, fname))
1116 #include "byteorder.h"
1117 #include "lib/mdigest.h"
1118 #include "lib/wildmatch.h"
1119 #include "lib/permstring.h"
1120 #include "lib/addrinfo.h"
1123 #define __attribute__(x)
1130 #define UNUSED(x) x __attribute__((__unused__))
1132 #define NORETURN __attribute__((__noreturn__))
1139 struct rsync_acl
*acc_acl
; /* access ACL */
1140 struct rsync_acl
*def_acl
; /* default ACL */
1142 #ifdef SUPPORT_XATTRS
1147 #define ACL_READY(sx) ((sx).acc_acl != NULL)
1148 #define XATTR_READY(sx) ((sx).xattr != NULL)
1150 #define CLVL_NOT_SPECIFIED INT_MIN
1152 #define CPRES_AUTO (-1)
1153 #define CPRES_NONE 0
1154 #define CPRES_ZLIB 1
1155 #define CPRES_ZLIBX 2
1157 #define CPRES_ZSTD 4
1159 #define NSTR_CHECKSUM 0
1160 #define NSTR_COMPRESS 1
1162 struct name_num_item
{
1165 struct name_num_item
*main_nni
;
1168 struct name_num_obj
{
1170 struct name_num_item
*negotiated_nni
;
1173 struct name_num_item
*list
;
1176 #ifdef EXTERNAL_ZLIB
1177 #define read_buf read_buf_
1184 #ifndef SUPPORT_XATTRS
1185 #define x_stat(fn,fst,xst) do_stat(fn,fst)
1186 #define x_lstat(fn,fst,xst) do_lstat(fn,fst)
1187 #define x_fstat(fd,fst,xst) do_fstat(fd,fst)
1190 /* We have replacement versions of these if they're missing. */
1191 #ifndef HAVE_ASPRINTF
1192 int asprintf(char **ptr
, const char *format
, ...);
1195 #ifndef HAVE_VASPRINTF
1196 int vasprintf(char **ptr
, const char *format
, va_list ap
);
1199 #if !defined HAVE_VSNPRINTF || !defined HAVE_C99_VSNPRINTF
1200 #define vsnprintf rsync_vsnprintf
1201 int vsnprintf(char *str
, size_t count
, const char *fmt
, va_list args
);
1204 #if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
1205 #define snprintf rsync_snprintf
1206 int snprintf(char *str
, size_t count
, const char *fmt
,...);
1209 #ifndef HAVE_STRERROR
1210 extern char *sys_errlist
[];
1211 #define strerror(i) sys_errlist[i]
1215 # define strchr index
1216 # define strrchr rindex
1219 #ifndef HAVE_ERRNO_DECL
1223 #ifdef HAVE_READLINK
1224 #define SUPPORT_LINKS 1
1225 #if !defined NO_SYMLINK_XATTRS && !defined NO_SYMLINK_USER_XATTRS
1226 #define do_readlink(path, buf, bufsiz) readlink(path, buf, bufsiz)
1230 #define SUPPORT_HARD_LINKS 1
1233 #ifdef HAVE_SIGACTION
1234 #define SIGACTION(n,h) sigact.sa_handler=(h), sigaction((n),&sigact,NULL)
1235 #define signal(n,h) we_need_to_call_SIGACTION_not_signal(n,h)
1237 #define SIGACTION(n,h) signal(n,h)
1241 #define EWOULDBLOCK EAGAIN
1244 #ifndef STDIN_FILENO
1245 #define STDIN_FILENO 0
1248 #ifndef STDOUT_FILENO
1249 #define STDOUT_FILENO 1
1252 #ifndef STDERR_FILENO
1253 #define STDERR_FILENO 2
1257 #define S_IRUSR 0400
1261 #define S_IWUSR 0200
1265 #define ACCESSPERMS 0777
1272 #define CHMOD_BITS (S_ISUID | S_ISGID | S_ISVTX | ACCESSPERMS)
1275 #define _S_IFMT 0170000
1279 #define _S_IFLNK 0120000
1283 #define S_ISLNK(mode) (((mode) & (_S_IFMT)) == (_S_IFLNK))
1287 #define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
1291 #define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
1296 #define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
1298 #define S_ISSOCK(mode) (0)
1304 #define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
1306 #define S_ISFIFO(mode) (0)
1311 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
1315 #define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
1318 /* work out what fcntl flag to use for non-blocking */
1320 # define NONBLOCK_FLAG O_NONBLOCK
1322 # define NONBLOCK_FLAG O_NDELAY
1324 # define NONBLOCK_FLAG FNDELAY
1327 #ifndef INADDR_LOOPBACK
1328 #define INADDR_LOOPBACK 0x7f000001
1332 #define INADDR_NONE 0xffffffff
1335 #define IS_SPECIAL(mode) (S_ISSOCK(mode) || S_ISFIFO(mode))
1336 #define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode))
1338 /* Initial mask on permissions given to temporary files. Mask off setuid
1339 bits and group access because of potential race-condition security
1340 holes, and mask other access because mode 707 is bizarre */
1341 #define INITACCESSPERMS 0700
1343 /* handler for null strings in printf format */
1344 #define NS(s) ((s)?(s):"<NULL>")
1346 extern char *do_calloc
;
1348 /* Convenient wrappers for malloc and realloc. Use them. */
1349 #define new(type) ((type*)my_alloc(NULL, sizeof (type), 1, __FILE__, __LINE__))
1350 #define new0(type) ((type*)my_alloc(do_calloc, sizeof (type), 1, __FILE__, __LINE__))
1351 #define realloc_buf(ptr, num) my_alloc((ptr), (num), 1, __FILE__, __LINE__)
1353 #define new_array(type, num) ((type*)my_alloc(NULL, (num), sizeof (type), __FILE__, __LINE__))
1354 #define new_array0(type, num) ((type*)my_alloc(do_calloc, (num), sizeof (type), __FILE__, __LINE__))
1355 #define realloc_array(ptr, type, num) ((type*)my_alloc((ptr), (num), sizeof (type), __FILE__, __LINE__))
1358 #define strdup(s) my_strdup(s, __FILE__, __LINE__)
1360 #define out_of_memory(msg) _out_of_memory(msg, __FILE__, __LINE__)
1361 #define overflow_exit(msg) _overflow_exit(msg, __FILE__, __LINE__)
1363 /* use magic gcc attributes to catch format errors */
1364 void rprintf(enum logcode
, const char *, ...)
1365 __attribute__((format (printf
, 2, 3)))
1368 /* This is just like rprintf, but it also tries to print some
1369 * representation of the error code. Normally errcode = errno. */
1370 void rsyserr(enum logcode
, int, const char *, ...)
1371 __attribute__((format (printf
, 3, 4)))
1374 /* Make sure that the O_BINARY flag is defined. */
1379 #ifndef HAVE_STRLCPY
1380 size_t strlcpy(char *d
, const char *s
, size_t bufsize
);
1383 #ifndef HAVE_STRLCAT
1384 size_t strlcat(char *d
, const char *s
, size_t bufsize
);
1388 #define WEXITSTATUS(stat) ((int)(((stat)>>8)&0xFF))
1391 #define WIFEXITED(stat) ((int)((stat)&0xFF) == 0)
1394 #define exit_cleanup(code) _exit_cleanup(code, __FILE__, __LINE__)
1397 #define MY_UID() geteuid()
1399 #define MY_UID() getuid()
1403 #define MY_GID() getegid()
1405 #define MY_GID() getgid()
1408 #ifdef FORCE_FD_ZERO_MEMSET
1410 #define FD_ZERO(fdsetp) memset(fdsetp, 0, sizeof (fd_set))
1413 extern short info_levels
[], debug_levels
[];
1415 #define INFO_GTE(flag, lvl) (info_levels[INFO_##flag] >= (lvl))
1416 #define INFO_EQ(flag, lvl) (info_levels[INFO_##flag] == (lvl))
1417 #define DEBUG_GTE(flag, lvl) (debug_levels[DEBUG_##flag] >= (lvl))
1418 #define DEBUG_EQ(flag, lvl) (debug_levels[DEBUG_##flag] == (lvl))
1420 #define INFO_BACKUP 0
1421 #define INFO_COPY (INFO_BACKUP+1)
1422 #define INFO_DEL (INFO_COPY+1)
1423 #define INFO_FLIST (INFO_DEL+1)
1424 #define INFO_MISC (INFO_FLIST+1)
1425 #define INFO_MOUNT (INFO_MISC+1)
1426 #define INFO_NAME (INFO_MOUNT+1)
1427 #define INFO_NONREG (INFO_NAME+1)
1428 #define INFO_PROGRESS (INFO_NONREG+1)
1429 #define INFO_REMOVE (INFO_PROGRESS+1)
1430 #define INFO_SKIP (INFO_REMOVE+1)
1431 #define INFO_STATS (INFO_SKIP+1)
1432 #define INFO_SYMSAFE (INFO_STATS+1)
1434 #define COUNT_INFO (INFO_SYMSAFE+1)
1437 #define DEBUG_BACKUP (DEBUG_ACL+1)
1438 #define DEBUG_BIND (DEBUG_BACKUP+1)
1439 #define DEBUG_CHDIR (DEBUG_BIND+1)
1440 #define DEBUG_CONNECT (DEBUG_CHDIR+1)
1441 #define DEBUG_CMD (DEBUG_CONNECT+1)
1442 #define DEBUG_DEL (DEBUG_CMD+1)
1443 #define DEBUG_DELTASUM (DEBUG_DEL+1)
1444 #define DEBUG_DUP (DEBUG_DELTASUM+1)
1445 #define DEBUG_EXIT (DEBUG_DUP+1)
1446 #define DEBUG_FILTER (DEBUG_EXIT+1)
1447 #define DEBUG_FLIST (DEBUG_FILTER+1)
1448 #define DEBUG_FUZZY (DEBUG_FLIST+1)
1449 #define DEBUG_GENR (DEBUG_FUZZY+1)
1450 #define DEBUG_HASH (DEBUG_GENR+1)
1451 #define DEBUG_HLINK (DEBUG_HASH+1)
1452 #define DEBUG_ICONV (DEBUG_HLINK+1)
1453 #define DEBUG_IO (DEBUG_ICONV+1)
1454 #define DEBUG_NSTR (DEBUG_IO+1)
1455 #define DEBUG_OWN (DEBUG_NSTR+1)
1456 #define DEBUG_PROTO (DEBUG_OWN+1)
1457 #define DEBUG_RECV (DEBUG_PROTO+1)
1458 #define DEBUG_SEND (DEBUG_RECV+1)
1459 #define DEBUG_TIME (DEBUG_SEND+1)
1461 #define COUNT_DEBUG (DEBUG_TIME+1)
1463 #ifndef HAVE_INET_NTOP
1464 const char *inet_ntop(int af
, const void *src
, char *dst
, size_t size
);
1467 #ifndef HAVE_INET_PTON
1468 int inet_pton(int af
, const char *src
, void *dst
);
1471 #ifndef HAVE_GETPASS
1472 char *getpass(const char *prompt
);
1475 #ifdef MAINTAINER_MODE
1476 const char *get_panic_action(void);
1479 #define NOISY_DEATH(msg) do { \
1480 fprintf(stderr, "%s in %s at line %d\n", msg, __FILE__, __LINE__); \
1481 exit_cleanup(RERR_UNSUPPORTED); \
1484 #ifdef HAVE_MALLINFO2
1485 #define MEM_ALLOC_INFO mallinfo2
1486 #elif defined HAVE_MALLINFO
1487 #define MEM_ALLOC_INFO mallinfo