1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/**
* Copyright (c) 2005 - 2011 Miek Gieben
* License: GPLv3(+), see LICENSE for details
*
* Not used anymore - this is a hack that I don't want to
* support anymore. It stinks
*
* It was used in saving the uid/gid information when doing
* a remote dump as a no root user.
*
* All xattr functions are grouped here
*/
#include "rdup.h"
extern gint opt_verbose;
uid_t read_attr_uid( __attribute__ ((unused))
char *path, uid_t u)
{
#ifdef HAVE_ATTR_XATTR_H
/* linux */
char buf[ATTR_SIZE + 1];
uid_t x;
int r;
if ((r = lgetxattr(path, "user.r_uid", buf, ATTR_SIZE)) > 0) {
x = (uid_t) atoi(buf);
buf[r - 1] = '\0';
if (x > R_MAX_ID) {
msg(_("Too large uid `%zd\' for `%s\', truncating"),
(size_t) x, path);
return R_MAX_ID;
}
return x;
} else {
if (opt_verbose > 0) {
msg(_("No uid xattr for `%s\'"), path);
}
return u;
}
#elif HAVE_ATTROPEN
/* solaris */
char buf[ATTR_SIZE + 1];
uid_t x;
int attfd;
int r;
if ((attfd = attropen(path, "r_uid", O_RDONLY)) == -1) {
if (opt_verbose > 0) {
msg(_("No uid xattr for `%s\'"), path);
}
return u;
}
if ((r = read(attfd, buf, ATTR_SIZE)) == -1) {
return u;
}
close(attfd);
buf[r - 1] = '\0';
x = (uid_t) atoi(buf);
if (x > R_MAX_ID) {
msg(_("Too large gid `%zd\' for `%s\', truncating"), (size_t) x,
path);
return R_MAX_ID;
}
return x;
#else
return u;
#endif /* HAVE_ATTR_XATTR_H, HAVE_ATTROPEN */
}
gid_t read_attr_gid( __attribute__ ((unused))
char *path, gid_t g)
{
#ifdef HAVE_ATTR_XATTR_H
char buf[ATTR_SIZE + 1];
gid_t x;
int r;
if ((r = lgetxattr(path, "user.r_gid", buf, ATTR_SIZE)) > 0) {
buf[r - 1] = '\0';
x = (gid_t) atoi(buf);
if (x > R_MAX_ID) {
msg(_("Too large gid `%zd\' for `%s\', truncating"),
(size_t) x, path);
return R_MAX_ID;
}
return x;
} else {
if (opt_verbose > 0) {
msg(_("No gid xattr for `%s\'"), path);
}
return g;
}
#elif HAVE_ATTROPEN
/* solaris */
char buf[ATTR_SIZE + 1];
gid_t x;
int attfd;
int r;
if ((attfd = attropen(path, "r_gid", O_RDONLY)) == -1) {
if (opt_verbose > 0) {
msg(_("No gid xattr for `%s\'"), path);
}
return g;
}
if ((r = read(attfd, buf, ATTR_SIZE)) == -1) {
return g;
}
close(attfd);
buf[r - 1] = '\0';
x = (uid_t) atoi(buf);
if (x > R_MAX_ID) {
msg(_("Too large gid `%zd\' for `%s\', truncating"), (size_t) x,
path);
return R_MAX_ID;
}
return x;
#else
return g;
#endif /* HAVE_ATTR_XATTR_H, HAVE_ATTROPEN */
}
|