This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] setfacl(1): Fix handling of -m and -x on a single commandline


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=bb231f6a62b073f4bde5a712b135758d929c9efd

commit bb231f6a62b073f4bde5a712b135758d929c9efd
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Mon Dec 21 18:15:57 2015 +0100

    setfacl(1): Fix handling of -m and -x on a single commandline
    
            * setfacl.cc (delace): New helper function to delete a single ACE.
            (delacl): Call delace.
            (modacl): Ditto, if entry is supposed to get deleted.  Align comments.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/utils/ChangeLog |  6 ++++++
 winsup/utils/setfacl.c | 31 ++++++++++++++++++++++---------
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index 43b4638..9078823 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,5 +1,11 @@
 2015-12-21  Corinna Vinschen  <corinna@vinschen.de>
 
+	* setfacl.cc (delace): New helper function to delete a single ACE.
+	(delacl): Call delace.
+	(modacl): Ditto, if entry is supposed to get deleted.  Align comments.
+
+2015-12-21  Corinna Vinschen  <corinna@vinschen.de>
+
 	* setfacl.cc (modacl): Move recomputing mask into new function.
 	(check_got_mask): New function checking if mask is in input.
 	(recompute_mask): New function to recompute mask.
diff --git a/winsup/utils/setfacl.c b/winsup/utils/setfacl.c
index 75b5120..3169e63 100644
--- a/winsup/utils/setfacl.c
+++ b/winsup/utils/setfacl.c
@@ -242,6 +242,17 @@ searchace (aclent_t *aclp, int nentries, int type, int id)
 }
 
 int
+delace (aclent_t *tgt, int tcnt, int t)
+{
+  int i;
+
+  for (i = t + 1; i < tcnt; ++i)
+    tgt[i - 1] = tgt[i];
+  --tcnt;
+  return tcnt;
+}
+
+int
 delacl (aclent_t *tgt, int tcnt, aclent_t *src, int scnt)
 {
   int t, s, i;
@@ -253,11 +264,7 @@ delacl (aclent_t *tgt, int tcnt, aclent_t *src, int scnt)
       if (t < 0)
 	return -1;
       if (t < tcnt)
-	{
-	  for (i = t + 1; i < tcnt; ++i)
-	    tgt[i - 1] = tgt[i];
-	  --tcnt;
-	}
+	tcnt = delace (tgt, tcnt, t);
     }
   return tcnt;
 }
@@ -267,16 +274,22 @@ modacl (aclent_t *tgt, int tcnt, aclent_t *src, int scnt)
 {
   int t, s;
 
-  /* Replace or add given acl entries. */
+  /* Delete, replace or add given acl entries. */
   for (s = 0; s < scnt; ++s)
     {
       t = searchace (tgt, MAX_ACL_ENTRIES, src[s].a_type,
 		     (src[s].a_type & (USER | GROUP)) ? src[s].a_id : -1);
       if (t < 0)
 	return -1;
-      tgt[t] = src[s];
-      if (t >= tcnt)
-	++tcnt;
+      /* ILLEGAL_MODE means "delete". */
+      if (src[s].a_perm == ILLEGAL_MODE && t < tcnt)
+	tcnt = delace (tgt, tcnt, t);
+      else
+	{
+	  tgt[t] = src[s];
+	  if (t >= tcnt)
+	    ++tcnt;
+	}
     }
   return tcnt;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]