A patch for Service Location Protocol support (derived from a
[rsync/rsync-patches.git] / acls.diff
index edd3029..bdd795c 100644 (file)
--- a/acls.diff
+++ b/acls.diff
@@ -2,7 +2,7 @@ After applying this patch, run these commands for a successful build:
 
     autoconf
     autoheader
-    ./configure --with-acl-support
+    ./configure --enable-acl-support
     make proto
     make
 
@@ -11,9 +11,9 @@ from a disk that doesn't support ACLs.  This should be changed to silently
 notice that no ACLs are available to copy.  Of course, trying to write out
 ACLs to a non-ACL-supporting disk should complain.
 
---- orig/Makefile.in   2004-11-02 16:47:15
-+++ Makefile.in        2004-10-20 06:32:26
-@@ -25,16 +25,16 @@ VERSION=@VERSION@
+--- orig/Makefile.in   2006-01-14 08:14:29
++++ Makefile.in        2005-11-07 04:31:05
+@@ -25,15 +25,15 @@ VERSION=@VERSION@
  .SUFFIXES:
  .SUFFIXES: .c .o
  
@@ -22,20 +22,19 @@ ACLs to a non-ACL-supporting disk should complain.
  LIBOBJ=lib/wildmatch.o lib/compat.o lib/snprintf.o lib/mdfour.o \
 -      lib/permstring.o lib/pool_alloc.o @LIBOBJS@
 +      lib/permstring.o lib/pool_alloc.o lib/sysacls.o @LIBOBJS@
- ZLIBOBJ=zlib/deflate.o zlib/infblock.o zlib/infcodes.o zlib/inffast.o \
-       zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/trees.o \
-       zlib/zutil.o zlib/adler32.o
+ ZLIBOBJ=zlib/deflate.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o \
+       zlib/trees.o zlib/zutil.o zlib/adler32.o zlib/compress.o zlib/crc32.o
  OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
        main.o checksum.o match.o syscall.o log.o backup.o
  OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
--      fileio.o batch.o clientname.o
-+      fileio.o batch.o clientname.o acls.o
+-      fileio.o batch.o clientname.o chmod.o
++      fileio.o batch.o clientname.o chmod.o acls.o
  OBJS3=progress.o pipe.o
  DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
  popt_OBJS=popt/findme.o  popt/popt.o  popt/poptconfig.o \
---- orig/acls.c        2005-05-12 23:30:45
-+++ acls.c     2005-05-12 23:30:45
-@@ -0,0 +1,1130 @@
+--- orig/acls.c        2006-01-31 19:25:53
++++ acls.c     2006-01-31 19:25:53
+@@ -0,0 +1,1202 @@
 +/* -*- c-file-style: "linux" -*-
 +   Copyright (C) Andrew Tridgell 1996
 +   Copyright (C) Paul Mackerras 1996
@@ -65,6 +64,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +extern int preserve_acls;
 +extern int am_root;
 +extern int dry_run;
++extern int orig_umask;
 +
 +typedef struct {
 +      id_t id;
@@ -377,13 +377,13 @@ ACLs to a non-ACL-supporting disk should complain.
 +/* Generate the ACL(s) for this flist entry;
 + * ACL(s) are either sent or cleaned-up by send_acl() below. */
 +
-+BOOL make_acl(const struct file_struct *file, const char *fname)
++int make_acl(const struct file_struct *file, const char *fname)
 +{
 +      SMB_ACL_TYPE_T *type,
 +              types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
 +      rsync_acl *curr_racl;
 +      if (!preserve_acls || S_ISLNK(file->mode))
-+              return True;
++              return 1;
 +      for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
 +           type < &types[0] + sizeof types / sizeof types[0]
 +              && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
@@ -394,14 +394,14 @@ ACLs to a non-ACL-supporting disk should complain.
 +              if (!(sacl = sys_acl_get_file(fname, *type))) {
 +                      rprintf(FERROR, "send_acl: sys_acl_get_file(%s, %s): %s\n",
 +                              fname, str_acl_type(*type), strerror(errno));
-+                      return False;
++                      return -1;
 +              }
 +              ok = unpack_smb_acl(curr_racl, sacl);
 +              sys_acl_free_acl(sacl);
 +              if (!ok)
-+                      return False;
++                      return -1;
 +      }
-+      return True;
++      return 0;
 +}
 +
 +/* Send the make_acl()-generated ACLs for this flist entry,
@@ -761,7 +761,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      char *fname;
 +      if (!preserve_acls || S_ISLNK(file->mode))
 +              return;
-+      fname = f_name(file);
++      fname = f_name(file, NULL);
 +      for (type = &types[0];
 +           type < &types[0] + sizeof types / sizeof types[0]
 +              && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(file->mode));
@@ -883,7 +883,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +              types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
 +      int ret = 0;
 +      if (!preserve_acls)
-+              return 0;
++              return 1;
 +      for (type = &types[0];
 +           type < &types[0] + sizeof types / sizeof types[0]
 +               && (*type == SMB_ACL_TYPE_ACCESS || S_ISDIR(mode));
@@ -942,7 +942,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      return ret;
 +}
 +
-+/* Stuff for redirecting calls to set_acl() from set_perms()
++/* Stuff for redirecting calls to set_acl() from set_file_attrs()
 + * for keep_backup(). */
 +static const struct file_struct *backup_orig_file = NULL;
 +static const char null_string[] = "";
