Fixed failing hunks.
[rsync/rsync-patches.git] / acls.diff
index 474056a..007cacf 100644 (file)
--- a/acls.diff
+++ b/acls.diff
@@ -7,7 +7,13 @@ After applying this patch, run these commands for a successful build:
 See the --acls (-A) option in the revised man page for a note on using this
 latest ACL-enabling patch to send files to an older ACL-enabled rsync.
 
-This code does not yet itemize changes in ACL information (see --itemize).
+TODO items:
+
+- The -i option does not yet itemize changes in ACL information.
+
+- The --link-dest option might link together two files that differ just
+  in their ACL info, and if that happens the file in the --link-dest dir
+  would get its ACLs updated.
 
 --- old/Makefile.in
 +++ new/Makefile.in
@@ -32,7 +38,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
  popt_OBJS=popt/findme.o  popt/popt.o  popt/poptconfig.o \
 --- old/acls.c
 +++ new/acls.c
-@@ -0,0 +1,1297 @@
+@@ -0,0 +1,1293 @@
 +/* -*- c-file-style: "linux" -*-
 +   Copyright (C) Andrew Tridgell 1996
 +   Copyright (C) Paul Mackerras 1996
@@ -323,8 +329,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +
 +static inline rsync_acl_list *rsync_acl_lists(SMB_ACL_TYPE_T type)
 +{
-+      return type == SMB_ACL_TYPE_ACCESS ? &_rsync_acl_lists[0]
-+          : &_rsync_acl_lists[1];
++      return &_rsync_acl_lists[type != SMB_ACL_TYPE_ACCESS];
 +}
 +
 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
@@ -357,9 +362,9 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +                                 const rsync_acl *racl)
 +{
 +      static int access_match = -1, default_match = -1;
-+      int *match = (type == SMB_ACL_TYPE_ACCESS) ?
-+                      &access_match : &default_match;
++      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. */
@@ -371,6 +376,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +              if (!(*match)--)
 +                      *match = racl_list->count - 1;
 +      }
++
 +      *match = -1;
 +      return *match;
 +}
@@ -427,9 +433,9 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +
 +static const char *str_acl_type(SMB_ACL_TYPE_T type)
 +{
-+      return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS" :
-+              type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT" :
-+              "unknown SMB_ACL_TYPE_T";
++      return type == SMB_ACL_TYPE_ACCESS ? "SMB_ACL_TYPE_ACCESS"
++           : type == SMB_ACL_TYPE_DEFAULT ? "SMB_ACL_TYPE_DEFAULT"
++           : "unknown SMB_ACL_TYPE_T";
 +}
 +
 +/* Generate the ACL(s) for this flist entry;
@@ -522,41 +528,41 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +typedef struct {
 +      size_t count;
 +      size_t malloced;
-+      file_acl_index *fileaclidxs;
++      file_acl_index *fais;
 +} file_acl_index_list;
 +
 +static file_acl_index_list _file_acl_index_lists[] = {
-+      {0, 0, NULL },/* SMB_ACL_TYPE_ACCESS */
-+      {0, 0, NULL } /* SMB_ACL_TYPE_DEFAULT */
++      {0, 0, NULL }, /* SMB_ACL_TYPE_ACCESS */
++      {0, 0, NULL }  /* SMB_ACL_TYPE_DEFAULT */
 +};
 +
 +static inline file_acl_index_list *file_acl_index_lists(SMB_ACL_TYPE_T type)
 +{
-+      return type == SMB_ACL_TYPE_ACCESS ?
-+              &_file_acl_index_lists[0] : &_file_acl_index_lists[1];
++      return &_file_acl_index_lists[type != SMB_ACL_TYPE_ACCESS];
 +}
 +
-+static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
++static void expand_file_acl_index_list(file_acl_index_list *flst)
 +{
 +      /* First time through, 0 <= 0, so list is expanded. */
-+      if (fileaclidx_list->malloced <= fileaclidx_list->count) {
++      if (flst->malloced <= flst->count) {
 +              file_acl_index *new_ptr;
 +              size_t new_size;
-+              if (fileaclidx_list->malloced < 1000)
-+                      new_size = fileaclidx_list->malloced + 1000;
++
++              if (flst->malloced < 1000)
++                      new_size = flst->malloced + 1000;
 +              else
-+                      new_size = fileaclidx_list->malloced * 2;
-+              new_ptr = realloc_array(fileaclidx_list->fileaclidxs, file_acl_index, new_size);
++                      new_size = flst->malloced * 2;
++              new_ptr = realloc_array(flst->fais, file_acl_index, new_size);
 +              if (verbose >= 3) {
 +                      rprintf(FINFO, "expand_file_acl_index_list to %.0f bytes, did%s move\n",
-+                              (double) new_size * sizeof fileaclidx_list->fileaclidxs[0],
-+                              fileaclidx_list->fileaclidxs ? "" : " not");
++                              (double) new_size * sizeof flst->fais[0],
++                              flst->fais ? "" : " not");
 +              }
 +
-+              fileaclidx_list->fileaclidxs = new_ptr;
-+              fileaclidx_list->malloced = new_size;
++              flst->fais = new_ptr;
++              flst->malloced = new_size;
 +
-+              if (!fileaclidx_list->fileaclidxs)
++              if (!flst->fais)
 +                      out_of_memory("expand_file_acl_index_list");
 +      }
 +}
