- Made the "types" array a single static instead of a separate
[rsync/rsync-patches.git] / acls.diff
index 27d2a5c..31ab54f 100644 (file)
--- a/acls.diff
+++ b/acls.diff
@@ -1,9 +1,7 @@
 After applying this patch, run these commands for a successful build:
 
-    autoconf
-    autoheader
-    ./configure --with-acl-support
-    make proto
+    ./prepare-source
+    ./configure --enable-acl-support
     make
 
 The program currently complains when the --acls (-A) option is used to copy
@@ -11,9 +9,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@
+--- old/Makefile.in
++++ new/Makefile.in
+@@ -25,15 +25,15 @@ VERSION=@VERSION@
  .SUFFIXES:
  .SUFFIXES: .c .o
  
@@ -22,20 +20,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        2004-10-20 06:36:04
-+++ acls.c     2004-10-20 06:36:04
-@@ -0,0 +1,1130 @@
+--- old/acls.c
++++ new/acls.c
+@@ -0,0 +1,1230 @@
 +/* -*- c-file-style: "linux" -*-
 +   Copyright (C) Andrew Tridgell 1996
 +   Copyright (C) Paul Mackerras 1996
@@ -60,11 +57,12 @@ ACLs to a non-ACL-supporting disk should complain.
 +#include "rsync.h"
 +#include "lib/sysacls.h"
 +
-+#if SUPPORT_ACLS
++#ifdef SUPPORT_ACLS
 +
 +extern int preserve_acls;
 +extern int am_root;
 +extern int dry_run;
++extern int orig_umask;
 +
 +typedef struct {
 +      id_t id;
@@ -79,11 +77,12 @@ ACLs to a non-ACL-supporting disk should complain.
 +} rsync_acl;
 +
 +static const rsync_acl rsync_acl_initializer = { 0, 0, NULL };
++static SMB_ACL_TYPE_T types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
 +
 +static void expand_rsync_acl(rsync_acl *racl)
 +{
-+      /* first time through, 0 <= 0, so list is expanded:
-+       * diabolical, rsync guys! */
++      /* First time through, 0 <= 0, so list is expanded.
++       * (Diabolical, rsync guys!) */
 +      if (racl->malloced <= racl->count) {
 +              rsync_ace *new_ptr;
 +              size_t new_size = racl->malloced + 10;
@@ -247,8 +246,8 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +static void expand_rsync_acl_list(rsync_acl_list *racl_list)
 +{
-+      /* first time through, 0 <= 0, so list is expanded:
-+       * diabolical, rsync guys! */
++      /* First time through, 0 <= 0, so list is expanded.
++       * (Diabolical, rsync guys!) */
 +      if (racl_list->malloced <= racl_list->count) {
 +              rsync_acl *new_ptr;
 +              size_t new_size;
@@ -274,8 +273,8 @@ ACLs to a non-ACL-supporting disk should complain.
 +#if 0
 +static void free_rsync_acl_list(rsync_acl_list *racl_list)
 +{
-+      /* run this in reverse, so references are freed before referents, */
-+      /* although not currently necessary */
++      /* Run this in reverse, so references are freed before referents,
++       * although not currently necessary. */
 +      while (racl_list->count--) {
 +              rsync_acl *racl = &racl_list->racls[racl_list->count];
 +              if (racl)
@@ -295,9 +294,9 @@ ACLs to a non-ACL-supporting disk should complain.
 +      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
++      /* 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 */
++       * best place to start hunting. */
 +      if (*match == -1)
 +              *match = racl_list->count - 1;
 +      while (count--) {
@@ -310,12 +309,12 @@ ACLs to a non-ACL-supporting disk should complain.
 +      return *match;
 +}
 +
-+/* the general strategy with the tag_type <-> character mapping is that
++/* The general strategy with the tag_type <-> character mapping is that
 + * lowercase implies that no qualifier follows, where uppercase does.
-+ * same sorta thing for the acl type (access or default) itself, but
++ * A similar idiom for the acl type (access or default) itself, but
 + * lowercase in this instance means there's no ACL following, so the
 + * ACL is a repeat, so the receiver should reuse the last of the same
-+ * type ACL */
++ * type ACL. */
 +
 +static void send_rsync_acl(int f, const rsync_acl *racl)
 +{
@@ -345,7 +344,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +                      break;
 +              default:
 +                      rprintf(FERROR,
-+                              "send_rsync_acl: unknown tag_type (%0x) on ACE; disregarding\n",
++                              "send_rsync_acl: unknown tag_type (%02x) on ACE; disregarding\n",
 +                              race->tag_type);
 +                      continue;
 +              }
@@ -353,9 +352,9 @@ ACLs to a non-ACL-supporting disk should complain.
 +              write_byte(f, race->access);
 +              if (isupper((int)ch)) {
 +                      write_int(f, race->id);
-+                      /* FIXME: sorta wasteful. we should maybe buffer as
++                      /* FIXME: sorta wasteful: we should maybe buffer as
 +                       * many ids as max(ACL_USER + ACL_GROUP) objects to
-+                       * keep from making so many calls */
++                       * keep from making so many calls. */
 +                      if (ch == 'U')
 +                              add_uid(race->id);
 +                      else
@@ -374,16 +373,33 @@ ACLs to a non-ACL-supporting disk should complain.
 +              "unknown SMB_ACL_TYPE_T";
 +}
 +
-+/* generate the ACL(s) for this flist entry;
-+ * ACL(s) are either sent or cleaned-up by send_acl() below */
++/*
++ * Overwrite racl with a new three-entry ACL from the given permissions.
++ */
++static void perms_to_acl(int perms, rsync_acl *racl)
++{
++      racl->count = 0;
++      expand_rsync_acl(racl);
++      racl->races[racl->count].tag_type = SMB_ACL_USER_OBJ;
++      racl->races[racl->count++].access = (perms >> 6) & 7;
++      expand_rsync_acl(racl);
++      racl->races[racl->count].tag_type = SMB_ACL_GROUP_OBJ;
++      racl->races[racl->count++].access = (perms >> 3) & 7;
++      expand_rsync_acl(racl);
++      racl->races[racl->count].tag_type = SMB_ACL_OTHER;
++      racl->races[racl->count++].access = (perms >> 0) & 7;
++}
 +
-+BOOL make_acl(const struct file_struct *file, const char *fname)
++/* Generate the ACL(s) for this flist entry;
++ * ACL(s) are either sent or cleaned-up by send_acl() below. */
++
++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};
++      SMB_ACL_TYPE_T *type;
 +      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));
@@ -391,27 +407,33 @@ ACLs to a non-ACL-supporting disk should complain.
 +              SMB_ACL_T sacl;
 +              BOOL ok;
 +              *curr_racl = rsync_acl_initializer;
-+              if (!(sacl = sys_acl_get_file(fname, *type))) {
++              if ((sacl = sys_acl_get_file(fname, *type)) != 0) {
++                      ok = unpack_smb_acl(curr_racl, sacl);
++                      sys_acl_free_acl(sacl);
++                      if (!ok)
++                              return -1;
++              } else if (errno == ENOTSUP) {
++                      /* ACLs are not supported.  Invent an access ACL from
++                       * permissions; let the default ACL default to empty. */
++                      if (*type == SMB_ACL_TYPE_ACCESS)
++                              perms_to_acl(file->mode & ACCESSPERMS, curr_racl);
++              } else {
 +                      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 True;
++      return 0;
 +}
 +
-+/* send the make_acl()-generated ACLs for this flist entry,
-+ * or clean up after an flist entry that's not being sent (f == -1) */
++/* Send the make_acl()-generated ACLs for this flist entry,
++ * or clean up after an flist entry that's not being sent (f == -1). */
 +
 +void send_acl(const struct file_struct *file, int f)
 +{
-+      SMB_ACL_TYPE_T *type,
-+              types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
++      SMB_ACL_TYPE_T *type;
 +      rsync_acl *curr_racl;
++
 +      if (!preserve_acls || S_ISLNK(file->mode))
 +              return;
 +      for (type = &types[0], curr_racl = &_curr_rsync_acls[0];
@@ -438,7 +460,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      }
 +}
 +
-+/* the below stuff is only used by the receiver */
++/* The below stuff is only used by the receiver: */
 +
 +/* structure to hold index to rsync_acl_list member corresponding to
 + * flist->files[i] */
@@ -467,8 +489,8 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +static void expand_file_acl_index_list(file_acl_index_list *fileaclidx_list)
 +{
-+      /* first time through, 0 <= 0, so list is expanded:
-+       * diabolical, rsync guys! */
++      /* First time through, 0 <= 0, so list is expanded.
++       * (Diabolical, rsync guys!) */
 +      if (fileaclidx_list->malloced <= fileaclidx_list->count) {
 +              file_acl_index *new_ptr;
 +              size_t new_size;
@@ -521,8 +543,8 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +static void expand_smb_acl_list(smb_acl_list *sacl_list)
 +{
-+      /* first time through, 0 <= 0, so list is expanded:
-+       * diabolical, rsync guys! */
++      /* First time through, 0 <= 0, so list is expanded.
++       * (Diabolical, rsync guys!) */
 +      if (sacl_list->malloced <= sacl_list->count) {
 +              SMB_ACL_T *new_ptr;
 +              size_t new_size;
@@ -756,12 +778,13 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +void receive_acl(struct file_struct *file, int f)
 +{
-+      SMB_ACL_TYPE_T *type,
-+              types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
++      SMB_ACL_TYPE_T *type;
 +      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));
@@ -830,14 +853,14 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +void sort_file_acl_index_lists()
 +{
-+      SMB_ACL_TYPE_T *type,
-+              types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
++      SMB_ACL_TYPE_T *type;
++
 +      if (!preserve_acls)
 +              return;
++
 +      for (type = &types[0];
 +           type < &types[0] + sizeof types / sizeof types[0];
-+           type++)
-+      {
++           type++) {
 +              file_acl_index_list *fileaclidx_list =
 +                      file_acl_index_lists(*type);
 +              if (!fileaclidx_list->count)
@@ -879,11 +902,12 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +int dup_acl(const char *orig, const char *bak, mode_t mode)
 +{
-+      SMB_ACL_TYPE_T *type,
-+              types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
++      SMB_ACL_TYPE_T *type;
 +      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));
@@ -917,12 +941,12 @@ ACLs to a non-ACL-supporting disk should complain.
 +                      ; /* presume they're unequal */
 +              }
 +              if (*type == SMB_ACL_TYPE_DEFAULT && !racl_orig.count) {
-+                      if (-1 == sys_acl_delete_def_file(bak)) {
++                      if (sys_acl_delete_def_file(bak) < 0) {
 +                              rprintf(FERROR, "dup_acl: sys_acl_delete_def_file(%s): %s\n",
 +                                      bak, strerror(errno));
 +                              ret = -1;
 +                      }
-+              } else if (-1 == sys_acl_set_file(bak, *type, sacl_bak)) {
++              } else if (sys_acl_set_file(bak, *type, sacl_bak) < 0) {
 +                      rprintf(FERROR, "dup_acl: sys_acl_set_file(%s, %s): %s\n",
 +                              bak, str_acl_type(*type), strerror(errno));
 +                      ret = -1;
@@ -942,8 +966,8 @@ ACLs to a non-ACL-supporting disk should complain.
 +      return ret;
 +}
 +
-+/* stuff for redirecting calls to set_acl() from set_perms()
-+ * for keep_backup() */
++/* 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[] = "";
 +static const char *backup_orig_fname = null_string;
@@ -954,12 +978,13 @@ ACLs to a non-ACL-supporting disk should complain.
 +                        const char *orig, const char *dest)
 +{
 +      if (preserve_acls) {
-+              SMB_ACL_TYPE_T *type,
-+                      types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
++              SMB_ACL_TYPE_T *type;
 +              SMB_ACL_T *sacl;
++
 +              backup_orig_file = file;
 +              backup_orig_fname = orig;
 +              backup_dest_fname = dest;
++
 +              for (type = &types[0], sacl = &_backup_sacl[0];
 +                   type < &types[0] + sizeof types / sizeof types[0];
 +                   type++) {
@@ -979,17 +1004,16 @@ ACLs to a non-ACL-supporting disk should complain.
 +static int set_keep_backup_acl()
 +{
 +      if (preserve_acls) {
-+              SMB_ACL_TYPE_T *type,
-+                      types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
++              SMB_ACL_TYPE_T *type;
 +              SMB_ACL_T *sacl;
 +              int ret = 0;
++
 +              for (type = &types[0], sacl = &_backup_sacl[0];
 +                   type < &types[0] + sizeof types / sizeof types[0];
 +                   type++) {
 +                      if (*sacl) {
-+                              if (-1 == sys_acl_set_file(backup_dest_fname,
-+                                                         *type, *sacl))
-+                              {
++                              if (sys_acl_set_file(backup_dest_fname,
++                                                   *type, *sacl) < 0) {
 +                                      rprintf(FERROR, "push_keep_backup_acl: sys_acl_get_file(%s, %s): %s\n",
 +                                              backup_dest_fname,
 +                                              str_acl_type(*type),
@@ -1000,18 +1024,19 @@ ACLs to a non-ACL-supporting disk should complain.
 +              }
 +              return ret;
 +      }
-+      return 0;
++      return 1;
 +}
 +
 +void cleanup_keep_backup_acl()
 +{
 +      if (preserve_acls) {
-+              SMB_ACL_TYPE_T *type,
-+                      types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
++              SMB_ACL_TYPE_T *type;
 +              SMB_ACL_T *sacl;
++
 +              backup_orig_file = NULL;
 +              backup_orig_fname = null_string;
 +              backup_dest_fname = null_string;
++
 +              for (type = &types[0], sacl = &_backup_sacl[0];
 +                   type < &types[0] + sizeof types / sizeof types[0];
 +                   type++) {
@@ -1026,11 +1051,12 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +int set_acl(const char *fname, const struct file_struct *file)
 +{
-+      int updated = 0;
-+      SMB_ACL_TYPE_T *type,
-+              types[] = {SMB_ACL_TYPE_ACCESS, SMB_ACL_TYPE_DEFAULT};
++      int unchanged = 1;
++      SMB_ACL_TYPE_T *type;
++
 +      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();
@@ -1050,13 +1076,13 @@ ACLs to a non-ACL-supporting disk should complain.
 +              if (!sacl_orig) {
 +                      rprintf(FERROR, "set_acl: sys_acl_get_file(%s, %s): %s\n",
 +                              fname, str_acl_type(*type), strerror(errno));
-+                      updated = -1;
++                      unchanged = -1;
 +                      continue;
 +              }
 +              ok = unpack_smb_acl(&racl_orig, sacl_orig);
 +              sys_acl_free_acl(sacl_orig);
 +              if (!ok) {
-+                      updated = -1;
++                      unchanged = -1;
 +                      continue;
 +              }
 +              ok = rsync_acls_equal(&racl_orig, racl_new);
@@ -1064,36 +1090,36 @@ ACLs to a non-ACL-supporting disk should complain.
 +              if (ok)
 +                      continue;
 +              if (*type == SMB_ACL_TYPE_DEFAULT && !racl_new->count) {
-+                      if (-1 == sys_acl_delete_def_file(fname)) {
++                      if (sys_acl_delete_def_file(fname) < 0) {
 +                              rprintf(FERROR, "set_acl: sys_acl_delete_def_file(%s): %s\n",
 +                                      fname, strerror(errno));
-+                              updated = -1;
++                              unchanged = -1;
 +                              continue;
 +                      }
 +              } else {
 +                      if (!*sacl_new)
 +                              if (!pack_smb_acl(sacl_new, racl_new)) {
-+                                      updated = -1;
++                                      unchanged = -1;
 +                                      continue;
 +                              }
-+                      if (-1 == sys_acl_set_file(fname, *type, *sacl_new)) {
++                      if (sys_acl_set_file(fname, *type, *sacl_new) < 0) {
 +                              rprintf(FERROR, "set_acl: sys_acl_set_file(%s, %s): %s\n",
 +                                      fname, str_acl_type(*type),
 +                                      strerror(errno));
-+                              updated = -1;
++                              unchanged = -1;
 +                              continue;
 +                      }
 +              }
-+              if (!updated)
-+                      updated = 1;
++              if (unchanged == 1)
++                      unchanged = 0;
 +      }
-+      return updated;
++      return unchanged;
 +}
 +
-+/* enumeration functions for uid mapping */
++/* Enumeration functions for uid mapping: */
 +
-+/* context -- one and only one. should be cycled through once on uid mapping
-+ * and once on gid mapping */
++/* Context -- one and only one.  Should be cycled through once on uid
++ * mapping and once on gid mapping. */
 +static rsync_acl_list *_enum_racl_lists[] = {
 +      &_rsync_acl_lists[0], &_rsync_acl_lists[1], NULL
 +};
@@ -1102,8 +1128,8 @@ ACLs to a non-ACL-supporting disk should complain.
 +static size_t enum_racl_index = 0;
 +static size_t enum_race_index = 0;
 +
-+/* this returns the next tag_type id from the given acl for the next entry,
-+ * or it returns 0 if there are no more tag_type ids in the acl */
++/* This returns the next tag_type id from the given acl for the next entry,
++ * 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)
 +{
@@ -1165,37 +1191,114 @@ 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
-+++ backup.c   2004-10-06 00:13:09
-@@ -135,6 +135,7 @@ static int make_bak_dir(char *fullpath)
+--- old/backup.c
++++ new/backup.c
+@@ -132,6 +132,9 @@ static int make_bak_dir(char *fullpath)
                        } else {
                                do_lchown(fullpath, st.st_uid, st.st_gid);
                                do_chmod(fullpath, st.st_mode);
-+                              (void)DUP_ACL(end, fullpath, st.st_mode);
++#ifdef SUPPORT_ACLS
++                              dup_acl(end, fullpath, st.st_mode);
++#endif
                        }
                }
                *p = '/';
-@@ -187,6 +188,8 @@ static int keep_backup(char *fname)
+@@ -185,6 +188,10 @@ static int keep_backup(char *fname)
        if (!(buf = get_backup_name(fname)))
                return 0;
  
-+      PUSH_KEEP_BACKUP_ACL(file, fname, buf);
++#ifdef SUPPORT_ACLS
++      push_keep_backup_acl(file, fname, buf);
++#endif
 +
        /* 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))) {
+@@ -260,6 +267,9 @@ static int keep_backup(char *fname)
                }
        }
-       set_perms(buf, file, NULL, 0);
-+      CLEANUP_KEEP_BACKUP_ACL();
+       set_file_attrs(buf, file, NULL, 0);
++#ifdef SUPPORT_ACLS
++      cleanup_keep_backup_acl();
++#endif
        free(file);
  
        if (verbose > 1) {
---- orig/configure.in  2005-04-07 17:04:26
-+++ configure.in       2004-08-19 19:53:27
-@@ -478,6 +478,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
+--- old/configure.in
++++ new/configure.in
+@@ -482,6 +482,11 @@ if test x"$ac_cv_func_strcasecmp" = x"no
      AC_CHECK_LIB(resolv, strcasecmp)
  fi
  
@@ -1207,7 +1310,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)
+@@ -738,6 +743,77 @@ AC_SUBST(OBJ_RESTORE)
  AC_SUBST(CC_SHOBJ_FLAG)
  AC_SUBST(BUILD_POPT)
  
@@ -1217,9 +1320,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,62 +1388,105 @@ 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-04-28 15:56:50
-+++ 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);
+--- old/flist.c
++++ new/flist.c
+@@ -966,6 +966,10 @@ static struct file_struct *send_file_nam
+                        f == -2 ? SERVER_FILTERS : ALL_FILTERS);
        if (!file)
                return NULL;
-+      if (!MAKE_ACL(file, fname))
-+              return;
-       maybe_emit_filelist_progress(flist->count + flist_count_offset);
++#ifdef SUPPORT_ACLS
++      if (make_acl(file, fname) < 0)
++              return NULL;
++#endif
  
-@@ -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);
+@@ -977,6 +981,12 @@ static struct file_struct *send_file_nam
        if (file->basename[0]) {
                flist->files[flist->count++] = file;
-               send_file_entry(file, f, base_flags);
-+              SEND_ACL(file, f);
+               send_file_entry(file, f);
++#ifdef SUPPORT_ACLS
++              send_acl(file, f);
 +      } else {
 +              /* Cleanup unsent ACL(s). */
-+              SEND_ACL(file, -1);
++              send_acl(file, -1);
++#endif
        }
        return file;
  }
-@@ -1308,6 +1314,8 @@ struct file_list *recv_file_list(int f)
+@@ -1365,6 +1375,10 @@ struct file_list *recv_file_list(int f)
                        flags |= read_byte(f) << 8;
                file = receive_file_entry(flist, flags, f);
  
-+              RECEIVE_ACL(file, f);
++#ifdef SUPPORT_ACLS
++              receive_acl(file, f);
++#endif
 +
-               if (S_ISREG(file->mode))
+               if (S_ISREG(file->mode) || S_ISLNK(file->mode))
                        stats.total_size += file->length;
  
-@@ -1330,6 +1338,8 @@ struct file_list *recv_file_list(int f)
+@@ -1387,6 +1401,10 @@ struct file_list *recv_file_list(int f)
  
        clean_flist(flist, relative_paths, 1);
  
-+      SORT_FILE_ACL_INDEX_LISTS();
++#ifdef SUPPORT_ACLS
++      sort_file_acl_index_lists();
++#endif
 +
        if (f >= 0) {
-               /* Now send the uid/gid list. This was introduced in
-                * protocol version 15 */
---- orig/generator.c   2005-04-28 16:26:28
-+++ generator.c        2005-03-11 11:18:22
-@@ -720,6 +720,10 @@ static void recv_generator(char *fname, 
-               if (set_perms(fname, file, statret ? NULL : &st, 0)
-                   && verbose && code && f_out != -1)
-                       rprintf(code, "%s/\n", safe_fname(fname));
-+#if SUPPORT_ACLS
-+              if (f_out == -1)
-+                      SET_ACL(fname, file);
+               recv_uid_list(f, flist);
+--- old/generator.c
++++ new/generator.c
+@@ -85,6 +85,7 @@ extern long block_size; /* "long" becaus
+ extern int max_delete;
+ extern int force_delete;
+ extern int one_file_system;
++extern mode_t orig_umask;
+ extern struct stats stats;
+ extern dev_t filesystem_dev;
+ extern char *backup_dir;
+@@ -753,6 +754,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
+@@ -844,6 +846,10 @@ static void recv_generator(char *fname, 
+                       }
+                       if (fuzzy_basis)
+                               need_fuzzy_dirlist = 1;
++#ifdef SUPPORT_ACLS
++                      if (!preserve_perms)
++                              dflt_perms = default_perms_for_dir(dn);
 +#endif
-               if (delete_during && f_out != -1 && !phase && dry_run < 2
-                   && (file->flags & FLAG_DEL_HERE))
-                       delete_in_dir(the_file_list, fname, file);
---- orig/lib/sysacls.c 2004-10-20 15:35:58
-+++ lib/sysacls.c      2004-10-20 15:35:58
-@@ -0,0 +1,3217 @@
+               }
+               parent_dirname = dn;
+@@ -871,7 +877,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)) {
+@@ -1342,6 +1349,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];
+--- old/lib/sysacls.c
++++ new/lib/sysacls.c
+@@ -0,0 +1,3242 @@
 +/* 
 +   Unix SMB/CIFS implementation.
 +   Samba system utilities for ACL support.
@@ -1362,8 +1508,9 @@ ACLs to a non-ACL-supporting disk should complain.
 +*/
 +
 +#include "rsync.h"
-+#include "sysacls.h"
++#include "sysacls.h" /****** ADDED ******/
 +
++/****** EXTRAS -- THESE ITEMS ARE NOT FROM THE SAMBA SOURCE ******/
 +void SAFE_FREE(void *mem)
 +{
 +      if (mem)
@@ -1381,6 +1528,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      }
 +      return pw->pw_name;
 +}
++/****** EXTRAS -- END ******/
 +
 +/*
 + This file wraps all differing system ACL interfaces into a consistent
@@ -1545,7 +1693,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      return acl_free(the_acl);
 +}
 +
-+int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
++int sys_acl_free_qualifier(void *qual, UNUSED(SMB_ACL_TAG_T tagtype))
 +{
 +      return acl_free(qual);
 +}
@@ -1974,7 +2122,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +       */
 +      len     = 0;
 +      maxlen  = 20 * acl_d->count;
-+      if ((text = malloc(maxlen)) == NULL) {
++      if ((text = SMB_MALLOC(maxlen)) == NULL) {
 +              errno = ENOMEM;
 +              return NULL;
 +      }
@@ -2052,7 +2200,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +                      maxlen += nbytes + 20 * (acl_d->count - i);
 +
-+                      if ((text = Realloc(oldtext, maxlen)) == NULL) {
++                      if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
 +                              SAFE_FREE(oldtext);
 +                              errno = ENOMEM;
 +                              return NULL;
@@ -2084,7 +2232,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +       * acl[] array, this actually allocates an ACL with room
 +       * for (count+1) entries
 +       */
-+      if ((a = malloc(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
++      if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
 +              errno = ENOMEM;
 +              return NULL;
 +      }
@@ -2248,7 +2396,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +               * allocate a temporary buffer for the complete ACL
 +               */
 +              acl_count = acc_acl->count + def_acl->count;
-+              acl_p = acl_buf = malloc(acl_count * sizeof(acl_buf[0]));
++              acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
 +
 +              if (acl_buf == NULL) {
 +                      sys_acl_free_acl(tmp_acl);
@@ -2605,7 +2753,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +       */
 +      len     = 0;
 +      maxlen  = 20 * acl_d->count;
-+      if ((text = malloc(maxlen)) == NULL) {
++      if ((text = SMB_MALLOC(maxlen)) == NULL) {
 +              errno = ENOMEM;
 +              return NULL;
 +      }
@@ -2683,7 +2831,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +                      maxlen += nbytes + 20 * (acl_d->count - i);
 +
-+                      if ((text = Realloc(oldtext, maxlen)) == NULL) {
++                      if ((text = SMB_REALLOC(oldtext, maxlen)) == NULL) {
 +                              free(oldtext);
 +                              errno = ENOMEM;
 +                              return NULL;
@@ -2715,7 +2863,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +       * acl[] array, this actually allocates an ACL with room
 +       * for (count+1) entries
 +       */
-+      if ((a = malloc(sizeof(*a) + count * sizeof(struct acl))) == NULL) {
++      if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + count * sizeof(struct acl))) == NULL) {
 +              errno = ENOMEM;
 +              return NULL;
 +      }
@@ -3181,7 +3329,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +               * allocate a temporary buffer for the complete ACL
 +               */
 +              acl_count = acc_acl->count + def_acl->count;
-+              acl_p = acl_buf = malloc(acl_count * sizeof(acl_buf[0]));
++              acl_p = acl_buf = SMB_MALLOC_ARRAY(struct acl, acl_count);
 +
 +              if (acl_buf == NULL) {
 +                      sys_acl_free_acl(tmp_acl);
@@ -3344,7 +3492,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +{
 +      SMB_ACL_T       a;
 +
-+      if ((a = malloc(sizeof(*a))) == NULL) {
++      if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
 +              errno = ENOMEM;
 +              return NULL;
 +      }
@@ -3361,7 +3509,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +{
 +      SMB_ACL_T       a;
 +
-+      if ((a = malloc(sizeof(*a))) == NULL) {
++      if ((a = SMB_MALLOC_P(struct SMB_ACL_T)) == NULL) {
 +              errno = ENOMEM;
 +              return NULL;
 +      }
@@ -3418,7 +3566,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +              return NULL;
 +      }
 +
-+      if ((a = malloc(sizeof(*a) + sizeof(struct acl))) == NULL) {
++      if ((a = SMB_MALLOC(sizeof(struct SMB_ACL_T) + sizeof(struct acl))) == NULL) {
 +              errno = ENOMEM;
 +              return NULL;
 +      }
@@ -3639,12 +3787,16 @@ ACLs to a non-ACL-supporting disk should complain.
 +      int rc = 0;
 +      uid_t user_id;
 +
++      /* AIX has no DEFAULT */
++      if  ( type == SMB_ACL_TYPE_DEFAULT )
++              return NULL;
++
 +      /* Get the acl using statacl */
 + 
 +      DEBUG(10,("Entering sys_acl_get_file\n"));
 +      DEBUG(10,("path_p is %s\n",path_p));
 +
-+      file_acl = (struct acl *)malloc(BUFSIZ);
++      file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
 + 
 +      if(file_acl == NULL) {
 +              errno=ENOMEM;
@@ -3675,7 +3827,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      if(acl_entry_link_head == NULL)
 +              return(NULL);
 +
-+      acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
++      acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
 +      if(acl_entry_link->entryp == NULL) {
 +              SAFE_FREE(file_acl);
 +              errno = ENOMEM;
@@ -3710,8 +3862,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +                       * and already has entryp allocated.                  */
 +
 +                      if(acl_entry_link_head->count != 0) {
-+                              acl_entry_link->nextp = (struct acl_entry_link *)
-+                                                                                      malloc(sizeof(struct acl_entry_link));
++                              acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
 +
 +                              if(acl_entry_link->nextp == NULL) {
 +                                      SAFE_FREE(file_acl);
@@ -3722,7 +3873,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +                              acl_entry_link->nextp->prevp = acl_entry_link;
 +                              acl_entry_link = acl_entry_link->nextp;
-+                              acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
++                              acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
 +                              if(acl_entry_link->entryp == NULL) {
 +                                      SAFE_FREE(file_acl);
 +                                      errno = ENOMEM;
@@ -3781,7 +3932,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      for( i = 1; i < 4; i++) {
 +              DEBUG(10,("i is %d\n",i));
 +              if(acl_entry_link_head->count != 0) {
-+                      acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
++                      acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
 +                      if(acl_entry_link->nextp == NULL) {
 +                              SAFE_FREE(file_acl);
 +                              errno = ENOMEM;
@@ -3791,7 +3942,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +                      acl_entry_link->nextp->prevp = acl_entry_link;
 +                      acl_entry_link = acl_entry_link->nextp;
-+                      acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
++                      acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
 +                      if(acl_entry_link->entryp == NULL) {
 +                              SAFE_FREE(file_acl);
 +                              errno = ENOMEM;
@@ -3858,7 +4009,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +   
 +      DEBUG(10,("Entering sys_acl_get_fd\n"));
 +      DEBUG(10,("fd is %d\n",fd));
-+      file_acl = (struct acl *)malloc(BUFSIZ);
++      file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
 +
 +      if(file_acl == NULL) {
 +              errno=ENOMEM;
@@ -3891,7 +4042,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +              return(NULL);
 +      }
 +
-+      acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
++      acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
 +
 +      if(acl_entry_link->entryp == NULL) {
 +              errno = ENOMEM;
@@ -3928,7 +4079,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +                       * and already has entryp allocated.                 */
 +
 +                      if(acl_entry_link_head->count != 0) {
-+                              acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
++                              acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
 +                              if(acl_entry_link->nextp == NULL) {
 +                                      errno = ENOMEM;
 +                                      DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
@@ -3937,7 +4088,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +                              }
 +                              acl_entry_link->nextp->prevp = acl_entry_link;
 +                              acl_entry_link = acl_entry_link->nextp;
-+                              acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
++                              acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
 +                              if(acl_entry_link->entryp == NULL) {
 +                                      errno = ENOMEM;
 +                                      DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
@@ -3996,7 +4147,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      for( i = 1; i < 4; i++) {
 +              DEBUG(10,("i is %d\n",i));
 +              if(acl_entry_link_head->count != 0){
-+                      acl_entry_link->nextp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
++                      acl_entry_link->nextp = SMB_MALLOC_P(struct acl_entry_link);
 +                      if(acl_entry_link->nextp == NULL) {
 +                              errno = ENOMEM;
 +                              DEBUG(0,("Error in sys_acl_get_fd is %d\n",errno));
@@ -4006,7 +4157,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +                      acl_entry_link->nextp->prevp = acl_entry_link;
 +                      acl_entry_link = acl_entry_link->nextp;
-+                      acl_entry_link->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
++                      acl_entry_link->entryp = SMB_MALLOC_P(struct new_acl_entry);
 +
 +                      if(acl_entry_link->entryp == NULL) {
 +                              SAFE_FREE(file_acl);
@@ -4085,7 +4236,7 @@ ACLs to a non-ACL-supporting disk should complain.
 + 
 +      DEBUG(10,("Entering sys_acl_init\n"));
 +
-+      theacl = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
++      theacl = SMB_MALLOC_P(struct acl_entry_link);
 +      if(theacl == NULL) {
 +              errno = ENOMEM;
 +              DEBUG(0,("Error in sys_acl_init is %d\n",errno));
@@ -4120,7 +4271,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +      }
 +
 +      if(theacl->count != 0){
-+              temp_entry->nextp = acl_entryp = (struct acl_entry_link *)malloc(sizeof(struct acl_entry_link));
++              temp_entry->nextp = acl_entryp = SMB_MALLOC_P(struct acl_entry_link);
 +              if(acl_entryp == NULL) {
 +                      errno = ENOMEM;
 +                      DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
@@ -4132,7 +4283,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +              DEBUG(10,("The acl_entryp->prevp is %d\n",acl_entryp->prevp));
 +      }
 +
-+      *pentry = acl_entryp->entryp = (struct new_acl_entry *)malloc(sizeof(struct new_acl_entry));
++      *pentry = acl_entryp->entryp = SMB_MALLOC_P(struct new_acl_entry);
 +      if(*pentry == NULL) {
 +              errno = ENOMEM;
 +              DEBUG(0,("Error in sys_acl_create_entry is %d\n",errno));
@@ -4222,7 +4373,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +              return(0);
 +
 +      acl_length = BUFSIZ;
-+      file_acl = (struct acl *)malloc(BUFSIZ);
++      file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
 +
 +      if(file_acl == NULL) {
 +              errno = ENOMEM;
@@ -4255,7 +4406,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +              if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
 +                      acl_length += sizeof(struct acl_entry);
-+                      file_acl_temp = (struct acl *)malloc(acl_length);
++                      file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
 +                      if(file_acl_temp == NULL) {
 +                              SAFE_FREE(file_acl);
 +                              errno = ENOMEM;
@@ -4310,7 +4461,7 @@ ACLs to a non-ACL-supporting disk should complain.
 + 
 +      DEBUG(10,("Entering sys_acl_set_fd\n"));
 +      acl_length = BUFSIZ;
-+      file_acl = (struct acl *)malloc(BUFSIZ);
++      file_acl = (struct acl *)SMB_MALLOC(BUFSIZ);
 +
 +      if(file_acl == NULL) {
 +              errno = ENOMEM;
@@ -4344,7 +4495,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +              if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) {
 +                      acl_length += sizeof(struct acl_entry);
-+                      file_acl_temp = (struct acl *)malloc(acl_length);
++                      file_acl_temp = (struct acl *)SMB_MALLOC(acl_length);
 +                      if(file_acl_temp == NULL) {
 +                              SAFE_FREE(file_acl);
 +                              errno = ENOMEM;
@@ -4425,49 +4576,49 @@ ACLs to a non-ACL-supporting disk should complain.
 +
 +#else /* No ACLs. */
 +
-+int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
++int sys_acl_get_entry(UNUSED(SMB_ACL_T the_acl), UNUSED(int entry_id), UNUSED(SMB_ACL_ENTRY_T *entry_p))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
++int sys_acl_get_tag_type(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_TAG_T *tag_type_p))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
++int sys_acl_get_permset(UNUSED(SMB_ACL_ENTRY_T entry_d), UNUSED(SMB_ACL_PERMSET_T *permset_p))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
++void *sys_acl_get_qualifier(UNUSED(SMB_ACL_ENTRY_T entry_d))
 +{
 +      errno = ENOSYS;
 +      return NULL;
 +}
 +
-+SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
++SMB_ACL_T sys_acl_get_file(UNUSED(const char *path_p), UNUSED(SMB_ACL_TYPE_T type))
 +{
 +      errno = ENOSYS;
 +      return (SMB_ACL_T)NULL;
 +}
 +
-+SMB_ACL_T sys_acl_get_fd(int fd)
++SMB_ACL_T sys_acl_get_fd(UNUSED(int fd))
 +{
 +      errno = ENOSYS;
 +      return (SMB_ACL_T)NULL;
 +}
 +
-+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
++int sys_acl_clear_perms(UNUSED(SMB_ACL_PERMSET_T permset))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
++int sys_acl_add_perm( UNUSED(SMB_ACL_PERMSET_T permset), UNUSED(SMB_ACL_PERM_T perm))
 +{
 +      errno = ENOSYS;
 +      return -1;
@@ -4479,89 +4630,112 @@ ACLs to a non-ACL-supporting disk should complain.
 +      return (permset & perm) ? 1 : 0;
 +}
 +
-+char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
++char *sys_acl_to_text(UNUSED(SMB_ACL_T the_acl), UNUSED(ssize_t *plen))
 +{
 +      errno = ENOSYS;
 +      return NULL;
 +}
 +
-+int sys_acl_free_text(char *text)
++int sys_acl_free_text(UNUSED(char *text))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+SMB_ACL_T sys_acl_init( int count)
++SMB_ACL_T sys_acl_init(UNUSED(int count))
 +{
 +      errno = ENOSYS;
 +      return NULL;
 +}
 +
-+int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
++int sys_acl_create_entry(UNUSED(SMB_ACL_T *pacl), UNUSED(SMB_ACL_ENTRY_T *pentry))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
++int sys_acl_set_tag_type(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_TAG_T tagtype))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
++int sys_acl_set_qualifier(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(void *qual))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
++int sys_acl_set_permset(UNUSED(SMB_ACL_ENTRY_T entry), UNUSED(SMB_ACL_PERMSET_T permset))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_valid( SMB_ACL_T theacl )
++int sys_acl_valid(UNUSED(SMB_ACL_T theacl))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
++int sys_acl_set_file(UNUSED(const char *name), UNUSED(SMB_ACL_TYPE_T acltype), UNUSED(SMB_ACL_T theacl))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_set_fd( int fd, SMB_ACL_T theacl)
++int sys_acl_set_fd(UNUSED(int fd), UNUSED(SMB_ACL_T theacl))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_delete_def_file(const char *name)
++int sys_acl_delete_def_file(UNUSED(const char *name))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_free_acl(SMB_ACL_T the_acl) 
++int sys_acl_free_acl(UNUSED(SMB_ACL_T the_acl))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
-+int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype)
++int sys_acl_free_qualifier(UNUSED(void *qual), UNUSED(SMB_ACL_TAG_T tagtype))
 +{
 +      errno = ENOSYS;
 +      return -1;
 +}
 +
 +#endif /* No ACLs. */
---- orig/lib/sysacls.h 2004-10-20 15:31:22
-+++ lib/sysacls.h      2004-10-20 15:31:22
-@@ -0,0 +1,25 @@
-+#define Realloc(mem, cnt)     realloc_array((mem), char, (cnt))
++
++/************************************************************************
++ Deliberately outside the ACL defines. Return 1 if this is a "no acls"
++ errno, 0 if not.
++************************************************************************/
++
++int no_acl_syscall_error(int err)
++{
++#if defined(ENOSYS)
++      if (err == ENOSYS) {
++              return 1;
++      }
++#endif
++#if defined(ENOTSUP)
++      if (err == ENOTSUP) {
++              return 1;
++      }
++#endif
++      return 0;
++}
+--- old/lib/sysacls.h
++++ new/lib/sysacls.h
+@@ -0,0 +1,28 @@
++#define SMB_MALLOC(cnt) new_array(char, cnt)
++#define SMB_MALLOC_P(obj) new_array(obj, 1)
++#define SMB_MALLOC_ARRAY(obj, cnt) new_array(obj, cnt)
++#define SMB_REALLOC(mem, cnt) realloc_array(mem, char, cnt)
 +#define slprintf snprintf
 +
 +int sys_acl_get_entry(SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
@@ -4586,28 +4760,28 @@ ACLs to a non-ACL-supporting disk should complain.
 +int sys_acl_free_text(char *text);
 +int sys_acl_free_acl(SMB_ACL_T the_acl);
 +int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype);
---- orig/mkproto.awk   2005-02-18 20:16:59
-+++ mkproto.awk        2005-02-18 20:18:17
+--- old/mkproto.awk
++++ new/mkproto.awk
 @@ -58,7 +58,7 @@ BEGIN {
    next;
  }
  
--!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const/ {
-+!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const/ {
+-!/^OFF_T|^size_t|^off_t|^pid_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
++!/^OFF_T|^size_t|^off_t|^pid_t|^id_t|^unsigned|^mode_t|^DIR|^user|^int|^char|^uint|^uchar|^short|^struct|^BOOL|^void|^time|^const|^RETSIGTYPE/ {
    next;
  }
  
---- orig/options.c     2005-05-10 15:32:58
-+++ options.c  2005-02-14 02:46:05
-@@ -44,6 +44,7 @@ int keep_dirlinks = 0;
+--- old/options.c
++++ new/options.c
+@@ -45,6 +45,7 @@ int copy_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
+@@ -194,6 +195,7 @@ static void print_rsync_version(enum log
        char const *got_socketpair = "no ";
        char const *have_inplace = "no ";
        char const *hardlinks = "no ";
@@ -4615,7 +4789,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
+@@ -210,6 +212,10 @@ static void print_rsync_version(enum log
        hardlinks = "";
  #endif
  
@@ -4626,42 +4800,46 @@ 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");
+@@ -223,9 +229,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",
-+              "%shard links, %sACLs, %ssymlinks, batchfiles, \n",
+-              "%shard links, %ssymlinks, batchfiles,\n",
++              "%shard links, %sACLs, %ssymlinks, batchfiles,\n",
                (int) (sizeof (OFF_T) * 8),
 -              got_socketpair, hardlinks, links);
 +              got_socketpair, hardlinks, acls, links);
  
        /* 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)
+@@ -295,6 +301,9 @@ void usage(enum logcode F)
    rprintf(F," -H, --hard-links            preserve hard links\n");
-   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");
++#ifdef SUPPORT_ACLS
 +  rprintf(F," -A, --acls                  preserve ACLs (implies --perms)\n");
-   rprintf(F," -o, --owner                 preserve owner (root only)\n");
++#endif
+   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");
-@@ -409,6 +416,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 },
-@@ -882,6 +890,24 @@ int parse_arguments(int *argc, const cha
-                       basis_dir[basis_dir_cnt++] = (char *)arg;
-                       break;
+@@ -410,6 +419,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 },
+@@ -1068,6 +1080,23 @@ int parse_arguments(int *argc, const cha
+                       usage(FINFO);
+                       exit_cleanup(0);
  
 +              case 'A':
-+#if SUPPORT_ACLS
-+                      preserve_acls = 1;
-+                      preserve_perms = 1;
++#ifdef SUPPORT_ACLS
++                      preserve_acls = preserve_perms = 1;
++                      break;
 +#else
 +                      /* FIXME: this should probably be ignored with a
 +                       * warning and then countermeasures taken to
@@ -4672,106 +4850,169 @@ ACLs to a non-ACL-supporting disk should complain.
 +                                 "ACLs are not supported on this %s\n",
 +                               am_server ? "server" : "client");
 +                      return 0;
-+#endif /* SUPPORT_ACLS */
-+                      break;
++#endif
 +
 +
                default:
                        /* A large opt value means that set_refuse_options()
                         * turned this option off. */
-@@ -1286,6 +1312,8 @@ void server_options(char **args,int *arg
+@@ -1511,6 +1540,10 @@ void server_options(char **args,int *arg
  
        if (preserve_hard_links)
                argstr[x++] = 'H';
++#ifdef SUPPORT_ACLS
 +      if (preserve_acls)
 +              argstr[x++] = 'A';
++#endif
        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
+--- old/receiver.c
++++ new/receiver.c
+@@ -46,6 +46,7 @@ extern int keep_partial;
+ extern int checksum_seed;
+ extern int inplace;
+ extern int delay_updates;
++extern mode_t orig_umask;
+ extern struct stats stats;
+ extern char *log_format;
+ extern char *tmpdir;
+@@ -344,6 +345,10 @@ 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);
++#ifdef SUPPORT_ACLS
++      char *parent_dirname = "";
++#endif
+       int i, recv_ok;
+       if (verbose > 2)
+@@ -541,7 +546,16 @@ 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
++                      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" */
+--- old/rsync.c
++++ new/rsync.c
+@@ -101,7 +101,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 cur_mode, int exists)
++mode_t dest_mode(mode_t flist_mode, mode_t cur_mode, int dflt_perms,
++               int exists)
+ {
+       /* If the file already exists, we'll return the local permissions,
+        * possibly tweaked by the --executability option. */
+@@ -116,7 +117,7 @@ mode_t dest_mode(mode_t flist_mode, mode
+                               cur_mode |= (cur_mode & 0444) >> 2;
+               }
+       } else
+-              cur_mode = flist_mode & ACCESSPERMS & ~orig_umask;
++              cur_mode = flist_mode & ACCESSPERMS & dflt_perms;
+       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,6 +204,13 @@ int set_file_attrs(char *fname, struct f
+               updated = 1;
        }
- #endif
  
-+      /* If this is a directory, SET_ACL() will be called on the cleanup
-+       * receive_generator() pass--if we called it here, we might clobber
-+       * writability on the directory. everything else is OK to do now. */
-+      if (!S_ISDIR(st->st_mode)) {
-+              if (SET_ACL(fname, file) == 0)
-+                      updated = 1;
-+      }
-+
-       if (verbose > 1 && flags & PERMS_REPORT) {
-               enum logcode code = daemon_log_format_has_i || dry_run
-                                 ? FCLIENT : FINFO;
---- orig/rsync.h       2005-05-03 17:11:01
-+++ rsync.h    2004-07-03 20:11:58
-@@ -638,6 +638,40 @@ struct stats {
- #include "lib/permstring.h"
- #include "lib/addrinfo.h"
++#ifdef SUPPORT_ACLS
++      /* It's OK to call set_acl() now, even for a dir, as the generator
++       * will enable owner-writability using chmod, if necessary. */
++      if (set_acl(fname, file) == 0)
++              updated = 1;
++#endif
++
+ #ifdef HAVE_CHMOD
+       if ((st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS)) {
+               int ret = do_chmod(fname, file->mode);
+--- old/rsync.h
++++ new/rsync.h
+@@ -658,6 +658,20 @@ struct chmod_mode_struct;
+ #define UNUSED(x) x __attribute__((__unused__))
  
-+#define SUPPORT_ACLS HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
-+              HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
++#if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
++    HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
++#define SUPPORT_ACLS 1
++#endif
 +
-+#define ACLS_NEED_MASK HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
++#if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
++#define ACLS_NEED_MASK 1
++#endif
 +
-+#if SUPPORT_ACLS
-+#if HAVE_SYS_ACL_H
++#if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
 +#include <sys/acl.h>
 +#endif
-+#define MAKE_ACL(file, fname)                 make_acl(file, fname)
-+#define SEND_ACL(file, f)                     send_acl(file, f)
-+#define RECEIVE_ACL(file, f)                  receive_acl(file, f)
-+#define SORT_FILE_ACL_INDEX_LISTS()           sort_file_acl_index_lists()
-+#define SET_ACL(fname, file)                  set_acl(fname, file)
-+#define NEXT_ACL_UID()                                next_acl_uid()
-+#define ACL_UID_MAP(uid)                      acl_uid_map(uid)
-+#define PUSH_KEEP_BACKUP_ACL(file, orig, dest) \
-+                                      push_keep_backup_acl(file, orig, dest)
-+#define CLEANUP_KEEP_BACKUP_ACL()             cleanup_keep_backup_acl()
-+#define DUP_ACL(orig, dest, mode)             dup_acl(orig, dest, mode)
-+#else /* SUPPORT_ACLS */
-+#define MAKE_ACL(file, fname)                 1 /* checked return value */
-+#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 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 */
-+#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 16:14:33
-+++ rsync.yo   2004-07-03 20:11:58
-@@ -317,6 +317,7 @@ to the detailed description below for a 
+--- old/rsync.yo
++++ new/rsync.yo
+@@ -321,6 +321,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).
+@@ -742,7 +743,9 @@ quote(itemize(
+   permissions, though the bf(--executability) option might change just
+   the execute permission for the file.
+   it() New files get their "normal" permission bits set to the source
+-  file's permissions masked with the receiving end's umask setting, and
++  file's permissions masked with the receiving directory's default
++  permissions (either the receiving process's umask, or the permissions
++  specified via the destination directory's default ACL), and
+   their special permission bits disabled except in the case where a new
+   directory inherits a setgid bit from its parent directory.
+ ))
+@@ -773,9 +776,11 @@ The preservation of the destination's se
+ directories when bf(--perms) is off was added in rsync 2.6.7.  Older rsync
+ versions erroneously preserved the three special permission bits for
+ newly-created files when bf(--perms) was off, while overriding the
+-destination's setgid bit setting on a newly-created directory.  (Keep in
+-mind that it is the version of the receiving rsync that affects this
+-behavior.)
++destination's setgid bit setting on a newly-created directory.  Default ACL
++observance was added to the ACL patch for rsync 2.6.7, so older (or
++non-ACL-enabled) rsyncs use the umask even if default ACLs are present.
++(Keep in mind that it is the version of the receiving rsync that affects
++these behaviors.)
+ dit(bf(-E, --executability)) This option causes rsync to preserve the
+ executability (or non-executability) of regular files when bf(--perms) is
+@@ -793,6 +798,10 @@ quote(itemize(
  
-+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
+ 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
+--- old/smb_acls.h
++++ new/smb_acls.h
 @@ -0,0 +1,277 @@
 +/* 
 +   Unix SMB/Netbios implementation.
@@ -4797,7 +5038,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +#ifndef _SMB_ACLS_H
 +#define _SMB_ACLS_H
 +
-+#if defined(HAVE_POSIX_ACLS)
++#if defined HAVE_POSIX_ACLS
 +
 +/* This is an identity mapping (just remove the SMB_). */
 +
@@ -4827,7 +5068,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +#define SMB_ACL_TYPE_ACCESS   ACL_TYPE_ACCESS
 +#define SMB_ACL_TYPE_DEFAULT  ACL_TYPE_DEFAULT
 +
-+#elif defined(HAVE_TRU64_ACLS)
++#elif defined HAVE_TRU64_ACLS
 +
 +/* This is for DEC/Compaq Tru64 UNIX */
 +
@@ -4857,7 +5098,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +#define SMB_ACL_TYPE_ACCESS   ACL_TYPE_ACCESS
 +#define SMB_ACL_TYPE_DEFAULT  ACL_TYPE_DEFAULT
 +
-+#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)
++#elif defined HAVE_UNIXWARE_ACLS || defined HAVE_SOLARIS_ACLS
 +/*
 + * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX.
 + * Modified by Toomas Soome <tsoome@ut.ee> for Solaris.
@@ -4895,7 +5136,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +#define SMB_ACL_TYPE_ACCESS   0
 +#define SMB_ACL_TYPE_DEFAULT  1
 +
-+#elif defined(HAVE_HPUX_ACLS)
++#elif defined HAVE_HPUX_ACLS
 +
 +/*
 + * Based on the Solaris & UnixWare code.
@@ -4936,7 +5177,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +#define SMB_ACL_TYPE_ACCESS   0
 +#define SMB_ACL_TYPE_DEFAULT  1
 +
-+#elif defined(HAVE_IRIX_ACLS)
++#elif defined HAVE_IRIX_ACLS
 +
 +#define SMB_ACL_TAG_T         acl_tag_t
 +#define SMB_ACL_TYPE_T                acl_type_t
@@ -4968,7 +5209,7 @@ ACLs to a non-ACL-supporting disk should complain.
 +#define SMB_ACL_TYPE_ACCESS   ACL_TYPE_ACCESS
 +#define SMB_ACL_TYPE_DEFAULT  ACL_TYPE_DEFAULT
 +
-+#elif defined(HAVE_AIX_ACLS)
++#elif defined HAVE_AIX_ACLS
 +
 +/* Donated by Medha Date, mdate@austin.ibm.com, for IBM */
 +
@@ -5050,8 +5291,66 @@ 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
+--- old/testsuite/default-acls.test
++++ new/testsuite/default-acls.test
+@@ -0,0 +1,55 @@
++#! /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
++
++$RSYNC --version | grep ", ACLs" >/dev/null || test_skipped "Rsync is configured without ACL support"
++setfacl -dm u::rwx,g::---,o::--- "$scratchdir" || test_skipped "Your filesystem has ACLs disabled"
++
++# Call as: testit <dirname> <default-acl> <file-expected> <program-expected>
++testit() {
++    todir="$scratchdir/$1"
++    mkdir "$todir"
++    # FIXME This doesn't work on solaris...
++    setfacl -k "$todir"
++    [ "$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/dir" "$scratchdir/file" "$scratchdir/program" "$todir/to/"
++    check_perms "$todir/to" $4 "Target $1"
++    check_perms "$todir/to/dir" $4 "Target $1"
++    check_perms "$todir/to/file" $3 "Target $1"
++    check_perms "$todir/to/program" $4 "Target $1"
++    # Make sure get_local_name doesn't mess us up when transferring only one file
++    $RSYNC -rvv "$scratchdir/file" "$todir/to/anotherfile"
++    check_perms "$todir/to/anotherfile" $3 "Target $1"
++    # Make sure we obey default ACLs when not transferring a regular file
++    $RSYNC -rvv "$scratchdir/dir/" "$todir/to/anotherdir/"
++    check_perms "$todir/to/anotherdir" $4 "Target $1"
++}
++
++mkdir "$scratchdir/dir"
++echo "File!" >"$scratchdir/file"
++echo "#!/bin/sh" >"$scratchdir/program"
++chmod 777 "$scratchdir/dir"
++chmod 666 "$scratchdir/file"
++chmod 777 "$scratchdir/program"
++
++# Test some target directories
++umask 0077
++testit da777 u::rwx,g::rwx,o::rwx rw-rw-rw- rwxrwxrwx
++testit da775 u::rwx,g::rwx,o::r-x rw-rw-r-- rwxrwxr-x
++testit da750 u::rwx,g::r-x,o::--- rw-r----- rwxr-x---
++testit da770mask u::rwx,g::---,m::rwx,o::--- rw-rw---- rwxrwx---
++testit noda1 '' rw------- rwx------
++umask 0000
++testit noda2 '' rw-rw-rw- rwxrwxrwx
++umask 0022
++testit noda3 '' rw-r--r-- rwxr-xr-x
++
++# Hooray
++exit 0
+--- old/uidlist.c
++++ new/uidlist.c
 @@ -34,6 +34,7 @@
  extern int verbose;
  extern int preserve_uid;
@@ -5087,31 +5386,31 @@ 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
                }
        }
  
-+#if SUPPORT_ACLS
++#ifdef SUPPORT_ACLS
 +      if (preserve_acls && !numeric_ids) {
 +              id_t id;
-+              /* the enumerations don't return 0 except to flag the last
-+               * entry, since uidlist doesn't munge 0 anyway */
-+              while ((id = next_acl_uid(flist)))
++              /* The enumerations don't return 0 except to flag the last
++               * entry, since uidlist doesn't munge 0 anyway. */
++              while ((id = next_acl_uid(flist)) != 0)
 +                      acl_uid_map(match_uid(id));
-+              while ((id = next_acl_gid(flist)))
++              while ((id = next_acl_gid(flist)) != 0)
 +                      acl_gid_map(match_gid(id));
 +      }
 +#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++)