@@ -1000,7 +1000,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +              }
 +              return ret;
 +      }
-+      return 0;
++      return 1;
 +}
 +
 +void cleanup_keep_backup_acl()
@@ -1030,7 +1030,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      SMB_ACL_TYPE_T *type,
 +              types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
 +      if (dry_run || !preserve_acls || S_ISLNK(file->mode))
-+              return 0;
++              return 1;
 +      if (file == backup_orig_file) {
 +              if (!strcmp(fname, backup_dest_fname))
 +                      return set_keep_backup_acl();
@@ -1165,8 +1165,79 @@ ACLs to a non-ACL-supporting disk should complain.
 +      set_acl_id(gid);
 +}
 +
++#define PERMS_SPLICE(perms,newbits,where) (((perms) & ~(7 << (where))) | ((newbits) << (where)))
++
++int default_perms_for_dir(const char *dir)
++{
++      rsync_acl racl;
++      SMB_ACL_T sacl;
++      BOOL ok, saw_mask = False;
++      size_t i;
++      int perms;
++
++      if (dir == NULL)
++              dir = ".";
++      perms = ACCESSPERMS & ~orig_umask;
++      /* Read the directory's default ACL.  If it has none, this will successfully return an empty ACL. */
++      sacl = sys_acl_get_file(dir, SMB_ACL_TYPE_DEFAULT);
++      if (sacl == NULL) {
++              /* Couldn't get an ACL.  Darn. */
++              switch (errno) {
++              case ENOTSUP:
++                      /* ACLs are disabled.  We could yell at the user to turn them on, but... */
++                      break;
++              case ENOENT:
++                      if (dry_run) {
++                              /* We're doing a dry run, so the containing directory
++                               * wasn't actually created.  Don't worry about it. */
++                              break;
++                      }
++                      /* Otherwise fall through. */
++              default:
++                      rprintf(FERROR, "default_perms_for_dir: sys_acl_get_file(%s, %s): %s, falling back on umask\n",
++                              dir, str_acl_type(SMB_ACL_TYPE_DEFAULT), strerror(errno));
++              }
++              return perms;
++      }
++
++      /* Convert it. */
++      ok = unpack_smb_acl(&racl, sacl);
++      sys_acl_free_acl(sacl);
++      if (!ok) {
++              rprintf(FERROR, "default_perms_for_dir: unpack_smb_acl failed, falling back on umask\n");
++              return perms;
++      }
++
++      /* Look at each default ACL entry and possibly modify three bits of `perms' accordingly.
++       * If there's "no" default ACL, there will be zero entries and the umask-based perms is unchanged. */
++      for (i = 0; i < racl.count; i++) {
++              switch (racl.races[i].tag_type) {
++              case SMB_ACL_USER_OBJ:
++                      perms = PERMS_SPLICE(perms, racl.races[i].access, 6);
++                      break;
++              case SMB_ACL_GROUP_OBJ:
++                      if (!saw_mask)
++                              perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
++                      break;
++              case SMB_ACL_MASK:
++                      saw_mask = True;
++                      perms = PERMS_SPLICE(perms, racl.races[i].access, 3);
++                      break;
++              case SMB_ACL_OTHER:
++                      perms = PERMS_SPLICE(perms, racl.races[i].access, 0);
++                      break;
++              default:
++                      break;
++              }
++      }
++      rsync_acl_free(&racl);
++      if (verbose > 2)
++              rprintf(FINFO, "got ACL-based default perms %o for directory %s\n", perms, dir);
++      return perms;
++}
++
 +#endif /* SUPPORT_ACLS */
---- orig/backup.c      2005-02-22 01:57:58
+--- orig/backup.c      2006-01-30 07:18:27
 +++ backup.c   2004-10-06 00:13:09
 @@ -135,6 +135,7 @@ static int make_bak_dir(char *fullpath)
                        } else {
@@ -1176,24 +1247,24 @@ ACLs to a non-ACL-supporting disk should complain.
                        }
                }
                *p = '/';
