1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-03 01:18:10 +03:00

s3:libads Make ads_get_dn() take a talloc context

Also remove ads_memfree(), which was only ever a wrapper around
SAFE_FREE, used only to free the DN from ads_get_ds().

This actually makes libgpo more consistant, as it mixed a talloc and a
malloc based string on the same element.

Andrew Bartlett

Signed-off-by: Günther Deschner <gd@samba.org>
This commit is contained in:
Andrew Bartlett 2009-03-18 17:35:03 +11:00 committed by Günther Deschner
parent 9d9f945281
commit 2050187673
11 changed files with 58 additions and 71 deletions

View File

@ -3,7 +3,7 @@
*/
void ads_msgfree(ADS_STRUCT *ads, LDAPMessage *msg);
char *ads_get_dn(ADS_STRUCT *ads, LDAPMessage *msg);
char *ads_get_dn(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, LDAPMessage *msg);
char *ads_get_dn_canonical(ADS_STRUCT *ads, LDAPMessage *msg);
char *ads_pull_string(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, LDAPMessage *msg,

View File

@ -1266,23 +1266,13 @@ ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path,
ldap_msgfree(msg);
}
/**
* Free up memory from various ads requests
* @param ads connection to ads server
* @param mem Area to free
**/
void ads_memfree(ADS_STRUCT *ads, void *mem)
{
SAFE_FREE(mem);
}
/**
* Get a dn from search results
* @param ads connection to ads server
* @param msg Search result
* @return dn string
**/
char *ads_get_dn(ADS_STRUCT *ads, LDAPMessage *msg)
char *ads_get_dn(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, LDAPMessage *msg)
{
char *utf8_dn, *unix_dn;
size_t converted_size;
@ -1294,7 +1284,7 @@ void ads_memfree(ADS_STRUCT *ads, void *mem)
return NULL;
}
if (!pull_utf8_allocate(&unix_dn, utf8_dn, &converted_size)) {
if (!pull_utf8_talloc(mem_ctx, &unix_dn, utf8_dn, &converted_size)) {
DEBUG(0,("ads_get_dn: string conversion failure utf8 [%s]\n",
utf8_dn ));
return NULL;
@ -1639,7 +1629,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
}
/* substitute the bind-path from the well-known-guid-search result */
wkn_dn = ads_get_dn(ads, res);
wkn_dn = ads_get_dn(ads, NULL, res);
if (!wkn_dn) {
goto out;
}
@ -1685,7 +1675,7 @@ char *ads_default_ou_string(ADS_STRUCT *ads, const char *wknguid)
out:
SAFE_FREE(base);
ads_msgfree(ads, res);
ads_memfree(ads, wkn_dn);
TALLOC_FREE(wkn_dn);
if (wkn_dn_exp) {
ldap_value_free(wkn_dn_exp);
}
@ -1741,14 +1731,14 @@ uint32 ads_get_kvno(ADS_STRUCT *ads, const char *account_name)
return kvno;
}
dn_string = ads_get_dn(ads, res);
dn_string = ads_get_dn(ads, NULL, res);
if (!dn_string) {
DEBUG(0,("ads_get_kvno: out of memory.\n"));
ads_msgfree(ads, res);
return kvno;
}
DEBUG(5,("ads_get_kvno: Using: %s\n", dn_string));
ads_memfree(ads, dn_string);
TALLOC_FREE(dn_string);
/* ---------------------------------------------------------
* 0 is returned as a default KVNO from this point on...
@ -1836,14 +1826,14 @@ ADS_STATUS ads_clear_service_principal_names(ADS_STRUCT *ads, const char *machin
talloc_destroy(ctx);
return ret;
}
dn_string = ads_get_dn(ads, res);
dn_string = ads_get_dn(ads, NULL, res);
if (!dn_string) {
talloc_destroy(ctx);
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
}
ret = ads_gen_mod(ads, dn_string, mods);
ads_memfree(ads,dn_string);
TALLOC_FREE(dn_string);
if (!ADS_ERR_OK(ret)) {
DEBUG(1,("ads_clear_service_principal_names: Error: Updating Service Principals for machine %s in LDAP\n",
machine_name));
@ -1933,13 +1923,12 @@ ADS_STATUS ads_add_service_principal_name(ADS_STRUCT *ads, const char *machine_n
goto out;
}
if ( (dn_string = ads_get_dn(ads, res)) == NULL ) {
if ( (dn_string = ads_get_dn(ads, ctx, res)) == NULL ) {
ret = ADS_ERROR(LDAP_NO_MEMORY);
goto out;
}
ret = ads_gen_mod(ads, dn_string, mods);
ads_memfree(ads,dn_string);
if (!ADS_ERR_OK(ret)) {
DEBUG(1,("ads_add_service_principal_name: Error: Updating Service Principals in LDAP\n"));
goto out;
@ -2052,7 +2041,7 @@ ADS_STATUS ads_move_machine_acct(ADS_STRUCT *ads, const char *machine_name,
goto done;
}
computer_dn = ads_get_dn(ads, res);
computer_dn = ads_get_dn(ads, NULL, res);
if (!computer_dn) {
rc = ADS_ERROR(LDAP_NO_MEMORY);
goto done;
@ -3029,7 +3018,7 @@ ADS_STATUS ads_site_dn_for_machine(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, const c
return ADS_ERROR(LDAP_NO_SUCH_OBJECT);
}
dn = ads_get_dn(ads, res);
dn = ads_get_dn(ads, mem_ctx, res);
if (dn == NULL) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
@ -3039,18 +3028,18 @@ ADS_STATUS ads_site_dn_for_machine(ADS_STRUCT *ads, TALLOC_CTX *mem_ctx, const c
parent = ads_parent_dn(ads_parent_dn(ads_parent_dn(dn)));
if (parent == NULL) {
ads_msgfree(ads, res);
ads_memfree(ads, dn);
TALLOC_FREE(dn);
return ADS_ERROR(LDAP_NO_MEMORY);
}
*site_dn = talloc_strdup(mem_ctx, parent);
if (*site_dn == NULL) {
ads_msgfree(ads, res);
ads_memfree(ads, dn);
TALLOC_FREE(dn);
return ADS_ERROR(LDAP_NO_MEMORY);
}
ads_memfree(ads, dn);
TALLOC_FREE(dn);
ads_msgfree(ads, res);
return status;
@ -3140,7 +3129,7 @@ ADS_STATUS ads_get_joinable_ous(ADS_STRUCT *ads,
char *dn = NULL;
dn = ads_get_dn(ads, msg);
dn = ads_get_dn(ads, NULL, msg);
if (!dn) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
@ -3149,12 +3138,12 @@ ADS_STATUS ads_get_joinable_ous(ADS_STRUCT *ads,
if (!add_string_to_array(mem_ctx, dn,
(const char ***)ous,
(int *)num_ous)) {
ads_memfree(ads, dn);
TALLOC_FREE(dn);
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
}
ads_memfree(ads, dn);
TALLOC_FREE(dn);
}
ads_msgfree(ads, res);
@ -3494,7 +3483,7 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname)
return ADS_ERROR_SYSTEM(ENOENT);
}
hostnameDN = ads_get_dn(ads, (LDAPMessage *)msg);
hostnameDN = ads_get_dn(ads, NULL, (LDAPMessage *)msg);
rc = ldap_delete_ext_s(ads->ldap.ld, hostnameDN, pldap_control, NULL);
if (rc) {
@ -3516,7 +3505,7 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname)
if (!ADS_ERR_OK(status)) {
SAFE_FREE(host);
ads_memfree(ads, hostnameDN);
TALLOC_FREE(hostnameDN);
return status;
}
@ -3525,9 +3514,9 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname)
char *dn = NULL;
if ((dn = ads_get_dn(ads, msg_sub)) == NULL) {
if ((dn = ads_get_dn(ads, NULL, msg_sub)) == NULL) {
SAFE_FREE(host);
ads_memfree(ads, hostnameDN);
TALLOC_FREE(hostnameDN);
return ADS_ERROR(LDAP_NO_MEMORY);
}
@ -3535,12 +3524,12 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname)
if (!ADS_ERR_OK(status)) {
DEBUG(3,("failed to delete dn %s: %s\n", dn, ads_errstr(status)));
SAFE_FREE(host);
ads_memfree(ads, dn);
ads_memfree(ads, hostnameDN);
TALLOC_FREE(dn);
TALLOC_FREE(hostnameDN);
return status;
}
ads_memfree(ads, dn);
TALLOC_FREE(dn);
}
/* there should be no subordinate objects anymore */
@ -3550,7 +3539,7 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname)
if (!ADS_ERR_OK(status) || ( (ads_count_replies(ads, res)) > 0 ) ) {
SAFE_FREE(host);
ads_memfree(ads, hostnameDN);
TALLOC_FREE(hostnameDN);
return status;
}
@ -3559,12 +3548,12 @@ ADS_STATUS ads_leave_realm(ADS_STRUCT *ads, const char *hostname)
if (!ADS_ERR_OK(status)) {
SAFE_FREE(host);
DEBUG(3,("failed to delete dn %s: %s\n", hostnameDN, ads_errstr(status)));
ads_memfree(ads, hostnameDN);
TALLOC_FREE(hostnameDN);
return status;
}
}
ads_memfree(ads, hostnameDN);
TALLOC_FREE(hostnameDN);
status = ads_find_machine_acct(ads, &res, host);
if (ADS_ERR_OK(status) && ads_count_replies(ads, res) == 1) {
@ -3723,7 +3712,7 @@ ADS_STATUS ads_find_samaccount(ADS_STRUCT *ads,
goto out;
}
dn = ads_get_dn(ads, res);
dn = ads_get_dn(ads, NULL, res);
if (dn == NULL) {
status = ADS_ERROR(LDAP_NO_MEMORY);
goto out;
@ -3746,7 +3735,7 @@ ADS_STATUS ads_find_samaccount(ADS_STRUCT *ads,
}
}
out:
ads_memfree(ads, dn);
TALLOC_FREE(dn);
ads_msgfree(ads, res);
return status;

View File

@ -415,7 +415,7 @@ ADS_STATUS ads_delete_gpo_link(ADS_STRUCT *ads,
if (gpo_dn) {
gpo->ds_path = talloc_strdup(mem_ctx, gpo_dn);
} else {
gpo->ds_path = ads_get_dn(ads, res);
gpo->ds_path = ads_get_dn(ads, mem_ctx, res);
}
ADS_ERROR_HAVE_NO_MEMORY(gpo->ds_path);
@ -523,7 +523,7 @@ ADS_STATUS ads_get_gpo(ADS_STRUCT *ads,
return ADS_ERROR(LDAP_NO_SUCH_OBJECT);
}
dn = ads_get_dn(ads, res);
dn = ads_get_dn(ads, mem_ctx, res);
if (dn == NULL) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
@ -531,7 +531,7 @@ ADS_STATUS ads_get_gpo(ADS_STRUCT *ads,
status = ads_parse_gpo(ads, mem_ctx, res, dn, gpo);
ads_msgfree(ads, res);
ads_memfree(ads, dn);
TALLOC_FREE(dn);
return status;
}

View File

@ -303,7 +303,7 @@ static ADS_STATUS libnet_join_find_machine_acct(TALLOC_CTX *mem_ctx,
goto done;
}
dn = ads_get_dn(r->in.ads, res);
dn = ads_get_dn(r->in.ads, mem_ctx, res);
if (!dn) {
status = ADS_ERROR_LDAP(LDAP_NO_MEMORY);
goto done;
@ -317,7 +317,7 @@ static ADS_STATUS libnet_join_find_machine_acct(TALLOC_CTX *mem_ctx,
done:
ads_msgfree(r->in.ads, res);
ads_memfree(r->in.ads, dn);
TALLOC_FREE(dn);
return status;
}

View File

@ -3357,13 +3357,13 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
printer->info_2->sharename, global_myname());
if (ADS_ERR_OK(ads_rc) && res && ads_count_replies(ads, res)) {
prt_dn = ads_get_dn(ads, res);
prt_dn = ads_get_dn(ads, NULL, res);
if (!prt_dn) {
ads_msgfree(ads, res);
return WERR_NOMEM;
}
ads_rc = ads_del_dn(ads, prt_dn);
ads_memfree(ads, prt_dn);
TALLOC_FREE(prt_dn);
}
if (res) {

View File

@ -503,9 +503,9 @@ static int ads_user_add(struct net_context *c, int argc, const char **argv)
ads_msgfree(ads, res);
status=ads_find_user_acct(ads, &res, argv[0]);
if (ADS_ERR_OK(status)) {
userdn = ads_get_dn(ads, res);
userdn = ads_get_dn(ads, NULL, res);
ads_del_dn(ads, userdn);
ads_memfree(ads, userdn);
TALLOC_FREE(userdn);
}
done:
@ -598,10 +598,10 @@ static int ads_user_delete(struct net_context *c, int argc, const char **argv)
ads_destroy(&ads);
return -1;
}
userdn = ads_get_dn(ads, res);
userdn = ads_get_dn(ads, NULL, res);
ads_msgfree(ads, res);
rc = ads_del_dn(ads, userdn);
ads_memfree(ads, userdn);
TALLOC_FREE(userdn);
if (ADS_ERR_OK(rc)) {
d_printf("User %s deleted\n", argv[0]);
ads_destroy(&ads);
@ -757,10 +757,10 @@ static int ads_group_delete(struct net_context *c, int argc, const char **argv)
ads_destroy(&ads);
return -1;
}
groupdn = ads_get_dn(ads, res);
groupdn = ads_get_dn(ads, NULL, res);
ads_msgfree(ads, res);
rc = ads_del_dn(ads, groupdn);
ads_memfree(ads, groupdn);
TALLOC_FREE(groupdn);
if (ADS_ERR_OK(rc)) {
d_printf("Group %s deleted\n", argv[0]);
ads_destroy(&ads);
@ -1740,10 +1740,10 @@ static int net_ads_printer_remove(struct net_context *c, int argc, const char **
return -1;
}
prt_dn = ads_get_dn(ads, res);
prt_dn = ads_get_dn(ads, NULL, res);
ads_msgfree(ads, res);
rc = ads_del_dn(ads, prt_dn);
ads_memfree(ads, prt_dn);
TALLOC_FREE(prt_dn);
if (!ADS_ERR_OK(rc)) {
d_fprintf(stderr, "ads_del_dn: %s\n", ads_errstr(rc));

View File

@ -257,7 +257,7 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar
msg;
msg = ads_next_entry(ads, msg)) {
if ((dn = ads_get_dn(ads, msg)) == NULL) {
if ((dn = ads_get_dn(ads, mem_ctx, msg)) == NULL) {
goto out;
}
@ -266,18 +266,16 @@ static int net_ads_gpo_list_all(struct net_context *c, int argc, const char **ar
if (!ADS_ERR_OK(status)) {
d_printf("ads_parse_gpo failed: %s\n",
ads_errstr(status));
ads_memfree(ads, dn);
goto out;
}
dump_gpo(ads, mem_ctx, &gpo, 0);
ads_memfree(ads, dn);
}
out:
ads_msgfree(ads, res);
talloc_destroy(mem_ctx);
TALLOC_FREE(mem_ctx);
ads_destroy(&ads);
return 0;

View File

@ -592,11 +592,11 @@ done:
while (e) {
struct winbindd_tdc_domain *domain_rec;
dn = ads_get_dn(ads, e);
dn = ads_get_dn(ads, frame, e);
BAIL_ON_PTR_ERROR(dn, nt_status);
dns_domain = cell_dn_to_dns(dn);
SAFE_FREE(dn);
TALLOC_FREE(dn);
BAIL_ON_PTR_ERROR(dns_domain, nt_status);
domain_rec = wcache_tdc_fetch_domain(frame, dns_domain);
@ -666,13 +666,13 @@ static NTSTATUS get_object_account_name(ADS_STRUCT *ads,
/* get the name and domain */
dn = ads_get_dn(ads, msg);
dn = ads_get_dn(ads, frame, msg);
BAIL_ON_PTR_ERROR(dn, nt_status);
DEBUG(10,("get_object_account_name: dn = \"%s\"\n", dn));
dns_domain = cell_dn_to_dns(dn);
SAFE_FREE(dn);
TALLOC_FREE(dn);
BAIL_ON_PTR_ERROR(dns_domain, nt_status);
domain_rec = wcache_tdc_fetch_domain(frame, dns_domain);

View File

@ -400,10 +400,10 @@ done:
e!=NULL;
e = ads_next_entry(c->conn, e))
{
char *dn = ads_get_dn(c->conn, e);
char *dn = ads_get_dn(c->conn, NULL, e);
DEBUGADD(10,(" dn: %s\n", dn ? dn : "<NULL>"));
SAFE_FREE(dn);
TALLOC_FREE(dn);
}
}

View File

@ -368,7 +368,7 @@ static NTSTATUS check_result_unique_scoped(ADS_STRUCT **ads_list,
LDAPMessage *e = ads_first_entry(ads_list[i], msg_list[i]);
while (e) {
entry_dn = ads_get_dn(ads_list[i], e);
entry_dn = ads_get_dn(ads_list[i], NULL, e);
BAIL_ON_PTR_ERROR(entry_dn, nt_status);
if (check_forest_scope(entry_dn)) {
@ -389,7 +389,7 @@ static NTSTATUS check_result_unique_scoped(ADS_STRUCT **ads_list,
}
e = ads_next_entry(ads_list[i], e);
SAFE_FREE(entry_dn);
TALLOC_FREE(entry_dn);
}
}
@ -439,7 +439,7 @@ done:
}
talloc_destroy(frame);
SAFE_FREE(entry_dn);
TALLOC_FREE(entry_dn);
return nt_status;
}

View File

@ -865,7 +865,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
goto done;
}
user_dn = ads_get_dn(ads, msg);
user_dn = ads_get_dn(ads, mem_ctx, msg);
if (user_dn == NULL) {
status = NT_STATUS_NO_MEMORY;
goto done;
@ -942,7 +942,7 @@ static NTSTATUS lookup_usergroups(struct winbindd_domain *domain,
DEBUG(3,("ads lookup_usergroups (tokenGroups) succeeded for sid=%s\n",
sid_string_dbg(sid)));
done:
ads_memfree(ads, user_dn);
TALLOC_FREE(user_dn);
ads_msgfree(ads, msg);
return status;
}