Author: gd Date: 2006-09-06 13:20:06 +0000 (Wed, 06 Sep 2006) New Revision: 18177
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=18177 Log: Some build- and memleak-fixes for the (not build by default) ADS GPO routines. Guenther Modified: branches/SAMBA_3_0/source/libads/gpo_util.c branches/SAMBA_3_0/source/utils/net_ads_gpo.c Changeset: Modified: branches/SAMBA_3_0/source/libads/gpo_util.c =================================================================== --- branches/SAMBA_3_0/source/libads/gpo_util.c 2006-09-06 13:15:37 UTC (rev 18176) +++ branches/SAMBA_3_0/source/libads/gpo_util.c 2006-09-06 13:20:06 UTC (rev 18177) @@ -445,7 +445,7 @@ 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 @@ } 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 @@ 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); } Modified: branches/SAMBA_3_0/source/utils/net_ads_gpo.c =================================================================== --- branches/SAMBA_3_0/source/utils/net_ads_gpo.c 2006-09-06 13:15:37 UTC (rev 18176) +++ branches/SAMBA_3_0/source/utils/net_ads_gpo.c 2006-09-06 13:20:06 UTC (rev 18177) @@ -47,7 +47,7 @@ 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 @@ goto out; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -132,18 +133,20 @@ { 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,9 +164,13 @@ /* 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)); goto out; @@ -174,6 +181,7 @@ } out: + ads_memfree(ads, dn); ads_msgfree(ads, res); talloc_destroy(mem_ctx); @@ -188,7 +196,7 @@ 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 @@ goto out; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -280,7 +289,8 @@ return -1; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -319,7 +329,8 @@ 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 @@ return -1; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; } @@ -385,7 +397,8 @@ return -1; } - if (!(ads = ads_startup())) { + status = ads_startup(False, &ads); + if (!ADS_ERR_OK(status)) { goto out; }