rsync-3.1.0/ 0000775 0000000 0000000 00000000000 12221641132 011343 5 ustar root root rsync-3.1.0/config.sub 0000664 0000000 0000000 00000105301 12146245643 013340 0 ustar root root #! /bin/sh
# Configuration validation subroutine script.
# Copyright 1992-2013 Free Software Foundation, Inc.
timestamp='2013-04-24'
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see .
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that
# program. This Exception is an additional permission under section 7
# of the GNU General Public License, version 3 ("GPLv3").
# Please send patches with a ChangeLog entry to config-patches@gnu.org.
#
# Configuration subroutine to validate and canonicalize a configuration type.
# Supply the specified configuration type as an argument.
# If it is invalid, we print an error message on stderr and exit with code 1.
# Otherwise, we print the canonical config type on stdout and succeed.
# You can get the latest version of this script from:
# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
# This file is supposed to be the same for all GNU packages
# and recognize all the CPU types, system types and aliases
# that are meaningful with *any* GNU software.
# Each package is responsible for reporting which valid configurations
# it does not support. The user should be able to distinguish
# a failure to support a valid configuration from a meaningless
# configuration.
# The goal of this file is to map all the various variations of a given
# machine specification into a single specification in the form:
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
# or in some cases, the newer four-part form:
# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
# It is wrong to echo any other type of specification.
me=`echo "$0" | sed -e 's,.*/,,'`
usage="\
Usage: $0 [OPTION] CPU-MFR-OPSYS
$0 [OPTION] ALIAS
Canonicalize a configuration name.
Operation modes:
-h, --help print this help, then exit
-t, --time-stamp print date of last modification, then exit
-v, --version print version number, then exit
Report bugs and patches to ."
version="\
GNU config.sub ($timestamp)
Copyright 1992-2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
help="
Try \`$me --help' for more information."
# Parse command line
while test $# -gt 0 ; do
case $1 in
--time-stamp | --time* | -t )
echo "$timestamp" ; exit ;;
--version | -v )
echo "$version" ; exit ;;
--help | --h* | -h )
echo "$usage"; exit ;;
-- ) # Stop option processing
shift; break ;;
- ) # Use stdin as input.
break ;;
-* )
echo "$me: invalid option $1$help"
exit 1 ;;
*local*)
# First pass through any local machine types.
echo $1
exit ;;
* )
break ;;
esac
done
case $# in
0) echo "$me: missing argument$help" >&2
exit 1;;
1) ;;
*) echo "$me: too many arguments$help" >&2
exit 1;;
esac
# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
# Here we must recognize all the valid KERNEL-OS combinations.
maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
case $maybe_os in
nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
knetbsd*-gnu* | netbsd*-gnu* | \
kopensolaris*-gnu* | \
storm-chaos* | os2-emx* | rtmk-nova*)
os=-$maybe_os
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
;;
android-linux)
os=-linux-android
basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
;;
*)
basic_machine=`echo $1 | sed 's/-[^-]*$//'`
if [ $basic_machine != $1 ]
then os=`echo $1 | sed 's/.*-/-/'`
else os=; fi
;;
esac
### Let's recognize common machines as not being operating systems so
### that things like config.sub decstation-3100 work. We also
### recognize some manufacturers as not being operating systems, so we
### can provide default operating systems below.
case $os in
-sun*os*)
# Prevent following clause from handling this invalid input.
;;
-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-apple | -axis | -knuth | -cray | -microblaze*)
os=
basic_machine=$1
;;
-bluegene*)
os=-cnk
;;
-sim | -cisco | -oki | -wec | -winbond)
os=
basic_machine=$1
;;
-scout)
;;
-wrs)
os=-vxworks
basic_machine=$1
;;
-chorusos*)
os=-chorusos
basic_machine=$1
;;
-chorusrdb)
os=-chorusrdb
basic_machine=$1
;;
-hiux*)
os=-hiuxwe2
;;
-sco6)
os=-sco5v6
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco5)
os=-sco3.2v5
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco4)
os=-sco3.2v4
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco3.2.[4-9]*)
os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco3.2v[4-9]*)
# Don't forget version if it is 3.2v4 or newer.
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco5v6*)
# Don't forget version if it is 3.2v4 or newer.
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-sco*)
os=-sco3.2v2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-udk*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-isc)
os=-isc2.2
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-clix*)
basic_machine=clipper-intergraph
;;
-isc*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
;;
-lynx*178)
os=-lynxos178
;;
-lynx*5)
os=-lynxos5
;;
-lynx*)
os=-lynxos
;;
-ptx*)
basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
;;
-windowsnt*)
os=`echo $os | sed -e 's/windowsnt/winnt/'`
;;
-psos*)
os=-psos
;;
-mint | -mint[0-9]*)
basic_machine=m68k-atari
os=-mint
;;
esac
# Decode aliases for certain CPU-COMPANY combinations.
case $basic_machine in
# Recognize the basic CPU types without company name.
# Some are omitted here because they have special meanings below.
1750a | 580 \
| a29k \
| aarch64 | aarch64_be \
| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
| am33_2.0 \
| arc | arceb \
| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
| avr | avr32 \
| be32 | be64 \
| bfin \
| c4x | clipper \
| d10v | d30v | dlx | dsp16xx \
| epiphany \
| fido | fr30 | frv \
| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
| hexagon \
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
| le32 | le64 \
| lm32 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \
| maxq | mb | microblaze | microblazeel | mcore | mep | metag \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
| mips64 | mips64el \
| mips64octeon | mips64octeonel \
| mips64orion | mips64orionel \
| mips64r5900 | mips64r5900el \
| mips64vr | mips64vrel \
| mips64vr4100 | mips64vr4100el \
| mips64vr4300 | mips64vr4300el \
| mips64vr5000 | mips64vr5000el \
| mips64vr5900 | mips64vr5900el \
| mipsisa32 | mipsisa32el \
| mipsisa32r2 | mipsisa32r2el \
| mipsisa64 | mipsisa64el \
| mipsisa64r2 | mipsisa64r2el \
| mipsisa64sb1 | mipsisa64sb1el \
| mipsisa64sr71k | mipsisa64sr71kel \
| mipsr5900 | mipsr5900el \
| mipstx39 | mipstx39el \
| mn10200 | mn10300 \
| moxie \
| mt \
| msp430 \
| nds32 | nds32le | nds32be \
| nios | nios2 | nios2eb | nios2el \
| ns16k | ns32k \
| open8 \
| or1k | or32 \
| pdp10 | pdp11 | pj | pjl \
| powerpc | powerpc64 | powerpc64le | powerpcle \
| pyramid \
| rl78 | rx \
| score \
| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
| sh64 | sh64le \
| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
| spu \
| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
| ubicom32 \
| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
| we32k \
| x86 | xc16x | xstormy16 | xtensa \
| z8k | z80)
basic_machine=$basic_machine-unknown
;;
c54x)
basic_machine=tic54x-unknown
;;
c55x)
basic_machine=tic55x-unknown
;;
c6x)
basic_machine=tic6x-unknown
;;
m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip)
basic_machine=$basic_machine-unknown
os=-none
;;
m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
;;
ms1)
basic_machine=mt-unknown
;;
strongarm | thumb | xscale)
basic_machine=arm-unknown
;;
xgate)
basic_machine=$basic_machine-unknown
os=-none
;;
xscaleeb)
basic_machine=armeb-unknown
;;
xscaleel)
basic_machine=armel-unknown
;;
# We use `pc' rather than `unknown'
# because (1) that's what they normally are, and
# (2) the word "unknown" tends to confuse beginning users.
i*86 | x86_64)
basic_machine=$basic_machine-pc
;;
# Object if more than one company name word.
*-*-*)
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
exit 1
;;
# Recognize the basic CPU types with company name.
580-* \
| a29k-* \
| aarch64-* | aarch64_be-* \
| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
| arm-* | armbe-* | armle-* | armeb-* | armv*-* \
| avr-* | avr32-* \
| be32-* | be64-* \
| bfin-* | bs2000-* \
| c[123]* | c30-* | [cjt]90-* | c4x-* \
| clipper-* | craynv-* | cydra-* \
| d10v-* | d30v-* | dlx-* \
| elxsi-* \
| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
| h8300-* | h8500-* \
| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
| hexagon-* \
| i*86-* | i860-* | i960-* | ia64-* \
| ip2k-* | iq2000-* \
| le32-* | le64-* \
| lm32-* \
| m32c-* | m32r-* | m32rle-* \
| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
| microblaze-* | microblazeel-* \
| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
| mips16-* \
| mips64-* | mips64el-* \
| mips64octeon-* | mips64octeonel-* \
| mips64orion-* | mips64orionel-* \
| mips64r5900-* | mips64r5900el-* \
| mips64vr-* | mips64vrel-* \
| mips64vr4100-* | mips64vr4100el-* \
| mips64vr4300-* | mips64vr4300el-* \
| mips64vr5000-* | mips64vr5000el-* \
| mips64vr5900-* | mips64vr5900el-* \
| mipsisa32-* | mipsisa32el-* \
| mipsisa32r2-* | mipsisa32r2el-* \
| mipsisa64-* | mipsisa64el-* \
| mipsisa64r2-* | mipsisa64r2el-* \
| mipsisa64sb1-* | mipsisa64sb1el-* \
| mipsisa64sr71k-* | mipsisa64sr71kel-* \
| mipsr5900-* | mipsr5900el-* \
| mipstx39-* | mipstx39el-* \
| mmix-* \
| mt-* \
| msp430-* \
| nds32-* | nds32le-* | nds32be-* \
| nios-* | nios2-* | nios2eb-* | nios2el-* \
| none-* | np1-* | ns16k-* | ns32k-* \
| open8-* \
| orion-* \
| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
| pyramid-* \
| rl78-* | romp-* | rs6000-* | rx-* \
| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
| sparclite-* \
| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
| tahoe-* \
| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
| tile*-* \
| tron-* \
| ubicom32-* \
| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
| vax-* \
| we32k-* \
| x86-* | x86_64-* | xc16x-* | xps100-* \
| xstormy16-* | xtensa*-* \
| ymp-* \
| z8k-* | z80-*)
;;
# Recognize the basic CPU types without company name, with glob match.
xtensa*)
basic_machine=$basic_machine-unknown
;;
# Recognize the various machine names and aliases which stand
# for a CPU type and a company and sometimes even an OS.
386bsd)
basic_machine=i386-unknown
os=-bsd
;;
3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
basic_machine=m68000-att
;;
3b*)
basic_machine=we32k-att
;;
a29khif)
basic_machine=a29k-amd
os=-udi
;;
abacus)
basic_machine=abacus-unknown
;;
adobe68k)
basic_machine=m68010-adobe
os=-scout
;;
alliant | fx80)
basic_machine=fx80-alliant
;;
altos | altos3068)
basic_machine=m68k-altos
;;
am29k)
basic_machine=a29k-none
os=-bsd
;;
amd64)
basic_machine=x86_64-pc
;;
amd64-*)
basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
amdahl)
basic_machine=580-amdahl
os=-sysv
;;
amiga | amiga-*)
basic_machine=m68k-unknown
;;
amigaos | amigados)
basic_machine=m68k-unknown
os=-amigaos
;;
amigaunix | amix)
basic_machine=m68k-unknown
os=-sysv4
;;
apollo68)
basic_machine=m68k-apollo
os=-sysv
;;
apollo68bsd)
basic_machine=m68k-apollo
os=-bsd
;;
aros)
basic_machine=i386-pc
os=-aros
;;
aux)
basic_machine=m68k-apple
os=-aux
;;
balance)
basic_machine=ns32k-sequent
os=-dynix
;;
blackfin)
basic_machine=bfin-unknown
os=-linux
;;
blackfin-*)
basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
os=-linux
;;
bluegene*)
basic_machine=powerpc-ibm
os=-cnk
;;
c54x-*)
basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c55x-*)
basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c6x-*)
basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
c90)
basic_machine=c90-cray
os=-unicos
;;
cegcc)
basic_machine=arm-unknown
os=-cegcc
;;
convex-c1)
basic_machine=c1-convex
os=-bsd
;;
convex-c2)
basic_machine=c2-convex
os=-bsd
;;
convex-c32)
basic_machine=c32-convex
os=-bsd
;;
convex-c34)
basic_machine=c34-convex
os=-bsd
;;
convex-c38)
basic_machine=c38-convex
os=-bsd
;;
cray | j90)
basic_machine=j90-cray
os=-unicos
;;
craynv)
basic_machine=craynv-cray
os=-unicosmp
;;
cr16 | cr16-*)
basic_machine=cr16-unknown
os=-elf
;;
crds | unos)
basic_machine=m68k-crds
;;
crisv32 | crisv32-* | etraxfs*)
basic_machine=crisv32-axis
;;
cris | cris-* | etrax*)
basic_machine=cris-axis
;;
crx)
basic_machine=crx-unknown
os=-elf
;;
da30 | da30-*)
basic_machine=m68k-da30
;;
decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
basic_machine=mips-dec
;;
decsystem10* | dec10*)
basic_machine=pdp10-dec
os=-tops10
;;
decsystem20* | dec20*)
basic_machine=pdp10-dec
os=-tops20
;;
delta | 3300 | motorola-3300 | motorola-delta \
| 3300-motorola | delta-motorola)
basic_machine=m68k-motorola
;;
delta88)
basic_machine=m88k-motorola
os=-sysv3
;;
dicos)
basic_machine=i686-pc
os=-dicos
;;
djgpp)
basic_machine=i586-pc
os=-msdosdjgpp
;;
dpx20 | dpx20-*)
basic_machine=rs6000-bull
os=-bosx
;;
dpx2* | dpx2*-bull)
basic_machine=m68k-bull
os=-sysv3
;;
ebmon29k)
basic_machine=a29k-amd
os=-ebmon
;;
elxsi)
basic_machine=elxsi-elxsi
os=-bsd
;;
encore | umax | mmax)
basic_machine=ns32k-encore
;;
es1800 | OSE68k | ose68k | ose | OSE)
basic_machine=m68k-ericsson
os=-ose
;;
fx2800)
basic_machine=i860-alliant
;;
genix)
basic_machine=ns32k-ns
;;
gmicro)
basic_machine=tron-gmicro
os=-sysv
;;
go32)
basic_machine=i386-pc
os=-go32
;;
h3050r* | hiux*)
basic_machine=hppa1.1-hitachi
os=-hiuxwe2
;;
h8300hms)
basic_machine=h8300-hitachi
os=-hms
;;
h8300xray)
basic_machine=h8300-hitachi
os=-xray
;;
h8500hms)
basic_machine=h8500-hitachi
os=-hms
;;
harris)
basic_machine=m88k-harris
os=-sysv3
;;
hp300-*)
basic_machine=m68k-hp
;;
hp300bsd)
basic_machine=m68k-hp
os=-bsd
;;
hp300hpux)
basic_machine=m68k-hp
os=-hpux
;;
hp3k9[0-9][0-9] | hp9[0-9][0-9])
basic_machine=hppa1.0-hp
;;
hp9k2[0-9][0-9] | hp9k31[0-9])
basic_machine=m68000-hp
;;
hp9k3[2-9][0-9])
basic_machine=m68k-hp
;;
hp9k6[0-9][0-9] | hp6[0-9][0-9])
basic_machine=hppa1.0-hp
;;
hp9k7[0-79][0-9] | hp7[0-79][0-9])
basic_machine=hppa1.1-hp
;;
hp9k78[0-9] | hp78[0-9])
# FIXME: really hppa2.0-hp
basic_machine=hppa1.1-hp
;;
hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
# FIXME: really hppa2.0-hp
basic_machine=hppa1.1-hp
;;
hp9k8[0-9][13679] | hp8[0-9][13679])
basic_machine=hppa1.1-hp
;;
hp9k8[0-9][0-9] | hp8[0-9][0-9])
basic_machine=hppa1.0-hp
;;
hppa-next)
os=-nextstep3
;;
hppaosf)
basic_machine=hppa1.1-hp
os=-osf
;;
hppro)
basic_machine=hppa1.1-hp
os=-proelf
;;
i370-ibm* | ibm*)
basic_machine=i370-ibm
;;
i*86v32)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv32
;;
i*86v4*)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv4
;;
i*86v)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-sysv
;;
i*86sol2)
basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
os=-solaris2
;;
i386mach)
basic_machine=i386-mach
os=-mach
;;
i386-vsta | vsta)
basic_machine=i386-unknown
os=-vsta
;;
iris | iris4d)
basic_machine=mips-sgi
case $os in
-irix*)
;;
*)
os=-irix4
;;
esac
;;
isi68 | isi)
basic_machine=m68k-isi
os=-sysv
;;
m68knommu)
basic_machine=m68k-unknown
os=-linux
;;
m68knommu-*)
basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
os=-linux
;;
m88k-omron*)
basic_machine=m88k-omron
;;
magnum | m3230)
basic_machine=mips-mips
os=-sysv
;;
merlin)
basic_machine=ns32k-utek
os=-sysv
;;
microblaze*)
basic_machine=microblaze-xilinx
;;
mingw64)
basic_machine=x86_64-pc
os=-mingw64
;;
mingw32)
basic_machine=i386-pc
os=-mingw32
;;
mingw32ce)
basic_machine=arm-unknown
os=-mingw32ce
;;
miniframe)
basic_machine=m68000-convergent
;;
*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
basic_machine=m68k-atari
os=-mint
;;
mips3*-*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
;;
mips3*)
basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
;;
monitor)
basic_machine=m68k-rom68k
os=-coff
;;
morphos)
basic_machine=powerpc-unknown
os=-morphos
;;
msdos)
basic_machine=i386-pc
os=-msdos
;;
ms1-*)
basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
;;
msys)
basic_machine=i386-pc
os=-msys
;;
mvs)
basic_machine=i370-ibm
os=-mvs
;;
nacl)
basic_machine=le32-unknown
os=-nacl
;;
ncr3000)
basic_machine=i486-ncr
os=-sysv4
;;
netbsd386)
basic_machine=i386-unknown
os=-netbsd
;;
netwinder)
basic_machine=armv4l-rebel
os=-linux
;;
news | news700 | news800 | news900)
basic_machine=m68k-sony
os=-newsos
;;
news1000)
basic_machine=m68030-sony
os=-newsos
;;
news-3600 | risc-news)
basic_machine=mips-sony
os=-newsos
;;
necv70)
basic_machine=v70-nec
os=-sysv
;;
next | m*-next )
basic_machine=m68k-next
case $os in
-nextstep* )
;;
-ns2*)
os=-nextstep2
;;
*)
os=-nextstep3
;;
esac
;;
nh3000)
basic_machine=m68k-harris
os=-cxux
;;
nh[45]000)
basic_machine=m88k-harris
os=-cxux
;;
nindy960)
basic_machine=i960-intel
os=-nindy
;;
mon960)
basic_machine=i960-intel
os=-mon960
;;
nonstopux)
basic_machine=mips-compaq
os=-nonstopux
;;
np1)
basic_machine=np1-gould
;;
neo-tandem)
basic_machine=neo-tandem
;;
nse-tandem)
basic_machine=nse-tandem
;;
nsr-tandem)
basic_machine=nsr-tandem
;;
op50n-* | op60c-*)
basic_machine=hppa1.1-oki
os=-proelf
;;
openrisc | openrisc-*)
basic_machine=or32-unknown
;;
os400)
basic_machine=powerpc-ibm
os=-os400
;;
OSE68000 | ose68000)
basic_machine=m68000-ericsson
os=-ose
;;
os68k)
basic_machine=m68k-none
os=-os68k
;;
pa-hitachi)
basic_machine=hppa1.1-hitachi
os=-hiuxwe2
;;
paragon)
basic_machine=i860-intel
os=-osf
;;
parisc)
basic_machine=hppa-unknown
os=-linux
;;
parisc-*)
basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
os=-linux
;;
pbd)
basic_machine=sparc-tti
;;
pbb)
basic_machine=m68k-tti
;;
pc532 | pc532-*)
basic_machine=ns32k-pc532
;;
pc98)
basic_machine=i386-pc
;;
pc98-*)
basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentium | p5 | k5 | k6 | nexgen | viac3)
basic_machine=i586-pc
;;
pentiumpro | p6 | 6x86 | athlon | athlon_*)
basic_machine=i686-pc
;;
pentiumii | pentium2 | pentiumiii | pentium3)
basic_machine=i686-pc
;;
pentium4)
basic_machine=i786-pc
;;
pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumpro-* | p6-* | 6x86-* | athlon-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pentium4-*)
basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
pn)
basic_machine=pn-gould
;;
power) basic_machine=power-ibm
;;
ppc | ppcbe) basic_machine=powerpc-unknown
;;
ppc-* | ppcbe-*)
basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppcle | powerpclittle | ppc-le | powerpc-little)
basic_machine=powerpcle-unknown
;;
ppcle-* | powerpclittle-*)
basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppc64) basic_machine=powerpc64-unknown
;;
ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ppc64le | powerpc64little | ppc64-le | powerpc64-little)
basic_machine=powerpc64le-unknown
;;
ppc64le-* | powerpc64little-*)
basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
ps2)
basic_machine=i386-ibm
;;
pw32)
basic_machine=i586-unknown
os=-pw32
;;
rdos | rdos64)
basic_machine=x86_64-pc
os=-rdos
;;
rdos32)
basic_machine=i386-pc
os=-rdos
;;
rom68k)
basic_machine=m68k-rom68k
os=-coff
;;
rm[46]00)
basic_machine=mips-siemens
;;
rtpc | rtpc-*)
basic_machine=romp-ibm
;;
s390 | s390-*)
basic_machine=s390-ibm
;;
s390x | s390x-*)
basic_machine=s390x-ibm
;;
sa29200)
basic_machine=a29k-amd
os=-udi
;;
sb1)
basic_machine=mipsisa64sb1-unknown
;;
sb1el)
basic_machine=mipsisa64sb1el-unknown
;;
sde)
basic_machine=mipsisa32-sde
os=-elf
;;
sei)
basic_machine=mips-sei
os=-seiux
;;
sequent)
basic_machine=i386-sequent
;;
sh)
basic_machine=sh-hitachi
os=-hms
;;
sh5el)
basic_machine=sh5le-unknown
;;
sh64)
basic_machine=sh64-unknown
;;
sparclite-wrs | simso-wrs)
basic_machine=sparclite-wrs
os=-vxworks
;;
sps7)
basic_machine=m68k-bull
os=-sysv2
;;
spur)
basic_machine=spur-unknown
;;
st2000)
basic_machine=m68k-tandem
;;
stratus)
basic_machine=i860-stratus
os=-sysv4
;;
strongarm-* | thumb-*)
basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
;;
sun2)
basic_machine=m68000-sun
;;
sun2os3)
basic_machine=m68000-sun
os=-sunos3
;;
sun2os4)
basic_machine=m68000-sun
os=-sunos4
;;
sun3os3)
basic_machine=m68k-sun
os=-sunos3
;;
sun3os4)
basic_machine=m68k-sun
os=-sunos4
;;
sun4os3)
basic_machine=sparc-sun
os=-sunos3
;;
sun4os4)
basic_machine=sparc-sun
os=-sunos4
;;
sun4sol2)
basic_machine=sparc-sun
os=-solaris2
;;
sun3 | sun3-*)
basic_machine=m68k-sun
;;
sun4)
basic_machine=sparc-sun
;;
sun386 | sun386i | roadrunner)
basic_machine=i386-sun
;;
sv1)
basic_machine=sv1-cray
os=-unicos
;;
symmetry)
basic_machine=i386-sequent
os=-dynix
;;
t3e)
basic_machine=alphaev5-cray
os=-unicos
;;
t90)
basic_machine=t90-cray
os=-unicos
;;
tile*)
basic_machine=$basic_machine-unknown
os=-linux-gnu
;;
tx39)
basic_machine=mipstx39-unknown
;;
tx39el)
basic_machine=mipstx39el-unknown
;;
toad1)
basic_machine=pdp10-xkl
os=-tops20
;;
tower | tower-32)
basic_machine=m68k-ncr
;;
tpf)
basic_machine=s390x-ibm
os=-tpf
;;
udi29k)
basic_machine=a29k-amd
os=-udi
;;
ultra3)
basic_machine=a29k-nyu
os=-sym1
;;
v810 | necv810)
basic_machine=v810-nec
os=-none
;;
vaxv)
basic_machine=vax-dec
os=-sysv
;;
vms)
basic_machine=vax-dec
os=-vms
;;
vpp*|vx|vx-*)
basic_machine=f301-fujitsu
;;
vxworks960)
basic_machine=i960-wrs
os=-vxworks
;;
vxworks68)
basic_machine=m68k-wrs
os=-vxworks
;;
vxworks29k)
basic_machine=a29k-wrs
os=-vxworks
;;
w65*)
basic_machine=w65-wdc
os=-none
;;
w89k-*)
basic_machine=hppa1.1-winbond
os=-proelf
;;
xbox)
basic_machine=i686-pc
os=-mingw32
;;
xps | xps100)
basic_machine=xps100-honeywell
;;
xscale-* | xscalee[bl]-*)
basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
;;
ymp)
basic_machine=ymp-cray
os=-unicos
;;
z8k-*-coff)
basic_machine=z8k-unknown
os=-sim
;;
z80-*-coff)
basic_machine=z80-unknown
os=-sim
;;
none)
basic_machine=none-none
os=-none
;;
# Here we handle the default manufacturer of certain CPU types. It is in
# some cases the only manufacturer, in others, it is the most popular.
w89k)
basic_machine=hppa1.1-winbond
;;
op50n)
basic_machine=hppa1.1-oki
;;
op60c)
basic_machine=hppa1.1-oki
;;
romp)
basic_machine=romp-ibm
;;
mmix)
basic_machine=mmix-knuth
;;
rs6000)
basic_machine=rs6000-ibm
;;
vax)
basic_machine=vax-dec
;;
pdp10)
# there are many clones, so DEC is not a safe bet
basic_machine=pdp10-unknown
;;
pdp11)
basic_machine=pdp11-dec
;;
we32k)
basic_machine=we32k-att
;;
sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
basic_machine=sh-unknown
;;
sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
basic_machine=sparc-sun
;;
cydra)
basic_machine=cydra-cydrome
;;
orion)
basic_machine=orion-highlevel
;;
orion105)
basic_machine=clipper-highlevel
;;
mac | mpw | mac-mpw)
basic_machine=m68k-apple
;;
pmac | pmac-mpw)
basic_machine=powerpc-apple
;;
*-unknown)
# Make sure to match an already-canonicalized machine name.
;;
*)
echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
exit 1
;;
esac
# Here we canonicalize certain aliases for manufacturers.
case $basic_machine in
*-digital*)
basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
;;
*-commodore*)
basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
;;
*)
;;
esac
# Decode manufacturer-specific aliases for certain operating systems.
if [ x"$os" != x"" ]
then
case $os in
# First match some system type aliases
# that might get confused with valid system types.
# -solaris* is a basic system type, with this one exception.
-auroraux)
os=-auroraux
;;
-solaris1 | -solaris1.*)
os=`echo $os | sed -e 's|solaris1|sunos4|'`
;;
-solaris)
os=-solaris2
;;
-svr4*)
os=-sysv4
;;
-unixware*)
os=-sysv4.2uw
;;
-gnu/linux*)
os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
;;
# First accept the basic system types.
# The portable systems comes first.
# Each alternative MUST END IN A *, to match a version number.
# -sysv* is not here because it comes later, after sysvr4.
-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
| -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
| -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
| -sym* | -kopensolaris* | -plan9* \
| -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
| -aos* | -aros* \
| -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
| -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
| -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
| -bitrig* | -openbsd* | -solidbsd* \
| -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
| -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
| -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -chorusos* | -chorusrdb* | -cegcc* \
| -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
| -linux-newlib* | -linux-musl* | -linux-uclibc* \
| -uxpv* | -beos* | -mpeix* | -udk* \
| -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
| -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
| -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
| -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
| -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
| -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
| -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-qnx*)
case $basic_machine in
x86-* | i*86-*)
;;
*)
os=-nto$os
;;
esac
;;
-nto-qnx*)
;;
-nto*)
os=`echo $os | sed -e 's|nto|nto-qnx|'`
;;
-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
| -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
| -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
;;
-mac*)
os=`echo $os | sed -e 's|mac|macos|'`
;;
-linux-dietlibc)
os=-linux-dietlibc
;;
-linux*)
os=`echo $os | sed -e 's|linux|linux-gnu|'`
;;
-sunos5*)
os=`echo $os | sed -e 's|sunos5|solaris2|'`
;;
-sunos6*)
os=`echo $os | sed -e 's|sunos6|solaris3|'`
;;
-opened*)
os=-openedition
;;
-os400*)
os=-os400
;;
-wince*)
os=-wince
;;
-osfrose*)
os=-osfrose
;;
-osf*)
os=-osf
;;
-utek*)
os=-bsd
;;
-dynix*)
os=-bsd
;;
-acis*)
os=-aos
;;
-atheos*)
os=-atheos
;;
-syllable*)
os=-syllable
;;
-386bsd)
os=-bsd
;;
-ctix* | -uts*)
os=-sysv
;;
-nova*)
os=-rtmk-nova
;;
-ns2 )
os=-nextstep2
;;
-nsk*)
os=-nsk
;;
# Preserve the version number of sinix5.
-sinix5.*)
os=`echo $os | sed -e 's|sinix|sysv|'`
;;
-sinix*)
os=-sysv4
;;
-tpf*)
os=-tpf
;;
-triton*)
os=-sysv3
;;
-oss*)
os=-sysv3
;;
-svr4)
os=-sysv4
;;
-svr3)
os=-sysv3
;;
-sysvr4)
os=-sysv4
;;
# This must come after -sysvr4.
-sysv*)
;;
-ose*)
os=-ose
;;
-es1800*)
os=-ose
;;
-xenix)
os=-xenix
;;
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
os=-mint
;;
-aros*)
os=-aros
;;
-zvmoe)
os=-zvmoe
;;
-dicos*)
os=-dicos
;;
-nacl*)
;;
-none)
;;
*)
# Get rid of the `-' at the beginning of $os.
os=`echo $os | sed 's/[^-]*-//'`
echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
exit 1
;;
esac
else
# Here we handle the default operating systems that come with various machines.
# The value should be what the vendor currently ships out the door with their
# machine or put another way, the most popular os provided with the machine.
# Note that if you're going to try to match "-MANUFACTURER" here (say,
# "-sun"), then you have to tell the case statement up towards the top
# that MANUFACTURER isn't an operating system. Otherwise, code above
# will signal an error saying that MANUFACTURER isn't an operating
# system, and we'll never get to this point.
case $basic_machine in
score-*)
os=-elf
;;
spu-*)
os=-elf
;;
*-acorn)
os=-riscix1.2
;;
arm*-rebel)
os=-linux
;;
arm*-semi)
os=-aout
;;
c4x-* | tic4x-*)
os=-coff
;;
hexagon-*)
os=-elf
;;
tic54x-*)
os=-coff
;;
tic55x-*)
os=-coff
;;
tic6x-*)
os=-coff
;;
# This must come before the *-dec entry.
pdp10-*)
os=-tops20
;;
pdp11-*)
os=-none
;;
*-dec | vax-*)
os=-ultrix4.2
;;
m68*-apollo)
os=-domain
;;
i386-sun)
os=-sunos4.0.2
;;
m68000-sun)
os=-sunos3
;;
m68*-cisco)
os=-aout
;;
mep-*)
os=-elf
;;
mips*-cisco)
os=-elf
;;
mips*-*)
os=-elf
;;
or1k-*)
os=-elf
;;
or32-*)
os=-coff
;;
*-tti) # must be before sparc entry or we get the wrong os.
os=-sysv3
;;
sparc-* | *-sun)
os=-sunos4.1.1
;;
*-be)
os=-beos
;;
*-haiku)
os=-haiku
;;
*-ibm)
os=-aix
;;
*-knuth)
os=-mmixware
;;
*-wec)
os=-proelf
;;
*-winbond)
os=-proelf
;;
*-oki)
os=-proelf
;;
*-hp)
os=-hpux
;;
*-hitachi)
os=-hiux
;;
i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
os=-sysv
;;
*-cbm)
os=-amigaos
;;
*-dg)
os=-dgux
;;
*-dolphin)
os=-sysv3
;;
m68k-ccur)
os=-rtu
;;
m88k-omron*)
os=-luna
;;
*-next )
os=-nextstep
;;
*-sequent)
os=-ptx
;;
*-crds)
os=-unos
;;
*-ns)
os=-genix
;;
i370-*)
os=-mvs
;;
*-next)
os=-nextstep3
;;
*-gould)
os=-sysv
;;
*-highlevel)
os=-bsd
;;
*-encore)
os=-bsd
;;
*-sgi)
os=-irix
;;
*-siemens)
os=-sysv4
;;
*-masscomp)
os=-rtu
;;
f30[01]-fujitsu | f700-fujitsu)
os=-uxpv
;;
*-rom68k)
os=-coff
;;
*-*bug)
os=-coff
;;
*-apple)
os=-macos
;;
*-atari*)
os=-mint
;;
*)
os=-none
;;
esac
fi
# Here we handle the case where we know the os, and the CPU type, but not the
# manufacturer. We pick the logical manufacturer.
vendor=unknown
case $basic_machine in
*-unknown)
case $os in
-riscix*)
vendor=acorn
;;
-sunos*)
vendor=sun
;;
-cnk*|-aix*)
vendor=ibm
;;
-beos*)
vendor=be
;;
-hpux*)
vendor=hp
;;
-mpeix*)
vendor=hp
;;
-hiux*)
vendor=hitachi
;;
-unos*)
vendor=crds
;;
-dgux*)
vendor=dg
;;
-luna*)
vendor=omron
;;
-genix*)
vendor=ns
;;
-mvs* | -opened*)
vendor=ibm
;;
-os400*)
vendor=ibm
;;
-ptx*)
vendor=sequent
;;
-tpf*)
vendor=ibm
;;
-vxsim* | -vxworks* | -windiss*)
vendor=wrs
;;
-aux*)
vendor=apple
;;
-hms*)
vendor=hitachi
;;
-mpw* | -macos*)
vendor=apple
;;
-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
vendor=atari
;;
-vos*)
vendor=stratus
;;
esac
basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
;;
esac
echo $basic_machine$os
exit
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "timestamp='"
# time-stamp-format: "%:y-%02m-%02d"
# time-stamp-end: "'"
# End:
rsync-3.1.0/acls.c 0000664 0000000 0000000 00000074052 12076567221 012457 0 ustar root root /*
* Handle passing Access Control Lists between systems.
*
* Copyright (C) 1996 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2006-2013 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, visit the http://fsf.org website.
*/
#include "rsync.h"
#include "lib/sysacls.h"
#ifdef SUPPORT_ACLS
extern int dry_run;
extern int am_root;
extern int read_only;
extern int list_only;
extern int orig_umask;
extern int numeric_ids;
extern int inc_recurse;
extern int preserve_devices;
extern int preserve_specials;
/* Flags used to indicate what items are being transmitted for an entry. */
#define XMIT_USER_OBJ (1<<0)
#define XMIT_GROUP_OBJ (1<<1)
#define XMIT_MASK_OBJ (1<<2)
#define XMIT_OTHER_OBJ (1<<3)
#define XMIT_NAME_LIST (1<<4)
#define NO_ENTRY ((uchar)0x80) /* Default value of a NON-name-list entry. */
#define NAME_IS_USER (1u<<31) /* Bit used only on a name-list entry. */
/* When we send the access bits over the wire, we shift them 2 bits to the
* left and use the lower 2 bits as flags (relevant only to a name entry).
* This makes the protocol more efficient than sending a value that would
* be likely to have its hightest bits set. */
#define XFLAG_NAME_FOLLOWS 0x0001u
#define XFLAG_NAME_IS_USER 0x0002u
/* === ACL structures === */
typedef struct {
id_t id;
uint32 access;
} id_access;
typedef struct {
id_access *idas;
int count;
} ida_entries;
typedef struct {
char *name;
uchar len;
} idname;
typedef struct rsync_acl {
ida_entries names;
/* These will be NO_ENTRY if there's no such entry. */
uchar user_obj;
uchar group_obj;
uchar mask_obj;
uchar other_obj;
} rsync_acl;
typedef struct {
rsync_acl racl;
SMB_ACL_T sacl;
} acl_duo;
static const rsync_acl empty_rsync_acl = {
{NULL, 0}, NO_ENTRY, NO_ENTRY, NO_ENTRY, NO_ENTRY
};
static item_list access_acl_list = EMPTY_ITEM_LIST;
static item_list default_acl_list = EMPTY_ITEM_LIST;
static size_t prior_access_count = (size_t)-1;
static size_t prior_default_count = (size_t)-1;
/* === Calculations on ACL types === */
static const char *str_acl_type(SMB_ACL_TYPE_T type)
{
switch (type) {
case SMB_ACL_TYPE_ACCESS:
#ifdef HAVE_OSX_ACLS
return "ACL_TYPE_EXTENDED";
#else
return "ACL_TYPE_ACCESS";
#endif
case SMB_ACL_TYPE_DEFAULT:
return "ACL_TYPE_DEFAULT";
default:
break;
}
return "unknown ACL type!";
}
static int calc_sacl_entries(const rsync_acl *racl)
{
/* A System ACL always gets user/group/other permission entries. */
return racl->names.count
#ifdef ACLS_NEED_MASK
+ 1
#else
+ (racl->mask_obj != NO_ENTRY)
#endif
+ 3;
}
/* Extracts and returns the permission bits from the ACL. This cannot be
* called on an rsync_acl that has NO_ENTRY in any spot but the mask. */
static int rsync_acl_get_perms(const rsync_acl *racl)
{
return (racl->user_obj << 6)
+ ((racl->mask_obj != NO_ENTRY ? racl->mask_obj : racl->group_obj) << 3)
+ racl->other_obj;
}
/* Removes the permission-bit entries from the ACL because these
* can be reconstructed from the file's mode. */
static void rsync_acl_strip_perms(stat_x *sxp)
{
rsync_acl *racl = sxp->acc_acl;
racl->user_obj = NO_ENTRY;
if (racl->mask_obj == NO_ENTRY)
racl->group_obj = NO_ENTRY;
else {
int group_perms = (sxp->st.st_mode >> 3) & 7;
if (racl->group_obj == group_perms)
racl->group_obj = NO_ENTRY;
#ifndef HAVE_SOLARIS_ACLS
if (racl->names.count != 0 && racl->mask_obj == group_perms)
racl->mask_obj = NO_ENTRY;
#endif
}
racl->other_obj = NO_ENTRY;
}
/* Given an empty rsync_acl, fake up the permission bits. */
static void rsync_acl_fake_perms(rsync_acl *racl, mode_t mode)
{
racl->user_obj = (mode >> 6) & 7;
racl->group_obj = (mode >> 3) & 7;
racl->other_obj = mode & 7;
}
/* === Rsync ACL functions === */
static rsync_acl *create_racl(void)
{
rsync_acl *racl = new(rsync_acl);
if (!racl)
out_of_memory("create_racl");
*racl = empty_rsync_acl;
return racl;
}
static BOOL ida_entries_equal(const ida_entries *ial1, const ida_entries *ial2)
{
id_access *ida1, *ida2;
int count = ial1->count;
if (count != ial2->count)
return False;
ida1 = ial1->idas;
ida2 = ial2->idas;
for (; count--; ida1++, ida2++) {
if (ida1->access != ida2->access || ida1->id != ida2->id)
return False;
}
return True;
}
static BOOL rsync_acl_equal(const rsync_acl *racl1, const rsync_acl *racl2)
{
return racl1->user_obj == racl2->user_obj
&& racl1->group_obj == racl2->group_obj
&& racl1->mask_obj == racl2->mask_obj
&& racl1->other_obj == racl2->other_obj
&& ida_entries_equal(&racl1->names, &racl2->names);
}
/* Are the extended (non-permission-bit) entries equal? If so, the rest of
* the ACL will be handled by the normal mode-preservation code. This is
* only meaningful for access ACLs! Note: the 1st arg is a fully-populated
* rsync_acl, but the 2nd parameter can be a condensed rsync_acl, which means
* that it might have several of its permission objects set to NO_ENTRY. */
static BOOL rsync_acl_equal_enough(const rsync_acl *racl1,
const rsync_acl *racl2, mode_t m)
{
if ((racl1->mask_obj ^ racl2->mask_obj) & NO_ENTRY)
return False; /* One has a mask and the other doesn't */
/* When there's a mask, the group_obj becomes an extended entry. */
if (racl1->mask_obj != NO_ENTRY) {
/* A condensed rsync_acl with a mask can only have no
* group_obj when it was identical to the mask. This
* means that it was also identical to the group attrs
* from the mode. */
if (racl2->group_obj == NO_ENTRY) {
if (racl1->group_obj != ((m >> 3) & 7))
return False;
} else if (racl1->group_obj != racl2->group_obj)
return False;
}
return ida_entries_equal(&racl1->names, &racl2->names);
}
static void rsync_acl_free(rsync_acl *racl)
{
if (racl->names.idas)
free(racl->names.idas);
*racl = empty_rsync_acl;
}
void free_acl(stat_x *sxp)
{
if (sxp->acc_acl) {
rsync_acl_free(sxp->acc_acl);
free(sxp->acc_acl);
sxp->acc_acl = NULL;
}
if (sxp->def_acl) {
rsync_acl_free(sxp->def_acl);
free(sxp->def_acl);
sxp->def_acl = NULL;
}
}
#ifdef SMB_ACL_NEED_SORT
static int id_access_sorter(const void *r1, const void *r2)
{
id_access *ida1 = (id_access *)r1;
id_access *ida2 = (id_access *)r2;
id_t rid1 = ida1->id, rid2 = ida2->id;
if ((ida1->access ^ ida2->access) & NAME_IS_USER)
return ida1->access & NAME_IS_USER ? -1 : 1;
return rid1 == rid2 ? 0 : rid1 < rid2 ? -1 : 1;
}
#endif
/* === System ACLs === */
/* Unpack system ACL -> rsync ACL verbatim. Return whether we succeeded. */
static BOOL unpack_smb_acl(SMB_ACL_T sacl, rsync_acl *racl)
{
static item_list temp_ida_list = EMPTY_ITEM_LIST;
SMB_ACL_ENTRY_T entry;
const char *errfun;
int rc;
errfun = "sys_acl_get_entry";
for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
rc == 1;
rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
SMB_ACL_TAG_T tag_type;
uint32 access;
id_t g_u_id;
id_access *ida;
if ((rc = sys_acl_get_info(entry, &tag_type, &access, &g_u_id)) != 0) {
errfun = "sys_acl_get_info";
break;
}
/* continue == done with entry; break == store in temporary ida list */
switch (tag_type) {
#ifndef HAVE_OSX_ACLS
case SMB_ACL_USER_OBJ:
if (racl->user_obj == NO_ENTRY)
racl->user_obj = access;
else
rprintf(FINFO, "unpack_smb_acl: warning: duplicate USER_OBJ entry ignored\n");
continue;
case SMB_ACL_GROUP_OBJ:
if (racl->group_obj == NO_ENTRY)
racl->group_obj = access;
else
rprintf(FINFO, "unpack_smb_acl: warning: duplicate GROUP_OBJ entry ignored\n");
continue;
case SMB_ACL_MASK:
if (racl->mask_obj == NO_ENTRY)
racl->mask_obj = access;
else
rprintf(FINFO, "unpack_smb_acl: warning: duplicate MASK entry ignored\n");
continue;
case SMB_ACL_OTHER:
if (racl->other_obj == NO_ENTRY)
racl->other_obj = access;
else
rprintf(FINFO, "unpack_smb_acl: warning: duplicate OTHER entry ignored\n");
continue;
#endif
case SMB_ACL_USER:
access |= NAME_IS_USER;
break;
case SMB_ACL_GROUP:
break;
default:
rprintf(FINFO, "unpack_smb_acl: warning: entry with unrecognized tag type ignored\n");
continue;
}
ida = EXPAND_ITEM_LIST(&temp_ida_list, id_access, -10);
ida->id = g_u_id;
ida->access = access;
}
if (rc) {
rsyserr(FERROR_XFER, errno, "unpack_smb_acl: %s()", errfun);
rsync_acl_free(racl);
return False;
}
/* Transfer the count id_access items out of the temp_ida_list
* into the names ida_entries list in racl. */
if (temp_ida_list.count) {
#ifdef SMB_ACL_NEED_SORT
if (temp_ida_list.count > 1) {
qsort(temp_ida_list.items, temp_ida_list.count,
sizeof (id_access), id_access_sorter);
}
#endif
if (!(racl->names.idas = new_array(id_access, temp_ida_list.count)))
out_of_memory("unpack_smb_acl");
memcpy(racl->names.idas, temp_ida_list.items,
temp_ida_list.count * sizeof (id_access));
} else
racl->names.idas = NULL;
racl->names.count = temp_ida_list.count;
/* Truncate the temporary list now that its idas have been saved. */
temp_ida_list.count = 0;
return True;
}
/* Synactic sugar for system calls */
#define CALL_OR_ERROR(func,args,str) \
do { \
if (func args) { \
errfun = str; \
goto error_exit; \
} \
} while (0)
#define COE(func,args) CALL_OR_ERROR(func,args,#func)
#define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
#ifndef HAVE_OSX_ACLS
/* Store the permissions in the system ACL entry. */
static int store_access_in_entry(uint32 access, SMB_ACL_ENTRY_T entry)
{
if (sys_acl_set_access_bits(entry, access)) {
rsyserr(FERROR_XFER, errno, "store_access_in_entry sys_acl_set_access_bits()");
return -1;
}
return 0;
}
#endif
/* Pack rsync ACL -> system ACL verbatim. Return whether we succeeded. */
static BOOL pack_smb_acl(SMB_ACL_T *smb_acl, const rsync_acl *racl)
{
#ifdef ACLS_NEED_MASK
uchar mask_bits;
#endif
size_t count;
id_access *ida;
const char *errfun = NULL;
SMB_ACL_ENTRY_T entry;
if (!(*smb_acl = sys_acl_init(calc_sacl_entries(racl)))) {
rsyserr(FERROR_XFER, errno, "pack_smb_acl: sys_acl_init()");
return False;
}
#ifndef HAVE_OSX_ACLS
COE( sys_acl_create_entry,(smb_acl, &entry) );
COE( sys_acl_set_info,(entry, SMB_ACL_USER_OBJ, racl->user_obj & ~NO_ENTRY, 0) );
#endif
for (ida = racl->names.idas, count = racl->names.count; count; ida++, count--) {
#ifdef SMB_ACL_NEED_SORT
if (!(ida->access & NAME_IS_USER))
break;
#endif
COE( sys_acl_create_entry,(smb_acl, &entry) );
COE( sys_acl_set_info,
(entry,
ida->access & NAME_IS_USER ? SMB_ACL_USER : SMB_ACL_GROUP,
ida->access & ~NAME_IS_USER, ida->id) );
}
#ifndef HAVE_OSX_ACLS
COE( sys_acl_create_entry,(smb_acl, &entry) );
COE( sys_acl_set_info,(entry, SMB_ACL_GROUP_OBJ, racl->group_obj & ~NO_ENTRY, 0) );
#ifdef SMB_ACL_NEED_SORT
for ( ; count; ida++, count--) {
COE( sys_acl_create_entry,(smb_acl, &entry) );
COE( sys_acl_set_info,(entry, SMB_ACL_GROUP, ida->access, ida->id) );
}
#endif
#ifdef ACLS_NEED_MASK
mask_bits = racl->mask_obj == NO_ENTRY ? racl->group_obj & ~NO_ENTRY : racl->mask_obj;
COE( sys_acl_create_entry,(smb_acl, &entry) );
COE( sys_acl_set_info,(entry, SMB_ACL_MASK, mask_bits, NULL) );
#else
if (racl->mask_obj != NO_ENTRY) {
COE( sys_acl_create_entry,(smb_acl, &entry) );
COE( sys_acl_set_info,(entry, SMB_ACL_MASK, racl->mask_obj, 0) );
}
#endif
COE( sys_acl_create_entry,(smb_acl, &entry) );
COE( sys_acl_set_info,(entry, SMB_ACL_OTHER, racl->other_obj & ~NO_ENTRY, 0) );
#endif
#ifdef DEBUG
if (sys_acl_valid(*smb_acl) < 0)
rprintf(FERROR_XFER, "pack_smb_acl: warning: system says the ACL I packed is invalid\n");
#endif
return True;
error_exit:
if (errfun) {
rsyserr(FERROR_XFER, errno, "pack_smb_acl %s()", errfun);
}
sys_acl_free_acl(*smb_acl);
return False;
}
static int find_matching_rsync_acl(const rsync_acl *racl, SMB_ACL_TYPE_T type,
const item_list *racl_list)
{
static int access_match = -1, default_match = -1;
int *match = type == SMB_ACL_TYPE_ACCESS ? &access_match : &default_match;
size_t count = racl_list->count;
/* If this is the first time through or we didn't match the last
* time, then start at the end of the list, which should be the
* best place to start hunting. */
if (*match == -1)
*match = racl_list->count - 1;
while (count--) {
rsync_acl *base = racl_list->items;
if (rsync_acl_equal(base + *match, racl))
return *match;
if (!(*match)--)
*match = racl_list->count - 1;
}
*match = -1;
return *match;
}
static int get_rsync_acl(const char *fname, rsync_acl *racl,
SMB_ACL_TYPE_T type, mode_t mode)
{
SMB_ACL_T sacl;
#ifdef SUPPORT_XATTRS
/* --fake-super support: load ACLs from an xattr. */
if (am_root < 0) {
char *buf;
size_t len;
int cnt;
if ((buf = get_xattr_acl(fname, type == SMB_ACL_TYPE_ACCESS, &len)) == NULL)
return 0;
cnt = (len - 4*4) / (4+4);
if (len < 4*4 || len != (size_t)cnt*(4+4) + 4*4) {
free(buf);
return -1;
}
racl->user_obj = IVAL(buf, 0);
if (racl->user_obj == NO_ENTRY)
racl->user_obj = (mode >> 6) & 7;
racl->group_obj = IVAL(buf, 4);
if (racl->group_obj == NO_ENTRY)
racl->group_obj = (mode >> 3) & 7;
racl->mask_obj = IVAL(buf, 8);
racl->other_obj = IVAL(buf, 12);
if (racl->other_obj == NO_ENTRY)
racl->other_obj = mode & 7;
if (cnt) {
char *bp = buf + 4*4;
id_access *ida;
if (!(ida = racl->names.idas = new_array(id_access, cnt)))
out_of_memory("get_rsync_acl");
racl->names.count = cnt;
for ( ; cnt--; ida++, bp += 4+4) {
ida->id = IVAL(bp, 0);
ida->access = IVAL(bp, 4);
}
}
free(buf);
return 0;
}
#endif
if ((sacl = sys_acl_get_file(fname, type)) != 0) {
BOOL ok = unpack_smb_acl(sacl, racl);
sys_acl_free_acl(sacl);
if (!ok) {
return -1;
}
} else if (no_acl_syscall_error(errno)) {
/* ACLs are not supported, so pretend we have a basic ACL. */
if (type == SMB_ACL_TYPE_ACCESS)
rsync_acl_fake_perms(racl, mode);
} else {
rsyserr(FERROR_XFER, errno, "get_acl: sys_acl_get_file(%s, %s)",
fname, str_acl_type(type));
return -1;
}
return 0;
}
/* Return the Access Control List for the given filename. */
int get_acl(const char *fname, stat_x *sxp)
{
sxp->acc_acl = create_racl();
if (S_ISREG(sxp->st.st_mode) || S_ISDIR(sxp->st.st_mode)) {
/* Everyone supports this. */
} else if (S_ISLNK(sxp->st.st_mode)) {
return 0;
} else if (IS_SPECIAL(sxp->st.st_mode)) {
#ifndef NO_SPECIAL_ACLS
if (!preserve_specials)
#endif
return 0;
} else if (IS_DEVICE(sxp->st.st_mode)) {
#ifndef NO_DEVICE_ACLS
if (!preserve_devices)
#endif
return 0;
}
if (get_rsync_acl(fname, sxp->acc_acl, SMB_ACL_TYPE_ACCESS,
sxp->st.st_mode) < 0) {
free_acl(sxp);
return -1;
}
if (S_ISDIR(sxp->st.st_mode)) {
sxp->def_acl = create_racl();
if (get_rsync_acl(fname, sxp->def_acl, SMB_ACL_TYPE_DEFAULT,
sxp->st.st_mode) < 0) {
free_acl(sxp);
return -1;
}
}
return 0;
}
/* === Send functions === */
/* Send the ida list over the file descriptor. */
static void send_ida_entries(int f, const ida_entries *idal)
{
id_access *ida;
size_t count = idal->count;
write_varint(f, idal->count);
for (ida = idal->idas; count--; ida++) {
uint32 xbits = ida->access << 2;
const char *name;
if (ida->access & NAME_IS_USER) {
xbits |= XFLAG_NAME_IS_USER;
name = numeric_ids ? NULL : add_uid(ida->id);
} else
name = numeric_ids ? NULL : add_gid(ida->id);
write_varint(f, ida->id);
if (inc_recurse && name) {
int len = strlen(name);
write_varint(f, xbits | XFLAG_NAME_FOLLOWS);
write_byte(f, len);
write_buf(f, name, len);
} else
write_varint(f, xbits);
}
}
static void send_rsync_acl(int f, rsync_acl *racl, SMB_ACL_TYPE_T type,
item_list *racl_list)
{
int ndx = find_matching_rsync_acl(racl, type, racl_list);
/* Send 0 (-1 + 1) to indicate that literal ACL data follows. */
write_varint(f, ndx + 1);
if (ndx < 0) {
rsync_acl *new_racl = EXPAND_ITEM_LIST(racl_list, rsync_acl, 1000);
uchar flags = 0;
if (racl->user_obj != NO_ENTRY)
flags |= XMIT_USER_OBJ;
if (racl->group_obj != NO_ENTRY)
flags |= XMIT_GROUP_OBJ;
if (racl->mask_obj != NO_ENTRY)
flags |= XMIT_MASK_OBJ;
if (racl->other_obj != NO_ENTRY)
flags |= XMIT_OTHER_OBJ;
if (racl->names.count)
flags |= XMIT_NAME_LIST;
write_byte(f, flags);
if (flags & XMIT_USER_OBJ)
write_varint(f, racl->user_obj);
if (flags & XMIT_GROUP_OBJ)
write_varint(f, racl->group_obj);
if (flags & XMIT_MASK_OBJ)
write_varint(f, racl->mask_obj);
if (flags & XMIT_OTHER_OBJ)
write_varint(f, racl->other_obj);
if (flags & XMIT_NAME_LIST)
send_ida_entries(f, &racl->names);
/* Give the allocated data to the new list object. */
*new_racl = *racl;
*racl = empty_rsync_acl;
}
}
/* Send the ACL from the stat_x structure down the indicated file descriptor.
* This also frees the ACL data. */
void send_acl(int f, stat_x *sxp)
{
if (!sxp->acc_acl) {
sxp->acc_acl = create_racl();
rsync_acl_fake_perms(sxp->acc_acl, sxp->st.st_mode);
}
/* Avoid sending values that can be inferred from other data. */
rsync_acl_strip_perms(sxp);
send_rsync_acl(f, sxp->acc_acl, SMB_ACL_TYPE_ACCESS, &access_acl_list);
if (S_ISDIR(sxp->st.st_mode)) {
if (!sxp->def_acl)
sxp->def_acl = create_racl();
send_rsync_acl(f, sxp->def_acl, SMB_ACL_TYPE_DEFAULT, &default_acl_list);
}
}
/* === Receive functions === */
static uint32 recv_acl_access(int f, uchar *name_follows_ptr)
{
uint32 access = read_varint(f);
if (name_follows_ptr) {
int flags = access & 3;
access >>= 2;
if (am_root >= 0 && access & ~SMB_ACL_VALID_NAME_BITS)
goto value_error;
if (flags & XFLAG_NAME_FOLLOWS)
*name_follows_ptr = 1;
else
*name_follows_ptr = 0;
if (flags & XFLAG_NAME_IS_USER)
access |= NAME_IS_USER;
} else if (am_root >= 0 && access & ~SMB_ACL_VALID_OBJ_BITS) {
value_error:
rprintf(FERROR_XFER, "recv_acl_access: value out of range: %x\n",
access);
exit_cleanup(RERR_STREAMIO);
}
return access;
}
static uchar recv_ida_entries(int f, ida_entries *ent)
{
uchar computed_mask_bits = 0;
int i, count = read_varint(f);
if (count) {
if (!(ent->idas = new_array(id_access, count)))
out_of_memory("recv_ida_entries");
} else
ent->idas = NULL;
ent->count = count;
for (i = 0; i < count; i++) {
uchar has_name;
id_t id = read_varint(f);
uint32 access = recv_acl_access(f, &has_name);
if (has_name) {
if (access & NAME_IS_USER)
id = recv_user_name(f, id);
else
id = recv_group_name(f, id, NULL);
} else if (access & NAME_IS_USER) {
if (inc_recurse && am_root && !numeric_ids)
id = match_uid(id);
} else {
if (inc_recurse && (!am_root || !numeric_ids))
id = match_gid(id, NULL);
}
ent->idas[i].id = id;
ent->idas[i].access = access;
computed_mask_bits |= access;
}
return computed_mask_bits & ~NO_ENTRY;
}
static int recv_rsync_acl(int f, item_list *racl_list, SMB_ACL_TYPE_T type, mode_t mode)
{
uchar computed_mask_bits = 0;
acl_duo *duo_item;
uchar flags;
int ndx = read_varint(f);
if (ndx < 0 || (size_t)ndx > racl_list->count) {
rprintf(FERROR_XFER, "recv_acl_index: %s ACL index %d > %d\n",
str_acl_type(type), ndx, (int)racl_list->count);
exit_cleanup(RERR_STREAMIO);
}
if (ndx != 0)
return ndx - 1;
ndx = racl_list->count;
duo_item = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
duo_item->racl = empty_rsync_acl;
flags = read_byte(f);
if (flags & XMIT_USER_OBJ)
duo_item->racl.user_obj = recv_acl_access(f, NULL);
if (flags & XMIT_GROUP_OBJ)
duo_item->racl.group_obj = recv_acl_access(f, NULL);
if (flags & XMIT_MASK_OBJ)
duo_item->racl.mask_obj = recv_acl_access(f, NULL);
if (flags & XMIT_OTHER_OBJ)
duo_item->racl.other_obj = recv_acl_access(f, NULL);
if (flags & XMIT_NAME_LIST)
computed_mask_bits |= recv_ida_entries(f, &duo_item->racl.names);
#ifdef HAVE_OSX_ACLS
/* If we received a superfluous mask, throw it away. */
duo_item->racl.mask_obj = NO_ENTRY;
#else
if (duo_item->racl.names.count && duo_item->racl.mask_obj == NO_ENTRY) {
/* Mask must be non-empty with lists. */
if (type == SMB_ACL_TYPE_ACCESS)
computed_mask_bits = (mode >> 3) & 7;
else
computed_mask_bits |= duo_item->racl.group_obj & ~NO_ENTRY;
duo_item->racl.mask_obj = computed_mask_bits;
}
#endif
duo_item->sacl = NULL;
return ndx;
}
/* Receive the ACL info the sender has included for this file-list entry. */
void receive_acl(int f, struct file_struct *file)
{
F_ACL(file) = recv_rsync_acl(f, &access_acl_list, SMB_ACL_TYPE_ACCESS, file->mode);
if (S_ISDIR(file->mode))
F_DIR_DEFACL(file) = recv_rsync_acl(f, &default_acl_list, SMB_ACL_TYPE_DEFAULT, 0);
}
static int cache_rsync_acl(rsync_acl *racl, SMB_ACL_TYPE_T type, item_list *racl_list)
{
int ndx;
if (!racl)
ndx = -1;
else if ((ndx = find_matching_rsync_acl(racl, type, racl_list)) == -1) {
acl_duo *new_duo;
ndx = racl_list->count;
new_duo = EXPAND_ITEM_LIST(racl_list, acl_duo, 1000);
new_duo->racl = *racl;
new_duo->sacl = NULL;
*racl = empty_rsync_acl;
}
return ndx;
}
/* Turn the ACL data in stat_x into cached ACL data, setting the index
* values in the file struct. */
void cache_tmp_acl(struct file_struct *file, stat_x *sxp)
{
if (prior_access_count == (size_t)-1)
prior_access_count = access_acl_list.count;
F_ACL(file) = cache_rsync_acl(sxp->acc_acl,
SMB_ACL_TYPE_ACCESS, &access_acl_list);
if (S_ISDIR(sxp->st.st_mode)) {
if (prior_default_count == (size_t)-1)
prior_default_count = default_acl_list.count;
F_DIR_DEFACL(file) = cache_rsync_acl(sxp->def_acl,
SMB_ACL_TYPE_DEFAULT, &default_acl_list);
}
}
static void uncache_duo_acls(item_list *duo_list, size_t start)
{
acl_duo *duo_item = duo_list->items;
acl_duo *duo_start = duo_item + start;
duo_item += duo_list->count;
duo_list->count = start;
while (duo_item-- > duo_start) {
rsync_acl_free(&duo_item->racl);
if (duo_item->sacl)
sys_acl_free_acl(duo_item->sacl);
}
}
void uncache_tmp_acls(void)
{
if (prior_access_count != (size_t)-1) {
uncache_duo_acls(&access_acl_list, prior_access_count);
prior_access_count = (size_t)-1;
}
if (prior_default_count != (size_t)-1) {
uncache_duo_acls(&default_acl_list, prior_default_count);
prior_default_count = (size_t)-1;
}
}
#ifndef HAVE_OSX_ACLS
static mode_t change_sacl_perms(SMB_ACL_T sacl, rsync_acl *racl, mode_t old_mode, mode_t mode)
{
SMB_ACL_ENTRY_T entry;
const char *errfun;
int rc;
if (S_ISDIR(mode)) {
/* If the sticky bit is going on, it's not safe to allow all
* the new ACL to go into effect before it gets set. */
#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
if (mode & S_ISVTX)
mode &= ~0077;
#else
if (mode & S_ISVTX && !(old_mode & S_ISVTX))
mode &= ~0077;
} else {
/* If setuid or setgid is going off, it's not safe to allow all
* the new ACL to go into effect before they get cleared. */
if ((old_mode & S_ISUID && !(mode & S_ISUID))
|| (old_mode & S_ISGID && !(mode & S_ISGID)))
mode &= ~0077;
#endif
}
errfun = "sys_acl_get_entry";
for (rc = sys_acl_get_entry(sacl, SMB_ACL_FIRST_ENTRY, &entry);
rc == 1;
rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
SMB_ACL_TAG_T tag_type;
if ((rc = sys_acl_get_tag_type(entry, &tag_type)) != 0) {
errfun = "sys_acl_get_tag_type";
break;
}
switch (tag_type) {
case SMB_ACL_USER_OBJ:
COE2( store_access_in_entry,((mode >> 6) & 7, entry) );
break;
case SMB_ACL_GROUP_OBJ:
/* group is only empty when identical to group perms. */
if (racl->group_obj != NO_ENTRY)
break;
COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
break;
case SMB_ACL_MASK:
#ifndef HAVE_SOLARIS_ACLS
#ifndef ACLS_NEED_MASK
/* mask is only empty when we don't need it. */
if (racl->mask_obj == NO_ENTRY)
break;
#endif
COE2( store_access_in_entry,((mode >> 3) & 7, entry) );
#endif
break;
case SMB_ACL_OTHER:
COE2( store_access_in_entry,(mode & 7, entry) );
break;
}
}
if (rc) {
error_exit:
if (errfun) {
rsyserr(FERROR_XFER, errno, "change_sacl_perms: %s()",
errfun);
}
return (mode_t)-1;
}
#ifdef SMB_ACL_LOSES_SPECIAL_MODE_BITS
/* Ensure that chmod() will be called to restore any lost setid bits. */
if (old_mode & (S_ISUID | S_ISGID | S_ISVTX)
&& BITS_EQUAL(old_mode, mode, CHMOD_BITS))
old_mode &= ~(S_ISUID | S_ISGID | S_ISVTX);
#endif
/* Return the mode of the file on disk, as we will set them. */
return (old_mode & ~ACCESSPERMS) | (mode & ACCESSPERMS);
}
#endif
static int set_rsync_acl(const char *fname, acl_duo *duo_item,
SMB_ACL_TYPE_T type, stat_x *sxp, mode_t mode)
{
if (type == SMB_ACL_TYPE_DEFAULT
&& duo_item->racl.user_obj == NO_ENTRY) {
int rc;
#ifdef SUPPORT_XATTRS
/* --fake-super support: delete default ACL from xattrs. */
if (am_root < 0)
rc = del_def_xattr_acl(fname);
else
#endif
rc = sys_acl_delete_def_file(fname);
if (rc < 0) {
rsyserr(FERROR_XFER, errno, "set_acl: sys_acl_delete_def_file(%s)",
fname);
return -1;
}
#ifdef SUPPORT_XATTRS
} else if (am_root < 0) {
/* --fake-super support: store ACLs in an xattr. */
int cnt = duo_item->racl.names.count;
size_t len = 4*4 + cnt * (4+4);
char *buf = new_array(char, len);
int rc;
SIVAL(buf, 0, duo_item->racl.user_obj);
SIVAL(buf, 4, duo_item->racl.group_obj);
SIVAL(buf, 8, duo_item->racl.mask_obj);
SIVAL(buf, 12, duo_item->racl.other_obj);
if (cnt) {
char *bp = buf + 4*4;
id_access *ida = duo_item->racl.names.idas;
for ( ; cnt--; ida++, bp += 4+4) {
SIVAL(bp, 0, ida->id);
SIVAL(bp, 4, ida->access);
}
}
rc = set_xattr_acl(fname, type == SMB_ACL_TYPE_ACCESS, buf, len);
free(buf);
return rc;
#endif
} else {
mode_t cur_mode = sxp->st.st_mode;
if (!duo_item->sacl
&& !pack_smb_acl(&duo_item->sacl, &duo_item->racl))
return -1;
#ifdef HAVE_OSX_ACLS
mode = 0; /* eliminate compiler warning */
#else
if (type == SMB_ACL_TYPE_ACCESS) {
cur_mode = change_sacl_perms(duo_item->sacl, &duo_item->racl,
cur_mode, mode);
if (cur_mode == (mode_t)-1)
return 0;
}
#endif
if (sys_acl_set_file(fname, type, duo_item->sacl) < 0) {
rsyserr(FERROR_XFER, errno, "set_acl: sys_acl_set_file(%s, %s)",
fname, str_acl_type(type));
return -1;
}
if (type == SMB_ACL_TYPE_ACCESS)
sxp->st.st_mode = cur_mode;
}
return 0;
}
/* Given a fname, this sets extended access ACL entries, the default ACL (for a
* dir), and the regular mode bits on the file. Call this with fname set to
* NULL to just check if the ACL is different.
*
* If the ACL operation has a side-effect of changing the file's mode, the
* sxp->st.st_mode value will be changed to match.
*
* Returns 0 for an unchanged ACL, 1 for changed, -1 for failed. */
int set_acl(const char *fname, const struct file_struct *file, stat_x *sxp, mode_t new_mode)
{
int changed = 0;
int32 ndx;
BOOL eq;
if (!dry_run && (read_only || list_only)) {
errno = EROFS;
return -1;
}
ndx = F_ACL(file);
if (ndx >= 0 && (size_t)ndx < access_acl_list.count) {
acl_duo *duo_item = access_acl_list.items;
duo_item += ndx;
eq = sxp->acc_acl
&& rsync_acl_equal_enough(sxp->acc_acl, &duo_item->racl, new_mode);
if (!eq) {
changed = 1;
if (!dry_run && fname
&& set_rsync_acl(fname, duo_item, SMB_ACL_TYPE_ACCESS,
sxp, new_mode) < 0)
return -1;
}
}
if (!S_ISDIR(new_mode))
return changed;
ndx = F_DIR_DEFACL(file);
if (ndx >= 0 && (size_t)ndx < default_acl_list.count) {
acl_duo *duo_item = default_acl_list.items;
duo_item += ndx;
eq = sxp->def_acl && rsync_acl_equal(sxp->def_acl, &duo_item->racl);
if (!eq) {
changed = 1;
if (!dry_run && fname
&& set_rsync_acl(fname, duo_item, SMB_ACL_TYPE_DEFAULT,
sxp, new_mode) < 0)
return -1;
}
}
return changed;
}
/* Non-incremental recursion needs to convert all the received IDs.
* This is done in a single pass after receiving the whole file-list. */
static void match_racl_ids(const item_list *racl_list)
{
int list_cnt, name_cnt;
acl_duo *duo_item = racl_list->items;
for (list_cnt = racl_list->count; list_cnt--; duo_item++) {
ida_entries *idal = &duo_item->racl.names;
id_access *ida = idal->idas;
for (name_cnt = idal->count; name_cnt--; ida++) {
if (ida->access & NAME_IS_USER)
ida->id = match_uid(ida->id);
else
ida->id = match_gid(ida->id, NULL);
}
}
}
void match_acl_ids(void)
{
match_racl_ids(&access_acl_list);
match_racl_ids(&default_acl_list);
}
/* This is used by dest_mode(). */
int default_perms_for_dir(const char *dir)
{
rsync_acl racl;
SMB_ACL_T sacl;
BOOL ok;
int perms;
if (dir == NULL)
dir = ".";
perms = ACCESSPERMS & ~orig_umask;
/* Read the directory's default ACL. If it has none, this will successfully return an empty ACL. */
sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
if (sacl == NULL) {
/* Couldn't get an ACL. Darn. */
switch (errno) {
case EINVAL:
/* If SMB_ACL_TYPE_DEFAULT isn't valid, then the ACLs must be non-POSIX. */
break;
#ifdef ENOTSUP
case ENOTSUP:
#endif
case ENOSYS:
/* No ACLs are available. */
break;
case ENOENT:
if (dry_run) {
/* We're doing a dry run, so the containing directory
* wasn't actually created. Don't worry about it. */
break;
}
/* Otherwise fall through. */
default:
rprintf(FWARNING,
"default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
}
return perms;
}
/* Convert it. */
racl = empty_rsync_acl;
ok = unpack_smb_acl(sacl, &racl);
sys_acl_free_acl(sacl);
if (!ok) {
rprintf(FWARNING, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
return perms;
}
/* Apply the permission-bit entries of the default ACL, if any. */
if (racl.user_obj != NO_ENTRY) {
perms = rsync_acl_get_perms(&racl);
if (DEBUG_GTE(ACL, 1))
rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
}
rsync_acl_free(&racl);
return perms;
}
#endif /* SUPPORT_ACLS */
rsync-3.1.0/prepare-source.mak 0000664 0000000 0000000 00000000247 11364616643 015014 0 ustar root root conf: configure.sh config.h.in
configure.sh: configure.ac aclocal.m4
autoconf -o configure.sh
config.h.in: configure.ac aclocal.m4
autoheader && touch config.h.in
rsync-3.1.0/rsync3.txt 0000664 0000000 0000000 00000034777 11353453505 013361 0 ustar root root -*- indented-text -*-
Notes towards a new version of rsync
Martin Pool , September 2001.
Good things about the current implementation:
- Widely known and adopted.
- Fast/efficient, especially for moderately small sets of files over
slow links (transoceanic or modem.)
- Fairly reliable.
- The choice of running over a plain TCP socket or tunneling over
ssh.
- rsync operations are idempotent: you can always run the same
command twice to make sure it worked properly without any fear.
(Are there any exceptions?)
- Small changes to files cause small deltas.
- There is a way to evolve the protocol to some extent.
- rdiff and rsync --write-batch allow generation of standalone patch
sets. rsync+ is pretty cheesy, though. xdelta seems cleaner.
- Process triangle is creative, but seems to provoke OS bugs.
- "Morning-after property": you don't need to know anything on the
local machine about the state of the remote machine, or about
transfers that have been done in the past.
- You can easily push or pull simply by switching the order of
files.
- The "modules" system has some neat features compared to
e.g. Apache's per-directory configuration. In particular, because
you can set a userid and chroot directory, there is strong
protection between different modules. I haven't seen any calls
for a more flexible system.
Bad things about the current implementation:
- Persistent and hard-to-diagnose hang bugs remain
- Protocol is sketchily documented, tied to this implementation, and
hard to modify/extend
- Both the program and the protocol assume a single non-interactive
one-way transfer
- A list of all files are held in memory for the entire transfer,
which cripples scalability to large file trees
- Opening a new socket for every operation causes problems,
especially when running over SSH with password authentication.
- Renamed files are not handled: the old file is removed, and the
new file created from scratch.
- The versioning approach assumes that future versions of the
program know about all previous versions, and will do the right
thing.
- People always get confused about ':' vs '::'
- Error messages can be cryptic.
- Default behaviour is not intuitive: in too many cases rsync will
happily do nothing. Perhaps -a should be the default?
- People get confused by trailing slashes, though it's hard to think
of another reasonable way to make this necessary distinction
between a directory and its contents.
Protocol philosophy:
*The* big difference between protocols like HTTP, FTP, and NFS is
that their fundamental operations are "read this file", "delete
this file", and "make this directory", whereas rsync is "make this
directory like this one".
Questionable features:
These are neat, but not necessarily clean or worth preserving.
- The remote rsync can be wrapped by some other program, such as in
tridge's rsync-mail scripts. The general feature of sending and
retrieving mail over rsync is good, but this is perhaps not the
right way to implement it.
Desirable features:
These don't really require architectural changes; they're just
something to keep in mind.
- Synchronize ACLs and extended attributes
- Anonymous servers should be efficient
- Code should be portable to non-UNIX systems
- Should be possible to document the protocol in RFC form
- --dry-run option
- IPv6 support. Pretty straightforward.
- Allow the basis and destination files to be different. For
example, you could use this when you have a CD-ROM and want to
download an updated image onto a hard drive.
- Efficiently interrupt and restart a transfer. We can write a
checkpoint file that says where we're up to in the filesystem.
Alternatively, as long as transfers are idempotent, we can just
restart the whole thing. [NFSv4]
- Scripting support.
- Propagate atimes and do not modify them. This is very ugly on
Unix. It might be better to try to add O_NOATIME to kernels, and
call that.
- Unicode. Probably just use UTF-8 for everything.
- Open authentication system. Can we use PAM? Is SASL an adequate
mapping of PAM to the network, or useful in some other way?
- Resume interrupted transfers without the --partial flag. We need
to leave the temporary file behind, and then know to use it. This
leaves a risk of large temporary files accumulating, which is not
good. Perhaps it should be off by default.
- tcpwrappers support. Should be trivial; can already be done
through tcpd or inetd.
- Socks support built in. It's not clear this is any better than
just linking against the socks library, though.
- When run over SSH, invoke with predictable command-line arguments,
so that people can restrict what commands sshd will run. (Is this
really required?)
- Comparison mode: give a list of which files are new, gone, or
different. Set return code depending on whether anything has
changed.
- Internationalized messages (gettext?)
- Optionally use real regexps rather than globs?
- Show overall progress. Pretty hard to do, especially if we insist
on not scanning the directory tree up front.
Regression testing:
- Support automatic testing.
- Have hard internal timeouts against hangs.
- Be deterministic.
- Measure performance.
Hard links:
At the moment, we can recreate hard links, but it's a bit
inefficient: it depends on holding a list of all files in the tree.
Every time we see a file with a linkcount >1, we need to search for
another known name that has the same (fsid,inum) tuple. We could do
that more efficiently by keeping a list of only files with
linkcount>1, and removing files from that list as all their names
become known.
Command-line options:
We have rather a lot at the moment. We might get more if the tool
becomes more flexible. Do we need a .rc or configuration file?
That wouldn't really fit with its pattern of use: cp and tar don't
have them, though ssh does.
Scripting issues:
- Perhaps support multiple scripting languages: candidates include
Perl, Python, Tcl, Scheme (guile?), sh, ...
- Simply running a subprocess and looking at its stdout/exit code
might be sufficient, though it could also be pretty slow if it's
called often.
- There are security issues about running remote code, at least if
it's not running in the users own account. So we can either
disallow it, or use some kind of sandbox system.
- Python is a good language, but the syntax is not so good for
giving small fragments on the command line.
- Tcl is broken Lisp.
- Lots of sysadmins know Perl, though Perl can give some bizarre or
confusing errors. The built in stat operators and regexps might
be useful.
- Sadly probably not enough people know Scheme.
- sh is hard to embed.
Scripting hooks:
- Whether to transfer a file
- What basis file to use
- Logging
- Whether to allow transfers (for public servers)
- Authentication
- Locking
- Cache
- Generating backup path/name.
- Post-processing of backups, e.g. to do compression.
- After transfer, before replacement: so that we can spit out a diff
of what was changed, or kick off some kind of reconciliation
process.
VFS:
Rather than talking straight to the filesystem, rsyncd talks through
an internal API. Samba has one. Is it useful?
- Could be a tidy way to implement cached signatures.
- Keep files compressed on disk?
Interactive interface:
- Something like ncFTP, or integration into GNOME-vfs. Probably
hold a single socket connection open.
- Can either call us as a separate process, or as a library.
- The standalone process needs to produce output in a form easily
digestible by a calling program, like the --emacs feature some
have. Same goes for output: rpm outputs a series of hash symbols,
which are easier for a GUI to handle than "\r30% complete"
strings.
- Yow! emacs support. (You could probably build that already, of
course.) I'd like to be able to write a simple script on a remote
machine that rsyncs it to my workstation, edits it there, then
pushes it back up.
Pie-in-the-sky features:
These might have a severe impact on the protocol, and are not
clearly in our core requirements. It looks like in many of them
having scripting hooks will allow us
- Transport over UDP multicast. The hard part is handling multiple
destinations which have different basis files. We can look at
multicast-TFTP for inspiration.
- Conflict resolution. Possibly general scripting support will be
sufficient.
- Integrate with locking. It's hard to see a good general solution,
because Unix systems have several locking mechanisms, and grabbing
the lock from programs that don't expect it could cause deadlocks,
timeouts, or other problems. Scripting support might help.
- Replicate in place, rather than to a temporary file. This is
dangerous in the case of interruption, and it also means that the
delta can't refer to blocks that have already been overwritten.
On the other hand we could semi-trivially do this at first by
simply generating a delta with no copy instructions.
- Replicate block devices. Most of the difficulties here are to do
with replication in place, though on some systems we will also
have to do I/O on block boundaries.
- Peer to peer features. Flavour of the year. Can we think about
ways for clients to smoothly and voluntarily become servers for
content they receive?
- Imagine a situation where the destination has a much faster link
to the cloud than the source. In this case, Mojo Nation downloads
interleaved blocks from several slower servers. The general
situation might be a way for a master rsync process to farm out
tasks to several subjobs. In this particular case they'd need
different sockets. This might be related to multicast.
Unlikely features:
- Allow remote source and destination. If this can be cleanly
designed into the protocol, perhaps with the remote machine acting
as a kind of echo, then it's good. It's uncommon enough that we
don't want to shape the whole protocol around it, though.
In fact, in a triangle of machines there are two possibilities:
all traffic passes from remote1 to remote2 through local, or local
just sets up the transfer and then remote1 talks to remote2. FTP
supports the second but it's not clearly good. There are some
security problems with being able to instruct one machine to open
a connection to another.
In favour of evolving the protocol:
- Keeping compatibility with existing rsync servers will help with
adoption and testing.
- We should at the very least be able to fall back to the new
protocol.
- Error handling is not so good.
In favour of using a new protocol:
- Maintaining compatibility might soak up development time that
would better go into improving a new protocol.
- If we start from scratch, it can be documented as we go, and we
can avoid design decisions that make the protocol complex or
implementation-bound.
Error handling:
- Errors should come back reliably, and be clearly associated with
the particular file that caused the problem.
- Some errors ought to cause the whole transfer to abort; some are
just warnings. If any errors have occurred, then rsync ought to
return an error.
Concurrency:
- We want to keep the CPU, filesystem, and network as full as
possible as much of the time as possible.
- We can do nonblocking network IO, but not so for disk.
- It makes sense to on the destination be generating signatures and
applying patches at the same time.
- Can structure this with nonblocking, threads, separate processes,
etc.
Uses:
- Mirroring software distributions:
- Synchronizing laptop and desktop
- NFS filesystem migration/replication. See
http://www.ietf.org/proceedings/00jul/00july-133.htm#P24510_1276764
- Sync with PDA
- Network backup systems
- CVS filemover
Conflict resolution:
- Requires application-specific knowledge. We want to provide
policy, rather than mechanism.
- Possibly allowing two-way migration across a single connection
would be useful.
Moved files:
- There's no trivial way to detect renamed files, especially if they
move between directories.
- If we had a picture of the remote directory from last time on
either machine, then the inode numbers might give us a hint about
files which may have been renamed.
- Files that are renamed and not modified can be detected by
examining the directory listing, looking for files with the same
size/date as the origin.
Filesystem migration:
NFSv4 probably wants to migrate file locks, but that's not really
our problem.
Atomic updates:
The NFSv4 working group wants atomic migration. Most of the
responsibility for this lies on the NFS server or OS.
If migrating a whole tree, then we could do a nearly-atomic rename
at the end. This ties in to having separate basis and destination
files.
There's no way in Unix to replace a whole set of files atomically.
However, if we get them all onto the destination machine and then do
the updates quickly it would greatly reduce the window.
Scalability:
We should aim to work well on machines in use in a year or two.
That probably means transfers of many millions of files in one
batch, and gigabytes or terabytes of data.
For argument's sake: at the low end, we want to sync ten files for a
total of 10kb across a 1kB/s link. At the high end, we want to sync
1e9 files for 1TB of data across a 1GB/s link.
On the whole CPU usage is not normally a limiting factor, if only
because running over SSH burns a lot of cycles on encryption.
Perhaps have resource throttling without relying on rlimit.
Streaming:
A big attraction of rsync is that there are few round-trip delays:
basically only one to get started, and then everything is
pipelined. This is a problem with FTP, and NFS (at least up to
v3). NFSv4 can pipeline operations, but building on that is
probably a bit complicated.
Related work:
- mirror.pl http://freshmeat.net/project/mirror/
- ProFTPd
- Apache
- http://freshmeat.net/search/?site=Freshmeat&q=mirror§ion=projects
- BitTorrent -- p2p mirroring
http://bitconjurer.org/BitTorrent/
rsync-3.1.0/t_stub.c 0000664 0000000 0000000 00000004450 12155744655 013036 0 ustar root root /*
* This file contains really simple implementations for rsync global
* functions, so that module test harnesses can run standalone.
*
* Copyright (C) 2001, 2002 Martin Pool
* Copyright (C) 2003-2013 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, visit the http://fsf.org website.
*/
#include "rsync.h"
int modify_window = 0;
int preallocate_files = 0;
int protect_args = 0;
int module_id = -1;
int checksum_len = 0;
int relative_paths = 0;
int module_dirlen = 0;
int preserve_acls = 0;
int preserve_times = 0;
int preserve_xattrs = 0;
char *partial_dir;
char *module_dir;
filter_rule_list daemon_filter_list;
void rprintf(UNUSED(enum logcode code), const char *format, ...)
{
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
}
void rsyserr(UNUSED(enum logcode code), int errcode, const char *format, ...)
{
va_list ap;
fputs(RSYNC_NAME ": ", stderr);
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
fprintf(stderr, ": %s (%d)\n", strerror(errcode), errcode);
}
void _exit_cleanup(int code, const char *file, int line)
{
fprintf(stderr, "exit(%d): %s(%d)\n",
code, file, line);
exit(code);
}
int check_filter(UNUSED(filter_rule_list *listp), UNUSED(enum logcode code),
UNUSED(const char *name), UNUSED(int name_is_dir))
{
/* This function doesn't really get called in this test context, so
* just return 0. */
return 0;
}
int copy_xattrs(UNUSED(const char *source), UNUSED(const char *dest))
{
return -1;
}
void free_xattr(UNUSED(stat_x *sxp))
{
return;
}
void free_acl(UNUSED(stat_x *sxp))
{
return;
}
char *lp_name(UNUSED(int mod))
{
return NULL;
}
BOOL lp_use_chroot(UNUSED(int mod))
{
return 0;
}
const char *who_am_i(void)
{
return "tester";
}
rsync-3.1.0/rsyncd.conf.5 0000664 0000000 0000000 00000135466 12221713423 013701 0 ustar root root .TH "rsyncd.conf" "5" "28 Sep 2013" "" ""
.SH "NAME"
rsyncd.conf \- configuration file for rsync in daemon mode
.SH "SYNOPSIS"
.PP
rsyncd.conf
.PP
.SH "DESCRIPTION"
.PP
The rsyncd.conf file is the runtime configuration file for rsync when
run as an rsync daemon.
.PP
The rsyncd.conf file controls authentication, access, logging and
available modules.
.PP
.SH "FILE FORMAT"
.PP
The file consists of modules and parameters. A module begins with the
name of the module in square brackets and continues until the next
module begins. Modules contain parameters of the form \(dq\&name = value\(dq\&.
.PP
The file is line\-based \-\- that is, each newline\-terminated line represents
either a comment, a module name or a parameter.
.PP
Only the first equals sign in a parameter is significant. Whitespace before
or after the first equals sign is discarded. Leading, trailing and internal
whitespace in module and parameter names is irrelevant. Leading and
trailing whitespace in a parameter value is discarded. Internal whitespace
within a parameter value is retained verbatim.
.PP
Any line \fBbeginning\fP with a hash (#) is ignored, as are lines containing
only whitespace. (If a hash occurs after anything other than leading
whitespace, it is considered a part of the line\(cq\&s content.)
.PP
Any line ending in a \e is \(dq\&continued\(dq\& on the next line in the
customary UNIX fashion.
.PP
The values following the equals sign in parameters are all either a string
(no quotes needed) or a boolean, which may be given as yes/no, 0/1 or
true/false. Case is not significant in boolean values, but is preserved
in string values.
.PP
.SH "LAUNCHING THE RSYNC DAEMON"
.PP
The rsync daemon is launched by specifying the \fB\-\-daemon\fP option to
rsync.
.PP
The daemon must run with root privileges if you wish to use chroot, to
bind to a port numbered under 1024 (as is the default 873), or to set
file ownership. Otherwise, it must just have permission to read and
write the appropriate data, log, and lock files.
.PP
You can launch it either via inetd, as a stand\-alone daemon, or from
an rsync client via a remote shell. If run as a stand\-alone daemon then
just run the command \(dq\&\fBrsync \-\-daemon\fP\(dq\& from a suitable startup script.
.PP
When run via inetd you should add a line like this to /etc/services:
.PP
.nf
rsync 873/tcp
.fi
.PP
and a single line something like this to /etc/inetd.conf:
.PP
.nf
rsync stream tcp nowait root /usr/bin/rsync rsyncd \-\-daemon
.fi
.PP
Replace \(dq\&/usr/bin/rsync\(dq\& with the path to where you have rsync installed on
your system. You will then need to send inetd a HUP signal to tell it to
reread its config file.
.PP
Note that you should \fBnot\fP send the rsync daemon a HUP signal to force
it to reread the \f(CWrsyncd.conf\fP file. The file is re\-read on each client
connection.
.PP
.SH "GLOBAL PARAMETERS"
.PP
The first parameters in the file (before a [module] header) are the
global parameters.
.PP
You may also include any module parameters in the global part of the
config file in which case the supplied value will override the
default for that parameter.
.PP
You may use references to environment variables in the values of parameters.
String parameters will have %VAR% references expanded as late as possible (when
the string is used in the program), allowing for the use of variables that
rsync sets at connection time, such as RSYNC_USER_NAME. Non\-string parameters
(such as true/false settings) are expanded when read from the config file. If
a variable does not exist in the environment, or if a sequence of characters is
not a valid reference (such as an un\-paired percent sign), the raw characters
are passed through unchanged. This helps with backward compatibility and
safety (e.g. expanding a non\-existent %VAR% to an empty string in a path could
result in a very unsafe path). The safest way to insert a literal % into a
value is to use %%.
.PP
.IP "\fBmotd file\fP"
This parameter allows you to specify a
\(dq\&message of the day\(dq\& to display to clients on each connect. This
usually contains site information and any legal notices. The default
is no motd file.
This can be overridden by the \fB\-\-dparam=motdfile=FILE\fP
command\-line option when starting the daemon.
.IP
.IP "\fBpid file\fP"
This parameter tells the rsync daemon to write
its process ID to that file. If the file already exists, the rsync
daemon will abort rather than overwrite the file.
This can be overridden by the \fB\-\-dparam=pidfile=FILE\fP
command\-line option when starting the daemon.
.IP
.IP "\fBport\fP"
You can override the default port the daemon will listen on
by specifying this value (defaults to 873). This is ignored if the daemon
is being run by inetd, and is superseded by the \fB\-\-port\fP command\-line option.
.IP
.IP "\fBaddress\fP"
You can override the default IP address the daemon
will listen on by specifying this value. This is ignored if the daemon is
being run by inetd, and is superseded by the \fB\-\-address\fP command\-line option.
.IP
.IP "\fBsocket options\fP"
This parameter can provide endless fun for people
who like to tune their systems to the utmost degree. You can set all
sorts of socket options which may make transfers faster (or
slower!). Read the man page for the
\f(CWsetsockopt()\fP
system call for
details on some of the options you may be able to set. By default no
special socket options are set. These settings can also be specified
via the \fB\-\-sockopts\fP command\-line option.
.IP
.IP "\fBlisten backlog\fP"
You can override the default backlog value when the
daemon listens for connections. It defaults to 5.
.IP
.SH "MODULE PARAMETERS"
.PP
After the global parameters you should define a number of modules, each
module exports a directory tree as a symbolic name. Modules are
exported by specifying a module name in square brackets [module]
followed by the parameters for that module.
The module name cannot contain a slash or a closing square bracket. If the
name contains whitespace, each internal sequence of whitespace will be
changed into a single space, while leading or trailing whitespace will be
discarded.
.PP
As with GLOBAL PARAMETERS, you may use references to environment variables in
the values of parameters. See the GLOBAL PARAMETERS section for more details.
.PP
.IP "\fBcomment\fP"
This parameter specifies a description string
that is displayed next to the module name when clients obtain a list
of available modules. The default is no comment.
.IP
.IP "\fBpath\fP"
This parameter specifies the directory in the daemon\(cq\&s
filesystem to make available in this module. You must specify this parameter
for each module in \f(CWrsyncd.conf\fP.
.IP
You may base the path\(cq\&s value off of an environment variable by surrounding
the variable name with percent signs. You can even reference a variable
that is set by rsync when the user connects.
For example, this would use the authorizing user\(cq\&s name in the path:
.IP
.nf
path = /home/%RSYNC_USER_NAME%
.fi
.IP
It is fine if the path includes internal spaces \-\- they will be retained
verbatim (which means that you shouldn\(cq\&t try to escape them). If your final
directory has a trailing space (and this is somehow not something you wish to
fix), append a trailing slash to the path to avoid losing the trailing
whitespace.
.IP
.IP "\fBuse chroot\fP"
If \(dq\&use chroot\(dq\& is true, the rsync daemon will chroot
to the \(dq\&path\(dq\& before starting the file transfer with the client. This has
the advantage of extra protection against possible implementation security
holes, but it has the disadvantages of requiring super\-user privileges,
of not being able to follow symbolic links that are either absolute or outside
of the new root path, and of complicating the preservation of users and groups
by name (see below).
.IP
As an additional safety feature, you can specify a dot\-dir in the module\(cq\&s
\(dq\&path\(dq\& to indicate the point where the chroot should occur. This allows rsync
to run in a chroot with a non\-\(dq\&/\(dq\& path for the top of the transfer hierarchy.
Doing this guards against unintended library loading (since those absolute
paths will not be inside the transfer hierarchy unless you have used an unwise
pathname), and lets you setup libraries for the chroot that are outside of the
transfer. For example, specifying \(dq\&/var/rsync/./module1\(dq\& will chroot to the
\(dq\&/var/rsync\(dq\& directory and set the inside\-chroot path to \(dq\&/module1\(dq\&. If you
had omitted the dot\-dir, the chroot would have used the whole path, and the
inside\-chroot path would have been \(dq\&/\(dq\&.
.IP
When \(dq\&use chroot\(dq\& is false or the inside\-chroot path is not \(dq\&/\(dq\&, rsync will:
(1) munge symlinks by
default for security reasons (see \(dq\&munge symlinks\(dq\& for a way to turn this
off, but only if you trust your users), (2) substitute leading slashes in
absolute paths with the module\(cq\&s path (so that options such as
\fB\-\-backup\-dir\fP, \fB\-\-compare\-dest\fP, etc. interpret an absolute path as
rooted in the module\(cq\&s \(dq\&path\(dq\& dir), and (3) trim \(dq\&..\(dq\& path elements from
args if rsync believes they would escape the module hierarchy.
The default for \(dq\&use chroot\(dq\& is true, and is the safer choice (especially
if the module is not read\-only).
.IP
When this parameter is enabled, rsync will not attempt to map users and groups
by name (by default), but instead copy IDs as though \fB\-\-numeric\-ids\fP had
been specified. In order to enable name\-mapping, rsync needs to be able to
use the standard library functions for looking up names and IDs (i.e.
\f(CWgetpwuid()\fP
,
\f(CWgetgrgid()\fP
,
\f(CWgetpwname()\fP
, and
\f(CWgetgrnam()\fP
).
This means the rsync
process in the chroot hierarchy will need to have access to the resources
used by these library functions (traditionally /etc/passwd and
/etc/group, but perhaps additional dynamic libraries as well).
.IP
If you copy the necessary resources into the module\(cq\&s chroot area, you
should protect them through your OS\(cq\&s normal user/group or ACL settings (to
prevent the rsync module\(cq\&s user from being able to change them), and then
hide them from the user\(cq\&s view via \(dq\&exclude\(dq\& (see how in the discussion of
that parameter). At that point it will be safe to enable the mapping of users
and groups by name using the \(dq\&numeric ids\(dq\& daemon parameter (see below).
.IP
Note also that you are free to setup custom user/group information in the
chroot area that is different from your normal system. For example, you
could abbreviate the list of users and groups.
.IP
.IP "\fBnumeric ids\fP"
Enabling this parameter disables the mapping
of users and groups by name for the current daemon module. This prevents
the daemon from trying to load any user/group\-related files or libraries.
This enabling makes the transfer behave as if the client had passed
the \fB\-\-numeric\-ids\fP command\-line option. By default, this parameter is
enabled for chroot modules and disabled for non\-chroot modules.
.IP
A chroot\-enabled module should not have this parameter enabled unless you\(cq\&ve
taken steps to ensure that the module has the necessary resources it needs
to translate names, and that it is not possible for a user to change those
resources.
.IP
.IP "\fBmunge symlinks\fP"
This parameter tells rsync to modify
all symlinks in the same way as the (non\-daemon\-affecting)
\fB\-\-munge\-links\fP command\-line option (using a method described below).
This should help protect your files from user trickery when
your daemon module is writable. The default is disabled when \(dq\&use chroot\(dq\&
is on and the inside\-chroot path is \(dq\&/\(dq\&, otherwise it is enabled.
.IP
If you disable this parameter on a daemon that is not read\-only, there
are tricks that a user can play with uploaded symlinks to access
daemon\-excluded items (if your module has any), and, if \(dq\&use chroot\(dq\&
is off, rsync can even be tricked into showing or changing data that
is outside the module\(cq\&s path (as access\-permissions allow).
.IP
The way rsync disables the use of symlinks is to prefix each one with
the string \(dq\&/rsyncd\-munged/\(dq\&. This prevents the links from being used
as long as that directory does not exist. When this parameter is enabled,
rsync will refuse to run if that path is a directory or a symlink to
a directory. When using the \(dq\&munge symlinks\(dq\& parameter in a chroot area
that has an inside\-chroot path of \(dq\&/\(dq\&, you should add \(dq\&/rsyncd\-munged/\(dq\&
to the exclude setting for the module so that
a user can\(cq\&t try to create it.
.IP
Note: rsync makes no attempt to verify that any pre\-existing symlinks in
the module\(cq\&s hierarchy are as safe as you want them to be (unless, of
course, it just copied in the whole hierarchy). If you setup an rsync
daemon on a new area or locally add symlinks, you can manually protect your
symlinks from being abused by prefixing \(dq\&/rsyncd\-munged/\(dq\& to the start of
every symlink\(cq\&s value. There is a perl script in the support directory
of the source code named \(dq\&munge\-symlinks\(dq\& that can be used to add or remove
this prefix from your symlinks.
.IP
When this parameter is disabled on a writable module and \(dq\&use chroot\(dq\& is off
(or the inside\-chroot path is not \(dq\&/\(dq\&),
incoming symlinks will be modified to drop a leading slash and to remove \(dq\&..\(dq\&
path elements that rsync believes will allow a symlink to escape the module\(cq\&s
hierarchy. There are tricky ways to work around this, though, so you had
better trust your users if you choose this combination of parameters.
.IP
.IP "\fBcharset\fP"
This specifies the name of the character set in which the
module\(cq\&s filenames are stored. If the client uses an \fB\-\-iconv\fP option,
the daemon will use the value of the \(dq\&charset\(dq\& parameter regardless of the
character set the client actually passed. This allows the daemon to
support charset conversion in a chroot module without extra files in the
chroot area, and also ensures that name\-translation is done in a consistent
manner. If the \(dq\&charset\(dq\& parameter is not set, the \fB\-\-iconv\fP option is
refused, just as if \(dq\&iconv\(dq\& had been specified via \(dq\&refuse options\(dq\&.
.IP
If you wish to force users to always use \fB\-\-iconv\fP for a particular
module, add \(dq\&no\-iconv\(dq\& to the \(dq\&refuse options\(dq\& parameter. Keep in mind
that this will restrict access to your module to very new rsync clients.
.IP
.IP "\fBmax connections\fP"
This parameter allows you to
specify the maximum number of simultaneous connections you will allow.
Any clients connecting when the maximum has been reached will receive a
message telling them to try later. The default is 0, which means no limit.
A negative value disables the module.
See also the \(dq\&lock file\(dq\& parameter.
.IP
.IP "\fBlog file\fP"
When the \(dq\&log file\(dq\& parameter is set to a non\-empty
string, the rsync daemon will log messages to the indicated file rather
than using syslog. This is particularly useful on systems (such as AIX)
where
\f(CWsyslog()\fP
doesn\(cq\&t work for chrooted programs. The file is
opened before
\f(CWchroot()\fP
is called, allowing it to be placed outside
the transfer. If this value is set on a per\-module basis instead of
globally, the global log will still contain any authorization failures
or config\-file error messages.
.IP
If the daemon fails to open the specified file, it will fall back to
using syslog and output an error about the failure. (Note that the
failure to open the specified log file used to be a fatal error.)
.IP
This setting can be overridden by using the \fB\-\-log\-file=FILE\fP or
\fB\-\-dparam=logfile=FILE\fP command\-line options. The former overrides
all the log\-file parameters of the daemon and all module settings.
The latter sets the daemon\(cq\&s log file and the default for all the
modules, which still allows modules to override the default setting.
.IP
.IP "\fBsyslog facility\fP"
This parameter allows you to
specify the syslog facility name to use when logging messages from the
rsync daemon. You may use any standard syslog facility name which is
defined on your system. Common names are auth, authpriv, cron, daemon,
ftp, kern, lpr, mail, news, security, syslog, user, uucp, local0,
local1, local2, local3, local4, local5, local6 and local7. The default
is daemon. This setting has no effect if the \(dq\&log file\(dq\& setting is a
non\-empty string (either set in the per\-modules settings, or inherited
from the global settings).
.IP
.IP "\fBmax verbosity\fP"
This parameter allows you to control
the maximum amount of verbose information that you\(cq\&ll allow the daemon to
generate (since the information goes into the log file). The default is 1,
which allows the client to request one level of verbosity.
.IP
.IP "\fBlock file\fP"
This parameter specifies the file to use to
support the \(dq\&max connections\(dq\& parameter. The rsync daemon uses record
locking on this file to ensure that the max connections limit is not
exceeded for the modules sharing the lock file.
The default is \f(CW/var/run/rsyncd.lock\fP.
.IP
.IP "\fBread only\fP"
This parameter determines whether clients
will be able to upload files or not. If \(dq\&read only\(dq\& is true then any
attempted uploads will fail. If \(dq\&read only\(dq\& is false then uploads will
be possible if file permissions on the daemon side allow them. The default
is for all modules to be read only.
.IP
Note that \(dq\&auth users\(dq\& can override this setting on a per\-user basis.
.IP
.IP "\fBwrite only\fP"
This parameter determines whether clients
will be able to download files or not. If \(dq\&write only\(dq\& is true then any
attempted downloads will fail. If \(dq\&write only\(dq\& is false then downloads
will be possible if file permissions on the daemon side allow them. The
default is for this parameter to be disabled.
.IP
.IP "\fBlist\fP"
This parameter determines whether this module is
listed when the client asks for a listing of available modules. In addition,
if this is false, the daemon will pretend the module does not exist
when a client denied by \(dq\&hosts allow\(dq\& or \(dq\&hosts deny\(dq\& attempts to access it.
Realize that if \(dq\&reverse lookup\(dq\& is disabled globally but enabled for the
module, the resulting reverse lookup to a potentially client\-controlled DNS
server may still reveal to the client that it hit an existing module.
The default is for modules to be listable.
.IP
.IP "\fBuid\fP"
This parameter specifies the user name or user ID that
file transfers to and from that module should take place as when the daemon
was run as root. In combination with the \(dq\&gid\(dq\& parameter this determines what
file permissions are available. The default when run by a super\-user is to
switch to the system\(cq\&s \(dq\&nobody\(dq\& user. The default for a non\-super\-user is to
not try to change the user. See also the \(dq\&gid\(dq\& parameter.
.IP
The RSYNC_USER_NAME environment variable may be used to request that rsync run
as the authorizing user. For example, if you want a rsync to run as the same
user that was received for the rsync authentication, this setup is useful:
.IP
.nf
uid = %RSYNC_USER_NAME%
gid = *
.fi
.IP
.IP "\fBgid\fP"
This parameter specifies one or more group names/IDs that will be
used when accessing the module. The first one will be the default group, and
any extra ones be set as supplemental groups. You may also specify a \(dq\&*\(dq\& as
the first gid in the list, which will be replaced by all the normal groups for
the transfer\(cq\&s user (see \(dq\&uid\(dq\&). The default when run by a super\-user is to
switch to your OS\(cq\&s \(dq\&nobody\(dq\& (or perhaps \(dq\&nogroup\(dq\&) group with no other
supplementary groups. The default for a non\-super\-user is to not change any
group attributes (and indeed, your OS may not allow a non\-super\-user to try to
change their group settings).
.IP
.IP "\fBfake super\fP"
Setting \(dq\&fake super = yes\(dq\& for a module causes the
daemon side to behave as if the \fB\-\-fake\-super\fP command\-line option had
been specified. This allows the full attributes of a file to be stored
without having to have the daemon actually running as root.
.IP
.IP "\fBfilter\fP"
The daemon has its own filter chain that determines what files
it will let the client access. This chain is not sent to the client and is
independent of any filters the client may have specified. Files excluded by
the daemon filter chain (\fBdaemon\-excluded\fP files) are treated as non\-existent
if the client tries to pull them, are skipped with an error message if the
client tries to push them (triggering exit code 23), and are never deleted from
the module. You can use daemon filters to prevent clients from downloading or
tampering with private administrative files, such as files you may add to
support uid/gid name translations.
.IP
The daemon filter chain is built from the \(dq\&filter\(dq\&, \(dq\&include from\(dq\&, \(dq\&include\(dq\&,
\(dq\&exclude from\(dq\&, and \(dq\&exclude\(dq\& parameters, in that order of priority. Anchored
patterns are anchored at the root of the module. To prevent access to an
entire subtree, for example, \(dq\&/secret\(dq\&, you \fImust\fP exclude everything in the
subtree; the easiest way to do this is with a triple\-star pattern like
\(dq\&/secret/***\(dq\&.
.IP
The \(dq\&filter\(dq\& parameter takes a space\-separated list of daemon filter rules,
though it is smart enough to know not to split a token at an internal space in
a rule (e.g. \(dq\&\- /foo \- /bar\(dq\& is parsed as two rules). You may specify one or
more merge\-file rules using the normal syntax. Only one \(dq\&filter\(dq\& parameter can
apply to a given module in the config file, so put all the rules you want in a
single parameter. Note that per\-directory merge\-file rules do not provide as
much protection as global rules, but they can be used to make \fB\-\-delete\fP work
better during a client download operation if the per\-dir merge files are
included in the transfer and the client requests that they be used.
.IP
.IP "\fBexclude\fP"
This parameter takes a space\-separated list of daemon
exclude patterns. As with the client \fB\-\-exclude\fP option, patterns can be
qualified with \(dq\&\- \(dq\& or \(dq\&+ \(dq\& to explicitly indicate exclude/include. Only one
\(dq\&exclude\(dq\& parameter can apply to a given module. See the \(dq\&filter\(dq\& parameter
for a description of how excluded files affect the daemon.
.IP
.IP "\fBinclude\fP"
Use an \(dq\&include\(dq\& to override the effects of the \(dq\&exclude\(dq\&
parameter. Only one \(dq\&include\(dq\& parameter can apply to a given module. See the
\(dq\&filter\(dq\& parameter for a description of how excluded files affect the daemon.
.IP
.IP "\fBexclude from\fP"
This parameter specifies the name of a file
on the daemon that contains daemon exclude patterns, one per line. Only one
\(dq\&exclude from\(dq\& parameter can apply to a given module; if you have multiple
exclude\-from files, you can specify them as a merge file in the \(dq\&filter\(dq\&
parameter. See the \(dq\&filter\(dq\& parameter for a description of how excluded files
affect the daemon.
.IP
.IP "\fBinclude from\fP"
Analogue of \(dq\&exclude from\(dq\& for a file of daemon include
patterns. Only one \(dq\&include from\(dq\& parameter can apply to a given module. See
the \(dq\&filter\(dq\& parameter for a description of how excluded files affect the
daemon.
.IP
.IP "\fBincoming chmod\fP"
This parameter allows you to specify a set of
comma\-separated chmod strings that will affect the permissions of all
incoming files (files that are being received by the daemon). These
changes happen after all other permission calculations, and this will
even override destination\-default and/or existing permissions when the
client does not specify \fB\-\-perms\fP.
See the description of the \fB\-\-chmod\fP rsync option and the \fBchmod\fP(1)
manpage for information on the format of this string.
.IP
.IP "\fBoutgoing chmod\fP"
This parameter allows you to specify a set of
comma\-separated chmod strings that will affect the permissions of all
outgoing files (files that are being sent out from the daemon). These
changes happen first, making the sent permissions appear to be different
than those stored in the filesystem itself. For instance, you could
disable group write permissions on the server while having it appear to
be on to the clients.
See the description of the \fB\-\-chmod\fP rsync option and the \fBchmod\fP(1)
manpage for information on the format of this string.
.IP
.IP "\fBauth users\fP"
This parameter specifies a comma and/or space\-separated
list of authorization rules. In its simplest form, you list the usernames
that will be allowed to connect to
this module. The usernames do not need to exist on the local
system. The rules may contain shell wildcard characters that will be matched
against the username provided by the client for authentication. If
\(dq\&auth users\(dq\& is set then the client will be challenged to supply a
username and password to connect to the module. A challenge response
authentication protocol is used for this exchange. The plain text
usernames and passwords are stored in the file specified by the
\(dq\&secrets file\(dq\& parameter. The default is for all users to be able to
connect without a password (this is called \(dq\&anonymous rsync\(dq\&).
.IP
In addition to username matching, you can specify groupname matching via a \(cq\&@\(cq\&
prefix. When using groupname matching, the authenticating username must be a
real user on the system, or it will be assumed to be a member of no groups.
For example, specifying \(dq\&@rsync\(dq\& will match the authenticating user if the
named user is a member of the rsync group.
.IP
Finally, options may be specified after a colon (:). The options allow you to
\(dq\&deny\(dq\& a user or a group, set the access to \(dq\&ro\(dq\& (read\-only), or set the access
to \(dq\&rw\(dq\& (read/write). Setting an auth\-rule\-specific ro/rw setting overrides
the module\(cq\&s \(dq\&read only\(dq\& setting.
.IP
Be sure to put the rules in the order you want them to be matched, because the
checking stops at the first matching user or group, and that is the only auth
that is checked. For example:
.IP
.nf
auth users = joe:deny @guest:deny admin:rw @rsync:ro susan joe sam
.fi
.IP
In the above rule, user joe will be denied access no matter what. Any user
that is in the group \(dq\&guest\(dq\& is also denied access. The user \(dq\&admin\(dq\& gets
access in read/write mode, but only if the admin user is not in group \(dq\&guest\(dq\&
(because the admin user\-matching rule would never be reached if the user is in
group \(dq\&guest\(dq\&). Any other user who is in group \(dq\&rsync\(dq\& will get read\-only
access. Finally, users susan, joe, and sam get the ro/rw setting of the
module, but only if the user didn\(cq\&t match an earlier group\-matching rule.
.IP
See the description of the secrets file for how you can have per\-user passwords
as well as per\-group passwords. It also explains how a user can authenticate
using their user password or (when applicable) a group password, depending on
what rule is being authenticated.
.IP
See also the section entitled \(dq\&USING RSYNC\-DAEMON FEATURES VIA A REMOTE
SHELL CONNECTION\(dq\& in \fBrsync\fP(1) for information on how handle an
rsyncd.conf\-level username that differs from the remote\-shell\-level
username when using a remote shell to connect to an rsync daemon.
.IP
.IP "\fBsecrets file\fP"
This parameter specifies the name of a file that contains
the username:password and/or @groupname:password pairs used for authenticating
this module. This file is only consulted if the \(dq\&auth users\(dq\& parameter is
specified. The file is line\-based and contains one name:password pair per
line. Any line has a hash (#) as the very first character on the line is
considered a comment and is skipped. The passwords can contain any characters
but be warned that many operating systems limit the length of passwords that
can be typed at the client end, so you may find that passwords longer than 8
characters don\(cq\&t work.
.IP
The use of group\-specific lines are only relevant when the module is being
authorized using a matching \(dq\&@groupname\(dq\& rule. When that happens, the user
can be authorized via either their \(dq\&username:password\(dq\& line or the
\(dq\&@groupname:password\(dq\& line for the group that triggered the authentication.
.IP
It is up to you what kind of password entries you want to include, either
users, groups, or both. The use of group rules in \(dq\&auth users\(dq\& does not
require that you specify a group password if you do not want to use shared
passwords.
.IP
There is no default for the \(dq\&secrets file\(dq\& parameter, you must choose a name
(such as \f(CW/etc/rsyncd.secrets\fP). The file must normally not be readable
by \(dq\&other\(dq\&; see \(dq\&strict modes\(dq\&. If the file is not found or is rejected, no
logins for a \(dq\&user auth\(dq\& module will be possible.
.IP
.IP "\fBstrict modes\fP"
This parameter determines whether or not
the permissions on the secrets file will be checked. If \(dq\&strict modes\(dq\& is
true, then the secrets file must not be readable by any user ID other
than the one that the rsync daemon is running under. If \(dq\&strict modes\(dq\& is
false, the check is not performed. The default is true. This parameter
was added to accommodate rsync running on the Windows operating system.
.IP
.IP "\fBhosts allow\fP"
This parameter allows you to specify a
list of patterns that are matched against a connecting clients
hostname and IP address. If none of the patterns match then the
connection is rejected.
.IP
Each pattern can be in one of five forms:
.IP
.RS
.IP o
a dotted decimal IPv4 address of the form a.b.c.d, or an IPv6 address
of the form a:b:c::d:e:f. In this case the incoming machine\(cq\&s IP address
must match exactly.
.IP o
an address/mask in the form ipaddr/n where ipaddr is the IP address
and n is the number of one bits in the netmask. All IP addresses which
match the masked IP address will be allowed in.
.IP o
an address/mask in the form ipaddr/maskaddr where ipaddr is the
IP address and maskaddr is the netmask in dotted decimal notation for IPv4,
or similar for IPv6, e.g. ffff:ffff:ffff:ffff:: instead of /64. All IP
addresses which match the masked IP address will be allowed in.
.IP o
a hostname pattern using wildcards. If the hostname of the connecting IP
(as determined by a reverse lookup) matches the wildcarded name (using the
same rules as normal unix filename matching), the client is allowed in. This
only works if \(dq\&reverse lookup\(dq\& is enabled (the default).
.IP o
a hostname. A plain hostname is matched against the reverse DNS of the
connecting IP (if \(dq\&reverse lookup\(dq\& is enabled), and/or the IP of the given
hostname is matched against the connecting IP (if \(dq\&forward lookup\(dq\& is
enabled, as it is by default). Any match will be allowed in.
.RE
.IP
Note IPv6 link\-local addresses can have a scope in the address specification:
.IP
.RS
\f(CW fe80::1%link1\fP
.br
\f(CW fe80::%link1/64\fP
.br
\f(CW fe80::%link1/ffff:ffff:ffff:ffff::\fP
.br
.RE
.IP
You can also combine \(dq\&hosts allow\(dq\& with a separate \(dq\&hosts deny\(dq\&
parameter. If both parameters are specified then the \(dq\&hosts allow\(dq\& parameter is
checked first and a match results in the client being able to
connect. The \(dq\&hosts deny\(dq\& parameter is then checked and a match means
that the host is rejected. If the host does not match either the
\(dq\&hosts allow\(dq\& or the \(dq\&hosts deny\(dq\& patterns then it is allowed to
connect.
.IP
The default is no \(dq\&hosts allow\(dq\& parameter, which means all hosts can connect.
.IP
.IP "\fBhosts deny\fP"
This parameter allows you to specify a
list of patterns that are matched against a connecting clients
hostname and IP address. If the pattern matches then the connection is
rejected. See the \(dq\&hosts allow\(dq\& parameter for more information.
.IP
The default is no \(dq\&hosts deny\(dq\& parameter, which means all hosts can connect.
.IP
.IP "\fBreverse lookup\fP"
Controls whether the daemon performs a reverse lookup
on the client\(cq\&s IP address to determine its hostname, which is used for
\(dq\&hosts allow\(dq\&/\(dq\&hosts deny\(dq\& checks and the \(dq\&%h\(dq\& log escape. This is enabled by
default, but you may wish to disable it to save time if you know the lookup will
not return a useful result, in which case the daemon will use the name
\(dq\&UNDETERMINED\(dq\& instead.
.IP
If this parameter is enabled globally (even by default), rsync performs the
lookup as soon as a client connects, so disabling it for a module will not
avoid the lookup. Thus, you probably want to disable it globally and then
enable it for modules that need the information.
.IP
.IP "\fBforward lookup\fP"
Controls whether the daemon performs a forward lookup
on any hostname specified in an hosts allow/deny setting. By default this is
enabled, allowing the use of an explicit hostname that would not be returned
by reverse DNS of the connecting IP.
.IP
.IP "\fBignore errors\fP"
This parameter tells rsyncd to
ignore I/O errors on the daemon when deciding whether to run the delete
phase of the transfer. Normally rsync skips the \fB\-\-delete\fP step if any
I/O errors have occurred in order to prevent disastrous deletion due
to a temporary resource shortage or other I/O error. In some cases this
test is counter productive so you can use this parameter to turn off this
behavior.
.IP
.IP "\fBignore nonreadable\fP"
This tells the rsync daemon to completely
ignore files that are not readable by the user. This is useful for
public archives that may have some non\-readable files among the
directories, and the sysadmin doesn\(cq\&t want those files to be seen at all.
.IP
.IP "\fBtransfer logging\fP"
This parameter enables per\-file
logging of downloads and uploads in a format somewhat similar to that
used by ftp daemons. The daemon always logs the transfer at the end, so
if a transfer is aborted, no mention will be made in the log file.
.IP
If you want to customize the log lines, see the \(dq\&log format\(dq\& parameter.
.IP
.IP "\fBlog format\fP"
This parameter allows you to specify the
format used for logging file transfers when transfer logging is enabled.
The format is a text string containing embedded single\-character escape
sequences prefixed with a percent (%) character. An optional numeric
field width may also be specified between the percent and the escape
letter (e.g. \(dq\&\fB%\-50n %8l %07p\fP\(dq\&).
In addition, one or more apostrophes may be specified prior to a numerical
escape to indicate that the numerical value should be made more human\-readable.
The 3 supported levels are the same as for the \fB\-\-human\-readable\fP
command\-line option, though the default is for human\-readability to be off.
Each added apostrophe increases the level (e.g. \(dq\&\fB%'\&'\&l %'\&b %f\fP\(dq\&).
.IP
The default log format is \(dq\&%o %h [%a] %m (%u) %f %l\(dq\&, and a \(dq\&%t [%p] \(dq\&
is always prefixed when using the \(dq\&log file\(dq\& parameter.
(A perl script that will summarize this default log format is included
in the rsync source code distribution in the \(dq\&support\(dq\& subdirectory:
rsyncstats.)
.IP
The single\-character escapes that are understood are as follows:
.IP
.RS
.IP o
%a the remote IP address (only available for a daemon)
.IP o
%b the number of bytes actually transferred
.IP o
%B the permission bits of the file (e.g. rwxrwxrwt)
.IP o
%c the total size of the block checksums received for the basis file (only when sending)
.IP o
%C the full\-file MD5 checksum if \fB\-\-checksum\fP is enabled or a file was transferred (only for protocol 30 or above).
.IP o
%f the filename (long form on sender; no trailing \(dq\&/\(dq\&)
.IP o
%G the gid of the file (decimal) or \(dq\&DEFAULT\(dq\&
.IP o
%h the remote host name (only available for a daemon)
.IP o
%i an itemized list of what is being updated
.IP o
%l the length of the file in bytes
.IP o
%L the string \(dq\& \-> SYMLINK\(dq\&, \(dq\& => HARDLINK\(dq\&, or \(dq\&\(dq\& (where \fBSYMLINK\fP or \fBHARDLINK\fP is a filename)
.IP o
%m the module name
.IP o
%M the last\-modified time of the file
.IP o
%n the filename (short form; trailing \(dq\&/\(dq\& on dir)
.IP o
%o the operation, which is \(dq\&send\(dq\&, \(dq\&recv\(dq\&, or \(dq\&del.\(dq\& (the latter includes the trailing period)
.IP o
%p the process ID of this rsync session
.IP o
%P the module path
.IP o
%t the current date time
.IP o
%u the authenticated username or an empty string
.IP o
%U the uid of the file (decimal)
.RE
.IP
For a list of what the characters mean that are output by \(dq\&%i\(dq\&, see the
\fB\-\-itemize\-changes\fP option in the rsync manpage.
.IP
Note that some of the logged output changes when talking with older
rsync versions. For instance, deleted files were only output as verbose
messages prior to rsync 2.6.4.
.IP
.IP "\fBtimeout\fP"
This parameter allows you to override the
clients choice for I/O timeout for this module. Using this parameter you
can ensure that rsync won\(cq\&t wait on a dead client forever. The timeout
is specified in seconds. A value of zero means no timeout and is the
default. A good choice for anonymous rsync daemons may be 600 (giving
a 10 minute timeout).
.IP
.IP "\fBrefuse options\fP"
This parameter allows you to
specify a space\-separated list of rsync command line options that will
be refused by your rsync daemon.
You may specify the full option name, its one\-letter abbreviation, or a
wild\-card string that matches multiple options.
For example, this would refuse \fB\-\-checksum\fP (\fB\-c\fP) and all the various
delete options:
.IP
.RS
\f(CW refuse options = c delete\fP
.RE
.IP
The reason the above refuses all delete options is that the options imply
\fB\-\-delete\fP, and implied options are refused just like explicit options.
As an additional safety feature, the refusal of \(dq\&delete\(dq\& also refuses
\fBremove\-source\-files\fP when the daemon is the sender; if you want the latter
without the former, instead refuse \(dq\&delete\-*\(dq\& \-\- that refuses all the
delete modes without affecting \fB\-\-remove\-source\-files\fP.
.IP
When an option is refused, the daemon prints an error message and exits.
To prevent all compression when serving files,
you can use \(dq\&dont compress = *\(dq\& (see below)
instead of \(dq\&refuse options = compress\(dq\& to avoid returning an error to a
client that requests compression.
.IP
.IP "\fBdont compress\fP"
This parameter allows you to select
filenames based on wildcard patterns that should not be compressed
when pulling files from the daemon (no analogous parameter exists to
govern the pushing of files to a daemon).
Compression is expensive in terms of CPU usage, so it
is usually good to not try to compress files that won\(cq\&t compress well,
such as already compressed files.
.IP
The \(dq\&dont compress\(dq\& parameter takes a space\-separated list of
case\-insensitive wildcard patterns. Any source filename matching one
of the patterns will not be compressed during transfer.
.IP
See the \fB\-\-skip\-compress\fP parameter in the \fBrsync\fP(1) manpage for the list
of file suffixes that are not compressed by default. Specifying a value
for the \(dq\&dont compress\(dq\& parameter changes the default when the daemon is
the sender.
.IP
.IP "\fBpre\-xfer exec\fP, \fBpost\-xfer exec\fP"
You may specify a command to be run
before and/or after the transfer. If the \fBpre\-xfer exec\fP command fails, the
transfer is aborted before it begins. Any output from the script on stdout (up
to several KB) will be displayed to the user when aborting, but is NOT
displayed if the script returns success. Any output from the script on stderr
goes to the daemon\(cq\&s stderr, which is typically discarded (though see
\-\-no\-detatch option for a way to see the stderr output, which can assist with
debugging).
.IP
The following environment variables will be set, though some are
specific to the pre\-xfer or the post\-xfer environment:
.IP
.RS
.IP o
\fBRSYNC_MODULE_NAME\fP: The name of the module being accessed.
.IP o
\fBRSYNC_MODULE_PATH\fP: The path configured for the module.
.IP o
\fBRSYNC_HOST_ADDR\fP: The accessing host\(cq\&s IP address.
.IP o
\fBRSYNC_HOST_NAME\fP: The accessing host\(cq\&s name.
.IP o
\fBRSYNC_USER_NAME\fP: The accessing user\(cq\&s name (empty if no user).
.IP o
\fBRSYNC_PID\fP: A unique number for this transfer.
.IP o
\fBRSYNC_REQUEST\fP: (pre\-xfer only) The module/path info specified
by the user. Note that the user can specify multiple source files,
so the request can be something like \(dq\&mod/path1 mod/path2\(dq\&, etc.
.IP o
\fBRSYNC_ARG#\fP: (pre\-xfer only) The pre\-request arguments are set
in these numbered values. RSYNC_ARG0 is always \(dq\&rsyncd\(dq\&, followed by
the options that were used in RSYNC_ARG1, and so on. There will be a
value of \(dq\&.\(dq\& indicating that the options are done and the path args
are beginning \-\- these contain similar information to RSYNC_REQUEST,
but with values separated and the module name stripped off.
.IP o
\fBRSYNC_EXIT_STATUS\fP: (post\-xfer only) the server side\(cq\&s exit value.
This will be 0 for a successful run, a positive value for an error that the
server generated, or a \-1 if rsync failed to exit properly. Note that an
error that occurs on the client side does not currently get sent to the
server side, so this is not the final exit status for the whole transfer.
.IP o
\fBRSYNC_RAW_STATUS\fP: (post\-xfer only) the raw exit value from
\f(CWwaitpid()\fP
\&.
.RE
.IP
Even though the commands can be associated with a particular module, they
are run using the permissions of the user that started the daemon (not the
module\(cq\&s uid/gid setting) without any chroot restrictions.
.IP
.SH "CONFIG DIRECTIVES"
.PP
There are currently two config directives available that allow a config file to
incorporate the contents of other files: \fB&include\fP and \fB&merge\fP. Both
allow a reference to either a file or a directory. They differ in how
segregated the file\(cq\&s contents are considered to be.
.PP
The \fB&include\fP directive treats each file as more distinct, with each one
inheriting the defaults of the parent file, starting the parameter parsing
as globals/defaults, and leaving the defaults unchanged for the parsing of
the rest of the parent file.
.PP
The \fB&merge\fP directive, on the other hand, treats the file\(cq\&s contents as
if it were simply inserted in place of the directive, and thus it can set
parameters in a module started in another file, can affect the defaults for
other files, etc.
.PP
When an \fB&include\fP or \fB&merge\fP directive refers to a directory, it will read
in all the \fB*.conf\fP or \fB*.inc\fP files (respectively) that are contained inside
that directory (without any
recursive scanning), with the files sorted into alpha order. So, if you have a
directory named \(dq\&rsyncd.d\(dq\& with the files \(dq\&foo.conf\(dq\&, \(dq\&bar.conf\(dq\&, and
\(dq\&baz.conf\(dq\& inside it, this directive:
.PP
.nf
&include /path/rsyncd.d
.fi
.PP
would be the same as this set of directives:
.PP
.nf
&include /path/rsyncd.d/bar.conf
&include /path/rsyncd.d/baz.conf
&include /path/rsyncd.d/foo.conf
.fi
.PP
except that it adjusts as files are added and removed from the directory.
.PP
The advantage of the \fB&include\fP directive is that you can define one or more
modules in a separate file without worrying about unintended side\-effects
between the self\-contained module files.
.PP
The advantage of the \fB&merge\fP directive is that you can load config snippets
that can be included into multiple module definitions, and you can also set
global values that will affect connections (such as \fBmotd file\fP), or globals
that will affect other include files.
.PP
For example, this is a useful /etc/rsyncd.conf file:
.PP
.nf
port = 873
log file = /var/log/rsync.log
pid file = /var/lock/rsync.lock
&merge /etc/rsyncd.d
&include /etc/rsyncd.d
.fi
.PP
This would merge any /etc/rsyncd.d/*.inc files (for global values that should
stay in effect), and then include any /etc/rsyncd.d/*.conf files (defining
modules without any global\-value cross\-talk).
.PP
.SH "AUTHENTICATION STRENGTH"
.PP
The authentication protocol used in rsync is a 128 bit MD4 based
challenge response system. This is fairly weak protection, though (with
at least one brute\-force hash\-finding algorithm publicly available), so
if you want really top\-quality security, then I recommend that you run
rsync over ssh. (Yes, a future version of rsync will switch over to a
stronger hashing method.)
.PP
Also note that the rsync daemon protocol does not currently provide any
encryption of the data that is transferred over the connection. Only
authentication is provided. Use ssh as the transport if you want
encryption.
.PP
Future versions of rsync may support SSL for better authentication and
encryption, but that is still being investigated.
.PP
.SH "EXAMPLES"
.PP
A simple rsyncd.conf file that allow anonymous rsync to a ftp area at
\f(CW/home/ftp\fP would be:
.PP
.nf
[ftp]
path = /home/ftp
comment = ftp export area
.fi
.PP
A more sophisticated example would be:
.PP
.nf
uid = nobody
gid = nobody
use chroot = yes
max connections = 4
syslog facility = local5
pid file = /var/run/rsyncd.pid
[ftp]
path = /var/ftp/./pub
comment = whole ftp area (approx 6.1 GB)
[sambaftp]
path = /var/ftp/./pub/samba
comment = Samba ftp area (approx 300 MB)
[rsyncftp]
path = /var/ftp/./pub/rsync
comment = rsync ftp area (approx 6 MB)
[sambawww]
path = /public_html/samba
comment = Samba WWW pages (approx 240 MB)
[cvs]
path = /data/cvs
comment = CVS repository (requires authentication)
auth users = tridge, susan
secrets file = /etc/rsyncd.secrets
.fi
.PP
The /etc/rsyncd.secrets file would look something like this:
.PP
.RS
\f(CWtridge:mypass\fP
.br
\f(CWsusan:herpass\fP
.br
.RE
.PP
.SH "FILES"
.PP
/etc/rsyncd.conf or rsyncd.conf
.PP
.SH "SEE ALSO"
.PP
\fBrsync\fP(1)
.PP
.SH "DIAGNOSTICS"
.PP
.SH "BUGS"
.PP
Please report bugs! The rsync bug tracking system is online at
http://rsync.samba.org/
.PP
.SH "VERSION"
.PP
This man page is current for version 3.1.0 of rsync.
.PP
.SH "CREDITS"
.PP
rsync is distributed under the GNU General Public License. See the file
COPYING for details.
.PP
The primary ftp site for rsync is
ftp://rsync.samba.org/pub/rsync.
.PP
A WEB site is available at
http://rsync.samba.org/
.PP
We would be delighted to hear from you if you like this program.
.PP
This program uses the zlib compression library written by Jean\-loup
Gailly and Mark Adler.
.PP
.SH "THANKS"
.PP
Thanks to Warren Stanley for his original idea and patch for the rsync
daemon. Thanks to Karsten Thygesen for his many suggestions and
documentation!
.PP
.SH "AUTHOR"
.PP
rsync was written by Andrew Tridgell and Paul Mackerras.
Many people have later contributed to it.
.PP
Mailing lists for support and development are available at
http://lists.samba.org
rsync-3.1.0/pipe.c 0000664 0000000 0000000 00000012156 12076567221 012467 0 ustar root root /*
* Routines used to setup various kinds of inter-process pipes.
*
* Copyright (C) 1996-2000 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2001, 2002 Martin Pool
* Copyright (C) 2004-2013 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, visit the http://fsf.org website.
*/
#include "rsync.h"
extern int am_sender;
extern int am_server;
extern int blocking_io;
extern int filesfrom_fd;
extern int munge_symlinks;
extern char *logfile_name;
extern int remote_option_cnt;
extern const char **remote_options;
extern struct chmod_mode_struct *chmod_modes;
/**
* Create a child connected to us via its stdin/stdout.
*
* This is derived from CVS code
*
* Note that in the child STDIN is set to blocking and STDOUT
* is set to non-blocking. This is necessary as rsh relies on stdin being blocking
* and ssh relies on stdout being non-blocking
*
* If blocking_io is set then use blocking io on both fds. That can be
* used to cope with badly broken rsh implementations like the one on
* Solaris.
**/
pid_t piped_child(char **command, int *f_in, int *f_out)
{
pid_t pid;
int to_child_pipe[2];
int from_child_pipe[2];
if (DEBUG_GTE(CMD, 1))
print_child_argv("opening connection using:", command);
if (fd_pair(to_child_pipe) < 0 || fd_pair(from_child_pipe) < 0) {
rsyserr(FERROR, errno, "pipe");
exit_cleanup(RERR_IPC);
}
pid = do_fork();
if (pid == -1) {
rsyserr(FERROR, errno, "fork");
exit_cleanup(RERR_IPC);
}
if (pid == 0) {
if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 ||
close(to_child_pipe[1]) < 0 ||
close(from_child_pipe[0]) < 0 ||
dup2(from_child_pipe[1], STDOUT_FILENO) < 0) {
rsyserr(FERROR, errno, "Failed to dup/close");
exit_cleanup(RERR_IPC);
}
if (to_child_pipe[0] != STDIN_FILENO)
close(to_child_pipe[0]);
if (from_child_pipe[1] != STDOUT_FILENO)
close(from_child_pipe[1]);
set_blocking(STDIN_FILENO);
if (blocking_io > 0)
set_blocking(STDOUT_FILENO);
execvp(command[0], command);
rsyserr(FERROR, errno, "Failed to exec %s", command[0]);
exit_cleanup(RERR_IPC);
}
if (close(from_child_pipe[1]) < 0 || close(to_child_pipe[0]) < 0) {
rsyserr(FERROR, errno, "Failed to close");
exit_cleanup(RERR_IPC);
}
*f_in = from_child_pipe[0];
*f_out = to_child_pipe[1];
return pid;
}
/* This function forks a child which calls child_main(). First,
* however, it has to establish communication paths to and from the
* newborn child. It creates two socket pairs -- one for writing to
* the child (from the parent) and one for reading from the child
* (writing to the parent). Since that's four socket ends, each
* process has to close the two ends it doesn't need. The remaining
* two socket ends are retained for reading and writing. In the
* child, the STDIN and STDOUT file descriptors refer to these
* sockets. In the parent, the function arguments f_in and f_out are
* set to refer to these sockets. */
pid_t local_child(int argc, char **argv, int *f_in, int *f_out,
int (*child_main)(int, char*[]))
{
pid_t pid;
int to_child_pipe[2];
int from_child_pipe[2];
/* The parent process is always the sender for a local rsync. */
assert(am_sender);
if (fd_pair(to_child_pipe) < 0 ||
fd_pair(from_child_pipe) < 0) {
rsyserr(FERROR, errno, "pipe");
exit_cleanup(RERR_IPC);
}
pid = do_fork();
if (pid == -1) {
rsyserr(FERROR, errno, "fork");
exit_cleanup(RERR_IPC);
}
if (pid == 0) {
am_sender = 0;
am_server = 1;
filesfrom_fd = -1;
munge_symlinks = 0; /* Each side needs its own option. */
chmod_modes = NULL; /* Let the sending side handle this. */
/* Let the client side handle this. */
if (logfile_name) {
logfile_name = NULL;
logfile_close();
}
if (remote_option_cnt) {
int rc = remote_option_cnt + 1;
const char **rv = remote_options;
if (!parse_arguments(&rc, &rv)) {
option_error();
exit_cleanup(RERR_SYNTAX);
}
}
if (dup2(to_child_pipe[0], STDIN_FILENO) < 0 ||
close(to_child_pipe[1]) < 0 ||
close(from_child_pipe[0]) < 0 ||
dup2(from_child_pipe[1], STDOUT_FILENO) < 0) {
rsyserr(FERROR, errno, "Failed to dup/close");
exit_cleanup(RERR_IPC);
}
if (to_child_pipe[0] != STDIN_FILENO)
close(to_child_pipe[0]);
if (from_child_pipe[1] != STDOUT_FILENO)
close(from_child_pipe[1]);
#ifdef ICONV_CONST
setup_iconv();
#endif
child_main(argc, argv);
}
if (close(from_child_pipe[1]) < 0 ||
close(to_child_pipe[0]) < 0) {
rsyserr(FERROR, errno, "Failed to close");
exit_cleanup(RERR_IPC);
}
*f_in = from_child_pipe[0];
*f_out = to_child_pipe[1];
return pid;
}
rsync-3.1.0/aclocal.m4 0000664 0000000 0000000 00000006146 10712707021 013215 0 ustar root root dnl AC_VALIDATE_CACHE_SYSTEM_TYPE[(cmd)]
dnl if the cache file is inconsistent with the current host,
dnl target and build system types, execute CMD or print a default
dnl error message.
AC_DEFUN(AC_VALIDATE_CACHE_SYSTEM_TYPE, [
AC_REQUIRE([AC_CANONICAL_SYSTEM])
AC_MSG_CHECKING([config.cache system type])
if { test x"${ac_cv_host_system_type+set}" = x"set" &&
test x"$ac_cv_host_system_type" != x"$host"; } ||
{ test x"${ac_cv_build_system_type+set}" = x"set" &&
test x"$ac_cv_build_system_type" != x"$build"; } ||
{ test x"${ac_cv_target_system_type+set}" = x"set" &&
test x"$ac_cv_target_system_type" != x"$target"; }; then
AC_MSG_RESULT([different])
ifelse($#, 1, [$1],
[AC_MSG_ERROR(["you must remove config.cache and restart configure"])])
else
AC_MSG_RESULT([same])
fi
ac_cv_host_system_type="$host"
ac_cv_build_system_type="$build"
ac_cv_target_system_type="$target"
])
dnl Check for socklen_t: historically on BSD it is an int, and in
dnl POSIX 1g it is a type of its own, but some platforms use different
dnl types for the argument to getsockopt, getpeername, etc. So we
dnl have to test to find something that will work.
dnl This is no good, because passing the wrong pointer on C compilers is
dnl likely to only generate a warning, not an error. We don't call this at
dnl the moment.
AC_DEFUN([TYPE_SOCKLEN_T],
[
AC_CHECK_TYPE([socklen_t], ,[
AC_MSG_CHECKING([for socklen_t equivalent])
AC_CACHE_VAL([rsync_cv_socklen_t_equiv],
[
# Systems have either "struct sockaddr *" or
# "void *" as the second argument to getpeername
rsync_cv_socklen_t_equiv=
for arg2 in "struct sockaddr" void; do
for t in int size_t unsigned long "unsigned long"; do
AC_TRY_COMPILE([
#include
#include
int getpeername (int, $arg2 *, $t *);
],[
$t len;
getpeername(0,0,&len);
],[
rsync_cv_socklen_t_equiv="$t"
break
])
done
done
if test "x$rsync_cv_socklen_t_equiv" = x; then
AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
fi
])
AC_MSG_RESULT($rsync_cv_socklen_t_equiv)
AC_DEFINE_UNQUOTED(socklen_t, $rsync_cv_socklen_t_equiv,
[type to use in place of socklen_t if not defined])],
[#include
#include ])
])
dnl AC_HAVE_TYPE(TYPE,INCLUDES)
AC_DEFUN([AC_HAVE_TYPE], [
AC_REQUIRE([AC_HEADER_STDC])
cv=`echo "$1" | sed 'y%./+- %__p__%'`
AC_MSG_CHECKING(for $1)
AC_CACHE_VAL([ac_cv_type_$cv],
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
AC_INCLUDES_DEFAULT
$2]],
[[$1 foo;]])],
[eval "ac_cv_type_$cv=yes"],
[eval "ac_cv_type_$cv=no"]))dnl
ac_foo=`eval echo \\$ac_cv_type_$cv`
AC_MSG_RESULT($ac_foo)
if test "$ac_foo" = yes; then
ac_tr_hdr=HAVE_`echo $1 | sed 'y%abcdefghijklmnopqrstuvwxyz./- %ABCDEFGHIJKLMNOPQRSTUVWXYZ____%'`
if false; then
AC_CHECK_TYPES($1)
fi
AC_DEFINE_UNQUOTED($ac_tr_hdr, 1, [Define if you have type `$1'])
fi
])
rsync-3.1.0/generator.c 0000664 0000000 0000000 00000176351 12076567221 013530 0 ustar root root /*
* Routines that are exclusive to the generator process.
*
* Copyright (C) 1996-2000 Andrew Tridgell
* Copyright (C) 1996 Paul Mackerras
* Copyright (C) 2002 Martin Pool
* Copyright (C) 2003-2013 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, visit the http://fsf.org website.
*/
#include "rsync.h"
#include "inums.h"
#include "ifuncs.h"
extern int dry_run;
extern int do_xfers;
extern int stdout_format_has_i;
extern int logfile_format_has_i;
extern int am_root;
extern int am_server;
extern int am_daemon;
extern int inc_recurse;
extern int relative_paths;
extern int implied_dirs;
extern int keep_dirlinks;
extern int preserve_acls;
extern int preserve_xattrs;
extern int preserve_links;
extern int preserve_devices;
extern int preserve_specials;
extern int preserve_hard_links;
extern int preserve_executability;
extern int preserve_perms;
extern int preserve_times;
extern int delete_mode;
extern int delete_before;
extern int delete_during;
extern int delete_after;
extern int missing_args;
extern int msgdone_cnt;
extern int ignore_errors;
extern int remove_source_files;
extern int delay_updates;
extern int update_only;
extern int human_readable;
extern int ignore_existing;
extern int ignore_non_existing;
extern int inplace;
extern int append_mode;
extern int make_backups;
extern int csum_length;
extern int ignore_times;
extern int size_only;
extern OFF_T max_size;
extern OFF_T min_size;
extern int io_error;
extern int flist_eof;
extern int allowed_lull;
extern int sock_f_out;
extern int protocol_version;
extern int file_total;
extern int fuzzy_basis;
extern int always_checksum;
extern int checksum_len;
extern char *partial_dir;
extern int compare_dest;
extern int copy_dest;
extern int link_dest;
extern int whole_file;
extern int list_only;
extern int read_batch;
extern int write_batch;
extern int safe_symlinks;
extern long block_size; /* "long" because popt can't set an int32. */
extern int unsort_ndx;
extern int max_delete;
extern int force_delete;
extern int one_file_system;
extern int skipped_deletes;
extern dev_t filesystem_dev;
extern mode_t orig_umask;
extern uid_t our_uid;
extern char *tmpdir;
extern char *basis_dir[MAX_BASIS_DIRS+1];
extern struct file_list *cur_flist, *first_flist, *dir_flist;
extern filter_rule_list filter_list, daemon_filter_list;
int maybe_ATTRS_REPORT = 0;
static dev_t dev_zero;
static int deldelay_size = 0, deldelay_cnt = 0;
static char *deldelay_buf = NULL;
static int deldelay_fd = -1;
static int loopchk_limit;
static int dir_tweaking;
static int symlink_timeset_failed_flags;
static int need_retouch_dir_times;
static int need_retouch_dir_perms;
static const char *solo_file = NULL;
enum nonregtype {
TYPE_DIR, TYPE_SPECIAL, TYPE_DEVICE, TYPE_SYMLINK
};
/* Forward declarations. */
#ifdef SUPPORT_HARD_LINKS
static void handle_skipped_hlink(struct file_struct *file, int itemizing,
enum logcode code, int f_out);
#endif
#define EARLY_DELAY_DONE_MSG() (!delay_updates)
#define EARLY_DELETE_DONE_MSG() (!(delete_during == 2 || delete_after))
static int start_delete_delay_temp(void)
{
char fnametmp[MAXPATHLEN];
int save_dry_run = dry_run;
dry_run = 0;
if (!get_tmpname(fnametmp, "deldelay", False)
|| (deldelay_fd = do_mkstemp(fnametmp, 0600)) < 0) {
rprintf(FINFO, "NOTE: Unable to create delete-delay temp file%s.\n",
inc_recurse ? "" : " -- switching to --delete-after");
delete_during = 0;
delete_after = !inc_recurse;
dry_run = save_dry_run;
return 0;
}
unlink(fnametmp);
dry_run = save_dry_run;
return 1;
}
static int flush_delete_delay(void)
{
if (deldelay_fd < 0 && !start_delete_delay_temp())
return 0;
if (write(deldelay_fd, deldelay_buf, deldelay_cnt) != deldelay_cnt) {
rsyserr(FERROR, errno, "flush of delete-delay buffer");
delete_during = 0;
delete_after = !inc_recurse;
close(deldelay_fd);
return 0;
}
deldelay_cnt = 0;
return 1;
}
static int remember_delete(struct file_struct *file, const char *fname, int flags)
{
int len;
if (deldelay_cnt == deldelay_size && !flush_delete_delay())
return 0;
if (flags & DEL_NO_UID_WRITE)
deldelay_buf[deldelay_cnt++] = '!';
while (1) {
len = snprintf(deldelay_buf + deldelay_cnt,
deldelay_size - deldelay_cnt,
"%x %s%c",
(int)file->mode, fname, '\0');
if ((deldelay_cnt += len) <= deldelay_size)
break;
deldelay_cnt -= len;
if (!flush_delete_delay())
return 0;
}
return 1;
}
static int read_delay_line(char *buf, int *flags_p)
{
static int read_pos = 0;
int j, len, mode;
char *bp, *past_space;
while (1) {
for (j = read_pos; j < deldelay_cnt && deldelay_buf[j]; j++) {}
if (j < deldelay_cnt)
break;
if (deldelay_fd < 0) {
if (j > read_pos)
goto invalid_data;
return -1;
}
deldelay_cnt -= read_pos;
if (deldelay_cnt == deldelay_size)
goto invalid_data;
if (deldelay_cnt && read_pos) {
memmove(deldelay_buf, deldelay_buf + read_pos,
deldelay_cnt);
}
len = read(deldelay_fd, deldelay_buf + deldelay_cnt,
deldelay_size - deldelay_cnt);
if (len == 0) {
if (deldelay_cnt) {
rprintf(FERROR,
"ERROR: unexpected EOF in delete-delay file.\n");
}
return -1;
}
if (len < 0) {
rsyserr(FERROR, errno,
"reading delete-delay file");
return -1;
}
deldelay_cnt += len;
read_pos = 0;
}
bp = deldelay_buf + read_pos;
if (*bp == '!') {
bp++;
*flags_p = DEL_NO_UID_WRITE;
} else
*flags_p = 0;
if (sscanf(bp, "%x ", &mode) != 1) {
invalid_data:
rprintf(FERROR, "ERROR: invalid data in delete-delay file.\n");
return -1;
}
past_space = strchr(bp, ' ') + 1;
len = j - read_pos - (past_space - bp) + 1; /* count the '\0' */
read_pos = j + 1;
if (len > MAXPATHLEN) {
rprintf(FERROR, "ERROR: filename too long in delete-delay file.\n");
return -1;
}
/* The caller needs the name in a MAXPATHLEN buffer, so we copy it
* instead of returning a pointer to our buffer. */
memcpy(buf, past_space, len);
return mode;
}
static void do_delayed_deletions(char *delbuf)
{
int mode, flags;
if (deldelay_fd >= 0) {
if (deldelay_cnt && !flush_delete_delay())
return;
lseek(deldelay_fd, 0, 0);
}
while ((mode = read_delay_line(delbuf, &flags)) >= 0)
delete_item(delbuf, mode, flags | DEL_RECURSE);
if (deldelay_fd >= 0)
close(deldelay_fd);
}
/* This function is used to implement per-directory deletion, and is used by
* all the --delete-WHEN options. Note that the fbuf pointer must point to a
* MAXPATHLEN buffer with the name of the directory in it (the functions we
* call will append names onto the end, but the old dir value will be restored
* on exit). */
static void delete_in_dir(char *fbuf, struct file_struct *file, dev_t *fs_dev)
{
static int already_warned = 0;
struct file_list *dirlist;
char delbuf[MAXPATHLEN];
int dlen, i;
if (!fbuf) {
change_local_filter_dir(NULL, 0, 0);
return;
}
if (DEBUG_GTE(DEL, 2))
rprintf(FINFO, "delete_in_dir(%s)\n", fbuf);
if (allowed_lull)
maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH);
if (io_error & IOERR_GENERAL && !ignore_errors) {
if (already_warned)
return;
rprintf(FINFO,
"IO error encountered -- skipping file deletion\n");
already_warned = 1;
return;
}
dlen = strlen(fbuf);
change_local_filter_dir(fbuf, dlen, F_DEPTH(file));
if (one_file_system) {
if (file->flags & FLAG_TOP_DIR)
filesystem_dev = *fs_dev;
else if (filesystem_dev != *fs_dev)
return;
}
dirlist = get_dirlist(fbuf, dlen, 0);
/* If an item in dirlist is not found in flist, delete it
* from the filesystem. */
for (i = dirlist->used; i--; ) {
struct file_struct *fp = dirlist->files[i];
if (!F_IS_ACTIVE(fp))
continue;
if (fp->flags & FLAG_MOUNT_DIR && S_ISDIR(fp->mode)) {
if (INFO_GTE(MOUNT, 1))
rprintf(FINFO, "cannot delete mount point: %s\n",
f_name(fp, NULL));
continue;
}
/* Here we want to match regardless of file type. Replacement
* of a file with one of another type is handled separately by
* a delete_item call with a DEL_MAKE_ROOM flag. */
if (flist_find_ignore_dirness(cur_flist, fp) < 0) {
int flags = DEL_RECURSE;
if (!(fp->mode & S_IWUSR) && !am_root && fp->flags & FLAG_OWNED_BY_US)
flags |= DEL_NO_UID_WRITE;
f_name(fp, delbuf);
if (delete_during == 2) {
if (!remember_delete(fp, delbuf, flags))
break;
} else
delete_item(delbuf, fp->mode, flags);
}
}
flist_free(dirlist);
}
/* This deletes any files on the receiving side that are not present on the
* sending side. This is used by --delete-before and --delete-after. */
static void do_delete_pass(void)
{
char fbuf[MAXPATHLEN];
STRUCT_STAT st;
int j;
/* dry_run is incremented when the destination doesn't exist yet. */
if (dry_run > 1 || list_only)
return;
for (j = 0; j < cur_flist->used; j++) {
struct file_struct *file = cur_flist->sorted[j];
f_name(file, fbuf);
if (!(file->flags & FLAG_CONTENT_DIR)) {
change_local_filter_dir(fbuf, strlen(fbuf), F_DEPTH(file));
continue;
}
if (DEBUG_GTE(DEL, 1) && file->flags & FLAG_TOP_DIR)
rprintf(FINFO, "deleting in %s\n", fbuf);
if (link_stat(fbuf, &st, keep_dirlinks) < 0
|| !S_ISDIR(st.st_mode))
continue;
delete_in_dir(fbuf, file, &st.st_dev);
}
delete_in_dir(NULL, NULL, &dev_zero);
if (INFO_GTE(FLIST, 2) && !am_server)
rprintf(FINFO, " \r");
}
static inline int time_differs(struct file_struct *file, stat_x *sxp)
{
return cmp_time(sxp->st.st_mtime, file->modtime);
}
static inline int perms_differ(struct file_struct *file, stat_x *sxp)
{
if (preserve_perms)
return !BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS);
if (preserve_executability)
return (sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0);
return 0;
}
static inline int ownership_differs(struct file_struct *file, stat_x *sxp)
{
if (am_root && uid_ndx && sxp->st.st_uid != (uid_t)F_OWNER(file))
return 1;
if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP) && sxp->st.st_gid != (gid_t)F_GROUP(file))
return 1;
return 0;
}
#ifdef SUPPORT_ACLS
static inline int acls_differ(const char *fname, struct file_struct *file, stat_x *sxp)
{
if (preserve_acls) {
if (!ACL_READY(*sxp))
get_acl(fname, sxp);
if (set_acl(NULL, file, sxp, file->mode))
return 1;
}
return 0;
}
#endif
#ifdef SUPPORT_XATTRS
static inline int xattrs_differ(const char *fname, struct file_struct *file, stat_x *sxp)
{
if (preserve_xattrs) {
if (!XATTR_READY(*sxp))
get_xattr(fname, sxp);
if (xattr_diff(file, sxp, 0))
return 1;
}
return 0;
}
#endif
int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp)
{
if (S_ISLNK(file->mode)) {
#ifdef CAN_SET_SYMLINK_TIMES
if (preserve_times & PRESERVE_LINK_TIMES && time_differs(file, sxp))
return 0;
#endif
#ifdef CAN_CHMOD_SYMLINK
if (perms_differ(file, sxp))
return 0;
#endif
#ifdef CAN_CHOWN_SYMLINK
if (ownership_differs(file, sxp))
return 0;
#endif
#if defined SUPPORT_ACLS && 0 /* no current symlink-ACL support */
if (acls_differ(fname, file, sxp))
return 0;
#endif
#if defined SUPPORT_XATTRS && !defined NO_SYMLINK_XATTRS
if (xattrs_differ(fname, file, sxp))
return 0;
#endif
} else {
if (preserve_times && time_differs(file, sxp))
return 0;
if (perms_differ(file, sxp))
return 0;
if (ownership_differs(file, sxp))
return 0;
#ifdef SUPPORT_ACLS
if (acls_differ(fname, file, sxp))
return 0;
#endif
#ifdef SUPPORT_XATTRS
if (xattrs_differ(fname, file, sxp))
return 0;
#endif
}
return 1;
}
void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statret,
stat_x *sxp, int32 iflags, uchar fnamecmp_type,
const char *xname)
{
if (statret >= 0) { /* A from-dest-dir statret can == 1! */
int keep_time = !preserve_times ? 0
: S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES
: S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES
: 1;
if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size)
iflags |= ITEM_REPORT_SIZE;
if (file->flags & FLAG_TIME_FAILED) { /* symlinks only */
if (iflags & ITEM_LOCAL_CHANGE)
iflags |= symlink_timeset_failed_flags;
} else if (keep_time
? cmp_time(file->modtime, sxp->st.st_mtime) != 0
: iflags & (ITEM_TRANSFER|ITEM_LOCAL_CHANGE) && !(iflags & ITEM_MATCHED)
&& (!(iflags & ITEM_XNAME_FOLLOWS) || *xname))
iflags |= ITEM_REPORT_TIME;
#if !defined HAVE_LCHMOD && !defined HAVE_SETATTRLIST
if (S_ISLNK(file->mode)) {
;
} else
#endif
if (preserve_perms) {
if (!BITS_EQUAL(sxp->st.st_mode, file->mode, CHMOD_BITS))
iflags |= ITEM_REPORT_PERMS;
} else if (preserve_executability
&& ((sxp->st.st_mode & 0111 ? 1 : 0) ^ (file->mode & 0111 ? 1 : 0)))
iflags |= ITEM_REPORT_PERMS;
if (uid_ndx && am_root && (uid_t)F_OWNER(file) != sxp->st.st_uid)
iflags |= ITEM_REPORT_OWNER;
if (gid_ndx && !(file->flags & FLAG_SKIP_GROUP)
&& sxp->st.st_gid != (gid_t)F_GROUP(file))
iflags |= ITEM_REPORT_GROUP;
#ifdef SUPPORT_ACLS
if (preserve_acls && !S_ISLNK(file->mode)) {
if (!ACL_READY(*sxp))
get_acl(fnamecmp, sxp);
if (set_acl(NULL, file, sxp, file->mode))
iflags |= ITEM_REPORT_ACL;
}
#endif
#ifdef SUPPORT_XATTRS
if (preserve_xattrs) {
if (!XATTR_READY(*sxp))
get_xattr(fnamecmp, sxp);
if (xattr_diff(file, sxp, 1))
iflags |= ITEM_REPORT_XATTR;
}
#endif
} else {
#ifdef SUPPORT_XATTRS
if (preserve_xattrs && xattr_diff(file, NULL, 1))
iflags |= ITEM_REPORT_XATTR;
#endif
iflags |= ITEM_IS_NEW;
}
iflags &= 0xffff;
if ((iflags & (SIGNIFICANT_ITEM_FLAGS|ITEM_REPORT_XATTR) || INFO_GTE(NAME, 2)
|| stdout_format_has_i > 1 || (xname && *xname)) && !read_batch) {
if (protocol_version >= 29) {
if (ndx >= 0)
write_ndx(sock_f_out, ndx);
write_shortint(sock_f_out, iflags);
if (iflags & ITEM_BASIS_TYPE_FOLLOWS)
write_byte(sock_f_out, fnamecmp_type);
if (iflags & ITEM_XNAME_FOLLOWS)
write_vstring(sock_f_out, xname, strlen(xname));
#ifdef SUPPORT_XATTRS
if (preserve_xattrs && do_xfers
&& iflags & (ITEM_REPORT_XATTR|ITEM_TRANSFER)) {
int fd = iflags & ITEM_REPORT_XATTR
&& (protocol_version < 31 || !BITS_SET(iflags, ITEM_XNAME_FOLLOWS|ITEM_LOCAL_CHANGE))
? sock_f_out : -1;
send_xattr_request(NULL, file, fd);
}
#endif
} else if (ndx >= 0) {
enum logcode code = logfile_format_has_i ? FINFO : FCLIENT;
log_item(code, file, iflags, xname);
}
}
}
/* Perform our quick-check heuristic for determining if a file is unchanged. */
int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
{
if (st->st_size != F_LENGTH(file))
return 0;
/* if always checksum is set then we use the checksum instead
of the file time to determine whether to sync */
if (always_checksum > 0 && S_ISREG(st->st_mode)) {
char sum[MAX_DIGEST_LEN];
file_checksum(fn, sum, st->st_size);
return memcmp(sum, F_SUM(file), checksum_len) == 0;
}
if (size_only > 0)
return 1;
if (ignore_times)
return 0;
return cmp_time(st->st_mtime, file->modtime) == 0;
}
/*
* set (initialize) the size entries in the per-file sum_struct
* calculating dynamic block and checksum sizes.
*
* This is only called from generate_and_send_sums() but is a separate
* function to encapsulate the logic.
*
* The block size is a rounded square root of file length.
*
* The checksum size is determined according to:
* blocksum_bits = BLOCKSUM_BIAS + 2*log2(file_len) - log2(block_len)
* provided by Donovan Baarda which gives a probability of rsync
* algorithm corrupting data and falling back using the whole md4
* checksums.
*
* This might be made one of several selectable heuristics.
*/
static void sum_sizes_sqroot(struct sum_struct *sum, int64 len)
{
int32 blength;
int s2length;
int64 l;
if (len < 0) {
/* The file length overflowed our int64 var, so we can't process this file. */
sum->count = -1; /* indicate overflow error */
return;
}
if (block_size)
blength = block_size;
else if (len <= BLOCK_SIZE * BLOCK_SIZE)
blength = BLOCK_SIZE;
else {
int32 max_blength = protocol_version < 30 ? OLD_MAX_BLOCK_SIZE : MAX_BLOCK_SIZE;
int32 c;
int cnt;
for (c = 1, l = len, cnt = 0; l >>= 2; c <<= 1, cnt++) {}
if (c < 0 || c >= max_blength)
blength = max_blength;
else {
blength = 0;
do {
blength |= c;
if (len < (int64)blength * blength)
blength &= ~c;
c >>= 1;
} while (c >= 8); /* round to multiple of 8 */
blength = MAX(blength, BLOCK_SIZE);
}
}
if (protocol_version < 27) {
s2length = csum_length;
} else if (csum_length == SUM_LENGTH) {
s2length = SUM_LENGTH;
} else {
int32 c;
int b = BLOCKSUM_BIAS;
for (l = len; l >>= 1; b += 2) {}
for (c = blength; (c >>= 1) && b; b--) {}
/* add a bit, subtract rollsum, round up. */
s2length = (b + 1 - 32 + 7) / 8; /* --optimize in compiler-- */
s2length = MAX(s2length, csum_length);
s2length = MIN(s2length, SUM_LENGTH);
}
sum->flength = len;
sum->blength = blength;
sum->s2length = s2length;
sum->remainder = (int32)(len % blength);
sum->count = (int32)(l = (len / blength) + (sum->remainder != 0));
if ((int64)sum->count != l)
sum->count = -1;
if (sum->count && DEBUG_GTE(DELTASUM, 2)) {
rprintf(FINFO,
"count=%s rem=%ld blength=%ld s2length=%d flength=%s\n",
big_num(sum->count), (long)sum->remainder, (long)sum->blength,
sum->s2length, big_num(sum->flength));
}
}
/*
* Generate and send a stream of signatures/checksums that describe a buffer
*
* Generate approximately one checksum every block_len bytes.
*/
static int generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy)
{
int32 i;
struct map_struct *mapbuf;
struct sum_struct sum;
OFF_T offset = 0;
sum_sizes_sqroot(&sum, len);
if (sum.count < 0)
return -1;
write_sum_head(f_out, &sum);
if (append_mode > 0 && f_copy < 0)
return 0;
if (len > 0)
mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength);
else
mapbuf = NULL;
for (i = 0; i < sum.count; i++) {
int32 n1 = (int32)MIN(len, (OFF_T)sum.blength);
char *map = map_ptr(mapbuf, offset, n1);
char sum2[SUM_LENGTH];
uint32 sum1;
len -= n1;
offset += n1;
if (f_copy >= 0) {
full_write(f_copy, map, n1);
if (append_mode > 0)
continue;
}
sum1 = get_checksum1(map, n1);
get_checksum2(map, n1, sum2);
if (DEBUG_GTE(DELTASUM, 3)) {
rprintf(FINFO,
"chunk[%s] offset=%s len=%ld sum1=%08lx\n",
big_num(i), big_num(offset - n1), (long)n1,
(unsigned long)sum1);
}
write_int(f_out, sum1);
write_buf(f_out, sum2, sum.s2length);
}
if (mapbuf)
unmap_file(mapbuf);
return 0;
}
/* Try to find a filename in the same dir as "fname" with a similar name. */
static struct file_struct *find_fuzzy(struct file_struct *file, struct file_list *dirlist_array[], uchar *fnamecmp_type_ptr)
{
int fname_len, fname_suf_len;
const char *fname_suf, *fname = file->basename;
uint32 lowest_dist = 25 << 16; /* ignore a distance greater than 25 */
int i, j;
struct file_struct *lowest_fp = NULL;
fname_len = strlen(fname);
fname_suf = find_filename_suffix(fname, fname_len, &fname_suf_len);
/* Try to find an exact size+mtime match first. */
for (i = 0; i < fuzzy_basis; i++) {
struct file_list *dirlist = dirlist_array[i];
if (!dirlist)
continue;
for (j = 0; j < dirlist->used; j++) {
struct file_struct *fp = dirlist->files[j];
if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_FILE_SENT)
continue;
if (F_LENGTH(fp) == F_LENGTH(file) && cmp_time(fp->modtime, file->modtime) == 0) {
if (DEBUG_GTE(FUZZY, 2))
rprintf(FINFO, "fuzzy size/modtime match for %s\n", f_name(fp, NULL));
*fnamecmp_type_ptr = FNAMECMP_FUZZY + i;
return fp;
}
}
}
for (i = 0; i < fuzzy_basis; i++) {
struct file_list *dirlist = dirlist_array[i];
if (!dirlist)
continue;
for (j = 0; j < dirlist->used; j++) {
struct file_struct *fp = dirlist->files[j];
const char *suf, *name;
int len, suf_len;
uint32 dist;
if (!S_ISREG(fp->mode) || !F_LENGTH(fp) || fp->flags & FLAG_FILE_SENT)
continue;
name = fp->basename;
len = strlen(name);
suf = find_filename_suffix(name, len, &suf_len);
dist = fuzzy_distance(name, len, fname, fname_len);
/* Add some extra weight to how well the suffixes match. */
dist += fuzzy_distance(suf, suf_len, fname_suf, fname_suf_len) * 10;
if (DEBUG_GTE(FUZZY, 2)) {
rprintf(FINFO, "fuzzy distance for %s = %d.%05d\n",
f_name(fp, NULL), (int)(dist>>16), (int)(dist&0xFFFF));
}
if (dist <= lowest_dist) {
lowest_dist = dist;
lowest_fp = fp;
*fnamecmp_type_ptr = FNAMECMP_FUZZY + i;
}
}
}
return lowest_fp;
}
/* Copy a file found in our --copy-dest handling. */
static int copy_altdest_file(const char *src, const char *dest, struct file_struct *file)
{
char buf[MAXPATHLEN];
const char *copy_to, *partialptr;
int save_preserve_xattrs = preserve_xattrs;
int ok, fd_w;
if (inplace) {
/* Let copy_file open the destination in place. */
fd_w = -1;
copy_to = dest;
} else {
fd_w = open_tmpfile(buf, dest, file);
if (fd_w < 0)
return -1;
copy_to = buf;
}
cleanup_set(copy_to, NULL, NULL, -1, -1);
if (copy_file(src, copy_to, fd_w, file->mode) < 0) {
if (INFO_GTE(COPY, 1)) {
rsyserr(FINFO, errno, "copy_file %s => %s",
full_fname(src), copy_to);
}
/* Try to clean up. */
unlink(copy_to);
cleanup_disable();
return -1;
}
partialptr = partial_dir ? partial_dir_fname(dest) : NULL;
preserve_xattrs = 0; /* xattrs were copied with file */
ok = finish_transfer(dest, copy_to, src, partialptr, file, 1, 0);
preserve_xattrs = save_preserve_xattrs;
cleanup_disable();
return ok ? 0 : -1;
}
/* This is only called for regular files. We return -2 if we've finished
* handling the file, -1 if no dest-linking occurred, or a non-negative
* value if we found an alternate basis file. If we're called with the
* find_exact_for_existing flag, the destination file already exists, so
* we only try to find an exact alt-dest match. In this case, the returns
* are only -2 & -1 (both as above). */
static int try_dests_reg(struct file_struct *file, char *fname, int ndx,
char *cmpbuf, stat_x *sxp, int find_exact_for_existing,
int itemizing, enum logcode code)
{
STRUCT_STAT real_st = sxp->st;
int best_match = -1;
int match_level = 0;
int j = 0;
do {
pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
if (link_stat(cmpbuf, &sxp->st, 0) < 0 || !S_ISREG(sxp->st.st_mode))
continue;
switch (match_level) {
case 0:
best_match = j;
match_level = 1;
/* FALL THROUGH */
case 1:
if (!unchanged_file(cmpbuf, file, &sxp->st))
continue;
best_match = j;
match_level = 2;
/* FALL THROUGH */
case 2:
if (!unchanged_attrs(cmpbuf, file, sxp)) {
free_stat_x(sxp);
continue;
}
best_match = j;
match_level = 3;
break;
}
break;
} while (basis_dir[++j] != NULL);
if (!match_level)
return -1;
if (j != best_match) {
j = best_match;
pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
if (link_stat(cmpbuf, &sxp->st, 0) < 0)
return -1;
}
if (match_level == 3 && !copy_dest) {
if (find_exact_for_existing) {
if (link_dest && real_st.st_dev == sxp->st.st_dev && real_st.st_ino == sxp->st.st_ino)
return -1;
if (do_unlink(fname) < 0 && errno != ENOENT) {
sxp->st = real_st;
return -1;
}
}
#ifdef SUPPORT_HARD_LINKS
if (link_dest) {
if (!hard_link_one(file, fname, cmpbuf, 1))
goto try_a_copy;
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, &sxp->st, itemizing, code, j);
if (!maybe_ATTRS_REPORT && (INFO_GTE(NAME, 2) || stdout_format_has_i > 1)) {
itemize(cmpbuf, file, ndx, 1, sxp,
ITEM_LOCAL_CHANGE | ITEM_XNAME_FOLLOWS,
0, "");
}
} else
#endif
{
if (itemizing)
itemize(cmpbuf, file, ndx, 0, sxp, 0, 0, NULL);
}
if (INFO_GTE(NAME, 2) && maybe_ATTRS_REPORT)
rprintf(FCLIENT, "%s is uptodate\n", fname);
return -2;
}
if (find_exact_for_existing) {
sxp->st = real_st;
return -1;
}
if (match_level >= 2) {
#ifdef SUPPORT_HARD_LINKS
try_a_copy: /* Copy the file locally. */
#endif
if (!dry_run && copy_altdest_file(cmpbuf, fname, file) < 0) {
if (find_exact_for_existing) /* Can get here via hard-link failure */
sxp->st = real_st;
return -1;
}
if (itemizing)
itemize(cmpbuf, file, ndx, 0, sxp, ITEM_LOCAL_CHANGE, 0, NULL);
if (maybe_ATTRS_REPORT
&& ((!itemizing && INFO_GTE(NAME, 1) && match_level == 2)
|| (INFO_GTE(NAME, 2) && match_level == 3))) {
code = match_level == 3 ? FCLIENT : FINFO;
rprintf(code, "%s%s\n", fname,
match_level == 3 ? " is uptodate" : "");
}
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, &sxp->st, itemizing, code, -1);
#endif
return -2;
}
return FNAMECMP_BASIS_DIR_LOW + j;
}
/* This is only called for non-regular files. We return -2 if we've finished
* handling the file, or -1 if no dest-linking occurred, or a non-negative
* value if we found an alternate basis file. */
static int try_dests_non(struct file_struct *file, char *fname, int ndx,
char *cmpbuf, stat_x *sxp, int itemizing,
enum logcode code)
{
int best_match = -1;
int match_level = 0;
enum nonregtype type;
uint32 *devp;
#ifdef SUPPORT_LINKS
char lnk[MAXPATHLEN];
int len;
#endif
int j = 0;
#ifndef SUPPORT_LINKS
if (S_ISLNK(file->mode))
return -1;
#endif
if (S_ISDIR(file->mode)) {
type = TYPE_DIR;
} else if (IS_SPECIAL(file->mode))
type = TYPE_SPECIAL;
else if (IS_DEVICE(file->mode))
type = TYPE_DEVICE;
#ifdef SUPPORT_LINKS
else if (S_ISLNK(file->mode))
type = TYPE_SYMLINK;
#endif
else {
rprintf(FERROR,
"internal: try_dests_non() called with invalid mode (%o)\n",
(int)file->mode);
exit_cleanup(RERR_UNSUPPORTED);
}
do {
pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
if (link_stat(cmpbuf, &sxp->st, 0) < 0)
continue;
switch (type) {
case TYPE_DIR:
if (!S_ISDIR(sxp->st.st_mode))
continue;
break;
case TYPE_SPECIAL:
if (!IS_SPECIAL(sxp->st.st_mode))
continue;
break;
case TYPE_DEVICE:
if (!IS_DEVICE(sxp->st.st_mode))
continue;
break;
case TYPE_SYMLINK:
#ifdef SUPPORT_LINKS
if (!S_ISLNK(sxp->st.st_mode))
continue;
break;
#else
return -1;
#endif
}
if (match_level < 1) {
match_level = 1;
best_match = j;
}
switch (type) {
case TYPE_DIR:
case TYPE_SPECIAL:
break;
case TYPE_DEVICE:
devp = F_RDEV_P(file);
if (sxp->st.st_rdev != MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp)))
continue;
break;
case TYPE_SYMLINK:
#ifdef SUPPORT_LINKS
if ((len = do_readlink(cmpbuf, lnk, MAXPATHLEN-1)) <= 0)
continue;
lnk[len] = '\0';
if (strcmp(lnk, F_SYMLINK(file)) != 0)
continue;
break;
#else
return -1;
#endif
}
if (match_level < 2) {
match_level = 2;
best_match = j;
}
if (unchanged_attrs(cmpbuf, file, sxp)) {
match_level = 3;
best_match = j;
break;
}
} while (basis_dir[++j] != NULL);
if (!match_level)
return -1;
if (j != best_match) {
j = best_match;
pathjoin(cmpbuf, MAXPATHLEN, basis_dir[j], fname);
if (link_stat(cmpbuf, &sxp->st, 0) < 0)
return -1;
}
if (match_level == 3) {
#ifdef SUPPORT_HARD_LINKS
if (link_dest
#ifndef CAN_HARDLINK_SYMLINK
&& !S_ISLNK(file->mode)
#endif
#ifndef CAN_HARDLINK_SPECIAL
&& !IS_SPECIAL(file->mode) && !IS_DEVICE(file->mode)
#endif
&& !S_ISDIR(file->mode)) {
if (do_link(cmpbuf, fname) < 0) {
rsyserr(FERROR_XFER, errno,
"failed to hard-link %s with %s",
cmpbuf, fname);
return j;
}
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, NULL, itemizing, code, -1);
} else
#endif
match_level = 2;
if (itemizing && stdout_format_has_i
&& (INFO_GTE(NAME, 2) || stdout_format_has_i > 1)) {
int chg = compare_dest && type != TYPE_DIR ? 0
: ITEM_LOCAL_CHANGE + (match_level == 3 ? ITEM_XNAME_FOLLOWS : 0);
char *lp = match_level == 3 ? "" : NULL;
itemize(cmpbuf, file, ndx, 0, sxp, chg + ITEM_MATCHED, 0, lp);
}
if (INFO_GTE(NAME, 2) && maybe_ATTRS_REPORT) {
rprintf(FCLIENT, "%s%s is uptodate\n",
fname, type == TYPE_DIR ? "/" : "");
}
return -2;
}
return j;
}
static void list_file_entry(struct file_struct *f)
{
char permbuf[PERMSTRING_SIZE];
int64 len;
int colwidth = human_readable ? 14 : 11;
if (!F_IS_ACTIVE(f)) {
/* this can happen if duplicate names were removed */
return;
}
permstring(permbuf, f->mode);
len = F_LENGTH(f);
/* TODO: indicate '+' if the entry has an ACL. */
#ifdef SUPPORT_LINKS
if (preserve_links && S_ISLNK(f->mode)) {
rprintf(FINFO, "%s %*s %s %s -> %s\n",
permbuf, colwidth, human_num(len),
timestring(f->modtime), f_name(f, NULL),
F_SYMLINK(f));
} else
#endif
if (missing_args == 2 && f->mode == 0) {
rprintf(FINFO, "%-*s %s\n",
colwidth + 31, "*missing",
f_name(f, NULL));
} else {
rprintf(FINFO, "%s %*s %s %s\n",
permbuf, colwidth, human_num(len),
timestring(f->modtime), f_name(f, NULL));
}
}
static int phase = 0;
static int dflt_perms;
static int implied_dirs_are_missing;
/* Helper for recv_generator's skip_dir and dry_missing_dir tests. */
static BOOL is_below(struct file_struct *file, struct file_struct *subtree)
{
return F_DEPTH(file) > F_DEPTH(subtree)
&& (!implied_dirs_are_missing || f_name_has_prefix(file, subtree));
}
/* Acts on the indicated item in cur_flist whose name is fname. If a dir,
* make sure it exists, and has the right permissions/timestamp info. For
* all other non-regular files (symlinks, etc.) we create them here. For
* regular files that have changed, we try to find a basis file and then
* start sending checksums. The ndx is the file's unique index value.
*
* The fname parameter must point to a MAXPATHLEN buffer! (e.g it gets
* passed to delete_item(), which can use it during a recursive delete.)
*
* Note that f_out is set to -1 when doing final directory-permission and
* modification-time repair. */
static void recv_generator(char *fname, struct file_struct *file, int ndx,
int itemizing, enum logcode code, int f_out)
{
static const char *parent_dirname = "";
/* Missing dir not created due to --dry-run; will still be scanned. */
static struct file_struct *dry_missing_dir = NULL;
/* Missing dir whose contents are skipped altogether due to
* --ignore-non-existing, daemon exclude, or mkdir failure. */
static struct file_struct *skip_dir = NULL;
static struct file_list *fuzzy_dirlist[MAX_BASIS_DIRS+1];
static int need_fuzzy_dirlist = 0;
struct file_struct *fuzzy_file = NULL;
int fd = -1, f_copy = -1;
stat_x sx, real_sx;
STRUCT_STAT partial_st;
struct file_struct *back_file = NULL;
int statret, real_ret, stat_errno;
char *fnamecmp, *partialptr, *backupptr = NULL;
char fnamecmpbuf[MAXPATHLEN];
uchar fnamecmp_type;
int del_opts = delete_mode || force_delete ? DEL_RECURSE : 0;
int is_dir = !S_ISDIR(file->mode) ? 0
: inc_recurse && ndx != cur_flist->ndx_start - 1 ? -1
: 1;
if (DEBUG_GTE(GENR, 1))
rprintf(FINFO, "recv_generator(%s,%d)\n", fname, ndx);
if (list_only) {
if (is_dir < 0
|| (is_dir && !implied_dirs && file->flags & FLAG_IMPLIED_DIR))
return;
list_file_entry(file);
return;
}
if (skip_dir) {
if (is_below(file, skip_dir)) {
if (is_dir)
file->flags |= FLAG_MISSING_DIR;
#ifdef SUPPORT_HARD_LINKS
else if (F_IS_HLINKED(file))
handle_skipped_hlink(file, itemizing, code, f_out);
#endif
return;
}
skip_dir = NULL;
}
init_stat_x(&sx);
if (daemon_filter_list.head && (*fname != '.' || fname[1])) {
if (check_filter(&daemon_filter_list, FLOG, fname, is_dir) < 0) {
if (is_dir < 0)
return;
#ifdef SUPPORT_HARD_LINKS
if (F_IS_HLINKED(file))
handle_skipped_hlink(file, itemizing, code, f_out);
#endif
rprintf(FERROR_XFER,
"ERROR: daemon refused to receive %s \"%s\"\n",
is_dir ? "directory" : "file", fname);
if (is_dir)
goto skipping_dir_contents;
return;
}
}
if (dry_run > 1 || (dry_missing_dir && is_below(file, dry_missing_dir))) {
int i;
parent_is_dry_missing:
for (i = 0; i < fuzzy_basis; i++) {
if (fuzzy_dirlist[i]) {
flist_free(fuzzy_dirlist[i]);
fuzzy_dirlist[i] = NULL;
}
}
parent_dirname = "";
statret = -1;
stat_errno = ENOENT;
} else {
const char *dn = file->dirname ? file->dirname : ".";
dry_missing_dir = NULL;
if (parent_dirname != dn && strcmp(parent_dirname, dn) != 0) {
if (relative_paths && !implied_dirs
&& do_stat(dn, &sx.st) < 0) {
if (dry_run)
goto parent_is_dry_missing;
if (make_path(fname, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0) {
rsyserr(FERROR_XFER, errno,
"recv_generator: mkdir %s failed",
full_fname(dn));
}
}
if (fuzzy_basis) {
int i;
for (i = 0; i < fuzzy_basis; i++) {
if (fuzzy_dirlist[i]) {
flist_free(fuzzy_dirlist[i]);
fuzzy_dirlist[i] = NULL;
}
}
need_fuzzy_dirlist = 1;
}
#ifdef SUPPORT_ACLS
if (!preserve_perms)
dflt_perms = default_perms_for_dir(dn);
#endif
}
parent_dirname = dn;
if (need_fuzzy_dirlist && S_ISREG(file->mode)) {
int i;
strlcpy(fnamecmpbuf, dn, sizeof fnamecmpbuf);
for (i = 0; i < fuzzy_basis; i++) {
if (i && pathjoin(fnamecmpbuf, MAXPATHLEN, basis_dir[i-1], dn) >= MAXPATHLEN)
continue;
fuzzy_dirlist[i] = get_dirlist(fnamecmpbuf, -1, GDL_IGNORE_FILTER_RULES);
if (fuzzy_dirlist[i] && fuzzy_dirlist[i]->used == 0) {
flist_free(fuzzy_dirlist[i]);
fuzzy_dirlist[i] = NULL;
}
}
need_fuzzy_dirlist = 0;
}
statret = link_stat(fname, &sx.st, keep_dirlinks && is_dir);
stat_errno = errno;
}
if (missing_args == 2 && file->mode == 0) {
if (filter_list.head && check_filter(&filter_list, FINFO, fname, is_dir) < 0)
return;
if (statret == 0)
delete_item(fname, sx.st.st_mode, del_opts);
return;
}
if (ignore_non_existing > 0 && statret == -1 && stat_errno == ENOENT) {
if (is_dir) {
if (is_dir < 0)
return;
skip_dir = file;
file->flags |= FLAG_MISSING_DIR;
}
#ifdef SUPPORT_HARD_LINKS
else if (F_IS_HLINKED(file))
handle_skipped_hlink(file, itemizing, code, f_out);
#endif
if (INFO_GTE(SKIP, 1)) {
rprintf(FINFO, "not creating new %s \"%s\"\n",
is_dir ? "directory" : "file", fname);
}
return;
}
if (statret == 0 && !(sx.st.st_mode & S_IWUSR)
&& !am_root && sx.st.st_uid == our_uid)
del_opts |= DEL_NO_UID_WRITE;
if (ignore_existing > 0 && statret == 0
&& (!is_dir || !S_ISDIR(sx.st.st_mode))) {
if (INFO_GTE(SKIP, 1) && is_dir >= 0)
rprintf(FINFO, "%s exists\n", fname);
#ifdef SUPPORT_HARD_LINKS
if (F_IS_HLINKED(file))
handle_skipped_hlink(file, itemizing, code, f_out);
#endif
goto cleanup;
}
fnamecmp = fname;
if (is_dir) {
mode_t added_perms;
if (!implied_dirs && file->flags & FLAG_IMPLIED_DIR)
goto cleanup;
if (am_root < 0) {
/* For --fake-super, the dir must be useable by the copying
* user, just like it would be for root. */
added_perms = S_IRUSR|S_IWUSR|S_IXUSR;
} else
added_perms = 0;
if (is_dir < 0) {
/* In inc_recurse mode we want to make sure any missing
* directories get created while we're still processing
* the parent dir (which allows us to touch the parent
* dir's mtime right away). We will handle the dir in
* full later (right before we handle its contents). */
if (statret == 0
&& (S_ISDIR(sx.st.st_mode)
|| delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_DIR) != 0))
goto cleanup; /* Any errors get reported later. */
if (do_mkdir(fname, (file->mode|added_perms) & 0700) == 0)
file->flags |= FLAG_DIR_CREATED;
goto cleanup;
}
/* The file to be received is a directory, so we need
* to prepare appropriately. If there is already a
* file of that name and it is *not* a directory, then
* we need to delete it. If it doesn't exist, then
* (perhaps recursively) create it. */
if (statret == 0 && !S_ISDIR(sx.st.st_mode)) {
if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_DIR) != 0)
goto skipping_dir_contents;
statret = -1;
}
if (dry_run && statret != 0) {
if (!dry_missing_dir)
dry_missing_dir = file;
file->flags |= FLAG_MISSING_DIR;
}
init_stat_x(&real_sx);
real_sx.st = sx.st;
real_ret = statret;
if (file->flags & FLAG_DIR_CREATED)
statret = -1;
if (!preserve_perms) { /* See comment in non-dir code below. */
file->mode = dest_mode(file->mode, sx.st.st_mode,
dflt_perms, statret == 0);
}
if (statret != 0 && basis_dir[0] != NULL) {
int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
itemizing, code);
if (j == -2) {
itemizing = 0;
code = FNONE;
statret = 1;
} else if (j >= 0) {
statret = 1;
fnamecmp = fnamecmpbuf;
}
}
if (itemizing && f_out != -1) {
itemize(fnamecmp, file, ndx, statret, &sx,
statret ? ITEM_LOCAL_CHANGE : 0, 0, NULL);
}
if (real_ret != 0 && do_mkdir(fname,file->mode|added_perms) < 0 && errno != EEXIST) {
if (!relative_paths || errno != ENOENT
|| make_path(fname, MKP_DROP_NAME | MKP_SKIP_SLASH) < 0
|| (do_mkdir(fname, file->mode|added_perms) < 0 && errno != EEXIST)) {
rsyserr(FERROR_XFER, errno,
"recv_generator: mkdir %s failed",
full_fname(fname));
skipping_dir_contents:
rprintf(FERROR,
"*** Skipping any contents from this failed directory ***\n");
skip_dir = file;
file->flags |= FLAG_MISSING_DIR;
goto cleanup;
}
}
#ifdef SUPPORT_XATTRS
if (preserve_xattrs && statret == 1)
copy_xattrs(fnamecmpbuf, fname);
#endif
if (set_file_attrs(fname, file, real_ret ? NULL : &real_sx, NULL, 0)
&& INFO_GTE(NAME, 1) && code != FNONE && f_out != -1)
rprintf(code, "%s/\n", fname);
/* We need to ensure that the dirs in the transfer have both
* readable and writable permissions during the time we are
* putting files within them. This is then restored to the
* former permissions after the transfer is done. */
#ifdef HAVE_CHMOD
if (!am_root && (file->mode & S_IRWXU) != S_IRWXU && dir_tweaking) {
mode_t mode = file->mode | S_IRWXU;
if (do_chmod(fname, mode) < 0) {
rsyserr(FERROR_XFER, errno,
"failed to modify permissions on %s",
full_fname(fname));
}
need_retouch_dir_perms = 1;
}
#endif
if (real_ret != 0 && one_file_system)
real_sx.st.st_dev = filesystem_dev;
if (inc_recurse) {
if (one_file_system) {
uint32 *devp = F_DIR_DEV_P(file);
DEV_MAJOR(devp) = major(real_sx.st.st_dev);
DEV_MINOR(devp) = minor(real_sx.st.st_dev);
}
}
else if (delete_during && f_out != -1 && !phase
&& !(file->flags & FLAG_MISSING_DIR)) {
if (file->flags & FLAG_CONTENT_DIR)
delete_in_dir(fname, file, &real_sx.st.st_dev);
else
change_local_filter_dir(fname, strlen(fname), F_DEPTH(file));
}
goto cleanup;
}
/* If we're not preserving permissions, change the file-list's
* mode based on the local permissions and some heuristics. */
if (!preserve_perms) {
int exists = statret == 0 && !S_ISDIR(sx.st.st_mode);
file->mode = dest_mode(file->mode, sx.st.st_mode, dflt_perms,
exists);
}
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_HLINK_NOT_FIRST(file)
&& hard_link_check(file, ndx, fname, statret, &sx, itemizing, code))
goto cleanup;
#endif
if (preserve_links && S_ISLNK(file->mode)) {
#ifdef SUPPORT_LINKS
const char *sl = F_SYMLINK(file);
if (safe_symlinks && unsafe_symlink(sl, fname)) {
if (INFO_GTE(NAME, 1)) {
if (solo_file) {
/* fname contains the destination path, but we
* want to report the source path. */
fname = f_name(file, NULL);
}
rprintf(FINFO,
"ignoring unsafe symlink \"%s\" -> \"%s\"\n",
fname, sl);
}
return;
}
if (statret == 0) {
char lnk[MAXPATHLEN];
int len;
if (S_ISLNK(sx.st.st_mode)
&& (len = do_readlink(fname, lnk, MAXPATHLEN-1)) > 0
&& strncmp(lnk, sl, len) == 0 && sl[len] == '\0') {
/* The link is pointing to the right place. */
set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT);
if (itemizing)
itemize(fname, file, ndx, 0, &sx, 0, 0, NULL);
#if defined SUPPORT_HARD_LINKS && defined CAN_HARDLINK_SYMLINK
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1);
#endif
if (remove_source_files == 1)
goto return_with_success;
goto cleanup;
}
} else if (basis_dir[0] != NULL) {
int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
itemizing, code);
if (j == -2) {
#ifndef CAN_HARDLINK_SYMLINK
if (link_dest) {
/* Resort to --copy-dest behavior. */
} else
#endif
if (!copy_dest)
goto cleanup;
itemizing = 0;
code = FNONE;
} else if (j >= 0)
statret = 1;
}
if (atomic_create(file, fname, sl, MAKEDEV(0, 0), &sx, statret == 0 ? DEL_FOR_SYMLINK : 0)) {
set_file_attrs(fname, file, NULL, NULL, 0);
if (itemizing) {
if (statret == 0 && !S_ISLNK(sx.st.st_mode))
statret = -1;
itemize(fname, file, ndx, statret, &sx,
ITEM_LOCAL_CHANGE|ITEM_REPORT_CHANGE, 0, NULL);
}
if (code != FNONE && INFO_GTE(NAME, 1))
rprintf(code, "%s -> %s\n", fname, sl);
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, NULL, itemizing, code, -1);
#endif
/* This does not check remove_source_files == 1
* because this is one of the items that the old
* --remove-sent-files option would remove. */
if (remove_source_files)
goto return_with_success;
}
#endif
goto cleanup;
}
if ((am_root && preserve_devices && IS_DEVICE(file->mode))
|| (preserve_specials && IS_SPECIAL(file->mode))) {
dev_t rdev;
int del_for_flag = 0;
if (IS_DEVICE(file->mode)) {
uint32 *devp = F_RDEV_P(file);
rdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
} else
rdev = 0;
if (statret == 0) {
if (IS_DEVICE(file->mode)) {
if (!IS_DEVICE(sx.st.st_mode))
statret = -1;
del_for_flag = DEL_FOR_DEVICE;
} else {
if (!IS_SPECIAL(sx.st.st_mode))
statret = -1;
del_for_flag = DEL_FOR_SPECIAL;
}
if (statret == 0
&& BITS_EQUAL(sx.st.st_mode, file->mode, _S_IFMT)
&& (IS_SPECIAL(sx.st.st_mode) || sx.st.st_rdev == rdev)) {
/* The device or special file is identical. */
set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT);
if (itemizing)
itemize(fname, file, ndx, 0, &sx, 0, 0, NULL);
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1);
#endif
if (remove_source_files == 1)
goto return_with_success;
goto cleanup;
}
} else if (basis_dir[0] != NULL) {
int j = try_dests_non(file, fname, ndx, fnamecmpbuf, &sx,
itemizing, code);
if (j == -2) {
#ifndef CAN_HARDLINK_SPECIAL
if (link_dest) {
/* Resort to --copy-dest behavior. */
} else
#endif
if (!copy_dest)
goto cleanup;
itemizing = 0;
code = FNONE;
} else if (j >= 0)
statret = 1;
}
if (DEBUG_GTE(GENR, 1)) {
rprintf(FINFO, "mknod(%s, 0%o, [%ld,%ld])\n",
fname, (int)file->mode,
(long)major(rdev), (long)minor(rdev));
}
if (atomic_create(file, fname, NULL, rdev, &sx, del_for_flag)) {
set_file_attrs(fname, file, NULL, NULL, 0);
if (itemizing) {
itemize(fname, file, ndx, statret, &sx,
ITEM_LOCAL_CHANGE|ITEM_REPORT_CHANGE, 0, NULL);
}
if (code != FNONE && INFO_GTE(NAME, 1))
rprintf(code, "%s\n", fname);
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, NULL, itemizing, code, -1);
#endif
if (remove_source_files == 1)
goto return_with_success;
}
goto cleanup;
}
if (!S_ISREG(file->mode)) {
if (solo_file)
fname = f_name(file, NULL);
rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname);
goto cleanup;
}
if (max_size >= 0 && F_LENGTH(file) > max_size) {
if (INFO_GTE(SKIP, 1)) {
if (solo_file)
fname = f_name(file, NULL);
rprintf(FINFO, "%s is over max-size\n", fname);
}
goto cleanup;
}
if (min_size >= 0 && F_LENGTH(file) < min_size) {
if (INFO_GTE(SKIP, 1)) {
if (solo_file)
fname = f_name(file, NULL);
rprintf(FINFO, "%s is under min-size\n", fname);
}
goto cleanup;
}
if (update_only > 0 && statret == 0
&& cmp_time(sx.st.st_mtime, file->modtime) > 0) {
if (INFO_GTE(SKIP, 1))
rprintf(FINFO, "%s is newer\n", fname);
#ifdef SUPPORT_HARD_LINKS
if (F_IS_HLINKED(file))
handle_skipped_hlink(file, itemizing, code, f_out);
#endif
goto cleanup;
}
fnamecmp_type = FNAMECMP_FNAME;
if (statret == 0 && !S_ISREG(sx.st.st_mode)) {
if (delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_FILE) != 0)
goto cleanup;
statret = -1;
stat_errno = ENOENT;
}
if (basis_dir[0] != NULL && (statret != 0 || !copy_dest)) {
int j = try_dests_reg(file, fname, ndx, fnamecmpbuf, &sx,
statret == 0, itemizing, code);
if (j == -2) {
if (remove_source_files == 1)
goto return_with_success;
goto cleanup;
}
if (j >= 0) {
fnamecmp = fnamecmpbuf;
fnamecmp_type = j;
statret = 0;
}
}
init_stat_x(&real_sx);
real_sx.st = sx.st; /* Don't copy xattr/acl pointers, as they would free wrong. */
real_ret = statret;
if (partial_dir && (partialptr = partial_dir_fname(fname)) != NULL
&& link_stat(partialptr, &partial_st, 0) == 0
&& S_ISREG(partial_st.st_mode)) {
if (statret != 0)
goto prepare_to_open;
} else
partialptr = NULL;
if (statret != 0 && fuzzy_basis) {
/* Sets fnamecmp_type to FNAMECMP_FUZZY or above. */
fuzzy_file = find_fuzzy(file, fuzzy_dirlist, &fnamecmp_type);
if (fuzzy_file) {
f_name(fuzzy_file, fnamecmpbuf);
if (DEBUG_GTE(FUZZY, 1)) {
rprintf(FINFO, "fuzzy basis selected for %s: %s\n",
fname, fnamecmpbuf);
}
sx.st.st_size = F_LENGTH(fuzzy_file);
statret = 0;
fnamecmp = fnamecmpbuf;
}
}
if (statret != 0) {
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_HLINK_NOT_LAST(file)) {
cur_flist->in_progress++;
goto cleanup;
}
#endif
if (stat_errno == ENOENT)
goto notify_others;
rsyserr(FERROR_XFER, stat_errno, "recv_generator: failed to stat %s",
full_fname(fname));
goto cleanup;
}
if (fnamecmp_type <= FNAMECMP_BASIS_DIR_HIGH)
;
else if (fnamecmp_type == FNAMECMP_FUZZY)
;
else if (unchanged_file(fnamecmp, file, &sx.st)) {
if (partialptr) {
do_unlink(partialptr);
handle_partial_dir(partialptr, PDIR_DELETE);
}
set_file_attrs(fname, file, &sx, NULL, maybe_ATTRS_REPORT);
if (itemizing)
itemize(fnamecmp, file, ndx, statret, &sx, 0, 0, NULL);
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1);
#endif
if (remove_source_files != 1)
goto cleanup;
return_with_success:
if (!dry_run)
send_msg_int(MSG_SUCCESS, ndx);
goto cleanup;
}
if (append_mode > 0 && sx.st.st_size >= F_LENGTH(file)) {
#ifdef SUPPORT_HARD_LINKS
if (F_IS_HLINKED(file))
handle_skipped_hlink(file, itemizing, code, f_out);
#endif
goto cleanup;
}
prepare_to_open:
if (partialptr) {
sx.st = partial_st;
fnamecmp = partialptr;
fnamecmp_type = FNAMECMP_PARTIAL_DIR;
statret = 0;
}
if (!do_xfers)
goto notify_others;
if (read_batch || whole_file) {
if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) {
if (!(backupptr = get_backup_name(fname)))
goto cleanup;
if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
goto pretend_missing;
if (copy_file(fname, backupptr, -1, back_file->mode) < 0) {
unmake_file(back_file);
back_file = NULL;
goto cleanup;
}
}
goto notify_others;
}
if (fuzzy_dirlist[0]) {
int j = flist_find(fuzzy_dirlist[0], file);
if (j >= 0) /* don't use changing file as future fuzzy basis */
fuzzy_dirlist[0]->files[j]->flags |= FLAG_FILE_SENT;
}
/* open the file */
if ((fd = do_open(fnamecmp, O_RDONLY, 0)) < 0) {
rsyserr(FERROR, errno, "failed to open %s, continuing",
full_fname(fnamecmp));
pretend_missing:
/* pretend the file didn't exist */
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_HLINK_NOT_LAST(file)) {
cur_flist->in_progress++;
goto cleanup;
}
#endif
statret = real_ret = -1;
goto notify_others;
}
if (inplace && make_backups > 0 && fnamecmp_type == FNAMECMP_FNAME) {
if (!(backupptr = get_backup_name(fname))) {
close(fd);
goto cleanup;
}
if (!(back_file = make_file(fname, NULL, NULL, 0, NO_FILTERS))) {
close(fd);
goto pretend_missing;
}
if (robust_unlink(backupptr) && errno != ENOENT) {
rsyserr(FERROR_XFER, errno, "unlink %s",
full_fname(backupptr));
unmake_file(back_file);
back_file = NULL;
close(fd);
goto cleanup;
}
if ((f_copy = do_open(backupptr, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
rsyserr(FERROR_XFER, errno, "open %s", full_fname(backupptr));
unmake_file(back_file);
back_file = NULL;
close(fd);
goto cleanup;
}
fnamecmp_type = FNAMECMP_BACKUP;
}
if (DEBUG_GTE(DELTASUM, 3)) {
rprintf(FINFO, "gen mapped %s of size %s\n",
fnamecmp, big_num(sx.st.st_size));
}
if (DEBUG_GTE(DELTASUM, 2))
rprintf(FINFO, "generating and sending sums for %d\n", ndx);
notify_others:
if (remove_source_files && !delay_updates && !phase && !dry_run)
increment_active_files(ndx, itemizing, code);
if (inc_recurse && (!dry_run || write_batch < 0))
cur_flist->in_progress++;
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_IS_HLINKED(file))
file->flags |= FLAG_FILE_SENT;
#endif
write_ndx(f_out, ndx);
if (itemizing) {
int iflags = ITEM_TRANSFER;
if (always_checksum > 0)
iflags |= ITEM_REPORT_CHANGE;
if (fnamecmp_type != FNAMECMP_FNAME)
iflags |= ITEM_BASIS_TYPE_FOLLOWS;
if (fnamecmp_type >= FNAMECMP_FUZZY)
iflags |= ITEM_XNAME_FOLLOWS;
itemize(fnamecmp, file, -1, real_ret, &real_sx, iflags, fnamecmp_type,
fuzzy_file ? fuzzy_file->basename : NULL);
free_stat_x(&real_sx);
}
if (!do_xfers) {
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && F_IS_HLINKED(file))
finish_hard_link(file, fname, ndx, &sx.st, itemizing, code, -1);
#endif
goto cleanup;
}
if (read_batch)
goto cleanup;
if (statret != 0 || whole_file)
write_sum_head(f_out, NULL);
else if (sx.st.st_size <= 0) {
write_sum_head(f_out, NULL);
close(fd);
} else {
if (generate_and_send_sums(fd, sx.st.st_size, f_out, f_copy) < 0) {
rprintf(FWARNING,
"WARNING: file is too large for checksum sending: %s\n",
fnamecmp);
write_sum_head(f_out, NULL);
}
close(fd);
}
cleanup:
if (back_file) {
int save_preserve_xattrs = preserve_xattrs;
if (f_copy >= 0)
close(f_copy);
#ifdef SUPPORT_XATTRS
if (preserve_xattrs) {
copy_xattrs(fname, backupptr);
preserve_xattrs = 0;
}
#endif
set_file_attrs(backupptr, back_file, NULL, NULL, 0);
preserve_xattrs = save_preserve_xattrs;
if (INFO_GTE(BACKUP, 1)) {
rprintf(FINFO, "backed up %s to %s\n",
fname, backupptr);
}
unmake_file(back_file);
}
free_stat_x(&sx);
}
/* If we are replacing an existing hard link, symlink, device, or special file,
* create a temp-name item and rename it into place. Only a symlink or hard
* link puts a non-NULL value into the lnk arg. Only a device puts a non-0
* value into the rdev arg. Specify 0 for the del_for_flag if there is not a
* file to replace. This returns 1 on success and 0 on failure. */
int atomic_create(struct file_struct *file, char *fname, const char *lnk,
dev_t rdev, stat_x *sxp, int del_for_flag)
{
char tmpname[MAXPATHLEN];
const char *create_name;
int skip_atomic, dir_in_the_way = del_for_flag && S_ISDIR(sxp->st.st_mode);
if (!del_for_flag || dir_in_the_way || tmpdir || !get_tmpname(tmpname, fname, True))
skip_atomic = 1;
else
skip_atomic = 0;
if (del_for_flag) {
if (make_backups > 0 && !dir_in_the_way) {
if (!make_backup(fname, skip_atomic))
return 0;
} else if (skip_atomic) {
int del_opts = delete_mode || force_delete ? DEL_RECURSE : 0;
if (delete_item(fname, sxp->st.st_mode, del_opts | del_for_flag) != 0)
return 0;
}
}
create_name = skip_atomic ? fname : tmpname;
if (lnk) {
#ifdef SUPPORT_LINKS
if (S_ISLNK(file->mode)
#ifdef SUPPORT_HARD_LINKS /* The first symlink in a hard-linked cluster is always created. */
&& (!F_IS_HLINKED(file) || file->flags & FLAG_HLINK_FIRST)
#endif
) {
if (do_symlink(lnk, create_name) < 0) {
rsyserr(FERROR_XFER, errno, "symlink %s -> \"%s\" failed",
full_fname(create_name), lnk);
return 0;
}
} else
#endif
#ifdef SUPPORT_HARD_LINKS
if (!hard_link_one(file, create_name, lnk, 0))
return 0;
#endif
} else {
if (do_mknod(create_name, file->mode, rdev) < 0) {
rsyserr(FERROR_XFER, errno, "mknod %s failed",
full_fname(create_name));
return 0;
}
}
if (!skip_atomic) {
if (do_rename(tmpname, fname) < 0) {
rsyserr(FERROR_XFER, errno, "rename %s -> \"%s\" failed",
full_fname(tmpname), full_fname(fname));
do_unlink(tmpname);
return 0;
}
}
return 1;
}
#ifdef SUPPORT_HARD_LINKS
static void handle_skipped_hlink(struct file_struct *file, int itemizing,
enum logcode code, int f_out)
{
char fbuf[MAXPATHLEN];
int new_last_ndx;
struct file_list *save_flist = cur_flist;
/* If we skip the last item in a chain of links and there was a
* prior non-skipped hard-link waiting to finish, finish it now. */
if ((new_last_ndx = skip_hard_link(file, &cur_flist)) < 0)
return;
file = cur_flist->files[new_last_ndx - cur_flist->ndx_start];
cur_flist->in_progress--; /* undo prior increment */
f_name(file, fbuf);
recv_generator(fbuf, file, new_last_ndx, itemizing, code, f_out);
cur_flist = save_flist;
}
#endif
static void touch_up_dirs(struct file_list *flist, int ndx)
{
static int counter = 0;
struct file_struct *file;
char *fname;
BOOL fix_dir_perms;
int i, start, end;
if (ndx < 0) {
start = 0;
end = flist->used - 1;
} else
start = end = ndx;
/* Fix any directory permissions that were modified during the
* transfer and/or re-set any tweaked modified-time values. */
for (i = start; i <= end; i++, counter++) {
file = flist->files[i];
if (!S_ISDIR(file->mode)
|| (!implied_dirs && file->flags & FLAG_IMPLIED_DIR))
continue;
if (DEBUG_GTE(TIME, 2)) {
fname = f_name(file, NULL);
rprintf(FINFO, "touch_up_dirs: %s (%d)\n",
NS(fname), i);
}
/* Be sure not to retouch permissions with --fake-super. */
fix_dir_perms = !am_root && !(file->mode & S_IWUSR);
if (!F_IS_ACTIVE(file) || file->flags & FLAG_MISSING_DIR
|| !(need_retouch_dir_times || fix_dir_perms))
continue;
fname = f_name(file, NULL);
if (fix_dir_perms)
do_chmod(fname, file->mode);
if (need_retouch_dir_times) {
STRUCT_STAT st;
if (link_stat(fname, &st, 0) == 0
&& cmp_time(st.st_mtime, file->modtime) != 0)
set_modtime(fname, file->modtime, F_MOD_NSEC(file), file->mode);
}
if (counter >= loopchk_limit) {
if (allowed_lull)
maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH);
else
maybe_flush_socket(0);
counter = 0;
}
}
}
void check_for_finished_files(int itemizing, enum logcode code, int check_redo)
{
struct file_struct *file;
struct file_list *flist;
char fbuf[MAXPATHLEN];
int ndx;
while (1) {
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && (ndx = get_hlink_num()) != -1) {
int send_failed = (ndx == -2);
if (send_failed)
ndx = get_hlink_num();
flist = flist_for_ndx(ndx, "check_for_finished_files.1");
file = flist->files[ndx - flist->ndx_start];
assert(file->flags & FLAG_HLINKED);
if (send_failed)
handle_skipped_hlink(file, itemizing, code, sock_f_out);
else
finish_hard_link(file, f_name(file, fbuf), ndx, NULL, itemizing, code, -1);
flist->in_progress--;
continue;
}
#endif
if (check_redo && (ndx = get_redo_num()) != -1) {
OFF_T save_max_size = max_size;
OFF_T save_min_size = min_size;
csum_length = SUM_LENGTH;
max_size = -1;
min_size = -1;
ignore_existing = -ignore_existing;
ignore_non_existing = -ignore_non_existing;
update_only = -update_only;
always_checksum = -always_checksum;
size_only = -size_only;
append_mode = -append_mode;
make_backups = -make_backups; /* avoid dup backup w/inplace */
ignore_times++;
flist = cur_flist;
cur_flist = flist_for_ndx(ndx, "check_for_finished_files.2");
file = cur_flist->files[ndx - cur_flist->ndx_start];
if (solo_file)
strlcpy(fbuf, solo_file, sizeof fbuf);
else
f_name(file, fbuf);
recv_generator(fbuf, file, ndx, itemizing, code, sock_f_out);
cur_flist->to_redo--;
cur_flist = flist;
csum_length = SHORT_SUM_LENGTH;
max_size = save_max_size;
min_size = save_min_size;
ignore_existing = -ignore_existing;
ignore_non_existing = -ignore_non_existing;
update_only = -update_only;
always_checksum = -always_checksum;
size_only = -size_only;
append_mode = -append_mode;
make_backups = -make_backups;
ignore_times--;
continue;
}
if (cur_flist == first_flist)
break;
/* We only get here if inc_recurse is enabled. */
if (first_flist->in_progress || first_flist->to_redo)
break;
write_ndx(sock_f_out, NDX_DONE);
if (!read_batch && !flist_eof) {
int old_total = 0;
for (flist = first_flist; flist != cur_flist; flist = flist->next)
old_total += flist->used;
maybe_flush_socket(!flist_eof && file_total - old_total < MIN_FILECNT_LOOKAHEAD/2);
}
if (delete_during == 2 || !dir_tweaking) {
/* Skip directory touch-up. */
} else if (first_flist->parent_ndx >= 0)
touch_up_dirs(dir_flist, first_flist->parent_ndx);
flist_free(first_flist); /* updates first_flist */
}
}
void generate_files(int f_out, const char *local_name)
{
int i, ndx, next_loopchk = 0;
char fbuf[MAXPATHLEN];
int itemizing;
enum logcode code;
int save_info_flist = info_levels[INFO_FLIST];
int save_info_progress = info_levels[INFO_PROGRESS];
if (protocol_version >= 29) {
itemizing = 1;
maybe_ATTRS_REPORT = stdout_format_has_i ? 0 : ATTRS_REPORT;
code = logfile_format_has_i ? FNONE : FLOG;
} else if (am_daemon) {
itemizing = logfile_format_has_i && do_xfers;
maybe_ATTRS_REPORT = ATTRS_REPORT;
code = itemizing || !do_xfers ? FCLIENT : FINFO;
} else if (!am_server) {
itemizing = stdout_format_has_i;
maybe_ATTRS_REPORT = stdout_format_has_i ? 0 : ATTRS_REPORT;
code = itemizing ? FNONE : FINFO;
} else {
itemizing = 0;
maybe_ATTRS_REPORT = ATTRS_REPORT;
code = FINFO;
}
solo_file = local_name;
dir_tweaking = !(list_only || solo_file || dry_run);
need_retouch_dir_times = preserve_times & PRESERVE_DIR_TIMES;
loopchk_limit = allowed_lull ? allowed_lull * 5 : 200;
symlink_timeset_failed_flags = ITEM_REPORT_TIME
| (protocol_version >= 30 || !am_server ? ITEM_REPORT_TIMEFAIL : 0);
implied_dirs_are_missing = relative_paths && !implied_dirs && protocol_version < 30;
if (DEBUG_GTE(GENR, 1))
rprintf(FINFO, "generator starting pid=%d\n", (int)getpid());
if (delete_before && !solo_file && cur_flist->used > 0)
do_delete_pass();
if (delete_during == 2) {
deldelay_size = BIGPATHBUFLEN * 4;
deldelay_buf = new_array(char, deldelay_size);
if (!deldelay_buf)
out_of_memory("delete-delay");
}
info_levels[INFO_FLIST] = info_levels[INFO_PROGRESS] = 0;
if (append_mode > 0 || whole_file < 0)
whole_file = 0;
if (DEBUG_GTE(FLIST, 1)) {
rprintf(FINFO, "delta-transmission %s\n",
whole_file
? "disabled for local transfer or --whole-file"
: "enabled");
}
dflt_perms = (ACCESSPERMS & ~orig_umask);
do {
#ifdef SUPPORT_HARD_LINKS
if (preserve_hard_links && inc_recurse) {
while (!flist_eof && file_total < MIN_FILECNT_LOOKAHEAD/2)
wait_for_receiver();
}
#endif
if (inc_recurse && cur_flist->parent_ndx >= 0) {
struct file_struct *fp = dir_flist->files[cur_flist->parent_ndx];
if (solo_file)
strlcpy(fbuf, solo_file, sizeof fbuf);
else
f_name(fp, fbuf);
ndx = cur_flist->ndx_start - 1;
recv_generator(fbuf, fp, ndx, itemizing, code, f_out);
if (delete_during && dry_run < 2 && !list_only
&& !(fp->flags & FLAG_MISSING_DIR)) {
if (fp->flags & FLAG_CONTENT_DIR) {
dev_t dirdev;
if (one_file_system) {
uint32 *devp = F_DIR_DEV_P(fp);
dirdev = MAKEDEV(DEV_MAJOR(devp), DEV_MINOR(devp));
} else
dirdev = MAKEDEV(0, 0);
delete_in_dir(fbuf, fp, &dirdev);
} else
change_local_filter_dir(fbuf, strlen(fbuf), F_DEPTH(fp));
}
}
for (i = cur_flist->low; i <= cur_flist->high; i++) {
struct file_struct *file = cur_flist->sorted[i];
if (!F_IS_ACTIVE(file))
continue;
if (unsort_ndx)
ndx = F_NDX(file);
else
ndx = i + cur_flist->ndx_start;
if (solo_file)
strlcpy(fbuf, solo_file, sizeof fbuf);
else
f_name(file, fbuf);
recv_generator(fbuf, file, ndx, itemizing, code, f_out);
check_for_finished_files(itemizing, code, 0);
if (i + cur_flist->ndx_start >= next_loopchk) {
if (allowed_lull)
maybe_send_keepalive(time(NULL), MSK_ALLOW_FLUSH);
else
maybe_flush_socket(0);
next_loopchk += loopchk_limit;
}
}
if (!inc_recurse) {
write_ndx(f_out, NDX_DONE);
break;
}
while (1) {
check_for_finished_files(itemizing, code, 1);
if (cur_flist->next || flist_eof)
break;
wait_for_receiver();
}
} while ((cur_flist = cur_flist->next) != NULL);
if (delete_during)
delete_in_dir(NULL, NULL, &dev_zero);
phase++;
if (DEBUG_GTE(GENR, 1))
rprintf(FINFO, "generate_files phase=%d\n", phase);
while (1) {
check_for_finished_files(itemizing, code, 1);
if (msgdone_cnt)
break;
wait_for_receiver();
}
phase++;
if (DEBUG_GTE(GENR, 1))
rprintf(FINFO, "generate_files phase=%d\n", phase);
write_ndx(f_out, NDX_DONE);
/* Reduce round-trip lag-time for a useless delay-updates phase. */
if (protocol_version >= 29 && EARLY_DELAY_DONE_MSG())
write_ndx(f_out, NDX_DONE);
if (protocol_version >= 31 && EARLY_DELETE_DONE_MSG()) {
if ((INFO_GTE(STATS, 2) && (delete_mode || force_delete)) || read_batch)
write_del_stats(f_out);
if (EARLY_DELAY_DONE_MSG()) /* Can't send this before delay */
write_ndx(f_out, NDX_DONE);
}
/* Read MSG_DONE for the redo phase (and any prior messages). */
while (1) {
check_for_finished_files(itemizing, code, 0);
if (msgdone_cnt > 1)
break;
wait_for_receiver();
}
if (protocol_version >= 29) {
phase++;
if (DEBUG_GTE(GENR, 1))
rprintf(FINFO, "generate_files phase=%d\n", phase);
if (!EARLY_DELAY_DONE_MSG()) {
write_ndx(f_out, NDX_DONE);
if (protocol_version >= 31 && EARLY_DELETE_DONE_MSG())
write_ndx(f_out, NDX_DONE);
}
/* Read MSG_DONE for delay-updates phase & prior messages. */
while (msgdone_cnt == 2)
wait_for_receiver();
}
info_levels[INFO_FLIST] = save_info_flist;
info_levels[INFO_PROGRESS] = save_info_progress;
if (delete_during == 2)
do_delayed_deletions(fbuf);
if (delete_after && !solo_file && file_total > 0)
do_delete_pass();
if (max_delete >= 0 && skipped_deletes) {
rprintf(FWARNING,
"Deletions stopped due to --max-delete limit (%d skipped)\n",
skipped_deletes);
io_error |= IOERR_DEL_LIMIT;
}
if (protocol_version >= 31) {
if (!EARLY_DELETE_DONE_MSG()) {
if (INFO_GTE(STATS, 2) || read_batch)
write_del_stats(f_out);
write_ndx(f_out, NDX_DONE);
}
/* Read MSG_DONE for late-delete phase & prior messages. */
while (msgdone_cnt == 3)
wait_for_receiver();
}
if ((need_retouch_dir_perms || need_retouch_dir_times)
&& dir_tweaking && (!inc_recurse || delete_during == 2))
touch_up_dirs(dir_flist, -1);
if (DEBUG_GTE(GENR, 1))
rprintf(FINFO, "generate_files finished\n");
}
rsync-3.1.0/tls.c 0000664 0000000 0000000 00000015615 12221640703 012324 0 ustar root root /*
* Trivial ls for comparing two directories after running an rsync.
*
* Copyright (C) 2001, 2002 Martin Pool
* Copyright (C) 2003-2013 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* The problem with using the system's own ls is that some features
* have little quirks that make directories look different when for
* our purposes they're the same -- for example, the BSD braindamage
* about setting the mode on symlinks based on your current umask.
*
* All the filenames must be given on the command line -- tls does not
* even read directories, let alone recurse. The typical usage is
* "find|sort|xargs tls".
*
* The format is not exactly the same as any particular Unix ls(1).
*
* A key requirement for this program is that the output be "very
* reproducible." So we mask away information that can accidentally
* change. */
#include "rsync.h"
#include
#include "lib/sysxattrs.h"
#define PROGRAM "tls"
/* These are to make syscall.o shut up. */
int dry_run = 0;
int am_root = 0;
int am_sender = 1;
int read_only = 1;
int list_only = 0;
int link_times = 0;
int link_owner = 0;
int nsec_times = 0;
int preserve_perms = 0;
int preserve_executability = 0;
#ifdef SUPPORT_XATTRS
#ifdef HAVE_LINUX_XATTRS
#define XSTAT_ATTR "user.rsync.%stat"
#else
#define XSTAT_ATTR "rsync.%stat"
#endif
static int stat_xattr(const char *fname, STRUCT_STAT *fst)
{
int mode, rdev_major, rdev_minor, uid, gid, len;
char buf[256];
if (am_root >= 0 || IS_DEVICE(fst->st_mode) || IS_SPECIAL(fst->st_mode))
return -1;
len = sys_lgetxattr(fname, XSTAT_ATTR, buf, sizeof buf - 1);
if (len >= (int)sizeof buf) {
len = -1;
errno = ERANGE;
}
if (len < 0) {
if (errno == ENOTSUP || errno == ENOATTR)
return -1;
if (errno == EPERM && S_ISLNK(fst->st_mode)) {
fst->st_uid = 0;
fst->st_gid = 0;
return 0;
}
fprintf(stderr, "failed to read xattr %s for %s: %s\n",
XSTAT_ATTR, fname, strerror(errno));
return -1;
}
buf[len] = '\0';
if (sscanf(buf, "%o %d,%d %d:%d",
&mode, &rdev_major, &rdev_minor, &uid, &gid) != 5) {
fprintf(stderr, "Corrupt %s xattr attached to %s: \"%s\"\n",
XSTAT_ATTR, fname, buf);
exit(1);
}
#if _S_IFLNK != 0120000
if ((mode & (_S_IFMT)) == 0120000)
mode = (mode & ~(_S_IFMT)) | _S_IFLNK;
#endif
fst->st_mode = mode;
fst->st_rdev = MAKEDEV(rdev_major, rdev_minor);
fst->st_uid = uid;
fst->st_gid = gid;
return 0;
}
#endif
static void failed(char const *what, char const *where)
{
fprintf(stderr, PROGRAM ": %s %s: %s\n",
what, where, strerror(errno));
exit(1);
}
static void list_file(const char *fname)
{
STRUCT_STAT buf;
char permbuf[PERMSTRING_SIZE];
struct tm *mt;
char datebuf[50];
char linkbuf[4096];
if (do_lstat(fname, &buf) < 0)
failed("stat", fname);
#ifdef SUPPORT_XATTRS
if (am_root < 0)
stat_xattr(fname, &buf);
#endif
/* The size of anything but a regular file is probably not
* worth thinking about. */
if (!S_ISREG(buf.st_mode))
buf.st_size = 0;
/* On some BSD platforms the mode bits of a symlink are
* undefined. Also it tends not to be possible to reset a
* symlink's mtime, so we default to ignoring it too. */
if (S_ISLNK(buf.st_mode)) {
int len;
buf.st_mode &= ~0777;
if (!link_times)
buf.st_mtime = (time_t)0;
if (!link_owner)
buf.st_uid = buf.st_gid = 0;
strlcpy(linkbuf, " -> ", sizeof linkbuf);
/* const-cast required for silly UNICOS headers */
len = do_readlink((char *) fname, linkbuf+4, sizeof(linkbuf) - 4);
if (len == -1)
failed("do_readlink", fname);
else
/* it's not nul-terminated */
linkbuf[4+len] = 0;
} else {
linkbuf[0] = 0;
}
permstring(permbuf, buf.st_mode);
if (buf.st_mtime) {
int len;
mt = gmtime(&buf.st_mtime);
len = snprintf(datebuf, sizeof datebuf,
"%04d-%02d-%02d %02d:%02d:%02d",
(int)mt->tm_year + 1900,
(int)mt->tm_mon + 1,
(int)mt->tm_mday,
(int)mt->tm_hour,
(int)mt->tm_min,
(int)mt->tm_sec);
#ifdef ST_MTIME_NSEC
if (nsec_times) {
snprintf(datebuf + len, sizeof datebuf - len,
".%09d", (int)buf.ST_MTIME_NSEC);
}
#endif
} else {
int len = MIN(19 + 9*nsec_times, (int)sizeof datebuf - 1);
memset(datebuf, ' ', len);
datebuf[len] = '\0';
}
/* TODO: Perhaps escape special characters in fname? */
printf("%s ", permbuf);
if (S_ISCHR(buf.st_mode) || S_ISBLK(buf.st_mode)) {
printf("%5ld,%6ld",
(long)major(buf.st_rdev),
(long)minor(buf.st_rdev));
} else
printf("%15s", do_big_num(buf.st_size, 1, NULL));
printf(" %6ld.%-6ld %6ld %s %s%s\n",
(long)buf.st_uid, (long)buf.st_gid, (long)buf.st_nlink,
datebuf, fname, linkbuf);
}
static struct poptOption long_options[] = {
/* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
{"link-times", 'l', POPT_ARG_NONE, &link_times, 0, 0, 0 },
{"link-owner", 'L', POPT_ARG_NONE, &link_owner, 0, 0, 0 },
#ifdef SUPPORT_XATTRS
{"fake-super", 'f', POPT_ARG_VAL, &am_root, -1, 0, 0 },
#endif
#ifdef ST_MTIME_NSEC
{"nsec", 's', POPT_ARG_NONE, &nsec_times, 0, 0, 0 },
#endif
{"help", 'h', POPT_ARG_NONE, 0, 'h', 0, 0 },
{0,0,0,0,0,0,0}
};
static void tls_usage(int ret)
{
FILE *F = ret ? stderr : stdout;
fprintf(F,"usage: " PROGRAM " [OPTIONS] FILE ...\n");
fprintf(F,"Trivial file listing program for portably checking rsync\n");
fprintf(F,"\nOptions:\n");
fprintf(F," -l, --link-times display the time on a symlink\n");
fprintf(F," -L, --link-owner display the owner+group on a symlink\n");
#ifdef SUPPORT_XATTRS
fprintf(F," -f, --fake-super display attributes including fake-super xattrs\n");
#endif
fprintf(F," -h, --help show this help\n");
exit(ret);
}
int
main(int argc, char *argv[])
{
poptContext pc;
const char **extra_args;
int opt;
pc = poptGetContext(PROGRAM, argc, (const char **)argv,
long_options, 0);
while ((opt = poptGetNextOpt(pc)) != -1) {
switch (opt) {
case 'h':
tls_usage(0);
default:
fprintf(stderr,
"%s: %s\n",
poptBadOption(pc, POPT_BADOPTION_NOALIAS),
poptStrerror(opt));
tls_usage(1);
}
}
extra_args = poptGetArgs(pc);
if (!extra_args || *extra_args == NULL)
tls_usage(1);
for (; *extra_args; extra_args++)
list_file(*extra_args);
poptFreeContext(pc);
return 0;
}
rsync-3.1.0/fileio.c 0000664 0000000 0000000 00000015342 12215625646 013002 0 ustar root root /*
* File IO utilities used in rsync.
*
* Copyright (C) 1998 Andrew Tridgell
* Copyright (C) 2002 Martin Pool
* Copyright (C) 2004-2013 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, visit the http://fsf.org website.
*/
#include "rsync.h"
#include "inums.h"
#ifndef ENODATA
#define ENODATA EAGAIN
#endif
/* We want all reads to be aligned on 1K boundries. */
#define ALIGN_BOUNDRY 1024
/* How far past the boundary is an offset? */
#define ALIGNED_OVERSHOOT(oft) ((oft) & (ALIGN_BOUNDRY-1))
/* Round up a length to the next boundary */
#define ALIGNED_LENGTH(len) ((((len) - 1) | (ALIGN_BOUNDRY-1)) + 1)
extern int sparse_files;
static OFF_T sparse_seek = 0;
int sparse_end(int f, OFF_T size)
{
int ret;
if (!sparse_seek)
return 0;
#ifdef HAVE_FTRUNCATE
ret = do_ftruncate(f, size);
#else
if (do_lseek(f, sparse_seek-1, SEEK_CUR) != size-1)
ret = -1;
else {
do {
ret = write(f, "", 1);
} while (ret < 0 && errno == EINTR);
ret = ret <= 0 ? -1 : 0;
}
#endif
sparse_seek = 0;
return ret;
}
static int write_sparse(int f, char *buf, int len)
{
int l1 = 0, l2 = 0;
int ret;
for (l1 = 0; l1 < len && buf[l1] == 0; l1++) {}
for (l2 = 0; l2 < len-l1 && buf[len-(l2+1)] == 0; l2++) {}
sparse_seek += l1;
if (l1 == len)
return len;
if (sparse_seek)
do_lseek(f, sparse_seek, SEEK_CUR);
sparse_seek = l2;
while ((ret = write(f, buf + l1, len - (l1+l2))) <= 0) {
if (ret < 0 && errno == EINTR)
continue;
sparse_seek = 0;
return ret;
}
if (ret != (int)(len - (l1+l2))) {
sparse_seek = 0;
return l1+ret;
}
return len;
}
static char *wf_writeBuf;
static size_t wf_writeBufSize;
static size_t wf_writeBufCnt;
int flush_write_file(int f)
{
int ret = 0;
char *bp = wf_writeBuf;
while (wf_writeBufCnt > 0) {
if ((ret = write(f, bp, wf_writeBufCnt)) < 0) {
if (errno == EINTR)
continue;
return ret;
}
wf_writeBufCnt -= ret;
bp += ret;
}
return ret;
}
/*
* write_file does not allow incomplete writes. It loops internally
* until len bytes are written or errno is set.
*/
int write_file(int f, char *buf, int len)
{
int ret = 0;
while (len > 0) {
int r1;
if (sparse_files > 0) {
int len1 = MIN(len, SPARSE_WRITE_SIZE);
r1 = write_sparse(f, buf, len1);
} else {
if (!wf_writeBuf) {
wf_writeBufSize = WRITE_SIZE * 8;
wf_writeBufCnt = 0;
wf_writeBuf = new_array(char, wf_writeBufSize);
if (!wf_writeBuf)
out_of_memory("write_file");
}
r1 = (int)MIN((size_t)len, wf_writeBufSize - wf_writeBufCnt);
if (r1) {
memcpy(wf_writeBuf + wf_writeBufCnt, buf, r1);
wf_writeBufCnt += r1;
}
if (wf_writeBufCnt == wf_writeBufSize) {
if (flush_write_file(f) < 0)
return -1;
if (!r1 && len)
continue;
}
}
if (r1 <= 0) {
if (ret > 0)
return ret;
return r1;
}
len -= r1;
buf += r1;
ret += r1;
}
return ret;
}
/* This provides functionality somewhat similar to mmap() but using read().
* It gives sliding window access to a file. mmap() is not used because of
* the possibility of another program (such as a mailer) truncating the
* file thus giving us a SIGBUS. */
struct map_struct *map_file(int fd, OFF_T len, int32 read_size, int32 blk_size)
{
struct map_struct *map;
if (!(map = new0(struct map_struct)))
out_of_memory("map_file");
if (blk_size && (read_size % blk_size))
read_size += blk_size - (read_size % blk_size);
map->fd = fd;
map->file_size = len;
map->def_window_size = ALIGNED_LENGTH(read_size);
return map;
}
/* slide the read window in the file */
char *map_ptr(struct map_struct *map, OFF_T offset, int32 len)
{
OFF_T window_start, read_start;
int32 window_size, read_size, read_offset, align_fudge;
if (len == 0)
return NULL;
if (len < 0) {
rprintf(FERROR, "invalid len passed to map_ptr: %ld\n",
(long)len);
exit_cleanup(RERR_FILEIO);
}
/* in most cases the region will already be available */
if (offset >= map->p_offset && offset+len <= map->p_offset+map->p_len)
return map->p + (offset - map->p_offset);
/* nope, we are going to have to do a read. Work out our desired window */
align_fudge = (int32)ALIGNED_OVERSHOOT(offset);
window_start = offset - align_fudge;
window_size = map->def_window_size;
if (window_start + window_size > map->file_size)
window_size = (int32)(map->file_size - window_start);
if (window_size < len + align_fudge)
window_size = ALIGNED_LENGTH(len + align_fudge);
/* make sure we have allocated enough memory for the window */
if (window_size > map->p_size) {
map->p = realloc_array(map->p, char, window_size);
if (!map->p)
out_of_memory("map_ptr");
map->p_size = window_size;
}
/* Now try to avoid re-reading any bytes by reusing any bytes from the previous buffer. */
if (window_start >= map->p_offset && window_start < map->p_offset + map->p_len
&& window_start + window_size >= map->p_offset + map->p_len) {
read_start = map->p_offset + map->p_len;
read_offset = (int32)(read_start - window_start);
read_size = window_size - read_offset;
memmove(map->p, map->p + (map->p_len - read_offset), read_offset);
} else {
read_start = window_start;
read_size = window_size;
read_offset = 0;
}
if (read_size <= 0) {
rprintf(FERROR, "invalid read_size of %ld in map_ptr\n",
(long)read_size);
exit_cleanup(RERR_FILEIO);
}
if (map->p_fd_offset != read_start) {
OFF_T ret = do_lseek(map->fd, read_start, SEEK_SET);
if (ret != read_start) {
rsyserr(FERROR, errno, "lseek returned %s, not %s",
big_num(ret), big_num(read_start));
exit_cleanup(RERR_FILEIO);
}
map->p_fd_offset = read_start;
}
map->p_offset = window_start;
map->p_len = window_size;
while (read_size > 0) {
int32 nread = read(map->fd, map->p + read_offset, read_size);
if (nread <= 0) {
if (!map->status)
map->status = nread ? errno : ENODATA;
/* The best we can do is zero the buffer -- the file
* has changed mid transfer! */
memset(map->p + read_offset, 0, read_size);
break;
}
map->p_fd_offset += nread;
read_offset += nread;
read_size -= nread;
}
return map->p + align_fudge;
}
int unmap_file(struct map_struct *map)
{
int ret;
if (map->p) {
free(map->p);
map->p = NULL;
}
ret = map->status;
memset(map, 0, sizeof map[0]);
free(map);
return ret;
}
rsync-3.1.0/syscall.c 0000664 0000000 0000000 00000024647 12076567221 013214 0 ustar root root /*
* Syscall wrappers to ensure that nothing gets done in dry_run mode
* and to handle system peculiarities.
*
* Copyright (C) 1998 Andrew Tridgell
* Copyright (C) 2002 Martin Pool
* Copyright (C) 2003-2013 Wayne Davison
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, visit the http://fsf.org website.
*/
#include "rsync.h"
#if !defined MKNOD_CREATES_SOCKETS && defined HAVE_SYS_UN_H
#include
#endif
#ifdef HAVE_SYS_ATTR_H
#include
#endif
#if defined HAVE_SYS_FALLOCATE && !defined HAVE_FALLOCATE
#include
#endif
extern int dry_run;
extern int am_root;
extern int am_sender;
extern int read_only;
extern int list_only;
extern int preserve_perms;
extern int preserve_executability;
#define RETURN_ERROR_IF(x,e) \
do { \
if (x) { \
errno = (e); \
return -1; \
} \
} while (0)
#define RETURN_ERROR_IF_RO_OR_LO RETURN_ERROR_IF(read_only || list_only, EROFS)
int do_unlink(const char *fname)
{
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
return unlink(fname);
}
#ifdef SUPPORT_LINKS
int do_symlink(const char *lnk, const char *fname)
{
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
#if defined NO_SYMLINK_XATTRS || defined NO_SYMLINK_USER_XATTRS
/* For --fake-super, we create a normal file with mode 0600
* and write the lnk into it. */
if (am_root < 0) {
int ok, len = strlen(lnk);
int fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR|S_IRUSR);
if (fd < 0)
return -1;
ok = write(fd, lnk, len) == len;
if (close(fd) < 0)
ok = 0;
return ok ? 0 : -1;
}
#endif
return symlink(lnk, fname);
}
#if defined NO_SYMLINK_XATTRS || defined NO_SYMLINK_USER_XATTRS
ssize_t do_readlink(const char *path, char *buf, size_t bufsiz)
{
/* For --fake-super, we read the link from the file. */
if (am_root < 0) {
int fd = do_open_nofollow(path, O_RDONLY);
if (fd >= 0) {
int len = read(fd, buf, bufsiz);
close(fd);
return len;
}
if (errno != ELOOP)
return -1;
/* A real symlink needs to be turned into a fake one on the receiving
* side, so tell the generator that the link has no length. */
if (!am_sender)
return 0;
/* Otherwise fall through and let the sender report the real length. */
}
return readlink(path, buf, bufsiz);
}
#endif
#endif
#ifdef HAVE_LINK
int do_link(const char *fname1, const char *fname2)
{
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
return link(fname1, fname2);
}
#endif
int do_lchown(const char *path, uid_t owner, gid_t group)
{
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
#ifndef HAVE_LCHOWN
#define lchown chown
#endif
return lchown(path, owner, group);
}
int do_mknod(const char *pathname, mode_t mode, dev_t dev)
{
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
/* For --fake-super, we create a normal file with mode 0600. */
if (am_root < 0) {
int fd = open(pathname, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR|S_IRUSR);
if (fd < 0 || close(fd) < 0)
return -1;
return 0;
}
#if !defined MKNOD_CREATES_FIFOS && defined HAVE_MKFIFO
if (S_ISFIFO(mode))
return mkfifo(pathname, mode);
#endif
#if !defined MKNOD_CREATES_SOCKETS && defined HAVE_SYS_UN_H
if (S_ISSOCK(mode)) {
int sock;
struct sockaddr_un saddr;
#ifdef HAVE_SOCKADDR_UN_LEN
unsigned int len =
#endif
strlcpy(saddr.sun_path, pathname, sizeof saddr.sun_path);
#ifdef HAVE_SOCKADDR_UN_LEN
saddr.sun_len = len >= sizeof saddr.sun_path
? sizeof saddr.sun_path : len + 1;
#endif
saddr.sun_family = AF_UNIX;
if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0
|| (unlink(pathname) < 0 && errno != ENOENT)
|| (bind(sock, (struct sockaddr*)&saddr, sizeof saddr)) < 0)
return -1;
close(sock);
#ifdef HAVE_CHMOD
return do_chmod(pathname, mode);
#else
return 0;
#endif
}
#endif
#ifdef HAVE_MKNOD
return mknod(pathname, mode, dev);
#else
return -1;
#endif
}
int do_rmdir(const char *pathname)
{
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
return rmdir(pathname);
}
int do_open(const char *pathname, int flags, mode_t mode)
{
if (flags != O_RDONLY) {
RETURN_ERROR_IF(dry_run, 0);
RETURN_ERROR_IF_RO_OR_LO;
}
return open(pathname, flags | O_BINARY, mode);
}
#ifdef HAVE_CHMOD
int do_chmod(const char *path, mode_t mode)
{
int code;
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
#ifdef HAVE_LCHMOD
code = lchmod(path, mode & CHMOD_BITS);
#else
if (S_ISLNK(mode)) {
# if defined HAVE_SETATTRLIST
struct attrlist attrList;
uint32_t m = mode & CHMOD_BITS; /* manpage is wrong: not mode_t! */
memset(&attrList, 0, sizeof attrList);
attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
attrList.commonattr = ATTR_CMN_ACCESSMASK;
code = setattrlist(path, &attrList, &m, sizeof m, FSOPT_NOFOLLOW);
# else
code = 1;
# endif
} else
code = chmod(path, mode & CHMOD_BITS); /* DISCOURAGED FUNCTION */
#endif /* !HAVE_LCHMOD */
if (code != 0 && (preserve_perms || preserve_executability))
return code;
return 0;
}
#endif
int do_rename(const char *fname1, const char *fname2)
{
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
return rename(fname1, fname2);
}
#ifdef HAVE_FTRUNCATE
int do_ftruncate(int fd, OFF_T size)
{
int ret;
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
do {
ret = ftruncate(fd, size);
} while (ret < 0 && errno == EINTR);
return ret;
}
#endif
void trim_trailing_slashes(char *name)
{
int l;
/* Some BSD systems cannot make a directory if the name
* contains a trailing slash.
* */
/* Don't change empty string; and also we can't improve on
* "/" */
l = strlen(name);
while (l > 1) {
if (name[--l] != '/')
break;
name[l] = '\0';
}
}
int do_mkdir(char *fname, mode_t mode)
{
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
trim_trailing_slashes(fname);
return mkdir(fname, mode);
}
/* like mkstemp but forces permissions */
int do_mkstemp(char *template, mode_t perms)
{
RETURN_ERROR_IF(dry_run, 0);
RETURN_ERROR_IF(read_only, EROFS);
perms |= S_IWUSR;
#if defined HAVE_SECURE_MKSTEMP && defined HAVE_FCHMOD && (!defined HAVE_OPEN64 || defined HAVE_MKSTEMP64)
{
int fd = mkstemp(template);
if (fd == -1)
return -1;
if (fchmod(fd, perms) != 0 && preserve_perms) {
int errno_save = errno;
close(fd);
unlink(template);
errno = errno_save;
return -1;
}
#if defined HAVE_SETMODE && O_BINARY
setmode(fd, O_BINARY);
#endif
return fd;
}
#else
if (!mktemp(template))
return -1;
return do_open(template, O_RDWR|O_EXCL|O_CREAT, perms);
#endif
}
int do_stat(const char *fname, STRUCT_STAT *st)
{
#ifdef USE_STAT64_FUNCS
return stat64(fname, st);
#else
return stat(fname, st);
#endif
}
int do_lstat(const char *fname, STRUCT_STAT *st)
{
#ifdef SUPPORT_LINKS
# ifdef USE_STAT64_FUNCS
return lstat64(fname, st);
# else
return lstat(fname, st);
# endif
#else
return do_stat(fname, st);
#endif
}
int do_fstat(int fd, STRUCT_STAT *st)
{
#ifdef USE_STAT64_FUNCS
return fstat64(fd, st);
#else
return fstat(fd, st);
#endif
}
OFF_T do_lseek(int fd, OFF_T offset, int whence)
{
#ifdef HAVE_LSEEK64
#if !SIZEOF_OFF64_T
OFF_T lseek64();
#else
off64_t lseek64();
#endif
return lseek64(fd, offset, whence);
#else
return lseek(fd, offset, whence);
#endif
}
#ifdef HAVE_UTIMENSAT
int do_utimensat(const char *fname, time_t modtime, uint32 mod_nsec)
{
struct timespec t[2];
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
t[0].tv_sec = 0;
t[0].tv_nsec = UTIME_NOW;
t[1].tv_sec = modtime;
t[1].tv_nsec = mod_nsec;
return utimensat(AT_FDCWD, fname, t, AT_SYMLINK_NOFOLLOW);
}
#endif
#ifdef HAVE_LUTIMES
int do_lutimes(const char *fname, time_t modtime, uint32 mod_nsec)
{
struct timeval t[2];
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
t[0].tv_sec = time(NULL);
t[0].tv_usec = 0;
t[1].tv_sec = modtime;
t[1].tv_usec = mod_nsec / 1000;
return lutimes(fname, t);
}
#endif
#ifdef HAVE_UTIMES
int do_utimes(const char *fname, time_t modtime, uint32 mod_nsec)
{
struct timeval t[2];
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
t[0].tv_sec = time(NULL);
t[0].tv_usec = 0;
t[1].tv_sec = modtime;
t[1].tv_usec = mod_nsec / 1000;
return utimes(fname, t);
}
#elif defined HAVE_UTIME
int do_utime(const char *fname, time_t modtime, UNUSED(uint32 mod_nsec))
{
#ifdef HAVE_STRUCT_UTIMBUF
struct utimbuf tbuf;
#else
time_t t[2];
#endif
if (dry_run) return 0;
RETURN_ERROR_IF_RO_OR_LO;
# ifdef HAVE_STRUCT_UTIMBUF
tbuf.actime = time(NULL);
tbuf.modtime = modtime;
return utime(fname, &tbuf);
# else
t[0] = time(NULL);
t[1] = modtime;
return utime(fname, t);
# endif
}
#else
#error Need utimes or utime function.
#endif
#ifdef SUPPORT_PREALLOCATION
int do_fallocate(int fd, OFF_T offset, OFF_T length)
{
#ifdef FALLOC_FL_KEEP_SIZE
#define DO_FALLOC_OPTIONS FALLOC_FL_KEEP_SIZE
#else
#define DO_FALLOC_OPTIONS 0
#endif
RETURN_ERROR_IF(dry_run, 0);
RETURN_ERROR_IF_RO_OR_LO;
#if defined HAVE_FALLOCATE
return fallocate(fd, DO_FALLOC_OPTIONS, offset, length);
#elif defined HAVE_SYS_FALLOCATE
return syscall(SYS_fallocate, fd, DO_FALLOC_OPTIONS, (loff_t)offset, (loff_t)length);
#elif defined HAVE_EFFICIENT_POSIX_FALLOCATE
return posix_fallocate(fd, offset, length);
#else
#error Coding error in SUPPORT_PREALLOCATION logic.
#endif
}
#endif
int do_open_nofollow(const char *pathname, int flags)
{
#ifndef O_NOFOLLOW
STRUCT_STAT f_st, l_st;
#endif
int fd;
if (flags != O_RDONLY) {
RETURN_ERROR_IF(dry_run, 0);
RETURN_ERROR_IF_RO_OR_LO;
#ifndef O_NOFOLLOW
/* This function doesn't support write attempts w/o O_NOFOLLOW. */
errno = EINVAL;
return -1;
#endif
}
#ifdef O_NOFOLLOW
fd = open(pathname, flags|O_NOFOLLOW);
#else
if (do_lstat(pathname, &l_st) < 0)
return -1;
if (S_ISLNK(l_st.st_mode)) {
errno = ELOOP;
return -1;
}
if ((fd = open(pathname, flags)) < 0)
return fd;
if (do_fstat(fd, &f_st) < 0) {
close_and_return_error:
{
int save_errno = errno;
close(fd);
errno = save_errno;
}
return -1;
}
if (l_st.st_dev != f_st.st_dev || l_st.st_ino != f_st.st_ino) {
errno = EINVAL;
goto close_and_return_error;
}
#endif
return fd;
}
rsync-3.1.0/wildtest.txt 0000664 0000000 0000000 00000010211 10351415543 013745 0 ustar root root # Input is in the following format (all items white-space separated):
#
# The first two items are 1 or 0 indicating if the wildmat call is expected to
# succeed and if fnmatch works the same way as wildmat, respectively. After
# that is a text string for the match, and a pattern string. Strings can be
# quoted (if desired) in either double or single quotes, as well as backticks.
#
# MATCH FNMATCH_SAME "text to match" 'pattern to use'
# Basic wildmat features
1 1 foo foo
0 1 foo bar
1 1 '' ""
1 1 foo ???
0 1 foo ??
1 1 foo *
1 1 foo f*
0 1 foo *f
1 1 foo *foo*
1 1 foobar *ob*a*r*
1 1 aaaaaaabababab *ab
1 1 foo* foo\*
0 1 foobar foo\*bar
1 1 f\oo f\\oo
1 1 ball *[al]?
0 1 ten [ten]
1 1 ten **[!te]
0 1 ten **[!ten]
1 1 ten t[a-g]n
0 1 ten t[!a-g]n
1 1 ton t[!a-g]n
1 1 ton t[^a-g]n
1 1 a]b a[]]b
1 1 a-b a[]-]b
1 1 a]b a[]-]b
0 1 aab a[]-]b
1 1 aab a[]a-]b
1 1 ] ]
# Extended slash-matching features
0 1 foo/baz/bar foo*bar
1 1 foo/baz/bar foo**bar
0 1 foo/bar foo?bar
0 1 foo/bar foo[/]bar
0 1 foo/bar f[^eiu][^eiu][^eiu][^eiu][^eiu]r
1 1 foo-bar f[^eiu][^eiu][^eiu][^eiu][^eiu]r
0 1 foo **/foo
1 1 /foo **/foo
1 1 bar/baz/foo **/foo
0 1 bar/baz/foo */foo
0 0 foo/bar/baz **/bar*
1 1 deep/foo/bar/baz **/bar/*
0 1 deep/foo/bar/baz/ **/bar/*
1 1 deep/foo/bar/baz/ **/bar/**
0 1 deep/foo/bar **/bar/*
1 1 deep/foo/bar/ **/bar/**
1 1 foo/bar/baz **/bar**
1 1 foo/bar/baz/x */bar/**
0 0 deep/foo/bar/baz/x */bar/**
1 1 deep/foo/bar/baz/x **/bar/*/*
# Various additional tests
0 1 acrt a[c-c]st
1 1 acrt a[c-c]rt
0 1 ] [!]-]
1 1 a [!]-]
0 1 '' \
0 1 \ \
0 1 /\ */\
1 1 /\ */\\
1 1 foo foo
1 1 @foo @foo
0 1 foo @foo
1 1 [ab] \[ab]
1 1 [ab] [[]ab]
1 1 [ab] [[:]ab]
0 1 [ab] [[::]ab]
1 1 [ab] [[:digit]ab]
1 1 [ab] [\[:]ab]
1 1 ?a?b \??\?b
1 1 abc \a\b\c
0 1 foo ''
1 1 foo/bar/baz/to **/t[o]
# Character class tests
1 1 a1B [[:alpha:]][[:digit:]][[:upper:]]
0 1 a [[:digit:][:upper:][:space:]]
1 1 A [[:digit:][:upper:][:space:]]
1 1 1 [[:digit:][:upper:][:space:]]
0 1 1 [[:digit:][:upper:][:spaci:]]
1 1 ' ' [[:digit:][:upper:][:space:]]
0 1 . [[:digit:][:upper:][:space:]]
1 1 . [[:digit:][:punct:][:space:]]
1 1 5 [[:xdigit:]]
1 1 f [[:xdigit:]]
1 1 D [[:xdigit:]]
1 1 _ [[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]
#1 1 … [^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]
1 1 [^[:alnum:][:alpha:][:blank:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]
1 1 . [^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]
1 1 5 [a-c[:digit:]x-z]
1 1 b [a-c[:digit:]x-z]
1 1 y [a-c[:digit:]x-z]
0 1 q [a-c[:digit:]x-z]
# Additional tests, including some malformed wildmats
1 1 ] [\\-^]
0 1 [ [\\-^]
1 1 - [\-_]
1 1 ] [\]]
0 1 \] [\]]
0 1 \ [\]]
0 1 ab a[]b
0 1 a[]b a[]b
0 1 ab[ ab[
0 1 ab [!
0 1 ab [-
1 1 - [-]
0 1 - [a-
0 1 - [!a-
1 1 - [--A]
1 1 5 [--A]
1 1 ' ' '[ --]'
1 1 $ '[ --]'
1 1 - '[ --]'
0 1 0 '[ --]'
1 1 - [---]
1 1 - [------]
0 1 j [a-e-n]
1 1 - [a-e-n]
1 1 a [!------]
0 1 [ []-a]
1 1 ^ []-a]
0 1 ^ [!]-a]
1 1 [ [!]-a]
1 1 ^ [a^bc]
1 1 -b] [a-]b]
0 1 \ [\]
1 1 \ [\\]
0 1 \ [!\\]
1 1 G [A-\\]
0 1 aaabbb b*a
0 1 aabcaa *ba*
1 1 , [,]
1 1 , [\\,]
1 1 \ [\\,]
1 1 - [,-.]
0 1 + [,-.]
0 1 -.] [,-.]
1 1 2 [\1-\3]
1 1 3 [\1-\3]
0 1 4 [\1-\3]
1 1 \ [[-\]]
1 1 [ [[-\]]
1 1 ] [[-\]]
0 1 - [[-\]]
# Test recursion and the abort code (use "wildtest -i" to see iteration counts)
1 1 -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1 -*-*-*-*-*-*-12-*-*-*-m-*-*-*
0 1 -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1 -*-*-*-*-*-*-12-*-*-*-m-*-*-*
0 1 -adobe-courier-bold-o-normal--12-120-75-75-/-70-iso8859-1 -*-*-*-*-*-*-12-*-*-*-m-*-*-*
1 1 /adobe/courier/bold/o/normal//12/120/75/75/m/70/iso8859/1 /*/*/*/*/*/*/12/*/*/*/m/*/*/*
0 1 /adobe/courier/bold/o/normal//12/120/75/75/X/70/iso8859/1 /*/*/*/*/*/*/12/*/*/*/m/*/*/*
1 1 abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txt **/*a*b*g*n*t
0 1 abcd/abcdefg/abcdefghijk/abcdefghijklmnop.txtz **/*a*b*g*n*t
rsync-3.1.0/shconfig.in 0000775 0000000 0000000 00000000550 11636172346 013515 0 ustar root root #! /bin/sh
# config.sh.in
# This file is processed by config.status to produce config.status,
# containing autoconf-determined values needed by the test scripts.
ECHO_T="@ECHO_T@"
ECHO_N="@ECHO_N@"
ECHO_C="@ECHO_C@"
HOST_OS="@host_os@"
SHELL_PATH="@SHELL_PATH@"
FAKEROOT_PATH="@FAKEROOT_PATH@"
export ECHO_T ECHO_N ECHO_C HOST_OS SHELL_PATH FAKEROOT_PATH
rsync-3.1.0/params.c 0000664 0000000 0000000 00000053523 11536535255 013022 0 ustar root root /* This modules is based on the params.c module from Samba, written by Karl Auer
and much modifed by Christopher Hertel. */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, visit the http://fsf.org website.
*/
/* -------------------------------------------------------------------------- **
*
* Module name: params
*
* -------------------------------------------------------------------------- **
*
* This module performs lexical analysis and initial parsing of a
* Windows-like parameter file. It recognizes and handles four token
* types: section-name, parameter-name, parameter-value, and
* end-of-file. Comments and line continuation are handled
* internally.
*
* The entry point to the module is function pm_process(). This
* function opens the source file, calls the Parse() function to parse
* the input, and then closes the file when either the EOF is reached
* or a fatal error is encountered.
*
* A sample parameter file might look like this:
*
* [section one]
* parameter one = value string
* parameter two = another value
* [section two]
* new parameter = some value or t'other
*
* The parameter file is divided into sections by section headers:
* section names enclosed in square brackets (eg. [section one]).
* Each section contains parameter lines, each of which consist of a
* parameter name and value delimited by an equal sign. Roughly, the
* syntax is:
*
* :== { } EOF
*
* :== { }
*
* :== '[' NAME ']'
*
* :== NAME '=' VALUE '\n'
*
* Blank lines and comment lines are ignored. Comment lines are lines
* beginning with either a semicolon (';') or a pound sign ('#').
*
* All whitespace in section names and parameter names is compressed
* to single spaces. Leading and trailing whitespace is stipped from
* both names and values.
*
* Only the first equals sign in a parameter line is significant.
* Parameter values may contain equals signs, square brackets and
* semicolons. Internal whitespace is retained in parameter values,
* with the exception of the '\r' character, which is stripped for
* historic reasons. Parameter names may not start with a left square
* bracket, an equal sign, a pound sign, or a semicolon, because these
* are used to identify other tokens.
*
* -------------------------------------------------------------------------- **
*/
#include "rsync.h"
#include "ifuncs.h"
#include "itypes.h"
/* -------------------------------------------------------------------------- **
* Constants...
*/
#define BUFR_INC 1024
/* -------------------------------------------------------------------------- **
* Variables...
*
* bufr - pointer to a global buffer. This is probably a kludge,
* but it was the nicest kludge I could think of (for now).
* bSize - The size of the global buffer .
*/
static char *bufr = NULL;
static int bSize = 0;
static BOOL (*the_sfunc)(char *);
static BOOL (*the_pfunc)(char *, char *);
/* -------------------------------------------------------------------------- **
* Functions...
*/
static int EatWhitespace( FILE *InFile )
/* ------------------------------------------------------------------------ **
* Scan past whitespace (see ctype(3C)) and return the first non-whitespace
* character, or newline, or EOF.
*
* Input: InFile - Input source.
*
* Output: The next non-whitespace character in the input stream.
*
* Notes: Because the config files use a line-oriented grammar, we
* explicitly exclude the newline character from the list of
* whitespace characters.
* - Note that both EOF (-1) and the nul character ('\0') are
* considered end-of-file markers.
*
* ------------------------------------------------------------------------ **
*/
{
int c;
for( c = getc( InFile ); isspace( c ) && ('\n' != c); c = getc( InFile ) )
;
return( c );
} /* EatWhitespace */
static int EatComment( FILE *InFile )
/* ------------------------------------------------------------------------ **
* Scan to the end of a comment.
*
* Input: InFile - Input source.
*
* Output: The character that marks the end of the comment. Normally,
* this will be a newline, but it *might* be an EOF.
*
* Notes: Because the config files use a line-oriented grammar, we
* explicitly exclude the newline character from the list of
* whitespace characters.
* - Note that both EOF (-1) and the nul character ('\0') are
* considered end-of-file markers.
*
* ------------------------------------------------------------------------ **
*/
{
int c;
for( c = getc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = getc( InFile ) )
;
return( c );
} /* EatComment */
static int Continuation( char *line, int pos )
/* ------------------------------------------------------------------------ **
* Scan backards within a string to discover if the last non-whitespace
* character is a line-continuation character ('\\').
*
* Input: line - A pointer to a buffer containing the string to be
* scanned.
* pos - This is taken to be the offset of the end of the
* string. This position is *not* scanned.
*
* Output: The offset of the '\\' character if it was found, or -1 to
* indicate that it was not.
*
* ------------------------------------------------------------------------ **
*/
{
pos--;
while( pos >= 0 && isSpace(line + pos) )
pos--;
return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 );
} /* Continuation */
static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) )
/* ------------------------------------------------------------------------ **
* Scan a section name, and pass the name to function sfunc().
*
* Input: InFile - Input source.
* sfunc - Pointer to the function to be called if the section
* name is successfully read.
*
* Output: True if the section name was read and True was returned from
* . False if failed or if a lexical error was
* encountered.
*
* ------------------------------------------------------------------------ **
*/
{
int c;
int i;
int end;
char *func = "params.c:Section() -";
i = 0; /* is the offset of the next free byte in bufr[] and */
end = 0; /* is the current "end of string" offset. In most */
/* cases these will be the same, but if the last */
/* character written to bufr[] is a space, then */
/* will be one less than . */
c = EatWhitespace( InFile ); /* We've already got the '['. Scan */
/* past initial white space. */
while( (EOF != c) && (c > 0) )
{
/* Check that the buffer is big enough for the next character. */
if( i > (bSize - 2) )
{
bSize += BUFR_INC;
bufr = realloc_array( bufr, char, bSize );
if( NULL == bufr )
{
rprintf(FLOG, "%s Memory re-allocation failure.", func);
return( False );
}
}
/* Handle a single character. */
switch( c )
{
case ']': /* Found the closing bracket. */
bufr[end] = '\0';
if( 0 == end ) /* Don't allow an empty name. */
{
rprintf(FLOG, "%s Empty section name in config file.\n", func );
return( False );
}
if( !sfunc( bufr ) ) /* Got a valid name. Deal with it. */
return( False );
(void)EatComment( InFile ); /* Finish off the line. */
return( True );
case '\n': /* Got newline before closing ']'. */
i = Continuation( bufr, i ); /* Check for line continuation. */
if( i < 0 )
{
bufr[end] = '\0';
rprintf(FLOG, "%s Badly formed line in config file: %s\n",
func, bufr );
return( False );
}
end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i);
c = getc( InFile ); /* Continue with next line. */
break;
default: /* All else are a valid name chars. */
if( isspace( c ) ) /* One space per whitespace region. */
{
bufr[end] = ' ';
i = end + 1;
c = EatWhitespace( InFile );
}
else /* All others copy verbatim. */
{
bufr[i++] = c;
end = i;
c = getc( InFile );
}
}
}
/* We arrive here if we've met the EOF before the closing bracket. */
rprintf(FLOG, "%s Unexpected EOF in the config file: %s\n", func, bufr );
return( False );
} /* Section */
static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c )
/* ------------------------------------------------------------------------ **
* Scan a parameter name and value, and pass these two fields to pfunc().
*
* Input: InFile - The input source.
* pfunc - A pointer to the function that will be called to
* process the parameter, once it has been scanned.
* c - The first character of the parameter name, which
* would have been read by Parse(). Unlike a comment
* line or a section header, there is no lead-in
* character that can be discarded.
*
* Output: True if the parameter name and value were scanned and processed
* successfully, else False.
*
* Notes: This function is in two parts. The first loop scans the
* parameter name. Internal whitespace is compressed, and an
* equal sign (=) terminates the token. Leading and trailing
* whitespace is discarded. The second loop scans the parameter
* value. When both have been successfully identified, they are
* passed to pfunc() for processing.
*
* ------------------------------------------------------------------------ **
*/
{
int i = 0; /* Position within bufr. */
int end = 0; /* bufr[end] is current end-of-string. */
int vstart = 0; /* Starting position of the parameter value. */
char *func = "params.c:Parameter() -";
/* Read the parameter name. */
while( 0 == vstart ) /* Loop until we've found the start of the value. */
{
if( i > (bSize - 2) ) /* Ensure there's space for next char. */
{
bSize += BUFR_INC;
bufr = realloc_array( bufr, char, bSize );
if( NULL == bufr )
{
rprintf(FLOG, "%s Memory re-allocation failure.", func) ;
return( False );
}
}
switch( c )
{
case '=': /* Equal sign marks end of param name. */
if( 0 == end ) /* Don't allow an empty name. */
{
rprintf(FLOG, "%s Invalid parameter name in config file.\n", func );
return( False );
}
bufr[end++] = '\0'; /* Mark end of string & advance. */
i = vstart = end; /* New string starts here. */
c = EatWhitespace(InFile);
break;
case '\n': /* Find continuation char, else error. */
i = Continuation( bufr, i );
if( i < 0 )
{
bufr[end] = '\0';
rprintf(FLOG, "%s Ignoring badly formed line in config file: %s\n",
func, bufr );
return( True );
}
end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i);
c = getc( InFile ); /* Read past eoln. */
break;
case '\0': /* Shouldn't have EOF within param name. */
case EOF:
bufr[i] = '\0';
rprintf(FLOG, "%s Unexpected end-of-file at: %s\n", func, bufr );
return( True );
case ' ':
case '\t':
/* A directive divides at the first space or tab. */
if (*bufr == '&') {
bufr[end++] = '\0';
i = vstart = end;
c = EatWhitespace(InFile);
if (c == '=')
c = EatWhitespace(InFile);
break;
}
/* FALL THROUGH */
default:
if( isspace( c ) ) /* One ' ' per whitespace region. */
{
bufr[end] = ' ';
i = end + 1;
c = EatWhitespace( InFile );
}
else /* All others verbatim. */
{
bufr[i++] = c;
end = i;
c = getc( InFile );
}
}
}
/* Now parse the value. */
while( (EOF !=c) && (c > 0) )
{
if( i > (bSize - 2) ) /* Make sure there's enough room. */
{
bSize += BUFR_INC;
bufr = realloc_array( bufr, char, bSize );
if( NULL == bufr )
{
rprintf(FLOG, "%s Memory re-allocation failure.", func) ;
return( False );
}
}
switch( c )
{
case '\r': /* Explicitly remove '\r' because the older */
c = getc( InFile ); /* version called fgets_slash() which also */
break; /* removes them. */
case '\n': /* Marks end of value unless there's a '\'. */
i = Continuation( bufr, i );
if( i < 0 )
c = 0;
else
{
for( end = i; end >= 0 && isSpace(bufr + end); end-- )
;
c = getc( InFile );
}
break;
default: /* All others verbatim. Note that spaces do */
bufr[i++] = c; /* not advance . This allows trimming */
if( !isspace( c ) ) /* of whitespace at the end of the line. */
end = i;
c = getc( InFile );
break;
}
}
bufr[end] = '\0'; /* End of value. */
return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */
} /* Parameter */
static int name_cmp(const void *n1, const void *n2)
{
return strcmp(*(char * const *)n1, *(char * const *)n2);
}
static int include_config(char *include, int manage_globals)
{
STRUCT_STAT sb;
char *match = manage_globals ? "*.conf" : "*.inc";
int ret;
if (do_stat(include, &sb) < 0) {
rsyserr(FLOG, errno, "unable to stat config file \"%s\"", include);
return 0;
}
if (S_ISREG(sb.st_mode)) {
if (manage_globals && the_sfunc)
the_sfunc("]push");
ret = pm_process(include, the_sfunc, the_pfunc);
if (manage_globals && the_sfunc)
the_sfunc("]pop");
} else if (S_ISDIR(sb.st_mode)) {
char buf[MAXPATHLEN], **bpp;
item_list conf_list;
struct dirent *di;
size_t j;
DIR *d;
if (!(d = opendir(include))) {
rsyserr(FLOG, errno, "unable to open config dir \"%s\"", include);
return 0;
}
memset(&conf_list, 0, sizeof conf_list);
while ((di = readdir(d)) != NULL) {
char *dname = d_name(di);
if (!wildmatch(match, dname))
continue;
bpp = EXPAND_ITEM_LIST(&conf_list, char *, 32);
pathjoin(buf, sizeof buf, include, dname);
*bpp = strdup(buf);
}
closedir(d);
if (!(bpp = conf_list.items))
return 1;
if (conf_list.count > 1)
qsort(bpp, conf_list.count, sizeof (char *), name_cmp);
for (j = 0, ret = 1; j < conf_list.count; j++) {
if (manage_globals && the_sfunc)
the_sfunc(j == 0 ? "]push" : "]reset");
if ((ret = pm_process(bpp[j], the_sfunc, the_pfunc)) != 1)
break;
}
if (manage_globals && the_sfunc)
the_sfunc("]pop");
for (j = 0; j < conf_list.count; j++)
free(bpp[j]);
free(bpp);
} else
ret = 0;
return ret;
}
static int parse_directives(char *name, char *val)
{
if (strcasecmp(name, "&include") == 0)
return include_config(val, 1);
if (strcasecmp(name, "&merge") == 0)
return include_config(val, 0);
rprintf(FLOG, "Unknown directive: %s.\n", name);
return 0;
}
static int Parse( FILE *InFile,
BOOL (*sfunc)(char *),
BOOL (*pfunc)(char *, char *) )
/* ------------------------------------------------------------------------ **
* Scan & parse the input.
*
* Input: InFile - Input source.
* sfunc - Function to be called when a section name is scanned.
* See Section().
* pfunc - Function to be called when a parameter is scanned.
* See Parameter().
*
* Output: 1 if the file was successfully scanned, 2 if the file was
* scanned until a section header with no section function, else 0.
*
* Notes: The input can be viewed in terms of 'lines'. There are four
* types of lines:
* Blank - May contain whitespace, otherwise empty.
* Comment - First non-whitespace character is a ';' or '#'.
* The remainder of the line is ignored.
* Section - First non-whitespace character is a '['.
* Parameter - The default case.
*
* ------------------------------------------------------------------------ **
*/
{
int c;
c = EatWhitespace( InFile );
while( (EOF != c) && (c > 0) )
{
switch( c )
{
case '\n': /* Blank line. */
c = EatWhitespace( InFile );
break;
case ';': /* Comment line. */
case '#':
c = EatComment( InFile );
break;
case '[': /* Section Header. */
if (!sfunc)
return 2;
if( !Section( InFile, sfunc ) )
return 0;
c = EatWhitespace( InFile );
break;
case '\\': /* Bogus backslash. */
c = EatWhitespace( InFile );
break;
case '&': /* Handle directives */
the_sfunc = sfunc;
the_pfunc = pfunc;
c = Parameter( InFile, parse_directives, c );
if (c != 1)
return c;
c = EatWhitespace( InFile );
break;
default: /* Parameter line. */
if( !Parameter( InFile, pfunc, c ) )
return 0;
c = EatWhitespace( InFile );
break;
}
}
return 1;
} /* Parse */
static FILE *OpenConfFile( char *FileName )
/* ------------------------------------------------------------------------ **
* Open a config file.
*
* Input: FileName - The pathname of the config file to be opened.
*
* Output: A pointer of type (FILE *) to the opened file, or NULL if the
* file could not be opened.
*
* ------------------------------------------------------------------------ **
*/
{
FILE *OpenedFile;
char *func = "params.c:OpenConfFile() -";
if( NULL == FileName || 0 == *FileName )
{
rprintf(FLOG, "%s No config filename specified.\n", func);
return( NULL );
}
OpenedFile = fopen( FileName, "r" );
if( NULL == OpenedFile )
{
rsyserr(FLOG, errno, "unable to open config file \"%s\"",
FileName);
}
return( OpenedFile );
} /* OpenConfFile */
int pm_process( char *FileName,
BOOL (*sfunc)(char *),
BOOL (*pfunc)(char *, char *) )
/* ------------------------------------------------------------------------ **
* Process the named parameter file.
*
* Input: FileName - The pathname of the parameter file to be opened.
* sfunc - A pointer to a function that will be called when
* a section name is discovered.
* pfunc - A pointer to a function that will be called when
* a parameter name and value are discovered.
*
* Output: 1 if the file was successfully parsed, 2 if parsing ended at a
* section header w/o a section function, else 0.
*
* ------------------------------------------------------------------------ **
*/
{
int result;
FILE *InFile;
char *func = "params.c:pm_process() -";
InFile = OpenConfFile( FileName ); /* Open the config file. */
if( NULL == InFile )
return( False );
if( NULL != bufr ) /* If we already have a buffer */
result = Parse( InFile, sfunc, pfunc ); /* (recursive call), then just */
/* use it. */
else /* If we don't have a buffer */
{ /* allocate one, then parse, */
bSize = BUFR_INC; /* then free. */
bufr = new_array( char, bSize );
if( NULL == bufr )
{
rprintf(FLOG, "%s memory allocation failure.\n", func);
fclose(InFile);
return( False );
}
result = Parse( InFile, sfunc, pfunc );
free( bufr );
bufr = NULL;
bSize = 0;
}
fclose(InFile);
if( !result ) /* Generic failure. */
{
rprintf(FLOG, "%s Failed. Error returned from params.c:parse().\n", func);
return 0;
}
return result;
} /* pm_process */
/* -------------------------------------------------------------------------- */
rsync-3.1.0/testhelp/ 0000775 0000000 0000000 00000000000 12221641132 013173 5 ustar root root rsync-3.1.0/testhelp/maketree.py 0000664 0000000 0000000 00000007202 07436504143 015357 0 ustar root root #! /usr/bin/python2.2
# Copyright (C) 2002 by Martin Pool
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version
# 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# Populate a tree with pseudo-randomly distributed files to test
# rsync.
from __future__ import generators
import random, string, os, os.path
nfiles = 10000
depth = 5
n_children = 20
n_files = 20
n_symlinks = 10
name_chars = string.digits + string.letters
abuffer = 'a' * 1024
def random_name_chars():
a = ""
for i in range(10):
a = a + random.choice(name_chars)
return a
def generate_names():
n = 0
while 1:
yield "%05d_%s" % (n, random_name_chars())
n += 1
class TreeBuilder:
def __init__(self):
self.n_children = 20
self.n_files = 100
self.total_entries = 100000 # long(1e8)
self.actual_size = 0
self.name_gen = generate_names()
self.all_files = []
self.all_dirs = []
self.all_symlinks = []
def random_size(self):
return random.lognormvariate(4, 4)
def random_symlink_target(self):
what = random.choice(['directory', 'file', 'symlink', 'none'])
try:
if what == 'directory':
return random.choice(self.all_dirs)
elif what == 'file':
return random.choice(self.all_files)
elif what == 'symlink':
return random.choice(self.all_symlinks)
elif what == 'none':
return self.name_gen.next()
except IndexError:
return self.name_gen.next()
def can_continue(self):
self.total_entries -= 1
return self.total_entries > 0
def build_tree(self, prefix, depth):
"""Generate a breadth-first tree"""
for count, function in [[n_files, self.make_file],
[n_children, self.make_child_recurse],
[n_symlinks, self.make_symlink]]:
for i in range(count):
if not self.can_continue():
return
name = os.path.join(prefix, self.name_gen.next())
function(name, depth)
def print_summary(self):
print "total bytes: %d" % self.actual_size
def make_child_recurse(self, dname, depth):
if depth > 1:
self.make_dir(dname)
self.build_tree(dname, depth-1)
def make_dir(self, dname, depth='ignore'):
print "%s/" % (dname)
os.mkdir(dname)
self.all_dirs.append(dname)
def make_symlink(self, lname, depth='ignore'):
print "%s -> %s" % (lname, self.random_symlink_target())
def make_file(self, fname, depth='ignore'):
size = long(self.random_size())
print "%-70s %d" % (fname, size)
f = open(fname, 'w')
f.truncate(size)
self.fill_file(f, size)
self.all_files.append(fname)
self.actual_size += size
def fill_file(self, f, size):
while size > 0:
f.write(abuffer[:size])
size -= len(abuffer)
tb = TreeBuilder()
tb.build_tree('/tmp/foo', 3)
tb.print_summary()
rsync-3.1.0/packaging/ 0000775 0000000 0000000 00000000000 12221641132 013267 5 ustar root root rsync-3.1.0/packaging/solaris/ 0000775 0000000 0000000 00000000000 12221641132 014743 5 ustar root root rsync-3.1.0/packaging/solaris/build_pkg.sh 0000664 0000000 0000000 00000004747 07505125477 017275 0 ustar root root #!/bin/sh
# Shell script for building Solaris package of rsync
# Author: Jens Apel
# License: GPL
#
# BASEDIR is /usr/local and should be the same as the
# --prefix parameter of configure
#
# this script should be copied under
# packaging/solaris/5.8/build_pkg.sh
# Definitions start here
# you can edit this, if you like
# The Package name under which rsync will b installed
PKGNAME=SMBrsync
# Extract common info requires for the 'info' part of the package.
# This should be made generic and generated by the configure script
# but for now it is hard coded
BASEDIR=/usr/local
VERSION="2.5.5"
ARCH=`uname -p`
NAME=rsync
# Definitions end here
# Please do not edit below this line or you know what you do.
## Start by faking root install
echo "Creating install directory (fake $BASEDIR)..."
START=`pwd`
FAKE_ROOT=$START/${PKGNAME}
mkdir $FAKE_ROOT
# copy the binary and the man page to their places
mkdir $FAKE_ROOT/bin
mkdir -p $FAKE_ROOT/doc/rsync
mkdir -p $FAKE_ROOT/man/man1
mkdir -p $FAKE_ROOT/man/man5
cp ../../../rsync $FAKE_ROOT/bin/rsync
cp ../../../rsync.1 $FAKE_ROOT/man/man1/rsync.1
cp ../../../rsyncd.conf.5 $FAKE_ROOT/man/man5/rsyncd.conf.5
cp ../../../README $FAKE_ROOT/doc/rsync/README
cp ../../../COPYING $FAKE_ROOT/doc/rsync/COPYING
cp ../../../tech_report.pdf $FAKE_ROOT/doc/rsync/tech_report.pdf
cp ../../../COPYING $FAKE_ROOT/COPYING
## Build info file
echo "Building pkginfo file..."
cat > $FAKE_ROOT/pkginfo << EOF_INFO
PKG=$PKGNAME
NAME=$NAME
DESC="Program for efficient remote updates of files."
VENDOR="Samba Team URL: http://samba.anu.edu.au/rsync/"
BASEDIR=$BASEDIR
ARCH=$ARCH
VERSION=$VERSION
CATEGORY=application
CLASSES=none
EOF_INFO
## Build prototype file
cat > $FAKE_ROOT/prototype << EOFPROTO
i copyright=COPYING
i pkginfo=pkginfo
d none bin 0755 bin bin
f none bin/rsync 0755 bin bin
d none doc 0755 bin bin
d none doc/$NAME 0755 bin bin
f none doc/$NAME/README 0644 bin bin
f none doc/$NAME/COPYING 0644 bin bin
f none doc/$NAME/tech_report.pdf 0644 bin bin
d none man 0755 bin bin
d none man/man1 0755 bin bin
f none man/man1/rsync.1 0644 bin bin
d none man/man5 0755 bin bin
f none man/man5/rsyncd.conf.5 0644 bin bin
EOFPROTO
## And now build the package.
OUTPUTFILE=$PKGNAME-$VERSION-sol8-$ARCH-local.pkg
echo "Building package.."
echo FAKE_ROOT = $FAKE_ROOT
cd $FAKE_ROOT
pkgmk -d . -r . -f ./prototype -o
pkgtrans -os . $OUTPUTFILE $PKGNAME
mv $OUTPUTFILE ..
cd ..
# Comment this out if you want to see, which file structure has been created
rm -rf $FAKE_ROOT
rsync-3.1.0/packaging/nightly-rsync 0000775 0000000 0000000 00000012267 11364616643 016057 0 ustar root root #!/usr/bin/perl
use strict;
# This script expects the directory ~/samba-rsync-ftp to exist and to be a
# copy of the /home/ftp/pub/rsync dir on samba.org. It also requires a
# git checkout of rsync (feel free to use your normal rsync build dir as
# long as it doesn't have any uncommitted changes).
#
# If this is run with -ctu, it will make an updated "nightly" tar file in
# the nightly dir. It will also remove any old tar files, regenerate the
# HTML man pages in the nightly dir, and then rsync the changes to the
# samba.org server.
use Getopt::Long;
use Date::Format;
# Where the local copy of /home/ftp/pub/rsync/dev/nightly should be updated.
our $dest = $ENV{HOME} . '/samba-rsync-ftp/dev/nightly';
our $nightly_symlink = "$dest/rsync-HEAD.tar.gz";
our($make_tar, $upload, $help_opt);
&Getopt::Long::Configure('bundling');
&usage if !&GetOptions(
'make-tar|t' => \$make_tar,
'upload|u' => \$upload,
'help|h' => \$help_opt,
) || $help_opt;
our $name = time2str('rsync-HEAD-%Y%m%d-%H%M%Z', time, 'GMT');
our $ztoday = time2str('%d %b %Y', time);
our $today = $ztoday;
our $gen_target = $upload ? 'gensend' : 'gen';
die "$dest does not exist\n" unless -d $dest;
die "There is no .git dir in the current directory.\n" unless -d '.git';
die "There is no rsync checkout in the current directory.\n" unless -f 'rsyncd.conf.yo';
if ($make_tar) {
open(IN, '-|', 'git status') or die $!;
my $status = join('', );
close IN;
die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
die "The checkout is not on the master branch.\n" unless $status =~ /^# On branch master\n/;
system "make $gen_target" and die "make $gen_target failed!\n";
my @extra_files;
open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
while () {
if (s/^GENFILES=//) {
while (s/\\$//) {
$_ .= ;
}
@extra_files = split(' ', $_);
last;
}
}
close IN;
my $confversion;
open(IN, '<', 'configure.ac') or die "Unable to open configure.ac: $!\n";
while () {
if (/^RSYNC_VERSION=(.*)/) {
$confversion = $1;
last;
}
}
close IN;
die "Unable to find RSYNC_VERSION in configure.ac\n" unless defined $confversion;
open(IN, '<', 'OLDNEWS') or die "Unable to open OLDNEWS: $!\n";
$_ = ;
my($lastversion) = /(\d+\.\d+\.\d+)/;
my $last_protocol_version;
while () {
if (my($ver,$pdate,$pver) = /^\s+\S\S\s\S\S\S\s\d\d\d\d\s+(\d+\.\d+\.\d+)\s+(\d\d \w\w\w \d\d\d\d\s+)?(\d+)$/) {
$last_protocol_version = $pver if $ver eq $lastversion;
}
}
close IN;
die "Unable to determine protocol_version for $lastversion.\n" unless defined $last_protocol_version;
my($protocol_version,$subprotocol_version);
open(IN, '<', 'rsync.h') or die "Unable to open rsync.h: $!\n";
while () {
if (/^#define\s+PROTOCOL_VERSION\s+(\d+)/) {
$protocol_version = $1;
} elsif (/^#define\s+SUBPROTOCOL_VERSION\s+(\d+)/) {
$subprotocol_version = $1;
}
}
close IN;
die "Unable to determine the current PROTOCOL_VERSION.\n" unless defined $protocol_version;
die "Unable to determine the current SUBPROTOCOL_VERSION.\n" unless defined $subprotocol_version;
if ($confversion =~ /dev|pre/) {
if ($last_protocol_version ne $protocol_version) {
if ($subprotocol_version == 0) {
die "SUBPROTOCOL_VERSION must not be 0 for a non-final release with a changed PROTOCOL_VERSION.\n";
}
} else {
if ($subprotocol_version != 0) {
die "SUBPROTOCOL_VERSION must be 0 when the PROTOCOL_VERSION hasn't changed from the last release.\n";
}
}
} else {
if ($subprotocol_version != 0) {
die "SUBPROTOCOL_VERSION must be 0 for a final release.\n";
}
}
print "Creating $name.tar.gz\n";
system "rsync -a @extra_files $name/";
system "git archive --format=tar --prefix=$name/ HEAD | tar xf -";
system "support/git-set-file-times --prefix=$name/";
system "fakeroot tar czf $dest/$name.tar.gz $name; rm -rf $name";
unlink($nightly_symlink);
symlink("$name.tar.gz", $nightly_symlink);
}
foreach my $fn (qw( rsync.yo rsyncd.conf.yo )) {
my $yo_tmp = "$dest/$fn";
(my $html_fn = "$dest/$fn") =~ s/\.yo/.html/;
open(IN, '<', $fn) or die $!;
undef $/; $_ = ; $/ = "\n";
close IN;
s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m;
#s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m;
open(OUT, '>', $yo_tmp) or die $!;
print OUT $_;
close OUT;
system 'yodl2html', '-o', $html_fn, $yo_tmp;
unlink($yo_tmp);
}
chdir($dest) or die $!;
my $cnt = 0;
open(PIPE, '-|', 'ls -1t rsync-HEAD-*') or die $!;
while () {
chomp;
next if $cnt++ < 10;
unlink($_);
}
close PIPE;
system 'ls -ltr';
if ($upload) {
my $opt = '';
if (defined $ENV{RSYNC_PARTIAL_DIR}) {
$opt = " -f 'R $ENV{RSYNC_PARTIAL_DIR}'";
}
system "rsync$opt -aviHP --delete-after . samba.org:/home/ftp/pub/rsync/dev/nightly";
}
exit;
sub usage
{
die <