Make sid_binstring & friends take a talloc context
authorVolker Lendecke <vl@samba.org>
Thu, 28 May 2009 09:18:22 +0000 (11:18 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 28 May 2009 09:33:21 +0000 (11:33 +0200)
source3/include/proto.h
source3/lib/util_sid.c
source3/lib/util_str.c
source3/lib/util_uuid.c
source3/libads/ldap_schema.c
source3/winbindd/idmap_ad.c
source3/winbindd/winbindd_ads.c

index 342c1432eb336dbf620b135401e57353b3f2eb0b..2217b3315bf933a5b6a241a76c4e8e1064e06748 100644 (file)
@@ -1298,7 +1298,7 @@ int sid_compare(const DOM_SID *sid1, const DOM_SID *sid2);
 int sid_compare_domain(const DOM_SID *sid1, const DOM_SID *sid2);
 bool sid_equal(const DOM_SID *sid1, const DOM_SID *sid2);
 bool non_mappable_sid(DOM_SID *sid);
-char *sid_binstring(const DOM_SID *sid);
+char *sid_binstring(TALLOC_CTX *mem_ctx, const DOM_SID *sid);
 char *sid_binstring_hex(const DOM_SID *sid);
 DOM_SID *sid_dup_talloc(TALLOC_CTX *ctx, const DOM_SID *src);
 NTSTATUS add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
@@ -1502,7 +1502,7 @@ void strupper_m(char *s);
 size_t strlen_m(const char *s);
 size_t strlen_m_term(const char *s);
 size_t strlen_m_term_null(const char *s);
-char *binary_string_rfc2254(char *buf, int len);
+char *binary_string_rfc2254(TALLOC_CTX *mem_ctx, const uint8_t *buf, int len);
 char *binary_string(char *buf, int len);
 int fstr_sprintf(fstring s, const char *fmt, ...);
 bool str_list_sub_basic( char **list, const char *smb_name,
@@ -1595,7 +1595,7 @@ int islower_ascii(int c);
 
 void smb_uuid_pack(const struct GUID uu, UUID_FLAT *ptr);
 void smb_uuid_unpack(const UUID_FLAT in, struct GUID *uu);
-char *guid_binstring(const struct GUID *guid);
+char *guid_binstring(TALLOC_CTX *mem_ctx, const struct GUID *guid);
 
 /* The following definitions come from lib/version.c  */
 
index 97284afae743f39d44f9138db6787c6e6dcced01..9e5d4d38a569302fc8d901e95554b90546e55e47 100644 (file)
@@ -520,16 +520,18 @@ bool non_mappable_sid(DOM_SID *sid)
  Caller must free.
 *****************************************************************/
 
-char *sid_binstring(const DOM_SID *sid)
+char *sid_binstring(TALLOC_CTX *mem_ctx, const DOM_SID *sid)
 {
-       char *buf, *s;
+       uint8_t *buf;
+       char *s;
        int len = ndr_size_dom_sid(sid, NULL, 0);
-       buf = (char *)SMB_MALLOC(len);
-       if (!buf)
+       buf = talloc_array(mem_ctx, uint8_t, len);
+       if (!buf) {
                return NULL;
-       sid_linearize(buf, len, sid);
-       s = binary_string_rfc2254(buf, len);
-       free(buf);
+       }
+       sid_linearize((char *)buf, len, sid);
+       s = binary_string_rfc2254(mem_ctx, buf, len);
+       TALLOC_FREE(buf);
        return s;
 }
 
index 3a941f2c21c3efa5fc069ea8f92e76ee35e7fec5..cdd7d0a300e118768653191e62ba3dff7cb3f1a9 100644 (file)
@@ -1529,14 +1529,15 @@ size_t strlen_m_term_null(const char *s)
  Caller must free.
 **/
 
-char *binary_string_rfc2254(char *buf, int len)
+char *binary_string_rfc2254(TALLOC_CTX *mem_ctx, const uint8_t *buf, int len)
 {
        char *s;
        int i, j;
        const char *hex = "0123456789ABCDEF";
-       s = (char *)SMB_MALLOC(len * 3 + 1);
-       if (!s)
+       s = talloc_array(mem_ctx, char, len * 3 + 1);
+       if (s == NULL) {
                return NULL;
+       }
        for (j=i=0;i<len;i++) {
                s[j] = '\\';
                s[j+1] = hex[((unsigned char)buf[i]) >> 4];
index c681b66d34a7a5d827f9002e70ceae0d81889ec4..656ba2a57cb16bbed501ac949ddd145ea38945e9 100644 (file)
@@ -43,11 +43,11 @@ void smb_uuid_unpack(const UUID_FLAT in, struct GUID *uu)
  Caller must free.
 *****************************************************************/
 
-char *guid_binstring(const struct GUID *guid)
+char *guid_binstring(TALLOC_CTX *mem_ctx, const struct GUID *guid)
 {
        UUID_FLAT guid_flat;
 
        smb_uuid_pack(*guid, &guid_flat);
 
-       return binary_string_rfc2254((char *)guid_flat.info, UUID_FLAT_SIZE);
+       return binary_string_rfc2254(mem_ctx, guid_flat.info, UUID_FLAT_SIZE);
 }
index b5d2d35889e17d5c4402bdcee995c7c90de8ad14..a841fbdca816ba3b9c30cdcf2fc2d30ac38a4059 100644 (file)
@@ -122,7 +122,7 @@ const char *ads_get_attrname_by_guid(ADS_STRUCT *ads,
                goto done;
        }
 
-       guid_bin = guid_binstring(schema_guid);
+       guid_bin = guid_binstring(mem_ctx, schema_guid);
        if (!guid_bin) {
                goto done;
        }
@@ -145,7 +145,7 @@ const char *ads_get_attrname_by_guid(ADS_STRUCT *ads,
        result = ads_pull_string(ads, mem_ctx, res, "lDAPDisplayName");
 
  done:
-       SAFE_FREE(guid_bin);
+       TALLOC_FREE(guid_bin);
        ads_msgfree(ads, res);
        return result;
        
index 5c29ba0b223dfd9aa604aaa11a9038634b0e7549..3791a86876f9da33ca316ef74f59e7cc7444ded5 100644 (file)
@@ -570,10 +570,10 @@ again:
 
                ids[idx]->status = ID_UNKNOWN;
 
-               sidstr = sid_binstring(ids[idx]->sid);
+               sidstr = sid_binstring(talloc_tos(), ids[idx]->sid);
                filter = talloc_asprintf_append_buffer(filter, "(objectSid=%s)", sidstr);
                        
-               free(sidstr);
+               TALLOC_FREE(sidstr);
                CHECK_ALLOC_DONE(filter);
        }
        filter = talloc_asprintf_append_buffer(filter, "))");
@@ -894,9 +894,9 @@ static NTSTATUS nss_ad_get_info( struct nss_domain_entry *e,
        attrs[2] = ctx->ad_schema->posix_gecos_attr;
        attrs[3] = ctx->ad_schema->posix_gidnumber_attr;
 
-       sidstr = sid_binstring(sid);
+       sidstr = sid_binstring(mem_ctx, sid);
        filter = talloc_asprintf(mem_ctx, "(objectSid=%s)", sidstr);
-       SAFE_FREE(sidstr);
+       TALLOC_FREE(sidstr);
 
        if (!filter) {
                nt_status = NT_STATUS_NO_MEMORY;
index dcf5623d29aa353a5a64ab1710fc1c27731932e5..0f40419a0ec44a599ab385ee53b949eb3cc83c07 100644 (file)
@@ -524,14 +524,14 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
                goto done;
        }
 
-       sidstr = sid_binstring(sid);
+       sidstr = sid_binstring(talloc_tos(), sid);
        if (asprintf(&ldap_exp, "(objectSid=%s)", sidstr) == -1) {
                status = NT_STATUS_NO_MEMORY;
                goto done;
        }
        rc = ads_search_retry(ads, &msg, ldap_exp, attrs);
        free(ldap_exp);
-       free(sidstr);
+       TALLOC_FREE(sidstr);
        if (!ADS_ERR_OK(rc) || !msg) {
                DEBUG(1,("query_user(sid=%s) ads_search: %s\n",
                         sid_string_dbg(sid), ads_errstr(rc)));
@@ -1011,21 +1011,19 @@ static NTSTATUS lookup_groupmem(struct winbindd_domain *domain,
                goto done;
        }
 
-       if ((sidbinstr = sid_binstring(group_sid)) == NULL) {
+       if ((sidbinstr = sid_binstring(talloc_tos(), group_sid)) == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto done;
        }
 
        /* search for all members of the group */
-       if (!(ldap_exp = talloc_asprintf(tmp_ctx, "(objectSid=%s)",
-                                        sidbinstr)))
-       {
-               SAFE_FREE(sidbinstr);
+       ldap_exp = talloc_asprintf(tmp_ctx, "(objectSid=%s)", sidbinstr);
+       TALLOC_FREE(sidbinstr);
+       if (ldap_exp == NULL) {
                DEBUG(1, ("ads: lookup_groupmem: talloc_asprintf for ldap_exp failed!\n"));
                status = NT_STATUS_NO_MEMORY;
                goto done;
        }
-       SAFE_FREE(sidbinstr);
 
        args.control = ADS_EXTENDED_DN_OID;
        args.val = ADS_EXTENDED_DN_HEX_STRING;