lib: Make sid_binstring_hex use TALLOC
authorVolker Lendecke <vl@samba.org>
Fri, 8 May 2015 10:06:23 +0000 (10:06 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 12 May 2015 23:44:20 +0000 (01:44 +0200)
talloc_tos() is better than plain malloc...

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/proto.h
source3/lib/util_sid.c
source3/libads/ldap_utils.c

index 815c8646b8b99ce45d72eb8deae0d793c6a558ff..dad4dd9dac9b90f3d95c0eaf1584b85c5fdf12af 100644 (file)
@@ -524,7 +524,7 @@ char *sid_string_dbg(const struct dom_sid *sid);
 char *sid_string_tos(const struct dom_sid *sid);
 bool sid_linearize(char *outbuf, size_t len, const struct dom_sid *sid);
 bool non_mappable_sid(struct dom_sid *sid);
-char *sid_binstring_hex(const struct dom_sid *sid);
+char *sid_binstring_hex_talloc(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
 struct netr_SamInfo3;
 NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx,
                              const struct netr_SamInfo3 *info3,
index 55904d7106370008c1278bed43eeb616e4dfee75..e336510ae403890c22c092a4beb548af387cb381 100644 (file)
@@ -113,14 +113,12 @@ bool non_mappable_sid(struct dom_sid *sid)
  Caller must free.
 *****************************************************************/
 
-char *sid_binstring_hex(const struct dom_sid *sid)
+char *sid_binstring_hex_talloc(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
 {
-       char *s;
        int len = ndr_size_dom_sid(sid, 0);
        char buf[len];
        sid_linearize(buf, len, sid);
-       hex_encode((const unsigned char *)buf, len, &s);
-       return s;
+       return hex_encode_talloc(mem_ctx, (const unsigned char *)buf, len);
 }
 
 NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx,
index 117dc557e25ec2688c28afbf56aaad2a61b7e9aa..157f69454218bbd99900c95ea1205d888cc9cd0d 100644 (file)
@@ -214,20 +214,20 @@ static ADS_STATUS ads_do_search_retry_args(ADS_STRUCT *ads, const char *bind_pat
        char *dn, *sid_string;
        ADS_STATUS status;
 
-       sid_string = sid_binstring_hex(sid);
+       sid_string = sid_binstring_hex_talloc(talloc_tos(), sid);
        if (sid_string == NULL) {
                return ADS_ERROR(LDAP_NO_MEMORY);
        }
 
        if (!asprintf(&dn, "<SID=%s>", sid_string)) {
-               SAFE_FREE(sid_string);
+               TALLOC_FREE(sid_string);
                return ADS_ERROR(LDAP_NO_MEMORY);
        }
 
        status = ads_do_search_retry(ads, dn, LDAP_SCOPE_BASE,
                                   "(objectclass=*)", attrs, res);
        SAFE_FREE(dn);
-       SAFE_FREE(sid_string);
+       TALLOC_FREE(sid_string);
        return status;
 }