From: Volker Lendecke Date: Thu, 14 Jan 2021 20:32:21 +0000 (+0100) Subject: libsmb: Simplify sec_desc_parse() X-Git-Tag: tevent-0.11.0~2006 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fa00ac31a86cb43af05fa7f3f0bb15c13af44f8;p=thirdparty%2Fsamba.git libsmb: Simplify sec_desc_parse() Avoid CALLOC for just one struct dom_sids Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c index 0751c65d58a..81365eef039 100644 --- a/source3/libsmb/libsmb_xattr.c +++ b/source3/libsmb/libsmb_xattr.c @@ -428,8 +428,9 @@ sec_desc_parse(TALLOC_CTX *ctx, char *tok; struct security_descriptor *ret = NULL; size_t sd_size; - struct dom_sid *group_sid=NULL; - struct dom_sid *owner_sid=NULL; + struct dom_sid owner_sid = { .num_auths = 0 }; + struct dom_sid group_sid = { .num_auths = 0 }; + bool have_owner = false, have_group = false; struct security_acl *dacl=NULL; int revision=1; @@ -441,66 +442,62 @@ sec_desc_parse(TALLOC_CTX *ctx, } if (strncasecmp_m(tok,"OWNER:", 6) == 0) { - if (owner_sid) { + if (have_owner) { DEBUG(5,("OWNER specified more than once!\n")); goto done; } - owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1); - if (!owner_sid || - !convert_string_to_sid(ipc_cli, pol, + if (!convert_string_to_sid(ipc_cli, pol, numeric, - owner_sid, tok+6)) { + &owner_sid, tok+6)) { DEBUG(5, ("Failed to parse owner sid\n")); goto done; } + have_owner = true; continue; } if (strncasecmp_m(tok,"OWNER+:", 7) == 0) { - if (owner_sid) { + if (have_owner) { DEBUG(5,("OWNER specified more than once!\n")); goto done; } - owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1); - if (!owner_sid || - !convert_string_to_sid(ipc_cli, pol, + if (!convert_string_to_sid(ipc_cli, pol, False, - owner_sid, tok+7)) { + &owner_sid, tok+7)) { DEBUG(5, ("Failed to parse owner sid\n")); goto done; } + have_owner = true; continue; } if (strncasecmp_m(tok,"GROUP:", 6) == 0) { - if (group_sid) { + if (have_group) { DEBUG(5,("GROUP specified more than once!\n")); goto done; } - group_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1); - if (!group_sid || - !convert_string_to_sid(ipc_cli, pol, + if (!convert_string_to_sid(ipc_cli, pol, numeric, - group_sid, tok+6)) { + &group_sid, tok+6)) { DEBUG(5, ("Failed to parse group sid\n")); goto done; } + have_group = true; continue; } if (strncasecmp_m(tok,"GROUP+:", 7) == 0) { - if (group_sid) { + if (have_group) { DEBUG(5,("GROUP specified more than once!\n")); goto done; } - group_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1); - if (!group_sid || - !convert_string_to_sid(ipc_cli, pol, + if (!convert_string_to_sid(ipc_cli, pol, False, - group_sid, tok+6)) { + &group_sid, tok+6)) { DEBUG(5, ("Failed to parse group sid\n")); goto done; } + have_group = true; continue; } @@ -534,12 +531,17 @@ sec_desc_parse(TALLOC_CTX *ctx, goto done; } - ret = make_sec_desc(ctx, revision, SEC_DESC_SELF_RELATIVE, - owner_sid, group_sid, NULL, dacl, &sd_size); + ret = make_sec_desc( + ctx, + revision, + SEC_DESC_SELF_RELATIVE, + have_owner ? &owner_sid : NULL, + have_group ? &group_sid : NULL, + NULL, + dacl, + &sd_size); done: - SAFE_FREE(group_sid); - SAFE_FREE(owner_sid); return ret; }