mirror of
https://github.com/samba-team/samba.git
synced 2025-08-21 09:49:28 +03:00
s3:net: Refactor net_ads_search(), allocate a talloc context
ADS_STRUCT will be allocated in the talloc context. Signed-off-by: Samuel Cabrero <scabrero@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
committed by
Jeremy Allison
parent
407e156d59
commit
f665c66133
@ -2706,30 +2706,36 @@ static int net_ads_search_usage(struct net_context *c, int argc, const char **ar
|
||||
*/
|
||||
static int net_ads_search(struct net_context *c, int argc, const char **argv)
|
||||
{
|
||||
ADS_STRUCT *ads;
|
||||
ADS_STATUS rc;
|
||||
const char *ldap_exp;
|
||||
const char **attrs;
|
||||
TALLOC_CTX *tmp_ctx = talloc_stackframe();
|
||||
ADS_STRUCT *ads = NULL;
|
||||
ADS_STATUS status;
|
||||
const char *ldap_exp = NULL;
|
||||
const char **attrs = NULL;
|
||||
LDAPMessage *res = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (argc < 1 || c->display_usage) {
|
||||
TALLOC_FREE(tmp_ctx);
|
||||
return net_ads_search_usage(c, argc, argv);
|
||||
}
|
||||
|
||||
if (!ADS_ERR_OK(ads_startup(c, false, &ads))) {
|
||||
return -1;
|
||||
status = ads_startup(c, false, &ads);
|
||||
if (!ADS_ERR_OK(status)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ldap_exp = argv[0];
|
||||
attrs = (argv + 1);
|
||||
|
||||
rc = ads_do_search_retry(ads, ads->config.bind_path,
|
||||
LDAP_SCOPE_SUBTREE,
|
||||
ldap_exp, attrs, &res);
|
||||
if (!ADS_ERR_OK(rc)) {
|
||||
d_fprintf(stderr, _("search failed: %s\n"), ads_errstr(rc));
|
||||
ads_destroy(&ads);
|
||||
return -1;
|
||||
status = ads_do_search_retry(ads,
|
||||
ads->config.bind_path,
|
||||
LDAP_SCOPE_SUBTREE,
|
||||
ldap_exp,
|
||||
attrs,
|
||||
&res);
|
||||
if (!ADS_ERR_OK(status)) {
|
||||
d_fprintf(stderr, _("search failed: %s\n"), ads_errstr(status));
|
||||
goto out;
|
||||
}
|
||||
|
||||
d_printf(_("Got %d replies\n\n"), ads_count_replies(ads, res));
|
||||
@ -2737,10 +2743,12 @@ static int net_ads_search(struct net_context *c, int argc, const char **argv)
|
||||
/* dump the results */
|
||||
ads_dump(ads, res);
|
||||
|
||||
ret = 0;
|
||||
out:
|
||||
ads_msgfree(ads, res);
|
||||
ads_destroy(&ads);
|
||||
|
||||
return 0;
|
||||
TALLOC_FREE(tmp_ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user