diff options
Diffstat (limited to 'source3/param')
-rw-r--r-- | source3/param/loadparm.c | 313 | ||||
-rw-r--r-- | source3/param/params.c | 590 | ||||
-rw-r--r-- | source3/param/test_lp_load.c | 88 |
3 files changed, 249 insertions, 742 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 60a1fa4858..d91d34d29b 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -52,6 +52,7 @@ */ #include "includes.h" +#include "printing.h" bool bLoaded = False; @@ -340,6 +341,7 @@ struct global { int iKeepalive; int iminreceivefile; struct param_opt_struct *param_opt; + int cups_connection_timeout; }; static struct global Globals; @@ -2595,6 +2597,15 @@ static struct parm_struct parm_table[] = { .flags = FLAG_ADVANCED | FLAG_PRINT | FLAG_GLOBAL, }, { + .label = "cups connection timeout", + .type = P_INTEGER, + .p_class = P_GLOBAL, + .ptr = &Globals.cups_connection_timeout, + .special = NULL, + .enum_list = NULL, + .flags = FLAG_ADVANCED, + }, + { .label = "iprint server", .type = P_STRING, .p_class = P_GLOBAL, @@ -4561,6 +4572,54 @@ static void init_printer_values(struct service *pService) } } +/** + * Free the allocated data for one parameter for a given share. + */ +static void free_parameter(int snum, struct parm_struct parm) +{ + void *parm_ptr; + + if (parm.ptr == NULL); { + return; + } + + if (snum < 0) { + parm_ptr = parm.ptr; + } else if (parm.p_class != P_LOCAL) { + return; + } else { + parm_ptr = lp_local_ptr(snum, parm.ptr); + } + + if ((parm.type == P_STRING) || + (parm.type == P_USTRING)) + { + string_free((char**)parm_ptr); + } else if (parm.type == P_LIST) { + TALLOC_FREE(*((char***)parm_ptr)); + } +} + +/** + * Free the allocated parameter data for a share. + */ +static void free_parameters(int snum) +{ + uint32_t i; + + for (i=0; parm_table[i].label; i++) { + free_parameter(snum, parm_table[i]); + } +} + +/** + * Free the allocated global parameters. + */ +static void free_global_parameters(void) +{ + free_parameters(GLOBAL_SECTION_SNUM); +} + /*************************************************************************** Initialise the global parameter structure. ***************************************************************************/ @@ -4585,14 +4644,7 @@ static void init_globals(bool first_time_only) } done_init = True; } else { - for (i = 0; parm_table[i].label; i++) { - if ((parm_table[i].type == P_STRING || - parm_table[i].type == P_USTRING) && - parm_table[i].ptr) - { - string_free((char **)parm_table[i].ptr); - } - } + free_global_parameters(); } memset((void *)&Globals, '\0', sizeof(Globals)); @@ -4794,6 +4846,7 @@ static void init_globals(bool first_time_only) * to never expire, though, when this runs out the afs client will * forget the token. Set to 0 to get NEVERDATE.*/ Globals.iAfsTokenLifetime = 604800; + Globals.cups_connection_timeout = CUPS_DEFAULT_CONNECTION_TIMEOUT; /* these parameters are set to defaults that are more appropriate for the increasing samba install base: @@ -5235,6 +5288,7 @@ FN_GLOBAL_LIST(lp_svcctl_list, &Globals.szServicesList) FN_LOCAL_STRING(lp_cups_options, szCupsOptions) FN_GLOBAL_STRING(lp_cups_server, &Globals.szCupsServer) FN_GLOBAL_STRING(lp_iprint_server, &Globals.szIPrintServer) +FN_GLOBAL_INTEGER(lp_cups_connection_timeout, &Globals.cups_connection_timeout) FN_GLOBAL_CONST_STRING(lp_ctdbd_socket, &Globals.ctdbdSocket) FN_GLOBAL_LIST(lp_cluster_addresses, &Globals.szClusterAddresses) FN_GLOBAL_BOOL(lp_clustering, &Globals.clustering) @@ -5377,6 +5431,7 @@ static bool do_section(const char *pszSectionName, void *userdata); static void init_copymap(struct service *pservice); static bool hash_a_service(const char *name, int number); static void free_service_byindex(int iService); +static void free_param_opts(struct param_opt_struct **popts); static char * canonicalize_servicename(const char *name); static void show_parameter(int parmIndex); static bool is_synonym_of(int parm1, int parm2, bool *inverse); @@ -5631,14 +5686,42 @@ static void init_service(struct service *pservice) copy_service(pservice, &sDefault, NULL); } + +/** + * free a param_opts structure. + * param_opts handling should be moved to talloc; + * then this whole functions reduces to a TALLOC_FREE(). + */ + +static void free_param_opts(struct param_opt_struct **popts) +{ + struct param_opt_struct *opt, *next_opt; + + if (popts == NULL) { + return; + } + + if (*popts != NULL) { + DEBUG(5, ("Freeing parametrics:\n")); + } + opt = *popts; + while (opt != NULL) { + string_free(&opt->key); + string_free(&opt->value); + TALLOC_FREE(opt->list); + next_opt = opt->next; + SAFE_FREE(opt); + opt = next_opt; + } + *popts = NULL; +} + /*************************************************************************** Free the dynamically allocated parts of a service struct. ***************************************************************************/ static void free_service(struct service *pservice) { - int i; - struct param_opt_struct *data, *pdata; if (!pservice) return; @@ -5646,36 +5729,12 @@ static void free_service(struct service *pservice) DEBUG(5, ("free_service: Freeing service %s\n", pservice->szService)); + free_parameters(getservicebyname(pservice->szService, NULL)); + string_free(&pservice->szService); bitmap_free(pservice->copymap); - for (i = 0; parm_table[i].label; i++) { - if ((parm_table[i].type == P_STRING || - parm_table[i].type == P_USTRING) && - parm_table[i].p_class == P_LOCAL) - string_free((char **) - (((char *)pservice) + - PTR_DIFF(parm_table[i].ptr, &sDefault))); - else if (parm_table[i].type == P_LIST && - parm_table[i].p_class == P_LOCAL) - TALLOC_FREE(*((char ***) - (((char *)pservice) + - PTR_DIFF(parm_table[i].ptr, - &sDefault)))); - } - - data = pservice->param_opt; - if (data) - DEBUG(5,("Freeing parametrics:\n")); - while (data) { - DEBUG(5,("[%s = %s]\n", data->key, data->value)); - string_free(&data->key); - string_free(&data->value); - TALLOC_FREE(data->list); - pdata = data->next; - SAFE_FREE(data); - data = pdata; - } + free_param_opts(&pservice->param_opt); ZERO_STRUCTP(pservice); } @@ -5717,7 +5776,6 @@ static int add_a_service(const struct service *pservice, const char *name) int i; struct service tservice; int num_to_alloc = iNumServices + 1; - struct param_opt_struct *data, *pdata; tservice = *pservice; @@ -5727,16 +5785,7 @@ static int add_a_service(const struct service *pservice, const char *name) if (i >= 0) { /* Clean all parametric options for service */ /* They will be added during parsing again */ - data = ServicePtrs[i]->param_opt; - while (data) { - string_free(&data->key); - string_free(&data->value); - TALLOC_FREE(data->list); - pdata = data->next; - SAFE_FREE(data); - data = pdata; - } - ServicePtrs[i]->param_opt = NULL; + free_param_opts(&ServicePtrs[i]->param_opt); return (i); } } @@ -6395,13 +6444,51 @@ static int getservicebyname(const char *pszServiceName, struct service *pservice If pcopymapDest is NULL then copy all fields ***************************************************************************/ +/** + * Add a parametric option to a param_opt_struct, + * replacing old value, if already present. + */ +static void set_param_opt(struct param_opt_struct **opt_list, + const char *opt_name, + const char *opt_value) +{ + struct param_opt_struct *new_opt, *opt; + bool not_added; + + if (opt_list == NULL) { + return; + } + + opt = *opt_list; + not_added = true; + + /* Traverse destination */ + while (opt) { + /* If we already have same option, override it */ + if (strwicmp(opt->key, opt_name) == 0) { + string_free(&opt->value); + TALLOC_FREE(opt->list); + opt->value = SMB_STRDUP(opt_value); + not_added = false; + break; + } + opt = opt->next; + } + if (not_added) { + new_opt = SMB_XMALLOC_P(struct param_opt_struct); + new_opt->key = SMB_STRDUP(opt_name); + new_opt->value = SMB_STRDUP(opt_value); + new_opt->list = NULL; + DLIST_ADD(*opt_list, new_opt); + } +} + static void copy_service(struct service *pserviceDest, struct service *pserviceSource, struct bitmap *pcopymapDest) { int i; bool bcopyall = (pcopymapDest == NULL); - struct param_opt_struct *data, *pdata, *paramo; - bool not_added; + struct param_opt_struct *data; for (i = 0; parm_table[i].label; i++) if (parm_table[i].ptr && parm_table[i].p_class == P_LOCAL && @@ -6442,7 +6529,7 @@ static void copy_service(struct service *pserviceDest, struct service *pserviceS break; case P_LIST: TALLOC_FREE(*((char ***)dest_ptr)); - str_list_copy(NULL, (char ***)dest_ptr, + *((char ***)dest_ptr) = str_list_copy(NULL, *(const char ***)src_ptr); break; default: @@ -6459,27 +6546,7 @@ static void copy_service(struct service *pserviceDest, struct service *pserviceS data = pserviceSource->param_opt; while (data) { - not_added = True; - pdata = pserviceDest->param_opt; - /* Traverse destination */ - while (pdata) { - /* If we already have same option, override it */ - if (strwicmp(pdata->key, data->key) == 0) { - string_free(&pdata->value); - TALLOC_FREE(data->list); - pdata->value = SMB_STRDUP(data->value); - not_added = False; - break; - } - pdata = pdata->next; - } - if (not_added) { - paramo = SMB_XMALLOC_P(struct param_opt_struct); - paramo->key = SMB_STRDUP(data->key); - paramo->value = SMB_STRDUP(data->value); - paramo->list = NULL; - DLIST_ADD(pserviceDest->param_opt, paramo); - } + set_param_opt(&pserviceDest->param_opt, data->key, data->value); data = data->next; } } @@ -6547,7 +6614,7 @@ static struct smbconf_ctx *lp_smbconf_ctx(void) return conf_ctx; } -static bool process_registry_service(struct smbconf_service *service) +static bool process_smbconf_service(struct smbconf_service *service) { uint32_t count; bool ret; @@ -6603,7 +6670,7 @@ static bool process_registry_globals(void) goto done; } - ret = process_registry_service(service); + ret = process_smbconf_service(service); if (!ret) { goto done; } @@ -6641,7 +6708,7 @@ static bool process_registry_shares(void) if (strequal(service[count]->name, GLOBAL_NAME)) { continue; } - ret = process_registry_service(service[count]); + ret = process_smbconf_service(service[count]); if (!ret) { goto done; } @@ -6863,7 +6930,7 @@ static bool handle_include(int snum, const char *pszParmValue, char **ptr) string_set(ptr, fname); - if (file_exist(fname, NULL)) { + if (file_exist(fname)) { bool ret = pm_process(fname, do_section, do_parameter, NULL); SAFE_FREE(fname); return ret; @@ -7144,14 +7211,11 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue int parmnum, i; void *parm_ptr = NULL; /* where we are going to store the result */ void *def_ptr = NULL; - struct param_opt_struct *paramo, *data; - bool not_added; + struct param_opt_struct **opt_list; parmnum = map_parameter(pszParmName); if (parmnum < 0) { - TALLOC_CTX *frame; - if (strchr(pszParmName, ':') == NULL) { DEBUG(0, ("Ignoring unknown parameter \"%s\"\n", pszParmName)); @@ -7162,37 +7226,10 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue * We've got a parametric option */ - frame = talloc_stackframe(); + opt_list = (snum < 0) + ? &Globals.param_opt : &ServicePtrs[snum]->param_opt; + set_param_opt(opt_list, pszParmName, pszParmValue); - not_added = True; - data = (snum < 0) - ? Globals.param_opt : ServicePtrs[snum]->param_opt; - /* Traverse destination */ - while (data) { - /* If we already have same option, override it */ - if (strwicmp(data->key, pszParmName) == 0) { - string_free(&data->value); - TALLOC_FREE(data->list); - data->value = SMB_STRDUP(pszParmValue); - not_added = False; - break; - } - data = data->next; - } - if (not_added) { - paramo = SMB_XMALLOC_P(struct param_opt_struct); - paramo->key = SMB_STRDUP(pszParmName); - paramo->value = SMB_STRDUP(pszParmValue); - paramo->list = NULL; - if (snum < 0) { - DLIST_ADD(Globals.param_opt, paramo); - } else { - DLIST_ADD(ServicePtrs[snum]->param_opt, - paramo); - } - } - - TALLOC_FREE(frame); return (True); } @@ -7213,9 +7250,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue pszParmName)); return (True); } - parm_ptr = - ((char *)ServicePtrs[snum]) + PTR_DIFF(def_ptr, - &sDefault); + parm_ptr = lp_local_ptr(snum, def_ptr); } if (snum >= 0) { @@ -7388,7 +7423,7 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2) return (*((char *)ptr1) == *((char *)ptr2)); case P_LIST: - return str_list_compare(*(char ***)ptr1, *(char ***)ptr2); + return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2); case P_STRING: case P_USTRING: @@ -7477,8 +7512,8 @@ static bool is_default(int i) return False; switch (parm_table[i].type) { case P_LIST: - return str_list_compare (parm_table[i].def.lvalue, - *(char ***)parm_table[i].ptr); + return str_list_equal((const char **)parm_table[i].def.lvalue, + *(const char ***)parm_table[i].ptr); case P_STRING: case P_USTRING: return strequal(parm_table[i].def.svalue, @@ -7813,7 +7848,7 @@ static void lp_add_auto_services(char *str) Auto-load one printer. ***************************************************************************/ -void lp_add_one_printer(char *name, char *comment) +void lp_add_one_printer(const char *name, const char *comment, void *pdata) { int printers = lp_servicenumber(PRINTERS_NAME); int i; @@ -7892,9 +7927,8 @@ static void lp_save_defaults(void) continue; switch (parm_table[i].type) { case P_LIST: - str_list_copy( - NULL, &(parm_table[i].def.lvalue), - *(const char ***)parm_table[i].ptr); + parm_table[i].def.lvalue = str_list_copy( + NULL, *(const char ***)parm_table[i].ptr); break; case P_STRING: case P_USTRING: @@ -8351,7 +8385,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i return -1; } - lines = fd_lines_load(fd, &numlines, MAX_USERSHARE_FILE_SIZE); + lines = fd_lines_load(fd, &numlines, MAX_USERSHARE_FILE_SIZE, NULL); close(fd); if (lines == NULL) { @@ -8366,7 +8400,7 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i /* Should we allow printers to be shared... ? */ ctx = talloc_init("usershare_sd_xctx"); if (!ctx) { - file_lines_free(lines); + TALLOC_FREE(lines); return 1; } @@ -8374,11 +8408,11 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i iService, lines, numlines, &sharepath, &comment, &psd, &guest_ok) != USERSHARE_OK) { talloc_destroy(ctx); - file_lines_free(lines); + TALLOC_FREE(lines); return -1; } - file_lines_free(lines); + TALLOC_FREE(lines); /* Everything ok - add the service possibly using a template. */ if (iService < 0) { @@ -8721,17 +8755,7 @@ void gfree_loadparm(void) /* Now release all resources allocated to global parameters and the default service */ - for (i = 0; parm_table[i].label; i++) - { - if ( parm_table[i].type == P_STRING - || parm_table[i].type == P_USTRING ) - { - string_free( (char**)parm_table[i].ptr ); - } - else if (parm_table[i].type == P_LIST) { - TALLOC_FREE( *((char***)parm_table[i].ptr) ); - } - } + free_global_parameters(); } @@ -8752,9 +8776,6 @@ bool lp_is_in_client(void) return in_client; } - - - /*************************************************************************** Load the services array from the services file. Return True on success, False on failure. @@ -8770,7 +8791,6 @@ bool lp_load_ex(const char *pszFname, { char *n2 = NULL; bool bRetval; - struct param_opt_struct *data, *pdata; bRetval = False; @@ -8788,22 +8808,11 @@ bool lp_load_ex(const char *pszFname, lp_save_defaults(); } + free_param_opts(&Globals.param_opt); + /* We get sections first, so have to start 'behind' to make up */ iServiceIndex = -1; - if (Globals.param_opt != NULL) { - data = Globals.param_opt; - while (data) { - string_free(&data->key); - string_free(&data->value); - TALLOC_FREE(data->list); - pdata = data->next; - SAFE_FREE(data); - data = pdata; - } - Globals.param_opt = NULL; - } - if (lp_config_backend_is_file()) { n2 = alloc_sub_basic(get_current_username(), current_user_info.domain, diff --git a/source3/param/params.c b/source3/param/params.c deleted file mode 100644 index 478376c9e9..0000000000 --- a/source3/param/params.c +++ /dev/null @@ -1,590 +0,0 @@ -/* -------------------------------------------------------------------------- ** - * Microsoft Network Services for Unix, AKA., Andrew Tridgell's SAMBA. - * - * This module Copyright (C) 1990-1998 Karl Auer - * - * Rewritten almost completely by Christopher R. Hertel, 1997. - * This module Copyright (C) 1997-1998 by Christopher R. Hertel - * - * -------------------------------------------------------------------------- ** - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - * - * -------------------------------------------------------------------------- ** - * - * Module name: params - * - * -------------------------------------------------------------------------- ** - * - * This module performs lexical analysis and initial parsing of a - * Windows-like parameter file. It recognizes and handles four token - * types: section-name, parameter-name, parameter-value, and - * end-of-file. Comments and line continuation are handled - * internally. - * - * The entry point to the module is function pm_process(). This - * function opens the source file, calls the Parse() function to parse - * the input, and then closes the file when either the EOF is reached - * or a fatal error is encountered. - * - * A sample parameter file might look like this: - * - * [section one] - * parameter one = value string - * parameter two = another value - * [section two] - * new parameter = some value or t'other - * - * The parameter file is divided into sections by section headers: - * section names enclosed in square brackets (eg. [section one]). - * Each section contains parameter lines, each of which consist of a - * parameter name and value delimited by an equal sign. Roughly, the - * syntax is: - * - * <file> :== { <section> } EOF - * - * <section> :== <section header> { <parameter line> } - * - * <section header> :== '[' NAME ']' - * - * <parameter line> :== NAME '=' VALUE '\n' - * - * Blank lines and comment lines are ignored. Comment lines are lines - * beginning with either a semicolon (';') or a pound sign ('#'). - * - * All whitespace in section names and parameter names is compressed - * to single spaces. Leading and trailing whitespace is stipped from - * both names and values. - * - * Only the first equals sign in a parameter line is significant. - * Parameter values may contain equals signs, square brackets and - * semicolons. Internal whitespace is retained in parameter values, - * with the exception of the '\r' character, which is stripped for - * historic reasons. Parameter names may not start with a left square - * bracket, an equal sign, a pound sign, or a semicolon, because these - * are used to identify other tokens. - * - * -------------------------------------------------------------------------- ** - */ - -#include "includes.h" - -/* -------------------------------------------------------------------------- ** - * Constants... - */ - -#define BUFR_INC 1024 - - -/* -------------------------------------------------------------------------- ** - * Variables... - * - * DEBUGLEVEL - The ubiquitous DEBUGLEVEL. This determines which DEBUG() - * messages will be produced. - * bufr - pointer to a global buffer. This is probably a kludge, - * but it was the nicest kludge I could think of (for now). - * bSize - The size of the global buffer <bufr>. - */ - -/* we can't use FILE* due to the 256 fd limit - use this cheap hack - instead */ -typedef struct { - char *buf; - char *p; - size_t size; - char *end_section_p; -} myFILE; - -static int mygetc(myFILE *f) -{ - if (f->p >= f->buf+f->size) - return EOF; - /* be sure to return chars >127 as positive values */ - return (int)( *(f->p++) & 0x00FF ); -} - -static void myfile_close(myFILE *f) -{ - if (!f) - return; - SAFE_FREE(f->buf); - SAFE_FREE(f); -} - -/* Find the end of the section. We must use mb functions for this. */ -static int FindSectionEnd(myFILE *f) -{ - f->end_section_p = strchr_m(f->p, ']'); - return f->end_section_p ? 1 : 0; -} - -static int AtSectionEnd(myFILE *f) -{ - if (f->p == f->end_section_p + 1) { - f->end_section_p = NULL; - return 1; - } - return 0; -} - -/* -------------------------------------------------------------------------- ** - * Functions... - */ - /* ------------------------------------------------------------------------ ** - * Scan past whitespace (see ctype(3C)) and return the first non-whitespace - * character, or newline, or EOF. - * - * Input: InFile - Input source. - * - * Output: The next non-whitespace character in the input stream. - * - * Notes: Because the config files use a line-oriented grammar, we - * explicitly exclude the newline character from the list of - * whitespace characters. - * - Note that both EOF (-1) and the nul character ('\0') are - * considered end-of-file markers. - * - * ------------------------------------------------------------------------ ** - */ - -static int EatWhitespace( myFILE *InFile ) -{ - int c; - - for( c = mygetc( InFile ); isspace( c ) && ('\n' != c); c = mygetc( InFile ) ) - ; - return( c ); -} - - /* ------------------------------------------------------------------------ ** - * Scan to the end of a comment. - * - * Input: InFile - Input source. - * - * Output: The character that marks the end of the comment. Normally, - * this will be a newline, but it *might* be an EOF. - * - * Notes: Because the config files use a line-oriented grammar, we - * explicitly exclude the newline character from the list of - * whitespace characters. - * - Note that both EOF (-1) and the nul character ('\0') are - * considered end-of-file markers. - * - * ------------------------------------------------------------------------ ** - */ - -static int EatComment( myFILE *InFile ) -{ - int c; - - for( c = mygetc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = mygetc( InFile ) ) - ; - return( c ); -} - -/***************************************************************************** - * Scan backards within a string to discover if the last non-whitespace - * character is a line-continuation character ('\\'). - * - * Input: line - A pointer to a buffer containing the string to be - * scanned. - * pos - This is taken to be the offset of the end of the - * string. This position is *not* scanned. - * - * Output: The offset of the '\\' character if it was found, or -1 to - * indicate that it was not. - * - *****************************************************************************/ - -static int Continuation(uint8_t *line, int pos ) -{ - pos--; - while( (pos >= 0) && isspace((int)line[pos])) - pos--; - - return (((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); -} - -/* ------------------------------------------------------------------------ ** - * Scan a section name, and pass the name to function sfunc(). - * - * Input: InFile - Input source. - * sfunc - Pointer to the function to be called if the section - * name is successfully read. - * - * Output: True if the section name was read and True was returned from - * <sfunc>. False if <sfunc> failed or if a lexical error was - * encountered. - * - * ------------------------------------------------------------------------ ** - */ - -static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *, void *), void *userdata ) -{ - int c; - int i; - int end; - const char *func = "params.c:Section() -"; - - i = 0; /* <i> is the offset of the next free byte in bufr[] and */ - end = 0; /* <end> is the current "end of string" offset. In most */ - /* cases these will be the same, but if the last */ - /* character written to bufr[] is a space, then <end> */ - /* will be one less than <i>. */ - - - /* Find the end of the section. We must use mb functions for this. */ - if (!FindSectionEnd(InFile)) { - DEBUG(0, ("%s No terminating ']' character in section.\n", func) ); - return False; - } - - c = EatWhitespace( InFile ); /* We've already got the '['. Scan */ - /* past initial white space. */ - - while( (EOF != c) && (c > 0) ) { - /* Check that the buffer is big enough for the next character. */ - if( i > (buf->length - 2) ) { - uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR(buf->data, buf->length+BUFR_INC ); - if(!tb) { - DEBUG(0, ("%s Memory re-allocation failure.", func) ); - return False; - } - buf->data = tb; - buf->length += BUFR_INC; - } - - /* Handle a single character other than section end. */ - switch( c ) { - case '\n': /* Got newline before closing ']'. */ - i = Continuation( buf->data, i ); /* Check for line continuation. */ - if( i < 0 ) { - buf->data[end] = '\0'; - DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, buf->data )); - return False; - } - end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i); - c = mygetc( InFile ); /* Continue with next line. */ - break; - - default: /* All else are a valid name chars. */ - if(isspace( c )) { - /* One space per whitespace region. */ - buf->data[end] = ' '; - i = end + 1; - c = EatWhitespace( InFile ); - } else { - buf->data[i++] = c; - end = i; - c = mygetc( InFile ); - } - } - - if (AtSectionEnd(InFile)) { - /* Got to the closing bracket. */ - buf->data[end] = '\0'; - if( 0 == end ) { - /* Don't allow an empty name. */ - DEBUG(0, ("%s Empty section name in configuration file.\n", func )); - return False; - } - if( !sfunc((char *)buf->data, userdata) ) /* Got a valid name. Deal with it. */ - return False; - EatComment( InFile ); /* Finish off the line. */ - return True; - } - - } - - /* We arrive here if we've met the EOF before the closing bracket. */ - DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, buf->data )); - return False; -} - -/* ------------------------------------------------------------------------ ** - * Scan a parameter name and value, and pass these two fields to pfunc(). - * - * Input: InFile - The input source. - * pfunc - A pointer to the function that will be called to - * process the parameter, once it has been scanned. - * c - The first character of the parameter name, which - * would have been read by Parse(). Unlike a comment - * line or a section header, there is no lead-in - * character that can be discarded. - * - * Output: True if the parameter name and value were scanned and processed - * successfully, else False. - * - * Notes: This function is in two parts. The first loop scans the - * parameter name. Internal whitespace is compressed, and an - * equal sign (=) terminates the token. Leading and trailing - * whitespace is discarded. The second loop scans the parameter - * value. When both have been successfully identified, they are - * passed to pfunc() for processing. - * - * ------------------------------------------------------------------------ ** - */ - -static bool Parameter( DATA_BLOB *buf, myFILE *InFile, bool (*pfunc)(const char *, const char *, void *), int c, void *userdata ) -{ - int i = 0; /* Position within bufr. */ - int end = 0; /* bufr[end] is current end-of-string. */ - int vstart = 0; /* Starting position of the parameter value. */ - const char *func = "params.c:Parameter() -"; - - /* Read the parameter name. */ - while( 0 == vstart ) { - /* Loop until we've found the start of the value. */ - if( i > (buf->length - 2) ) { - /* Ensure there's space for next char. */ - uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR( buf->data, buf->length + BUFR_INC ); - if (!tb) { - DEBUG(0, ("%s Memory re-allocation failure.", func) ); - return False; - } - buf->data = tb; - buf->length += BUFR_INC; - } - - switch(c) { - case '=': /* Equal sign marks end of param name. */ - if( 0 == end ) { - /* Don't allow an empty name. */ - DEBUG(0, ("%s Invalid parameter name in config. file.\n", func )); - return False; - } - buf->data[end++] = '\0'; /* Mark end of string & advance. */ - i = end; /* New string starts here. */ - vstart = end; /* New string is parameter value. */ - buf->data[i] = '\0'; /* New string is nul, for now. */ - break; - - case '\n': /* Find continuation char, else error. */ - i = Continuation( buf->data, i ); - if( i < 0 ) { - buf->data[end] = '\0'; - DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, buf->data )); - return True; - } - end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i); - c = mygetc( InFile ); /* Read past eoln. */ - break; - - case '\0': /* Shouldn't have EOF within param name. */ - case EOF: - buf->data[i] = '\0'; - DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, buf->data )); - return True; - - default: - if(isspace( c )) { - /* One ' ' per whitespace region. */ - buf->data[end] = ' '; - i = end + 1; - c = EatWhitespace( InFile ); - } else { - buf->data[i++] = c; - end = i; - c = mygetc( InFile ); - } - } - } - - /* Now parse the value. */ - c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */ - while( (EOF !=c) && (c > 0) ) { - if( i > (buf->length - 2) ) { - /* Make sure there's enough room. */ - uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR( buf->data, buf->length + BUFR_INC ); - if (!tb) { - DEBUG(0, ("%s Memory re-allocation failure.", func)); - return False; - } - buf->data = tb; - buf->length += BUFR_INC; - } - - switch(c) { - case '\r': /* Explicitly remove '\r' because the older */ - c = mygetc( InFile ); /* version called fgets_slash() which also */ - break; /* removes them. */ - - case '\n': /* Marks end of value unless there's a '\'. */ - i = Continuation( buf->data, i ); - if( i < 0 ) { - c = 0; - } else { - for( end = i; (end >= 0) && isspace((int)buf->data[end]); end-- ) - ; - c = mygetc( InFile ); - } - break; - - default: /* All others verbatim. Note that spaces do not advance <end>. This allows trimming */ - buf->data[i++] = c; - if( !isspace( c ) ) /* of whitespace at the end of the line. */ - end = i; - c = mygetc( InFile ); - break; - } - } - buf->data[end] = '\0'; /* End of value. */ - - return( pfunc( (char *)buf->data, (char *)&buf->data[vstart], userdata ) ); /* Pass name & value to pfunc(). */ -} - -/* ------------------------------------------------------------------------ ** - * Scan & parse the input. - * - * Input: InFile - Input source. - * sfunc - Function to be called when a section name is scanned. - * See Section(). - * pfunc - Function to be called when a parameter is scanned. - * See Parameter(). - * - * Output: True if the file was successfully scanned, else False. - * - * Notes: The input can be viewed in terms of 'lines'. There are four - * types of lines: - * Blank - May contain whitespace, otherwise empty. - * Comment - First non-whitespace character is a ';' or '#'. - * The remainder of the line is ignored. - * Section - First non-whitespace character is a '['. - * Parameter - The default case. - * - * ------------------------------------------------------------------------ ** - */ - -static bool Parse( DATA_BLOB *buf, myFILE *InFile, - bool (*sfunc)(const char *, void *), - bool (*pfunc)(const char *, const char *, void *), - void *userdata) -{ - int c; - - c = EatWhitespace( InFile ); - while( (EOF != c) && (c > 0) ) { - switch( c ) { - case '\n': /* Blank line. */ - c = EatWhitespace( InFile ); - break; - - case ';': /* Comment line. */ - case '#': - c = EatComment( InFile ); - break; - - case '[': /* Section Header. */ - if( !Section( buf, InFile, sfunc, userdata ) ) - return False; - c = EatWhitespace( InFile ); - break; - - case '\\': /* Bogus backslash. */ - c = EatWhitespace( InFile ); - break; - - default: /* Parameter line. */ - if( !Parameter( buf, InFile, pfunc, c, userdata ) ) - return False; - c = EatWhitespace( InFile ); - break; - } - } - return True; -} - -/* ------------------------------------------------------------------------ ** - * Open a configuration file. - * - * Input: FileName - The pathname of the config file to be opened. - * - * Output: A pointer of type (char **) to the lines of the file - * - * ------------------------------------------------------------------------ ** - */ - -static myFILE *OpenConfFile( const char *FileName ) -{ - const char *func = "params.c:OpenConfFile() -"; - int lvl = lp_is_in_client() ? 1 : 0; - myFILE *ret; - - ret = SMB_MALLOC_P(myFILE); - if (!ret) - return NULL; - - ret->buf = file_load(FileName, &ret->size, 0); - if( NULL == ret->buf ) { - DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n", - func, FileName, strerror(errno)) ); - SAFE_FREE(ret); - return NULL; - } - - ret->p = ret->buf; - ret->end_section_p = NULL; - return( ret ); -} - -/* ------------------------------------------------------------------------ ** - * Process the named parameter file. - * - * Input: FileName - The pathname of the parameter file to be opened. - * sfunc - A pointer to a function that will be called when - * a section name is discovered. - * pfunc - A pointer to a function that will be called when - * a parameter name and value are discovered. - * - * Output: TRUE if the file was successfully parsed, else FALSE. - * - * ------------------------------------------------------------------------ ** - */ - -bool pm_process( const char *FileName, - bool (*sfunc)(const char *, void *), - bool (*pfunc)(const char *, const char *, void *), - void *userdata) -{ - int result; - myFILE *InFile; - const char *func = "params.c:pm_process() -"; - DATA_BLOB buf; - - InFile = OpenConfFile( FileName ); /* Open the config file. */ - if( NULL == InFile ) - return False; - - DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); - - buf = data_blob(NULL, 256); - - if (buf.data == NULL) { - DEBUG(0,("%s memory allocation failure.\n", func)); - myfile_close(InFile); - return False; - } - - result = Parse( &buf, InFile, sfunc, pfunc, userdata ); - data_blob_free(&buf); - - myfile_close(InFile); - - if( !result ) { - DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); - return False; - } - - return True; -} diff --git a/source3/param/test_lp_load.c b/source3/param/test_lp_load.c new file mode 100644 index 0000000000..1ec123e70a --- /dev/null +++ b/source3/param/test_lp_load.c @@ -0,0 +1,88 @@ +/* + * Unix SMB/CIFS implementation. + * Test for lp_load() + * Copyright (C) Michael Adam 2008 + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" + +extern bool AllowDebugChange; + +int main(int argc, const char **argv) +{ + const char *config_file = get_dyn_CONFIGFILE(); + int ret = 0; + poptContext pc; + char *count_str = NULL; + int i, count = 1; + + struct poptOption long_options[] = { + POPT_AUTOHELP + {"count", 'c', POPT_ARG_STRING, &count_str, 1, + "Load config <count> number of times"}, + POPT_COMMON_DEBUGLEVEL + POPT_TABLEEND + }; + + TALLOC_CTX *frame = talloc_stackframe(); + + load_case_tables(); + DEBUGLEVEL_CLASS[DBGC_ALL] = 0; + + pc = poptGetContext(NULL, argc, argv, long_options, + POPT_CONTEXT_KEEP_FIRST); + poptSetOtherOptionHelp(pc, "[OPTION...] <config-file>"); + + while(poptGetNextOpt(pc) != -1); + + setup_logging(poptGetArg(pc), True); + + if (poptPeekArg(pc)) { + config_file = poptGetArg(pc); + } + + poptFreeContext(pc); + + if (count_str != NULL) { + count = atoi(count_str); + } + + dbf = x_stderr; + /* Don't let the debuglevel be changed by smb.conf. */ + AllowDebugChange = False; + + for (i=0; i < count; i++) { + printf("call lp_load() #%d: ", i+1); + if (!lp_load_with_registry_shares(config_file, + False, /* global only */ + True, /* save defaults */ + False, /*add_ipc */ + True)) /*init globals */ + { + printf("ERROR.\n"); + ret = 1; + goto done; + } + printf("ok.\n"); + } + + +done: + gfree_loadparm(); + TALLOC_FREE(frame); + return ret; +} + |