From: Volker Lendecke Date: Thu, 14 Jan 2021 20:33:13 +0000 (+0100) Subject: libsmb: Simplify add_ace() X-Git-Tag: tevent-0.11.0~2005 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4bbaee890416609add457aa9534152c61b3671d;p=thirdparty%2Fsamba.git libsmb: Simplify add_ace() Use ADD_TO_ARRAY() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c index 81365eef039..9a3a1210ea1 100644 --- a/source3/libsmb/libsmb_xattr.c +++ b/source3/libsmb/libsmb_xattr.c @@ -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; }