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
-/**
- * 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
**/
/**
* 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;
{
char *utf8_dn, *unix_dn;
size_t converted_size;
- 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;
DEBUG(0,("ads_get_dn: string conversion failure utf8 [%s]\n",
utf8_dn ));
return NULL;
}
/* substitute the bind-path from the well-known-guid-search result */
}
/* 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;
}
if (!wkn_dn) {
goto out;
}
out:
SAFE_FREE(base);
ads_msgfree(ads, res);
out:
SAFE_FREE(base);
ads_msgfree(ads, res);
- ads_memfree(ads, wkn_dn);
if (wkn_dn_exp) {
ldap_value_free(wkn_dn_exp);
}
if (wkn_dn_exp) {
ldap_value_free(wkn_dn_exp);
}
- 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));
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...
/* ---------------------------------------------------------
* 0 is returned as a default KVNO from this point on...
talloc_destroy(ctx);
return ret;
}
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);
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));
if (!ADS_ERR_OK(ret)) {
DEBUG(1,("ads_clear_service_principal_names: Error: Updating Service Principals for machine %s in LDAP\n",
machine_name));
- 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);
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;
if (!ADS_ERR_OK(ret)) {
DEBUG(1,("ads_add_service_principal_name: Error: Updating Service Principals in LDAP\n"));
goto out;
- 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;
if (!computer_dn) {
rc = ADS_ERROR(LDAP_NO_MEMORY);
goto done;
return ADS_ERROR(LDAP_NO_SUCH_OBJECT);
}
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);
if (dn == NULL) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
parent = ads_parent_dn(ads_parent_dn(ads_parent_dn(dn)));
if (parent == NULL) {
ads_msgfree(ads, res);
parent = ads_parent_dn(ads_parent_dn(ads_parent_dn(dn)));
if (parent == NULL) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
}
*site_dn = talloc_strdup(mem_ctx, parent);
if (*site_dn == NULL) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
}
*site_dn = talloc_strdup(mem_ctx, parent);
if (*site_dn == NULL) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
}
return ADS_ERROR(LDAP_NO_MEMORY);
}
ads_msgfree(ads, res);
return status;
ads_msgfree(ads, res);
return status;
- 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);
if (!dn) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
if (!add_string_to_array(mem_ctx, dn,
(const char ***)ous,
(int *)num_ous)) {
if (!add_string_to_array(mem_ctx, dn,
(const char ***)ous,
(int *)num_ous)) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
}
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
}
return ADS_ERROR_SYSTEM(ENOENT);
}
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) {
rc = ldap_delete_ext_s(ads->ldap.ld, hostnameDN, pldap_control, NULL);
if (rc) {
if (!ADS_ERR_OK(status)) {
SAFE_FREE(host);
if (!ADS_ERR_OK(status)) {
SAFE_FREE(host);
- ads_memfree(ads, hostnameDN);
+ TALLOC_FREE(hostnameDN);
- if ((dn = ads_get_dn(ads, msg_sub)) == NULL) {
+ if ((dn = ads_get_dn(ads, NULL, msg_sub)) == NULL) {
- ads_memfree(ads, hostnameDN);
+ TALLOC_FREE(hostnameDN);
return ADS_ERROR(LDAP_NO_MEMORY);
}
return ADS_ERROR(LDAP_NO_MEMORY);
}
if (!ADS_ERR_OK(status)) {
DEBUG(3,("failed to delete dn %s: %s\n", dn, ads_errstr(status)));
SAFE_FREE(host);
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);
}
/* there should be no subordinate objects anymore */
}
/* there should be no subordinate objects anymore */
if (!ADS_ERR_OK(status) || ( (ads_count_replies(ads, res)) > 0 ) ) {
SAFE_FREE(host);
if (!ADS_ERR_OK(status) || ( (ads_count_replies(ads, res)) > 0 ) ) {
SAFE_FREE(host);
- ads_memfree(ads, hostnameDN);
+ TALLOC_FREE(hostnameDN);
if (!ADS_ERR_OK(status)) {
SAFE_FREE(host);
DEBUG(3,("failed to delete dn %s: %s\n", hostnameDN, ads_errstr(status)));
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);
- 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) {
status = ads_find_machine_acct(ads, &res, host);
if (ADS_ERR_OK(status) && ads_count_replies(ads, res) == 1) {
- dn = ads_get_dn(ads, res);
+ dn = ads_get_dn(ads, NULL, res);
if (dn == NULL) {
status = ADS_ERROR(LDAP_NO_MEMORY);
goto out;
if (dn == NULL) {
status = ADS_ERROR(LDAP_NO_MEMORY);
goto out;
ads_msgfree(ads, res);
return status;
ads_msgfree(ads, res);
return status;
if (gpo_dn) {
gpo->ds_path = talloc_strdup(mem_ctx, gpo_dn);
} else {
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);
}
ADS_ERROR_HAVE_NO_MEMORY(gpo->ds_path);
return ADS_ERROR(LDAP_NO_SUCH_OBJECT);
}
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);
if (dn == NULL) {
ads_msgfree(ads, res);
return ADS_ERROR(LDAP_NO_MEMORY);
status = ads_parse_gpo(ads, mem_ctx, res, dn, gpo);
ads_msgfree(ads, res);
status = ads_parse_gpo(ads, mem_ctx, res, dn, gpo);
ads_msgfree(ads, res);
- 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;
if (!dn) {
status = ADS_ERROR_LDAP(LDAP_NO_MEMORY);
goto done;
done:
ads_msgfree(r->in.ads, res);
done:
ads_msgfree(r->in.ads, res);
- ads_memfree(r->in.ads, dn);
printer->info_2->sharename, global_myname());
if (ADS_ERR_OK(ads_rc) && res && ads_count_replies(ads, res)) {
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);
if (!prt_dn) {
ads_msgfree(ads, res);
return WERR_NOMEM;
}
ads_rc = ads_del_dn(ads, prt_dn);
- ads_memfree(ads, prt_dn);
ads_msgfree(ads, res);
status=ads_find_user_acct(ads, &res, argv[0]);
if (ADS_ERR_OK(status)) {
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_memfree(ads, userdn);
ads_destroy(&ads);
return -1;
}
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_msgfree(ads, res);
rc = ads_del_dn(ads, userdn);
- ads_memfree(ads, userdn);
if (ADS_ERR_OK(rc)) {
d_printf("User %s deleted\n", argv[0]);
ads_destroy(&ads);
if (ADS_ERR_OK(rc)) {
d_printf("User %s deleted\n", argv[0]);
ads_destroy(&ads);
ads_destroy(&ads);
return -1;
}
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_msgfree(ads, res);
rc = ads_del_dn(ads, groupdn);
- ads_memfree(ads, groupdn);
if (ADS_ERR_OK(rc)) {
d_printf("Group %s deleted\n", argv[0]);
ads_destroy(&ads);
if (ADS_ERR_OK(rc)) {
d_printf("Group %s deleted\n", argv[0]);
ads_destroy(&ads);
- 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_msgfree(ads, res);
rc = ads_del_dn(ads, prt_dn);
- ads_memfree(ads, prt_dn);
if (!ADS_ERR_OK(rc)) {
d_fprintf(stderr, "ads_del_dn: %s\n", ads_errstr(rc));
if (!ADS_ERR_OK(rc)) {
d_fprintf(stderr, "ads_del_dn: %s\n", ads_errstr(rc));
msg;
msg = ads_next_entry(ads, msg)) {
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) {
if (!ADS_ERR_OK(status)) {
d_printf("ads_parse_gpo failed: %s\n",
ads_errstr(status));
if (!ADS_ERR_OK(status)) {
d_printf("ads_parse_gpo failed: %s\n",
ads_errstr(status));
goto out;
}
dump_gpo(ads, mem_ctx, &gpo, 0);
goto out;
}
dump_gpo(ads, mem_ctx, &gpo, 0);
}
out:
ads_msgfree(ads, res);
}
out:
ads_msgfree(ads, res);
- talloc_destroy(mem_ctx);
ads_destroy(&ads);
return 0;
ads_destroy(&ads);
return 0;
while (e) {
struct winbindd_tdc_domain *domain_rec;
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);
BAIL_ON_PTR_ERROR(dn, nt_status);
dns_domain = cell_dn_to_dns(dn);
BAIL_ON_PTR_ERROR(dns_domain, nt_status);
domain_rec = wcache_tdc_fetch_domain(frame, dns_domain);
BAIL_ON_PTR_ERROR(dns_domain, nt_status);
domain_rec = wcache_tdc_fetch_domain(frame, dns_domain);
/* get the name and domain */
/* 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);
BAIL_ON_PTR_ERROR(dn, nt_status);
DEBUG(10,("get_object_account_name: dn = \"%s\"\n", dn));
dns_domain = cell_dn_to_dns(dn);
BAIL_ON_PTR_ERROR(dns_domain, nt_status);
domain_rec = wcache_tdc_fetch_domain(frame, dns_domain);
BAIL_ON_PTR_ERROR(dns_domain, nt_status);
domain_rec = wcache_tdc_fetch_domain(frame, dns_domain);
e!=NULL;
e = ads_next_entry(c->conn, e))
{
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>"));
DEBUGADD(10,(" dn: %s\n", dn ? dn : "<NULL>"));
- 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;
if (user_dn == NULL) {
status = NT_STATUS_NO_MEMORY;
goto done;
DEBUG(3,("ads lookup_usergroups (tokenGroups) succeeded for sid=%s\n",
sid_string_dbg(sid)));
done:
DEBUG(3,("ads lookup_usergroups (tokenGroups) succeeded for sid=%s\n",
sid_string_dbg(sid)));
done:
- ads_memfree(ads, user_dn);
ads_msgfree(ads, msg);
return status;
}
ads_msgfree(ads, msg);
return status;
}