@@ -576,8 +582,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +
 +static inline smb_acl_list *smb_acl_lists(SMB_ACL_TYPE_T type)
 +{
-+      return type == SMB_ACL_TYPE_ACCESS ? &_smb_acl_lists[0] :
-+              &_smb_acl_lists[1];
++      return &_smb_acl_lists[type != SMB_ACL_TYPE_ACCESS];
 +}
 +
 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
@@ -869,7 +874,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +              }
 +      } else
 +#endif
-+      if (racl->mask == ACL_NO_ENTRY) /* always made non-empty when needed */
++      if (racl->mask == ACL_NO_ENTRY) /* Always non-empty when needed. */
 +              racl->mask = computed_mask_bits | (racl->group_obj & 7);
 +}
 +
@@ -885,10 +890,10 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +      fname = f_name(file, NULL);
 +      type = SMB_ACL_TYPE_ACCESS;
 +      do {
-+              file_acl_index_list *fileaclidx_list =
-+                      file_acl_index_lists(type);
 +              char tag;
-+              expand_file_acl_index_list(fileaclidx_list);
++              file_acl_index_list *flst = file_acl_index_lists(type);
++
++              expand_file_acl_index_list(flst);
 +
 +              tag = read_byte(f);
 +              if (tag == 'A' || tag == 'a') {
@@ -912,10 +917,8 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +                      rsync_acl racl;
 +                      rsync_acl_list *racl_list = rsync_acl_lists(type);
 +                      smb_acl_list *sacl_list = smb_acl_lists(type);
-+                      fileaclidx_list->fileaclidxs[fileaclidx_list->count].
-+                              aclidx = racl_list->count;
-+                      fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
-+                              file = file;
++                      flst->fais[flst->count].aclidx = racl_list->count;
++                      flst->fais[flst->count++].file = file;
 +                      receive_rsync_acl(&racl, f, type);
 +                      expand_rsync_acl_list(racl_list);
 +                      racl_list->racls[racl_list->count++] = racl;
@@ -931,10 +934,8 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +                                      index);
 +                              exit_cleanup(RERR_STREAMIO);
 +                      }
-+                      fileaclidx_list->fileaclidxs[fileaclidx_list->count].
-+                              aclidx = index;
-+                      fileaclidx_list->fileaclidxs[fileaclidx_list->count++].
-+                              file = file;
++                      flst->fais[flst->count].aclidx = index;
++                      flst->fais[flst->count++].file = file;
 +              }
 +      } while (BUMP_TYPE(type) && S_ISDIR(file->mode));
 +}
@@ -943,8 +944,8 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +{
 +      const file_acl_index *fileaclidx1 = (const file_acl_index *)f1;
 +      const file_acl_index *fileaclidx2 = (const file_acl_index *)f2;
-+      return fileaclidx1->file == fileaclidx2->file ? 0 :
-+              fileaclidx1->file < fileaclidx2->file ? -1 : 1;
++      return fileaclidx1->file == fileaclidx2->file ? 0
++           : fileaclidx1->file < fileaclidx2->file ? -1 : 1;
 +}
 +
 +void sort_file_acl_index_lists()
@@ -953,36 +954,38 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +
 +      type = SMB_ACL_TYPE_ACCESS;
 +      do {
-+              file_acl_index_list *fileaclidx_list =
-+                      file_acl_index_lists(type);
-+              if (!fileaclidx_list->count)
++              file_acl_index_list *flst = file_acl_index_lists(type);
++
++              if (!flst->count)
 +                      continue;
-+              qsort(fileaclidx_list->fileaclidxs, fileaclidx_list->count,
-+                    sizeof fileaclidx_list->fileaclidxs[0],
++
++              qsort(flst->fais, flst->count, sizeof flst->fais[0],
 +                    &file_acl_index_list_sorter);
 +      } while (BUMP_TYPE(type));
 +}
 +
