From a3a7881d39d0c294d0cd2ce13203478fb889b07c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 30 Aug 2005 13:58:48 +0000 Subject: r9798: Add generic functions for handling smb.conf files (the parameters don't to be pre-declared). Also doesn't use any globals, so multiple files can be loaded at once. Currently uses the prefix "param" for all functions and structures; suggestions for better ones are welcome... Remove old smb.conf-parsing code from libsamba3. (This used to be commit 414e5f7f6dc38a8fde3b61d524a664f56f9ea592) --- source4/param/generic.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 source4/param/generic.c (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c new file mode 100644 index 0000000000..0129f82eeb --- /dev/null +++ b/source4/param/generic.c @@ -0,0 +1,231 @@ +/* + * Unix SMB/CIFS implementation. + * Copyright (C) Jelmer Vernooij 2005 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" +#include "dlinklist.h" +#include "param/generic.h" + +struct param_section *param_get_section(struct param_context *ctx, const char *name) +{ + struct param_section *sect; + + if (name == NULL) + name = GLOBAL_NAME; + + for (sect = ctx->sections; sect; sect = sect->next) { + if (!strcasecmp_m(sect->name, name)) + return sect; + } + + return NULL; +} + +struct param *param_section_get (struct param_section *section, const char *name) +{ + struct param *p; + + for (p = section->parameters; p; p = p->next) { + if (strcasecmp(p->name, name) == 0) + return p; + } + + return NULL; +} + +struct param *param_get (struct param_context *ctx, const char *section_name, const char *name) +{ + struct param_section *section = param_get_section(ctx, section_name); + if (section == NULL) + return NULL; + + return param_section_get(section, name); +} + +/* Look up parameter. If it is not found, add it */ +static struct param *param_get_add(struct param_context *ctx, const char *section_name, const char *name) +{ + struct param_section *section; + struct param *p; + + section = param_get_section(ctx, section_name); + + if (section == NULL) { + section = talloc_zero(ctx, struct param_section); + section->name = talloc_strdup(section, section_name); + DLIST_ADD(ctx->sections, section); + } + + p = param_section_get(section, name); + if (p == NULL) { + p = talloc_zero(section, struct param); + p->name = talloc_strdup(p, name); + DLIST_ADD(section->parameters, p); + } + + return p; +} + +const char *param_get_string(struct param_context *ctx, const char *section, const char *param) +{ + struct param *p = param_get(ctx, section, param); + + if (p == NULL) + return NULL; + + return p->value; +} + +void param_set_string(struct param_context *ctx, const char *section, const char *param, const char *value) +{ + struct param *p = param_get_add(ctx, section, param); + + p->value = talloc_strdup(p, value); +} + +const char **param_get_string_list(struct param_context *ctx, const char *section, const char *param, + const char *separator) +{ + struct param *p = param_get(ctx, section, param); + + if (p == NULL) + return NULL; + + if (p->list_value == NULL) { + p->list_value = str_list_make(ctx, p->value, separator); + } + + return p->list_value; +} + +void param_set_string_list(struct param_context *ctx, const char *section, const char *param, const char **list) +{ + struct param *p = param_get_add(ctx, section, param); + + p->value = str_list_join(p, list, ' '); + p->list_value = str_list_copy(p, list); +} + +int param_get_int(struct param_context *ctx, const char *section, const char *param, int default_v) +{ + const char *value = param_get_string(ctx, section, param); + + if (value) + return strtol(value, NULL, 0); + + return default_v; +} + +void param_set_int(struct param_context *ctx, const char *section, const char *param, int value) +{ + struct param *p = param_get_add(ctx, section, param); + + p->value = talloc_asprintf(p, "%d", value); +} + +unsigned long param_get_ulong(struct param_context *ctx, const char *section, const char *param, unsigned long default_v) +{ + const char *value = param_get_string(ctx, section, param); + + if (value) + return strtoul(value, NULL, 0); + + return default_v; +} + +void param_set_ulong(struct param_context *ctx, const char *section, const char *name, unsigned long value) +{ + struct param *p = param_get_add(ctx, section, name); + + p->value = talloc_asprintf(p, "%lu", value); +} + +static BOOL param_sfunc (const char *name, void *_ctx) +{ + struct param_context *ctx = _ctx; + struct param_section *section = param_get_section(ctx, name); + + if (section == NULL) { + section = talloc_zero(ctx, struct param_section); + section->name = talloc_strdup(section, name); + + DLIST_ADD(ctx->sections, section); + } + + DLIST_PROMOTE(ctx->sections, section); + + return True; +} + + + +static BOOL param_pfunc (const char *name, const char *value, void *_ctx) +{ + struct param_context *ctx = _ctx; + struct param *p = param_section_get(ctx->sections, name); + + if (!p) { + p = talloc_zero(ctx->sections, struct param); + p->name = talloc_strdup(p, name); + p->value = talloc_strdup(p, value); + DLIST_ADD(ctx->sections->parameters, p); + } else { /* Replace current value */ + talloc_free(p->value); + p->value = talloc_strdup(p, value); + } + + return True; +} + +struct param_context *param_read(TALLOC_CTX *mem_ctx, const char *fn) +{ + struct param_context *ctx = talloc_zero(mem_ctx, struct param_context); + + ctx->sections = talloc_zero(ctx, struct param_section); + ctx->sections->name = talloc_strdup(ctx->sections, "global"); + + if (!pm_process( fn, param_sfunc, param_pfunc, ctx)) { + talloc_free(ctx); + return NULL; + } + + return ctx; +} + +int param_write(FILE *file, struct param_context *ctx) +{ + struct param_section *section; + + if (file == NULL) + return -1; + + if (ctx == NULL) + return -1; + + for (section = ctx->sections; section; section = section->next) { + struct param *param; + + fprintf(file, "[%s]\n", section->name); + for (param = section->parameters; param; param = param->next) { + fprintf(file, "\t%s = %s\n", param->name, param->value); + } + fprintf(file, "\n"); + } + + return 0; +} -- cgit From 9f4b32996c1c97122b198a13216c35ad40f6ea2d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 30 Aug 2005 14:44:33 +0000 Subject: r9800: Add EJS interface to param. tridge, sorry this overlaps a bit with your loadparm interface. :-/ (This used to be commit bb0cef581a09a86113f3212c776c011ae73def14) --- source4/param/generic.c | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index 0129f82eeb..2e18b69f03 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -20,6 +20,7 @@ #include "includes.h" #include "dlinklist.h" #include "param/generic.h" +#include "system/filesys.h" struct param_section *param_get_section(struct param_context *ctx, const char *name) { @@ -41,7 +42,7 @@ struct param *param_section_get (struct param_section *section, const char *name struct param *p; for (p = section->parameters; p; p = p->next) { - if (strcasecmp(p->name, name) == 0) + if (strcasecmp_m(p->name, name) == 0) return p; } @@ -91,11 +92,16 @@ const char *param_get_string(struct param_context *ctx, const char *section, con return p->value; } -void param_set_string(struct param_context *ctx, const char *section, const char *param, const char *value) +int param_set_string(struct param_context *ctx, const char *section, const char *param, const char *value) { struct param *p = param_get_add(ctx, section, param); + if (p == NULL) + return -1; + p->value = talloc_strdup(p, value); + + return 0; } const char **param_get_string_list(struct param_context *ctx, const char *section, const char *param, @@ -105,6 +111,9 @@ const char **param_get_string_list(struct param_context *ctx, const char *sectio if (p == NULL) return NULL; + + if (separator == NULL) + separator = LIST_SEP; if (p->list_value == NULL) { p->list_value = str_list_make(ctx, p->value, separator); @@ -167,13 +176,12 @@ static BOOL param_sfunc (const char *name, void *_ctx) DLIST_ADD(ctx->sections, section); } + /* Make sure this section is on top of the list for param_pfunc */ DLIST_PROMOTE(ctx->sections, section); return True; } - - static BOOL param_pfunc (const char *name, const char *value, void *_ctx) { struct param_context *ctx = _ctx; @@ -192,40 +200,48 @@ static BOOL param_pfunc (const char *name, const char *value, void *_ctx) return True; } -struct param_context *param_read(TALLOC_CTX *mem_ctx, const char *fn) +struct param_context *param_init(TALLOC_CTX *mem_ctx) { - struct param_context *ctx = talloc_zero(mem_ctx, struct param_context); + return talloc_zero(mem_ctx, struct param_context); +} + +int param_read(struct param_context *ctx, const char *fn) +{ ctx->sections = talloc_zero(ctx, struct param_section); ctx->sections->name = talloc_strdup(ctx->sections, "global"); if (!pm_process( fn, param_sfunc, param_pfunc, ctx)) { - talloc_free(ctx); - return NULL; + return -1; } - return ctx; + return 0; } -int param_write(FILE *file, struct param_context *ctx) +int param_write(struct param_context *ctx, const char *fn) { + XFILE *file; struct param_section *section; - if (file == NULL) + if (fn == NULL || ctx == NULL) return -1; - if (ctx == NULL) + file = x_fopen(fn, O_WRONLY|O_CREAT, 0755); + + if (file == NULL) return -1; for (section = ctx->sections; section; section = section->next) { struct param *param; - fprintf(file, "[%s]\n", section->name); + x_fprintf(file, "[%s]\n", section->name); for (param = section->parameters; param; param = param->next) { - fprintf(file, "\t%s = %s\n", param->name, param->value); + x_fprintf(file, "\t%s = %s\n", param->name, param->value); } - fprintf(file, "\n"); + x_fprintf(file, "\n"); } + x_fclose(file); + return 0; } -- cgit From cf016f972b931b54c155ca8e6df485e05c37b034 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 30 Aug 2005 16:09:38 +0000 Subject: r9805: Add 'data' property to param EJS object Write out new smb.conf file. Parameters that have disappeared between Samba 3 and 4 will optionally be prefixed with 'samba3:' (This used to be commit 27eefbd9059fe0a3daca15a71da7b4cb88ed22ec) --- source4/param/generic.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index 2e18b69f03..6866ffbf56 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -122,12 +122,14 @@ const char **param_get_string_list(struct param_context *ctx, const char *sectio return p->list_value; } -void param_set_string_list(struct param_context *ctx, const char *section, const char *param, const char **list) +int param_set_string_list(struct param_context *ctx, const char *section, const char *param, const char **list) { struct param *p = param_get_add(ctx, section, param); p->value = str_list_join(p, list, ' '); p->list_value = str_list_copy(p, list); + + return 0; } int param_get_int(struct param_context *ctx, const char *section, const char *param, int default_v) -- cgit From adf31c5042497cbdf10d3542672bf8a5d0956216 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 31 Aug 2005 14:26:20 +0000 Subject: r9826: Add some more OOM checks (This used to be commit 213bcb7e16290da0c26492ced65509a63942d4ce) --- source4/param/generic.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index 6866ffbf56..b6d2fd0449 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -68,6 +68,9 @@ static struct param *param_get_add(struct param_context *ctx, const char *sectio if (section == NULL) { section = talloc_zero(ctx, struct param_section); + if (section == NULL) + return NULL; + section->name = talloc_strdup(section, section_name); DLIST_ADD(ctx->sections, section); } @@ -75,6 +78,9 @@ static struct param *param_get_add(struct param_context *ctx, const char *sectio p = param_section_get(section, name); if (p == NULL) { p = talloc_zero(section, struct param); + if (p == NULL) + return NULL; + p->name = talloc_strdup(p, name); DLIST_ADD(section->parameters, p); } @@ -146,6 +152,9 @@ void param_set_int(struct param_context *ctx, const char *section, const char *p { struct param *p = param_get_add(ctx, section, param); + if (!p) + return; + p->value = talloc_asprintf(p, "%d", value); } @@ -163,6 +172,9 @@ void param_set_ulong(struct param_context *ctx, const char *section, const char { struct param *p = param_get_add(ctx, section, name); + if (!p) + return; + p->value = talloc_asprintf(p, "%lu", value); } @@ -173,6 +185,9 @@ static BOOL param_sfunc (const char *name, void *_ctx) if (section == NULL) { section = talloc_zero(ctx, struct param_section); + if (section == NULL) + return False; + section->name = talloc_strdup(section, name); DLIST_ADD(ctx->sections, section); @@ -191,6 +206,9 @@ static BOOL param_pfunc (const char *name, const char *value, void *_ctx) if (!p) { p = talloc_zero(ctx->sections, struct param); + if (p == NULL) + return False; + p->name = talloc_strdup(p, name); p->value = talloc_strdup(p, value); DLIST_ADD(ctx->sections->parameters, p); @@ -211,8 +229,10 @@ struct param_context *param_init(TALLOC_CTX *mem_ctx) int param_read(struct param_context *ctx, const char *fn) { ctx->sections = talloc_zero(ctx, struct param_section); + if (ctx->sections == NULL) + return -1; + ctx->sections->name = talloc_strdup(ctx->sections, "global"); - if (!pm_process( fn, param_sfunc, param_pfunc, ctx)) { return -1; } -- cgit From fd619b4fb3a9a5c05df765d2cf57a042a4d5da2d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 15 Sep 2005 19:52:13 +0000 Subject: r10245: Get rid of XFILE in a few places. Add fdprintf() and vfdprintf() helper functions. (This used to be commit 6685009f6af94b088084d69a43bcea5f8335ae57) --- source4/param/generic.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index b6d2fd0449..adf1eb0b31 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -242,28 +242,28 @@ int param_read(struct param_context *ctx, const char *fn) int param_write(struct param_context *ctx, const char *fn) { - XFILE *file; + int file; struct param_section *section; if (fn == NULL || ctx == NULL) return -1; - file = x_fopen(fn, O_WRONLY|O_CREAT, 0755); + file = open(fn, O_WRONLY|O_CREAT, 0755); - if (file == NULL) + if (file == -1) return -1; for (section = ctx->sections; section; section = section->next) { struct param *param; - x_fprintf(file, "[%s]\n", section->name); + fdprintf(file, "[%s]\n", section->name); for (param = section->parameters; param; param = param->next) { - x_fprintf(file, "\t%s = %s\n", param->name, param->value); + fdprintf(file, "\t%s = %s\n", param->name, param->value); } - x_fprintf(file, "\n"); + fdprintf(file, "\n"); } - x_fclose(file); + close(file); return 0; } -- cgit From 61933e159cc2a8399f8bb1fa53844a67f8bba55b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 14 Mar 2006 15:22:36 +0000 Subject: r14381: Kill structs.h (This used to be commit 1ffb82a7596f989c90df69573083a2c2e28f8808) --- source4/param/generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index adf1eb0b31..bed675be69 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -19,7 +19,7 @@ #include "includes.h" #include "dlinklist.h" -#include "param/generic.h" +#include "param/param.h" #include "system/filesys.h" struct param_section *param_get_section(struct param_context *ctx, const char *name) -- cgit From 0329d755a7611ba3897fc1ee9bdce410cc33d7f8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Aug 2006 11:29:34 +0000 Subject: r17930: Merge noinclude branch: * Move dlinklist.h, smb.h to subsystem-specific directories * Clean up ads.h and move what is left of it to dsdb/ (only place where it's used) (This used to be commit f7afa1cb77f3cfa7020b57de12e6003db7cfcc42) --- source4/param/generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index bed675be69..ca473ce7e7 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -18,7 +18,7 @@ */ #include "includes.h" -#include "dlinklist.h" +#include "lib/util/dlinklist.h" #include "param/param.h" #include "system/filesys.h" -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/param/generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index ca473ce7e7..8082b37dd4 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -4,7 +4,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From cd1217ff5ff18e53c6c9fa3d4f4fd56193fe2a17 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 5c9b19271e0e3ad897499707003ce4703ffa4870) --- source4/param/generic.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index 8082b37dd4..ca52934950 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -13,8 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" -- cgit From dccf3f99e45137b6cd18c1de1c79808ad67130d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 13:27:14 +0000 Subject: r25027: Fix more warnings. (This used to be commit 5085c53fcfade614e83d21fc2c1a5bc43bb2a729) --- source4/param/generic.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index ca52934950..cc269af1ec 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -177,15 +177,15 @@ void param_set_ulong(struct param_context *ctx, const char *section, const char p->value = talloc_asprintf(p, "%lu", value); } -static BOOL param_sfunc (const char *name, void *_ctx) +static bool param_sfunc (const char *name, void *_ctx) { - struct param_context *ctx = _ctx; + struct param_context *ctx = (struct param_context *)_ctx; struct param_section *section = param_get_section(ctx, name); if (section == NULL) { section = talloc_zero(ctx, struct param_section); if (section == NULL) - return False; + return false; section->name = talloc_strdup(section, name); @@ -195,12 +195,12 @@ static BOOL param_sfunc (const char *name, void *_ctx) /* Make sure this section is on top of the list for param_pfunc */ DLIST_PROMOTE(ctx->sections, section); - return True; + return true; } -static BOOL param_pfunc (const char *name, const char *value, void *_ctx) +static bool param_pfunc (const char *name, const char *value, void *_ctx) { - struct param_context *ctx = _ctx; + struct param_context *ctx = (struct param_context *)_ctx; struct param *p = param_section_get(ctx->sections, name); if (!p) { -- cgit From 30047a95432984c8c450b8a819b9f742bdedf66b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 2 Oct 2007 13:00:33 +0000 Subject: r25460: use common structure in param/generic.c (This used to be commit 01ce5448f44ddda7ec864d812fe23f0fa68d1561) --- source4/param/generic.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index cc269af1ec..6e9a8e60e4 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -36,19 +36,20 @@ struct param_section *param_get_section(struct param_context *ctx, const char *n return NULL; } -struct param *param_section_get (struct param_section *section, const char *name) +struct param_opt *param_section_get(struct param_section *section, + const char *name) { - struct param *p; + struct param_opt *p; for (p = section->parameters; p; p = p->next) { - if (strcasecmp_m(p->name, name) == 0) + if (strcasecmp_m(p->key, name) == 0) return p; } return NULL; } -struct param *param_get (struct param_context *ctx, const char *section_name, const char *name) +struct param_opt *param_get (struct param_context *ctx, const char *section_name, const char *name) { struct param_section *section = param_get_section(ctx, section_name); if (section == NULL) @@ -58,10 +59,10 @@ struct param *param_get (struct param_context *ctx, const char *section_name, co } /* Look up parameter. If it is not found, add it */ -static struct param *param_get_add(struct param_context *ctx, const char *section_name, const char *name) +static struct param_opt *param_get_add(struct param_context *ctx, const char *section_name, const char *name) { struct param_section *section; - struct param *p; + struct param_opt *p; section = param_get_section(ctx, section_name); @@ -76,11 +77,11 @@ static struct param *param_get_add(struct param_context *ctx, const char *sectio p = param_section_get(section, name); if (p == NULL) { - p = talloc_zero(section, struct param); + p = talloc_zero(section, struct param_opt); if (p == NULL) return NULL; - p->name = talloc_strdup(p, name); + p->key = talloc_strdup(p, name); DLIST_ADD(section->parameters, p); } @@ -89,7 +90,7 @@ static struct param *param_get_add(struct param_context *ctx, const char *sectio const char *param_get_string(struct param_context *ctx, const char *section, const char *param) { - struct param *p = param_get(ctx, section, param); + struct param_opt *p = param_get(ctx, section, param); if (p == NULL) return NULL; @@ -99,7 +100,7 @@ const char *param_get_string(struct param_context *ctx, const char *section, con int param_set_string(struct param_context *ctx, const char *section, const char *param, const char *value) { - struct param *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, section, param); if (p == NULL) return -1; @@ -112,7 +113,7 @@ int param_set_string(struct param_context *ctx, const char *section, const char const char **param_get_string_list(struct param_context *ctx, const char *section, const char *param, const char *separator) { - struct param *p = param_get(ctx, section, param); + struct param_opt *p = param_get(ctx, section, param); if (p == NULL) return NULL; @@ -120,19 +121,14 @@ const char **param_get_string_list(struct param_context *ctx, const char *sectio if (separator == NULL) separator = LIST_SEP; - if (p->list_value == NULL) { - p->list_value = str_list_make(ctx, p->value, separator); - } - - return p->list_value; + return str_list_make(ctx, p->value, separator); } int param_set_string_list(struct param_context *ctx, const char *section, const char *param, const char **list) { - struct param *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, section, param); p->value = str_list_join(p, list, ' '); - p->list_value = str_list_copy(p, list); return 0; } @@ -149,7 +145,7 @@ int param_get_int(struct param_context *ctx, const char *section, const char *pa void param_set_int(struct param_context *ctx, const char *section, const char *param, int value) { - struct param *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, section, param); if (!p) return; @@ -169,7 +165,7 @@ unsigned long param_get_ulong(struct param_context *ctx, const char *section, co void param_set_ulong(struct param_context *ctx, const char *section, const char *name, unsigned long value) { - struct param *p = param_get_add(ctx, section, name); + struct param_opt *p = param_get_add(ctx, section, name); if (!p) return; @@ -201,14 +197,14 @@ static bool param_sfunc (const char *name, void *_ctx) static bool param_pfunc (const char *name, const char *value, void *_ctx) { struct param_context *ctx = (struct param_context *)_ctx; - struct param *p = param_section_get(ctx->sections, name); + struct param_opt *p = param_section_get(ctx->sections, name); if (!p) { - p = talloc_zero(ctx->sections, struct param); + p = talloc_zero(ctx->sections, struct param_opt); if (p == NULL) return False; - p->name = talloc_strdup(p, name); + p->key = talloc_strdup(p, name); p->value = talloc_strdup(p, value); DLIST_ADD(ctx->sections->parameters, p); } else { /* Replace current value */ @@ -253,11 +249,11 @@ int param_write(struct param_context *ctx, const char *fn) return -1; for (section = ctx->sections; section; section = section->next) { - struct param *param; + struct param_opt *param; fdprintf(file, "[%s]\n", section->name); for (param = section->parameters; param; param = param->next) { - fdprintf(file, "\t%s = %s\n", param->name, param->value); + fdprintf(file, "\t%s = %s\n", param->key, param->value); } fdprintf(file, "\n"); } -- cgit From d5a93dfcb950ecd52d8dea7a2a5d667feb6259ca Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 Oct 2007 21:39:52 +0000 Subject: r25547: Convert to standard bool type. (This used to be commit 97a241692c4b8dc45e086aa9b959f2cd30b8d6c9) --- source4/param/generic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index 6e9a8e60e4..d65502c02d 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -202,7 +202,7 @@ static bool param_pfunc (const char *name, const char *value, void *_ctx) if (!p) { p = talloc_zero(ctx->sections, struct param_opt); if (p == NULL) - return False; + return false; p->key = talloc_strdup(p, name); p->value = talloc_strdup(p, value); @@ -212,7 +212,7 @@ static bool param_pfunc (const char *name, const char *value, void *_ctx) p->value = talloc_strdup(p, value); } - return True; + return true; } struct param_context *param_init(TALLOC_CTX *mem_ctx) -- cgit From 6357fb802a27b8160e263d32d0596f69186b81a7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 14:49:27 +0100 Subject: r26095: Add function for import a generic configuration file in a loadparm context. (This used to be commit d74018d05542582515a4d3cc995820667200b301) --- source4/param/generic.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index d65502c02d..f706dd6407 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -64,6 +64,9 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se struct param_section *section; struct param_opt *p; + SMB_ASSERT(section_name != NULL); + SMB_ASSERT(name != NULL); + section = param_get_section(ctx, section_name); if (section == NULL) { @@ -72,7 +75,7 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se return NULL; section->name = talloc_strdup(section, section_name); - DLIST_ADD(ctx->sections, section); + DLIST_ADD_END(ctx->sections, section, struct param_section *); } p = param_section_get(section, name); @@ -82,7 +85,7 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se return NULL; p->key = talloc_strdup(p, name); - DLIST_ADD(section->parameters, p); + DLIST_ADD_END(section->parameters, p, struct param_opt *); } return p; @@ -185,7 +188,7 @@ static bool param_sfunc (const char *name, void *_ctx) section->name = talloc_strdup(section, name); - DLIST_ADD(ctx->sections, section); + DLIST_ADD_END(ctx->sections, section, struct param_section *); } /* Make sure this section is on top of the list for param_pfunc */ @@ -235,6 +238,32 @@ int param_read(struct param_context *ctx, const char *fn) return 0; } +int param_use(struct loadparm_context *lp_ctx, struct param_context *ctx) +{ + struct param_section *section; + + for (section = ctx->sections; section; section = section->next) { + struct param_opt *param; + bool isglobal = strcmp(section->name, "global") == 0; + for (param = section->parameters; param; param = param->next) { + if (isglobal) + lp_do_global_parameter(lp_ctx, param->key, + param->value); + else { + struct loadparm_service *service = + lp_service(lp_ctx, section->name); + if (service == NULL) + service = lp_add_service(lp_ctx, &sDefault, section->name); + lp_do_service_parameter(lp_ctx, + service, + param->key, + param->value); + } + } + } + return 0; +} + int param_write(struct param_context *ctx, const char *fn) { int file; -- cgit From 32f439bfa458f7936b507cb5a1e3c74bcb8c68bf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 17 Dec 2007 11:12:36 +0100 Subject: r26503: Change order of arguments in param interface so it's easier to make the section name optional. Fix several smaller bits and pieces in the Python code. (This used to be commit 1b89311e5fa4fcde060df50e580dc221205cc8ca) --- source4/param/generic.c | 54 +++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index f706dd6407..2327000fc9 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -49,7 +49,7 @@ struct param_opt *param_section_get(struct param_section *section, return NULL; } -struct param_opt *param_get (struct param_context *ctx, const char *section_name, const char *name) +struct param_opt *param_get (struct param_context *ctx, const char *name, const char *section_name) { struct param_section *section = param_get_section(ctx, section_name); if (section == NULL) @@ -58,8 +58,20 @@ struct param_opt *param_get (struct param_context *ctx, const char *section_name return param_section_get(section, name); } +struct param_section *param_add_section(struct param_context *ctx, const char *section_name) +{ + struct param_section *section; + section = talloc_zero(ctx, struct param_section); + if (section == NULL) + return NULL; + + section->name = talloc_strdup(section, section_name); + DLIST_ADD_END(ctx->sections, section, struct param_section *); + return section; +} + /* Look up parameter. If it is not found, add it */ -static struct param_opt *param_get_add(struct param_context *ctx, const char *section_name, const char *name) +struct param_opt *param_get_add(struct param_context *ctx, const char *name, const char *section_name) { struct param_section *section; struct param_opt *p; @@ -70,12 +82,7 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se section = param_get_section(ctx, section_name); if (section == NULL) { - section = talloc_zero(ctx, struct param_section); - if (section == NULL) - return NULL; - - section->name = talloc_strdup(section, section_name); - DLIST_ADD_END(ctx->sections, section, struct param_section *); + section = param_add_section(ctx, section_name); } p = param_section_get(section, name); @@ -91,9 +98,9 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se return p; } -const char *param_get_string(struct param_context *ctx, const char *section, const char *param) +const char *param_get_string(struct param_context *ctx, const char *param, const char *section) { - struct param_opt *p = param_get(ctx, section, param); + struct param_opt *p = param_get(ctx, param, section); if (p == NULL) return NULL; @@ -101,9 +108,9 @@ const char *param_get_string(struct param_context *ctx, const char *section, con return p->value; } -int param_set_string(struct param_context *ctx, const char *section, const char *param, const char *value) +int param_set_string(struct param_context *ctx, const char *param, const char *value, const char *section) { - struct param_opt *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, param, section); if (p == NULL) return -1; @@ -113,10 +120,9 @@ int param_set_string(struct param_context *ctx, const char *section, const char return 0; } -const char **param_get_string_list(struct param_context *ctx, const char *section, const char *param, - const char *separator) +const char **param_get_string_list(struct param_context *ctx, const char *param, const char *separator, const char *section) { - struct param_opt *p = param_get(ctx, section, param); + struct param_opt *p = param_get(ctx, param, section); if (p == NULL) return NULL; @@ -127,18 +133,18 @@ const char **param_get_string_list(struct param_context *ctx, const char *sectio return str_list_make(ctx, p->value, separator); } -int param_set_string_list(struct param_context *ctx, const char *section, const char *param, const char **list) +int param_set_string_list(struct param_context *ctx, const char *param, const char **list, const char *section) { - struct param_opt *p = param_get_add(ctx, section, param); + struct param_opt *p = param_get_add(ctx, param, section); p->value = str_list_join(p, list, ' '); return 0; } -int param_get_int(struct param_context *ctx, const char *section, const char *param, int default_v) +int param_get_int(struct param_context *ctx, const char *param, int default_v, const char *section) { - const char *value = param_get_string(ctx, section, param); + const char *value = param_get_string(ctx, param, section); if (value) return strtol(value, NULL, 0); @@ -146,7 +152,7 @@ int param_get_int(struct param_context *ctx, const char *section, const char *pa return default_v; } -void param_set_int(struct param_context *ctx, const char *section, const char *param, int value) +void param_set_int(struct param_context *ctx, const char *param, int value, const char *section) { struct param_opt *p = param_get_add(ctx, section, param); @@ -156,9 +162,9 @@ void param_set_int(struct param_context *ctx, const char *section, const char *p p->value = talloc_asprintf(p, "%d", value); } -unsigned long param_get_ulong(struct param_context *ctx, const char *section, const char *param, unsigned long default_v) +unsigned long param_get_ulong(struct param_context *ctx, const char *param, unsigned long default_v, const char *section) { - const char *value = param_get_string(ctx, section, param); + const char *value = param_get_string(ctx, param, section); if (value) return strtoul(value, NULL, 0); @@ -166,9 +172,9 @@ unsigned long param_get_ulong(struct param_context *ctx, const char *section, co return default_v; } -void param_set_ulong(struct param_context *ctx, const char *section, const char *name, unsigned long value) +void param_set_ulong(struct param_context *ctx, const char *name, unsigned long value, const char *section) { - struct param_opt *p = param_get_add(ctx, section, name); + struct param_opt *p = param_get_add(ctx, name, section); if (!p) return; -- cgit From 2ba62662f8e2578153be3125eb557b9349ccfd3b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 28 Feb 2008 20:04:58 +0100 Subject: Remove sDefault as static variable. (This used to be commit 16f36ce499e93860dd535034a584ec2b93e7a172) --- source4/param/generic.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source4/param/generic.c') diff --git a/source4/param/generic.c b/source4/param/generic.c index 2327000fc9..b86e3ad234 100644 --- a/source4/param/generic.c +++ b/source4/param/generic.c @@ -259,11 +259,8 @@ int param_use(struct loadparm_context *lp_ctx, struct param_context *ctx) struct loadparm_service *service = lp_service(lp_ctx, section->name); if (service == NULL) - service = lp_add_service(lp_ctx, &sDefault, section->name); - lp_do_service_parameter(lp_ctx, - service, - param->key, - param->value); + service = lp_add_service(lp_ctx, lp_default_service(lp_ctx), section->name); + lp_do_service_parameter(lp_ctx, service, param->key, param->value); } } } -- cgit