X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/8e41b68e8f975c02a5d9281be780ba5d1a385107..7ed6bc53b90ddfe262b9df467b147750a0e822e0:/xattrs.c diff --git a/xattrs.c b/xattrs.c index 595ec422..e65f652a 100644 --- a/xattrs.c +++ b/xattrs.c @@ -20,6 +20,7 @@ */ #include "rsync.h" +#include "ifuncs.h" #include "lib/sysxattrs.h" #ifdef SUPPORT_XATTRS @@ -63,6 +64,8 @@ extern int checksum_seed; #define RPRE_LEN ((int)sizeof RSYNC_PREFIX - 1) #define XSTAT_ATTR RSYNC_PREFIX "%stat" +#define XACC_ACL_ATTR RSYNC_PREFIX "%aacl" +#define XDEF_ACL_ATTR RSYNC_PREFIX "%dacl" typedef struct { char *datum, *name; @@ -89,7 +92,7 @@ static void rsync_xal_free(item_list *xalp) xalp->count = 0; } -void free_xattr(statx *sxp) +void free_xattr(stat_x *sxp) { if (!sxp->xattr) return; @@ -267,7 +270,7 @@ static int rsync_xal_get(const char *fname, item_list *xalp) } /* Read the xattr(s) for this filename. */ -int get_xattr(const char *fname, statx *sxp) +int get_xattr(const char *fname, stat_x *sxp) { sxp->xattr = new(item_list); *sxp->xattr = empty_xattr; @@ -329,7 +332,7 @@ static void rsync_xal_store(item_list *xalp) } /* Send the make_xattr()-generated xattr list for this flist entry. */ -int send_xattr(statx *sxp, int f) +int send_xattr(stat_x *sxp, int f) { int ndx = find_matching_xattr(sxp->xattr); @@ -375,7 +378,7 @@ int send_xattr(statx *sxp, int f) /* Return a flag indicating if we need to change a file's xattrs. If * "find_all" is specified, also mark any abbreviated xattrs that we * need so that send_xattr_request() can tell the sender about them. */ -int xattr_diff(struct file_struct *file, statx *sxp, int find_all) +int xattr_diff(struct file_struct *file, stat_x *sxp, int find_all) { item_list *lst = rsync_xal_l.items; rsync_xa *snd_rxa, *rec_rxa; @@ -656,9 +659,9 @@ void receive_xattr(struct file_struct *file, int f) F_XATTR(file) = ndx; } -/* Turn the xattr data in statx into cached xattr data, setting the index +/* Turn the xattr data in stat_x into cached xattr data, setting the index * values in the file struct. */ -void cache_xattr(struct file_struct *file, statx *sxp) +void cache_xattr(struct file_struct *file, stat_x *sxp) { int ndx; @@ -673,7 +676,7 @@ void cache_xattr(struct file_struct *file, statx *sxp) } static int rsync_xal_set(const char *fname, item_list *xalp, - const char *fnamecmp, statx *sxp) + const char *fnamecmp, stat_x *sxp) { rsync_xa *rxas = xalp->items; ssize_t list_len; @@ -780,7 +783,7 @@ static int rsync_xal_set(const char *fname, item_list *xalp, /* Set extended attributes on indicated filename. */ int set_xattr(const char *fname, const struct file_struct *file, - const char *fnamecmp, statx *sxp) + const char *fnamecmp, stat_x *sxp) { int ndx; item_list *lst = rsync_xal_l.items; @@ -797,6 +800,31 @@ int set_xattr(const char *fname, const struct file_struct *file, return rsync_xal_set(fname, lst + ndx, fnamecmp, sxp); } +#ifdef SUPPORT_ACLS +char *get_xattr_acl(const char *fname, int is_access_acl, size_t *len_p) +{ + const char *name = is_access_acl ? XACC_ACL_ATTR : XDEF_ACL_ATTR; + return get_xattr_data(fname, name, len_p, 1); +} + +int set_xattr_acl(const char *fname, int is_access_acl, const char *buf, size_t buf_len) +{ + const char *name = is_access_acl ? XACC_ACL_ATTR : XDEF_ACL_ATTR; + if (sys_lsetxattr(fname, name, buf, buf_len) < 0) { + rsyserr(FERROR, errno, + "set_xattr_acl: lsetxattr(\"%s\",\"%s\") failed", + fname, name); + return -1; + } + return 0; +} + +int del_def_xattr_acl(const char *fname) +{ + return sys_lremovexattr(fname, XDEF_ACL_ATTR); +} +#endif + int get_stat_xattr(const char *fname, int fd, STRUCT_STAT *fst, STRUCT_STAT *xst) { int mode, rdev_major, rdev_minor, uid, gid, len;