]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
sharesec: Simplify add_ace()
authorVolker Lendecke <vl@samba.org>
Thu, 14 Jan 2021 20:52:51 +0000 (21:52 +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/utils/sharesec.c

index 97ff0cfc9c5e7923248b07934885174b10e07314..19841cc5a13f5931b688f3273c2f4869020aa644 100644 (file)
@@ -90,21 +90,21 @@ static struct security_descriptor* parse_acl_string(TALLOC_CTX *mem_ctx, const c
 /* add an ACE to a list of ACEs in a struct security_acl */
 static bool add_ace(TALLOC_CTX *mem_ctx, struct security_acl **the_acl, struct security_ace *ace)
 {
-       struct security_acl *new_ace;
-       struct security_ace *aces;
-       if (! *the_acl) {
-               return (((*the_acl) = make_sec_acl(mem_ctx, 3, 1, ace)) != NULL);
+       struct security_acl *acl = *the_acl;
+
+       if (acl == NULL) {
+               acl = make_sec_acl(mem_ctx, 3, 1, ace);
+               if (acl == NULL) {
+                       return false;
+               }
        }
 
-       if (!(aces = SMB_CALLOC_ARRAY(struct security_ace, 1+(*the_acl)->num_aces))) {
-               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));
-       new_ace = make_sec_acl(mem_ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
-       SAFE_FREE(aces);
-       (*the_acl) = new_ace;
+       ADD_TO_ARRAY(
+               acl, struct security_ace, *ace, &acl->aces, &acl->num_aces);
+       *the_acl = acl;
        return True;
 }