Updated patches to work with the current trunk.
[rsync/rsync-patches.git] / adaptec_acl_mods.diff
index f9988e7..eaa1ed2 100644 (file)
-Depends-On-Patch: acls.diff
-
-After applying the above patch and this one, run these commands for a
-successful build:
+To use this patch, run these commands for a successful build:
 
+    patch -p1 <patches/adaptec_acl_mods.diff
     ./prepare-source
     ./configure --enable-acl-support
     make
 
 Philip Lowman wrote:
-> Attached is a small patch which is meant to be applied to a copy of
-> rsync which has already been patched with acl support (the acls.diff
-> file in the patches folder).  It allows the preservation of the delete,
+> Attached is a small patch which allows the preservation of the delete,
 > chmod, and chown bits which Adaptec has added to XFS on their SnapOS NAS
 > units.  This is nice for backing up files between different NAS units
 > and preserving all of the Samba ACLs.
-> 
+>
 > I'm not sure how useful this patch will be because I'm not sure if any
 > other NAS vendors have standardized on their extensions to POSIX ACLs to
 > support Samba in the same manner that Adaptec has.  FWIW, though, this
 > will allow you to preserve acls when copying between different Adaptec
 > based NAS units running SnapOS.
 
-I (Wayne) tweaked the patch for style and to avoid using SMB_* constants
-with literal values were needed.
+I (Wayne) tweaked the patch to work with the latest source.
+
+Todo:
 
---- old/acls.c
-+++ new/acls.c
-@@ -30,9 +30,11 @@ extern int am_root;
- extern int dry_run;
- extern int orig_umask;
+Fix a bug that could lose some bits when stripping some (supposedly)
+superfluous ACL info.
+
+based-on: a01e3b490eb36ccf9e704840e1b6683dab867550
+diff --git a/lib/sysacls.c b/lib/sysacls.c
+--- a/lib/sysacls.c
++++ b/lib/sysacls.c
+@@ -31,6 +31,18 @@
+ #endif
+ #define DEBUG(x,y)
  
-+typedef unsigned short abits;
++/* These are custom ACL bits used by Adaptec's modifications
++ * to XFS on their SnapOS units. */
++#ifndef ACL_DELETE
++#define ACL_DELETE 8
++#endif
++#ifndef ACL_CHMOD
++#define ACL_CHMOD 16
++#endif
++#ifndef ACL_CHOWN
++#define ACL_CHOWN 32
++#endif
 +
