view release on metacpan or search on metacpan
BackupPC_XS.xs view on Meta::CPAN
#define hv_get_uint(hv, key, value) { SV** svp = hv_fetch((hv), (key), strlen(key), 0); if ( svp && *svp ) (value) = SvUV(*svp); }
#define hv_get_str(hv, key, value, len) { SV** svp = hv_fetch((hv), (key), strlen(key), 0); if ( svp && *svp ) (value) = SvPV(*svp, len); }
static HV* convert_file2hv(bpc_attrib_file *file, char *fileName)
{
HV *rh;
size_t listLen, i;
rh = newHV();
(void)hv_store(rh, "uid", 3, newSVuv(file->uid), 0);
(void)hv_store(rh, "gid", 3, newSVuv(file->gid), 0);
(void)hv_store(rh, "name", 4, newSVpvn(fileName, strlen(fileName)), 0);
(void)hv_store(rh, "type", 4, newSVuv(file->type), 0);
(void)hv_store(rh, "mode", 4, newSVuv(file->mode), 0);
(void)hv_store(rh, "size", 4, newSVuv(file->size), 0);
(void)hv_store(rh, "mtime", 5, newSViv(file->mtime), 0);
(void)hv_store(rh, "inode", 5, newSVuv(file->inode), 0);
(void)hv_store(rh, "nlinks", 6, newSVuv(file->nlinks), 0);
(void)hv_store(rh, "digest", 6, newSVpvn((char*)file->digest.digest, file->digest.len), 0);
(void)hv_store(rh, "compress", 8, newSVuv(file->compress), 0);
BackupPC_XS.xs view on Meta::CPAN
return rh;
}
static void convert_hv2file(HV *hv, bpc_attrib_file *file)
{
char *digestStr = "";
STRLEN digestLen = 0;
SV** svp;
hv_get_uint(hv, "uid", file->uid);
hv_get_uint(hv, "gid", file->gid);
hv_get_uint(hv, "type", file->type);
hv_get_uint(hv, "mode", file->mode);
hv_get_uint(hv, "size", file->size);
hv_get_int(hv, "mtime", file->mtime);
hv_get_uint(hv, "inode", file->inode);
hv_get_uint(hv, "nlinks", file->nlinks);
hv_get_uint(hv, "compress", file->compress);
hv_get_str(hv, "digest", digestStr, digestLen);
if ( 0 < digestLen && digestLen <= sizeof(file->digest.digest) ) {
memcpy(file->digest.digest, digestStr, digestLen);
ushort compress;
/*
* isTemp is set if this is a temporary attribute entry (eg: mkstemp), that
* doesn't have referencing counting for the digest. Therefore, when a
* temporary file is created or deleted, there is no change to the
* reference counts.
*/
ushort isTemp;
uint32 mode;
uid_t uid;
gid_t gid;
uint32 nlinks;
time_t mtime;
OFF_T size;
ino_t inode;
int32 backupNum;
bpc_digest digest;
/*
* hash table of bpc_attrib_xattr entries, indexed by xattr key
*/
bpc_hashtable xattrHT;
bpc_attrib.c view on Meta::CPAN
*/
void bpc_attrib_fileCopyOpt(bpc_attrib_file *fileDest, bpc_attrib_file *fileSrc, int overwriteEmptyDigest)
{
if ( fileDest == fileSrc ) return;
fileDest->type = fileSrc->type;
fileDest->compress = fileSrc->compress;
fileDest->mode = fileSrc->mode;
fileDest->isTemp = fileSrc->isTemp;
fileDest->uid = fileSrc->uid;
fileDest->gid = fileSrc->gid;
fileDest->nlinks = fileSrc->nlinks;
fileDest->mtime = fileSrc->mtime;
fileDest->size = fileSrc->size;
fileDest->inode = fileSrc->inode;
fileDest->backupNum = fileSrc->backupNum;
if ( fileSrc->digest.len > 0 || overwriteEmptyDigest ) {
fileDest->digest = fileSrc->digest;
}
bpc_hashtable_iterate(&fileDest->xattrHT, (void*)bpc_attrib_xattrDestroy, NULL);
bpc_hashtable_erase(&fileDest->xattrHT);
bpc_attrib.c view on Meta::CPAN
* Check if two file attribute structures are the same. Returns 0 if they are the same.
*/
int bpc_attrib_fileCompare(bpc_attrib_file *file0, bpc_attrib_file *file1)
{
uint idx = 0;
if ( file0->type != file1->type
|| file0->compress != file1->compress
|| file0->mode != file1->mode
|| file0->uid != file1->uid
|| file0->gid != file1->gid
|| file0->nlinks != file1->nlinks
|| file0->mtime != file1->mtime
|| file0->size != file1->size
|| file0->inode != file1->inode
|| file0->digest.len != file1->digest.len
|| memcmp(file0->digest.digest, file1->digest.digest, file0->digest.len)
|| bpc_attrib_xattrCount(file0) != bpc_attrib_xattrCount(file1) ) {
if ( BPC_LogLevel >= 9 ) bpc_logMsgf("bpc_attrib_fileCompare: %s %s differ\n", file0->name, file1->name);
return 1;
}
bpc_attrib.c view on Meta::CPAN
*/
uchar *bpc_attrib_buf2file(bpc_attrib_file *file, uchar *buf, uchar *bufEnd, int xattrNumEntries, int *xattrFixup)
{
uchar *bufP = buf;
int i;
file->type = getVarInt(&bufP, bufEnd);
file->mtime = getVarInt(&bufP, bufEnd);
file->mode = getVarInt(&bufP, bufEnd);
file->uid = getVarInt(&bufP, bufEnd);
file->gid = getVarInt(&bufP, bufEnd);
file->size = getVarInt(&bufP, bufEnd);
file->inode = getVarInt(&bufP, bufEnd);
file->compress = getVarInt(&bufP, bufEnd);
file->nlinks = getVarInt(&bufP, bufEnd);
file->digest.len = getVarInt(&bufP, bufEnd);
file->isTemp = 0;
if ( file->digest.len > 0 && bufP + file->digest.len <= bufEnd ) {
memcpy(file->digest.digest, bufP, file->digest.len);
}
bpc_attrib.c view on Meta::CPAN
if ( BPC_LogLevel >= 7 ) bpc_logMsgf("bpc_attrib_dirRead: retrying file conversion\n");
bufP = bufPsave;
if ( read_more_data(&fd, buf, sizeof(buf), &nRead, &bufP, attribPath) ) {
bpc_fileZIO_close(&fd);
return -1;
}
retry = 1;
} else {
retry = 0;
}
if ( !retry && BPC_LogLevel >= 8 ) bpc_logMsgf("bpc_attrib_dirRead(%s): Got file %s: type = %d, mode = 0%o, uid/gid = %d/%d, size = %d\n",
attribPath, file->name, file->type, file->mode, file->uid, file->gid, file->size);
}
} else if ( magic == BPC_ATTRIB_TYPE_UNIX ) {
while ( bufP < buf + nRead ) {
uint fileNameLen;
char *fileName;
bpc_attrib_file *file;
int64 sizeDiv4GB;
uint type;
if ( nRead == sizeof(buf) && bufP > buf + nRead - 2 * BPC_MAXPATHLEN
bpc_attrib.c view on Meta::CPAN
bufP += fileNameLen;
type = getVarInt_v3(&bufP, buf + nRead);
fileName[fileNameLen] = '\0';
file = bpc_attrib_fileGet(dir, fileName, 1);
bpc_attrib_fileInit(file, fileName, 0);
file->type = type;
file->mode = getVarInt_v3(&bufP, buf + nRead);
file->uid = getVarInt_v3(&bufP, buf + nRead);
file->gid = getVarInt_v3(&bufP, buf + nRead);
sizeDiv4GB = getVarInt_v3(&bufP, buf + nRead);
file->size = (sizeDiv4GB << 32) + getVarInt_v3(&bufP, buf + nRead);
file->mtime = CONV_BUF_TO_UINT32(bufP); bufP += 4;
file->compress = dir->compress;
file->backupNum = backupNum;
if ( BPC_LogLevel >= 8 ) bpc_logMsgf("bpc_attrib_dirRead(%s): Got v3 file %s: type = %d, mode = 0%o, uid/gid = %d/%d, size = %d\n",
attribPath, file->name, file->type, file->mode, file->uid, file->gid, file->size);
}
} else {
bpc_logErrf("Unexpected magic number 0x%x read from %s\n", magic, attribPath);
return -1;
}
/* TODO: make sure we are at EOF? */
bpc_fileZIO_close(&fd);
return 0;
}
bpc_attrib.c view on Meta::CPAN
if ( bufP + fileNameLen < bufEnd ) {
memcpy(bufP, file->name, fileNameLen);
}
bufP += fileNameLen;
setVarInt(&bufP, bufEnd, xattrEntryCnt);
setVarInt(&bufP, bufEnd, file->type);
setVarInt(&bufP, bufEnd, file->mtime);
setVarInt(&bufP, bufEnd, file->mode);
setVarInt(&bufP, bufEnd, file->uid);
setVarInt(&bufP, bufEnd, file->gid);
setVarInt(&bufP, bufEnd, file->size);
setVarInt(&bufP, bufEnd, file->inode);
setVarInt(&bufP, bufEnd, file->compress);
setVarInt(&bufP, bufEnd, file->nlinks);
setVarInt(&bufP, bufEnd, file->digest.len);
if ( bufP + file->digest.len <= bufEnd ) {
memcpy(bufP, file->digest.digest, file->digest.len);
}
bufP += file->digest.len;
bpc_attrib.c view on Meta::CPAN
bpc_logErrf("bpc_attrib_file2buf: BOTCH: wrote %u xattr entries vs %u; attrib file corrupted\n", info.numEntries, xattrEntryCnt);
}
return info.bufP;
}
static void bpc_attrib_fileWrite(bpc_attrib_file *file, write_info *info)
{
uchar *bufP;
if ( file->isTemp ) {
if ( BPC_LogLevel >= 6 ) bpc_logMsgf("Skipping temp file %s: type = %d, mode = 0%o, uid/gid = %lu/%lu, size = %lu, inode = %lu, nlinks = %d, digest = 0x%02x%02x%02x..., bufUsed = %lu\n",
file->name, file->type, file->mode,
(unsigned long)file->uid, (unsigned long)file->gid,
(unsigned long)file->size, (unsigned long)file->inode, file->nlinks,
file->digest.digest[0], file->digest.digest[1], file->digest.digest[2],
(unsigned long)(info->bufP - info->buf));
return;
}
bufP = bpc_attrib_file2buf(file, info->bufP, info->buf + sizeof(info->buf));
if ( BPC_LogLevel >= 6 ) bpc_logMsgf("Wrote file %s: type = %d, mode = 0%o, uid/gid = %lu/%lu, size = %lu, inode = %lu, nlinks = %d, digest = 0x%02x%02x%02x..., bufUsed = %lu\n",
file->name, file->type, file->mode,
(unsigned long)file->uid, (unsigned long)file->gid,
(unsigned long)file->size, (unsigned long)file->inode, file->nlinks,
file->digest.digest[0], file->digest.digest[1], file->digest.digest[2],
(unsigned long)(info->bufP - info->buf));
if ( bufP <= info->buf + sizeof(info->buf) ) {
/*
* it fit into the buffer
*/
info->bufP = bufP;
return;
config.h.in view on Meta::CPAN
*/
#undef CRAY_STACKSEG_END
/* Define to 1 if using `alloca.c'. */
#undef C_ALLOCA
/* Used to make "checker" understand that FD_ZERO() clears memory. */
#undef FORCE_FD_ZERO_MEMSET
/* Define to the type of elements in the array set by `getgroups'. Usually
this is either `int' or `gid_t'. */
#undef GETGROUPS_T
/* Define to 1 if the `getpgrp' function requires zero arguments. */
#undef GETPGRP_VOID
/* Define to 1 if you have the `aclsort' function. */
#undef HAVE_ACLSORT
/* true if you have acl_get_perm_np */
#undef HAVE_ACL_GET_PERM_NP
config.h.in view on Meta::CPAN
/* Define to 1 if you have the `ftruncate' function. */
#undef HAVE_FTRUNCATE
/* Define to 1 if you have the "getaddrinfo" function and required types. */
#undef HAVE_GETADDRINFO
/* Define to 1 if you have the `getcwd' function. */
#undef HAVE_GETCWD
/* Define to 1 if you have the `getegid' function. */
#undef HAVE_GETEGID
/* Define to 1 if you have the `geteuid' function. */
#undef HAVE_GETEUID
/* Define to 1 if you have the `getgroups' function. */
#undef HAVE_GETGROUPS
/* Define to 1 if you have the `getpgrp' function. */
#undef HAVE_GETPGRP
config.h.in view on Meta::CPAN
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
/* Define _GNU_SOURCE so that we get all necessary prototypes */
#undef _GNU_SOURCE
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES
/* Define to `int' if <sys/types.h> doesn't define. */
#undef gid_t
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus
#undef inline
#endif
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
configure.sh view on Meta::CPAN
rm -f conftest*
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_uid_t" >&5
$as_echo "$ac_cv_type_uid_t" >&6; }
if test $ac_cv_type_uid_t = no; then
$as_echo "#define uid_t int" >>confdefs.h
$as_echo "#define gid_t int" >>confdefs.h
fi
ac_fn_c_check_type "$LINENO" "mode_t" "ac_cv_type_mode_t" "$ac_includes_default"
if test "x$ac_cv_type_mode_t" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_MODE_T 1
_ACEOF
configure.sh view on Meta::CPAN
/* end confdefs.h. */
/* Thanks to Mike Rendell for this test. */
$ac_includes_default
#define NGID 256
#undef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
int
main ()
{
gid_t gidset[NGID];
int i, n;
union { gid_t gval; long int lval; } val;
val.lval = -1;
for (i = 0; i < NGID; i++)
gidset[i] = val.gval;
n = getgroups (sizeof (gidset) / MAX (sizeof (int), sizeof (gid_t)) - 1,
gidset);
/* Exit non-zero if getgroups seems to require an array of ints. This
happens when gid_t is short int but getgroups modifies an array
of ints. */
return n > 0 && gidset[n] != val.gval;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
ac_cv_type_getgroups=gid_t
else
ac_cv_type_getgroups=int
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
if test $ac_cv_type_getgroups = cross; then
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <unistd.h>
_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
$EGREP "getgroups.*int.*gid_t" >/dev/null 2>&1; then :
ac_cv_type_getgroups=gid_t
else
ac_cv_type_getgroups=int
fi
rm -f conftest*
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_type_getgroups" >&5
$as_echo "$ac_cv_type_getgroups" >&6; }
configure.sh view on Meta::CPAN
cat >>confdefs.h <<_ACEOF
#define STACK_DIRECTION $ac_cv_c_stack_direction
_ACEOF
fi
for ac_func in waitpid wait4 getcwd strdup chown chmod lchmod mknod mkfifo \
fchmod fstat ftruncate strchr readlink link utime utimes lutimes strftime \
memmove lchown vsnprintf snprintf vasprintf asprintf setsid strpbrk \
strlcat strlcpy strtol mallinfo getgroups setgroups geteuid getegid \
setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \
seteuid strerror putenv iconv_open locale_charset nl_langinfo getxattr \
extattr_get_link sigaction sigprocmask setattrlist \
utimensat
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
configure.sh view on Meta::CPAN
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <stdlib.h>
#include <errno.h>
main() {
char const *dangling_symlink = "conftest.dangle";
unlink(dangling_symlink);
if (symlink("conftest.no-such", dangling_symlink) < 0) abort();
if (chown(dangling_symlink, getuid(), getgid()) < 0 && errno == ENOENT) exit(1);
exit(0);
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
rsync_cv_chown_modifies_symlink=yes
else
rsync_cv_chown_modifies_symlink=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
#include <sys/select.h>
#endif
#ifdef HAVE_SYS_MODE_H
/* apparently AIX needs this for S_ISLNK */
#ifndef S_ISLNK
#include <sys/mode.h>
#endif
#endif
/* these are needed for the uid/gid mapping code */
#include <pwd.h>
#include <grp.h>
#include <stdarg.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#include <syslog.h>