From b5f6cbbe1be4379a1ebab1f70ef05af838d48fb7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 6 Sep 2006 13:20:06 +0000 Subject: r18177: Some build- and memleak-fixes for the (not build by default) ADS GPO routines. Guenther (This used to be commit 0ef504a0a6dc8f5db1dbc7f2410aa981e11fd56c) --- source3/libads/gpo_util.c | 7 ++++++- source3/utils/net_ads_gpo.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/source3/libads/gpo_util.c b/source3/libads/gpo_util.c index 8f913c1971..7df38eb125 100644 --- a/source3/libads/gpo_util.c +++ b/source3/libads/gpo_util.c @@ -445,7 +445,7 @@ ADS_STATUS gpo_password_policy(ADS_STRUCT *ads, struct GROUP_POLICY_OBJECT *gpo_list; const char *attrs[] = {"distinguishedName", "userAccountControl", NULL}; char *filter, *dn; - void *res = NULL; + LDAPMessage *res = NULL; uint32 uac; return ADS_ERROR_NT(NT_STATUS_NOT_IMPLEMENTED); @@ -473,15 +473,18 @@ ADS_STATUS gpo_password_policy(ADS_STRUCT *ads, } if (!ads_pull_uint32(ads, res, "userAccountControl", &uac)) { + ads_memfree(ads, dn); return ADS_ERROR(LDAP_NO_MEMORY); } if (!(uac & UF_WORKSTATION_TRUST_ACCOUNT)) { + ads_memfree(ads, dn); return ADS_ERROR(LDAP_NO_SUCH_OBJECT); } status = ads_get_gpo_list(ads, mem_ctx, dn, GPO_LIST_FLAG_MACHINE, &gpo_list); if (!ADS_ERR_OK(status)) { + ads_memfree(ads, dn); return status; } @@ -489,8 +492,10 @@ ADS_STATUS gpo_password_policy(ADS_STRUCT *ads, cse_gpo_name_to_guid_string("Security"), GPO_LIST_FLAG_MACHINE); if (!ADS_ERR_OK(status)) { + ads_memfree(ads, dn); return status; } + ads_memfree(ads, dn); return ADS_ERROR(LDAP_SUCCESS); } diff --git a/source3/utils/net_ads_gpo.c b/source3/utils/net_ads_gpo.c index fec6fb88fa..2a044215b4 100644 --- a/source3/utils/net_ads_gpo.c +++ b/source3/utils/net_ads_gpo.c @@ -47,7 +47,7 @@ static int net_ads_gpo_effective(int argc, const char **argv) ADS_STRUCT *ads; ADS_STATUS status; const char *attrs[] = {"distinguishedName", "userAccountControl", NULL}; - void *res = NULL; + LDAPMessage *res = NULL; const char *filter; char *dn = NULL; struct GROUP_POLICY_OBJECT *gpo_list; @@ -68,7 +68,8 @@ static int net_ads_gpo_effective(int argc, const char **argv) goto out; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -132,18 +133,20 @@ static int net_ads_gpo_list(int argc, const char **argv) { ADS_STRUCT *ads; ADS_STATUS status; - void *res = NULL; + LDAPMessage *res = NULL; int num_reply = 0; void *msg = NULL; struct GROUP_POLICY_OBJECT gpo; TALLOC_CTX *mem_ctx; + char *dn; mem_ctx = talloc_init("net_ads_gpo_list"); if (mem_ctx == NULL) { return -1; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -161,8 +164,12 @@ static int net_ads_gpo_list(int argc, const char **argv) /* dump the results */ for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) { - - status = ads_parse_gpo(ads, mem_ctx, msg, ads_get_dn(ads, msg), &gpo); + + if ((dn = ads_get_dn(ads, msg)) == NULL) { + goto out; + } + + status = ads_parse_gpo(ads, mem_ctx, msg, dn, &gpo); if (!ADS_ERR_OK(status)) { d_printf("parse failed: %s\n", ads_errstr(status)); @@ -174,6 +181,7 @@ static int net_ads_gpo_list(int argc, const char **argv) } out: + ads_memfree(ads, dn); ads_msgfree(ads, res); talloc_destroy(mem_ctx); @@ -188,7 +196,7 @@ static int net_ads_gpo_apply(int argc, const char **argv) ADS_STRUCT *ads; ADS_STATUS status; const char *attrs[] = {"distinguishedName", "userAccountControl", NULL}; - void *res = NULL; + LDAPMessage *res = NULL; const char *filter; char *dn = NULL; struct GROUP_POLICY_OBJECT *gpo_list; @@ -209,7 +217,8 @@ static int net_ads_gpo_apply(int argc, const char **argv) goto out; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -280,7 +289,8 @@ static int net_ads_gpo_get_link(int argc, const char **argv) return -1; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -319,7 +329,8 @@ static int net_ads_gpo_add_link(int argc, const char **argv) gpo_opt = atoi(argv[2]); } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -351,7 +362,8 @@ static int net_ads_gpo_delete_link(int argc, const char **argv) return -1; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -385,7 +397,8 @@ static int net_ads_gpo_get_gpo(int argc, const char **argv) return -1; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } -- cgit