summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/proto.h6
-rw-r--r--source3/lib/util_sid.c16
-rw-r--r--source3/lib/util_str.c7
-rw-r--r--source3/lib/util_uuid.c4
-rw-r--r--source3/libads/ldap_schema.c4
-rw-r--r--source3/winbindd/idmap_ad.c8
-rw-r--r--source3/winbindd/winbindd_ads.c14
7 files changed, 30 insertions, 29 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 342c1432eb..2217b3315b 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -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 */
diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c
index 97284afae7..9e5d4d38a5 100644
--- a/source3/lib/util_sid.c
+++ b/source3/lib/util_sid.c
@@ -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;
}
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 3a941f2c21..cdd7d0a300 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -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];
diff --git a/source3/lib/util_uuid.c b/source3/lib/util_uuid.c
index c681b66d34..656ba2a57c 100644
--- a/source3/lib/util_uuid.c
+++ b/source3/lib/util_uuid.c
@@ -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);
}
diff --git a/source3/libads/ldap_schema.c b/source3/libads/ldap_schema.c
index b5d2d35889..a841fbdca8 100644
--- a/source3/libads/ldap_schema.c
+++ b/source3/libads/ldap_schema.c
@@ -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;
diff --git a/source3/winbindd/idmap_ad.c b/source3/winbindd/idmap_ad.c
index 5c29ba0b22..3791a86876 100644
--- a/source3/winbindd/idmap_ad.c
+++ b/source3/winbindd/idmap_ad.c
@@ -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;
diff --git a/source3/winbindd/winbindd_ads.c b/source3/winbindd/winbindd_ads.c
index dcf5623d29..0f40419a0e 100644
--- a/source3/winbindd/winbindd_ads.c
+++ b/source3/winbindd/winbindd_ads.c
@@ -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;