]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libsmb: Simplify add_ace()
authorVolker Lendecke <vl@samba.org>
Thu, 14 Jan 2021 20:33:13 +0000 (21:33 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 22 Jan 2021 19:54:38 +0000 (19:54 +0000)
Use ADD_TO_ARRAY()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/libsmb/libsmb_xattr.c

index 81365eef0390de1bbff803fa6aee7c3bdf049796..9a3a1210ea159496d5ca5edca0ab54fc03fc51a5 100644 (file)
@@ -391,27 +391,24 @@ done:
 /* add an struct security_ace to a list of struct security_aces in a struct security_acl */
 static bool
 add_ace(struct security_acl **the_acl,
-        struct security_ace *ace,
+        const struct security_ace *ace,
         TALLOC_CTX *ctx)
 {
-       struct security_acl *newacl;
-       struct security_ace *aces;
+       struct security_acl *acl = *the_acl;
 
-       if (! *the_acl) {
-               (*the_acl) = make_sec_acl(ctx, 3, 1, ace);
-               return True;
+       if (acl == NULL) {
+               acl = make_sec_acl(ctx, 3, 0, NULL);
+               if (acl == NULL) {
+                       return false;
+               }
        }
 
-       if ((aces = SMB_CALLOC_ARRAY(struct security_ace,
-                                     1+(*the_acl)->num_aces)) == NULL) {
-               return False;
+       if (acl->num_aces == UINT32_MAX) {
+               return false;
        }
-       memcpy(aces, (*the_acl)->aces, (*the_acl)->num_aces * sizeof(struct security_ace));
-       memcpy(aces+(*the_acl)->num_aces, ace, sizeof(struct security_ace));
-       newacl = make_sec_acl(ctx, (*the_acl)->revision,
-                              1+(*the_acl)->num_aces, aces);
-       SAFE_FREE(aces);
-       (*the_acl) = newacl;
+       ADD_TO_ARRAY(
+               acl, struct security_ace, *ace, &acl->aces, &acl->num_aces);
+       *the_acl = acl;
        return True;
 }