From e2bebe486550374978af200232334ddc7757ba8d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 1 Dec 2006 14:54:31 +0000 Subject: r19978: More "net sam policy" improvements. Thanks to Karolin Seeger Volker (This used to be commit fde042f29e9e9ac19ed3380e8fbe45fa8441e705) --- source3/lib/account_pol.c | 28 +++++++--------- source3/utils/net_sam.c | 83 ++++++++++++++++++++++++++++++++--------------- source3/utils/pdbedit.c | 16 ++++++--- 3 files changed, 80 insertions(+), 47 deletions(-) diff --git a/source3/lib/account_pol.c b/source3/lib/account_pol.c index 4cb0b77e74..f4008457ac 100644 --- a/source3/lib/account_pol.c +++ b/source3/lib/account_pol.c @@ -83,28 +83,24 @@ static const struct ap_table account_policy_names[] = { {0, NULL, 0, "", NULL} }; -char *account_policy_names_list(void) -{ - char *nl, *p; - int i; - size_t len = 0; +void account_policy_names_list(const char ***names, int *num_names) +{ + const char **nl; + int i, count; - for (i=0; account_policy_names[i].string; i++) { - len += strlen(account_policy_names[i].string) + 1; + for (count=0; account_policy_names[count].string; count++) { } - len++; - nl = (char *)SMB_MALLOC(len); + nl = SMB_MALLOC_ARRAY(const char *, count); if (!nl) { - return NULL; + *num_names = 0; + return; } - p = nl; for (i=0; account_policy_names[i].string; i++) { - memcpy(p, account_policy_names[i].string, strlen(account_policy_names[i].string) + 1); - p[strlen(account_policy_names[i].string)] = '\n'; - p += strlen(account_policy_names[i].string) + 1; + nl[i] = account_policy_names[i].string; } - *p = '\0'; - return nl; + *num_names = count; + *names = nl; + return; } /**************************************************************************** diff --git a/source3/utils/net_sam.c b/source3/utils/net_sam.c index d92bf1521c..2c9b9649f7 100644 --- a/source3/utils/net_sam.c +++ b/source3/utils/net_sam.c @@ -365,38 +365,57 @@ static int net_sam_policy_set(int argc, const char **argv) const char *account_policy = NULL; uint32 value, old_value; int field; + char *endptr; if (argc != 2) { - d_fprintf(stderr, "usage: net sam policy set" + d_fprintf(stderr, "usage: net sam policy set " "\"\" \n"); return -1; } - value = strtoul(argv[1], NULL, 10); account_policy = argv[0]; field = account_policy_name_to_fieldnum(account_policy); + value = strtoul(argv[1], &endptr, 10); - printf("Account policy \"%s\" description: %s\n", account_policy, - account_policy_get_desc(field)); + if (field == 0) { + const char **names; + int i, count; + + account_policy_names_list(&names, &count); + d_fprintf(stderr, "No account policy \"%s\"!\n\n", argv[0]); + d_fprintf(stderr, "Valid account policies are:\n"); + + for (i=0; i