-+static int find_file_acl_index(const file_acl_index_list *fileaclidx_list,
-+                             const struct file_struct *file) {
-+      int low = 0, high = fileaclidx_list->count;
++static int find_file_acl_index(const file_acl_index_list *flst,
++                             const struct file_struct *file)
++{
++      int low = 0, high = flst->count;
 +      const struct file_struct *file_mid;
++
 +      if (!high--)
 +              return -1;
 +      do {
 +              int mid = (high + low) / 2;
-+              file_mid = fileaclidx_list->fileaclidxs[mid].file;
++              file_mid = flst->fais[mid].file;
 +              if (file_mid == file)
-+                      return fileaclidx_list->fileaclidxs[mid].aclidx;
++                      return flst->fais[mid].aclidx;
 +              if (file_mid > file)
 +                      high = mid - 1;
 +              else
 +                      low = mid + 1;
 +      } while (low < high);
 +      if (low == high) {
-+              file_mid = fileaclidx_list->fileaclidxs[low].file;
++              file_mid = flst->fais[low].file;
 +              if (file_mid == file)
-+                      return fileaclidx_list->fileaclidxs[low].aclidx;
++                      return flst->fais[low].aclidx;
 +      }
 +      rprintf(FERROR,
 +              "find_file_acl_index: can't find entry for file in list\n");
@@ -1235,8 +1238,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
 + * or it returns 0 if there are no more tag_type ids in the acl. */
 +static id_t *next_ace_id(SMB_ACL_TAG_T tag_type, const rsync_acl *racl)
 +{
-+      const ida_list *idal = (tag_type == SMB_ACL_USER ?
-+              &racl->users : &racl->groups);
++      const ida_list *idal = tag_type == SMB_ACL_USER ? &racl->users : &racl->groups;
 +      if (enum_ida_index < idal->count) {
 +              id_access *ida = &idal->idas[enum_ida_index++];
 +              return &ida->id;
@@ -1388,7 +1390,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
  dnl At the moment we don't test for a broken memcmp(), because all we
  dnl need to do is test for equality, not comparison, and it seems that
  dnl every platform has a memcmp that can do at least that.
-@@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
+@@ -738,6 +743,78 @@ AC_SUBST(OBJ_RESTORE)
  AC_SUBST(CC_SHOBJ_FLAG)
  AC_SUBST(BUILD_POPT)
  
@@ -1437,6 +1439,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +#include <sys/acl.h>],
 +[ acl_t acl; int entry_id; acl_entry_t *entry_p; return acl_get_entry( acl, entry_id, entry_p);],
 +samba_cv_HAVE_POSIX_ACLS=yes,samba_cv_HAVE_POSIX_ACLS=no)])
++                      AC_MSG_CHECKING(ACL test results)
 +                      if test x"$samba_cv_HAVE_POSIX_ACLS" = x"yes"; then
 +                          AC_MSG_RESULT(Using posix ACLs)
 +                          AC_DEFINE(HAVE_POSIX_ACLS, 1, [true if you have posix ACLs])
@@ -4889,7 +4892,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
  int preserve_perms = 0;
  int preserve_executability = 0;
  int preserve_devices = 0;
-@@ -194,6 +195,7 @@ static void print_rsync_version(enum log
+@@ -192,6 +193,7 @@ static void print_rsync_version(enum log
        char const *got_socketpair = "no ";
        char const *have_inplace = "no ";
        char const *hardlinks = "no ";
@@ -4897,7 +4900,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
        char const *links = "no ";
        char const *ipv6 = "no ";
        STRUCT_STAT *dumstat;
-@@ -210,6 +212,10 @@ static void print_rsync_version(enum log
+@@ -208,6 +210,10 @@ static void print_rsync_version(enum log
        hardlinks = "";
  #endif
  
@@ -4908,7 +4911,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
  #ifdef SUPPORT_LINKS
        links = "";
  #endif
-@@ -223,9 +229,9 @@ static void print_rsync_version(enum log
+@@ -221,9 +227,9 @@ static void print_rsync_version(enum log
        rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
        rprintf(f, "<http://rsync.samba.org/>\n");
        rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
@@ -4920,7 +4923,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
  
        /* Note that this field may not have type ino_t.  It depends
         * on the complicated interaction between largefile feature
-@@ -295,6 +301,9 @@ void usage(enum logcode F)
+@@ -293,6 +299,9 @@ void usage(enum logcode F)
    rprintf(F," -H, --hard-links            preserve hard links\n");
    rprintf(F," -p, --perms                 preserve permissions\n");
    rprintf(F," -E, --executability         preserve the file's executability\n");
@@ -4930,7 +4933,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
    rprintf(F,"     --chmod=CHMOD           change destination permissions\n");
    rprintf(F," -o, --owner                 preserve owner (super-user only)\n");
    rprintf(F," -g, --group                 preserve group\n");
-@@ -410,6 +419,9 @@ static struct poptOption long_options[] 
+@@ -408,6 +417,9 @@ static struct poptOption long_options[] 
    {"no-perms",         0,  POPT_ARG_VAL,    &preserve_perms, 0, 0, 0 },
    {"no-p",             0,  POPT_ARG_VAL,    &preserve_perms, 0, 0, 0 },
    {"executability",   'E', POPT_ARG_NONE,   &preserve_executability, 0, 0, 0 },
@@ -4940,7 +4943,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
    {"times",           't', POPT_ARG_VAL,    &preserve_times, 1, 0, 0 },
    {"no-times",         0,  POPT_ARG_VAL,    &preserve_times, 0, 0, 0 },
    {"no-t",             0,  POPT_ARG_VAL,    &preserve_times, 0, 0, 0 },
-@@ -1068,6 +1080,24 @@ int parse_arguments(int *argc, const cha
+@@ -1066,6 +1078,24 @@ int parse_arguments(int *argc, const cha
                        usage(FINFO);
                        exit_cleanup(0);
  
@@ -4965,7 +4968,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
                default:
                        /* A large opt value means that set_refuse_options()
                         * turned this option off. */
-@@ -1511,6 +1541,10 @@ void server_options(char **args,int *arg
+@@ -1508,6 +1538,10 @@ void server_options(char **args,int *arg
  
        if (preserve_hard_links)
                argstr[x++] = 'H';
@@ -5044,7 +5047,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
        if (daemon_chmod_modes && !S_ISLNK(flist_mode))
                cur_mode = tweak_mode(cur_mode, daemon_chmod_modes);
        return (flist_mode & ~CHMOD_BITS) | (cur_mode & CHMOD_BITS);
-@@ -203,9 +205,21 @@ int set_file_attrs(char *fname, struct f
+@@ -203,6 +205,17 @@ int set_file_attrs(char *fname, struct f
                updated = 1;
        }
  
@@ -5061,15 +5064,10 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +
  #ifdef HAVE_CHMOD
        if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
--              int ret = do_chmod(fname, file->mode);
-+              mode_t mode = file->mode;
-+              int ret = do_chmod(fname, mode);
-               if (ret < 0) {
-                       rsyserr(FERROR, errno,
-                               "failed to set permissions on %s",
+               int ret = do_chmod(fname, file->mode);
 --- old/rsync.h
 +++ new/rsync.h
-@@ -660,6 +660,20 @@ struct chmod_mode_struct;
+@@ -661,6 +661,20 @@ struct chmod_mode_struct;
  
  #define UNUSED(x) x __attribute__((__unused__))
  
@@ -5426,12 +5424,49 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +
 +#endif /* No ACLs. */
 +#endif /* _SMB_ACLS_H */
+--- old/testsuite/acls.test
++++ new/testsuite/acls.test
+@@ -0,0 +1,34 @@
++#! /bin/sh
++
++# This program is distributable under the terms of the GNU GPL (see
++# COPYING).
++
++# Test that rsync handles basic ACL preservation.
++
++. $srcdir/testsuite/rsync.fns
++
++$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
++case "$setfacl_nodef" in
++true) test_skipped "I don't know how to use your setfacl command" ;;
++esac
++
++makepath "$fromdir/foo"
++echo something >"$fromdir/file1"
++echo else >"$fromdir/file2"
++
++files='foo file1 file2'
++
++setfacl -m u:0:7 "$fromdir/foo" || test_skipped "Your filesystem has ACLs disabled"
++setfacl -m u:0:5 "$fromdir/file1"
++setfacl -m u:0:5 "$fromdir/file2"
++
++$RSYNC -avvA "$fromdir/" "$todir/"
++
++cd "$fromdir"
++getfacl $files >"$scratchdir/acls.txt"
++
++cd "$todir"
++getfacl $files | diff $diffopt "$scratchdir/acls.txt" -
++
++# The script would have aborted on error, so getting here means we've won.
++exit 0
 --- old/testsuite/default-acls.test
 +++ new/testsuite/default-acls.test
-@@ -0,0 +1,64 @@
+@@ -0,0 +1,65 @@
 +#! /bin/sh
 +
-+# This program is distributable under the terms of the GNU GPL see
++# This program is distributable under the terms of the GNU GPL (see
 +# COPYING).
 +
 +# Test that rsync obeys default ACLs. -- Matt McCutchen
@@ -5440,6 +5475,7 @@ This code does not yet itemize changes in ACL information (see --itemize).
 +
 +$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
 +case "$setfacl_nodef" in
++true) test_skipped "I don't know how to use your setfacl command" ;;
 +*-k*) opts='-dm u::7,g::5,o:5' ;;
 +*) opts='-m d:u::7,d:g::5,d:o:5' ;;
 +esac