00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define False 0
00023 #define True 1
00024
00025 #define BLOCK_SIZE 700
00026 #define RSYNC_RSH_ENV "RSYNC_RSH"
00027 #define RSYNC_RSH_IO_ENV "RSYNC_RSH_IO"
00028
00029 #define RSYNC_NAME "rsync"
00030
00031 #define RSYNCD_USERCONF "rsyncd.conf"
00032
00033 #define DEFAULT_LOCK_FILE "/var/run/rsyncd.lock"
00034 #define URL_PREFIX "rsync://"
00035
00036 #define BACKUP_SUFFIX "~"
00037
00038
00039
00040 #define CHAR_OFFSET 0
00041
00042
00043
00044 #define XMIT_TOP_DIR (1<<0)
00045 #define XMIT_SAME_MODE (1<<1)
00046 #define XMIT_EXTENDED_FLAGS (1<<2)
00047 #define XMIT_SAME_RDEV_pre28 XMIT_EXTENDED_FLAGS
00048 #define XMIT_SAME_UID (1<<3)
00049 #define XMIT_SAME_GID (1<<4)
00050 #define XMIT_SAME_NAME (1<<5)
00051 #define XMIT_LONG_NAME (1<<6)
00052 #define XMIT_SAME_TIME (1<<7)
00053 #define XMIT_SAME_RDEV_MAJOR (1<<8)
00054 #define XMIT_HAS_IDEV_DATA (1<<9)
00055 #define XMIT_SAME_DEV (1<<10)
00056 #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
00057
00058
00059
00060 #define FLAG_TOP_DIR (1<<0)
00061 #define FLAG_SENT (1<<1)
00062 #define FLAG_HLINK_EOL (1<<1)
00063 #define FLAG_MOUNT_POINT (1<<2)
00064 #define FLAG_DEL_HERE (1<<3)
00065 #define FLAG_HLINK_TOL (1<<4)
00066 #define FLAG_NO_FUZZY (1<<5)
00067
00068
00069 #define PROTOCOL_VERSION 29
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 #define MIN_PROTOCOL_VERSION 20
00089 #define OLD_PROTOCOL_VERSION 25
00090 #define MAX_PROTOCOL_VERSION 40
00091
00092 #define RSYNC_PORT 873
00093
00094 #define SPARSE_WRITE_SIZE (1024)
00095 #define WRITE_SIZE (32*1024)
00096 #define CHUNK_SIZE (32*1024)
00097 #define MAX_MAP_SIZE (256*1024)
00098 #define IO_BUFFER_SIZE (4092)
00099 #define MAX_BLOCK_SIZE ((int32)1 << 29)
00100
00101 #define IOERR_GENERAL (1<<0)
00102 #define IOERR_VANISHED (1<<1)
00103 #define IOERR_DEL_LIMIT (1<<2)
00104
00105 #define MAX_ARGS 1000
00106 #define MAX_BASIS_DIRS 20
00107 #define MAX_SERVER_ARGS (MAX_BASIS_DIRS*2 + 100)
00108
00109 #define MPLEX_BASE 7
00110
00111 #define NO_FILTERS 0
00112 #define SERVER_FILTERS 1
00113 #define ALL_FILTERS 2
00114
00115 #define XFLG_FATAL_ERRORS (1<<0)
00116 #define XFLG_OLD_PREFIXES (1<<1)
00117 #define XFLG_ANCHORED2ABS (1<<2)
00118 #define XFLG_ABS_IF_SLASH (1<<3)
00119
00120 #define ATTRS_REPORT (1<<0)
00121 #define ATTRS_SKIP_MTIME (1<<1)
00122
00123 #define FULL_FLUSH 1
00124 #define NORMAL_FLUSH 0
00125
00126 #define PDIR_CREATE 1
00127 #define PDIR_DELETE 0
00128
00129
00130 #define FNAMECMP_BASIS_DIR_LOW 0x00
00131 #define FNAMECMP_BASIS_DIR_HIGH 0x7F
00132 #define FNAMECMP_FNAME 0x80
00133 #define FNAMECMP_PARTIAL_DIR 0x81
00134 #define FNAMECMP_BACKUP 0x82
00135 #define FNAMECMP_FUZZY 0x83
00136
00137
00138 #define ITEM_REPORT_ATIME (1<<0)
00139 #define ITEM_REPORT_CHECKSUM (1<<1)
00140 #define ITEM_REPORT_SIZE (1<<2)
00141 #define ITEM_REPORT_TIME (1<<3)
00142 #define ITEM_REPORT_PERMS (1<<4)
00143 #define ITEM_REPORT_OWNER (1<<5)
00144 #define ITEM_REPORT_GROUP (1<<6)
00145 #define ITEM_REPORT_ACL (1<<7)
00146 #define ITEM_REPORT_XATTR (1<<8)
00147 #define ITEM_BASIS_TYPE_FOLLOWS (1<<11)
00148 #define ITEM_XNAME_FOLLOWS (1<<12)
00149 #define ITEM_IS_NEW (1<<13)
00150 #define ITEM_LOCAL_CHANGE (1<<14)
00151 #define ITEM_TRANSFER (1<<15)
00152
00153 #define ITEM_MISSING_DATA (1<<16)
00154 #define ITEM_DELETED (1<<17)
00155
00156 #define SIGNIFICANT_ITEM_FLAGS (~(\
00157 ITEM_BASIS_TYPE_FOLLOWS | ITEM_XNAME_FOLLOWS | ITEM_LOCAL_CHANGE))
00158
00159
00160
00161
00162
00163 enum logcode { FERROR=1, FINFO=2, FLOG=3, FCLIENT=4, FNAME=5, FSOCKERR=6 };
00164
00165
00166
00167 enum msgcode {
00168 MSG_DATA=0,
00169 MSG_ERROR=FERROR, MSG_INFO=FINFO,
00170 MSG_LOG=FLOG, MSG_SOCKERR=FSOCKERR,
00171 MSG_REDO=9,
00172 MSG_SUCCESS=100,
00173 MSG_DELETED=101,
00174 MSG_DONE=86
00175 };
00176
00177 #include "errcode.h"
00178
00179 #include "config.h"
00180
00181
00182
00183 #include <stdio.h>
00184 #ifdef HAVE_SYS_TYPES_H
00185 # include <sys/types.h>
00186 #endif
00187 #ifdef HAVE_SYS_STAT_H
00188 # include <sys/stat.h>
00189 #endif
00190 #ifdef STDC_HEADERS
00191 # include <stdlib.h>
00192 # include <stddef.h>
00193 #else
00194 # ifdef HAVE_STDLIB_H
00195 # include <stdlib.h>
00196 # endif
00197 #endif
00198 #ifdef HAVE_STRING_H
00199 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
00200 # include <memory.h>
00201 # endif
00202 # include <string.h>
00203 #endif
00204 #ifdef HAVE_STRINGS_H
00205 # include <strings.h>
00206 #endif
00207 #ifdef HAVE_UNISTD_H
00208 # include <unistd.h>
00209 #endif
00210
00211 #ifdef HAVE_SYS_PARAM_H
00212 #include <sys/param.h>
00213 #endif
00214
00215 #if defined HAVE_MALLOC_H && (defined HAVE_MALLINFO || !defined HAVE_STDLIB_H)
00216 #include <malloc.h>
00217 #endif
00218
00219 #ifdef HAVE_SYS_SOCKET_H
00220 #include <sys/socket.h>
00221 #endif
00222
00223 #ifdef TIME_WITH_SYS_TIME
00224 #include <sys/time.h>
00225 #include <time.h>
00226 #else
00227 #ifdef HAVE_SYS_TIME_H
00228 #include <sys/time.h>
00229 #else
00230 #include <time.h>
00231 #endif
00232 #endif
00233
00234 #ifdef HAVE_FCNTL_H
00235 #include <fcntl.h>
00236 #else
00237 #ifdef HAVE_SYS_FCNTL_H
00238 #include <sys/fcntl.h>
00239 #endif
00240 #endif
00241
00242 #ifdef HAVE_SYS_IOCTL_H
00243 #include <sys/ioctl.h>
00244 #endif
00245
00246 #ifdef HAVE_SYS_FILIO_H
00247 #include <sys/filio.h>
00248 #endif
00249
00250 #include <signal.h>
00251 #ifdef HAVE_SYS_WAIT_H
00252 #include <sys/wait.h>
00253 #endif
00254 #ifdef HAVE_CTYPE_H
00255 #include <ctype.h>
00256 #endif
00257 #ifdef HAVE_GRP_H
00258 #include <grp.h>
00259 #endif
00260 #include <errno.h>
00261
00262 #ifdef HAVE_UTIME_H
00263 #include <utime.h>
00264 #endif
00265
00266 #ifdef HAVE_SYS_SELECT_H
00267 #include <sys/select.h>
00268 #endif
00269
00270 #ifdef HAVE_SYS_MODE_H
00271
00272 #ifndef S_ISLNK
00273 #include <sys/mode.h>
00274 #endif
00275 #endif
00276
00277 #ifdef HAVE_GLOB_H
00278 #include <glob.h>
00279 #endif
00280
00281
00282 #include <pwd.h>
00283 #include <grp.h>
00284
00285 #include <stdarg.h>
00286 #include <netinet/in.h>
00287 #include <arpa/inet.h>
00288 #include <netdb.h>
00289 #include <syslog.h>
00290 #include <sys/file.h>
00291
00292 #ifdef HAVE_DIRENT_H
00293 # include <dirent.h>
00294 #else
00295 # define dirent direct
00296 # ifdef HAVE_SYS_NDIR_H
00297 # include <sys/ndir.h>
00298 # endif
00299 # ifdef HAVE_SYS_DIR_H
00300 # include <sys/dir.h>
00301 # endif
00302 # ifdef HAVE_NDIR_H
00303 # include <ndir.h>
00304 # endif
00305 #endif
00306
00307 #ifdef MAJOR_IN_MKDEV
00308 #include <sys/mkdev.h>
00309 # if !defined makedev && (defined mkdev || defined _WIN32 || defined __WIN32__)
00310 # define makedev mkdev
00311 # endif
00312 #elif defined MAJOR_IN_SYSMACROS
00313 #include <sys/sysmacros.h>
00314 #endif
00315
00316 #ifdef HAVE_COMPAT_H
00317 #include <compat.h>
00318 #endif
00319
00320 #ifdef HAVE_LIMITS_H
00321 # include <limits.h>
00322 #endif
00323
00324 #include <assert.h>
00325
00326 #include "lib/pool_alloc.h"
00327
00328 #define BOOL int
00329
00330 #ifndef uchar
00331 #define uchar unsigned char
00332 #endif
00333
00334 #ifdef SIGNED_CHAR_OK
00335 #define schar signed char
00336 #else
00337 #define schar char
00338 #endif
00339
00340
00341
00342
00343 #ifndef int32
00344 #if SIZEOF_INT == 4
00345 # define int32 int
00346 # define SIZEOF_INT32 4
00347 #elif SIZEOF_LONG == 4
00348 # define int32 long
00349 # define SIZEOF_INT32 4
00350 #elif SIZEOF_SHORT == 4
00351 # define int32 short
00352 # define SIZEOF_INT32 4
00353 #elif SIZEOF_INT > 4
00354 # define int32 int
00355 # define SIZEOF_INT32 SIZEOF_INT
00356 #elif SIZEOF_LONG > 4
00357 # define int32 long
00358 # define SIZEOF_INT32 SIZEOF_LONG
00359 #else
00360 # error Could not find a 32-bit integer variable
00361 #endif
00362 #else
00363 # define SIZEOF_INT32 4
00364 #endif
00365
00366 #ifndef uint32
00367 #define uint32 unsigned int32
00368 #endif
00369
00370 #if SIZEOF_OFF_T == 8 || !SIZEOF_OFF64_T || !defined HAVE_STRUCT_STAT64
00371 #define OFF_T off_t
00372 #define STRUCT_STAT struct stat
00373 #else
00374 #define OFF_T off64_t
00375 #define STRUCT_STAT struct stat64
00376 #define USE_STAT64_FUNCS 1
00377 #endif
00378
00379
00380
00381
00382
00383
00384
00385 #if SIZEOF_OFF64_T == 8
00386 # define int64 off64_t
00387 # define SIZEOF_INT64 8
00388 #elif SIZEOF_LONG == 8
00389 # define int64 long
00390 # define SIZEOF_INT64 8
00391 #elif SIZEOF_INT == 8
00392 # define int64 int
00393 # define SIZEOF_INT64 8
00394 #elif SIZEOF_LONG_LONG == 8
00395 # define int64 long long
00396 # define SIZEOF_INT64 8
00397 #elif SIZEOF_OFF_T == 8
00398 # define int64 off_t
00399 # define SIZEOF_INT64 8
00400 #elif SIZEOF_INT > 8
00401 # define int64 int
00402 # define SIZEOF_INT64 SIZEOF_INT
00403 #elif SIZEOF_LONG > 8
00404 # define int64 long
00405 # define SIZEOF_INT64 SIZEOF_LONG
00406 #elif SIZEOF_LONG_LONG > 8
00407 # define int64 long long
00408 # define SIZEOF_INT64 SIZEOF_LONG_LONG
00409 #else
00410
00411 # define int64 off_t
00412 # define SIZEOF_INT64 SIZEOF_OFF_T
00413 #endif
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 struct idev {
00442 int64 inode;
00443 int64 dev;
00444 };
00445
00446 #ifndef MIN
00447 #define MIN(a,b) ((a)<(b)?(a):(b))
00448 #endif
00449
00450 #ifndef MAX
00451 #define MAX(a,b) ((a)>(b)?(a):(b))
00452 #endif
00453
00454 #ifndef MAXHOSTNAMELEN
00455 #define MAXHOSTNAMELEN 256
00456 #endif
00457
00458
00459 #define MD4_SUM_LENGTH 16
00460 #define SUM_LENGTH 16
00461 #define SHORT_SUM_LENGTH 2
00462 #define BLOCKSUM_BIAS 10
00463
00464 #ifndef MAXPATHLEN
00465 #define MAXPATHLEN 1024
00466 #endif
00467
00468
00469
00470 #if MAXPATHLEN < 4096
00471 #define BIGPATHBUFLEN (4096+1024)
00472 #else
00473 #define BIGPATHBUFLEN (MAXPATHLEN+1024)
00474 #endif
00475
00476 #ifndef NAME_MAX
00477 #define NAME_MAX 255
00478 #endif
00479
00480 #ifndef INADDR_NONE
00481 #define INADDR_NONE 0xffffffff
00482 #endif
00483
00484 #ifndef IN_LOOPBACKNET
00485 #define IN_LOOPBACKNET 127
00486 #endif
00487
00488 #define GID_NONE ((gid_t)-1)
00489
00490 #define HL_CHECK_MASTER 0
00491 #define HL_SKIP 1
00492
00493 struct hlink {
00494 int next;
00495 int hlindex;
00496 };
00497
00498 #define F_DEV link_u.idev->dev
00499 #define F_INODE link_u.idev->inode
00500
00501 #define F_HLINDEX link_u.links->hlindex
00502 #define F_NEXT link_u.links->next
00503
00504 struct file_struct {
00505 union {
00506 dev_t rdev;
00507 char *sum;
00508 char *link;
00509 } u;
00510 OFF_T length;
00511 char *basename;
00512 char *dirname;
00513 union {
00514 char *root;
00515 int depth;
00516 } dir;
00517 union {
00518 struct idev *idev;
00519 struct hlink *links;
00520 } link_u;
00521 time_t modtime;
00522 uid_t uid;
00523 gid_t gid;
00524 mode_t mode;
00525 uchar flags;
00526 };
00527
00528
00529
00530
00531
00532 #define FLIST_START (32 * 1024)
00533 #define FLIST_LINEAR (FLIST_START * 512)
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544 #define FILE_EXTENT (256 * 1024)
00545 #define HLINK_EXTENT (128 * 1024)
00546
00547 #define WITH_HLINK 1
00548 #define WITHOUT_HLINK 0
00549
00550 struct file_list {
00551 struct file_struct **files;
00552 alloc_pool_t file_pool;
00553 alloc_pool_t hlink_pool;
00554 int count;
00555 int malloced;
00556 int low, high;
00557 };
00558
00559 #define SUMFLG_SAME_OFFSET (1<<0)
00560
00561 struct sum_buf {
00562 OFF_T offset;
00563 int32 len;
00564 uint32 sum1;
00565 int32 chain;
00566 short flags;
00567 char sum2[SUM_LENGTH];
00568 };
00569
00570 struct sum_struct {
00571 OFF_T flength;
00572 struct sum_buf *sums;
00573 int32 count;
00574 int32 blength;
00575 int32 remainder;
00576 int s2length;
00577 };
00578
00579 struct map_struct {
00580 OFF_T file_size;
00581 OFF_T p_offset;
00582 OFF_T p_fd_offset;
00583 char *p;
00584 int32 p_size;
00585 int32 p_len;
00586 int32 def_window_size;
00587 int fd;
00588 int status;
00589 };
00590
00591 #define MATCHFLG_WILD (1<<0)
00592 #define MATCHFLG_WILD2 (1<<1)
00593 #define MATCHFLG_WILD2_PREFIX (1<<2)
00594 #define MATCHFLG_WILD3_SUFFIX (1<<3)
00595 #define MATCHFLG_ABS_PATH (1<<4)
00596 #define MATCHFLG_INCLUDE (1<<5)
00597 #define MATCHFLG_DIRECTORY (1<<6)
00598 #define MATCHFLG_WORD_SPLIT (1<<7)
00599 #define MATCHFLG_NO_INHERIT (1<<8)
00600 #define MATCHFLG_NO_PREFIXES (1<<9)
00601 #define MATCHFLG_MERGE_FILE (1<<10)
00602 #define MATCHFLG_PERDIR_MERGE (1<<11)
00603 #define MATCHFLG_EXCLUDE_SELF (1<<12)
00604 #define MATCHFLG_FINISH_SETUP (1<<13)
00605 #define MATCHFLG_NEGATE (1<<14)
00606 #define MATCHFLG_CVS_IGNORE (1<<15)
00607 #define MATCHFLG_SENDER_SIDE (1<<16)
00608 #define MATCHFLG_RECEIVER_SIDE (1<<17)
00609 #define MATCHFLG_CLEAR_LIST (1<<18)
00610
00611 #define MATCHFLGS_FROM_CONTAINER (MATCHFLG_ABS_PATH | MATCHFLG_INCLUDE \
00612 | MATCHFLG_DIRECTORY | MATCHFLG_SENDER_SIDE \
00613 | MATCHFLG_NEGATE | MATCHFLG_RECEIVER_SIDE)
00614
00615 struct filter_struct {
00616 struct filter_struct *next;
00617 char *pattern;
00618 uint32 match_flags;
00619 union {
00620 int slash_cnt;
00621 struct filter_list_struct *mergelist;
00622 } u;
00623 };
00624
00625 struct filter_list_struct {
00626 struct filter_struct *head;
00627 struct filter_struct *tail;
00628 char *debug_type;
00629 };
00630
00631 struct stats {
00632 int64 total_size;
00633 int64 total_transferred_size;
00634 int64 total_written;
00635 int64 total_read;
00636 int64 literal_data;
00637 int64 matched_data;
00638 int64 flist_buildtime;
00639 int64 flist_xfertime;
00640 int flist_size;
00641 int num_files;
00642 int num_transferred_files;
00643 int current_file_index;
00644 };
00645
00646 struct chmod_mode_struct;
00647
00648 #include "byteorder.h"
00649 #include "lib/mdfour.h"
00650 #include "lib/wildmatch.h"
00651 #include "lib/permstring.h"
00652 #include "lib/addrinfo.h"
00653
00654 #if !defined __GNUC__ || defined __APPLE__
00655
00656
00657
00658 #define __attribute__(x)
00659 #endif
00660
00661 #define UNUSED(x) x __attribute__((__unused__))
00662
00663 #if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
00664 HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
00665 #define SUPPORT_ACLS 1
00666 #endif
00667
00668 #if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
00669 #define ACLS_NEED_MASK 1
00670 #endif
00671
00672 #if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
00673 #include <sys/acl.h>
00674 #endif
00675 #include "smb_acls.h"
00676
00677 #ifdef HAVE_LINUX_XATTRS
00678 #define SUPPORT_XATTRS 1
00679 #endif
00680
00681 #if defined SUPPORT_XATTRS && defined HAVE_ATTR_XATTR_H
00682 #include <attr/xattr.h>
00683 #endif
00684
00685 #include "proto.h"
00686
00687
00688 #ifndef HAVE_ASPRINTF
00689 int asprintf(char **ptr, const char *format, ...);
00690 #endif
00691
00692 #ifndef HAVE_VASPRINTF
00693 int vasprintf(char **ptr, const char *format, va_list ap);
00694 #endif
00695
00696 #if !defined HAVE_VSNPRINTF || !defined HAVE_C99_VSNPRINTF
00697 #define vsnprintf rsync_vsnprintf
00698 int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
00699 #endif
00700
00701 #if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
00702 #define snprintf rsync_snprintf
00703 int snprintf(char *str,size_t count,const char *fmt,...);
00704 #endif
00705
00706
00707 #ifndef HAVE_STRERROR
00708 extern char *sys_errlist[];
00709 #define strerror(i) sys_errlist[i]
00710 #endif
00711
00712 #ifndef HAVE_STRCHR
00713 # define strchr index
00714 # define strrchr rindex
00715 #endif
00716
00717 #ifndef HAVE_ERRNO_DECL
00718 extern int errno;
00719 #endif
00720
00721 #ifdef HAVE_READLINK
00722 #define SUPPORT_LINKS 1
00723 #endif
00724 #ifdef HAVE_LINK
00725 #define SUPPORT_HARD_LINKS 1
00726 #endif
00727
00728 #ifdef HAVE_SIGACTION
00729 #define SIGACTION(n,h) sigact.sa_handler=(h), sigaction((n),&sigact,NULL)
00730 #define signal(n,h) we_need_to_call_SIGACTION_not_signal(n,h)
00731 #else
00732 #define SIGACTION(n,h) signal(n,h)
00733 #endif
00734
00735 #ifndef EWOULDBLOCK
00736 #define EWOULDBLOCK EAGAIN
00737 #endif
00738
00739 #ifndef STDIN_FILENO
00740 #define STDIN_FILENO 0
00741 #endif
00742
00743 #ifndef STDOUT_FILENO
00744 #define STDOUT_FILENO 1
00745 #endif
00746
00747 #ifndef STDERR_FILENO
00748 #define STDERR_FILENO 2
00749 #endif
00750
00751 #ifndef S_IRUSR
00752 #define S_IRUSR 0400
00753 #endif
00754
00755 #ifndef S_IWUSR
00756 #define S_IWUSR 0200
00757 #endif
00758
00759 #ifndef ACCESSPERMS
00760 #define ACCESSPERMS 0777
00761 #endif
00762
00763 #ifndef S_ISVTX
00764 #define S_ISVTX 0
00765 #endif
00766
00767 #define CHMOD_BITS (S_ISUID | S_ISGID | S_ISVTX | ACCESSPERMS)
00768
00769 #ifndef _S_IFMT
00770 #define _S_IFMT 0170000
00771 #endif
00772
00773 #ifndef _S_IFLNK
00774 #define _S_IFLNK 0120000
00775 #endif
00776
00777 #ifndef S_ISLNK
00778 #define S_ISLNK(mode) (((mode) & (_S_IFMT)) == (_S_IFLNK))
00779 #endif
00780
00781 #ifndef S_ISBLK
00782 #define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
00783 #endif
00784
00785 #ifndef S_ISCHR
00786 #define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
00787 #endif
00788
00789 #ifndef S_ISSOCK
00790 #ifdef _S_IFSOCK
00791 #define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
00792 #else
00793 #define S_ISSOCK(mode) (0)
00794 #endif
00795 #endif
00796
00797 #ifndef S_ISFIFO
00798 #ifdef _S_IFIFO
00799 #define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
00800 #else
00801 #define S_ISFIFO(mode) (0)
00802 #endif
00803 #endif
00804
00805 #ifndef S_ISDIR
00806 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
00807 #endif
00808
00809 #ifndef S_ISREG
00810 #define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
00811 #endif
00812
00813
00814 #ifdef O_NONBLOCK
00815 # define NONBLOCK_FLAG O_NONBLOCK
00816 #elif defined SYSV
00817 # define NONBLOCK_FLAG O_NDELAY
00818 #else
00819 # define NONBLOCK_FLAG FNDELAY
00820 #endif
00821
00822 #ifndef INADDR_LOOPBACK
00823 #define INADDR_LOOPBACK 0x7f000001
00824 #endif
00825
00826 #ifndef INADDR_NONE
00827 #define INADDR_NONE 0xffffffff
00828 #endif
00829
00830 #define IS_SPECIAL(mode) (S_ISSOCK(mode) || S_ISFIFO(mode))
00831 #define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode))
00832
00833
00834
00835
00836 #define INITACCESSPERMS 0700
00837
00838
00839 #define NS(s) ((s)?(s):"<NULL>")
00840
00841
00842 #define new(type) ((type *)malloc(sizeof(type)))
00843 #define new_array(type, num) ((type *)_new_array(sizeof(type), (num)))
00844 #define realloc_array(ptr, type, num) ((type *)_realloc_array((ptr), sizeof(type), (num)))
00845
00846
00847 void rprintf(enum logcode , const char *, ...)
00848 __attribute__((format (printf, 2, 3)))
00849 ;
00850
00851
00852
00853 void rsyserr(enum logcode, int, const char *, ...)
00854 __attribute__((format (printf, 3, 4)))
00855 ;
00856
00857
00858 #ifndef O_BINARY
00859 #define O_BINARY 0
00860 #endif
00861
00862 #ifndef HAVE_STRLCPY
00863 size_t strlcpy(char *d, const char *s, size_t bufsize);
00864 #endif
00865
00866 #ifndef HAVE_STRLCAT
00867 size_t strlcat(char *d, const char *s, size_t bufsize);
00868 #endif
00869
00870 #ifndef WEXITSTATUS
00871 #define WEXITSTATUS(stat) ((int)(((stat)>>8)&0xFF))
00872 #endif
00873
00874 #define exit_cleanup(code) _exit_cleanup(code, __FILE__, __LINE__)
00875
00876 #ifdef HAVE_GETEUID
00877 #define MY_UID() geteuid()
00878 #else
00879 #define MY_UID() getuid()
00880 #endif
00881
00882 #ifdef HAVE_GETEGID
00883 #define MY_GID() getegid()
00884 #else
00885 #define MY_GID() getgid()
00886 #endif
00887
00888 extern int verbose;
00889
00890 #ifndef HAVE_INET_NTOP
00891 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
00892 #endif
00893
00894 #ifndef HAVE_INET_PTON
00895 int inet_pton(int af, const char *src, void *dst);
00896 #endif
00897
00898 #ifdef MAINTAINER_MODE
00899 const char *get_panic_action(void);
00900 #endif