- typedef struct {
-       id_t id;
--      uchar access;
-+      abits access;
- } id_access;
- typedef struct {
-@@ -41,15 +43,15 @@ typedef struct {
-       id_access *idas;
- } ida_list;
--#define NO_ENTRY ((uchar)0x80)
-+#define NO_ENTRY ((abits)0x8000)
- typedef struct {
-       ida_list users;
-       ida_list groups;
-       /* These will be NO_ENTRY if there's no such entry. */
--      uchar user_obj;
--      uchar group_obj;
--      uchar mask;
--      uchar other;
-+      abits user_obj;
-+      abits group_obj;
-+      abits mask;
-+      abits other;
- } rsync_acl;
- static const rsync_acl rsync_acl_initializer =
-@@ -148,7 +150,7 @@ static BOOL unpack_smb_acl(rsync_acl *ra
-            rc = sys_acl_get_entry(sacl, SMB_ACL_NEXT_ENTRY, &entry)) {
-               SMB_ACL_TAG_T tag_type;
-               SMB_ACL_PERMSET_T permset;
--              uchar access;
-+              abits access;
-               void *qualifier;
-               id_access *ida;
-               ida_list *idal;
-@@ -162,6 +164,9 @@ static BOOL unpack_smb_acl(rsync_acl *ra
-               }
-               access = (sys_acl_get_perm(permset, SMB_ACL_READ) ? 4 : 0)
-                      | (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? 2 : 0)
-+                     | (sys_acl_get_perm(permset, SMB_ACL_DELETE) ? 8 : 0)
-+                     | (sys_acl_get_perm(permset, SMB_ACL_CHMOD) ? 16 : 0)
-+                     | (sys_acl_get_perm(permset, SMB_ACL_CHOWN) ? 32 : 0)
-                      | (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? 1 : 0);
-               /* continue == done with entry; break == store in given idal */
-               switch (tag_type) {
-@@ -559,13 +564,19 @@ static void expand_smb_acl_list(smb_acl_
- #define COE(func,args) CALL_OR_ERROR(func,args,#func)
- #define COE2(func,args) CALL_OR_ERROR(func,args,NULL)
--static int store_access_in_entry(uchar access, SMB_ACL_ENTRY_T entry)
-+static int store_access_in_entry(abits access, SMB_ACL_ENTRY_T entry)
+ void SAFE_FREE(void *mem)
  {
-       const char *errfun = NULL;
-       SMB_ACL_PERMSET_T permset;
+       if (mem)
+@@ -100,6 +112,9 @@ int sys_acl_get_info(SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T *tag_type_p, uint32 *b
+               return -1;
  
-       COE( sys_acl_get_permset,(entry, &permset) );
-       COE( sys_acl_clear_perms,(permset) );
-+      if (access & 32)
-+              COE( sys_acl_add_perm(permset, SMB_ACL_CHOWN) );
-+      if (access & 16)
-+              COE( sys_acl_add_perm(permset, SMB_ACL_CHMOD) );
-+      if (access & 8)
-+              COE( sys_acl_add_perm(permset, SMB_ACL_DELETE) );
-       if (access & 4)
-               COE( sys_acl_add_perm,(permset, SMB_ACL_READ) );
-       if (access & 2)
-@@ -645,7 +656,7 @@ static BOOL pack_smb_acl(SMB_ACL_T *smb_
-       return False;
- }
+       *bits_p = (acl_get_perm(permset, ACL_READ) ? 4 : 0)
++              | (acl_get_perm(permset, ACL_CHOWN) ? 32 : 0)
++              | (acl_get_perm(permset, ACL_CHMOD) ? 16 : 0)
++              | (acl_get_perm(permset, ACL_DELETE) ? 8 : 0)
+               | (acl_get_perm(permset, ACL_WRITE) ? 2 : 0)
+               | (acl_get_perm(permset, ACL_EXECUTE) ? 1 : 0);
  
--static mode_t change_sacl_perms(SMB_ACL_T sacl, uchar mask, mode_t old_mode, mode_t mode)
-+static mode_t change_sacl_perms(SMB_ACL_T sacl, abits mask, mode_t old_mode, mode_t mode)
- {
-       SMB_ACL_ENTRY_T entry;
-       int group_id = mask != NO_ENTRY ? SMB_ACL_MASK : SMB_ACL_GROUP_OBJ;
-@@ -696,7 +707,7 @@ static mode_t change_sacl_perms(SMB_ACL_
+@@ -144,6 +159,12 @@ int sys_acl_set_access_bits(SMB_ACL_ENTRY_T entry, uint32 bits)
+       if ((rc = acl_get_permset(entry, &permset)) != 0)
+               return rc;
+       acl_clear_perms(permset);
++      if (bits & 32)
++              acl_add_perm(permset, ACL_CHOWN);
++      if (bits & 16)
++              acl_add_perm(permset, ACL_CHMOD);
++      if (bits & 8)
++              acl_add_perm(permset, ACL_DELETE);
+       if (bits & 4)
+               acl_add_perm(permset, ACL_READ);
+       if (bits & 2)
+diff --git a/lib/sysacls.h b/lib/sysacls.h
+--- a/lib/sysacls.h
++++ b/lib/sysacls.h
+@@ -59,8 +59,8 @@
+ #define SMB_ACL_TYPE_ACCESS   ACL_TYPE_ACCESS
+ #define SMB_ACL_TYPE_DEFAULT  ACL_TYPE_DEFAULT
  
- static void receive_rsync_acl(rsync_acl *racl, int f)
- {
--      uchar computed_mask_bits = 0;
-+      abits computed_mask_bits = 0;
-       ida_list *idal = NULL;
-       id_access *ida;
-       size_t count;
-@@ -708,8 +719,8 @@ static void receive_rsync_acl(rsync_acl 
+-#define SMB_ACL_VALID_NAME_BITS       (4 | 2 | 1)
+-#define SMB_ACL_VALID_OBJ_BITS        (4 | 2 | 1)
++#define SMB_ACL_VALID_NAME_BITS       (32 | 16 | 8 | 4 | 2 | 1)
++#define SMB_ACL_VALID_OBJ_BITS        (32 | 16 | 8 | 4 | 2 | 1)
  
-       while (count--) {
-               char tag = read_byte(f);
--              uchar access = read_byte(f);
--              if (access & ~ (4 | 2 | 1)) {
-+              abits access = read_byte(f);
-+              if (access & ~(32 | 16 | 8 | 4 | 2 | 1)) {
-                       rprintf(FERROR, "receive_rsync_acl: bogus permset %o\n",
-                               access);
-                       exit_cleanup(RERR_STREAMIO);
---- old/smb_acls.h
-+++ new/smb_acls.h
-@@ -33,6 +33,11 @@
- #define SMB_ACL_READ          ACL_READ
- #define SMB_ACL_WRITE         ACL_WRITE
- #define SMB_ACL_EXECUTE               ACL_EXECUTE
-+/* These are custom ACL bits used by Adaptec's modifications
-+ * to XFS on their SnapOS units. */
-+#define SMB_ACL_DELETE                0x08
-+#define SMB_ACL_CHMOD         0x10
-+#define SMB_ACL_CHOWN         0x20
+ #define SMB_ACL_NEED_SORT
  
- /* Types of ACLs. */
- #define SMB_ACL_USER          ACL_USER