-@@ -187,6 +188,8 @@ static int keep_backup(char *fname)
+@@ -188,6 +189,8 @@ static int keep_backup(char *fname)
        if (!(buf = get_backup_name(fname)))
                return 0;
  
 +      PUSH_KEEP_BACKUP_ACL(file, fname, buf);
 +
        /* Check to see if this is a device file, or link */
-       if (IS_DEVICE(file->mode)) {
-               if (am_root && preserve_devices) {
-@@ -260,6 +263,7 @@ static int keep_backup(char *fname)
+       if ((am_root && preserve_devices && IS_DEVICE(file->mode))
+        || (preserve_specials && IS_SPECIAL(file->mode))) {
+@@ -263,6 +266,7 @@ static int keep_backup(char *fname)
                }
        }
-       set_perms(buf, file, NULL, 0);
+       set_file_attrs(buf, file, NULL, 0);
 +      CLEANUP_KEEP_BACKUP_ACL();
        free(file);
  
        if (verbose > 1) {
---- orig/configure.in  2005-05-13 22:24:18
+--- orig/configure.in  2006-01-15 14:52:33
 +++ configure.in       2004-08-19 19:53:27
 @@ -478,6 +478,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
      AC_CHECK_LIB(resolv, strcasecmp)
@@ -1207,7 +1278,7 @@ ACLs to a non-ACL-supporting disk should complain.
  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.
-@@ -734,6 +739,77 @@ AC_SUBST(OBJ_RESTORE)
+@@ -750,6 +755,77 @@ AC_SUBST(OBJ_RESTORE)
  AC_SUBST(CC_SHOBJ_FLAG)
  AC_SUBST(BUILD_POPT)
  
@@ -1217,9 +1288,9 @@ ACLs to a non-ACL-supporting disk should complain.
 +# check for ACL support
 +
 +AC_MSG_CHECKING(whether to support ACLs)
-+AC_ARG_WITH(acl-support,
-+[  --with-acl-support      Include ACL support (default=no)],
-+[ case "$withval" in
++AC_ARG_ENABLE(acl-support,
++AC_HELP_STRING([--enable-acl-support], [Include ACL support (default=no)]),
++[ case "$enableval" in
 +  yes)
 +
 +              case "$host_os" in
@@ -1285,21 +1356,21 @@ ACLs to a non-ACL-supporting disk should complain.
  AC_CONFIG_FILES([Makefile lib/dummy zlib/dummy popt/dummy shconfig])
  AC_OUTPUT
  
---- orig/flist.c       2005-05-14 19:51:15
-+++ flist.c    2005-03-16 02:24:11
-@@ -974,6 +974,8 @@ static struct file_struct *send_file_nam
-       file = make_file(fname, flist, f == -2 ? SERVER_FILTERS : ALL_FILTERS);
+--- orig/flist.c       2006-01-31 02:30:18
++++ flist.c    2006-01-31 02:37:33
+@@ -967,6 +967,8 @@ static struct file_struct *send_file_nam
+                        f == -2 ? SERVER_FILTERS : ALL_FILTERS);
        if (!file)
                return NULL;
-+      if (!MAKE_ACL(file, fname))
++      if (MAKE_ACL(file, fname) < 0)
 +              return NULL;
  
-       maybe_emit_filelist_progress(flist->count + flist_count_offset);
-@@ -982,6 +984,10 @@ static struct file_struct *send_file_nam
+       if (chmod_modes && !S_ISLNK(file->mode))
+               file->mode = tweak_mode(file->mode, chmod_modes);
+@@ -978,6 +980,10 @@ static struct file_struct *send_file_nam
        if (file->basename[0]) {
                flist->files[flist->count++] = file;
-               send_file_entry(file, f, base_flags);
+               send_file_entry(file, f);
 +              SEND_ACL(file, f);
 +      } else {
 +              /* Cleanup unsent ACL(s). */
@@ -1307,7 +1378,7 @@ ACLs to a non-ACL-supporting disk should complain.
        }
        return file;
  }
-@@ -1318,6 +1324,8 @@ struct file_list *recv_file_list(int f)
+@@ -1366,6 +1372,8 @@ struct file_list *recv_file_list(int f)
                        flags |= read_byte(f) << 8;
                file = receive_file_entry(flist, flags, f);
  
@@ -1316,28 +1387,112 @@ ACLs to a non-ACL-supporting disk should complain.
                if (S_ISREG(file->mode))
                        stats.total_size += file->length;
  
-@@ -1340,6 +1348,8 @@ struct file_list *recv_file_list(int f)
+@@ -1388,6 +1396,8 @@ struct file_list *recv_file_list(int f)
  
        clean_flist(flist, relative_paths, 1);
  
 +      SORT_FILE_ACL_INDEX_LISTS();
 +
        if (f >= 0) {
-               /* Now send the uid/gid list. This was introduced in
-                * protocol version 15 */
---- orig/generator.c   2005-05-19 08:52:42
-+++ generator.c        2005-05-12 23:34:00
-@@ -719,6 +719,10 @@ static void recv_generator(char *fname, 
-               if (set_perms(fname, file, statret ? NULL : &st, 0)
+               recv_uid_list(f, flist);
+--- orig/generator.c   2006-01-31 18:59:39
++++ generator.c        2006-01-31 19:36:04
+@@ -42,6 +42,7 @@ extern int preserve_specials;
+ extern int preserve_hard_links;
+ extern int preserve_perms;
+ extern int preserve_executability;
++extern int preserve_acls;
+ extern int preserve_uid;
+ extern int preserve_gid;
+ extern int preserve_times;
+@@ -756,6 +757,7 @@ static int try_dests_non(struct file_str
+ }
+ static int phase = 0;
++static int dflt_perms;
+ /* Acts on the_file_list->file's ndx'th item, whose name is fname.  If a dir,
+  * make sure it exists, and has the right permissions/timestamp info.  For
+@@ -772,7 +774,7 @@ static void recv_generator(char *fname, 
+                          enum logcode code, int f_out)
+ {
+       static int missing_below = -1, excluded_below = -1;
+-      static char *fuzzy_dirname = "";
++      static char *parent_dirname = "";
+       static struct file_list *fuzzy_dirlist = NULL;
+       struct file_struct *fuzzy_file = NULL;
+       int fd = -1, f_copy = -1;
+@@ -791,12 +793,12 @@ static void recv_generator(char *fname, 
+               if (fuzzy_dirlist) {
+                       flist_free(fuzzy_dirlist);
+                       fuzzy_dirlist = NULL;
+-                      fuzzy_dirname = "";
+               }
+               if (missing_below >= 0) {
+                       dry_run--;
+                       missing_below = -1;
+               }
++              parent_dirname = "";
+               return;
+       }
+@@ -831,15 +833,20 @@ static void recv_generator(char *fname, 
+               statret = -1;
+               stat_errno = ENOENT;
+       } else {
+-              if (fuzzy_basis && S_ISREG(file->mode)) {
++              if ((fuzzy_basis || preserve_acls) && S_ISREG(file->mode)) {
+                       char *dn = file->dirname ? file->dirname : ".";
+-                      if (fuzzy_dirname != dn
+-                          && strcmp(fuzzy_dirname, dn) != 0) {
++                      if (parent_dirname != dn
++                       && strcmp(parent_dirname, dn) != 0) {
+                               if (fuzzy_dirlist)
+                                       flist_free(fuzzy_dirlist);
+-                              fuzzy_dirlist = get_dirlist(dn, -1, 1);
++                              if (fuzzy_basis)
++                                      fuzzy_dirlist = get_dirlist(dn, -1, 1);
++#ifdef SUPPORT_ACLS
++                              if (preserve_acls)
++                                      dflt_perms = default_perms_for_dir(dn);
++#endif
+                       }
+-                      fuzzy_dirname = dn;
++                      parent_dirname = dn;
+               }
+               statret = link_stat(fname, &st,
+@@ -861,7 +868,8 @@ static void recv_generator(char *fname, 
+       if (!preserve_perms) {
+               int exists = statret == 0
+                         && S_ISDIR(st.st_mode) == S_ISDIR(file->mode);
+-              file->mode = dest_mode(file->mode, st.st_mode, exists);
++              file->mode = dest_mode(file->mode, st.st_mode, dflt_perms,
++                                     exists);
+       }
+       if (S_ISDIR(file->mode)) {
+@@ -895,6 +903,10 @@ static void recv_generator(char *fname, 
+               if (set_file_attrs(fname, file, statret ? NULL : &st, 0)
                    && verbose && code && f_out != -1)
-                       rprintf(code, "%s/\n", safe_fname(fname));
+                       rprintf(code, "%s/\n", fname);
 +#ifdef SUPPORT_ACLS
 +              if (f_out == -1)
 +                      SET_ACL(fname, file);
 +#endif
                if (delete_during && f_out != -1 && !phase && dry_run < 2
                    && (file->flags & FLAG_DEL_HERE))
-                       delete_in_dir(the_file_list, fname, file);
+                       delete_in_dir(the_file_list, fname, file, &st);
+@@ -1330,6 +1342,8 @@ void generate_files(int f_out, struct fi
+        * notice that and let us know via the redo pipe (or its closing). */
+       ignore_timeout = 1;
++      dflt_perms = (ACCESSPERMS & ~orig_umask);
++
+       for (i = 0; i < flist->count; i++) {
+               struct file_struct *file = flist->files[i];
 --- orig/lib/sysacls.c 2005-05-16 23:27:53
 +++ lib/sysacls.c      2005-05-16 23:27:53
 @@ -0,0 +1,3242 @@
@@ -4625,17 +4780,17 @@ ACLs to a non-ACL-supporting disk should complain.
    next;
  }
  
---- orig/options.c     2005-05-19 08:52:42
-+++ options.c  2005-05-12 23:34:38
-@@ -43,6 +43,7 @@ int keep_dirlinks = 0;
+--- orig/options.c     2006-01-31 03:11:30
++++ options.c  2006-01-31 03:11:18
+@@ -44,6 +44,7 @@ int keep_dirlinks = 0;
  int copy_links = 0;
  int preserve_links = 0;
  int preserve_hard_links = 0;
 +int preserve_acls = 0;
  int preserve_perms = 0;
+ int preserve_executability = 0;
  int preserve_devices = 0;
- int preserve_uid = 0;
-@@ -180,6 +181,7 @@ static void print_rsync_version(enum log
+@@ -193,6 +194,7 @@ static void print_rsync_version(enum log
        char const *got_socketpair = "no ";
        char const *have_inplace = "no ";
        char const *hardlinks = "no ";
@@ -4643,7 +4798,7 @@ ACLs to a non-ACL-supporting disk should complain.
        char const *links = "no ";
        char const *ipv6 = "no ";
        STRUCT_STAT *dumstat;
-@@ -196,6 +198,10 @@ static void print_rsync_version(enum log
+@@ -209,6 +211,10 @@ static void print_rsync_version(enum log
        hardlinks = "";
  #endif
  
@@ -4654,8 +4809,8 @@ ACLs to a non-ACL-supporting disk should complain.
  #ifdef SUPPORT_LINKS
        links = "";
  #endif
-@@ -210,9 +216,9 @@ static void print_rsync_version(enum log
-               "Copyright (C) 1996-2005 by Andrew Tridgell and others\n");
+@@ -222,9 +228,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, "
 -              "%shard links, %ssymlinks, batchfiles, \n",
@@ -4666,30 +4821,33 @@ ACLs to a non-ACL-supporting disk should complain.
  
        /* Note that this field may not have type ino_t.  It depends
         * on the complicated interaction between largefile feature
-@@ -282,6 +288,7 @@ void usage(enum logcode F)
-   rprintf(F," -H, --hard-links            preserve hard links\n");
+@@ -293,6 +299,7 @@ void usage(enum logcode F)
    rprintf(F," -K, --keep-dirlinks         treat symlinked dir on receiver as dir\n");
    rprintf(F," -p, --perms                 preserve permissions\n");
+   rprintf(F," -E, --executability         preserve the file's executability\n");
 +  rprintf(F," -A, --acls                  preserve ACLs (implies --perms)\n");
-   rprintf(F," -o, --owner                 preserve owner (root only)\n");
+   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");
-   rprintf(F," -D, --devices               preserve devices (root only)\n");
-@@ -408,6 +415,7 @@ static struct poptOption long_options[] 
-   {"no-whole-file",    0,  POPT_ARG_VAL,    &whole_file, 0, 0, 0 },
-   {"copy-unsafe-links",0,  POPT_ARG_NONE,   &copy_unsafe_links, 0, 0, 0 },
-   {"perms",           'p', POPT_ARG_NONE,   &preserve_perms, 0, 0, 0 },
-+  {"acls",            'A', POPT_ARG_NONE,   0,              'A', 0, 0 },
-   {"owner",           'o', POPT_ARG_NONE,   &preserve_uid, 0, 0, 0 },
-   {"group",           'g', POPT_ARG_NONE,   &preserve_gid, 0, 0, 0 },
-   {"devices",         'D', POPT_ARG_NONE,   &preserve_devices, 0, 0, 0 },
-@@ -876,6 +884,24 @@ int parse_arguments(int *argc, const cha
-                       basis_dir[basis_dir_cnt++] = (char *)arg;
-                       break;
+@@ -409,6 +416,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 },
++  {"acls",            'A', POPT_ARG_NONE,   0, 'A', 0, 0 },
++  {"no-acls",          0,  POPT_ARG_VAL,    &preserve_acls, 0, 0, 0 },
++  {"no-A",             0,  POPT_ARG_VAL,    &preserve_acls, 0, 0, 0 },
+   {"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 },
+@@ -1057,6 +1067,24 @@ int parse_arguments(int *argc, const cha
+                       usage(FINFO);
+                       exit_cleanup(0);
  
 +              case 'A':
 +#ifdef SUPPORT_ACLS
 +                      preserve_acls = 1;
 +                      preserve_perms = 1;
++                      break;
 +#else
 +                      /* FIXME: this should probably be ignored with a
 +                       * warning and then countermeasures taken to
@@ -4701,13 +4859,12 @@ ACLs to a non-ACL-supporting disk should complain.
 +                               am_server ? "server" : "client");
 +                      return 0;
 +#endif /* SUPPORT_ACLS */
-+                      break;
 +
 +
                default:
                        /* A large opt value means that set_refuse_options()
                         * turned this option off. */
-@@ -1282,6 +1308,8 @@ void server_options(char **args,int *arg
+@@ -1497,6 +1525,8 @@ void server_options(char **args,int *arg
  
        if (preserve_hard_links)
                argstr[x++] = 'H';
@@ -4716,9 +4873,67 @@ ACLs to a non-ACL-supporting disk should complain.
        if (preserve_uid)
                argstr[x++] = 'o';
        if (preserve_gid)
---- orig/rsync.c       2005-03-16 02:19:30
-+++ rsync.c    2004-07-03 20:11:58
-@@ -137,6 +137,14 @@ int set_perms(char *fname,struct file_st
+--- orig/receiver.c    2006-01-31 02:30:18
++++ receiver.c 2006-01-31 19:36:48
+@@ -37,6 +37,7 @@ extern int relative_paths;
+ extern int keep_dirlinks;
+ extern int preserve_hard_links;
+ extern int preserve_perms;
++extern int preserve_acls;
+ extern int io_error;
+ extern int basis_dir_cnt;
+ extern int make_backups;
+@@ -410,6 +411,8 @@ int recv_files(int f_in, struct file_lis
+       int itemizing = am_daemon ? daemon_log_format_has_i
+                     : !am_server && log_format_has_i;
+       int max_phase = protocol_version >= 29 ? 2 : 1;
++      int dflt_perms = (ACCESSPERMS & ~orig_umask);
++      char *parent_dirname = "";
+       int i, recv_ok;
+       if (verbose > 2)
+@@ -607,7 +610,18 @@ int recv_files(int f_in, struct file_lis
+                * mode based on the local permissions and some heuristics. */
+               if (!preserve_perms) {
+                       int exists = fd1 != -1;
+-                      file->mode = dest_mode(file->mode, st.st_mode, exists);
++#ifdef SUPPORT_ACLS
++                      if (preserve_acls) {
++                              char *dn = file->dirname ? file->dirname : ".";
++                              if (parent_dirname != dn
++                               && strcmp(parent_dirname, dn) != 0) {
++                                      dflt_perms = default_perms_for_dir(dn);
++                                      parent_dirname = dn;
++                              }
++                      }
++#endif
++                      file->mode = dest_mode(file->mode, st.st_mode,
++                                             dflt_perms, exists);
+               }
+               /* We now check to see if we are writing file "inplace" */
+--- orig/rsync.c       2006-01-31 02:30:18
++++ rsync.c    2006-01-31 19:35:44
+@@ -53,7 +53,8 @@ void free_sums(struct sum_struct *s)
+ /* This is only called when we aren't preserving permissions.  Figure out what
+  * the permissions should be and return them merged back into the mode. */
+-mode_t dest_mode(mode_t flist_mode, mode_t dest_mode, int exists)
++mode_t dest_mode(mode_t flist_mode, mode_t dest_mode, int dflt_perms,
++               int exists)
+ {
+       /* If the file already exists we'll return the local permissions,
+        * possibly tweaked by the --executability option. */
+@@ -68,7 +69,7 @@ mode_t dest_mode(mode_t flist_mode, mode
+                               dest_mode |= (dest_mode & 0444) >> 2;
+               }
+       } else
+-              dest_mode = flist_mode & ~orig_umask;
++              dest_mode = ((flist_mode & CHMOD_BITS) & dflt_perms) | S_IWUSR;
+       return (flist_mode & ~CHMOD_BITS) | (dest_mode & CHMOD_BITS);
+ }
+@@ -161,6 +162,14 @@ int set_file_attrs(char *fname, struct f
        }
  #endif
  
@@ -4730,12 +4945,12 @@ ACLs to a non-ACL-supporting disk should complain.
 +                      updated = 1;
 +      }
 +
-       if (verbose > 1 && flags & PERMS_REPORT) {
+       if (verbose > 1 && flags & ATTRS_REPORT) {
                enum logcode code = daemon_log_format_has_i || dry_run
                                  ? FCLIENT : FINFO;
---- orig/rsync.h       2005-05-03 17:11:01
-+++ rsync.h    2005-05-12 23:32:56
-@@ -638,6 +638,44 @@ struct stats {
+--- orig/rsync.h       2006-01-30 20:39:09
++++ rsync.h    2006-01-31 19:27:00
+@@ -648,6 +648,44 @@ struct chmod_mode_struct;
  #include "lib/permstring.h"
  #include "lib/addrinfo.h"
  
@@ -4768,40 +4983,76 @@ ACLs to a non-ACL-supporting disk should complain.
 +#define SEND_ACL(file, f)
 +#define RECEIVE_ACL(file, f)
 +#define SORT_FILE_ACL_INDEX_LISTS()
-+#define SET_ACL(fname, file)                  0 /* checked return value */
++#define SET_ACL(fname, file)                  1 /* checked return value */
 +#define NEXT_ACL_UID()        
 +#define ACL_UID_MAP(uid)
 +#define PUSH_KEEP_BACKUP_ACL(file, orig, dest)
 +#define CLEANUP_KEEP_BACKUP_ACL()
-+#define DUP_ACL(src, orig, mode)              0 /* checked return value */
++#define DUP_ACL(src, orig, mode)              1 /* checked return value */
 +#endif /* SUPPORT_ACLS */
 +#include "smb_acls.h"
 +
  #include "proto.h"
  
  /* We have replacement versions of these if they're missing. */
---- orig/rsync.yo      2005-05-10 23:47:12
-+++ rsync.yo   2004-07-03 20:11:58
+--- orig/rsync.yo      2006-01-31 03:05:44
++++ rsync.yo   2006-01-31 03:14:05
 @@ -317,6 +317,7 @@ to the detailed description below for a 
-  -H, --hard-links            preserve hard links
   -K, --keep-dirlinks         treat symlinked dir on receiver as dir
   -p, --perms                 preserve permissions
-+ -A, --acls                  preserve ACLs (implies -p) [local option]
-  -o, --owner                 preserve owner (root only)
+  -E, --executability         preserve executability
++ -A, --acls                  preserve ACLs (implies -p) [non-standard]
+      --chmod=CHMOD           change destination permissions
+  -o, --owner                 preserve owner (super-user only)
   -g, --group                 preserve group
-  -D, --devices               preserve devices (root only)
-@@ -629,6 +630,11 @@ based on the source file's permissions, 
- umask setting
- (which is the same behavior as other file-copy utilities, such as cp).
+@@ -691,14 +692,23 @@ quote(itemize(
+   permissions, though the bf(--executability) option might change just
+   the execute permission for the file.
+   it() Each new file gets its permissions set based on the source file's
+-  permissions, but masked by the receiving end's umask setting (including
++  permissions, but masked by the receiving end's destination-default
++  permissions (which is either based on the ACL of the destination
++  directory, if available, or the receiving end's umask setting) and
++  includes
+   the stripping of the three special permission bits).
++  Hint: Using bf(--chmod=ugo=rwX) without bf(--perms) will cause new
++  files to get all the destination-default permissions.
+ ))
+   
+ Thus, when bf(--perms) and bf(--executability) are both disabled,
+ rsync's behavior is the same as that of other file-copy utilities,
+ such as bf(cp)(1) and bf(tar)(1).
++This version of rsync observes default ACLs; patched versions of rsync only
++applied the umask, and could thus set wrong permissions in the presence of
++default ACLs.
++
+ dit(bf(-E, --executability)) This option causes rsync to preserve the
+ executability (or non-executability) of regular files when bf(--perms) is
+ not enabled.  A regular file is considered to be executable if at least one
+@@ -713,6 +723,10 @@ quote(itemize(
+ If bf(--perms) is enabled, this option is ignored.
++dit(bf(-A, --acls)) This option causes rsync to update the destination
++ACLs to be the same as the source ACLs.  This nonstandard option only
++works if the remote rsync also supports it.  bf(--acls) implies bf(--perms).
++
+ dit(bf(--chmod)) This option tells rsync to apply one or more
+ comma-separated "chmod" strings to the permission of the files in the
+ transfer.  The resulting value is treated as though it was the permissions
+--- orig/runtests.sh   2005-08-17 06:45:08
++++ runtests.sh        2006-01-31 19:09:40
+@@ -195,6 +195,9 @@ export scratchdir suitedir
+ prep_scratch() {
+     [ -d "$scratchdir" ] && rm -rf "$scratchdir"
+     mkdir "$scratchdir"
++    # Get rid of default ACLs and directory setgid because they confuse some tests.
++    setfacl -k "$scratchdir" 2>/dev/null || true
++    chmod g-s "$scratchdir"
+     return 0
+ }
  
-+dit(bf(-A, --acls)) This option causes rsync to update the remote
-+ACLs to be the same as the local ACLs.  This will work only if the
-+remote machine's rsync supports this option also. This is a non-standard
-+option.
-+
- dit(bf(-o, --owner)) This option causes rsync to set the owner of the
- destination file to be the same as the source file.  On most systems,
- only the super-user can set file ownership.  By default, the preservation
 --- orig/smb_acls.h    2004-06-30 00:04:07
 +++ smb_acls.h 2004-06-30 00:04:07
 @@ -0,0 +1,277 @@
@@ -5082,8 +5333,62 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +#endif /* No ACLs. */
 +#endif /* _SMB_ACLS_H */
---- orig/uidlist.c     2005-02-14 00:53:44
-+++ uidlist.c  2004-07-03 20:11:58
+--- orig/testsuite/default-acls-obey.test      2005-10-15 16:08:45
++++ testsuite/default-acls-obey.test   2005-10-15 16:08:45
+@@ -0,0 +1,51 @@
++#! /bin/sh
++
++# This program is distributable under the terms of the GNU GPL see
++# COPYING).
++
++# Test that rsync obeys default ACLs. -- Matt McCutchen
++
++. $srcdir/testsuite/rsync.fns
++
++set -x
++
++$RSYNC --help | grep -q "ACLs" || test_skipped "Rsync is configured without ACL support"
++setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
++
++echo "File!" >"$scratchdir/file"
++echo "#!/bin/bash" >"$scratchdir/program"
++chmod 666 "$scratchdir/file"
++chmod 777 "$scratchdir/program"
++
++# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
++function testit {
++    todir="$scratchdir/$1"
++    mkdir "$todir"
++    setfacl -k "$todir"
++    chmod g-s "$todir" ### Don't let directory setgid interfere
++    [ "$2" ] && setfacl -dm "$2" "$todir"
++    # Make sure we obey ACLs when creating a directory to hold multiple transferred files,
++    # even though the directory itself is outside the transfer
++    $RSYNC -rvv "$scratchdir/file" "$scratchdir/program" "$todir/to/"
++    [ `stat --format=%a "$todir/to"` == $4 ] || test_fail "Target $1: to should have $4 permissions"
++    [ `stat --format=%a "$todir/to/file"` == $3 ] || test_fail "Target $1: to/file should have $3 permissions"
++    [ `stat --format=%a "$todir/to/program"` == $4 ] || test_fail "Target $1: to/program should have $4 permissions"
++    # Make sure get_local_name doesn't mess us up when transferring only one file
++    $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
++    [ `stat --format=%a "$todir/to/anotherfile"` == $3 ] || test_fail "Target $1: to/anotherfile should have $3 permissions"
++}
++
++# Test some target directories
++umask 0077
++testit da777 u::rwx,g::rwx,o::rwx 666 777
++testit da775 u::rwx,g::rwx,o::r-x 664 775
++testit da750 u::rwx,g::r-x,o::--- 640 750
++testit da770mask u::rwx,g::---,m::rwx,o::--- 660 770
++testit noda1 '' 600 700
++umask 0000
++testit noda2 '' 666 777
++umask 0022
++testit noda3 '' 644 755
++
++# Hooray
++exit 0
+--- orig/uidlist.c     2006-01-25 17:15:13
++++ uidlist.c  2006-01-25 17:45:21
 @@ -34,6 +34,7 @@
  extern int verbose;
  extern int preserve_uid;
@@ -5119,16 +5424,16 @@ ACLs to a non-ACL-supporting disk should complain.
                /* read the uid list */
                while ((id = read_int(f)) != 0) {
                        int len = read_byte(f);
-@@ -325,7 +326,7 @@ void recv_uid_list(int f, struct file_li
+@@ -324,7 +325,7 @@ void recv_uid_list(int f, struct file_li
+               }
        }
  
 -      if (preserve_gid && !numeric_ids) {
 +      if ((preserve_gid || preserve_acls) && !numeric_ids) {
                /* read the gid list */
                while ((id = read_int(f)) != 0) {
                        int len = read_byte(f);
-@@ -337,6 +338,18 @@ void recv_uid_list(int f, struct file_li
+@@ -336,6 +337,18 @@ void recv_uid_list(int f, struct file_li
                }
        }
  
@@ -5144,6 +5449,6 @@ ACLs to a non-ACL-supporting disk should complain.
 +      }
 +#endif /* SUPPORT_ACLS */
 +
-       /* now convert the uid/gid of all files in the list to the mapped
-        * uid/gid */
+       /* Now convert all the uids/gids from sender values to our values. */
        if (am_root && preserve_uid && !numeric_ids) {
+               for (i = 0; i < flist->count; i++)