r18177: Some build- and memleak-fixes for the (not build by default) ADS GPO
authorGünther Deschner <gd@samba.org>
Wed, 6 Sep 2006 13:20:06 +0000 (13:20 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:43:30 +0000 (11:43 -0500)
routines.

Guenther
(This used to be commit 0ef504a0a6dc8f5db1dbc7f2410aa981e11fd56c)

source3/libads/gpo_util.c
source3/utils/net_ads_gpo.c

index 8f913c19714b468277967b16dc11626111e14669..7df38eb12563c64a850b6d4d6d5f298dfb2220a9 100644 (file)
@@ -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);
 }
index fec6fb88fa26eaa1ef1ba824973939f629215e9c..2a044215b4ec684565327c8d8ed7c8d19bd2c9cf 100644 (file)
@@ -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;
        }