X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/40ec1b8b8ce942a4505b3a4a67516b8d5947f786..c2f699cc6bfb241c97cc53dfe6bfd0ea0385456c:/fake-super.diff diff --git a/fake-super.diff b/fake-super.diff index e4f47c5..a5d1c5b 100644 --- a/fake-super.diff +++ b/fake-super.diff @@ -1,22 +1,21 @@ -Depends-On-Patch: acls.diff -Depends-On-Patch: xattrs.diff - This patch adds a new option: --fake-super, which tells rsync to copy in a fake super-user mode that stores various file attributes in an extended- attribute value instead of as real file-system attributes. See the changes to the manpages for details. -After applying this patch, run these commands for a successful build: +To use this patch, run these commands for a successful build: + patch -p1 0 ; left -= len, name += len) { -- rsync_xa *rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL); -+ rsync_xa *rxas; + char *datum, *name; +@@ -148,6 +153,10 @@ static int rsync_xal_get(const char *fna + continue; + #endif - len = strlen(name) + 1; -+ if (am_root < 0 && len == sizeof FAKE_XATTR -+ && name[10] == '%' && strcmp(name, FAKE_XATTR) == 0) ++ if (am_root < 0 && name_len == XSTAT_LEN + 1 ++ && name[CENT_POS] == '%' && strcmp(name, XSTAT_ATTR) == 0) + continue; + -+ rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL); -+ - datum_size = sys_lgetxattr(fname, name, NULL, 0); - if (datum_size < 0) { + datum_len = sys_lgetxattr(fname, name, NULL, 0); + if (datum_len < 0) { if (errno == ENOTSUP) -@@ -287,10 +296,19 @@ void receive_xattr(struct file_struct *f - out_of_memory("receive_xattr"); - read_buf(f, ptr, name_len); - read_buf(f, ptr + name_len, datum_len); -+ -+ if (am_root < 0 && name_len == sizeof FAKE_XATTR -+ && ptr[10] == '%' && strcmp(ptr, FAKE_XATTR) == 0) { +@@ -177,6 +186,13 @@ static int rsync_xal_get(const char *fna + return -1; + } + } ++#ifdef HAVE_LINUX_XATTRS ++ if (am_root < 0 && name_len > RPRE_LEN ++ && HAS_PREFIX(name, RSYNC_PREFIX)) { ++ name += RPRE_LEN; ++ name_len -= RPRE_LEN; ++ } ++#endif + rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL); + rxas->name = ptr + datum_len; + rxas->datum = ptr; +@@ -299,10 +315,8 @@ void receive_xattr(struct file_struct *f + size_t name_len = read_int(f); + size_t datum_len = read_int(f); + size_t extra_len = am_root < 0 ? RPRE_LEN : 0; +-#ifndef HAVE_LINUX_XATTRS + if (datum_len + extra_len < datum_len) + out_of_memory("receive_xattr"); /* overflow */ +-#endif + if (name_len + datum_len + extra_len < name_len) + out_of_memory("receive_xattr"); /* overflow */ + ptr = new_array(char, name_len + datum_len + extra_len); +@@ -313,6 +327,10 @@ void receive_xattr(struct file_struct *f + read_buf(f, ptr, datum_len); + #ifdef HAVE_LINUX_XATTRS + /* Non-root can only save the user namespace. */ ++ if (am_root < 0 && !HAS_PREFIX(name, USER_PREFIX)) { ++ name -= RPRE_LEN; ++ memcpy(name, RSYNC_PREFIX, RPRE_LEN); ++ } else + if (!am_root && !HAS_PREFIX(name, USER_PREFIX)) { + free(ptr); + continue; +@@ -333,6 +351,11 @@ void receive_xattr(struct file_struct *f + continue; + } + #endif ++ if (am_root < 0 && name_len == XSTAT_LEN + 1 ++ && name[CENT_POS] == '%' && strcmp(name, XSTAT_ATTR) == 0) { + free(ptr); -+ temp_xattr.count--; + continue; + } -+ - rxa->name_len = name_len; - rxa->datum_len = datum_len; - rxa->name = ptr; - rxa->datum = ptr + name_len; -+ - #ifdef HAVE_OSX_XATTRS - if (strncmp(rxa->name, UNIQUE_PREFIX, UPRE_LEN) == 0) { - rxa->name_len -= UPRE_LEN; -@@ -372,4 +390,146 @@ int set_xattr(const char *fname, const s + rxa = EXPAND_ITEM_LIST(&temp_xattr, rsync_xa, count); + rxa->name = name; + rxa->datum = ptr; +@@ -412,4 +435,149 @@ int set_xattr(const char *fname, const s return rsync_xal_set(fname, lst + ndx); /* TODO: This needs to return 1 if no xattrs changed! */ } @@ -505,10 +530,10 @@ or, if you want ACL support too: + xst = fst; + if (fname) { + fd = -1; -+ len = sys_lgetxattr(fname, FAKE_XATTR, buf, sizeof buf - 1); ++ len = sys_lgetxattr(fname, XSTAT_ATTR, buf, sizeof buf - 1); + } else { + fname = "fd"; -+ len = sys_fgetxattr(fd, FAKE_XATTR, buf, sizeof buf - 1); ++ len = sys_fgetxattr(fd, XSTAT_ATTR, buf, sizeof buf - 1); + } + if (len >= (int)sizeof buf) { + len = -1; @@ -523,7 +548,7 @@ or, if you want ACL support too: + return 0; + } + rsyserr(FERROR, errno, "failed to read xattr %s for %s", -+ FAKE_XATTR, full_fname(fname)); ++ XSTAT_ATTR, full_fname(fname)); + return -1; + } + buf[len] = '\0'; @@ -531,7 +556,7 @@ or, if you want ACL support too: + if (sscanf(buf, "%o %d,%d %d:%d", + &mode, &rdev_major, &rdev_minor, &uid, &gid) != 5) { + rprintf(FERROR, "Corrupt %s xattr attached to %s: \"%s\"\n", -+ FAKE_XATTR, full_fname(fname), buf); ++ XSTAT_ATTR, full_fname(fname), buf); + exit_cleanup(RERR_FILEIO); + } + @@ -547,14 +572,14 @@ or, if you want ACL support too: +{ + STRUCT_STAT fst, xst; + dev_t rdev; -+ mode_t mode; ++ mode_t mode, fmode; + + if (dry_run) + return 0; + + if (read_only || list_only) { + rsyserr(FERROR, EROFS, "failed to write xattr %s for %s", -+ FAKE_XATTR, full_fname(fname)); ++ XSTAT_ATTR, full_fname(fname)); + return -1; + } + @@ -564,23 +589,26 @@ or, if you want ACL support too: + return -1; + } + -+ if (IS_DEVICE(file->mode) || IS_SPECIAL(file->mode)) ++ fst.st_mode &= (_S_IFMT | CHMOD_BITS); ++ fmode = file->mode & (_S_IFMT | CHMOD_BITS); ++ ++ if (IS_DEVICE(fmode) || IS_SPECIAL(fmode)) + rdev = file->u.rdev; + else + rdev = 0; + + /* Dump the special permissions and enable full owner access. */ -+ mode = (fst.st_mode & ~CHMOD_BITS) | (file->mode & ACCESSPERMS) ++ mode = (fst.st_mode & _S_IFMT) | (fmode & ACCESSPERMS) + | (S_ISDIR(fst.st_mode) ? 0700 : 0600); + if (fst.st_mode != mode) + do_chmod(fname, mode); + if (!IS_DEVICE(fst.st_mode) && !IS_SPECIAL(fst.st_mode)) + fst.st_rdev = 0; /* just in case */ + -+ if (mode == file->mode && fst.st_rdev == rdev ++ if (mode == fmode && fst.st_rdev == rdev + && fst.st_uid == file->uid && fst.st_gid == file->gid) { + /* xst.st_mode will be 0 if there's no current stat xattr */ -+ if (xst.st_mode && sys_lremovexattr(fname, FAKE_XATTR) < 0) { ++ if (xst.st_mode && sys_lremovexattr(fname, XSTAT_ATTR) < 0) { + rsyserr(FERROR, errno, + "delete of stat xattr failed for %s", + full_fname(fname)); @@ -589,19 +617,19 @@ or, if you want ACL support too: + return 0; + } + -+ if (xst.st_mode != file->mode || xst.st_rdev != rdev ++ if (xst.st_mode != fmode || xst.st_rdev != rdev + || xst.st_uid != file->uid || xst.st_gid != file->gid) { + char buf[256]; + int len = snprintf(buf, sizeof buf, "%o %u,%u %u:%u", -+ to_wire_mode(file->mode) & (_S_IFMT|CHMOD_BITS), ++ to_wire_mode(fmode), + (int)major(rdev), (int)minor(rdev), + (int)file->uid, (int)file->gid); -+ if (sys_lsetxattr(fname, FAKE_XATTR, buf, len, 0) < 0) { ++ if (sys_lsetxattr(fname, XSTAT_ATTR, buf, len) < 0) { + if (errno == EPERM && S_ISLNK(fst.st_mode)) + return 0; + rsyserr(FERROR, errno, + "failed to write xattr %s for %s", -+ FAKE_XATTR, full_fname(fname)); ++ XSTAT_ATTR, full_fname(fname)); + return -1; + } + }