From: Samuel Cabrero Date: Thu, 26 May 2022 10:23:17 +0000 (+0200) Subject: s3:net: Refactor net_ads_printer_search(), allocate a talloc context X-Git-Tag: tevent-0.13.0~267 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=507c90e2fb8f97e464f75197b2dac84849489f8d;p=thirdparty%2Fsamba.git s3:net: Refactor net_ads_printer_search(), allocate a talloc context ADS_STRUCT will be allocated in the talloc context. Signed-off-by: Samuel Cabrero Reviewed-by: Jeremy Allison --- diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 107e0d0e605..735fbc8ec00 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -2130,11 +2130,15 @@ int net_ads_printer_usage(struct net_context *c, int argc, const char **argv) /******************************************************************* ********************************************************************/ -static int net_ads_printer_search(struct net_context *c, int argc, const char **argv) +static int net_ads_printer_search(struct net_context *c, + int argc, + const char **argv) { - ADS_STRUCT *ads; - ADS_STATUS rc; + TALLOC_CTX *tmp_ctx = talloc_stackframe(); + ADS_STRUCT *ads = NULL; + ADS_STATUS status; LDAPMessage *res = NULL; + int ret = -1; if (c->display_usage) { d_printf( "%s\n" @@ -2142,33 +2146,35 @@ static int net_ads_printer_search(struct net_context *c, int argc, const char ** " %s\n", _("Usage:"), _("List printers in the AD")); + TALLOC_FREE(tmp_ctx); return 0; } - if (!ADS_ERR_OK(ads_startup(c, false, &ads))) { - return -1; + status = ads_startup(c, false, &ads); + if (!ADS_ERR_OK(status)) { + goto out; } - rc = ads_find_printers(ads, &res); - - if (!ADS_ERR_OK(rc)) { - d_fprintf(stderr, _("ads_find_printer: %s\n"), ads_errstr(rc)); - ads_msgfree(ads, res); - ads_destroy(&ads); - return -1; + status = ads_find_printers(ads, &res); + if (!ADS_ERR_OK(status)) { + d_fprintf(stderr, _("ads_find_printer: %s\n"), + ads_errstr(status)); + goto out; } if (ads_count_replies(ads, res) == 0) { d_fprintf(stderr, _("No results found\n")); - ads_msgfree(ads, res); - ads_destroy(&ads); - return -1; + goto out; } ads_dump(ads, res); + + ret = 0; +out: ads_msgfree(ads, res); ads_destroy(&ads); - return 0; + TALLOC_FREE(tmp_ctx); + return ret; } static int net_ads_printer_info(struct net_context *c, int argc, const char **argv)