s3-passdb: Replace SMB_MALLOC_ARRAY()/SAFE_FREE() with talloc equivalents.
authorAmitay Isaacs <amitay@gmail.com>
Mon, 15 Aug 2011 07:12:46 +0000 (17:12 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 19 Aug 2011 06:34:56 +0000 (16:34 +1000)
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
source3/passdb/account_pol.c
source3/passdb/proto.h
source3/utils/net_sam.c
source3/utils/pdbedit.c

index 3556869bd8c947e3da5f5cdd413062152f1c0621..a491c27a9dd4ca5867f92b1eefb711bcfe634888 100644 (file)
@@ -89,22 +89,21 @@ static const struct ap_table account_policy_names[] = {
        {0, NULL, 0, "", NULL}
 };
 
-void account_policy_names_list(const char ***names, int *num_names)
+void account_policy_names_list(TALLOC_CTX *mem_ctx, const char ***names, int *num_names)
 {
        const char **nl;
-       int i, count;
+       int i, count = ARRAY_SIZE(account_policy_names);
 
-       for (count=0; account_policy_names[count].string; count++) {
-       }
-       nl = SMB_MALLOC_ARRAY(const char *, count);
+       nl = talloc_array(mem_ctx, const char *, count);
        if (!nl) {
                *num_names = 0;
                return;
        }
-       for (i=0; account_policy_names[i].string; i++) {
+       for (i=0; i<count; i++) {
                nl[i] = account_policy_names[i].string;
        }
-       *num_names = count;
+       /* Do not return the last null entry */
+       *num_names = count-1;
        *names = nl;
        return;
 }
index 24a7cba8915041cb65046bea58f1bbaef847cf38..63208ea9c16bde25595c6d0fd82c3121f22e0f2b 100644 (file)
@@ -39,7 +39,7 @@
 
 /* The following definitions come from passdb/account_pol.c  */
 
-void account_policy_names_list(const char ***names, int *num_names);
+void account_policy_names_list(TALLOC_CTX *mem_ctx, const char ***names, int *num_names);
 const char *decode_account_policy_name(enum pdb_policy_type type);
 const char *get_account_policy_attr(enum pdb_policy_type type);
 const char *account_policy_get_desc(enum pdb_policy_type type);
index 4754fb0f34327ba106d212a8faaaa69a74c8f5eb..467e441f60f37cd6c0626a0b986c669be6d564af 100644 (file)
@@ -499,7 +499,7 @@ static int net_sam_policy_set(struct net_context *c, int argc, const char **argv
                const char **names;
                 int i, count;
 
-                account_policy_names_list(&names, &count);
+                account_policy_names_list(talloc_tos(), &names, &count);
                d_fprintf(stderr, _("No account policy \"%s\"!\n\n"), argv[0]);
                d_fprintf(stderr, _("Valid account policies are:\n"));
 
@@ -507,7 +507,8 @@ static int net_sam_policy_set(struct net_context *c, int argc, const char **argv
                        d_fprintf(stderr, "%s\n", names[i]);
                }
 
-               SAFE_FREE(names);
+               TALLOC_FREE(names);
+
                return -1;
        }
 
@@ -551,7 +552,7 @@ static int net_sam_policy_show(struct net_context *c, int argc, const char **arg
                const char **names;
                int count;
                int i;
-                account_policy_names_list(&names, &count);
+                account_policy_names_list(talloc_tos(), &names, &count);
                 d_fprintf(stderr, _("No account policy by that name!\n"));
                 if (count != 0) {
                         d_fprintf(stderr, _("Valid account policies "
@@ -560,7 +561,7 @@ static int net_sam_policy_show(struct net_context *c, int argc, const char **arg
                                d_fprintf(stderr, "%s\n", names[i]);
                        }
                 }
-                SAFE_FREE(names);
+                TALLOC_FREE(names);
                 return -1;
         }
 
@@ -592,7 +593,7 @@ static int net_sam_policy_list(struct net_context *c, int argc, const char **arg
                return 0;
        }
 
-       account_policy_names_list(&names, &count);
+       account_policy_names_list(talloc_tos(), &names, &count);
         if (count != 0) {
                d_fprintf(stderr, _("Valid account policies "
                          "are:\n"));
@@ -600,7 +601,7 @@ static int net_sam_policy_list(struct net_context *c, int argc, const char **arg
                        d_fprintf(stderr, "%s\n", names[i]);
                }
        }
-        SAFE_FREE(names);
+        TALLOC_FREE(names);
         return -1;
 }
 
index 123db0f87053f956ef9b29ab497d0ef17fea454c..cec65a9db7b826a0a1a48998604381fe39b20b22 100644 (file)
@@ -1142,7 +1142,7 @@ int main (int argc, char **argv)
                        const char **names;
                        int count;
                        int i;
-                       account_policy_names_list(&names, &count);
+                       account_policy_names_list(talloc_tos(), &names, &count);
                        fprintf(stderr, "No account policy by that name!\n");
                        if (count !=0) {
                                fprintf(stderr, "Account policy names are:\n");
@@ -1150,7 +1150,7 @@ int main (int argc, char **argv)
                                        d_fprintf(stderr, "%s\n", names[i]);
                                }
                        }
-                       SAFE_FREE(names);
+                       TALLOC_FREE(names);
                        exit(1);
                }
                if (!pdb_get_account_policy(field, &value)) {