From 0e8fd3398771da2f016d72830179507f3edda51b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 4 May 1996 07:50:46 +0000 Subject: Initial version imported to CVS (This used to be commit 291551d80711daab7b7581720bcd9a08d6096517) --- source3/param/params.c | 335 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 335 insertions(+) create mode 100644 source3/param/params.c (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c new file mode 100644 index 0000000000..b9d61382a1 --- /dev/null +++ b/source3/param/params.c @@ -0,0 +1,335 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + Parameter loading utlities + Copyright (C) Karl Auer 1993,1994 + + 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. +*/ + +/************************************************************************** +PARAMS.C + +Copyright (C) 1990, 1991, 1992, 1993, 1994 Karl Auer + +This module provides for streamlines retrieval of information from a +Windows-like parameter files. There is a function which will search for +all sections in the file and call a specified function with each. There is +a similar function which will call a specified function for all parameters +in a section. The idea is that you pass the addresses of suitable functions +to a single function in this module which will then enumerate all sections, +and within each section all parameters, to your program. + +Parameter files contain text lines (newline delimited) which consist of +either a section name in square brackets or a parameter name, delimited +from the parameter value by an equals sign. Blank lines or lines where the +first non-whitespace character is a colon are ignored. All whitespace in +section names and parameter names is compressed to single spaces. Leading +and trailing whitespace on parameter names and parameter values is stripped. + +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. Parameter names may not start +with a square bracket, an equals sign or a semicolon, for obvious reasons. + +A sample parameter file might look like this: + +[things] +this=1 +that=2 +[other things] +the other = 3 + +**************************************************************************/ + +#include "includes.h" + +#include "smb.h" +#include "params.h" + +/* local variable pointing to passed filename */ +static char *pszParmFile = NULL; +extern int DEBUGLEVEL; + +/* local prototypes */ +static BOOL enumerate_parameters(FILE *infile, PM_PARMFUNC pfunc); +static BOOL enumerate_sections(FILE *infile, + PM_SECFUNC sfunc, PM_PARMFUNC pfunc); + +/* prototypes for local toolbox functions */ +static void trimleft(char *psz); +static void trimright(char *psz); +static void collapse_spaces(char *psz); +static int firstnonwhite(char *psz); + +/************************************************************************** +Identifies all parameters in the current section, calls the parameter +function for each. Ignores comment lines, stops and backs up in file when +a section is encountered. Returns True on success, False on error. +**************************************************************************/ +static BOOL enumerate_parameters(FILE *fileIn, PM_PARMFUNC pfunc) +{ + pstring szBuf; + char *pszTemp; + BOOL bRetval; + long lFileOffset; + int cTemp; + BOOL bParmFound; + + bRetval = False; + bParmFound = False; + while (True) + { + /* first remember where we are */ + if ((lFileOffset = ftell(fileIn)) >= 0L) + { + /* then get and check a line */ + if (fgets_slash(szBuf, sizeof(szBuf)-1, fileIn) == NULL) + { + /* stop - return OK unless file error */ + bRetval = !ferror(fileIn); + if (!bRetval) + DEBUG(0,( "Read error on configuration file (enumerating parameters)!\n")); + break; + } + else + /* if first non-white is a '[', stop (new section) */ + if ((cTemp = firstnonwhite(szBuf)) == '[') + { + /* restore position to start of new section */ + if (fseek(fileIn, lFileOffset, SEEK_SET) < 0L) + { + DEBUG(0,( "Seek error on configuration file!\n")); + break; + } + + /* return success */ + bRetval = True; + break; + } + else + /* if it's a semicolon or line is blank, ignore the line */ + if (!cTemp || strchr(";#",cTemp)) + { + continue; + } + else + /* if no equals sign and line contains non-whitespace */ + /* then line is badly formed */ + if ((pszTemp = strchr(szBuf, '=')) == NULL) + { + DEBUG(0,( "Ignoring badly formed line: %s", szBuf)); + } + else + { + /* Note that we have found a parameter */ + bParmFound = True; + /* cut line at the equals sign */ + *pszTemp++ = '\0'; + /* trim leading and trailing space from both halves */ + trimright(szBuf); + trimleft(szBuf); + trimright(pszTemp); + trimleft(pszTemp); + /* process the parameter iff passed pointer not NULL */ + if (pfunc != NULL) + if (!pfunc(szBuf, pszTemp)) + break; + } + } + } + return (bRetval); +} + + +/*********************************************************************** +Close up s by n chars, at offset start. +***********************************************************************/ +static void closestr(char *s, int start, int n) +{ + char *src; + char *dest; + int len; + + if (n > 0) + if ((src = dest = s) != NULL) + { + len = strlen(s); + if (start >= 0 && start < len - n) + { + src += start + n; + dest += start; + + while (*src) + *dest++ = *src++; + *dest = '\0'; + } + } +} + +/************************************************************************** +Identifies all sections in the parameter file, calls passed section_func() +for each, passing the section name, then calls enumerate_parameters(). +Returns True on success, False on failure. Note that the section and +parameter names will have all internal whitespace areas collapsed to a +single space for processing. +**************************************************************************/ +static BOOL enumerate_sections(FILE *fileIn, + PM_SECFUNC sfunc, PM_PARMFUNC pfunc) +{ + pstring szBuf; + BOOL bRetval; + BOOL bSectionFound; + + /* this makes sure we get include lines right */ + enumerate_parameters(fileIn, pfunc); + + bRetval = False; + bSectionFound = False; + while (True) + { + if (fgets_slash(szBuf, sizeof(szBuf)-1, fileIn) == NULL) + { + /* stop - return OK unless file error */ + bRetval = !ferror(fileIn); + if (!bRetval) + DEBUG(0,( "Read error on configuration file (enumerating sections)!\n")); + break; + } + else + { + trimleft(szBuf); + trimright(szBuf); + if (szBuf[0] == '[') + { + closestr(szBuf, 0, 1); + if (strlen(szBuf) > 1) + if (szBuf[strlen(szBuf) - 1] == ']') + { + /* found a section - note the fact */ + bSectionFound = True; + /* remove trailing metabracket */ + szBuf[strlen(szBuf) - 1] = '\0'; + /* remove leading and trailing whitespace from name */ + trimleft(szBuf); + trimright(szBuf); + /* reduce all internal whitespace to one space */ + collapse_spaces(szBuf); + /* process it - stop if the processing fails */ + if (sfunc != NULL) + if (!sfunc(szBuf)) + break; + if (!enumerate_parameters(fileIn, pfunc)) + break; + } + } + } + } + + return (bRetval); +} + +/************************************************************************** +Process the passed parameter file. + +Returns True if successful, else False. +**************************************************************************/ +BOOL pm_process(char *pszFileName, PM_SECFUNC sfunc, PM_PARMFUNC pfunc) +{ + FILE *fileIn; + BOOL bRetval; + + bRetval = False; + + /* record the filename for use in error messages one day... */ + pszParmFile = pszFileName; + + if (pszParmFile == NULL || strlen(pszParmFile) < 1) + DEBUG(0,( "No configuration filename specified!\n")); + else + if ((fileIn = fopen(pszParmFile, "r")) == NULL) + DEBUG(0,( "Unable to open configuration file \"%s\"!\n", pszParmFile)); + else + { + DEBUG(2,( "Processing configuration file \"%s\"\n", pszParmFile)); + bRetval = enumerate_sections(fileIn, sfunc, pfunc); + fclose(fileIn); + } + + if (!bRetval) + DEBUG(0,("pm_process retuned false\n")); + return (bRetval); +} + + +/************************************************************************** +Strip all leading whitespace from a string. +**************************************************************************/ +static void trimleft(char *psz) +{ + char *pszDest; + + pszDest = psz; + if (psz != NULL) + { + while (*psz != '\0' && isspace(*psz)) + psz++; + while (*psz != '\0') + *pszDest++ = *psz++; + *pszDest = '\0'; + } +} + +/************************************************************************** +Strip all trailing whitespace from a string. +**************************************************************************/ +static void trimright(char *psz) +{ + char *pszTemp; + + if (psz != NULL && psz[0] != '\0') + { + pszTemp = psz + strlen(psz) - 1; + while (isspace(*pszTemp)) + *pszTemp-- = '\0'; + } +} + +/*********************************************************************** +Collapse each whitespace area in a string to a single space. +***********************************************************************/ +static void collapse_spaces(char *psz) +{ + while (*psz) + if (isspace(*psz)) + { + *psz++ = ' '; + trimleft(psz); + } + else + psz++; +} + +/************************************************************************** +Return the value of the first non-white character in the specified string. +The terminating NUL counts as non-white for the purposes of this function. +Note - no check for a NULL string! What would we return? +**************************************************************************/ +static int firstnonwhite(char *psz) +{ + while (isspace(*psz) && (*psz != '\0')) + psz++; + return (*psz); +} -- cgit From a2c1623827406667a4f2f058c24f1d971f6627f8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Jun 1996 06:42:03 +0000 Subject: a huge pile of changes :-) The biggest thing is the integration of Lukes new nmbd. Its still largely untested, so we will really need some feedback I've also added auto prototype generation and cleaned up a lot of minor things as a result (This used to be commit 0d8dcfa13c527ec2c8aca39ba49c09e4e694b26c) --- source3/param/params.c | 136 +++++++++++++++++++++++-------------------------- 1 file changed, 64 insertions(+), 72 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index b9d61382a1..d5d841dceb 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -63,23 +63,74 @@ the other = 3 static char *pszParmFile = NULL; extern int DEBUGLEVEL; -/* local prototypes */ -static BOOL enumerate_parameters(FILE *infile, PM_PARMFUNC pfunc); -static BOOL enumerate_sections(FILE *infile, - PM_SECFUNC sfunc, PM_PARMFUNC pfunc); -/* prototypes for local toolbox functions */ -static void trimleft(char *psz); -static void trimright(char *psz); -static void collapse_spaces(char *psz); -static int firstnonwhite(char *psz); +/************************************************************************** +Strip all leading whitespace from a string. +**************************************************************************/ +static void trimleft(char *psz) +{ + char *pszDest; + + pszDest = psz; + if (psz != NULL) + { + while (*psz != '\0' && isspace(*psz)) + psz++; + while (*psz != '\0') + *pszDest++ = *psz++; + *pszDest = '\0'; + } +} + +/************************************************************************** +Strip all trailing whitespace from a string. +**************************************************************************/ +static void trimright(char *psz) +{ + char *pszTemp; + + if (psz != NULL && psz[0] != '\0') + { + pszTemp = psz + strlen(psz) - 1; + while (isspace(*pszTemp)) + *pszTemp-- = '\0'; + } +} + +/*********************************************************************** +Collapse each whitespace area in a string to a single space. +***********************************************************************/ +static void collapse_spaces(char *psz) +{ + while (*psz) + if (isspace(*psz)) + { + *psz++ = ' '; + trimleft(psz); + } + else + psz++; +} + +/************************************************************************** +Return the value of the first non-white character in the specified string. +The terminating NUL counts as non-white for the purposes of this function. +Note - no check for a NULL string! What would we return? +**************************************************************************/ +static int firstnonwhite(char *psz) +{ + while (isspace(*psz) && (*psz != '\0')) + psz++; + return (*psz); +} + /************************************************************************** Identifies all parameters in the current section, calls the parameter function for each. Ignores comment lines, stops and backs up in file when a section is encountered. Returns True on success, False on error. **************************************************************************/ -static BOOL enumerate_parameters(FILE *fileIn, PM_PARMFUNC pfunc) +static BOOL enumerate_parameters(FILE *fileIn, BOOL (*pfunc)(char *,char *)) { pstring szBuf; char *pszTemp; @@ -186,8 +237,8 @@ Returns True on success, False on failure. Note that the section and parameter names will have all internal whitespace areas collapsed to a single space for processing. **************************************************************************/ -static BOOL enumerate_sections(FILE *fileIn, - PM_SECFUNC sfunc, PM_PARMFUNC pfunc) +static BOOL enumerate_sections(FILE *fileIn, + BOOL (*sfunc)(char *),BOOL (*pfunc)(char *,char *)) { pstring szBuf; BOOL bRetval; @@ -246,7 +297,7 @@ Process the passed parameter file. Returns True if successful, else False. **************************************************************************/ -BOOL pm_process(char *pszFileName, PM_SECFUNC sfunc, PM_PARMFUNC pfunc) +BOOL pm_process(char *pszFileName,BOOL (*sfunc)(char *),BOOL (*pfunc)(char *,char *)) { FILE *fileIn; BOOL bRetval; @@ -274,62 +325,3 @@ BOOL pm_process(char *pszFileName, PM_SECFUNC sfunc, PM_PARMFUNC pfunc) } -/************************************************************************** -Strip all leading whitespace from a string. -**************************************************************************/ -static void trimleft(char *psz) -{ - char *pszDest; - - pszDest = psz; - if (psz != NULL) - { - while (*psz != '\0' && isspace(*psz)) - psz++; - while (*psz != '\0') - *pszDest++ = *psz++; - *pszDest = '\0'; - } -} - -/************************************************************************** -Strip all trailing whitespace from a string. -**************************************************************************/ -static void trimright(char *psz) -{ - char *pszTemp; - - if (psz != NULL && psz[0] != '\0') - { - pszTemp = psz + strlen(psz) - 1; - while (isspace(*pszTemp)) - *pszTemp-- = '\0'; - } -} - -/*********************************************************************** -Collapse each whitespace area in a string to a single space. -***********************************************************************/ -static void collapse_spaces(char *psz) -{ - while (*psz) - if (isspace(*psz)) - { - *psz++ = ' '; - trimleft(psz); - } - else - psz++; -} - -/************************************************************************** -Return the value of the first non-white character in the specified string. -The terminating NUL counts as non-white for the purposes of this function. -Note - no check for a NULL string! What would we return? -**************************************************************************/ -static int firstnonwhite(char *psz) -{ - while (isspace(*psz) && (*psz != '\0')) - psz++; - return (*psz); -} -- cgit From 7e3b4a1c0df1434eb3d02f93c736ce065f9898d8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Jun 1996 04:38:24 +0000 Subject: got rid of a lot of redundent header files as we now globally generate prototypes automatically using "make proto". This is much less prone to error than the old method of manually adding prototypes (This used to be commit b551dc98f7cc194a5fc2e67a4ebae7fd67a01bbc) --- source3/param/params.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index d5d841dceb..8ff3d59d28 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -57,7 +57,6 @@ the other = 3 #include "includes.h" #include "smb.h" -#include "params.h" /* local variable pointing to passed filename */ static char *pszParmFile = NULL; -- cgit From 6b680bb89c05f4c67e78b927cab4231b647406d7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 Jul 1996 06:14:51 +0000 Subject: minor cleanups (This used to be commit 7c8fd43b4e78f439406c3bb4478adf99ae17172f) --- source3/param/params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 8ff3d59d28..8030e4ab58 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -313,7 +313,7 @@ BOOL pm_process(char *pszFileName,BOOL (*sfunc)(char *),BOOL (*pfunc)(char *,cha DEBUG(0,( "Unable to open configuration file \"%s\"!\n", pszParmFile)); else { - DEBUG(2,( "Processing configuration file \"%s\"\n", pszParmFile)); + DEBUG(3,("Processing configuration file \"%s\"\n", pszParmFile)); bRetval = enumerate_sections(fileIn, sfunc, pfunc); fclose(fileIn); } -- cgit From 0f1f0ceb9519368188f695e18e2341ccfd1b2d15 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 8 May 1997 01:14:17 +0000 Subject: 'The mother of all checkins' :-). Jeremy Allison (jallison@whistle.com) Wed May 7 1997: Update for 1.9.17alpha1 release - 'browsefix release' designed to make browsing across subnets work. byteorder.h: Updated copyright to 1997. charcnv.c: Updated copyright to 1997. charset.c Updated copyright to 1997. charset.h Updated copyright to 1997. client.c Updated copyright to 1997. clientutil.c Updated copyright to 1997. dir.c Updated copyright to 1997. fault.c Updated copyright to 1997. includes.h Updated copyright to 1997. interface.c Updated copyright to 1997. ipc.c Updated copyright to 1997. kanji.c Updated copyright to 1997. kanji.h Updated copyright to 1997. loadparm.c Updated copyright to 1997. locking.c Updated copyright to 1997. mangle.c Updated copyright to 1997. message.c Updated copyright to 1997. nameannounce.c Made use of WINS subnet explicit. Added reset_announce_timer() so announcement can be made immediately when we become a master. Expanded code to do sync with dmb. namebrowse.c Removed redundent checks for AM_MASTER in sync code. Made use of WINS subnet explicit. namedbname.c Made use of WINS subnet explicit. namedbresp.c Made use of WINS subnet explicit. namedbserver.c Made use of WINS subnet explicit. namedbsubnet.c Explicitly add workgroup to WINS subnet when we become a dmb. Made use of WINS subnet explicit. namedbwork.c Made use of WINS subnet explicit. Removed redundent check_work_servertype() function. nameelect.c Explicitly add workgroup to WINS subnet when we become a master browser. Made use of WINS subnet explicit. namelogon.c Updated copyright to 1997. namepacket.c Updated copyright to 1997. namequery.c Updated copyright to 1997. nameresp.c Made use of WINS subnet explicit. Made nmbd fail if configured as master browser and one exists already. nameserv.c Made use of WINS subnet explicit. Remove redundent logon server and domain master code. nameserv.h Add emumerate subnet macros. nameservreply.c Made use of WINS subnet explicit. nameservresp.c Updated copyright to 1997. namework.c Made use of WINS subnet explicit. Updated code to add sync browser entries to add subnet parameter. nmbd.c Added sanity check for misconfigured nmbd. nmblib.c Updated copyright to 1997. nmblookup.c Updated copyright to 1997. nmbsync.c Removed redundent AM_ANY_MASTER check. params.c Updated copyright to 1997. password.c Updated copyright to 1997. pipes.c Updated copyright to 1997. predict.c Updated copyright to 1997. printing.c Updated copyright to 1997. proto.h Changed protos for new nmbd code. quotas.c Updated copyright to 1997. replace.c Updated copyright to 1997. reply.c Updated copyright to 1997. server.c Updated copyright to 1997. shmem.c Updated copyright to 1997. smb.h Updated copyright to 1997. smbencrypt.c Updated copyright to 1997. smbpasswd.c Updated copyright to 1997. smbrun.c Updated copyright to 1997. status.c Updated copyright to 1997. system.c Updated copyright to 1997. testparm.c Updated copyright to 1997. testprns.c Updated copyright to 1997. time.c Updated copyright to 1997. trans2.c Updated copyright to 1997. trans2.h Updated copyright to 1997. uid.c Updated copyright to 1997. username.c Updated copyright to 1997. util.c Updated copyright to 1997. version.h Changed to 1.9.17alpha1. (This used to be commit cf23a155a1315f50d488794a2caf88402bf3e3e6) --- source3/param/params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 8030e4ab58..0fdde0348f 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. Parameter loading utlities - Copyright (C) Karl Auer 1993,1994 + Copyright (C) Karl Auer 1993,1994,1997 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 -- cgit From e722d7077695242a7d6c0749b9a63741f660382a Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Sat, 4 Oct 1997 01:07:47 +0000 Subject: nmblookup.c: I've added a -r option. When specified, nmblookup will attempt to bind to port 137. In order for this to work, the user must be root and the port must be available (i.e., nmbd not running). If either condition is not met, nmblookup will default to normal behavior; it will try to bind to a free port above 7999. I also removed an artifact. The -p option was being accepted but falling through to the default, which was the usage message. I removed "p:" from the getopt() list. params.c: Rewritten. The scanning is much more linear, and I found and fixed a few bugs. I don't like the way that the scratch buffer is handled, but I believe that it is an improvement over the previous version. Chris -)----- (This used to be commit 09dc951f2acd67da9d895e8e00c01e7abbbe0960) --- source3/param/params.c | 855 +++++++++++++++++++++++++++++++------------------ 1 file changed, 548 insertions(+), 307 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 0fdde0348f..8c41eef789 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -1,326 +1,567 @@ -/* - Unix SMB/Netbios implementation. - Version 1.9. - Parameter loading utlities - Copyright (C) Karl Auer 1993,1994,1997 - - 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. -*/ - -/************************************************************************** -PARAMS.C - -Copyright (C) 1990, 1991, 1992, 1993, 1994 Karl Auer - -This module provides for streamlines retrieval of information from a -Windows-like parameter files. There is a function which will search for -all sections in the file and call a specified function with each. There is -a similar function which will call a specified function for all parameters -in a section. The idea is that you pass the addresses of suitable functions -to a single function in this module which will then enumerate all sections, -and within each section all parameters, to your program. - -Parameter files contain text lines (newline delimited) which consist of -either a section name in square brackets or a parameter name, delimited -from the parameter value by an equals sign. Blank lines or lines where the -first non-whitespace character is a colon are ignored. All whitespace in -section names and parameter names is compressed to single spaces. Leading -and trailing whitespace on parameter names and parameter values is stripped. - -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. Parameter names may not start -with a square bracket, an equals sign or a semicolon, for obvious reasons. - -A sample parameter file might look like this: - -[things] -this=1 -that=2 -[other things] -the other = 3 - -**************************************************************************/ +/* -------------------------------------------------------------------------- ** + * Microsoft Network Services for Unix, AKA., Andrew Tridgell's SAMBA. + * + * This module Copyright (C) 1990, 1991, 1992, 1993, 1994 Karl Auer + * + * Rewritten almost completely by Christopher R. Hertel + * at the University of Minnesota, September, 1997. + * This module Copyright (C) 1997 by the University of Minnesota + * -------------------------------------------------------------------------- ** + * + * 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. + * + * -------------------------------------------------------------------------- ** + * + * 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: + * + * :== {
} EOF + * + *
:==
{ } + * + *
:== '[' NAME ']' + * + * :== 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" -#include "smb.h" +/* -------------------------------------------------------------------------- ** + * Constants... + */ -/* local variable pointing to passed filename */ -static char *pszParmFile = NULL; -extern int DEBUGLEVEL; +#define BUFR_INC 1024 -/************************************************************************** -Strip all leading whitespace from a string. -**************************************************************************/ -static void trimleft(char *psz) -{ - char *pszDest; - - pszDest = psz; - if (psz != NULL) - { - while (*psz != '\0' && isspace(*psz)) - psz++; - while (*psz != '\0') - *pszDest++ = *psz++; - *pszDest = '\0'; - } -} - -/************************************************************************** -Strip all trailing whitespace from a string. -**************************************************************************/ -static void trimright(char *psz) -{ - char *pszTemp; - - if (psz != NULL && psz[0] != '\0') - { - pszTemp = psz + strlen(psz) - 1; - while (isspace(*pszTemp)) - *pszTemp-- = '\0'; - } -} - -/*********************************************************************** -Collapse each whitespace area in a string to a single space. -***********************************************************************/ -static void collapse_spaces(char *psz) -{ - while (*psz) - if (isspace(*psz)) - { - *psz++ = ' '; - trimleft(psz); - } - else - psz++; -} - -/************************************************************************** -Return the value of the first non-white character in the specified string. -The terminating NUL counts as non-white for the purposes of this function. -Note - no check for a NULL string! What would we return? -**************************************************************************/ -static int firstnonwhite(char *psz) -{ - while (isspace(*psz) && (*psz != '\0')) - psz++; - return (*psz); -} - - -/************************************************************************** -Identifies all parameters in the current section, calls the parameter -function for each. Ignores comment lines, stops and backs up in file when -a section is encountered. Returns True on success, False on error. -**************************************************************************/ -static BOOL enumerate_parameters(FILE *fileIn, BOOL (*pfunc)(char *,char *)) -{ - pstring szBuf; - char *pszTemp; - BOOL bRetval; - long lFileOffset; - int cTemp; - BOOL bParmFound; - - bRetval = False; - bParmFound = False; - while (True) - { - /* first remember where we are */ - if ((lFileOffset = ftell(fileIn)) >= 0L) +/* -------------------------------------------------------------------------- ** + * 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 . + */ + +extern int DEBUGLEVEL; + +static char *bufr = NULL; +static int bSize = 0; + +/* -------------------------------------------------------------------------- ** + * Functions... + */ + +static int EatWhitespace( FILE *InFile ) + /* ------------------------------------------------------------------------ ** + * 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. + * + * ------------------------------------------------------------------------ ** + */ + { + int c; + + for( c = getc( InFile ); isspace( c ) && ('\n' != c); c = getc( InFile ) ) + ; + return( c ); + } /* EatWhitespace */ + +static int EatComment( FILE *InFile ) + /* ------------------------------------------------------------------------ ** + * 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. + * + * ------------------------------------------------------------------------ ** + */ + { + int c; + + for( c = getc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = getc( InFile ) ) + ; + return( c ); + } /* EatComment */ + +static int Continuation( char *line, int pos ) + /* ------------------------------------------------------------------------ ** + * 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. + * + * ------------------------------------------------------------------------ ** + */ + { + pos--; + while( (pos >= 0) && isspace(line[pos]) ) + pos--; + + return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); + } /* Continuation */ + + +static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) ) + /* ------------------------------------------------------------------------ ** + * 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 + * . False if failed or if a lexical error was + * encountered. + * + * ------------------------------------------------------------------------ ** + */ + { + int c; + int i; + int end; + char *func = "params.c:Section() -"; + + i = 0; /* is the offset of the next free byte in bufr[] and */ + end = 0; /* 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 */ + /* will be one less than . */ + + 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 > (bSize - 2) ) { - /* then get and check a line */ - if (fgets_slash(szBuf, sizeof(szBuf)-1, fileIn) == NULL) - { - /* stop - return OK unless file error */ - bRetval = !ferror(fileIn); - if (!bRetval) - DEBUG(0,( "Read error on configuration file (enumerating parameters)!\n")); - break; - } - else - /* if first non-white is a '[', stop (new section) */ - if ((cTemp = firstnonwhite(szBuf)) == '[') - { - /* restore position to start of new section */ - if (fseek(fileIn, lFileOffset, SEEK_SET) < 0L) - { - DEBUG(0,( "Seek error on configuration file!\n")); - break; - } - - /* return success */ - bRetval = True; - break; - } - else - /* if it's a semicolon or line is blank, ignore the line */ - if (!cTemp || strchr(";#",cTemp)) - { - continue; - } - else - /* if no equals sign and line contains non-whitespace */ - /* then line is badly formed */ - if ((pszTemp = strchr(szBuf, '=')) == NULL) - { - DEBUG(0,( "Ignoring badly formed line: %s", szBuf)); - } - else - { - /* Note that we have found a parameter */ - bParmFound = True; - /* cut line at the equals sign */ - *pszTemp++ = '\0'; - /* trim leading and trailing space from both halves */ - trimright(szBuf); - trimleft(szBuf); - trimright(pszTemp); - trimleft(pszTemp); - /* process the parameter iff passed pointer not NULL */ - if (pfunc != NULL) - if (!pfunc(szBuf, pszTemp)) - break; - } + bSize += BUFR_INC; + bufr = Realloc( bufr, bSize ); + if( NULL == bufr ) + { + DEBUG(0, ("%s Memory re-allocation failure.", func) ); + return( False ); + } } - } - return (bRetval); -} - - -/*********************************************************************** -Close up s by n chars, at offset start. -***********************************************************************/ -static void closestr(char *s, int start, int n) -{ - char *src; - char *dest; - int len; - - if (n > 0) - if ((src = dest = s) != NULL) + + /* Handle a single character. */ + switch( c ) { - len = strlen(s); - if (start >= 0 && start < len - n) - { - src += start + n; - dest += start; - - while (*src) - *dest++ = *src++; - *dest = '\0'; - } + case ']': /* Found the closing bracket. */ + bufr[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( bufr ) ) /* Got a valid name. Deal with it. */ + return( False ); + (void)EatComment( InFile ); /* Finish off the line. */ + return( True ); + + case '\n': /* Got newline before closing ']'. */ + i = Continuation( bufr, i ); /* Check for line continuation. */ + if( i < 0 ) + { + bufr[end] = '\0'; + DEBUG(0, ("%s Badly formed line in configuration file: %s\n", + func, bufr )); + return( False ); + } + end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); + c = getc( InFile ); /* Continue with next line. */ + break; + + default: /* All else are a valid name chars. */ + if( isspace( c ) ) /* One space per whitespace region. */ + { + bufr[end] = ' '; + i = end + 1; + c = EatWhitespace( InFile ); + } + else /* All others copy verbatim. */ + { + bufr[i++] = c; + end = i; + c = getc( InFile ); + } } -} - -/************************************************************************** -Identifies all sections in the parameter file, calls passed section_func() -for each, passing the section name, then calls enumerate_parameters(). -Returns True on success, False on failure. Note that the section and -parameter names will have all internal whitespace areas collapsed to a -single space for processing. -**************************************************************************/ -static BOOL enumerate_sections(FILE *fileIn, - BOOL (*sfunc)(char *),BOOL (*pfunc)(char *,char *)) -{ - pstring szBuf; - BOOL bRetval; - BOOL bSectionFound; - - /* this makes sure we get include lines right */ - enumerate_parameters(fileIn, pfunc); - - bRetval = False; - bSectionFound = False; - while (True) - { - if (fgets_slash(szBuf, sizeof(szBuf)-1, fileIn) == NULL) + } + + /* 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, bufr )); + return( False ); + } /* Section */ + +static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c ) + /* ------------------------------------------------------------------------ ** + * 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. + * + * ------------------------------------------------------------------------ ** + */ + { + 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. */ + char *func = "params.c:Parameter() -"; + + /* Read the parameter name. */ + while( 0 == vstart ) /* Loop until we've found the start of the value. */ + { + + if( i > (bSize - 2) ) /* Ensure there's space for next char. */ { - /* stop - return OK unless file error */ - bRetval = !ferror(fileIn); - if (!bRetval) - DEBUG(0,( "Read error on configuration file (enumerating sections)!\n")); - break; + bSize += BUFR_INC; + bufr = Realloc( bufr, bSize ); + if( NULL == bufr ) + { + DEBUG(0, ("%s Memory re-allocation failure.", func) ); + return( False ); + } } - else + + switch( c ) { - trimleft(szBuf); - trimright(szBuf); - if (szBuf[0] == '[') - { - closestr(szBuf, 0, 1); - if (strlen(szBuf) > 1) - if (szBuf[strlen(szBuf) - 1] == ']') - { - /* found a section - note the fact */ - bSectionFound = True; - /* remove trailing metabracket */ - szBuf[strlen(szBuf) - 1] = '\0'; - /* remove leading and trailing whitespace from name */ - trimleft(szBuf); - trimright(szBuf); - /* reduce all internal whitespace to one space */ - collapse_spaces(szBuf); - /* process it - stop if the processing fails */ - if (sfunc != NULL) - if (!sfunc(szBuf)) - break; - if (!enumerate_parameters(fileIn, pfunc)) - break; - } - } + 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 ); + } + bufr[end++] = '\0'; /* Mark end of string & advance. */ + i = end; /* New string starts here. */ + vstart = end; /* New string is parameter value. */ + bufr[i] = '\0'; /* New string is nul, for now. */ + break; + + case '\n': /* Find continuation char, else error. */ + i = Continuation( bufr, i ); + if( i < 0 ) + { + bufr[end] = '\0'; + DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", + func, bufr )); + return( True ); + } + end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); + c = getc( InFile ); /* Read past eoln. */ + break; + + case '\0': /* Shouldn't have EOF within param name. */ + case EOF: + bufr[i] = '\0'; + DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr )); + return( True ); + + default: + if( isspace( c ) ) /* One ' ' per whitespace region. */ + { + bufr[end] = ' '; + i = end + 1; + c = EatWhitespace( InFile ); + } + else /* All others verbatim. */ + { + bufr[i++] = c; + end = i; + c = getc( InFile ); + } } - } - - return (bRetval); -} - -/************************************************************************** -Process the passed parameter file. + } -Returns True if successful, else False. -**************************************************************************/ -BOOL pm_process(char *pszFileName,BOOL (*sfunc)(char *),BOOL (*pfunc)(char *,char *)) -{ - FILE *fileIn; - BOOL bRetval; + /* Now parse the value. */ + c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */ + while( (EOF !=c) && (c > 0) ) + { - bRetval = False; - - /* record the filename for use in error messages one day... */ - pszParmFile = pszFileName; - - if (pszParmFile == NULL || strlen(pszParmFile) < 1) - DEBUG(0,( "No configuration filename specified!\n")); - else - if ((fileIn = fopen(pszParmFile, "r")) == NULL) - DEBUG(0,( "Unable to open configuration file \"%s\"!\n", pszParmFile)); - else + if( i > (bSize - 2) ) /* Make sure there's enough room. */ { - DEBUG(3,("Processing configuration file \"%s\"\n", pszParmFile)); - bRetval = enumerate_sections(fileIn, sfunc, pfunc); - fclose(fileIn); + bSize += BUFR_INC; + bufr = Realloc( bufr, bSize ); + if( NULL == bufr ) + { + DEBUG(0, ("%s Memory re-allocation failure.", func) ); + return( False ); + } } - if (!bRetval) - DEBUG(0,("pm_process retuned false\n")); - return (bRetval); -} - - + switch( c ) + { + case '\r': /* Explicitly remove '\r' because the older */ + c = getc( InFile ); /* version called fgets_slash() which also */ + break; /* removes them. */ + + case '\n': /* Marks end of value unless there's a '\'. */ + i = Continuation( bufr, i ); + if( i < 0 ) + c = 0; + else + { + for( end = i; (end >= 0) && isspace(bufr[end]); end-- ) + ; + c = getc( InFile ); + } + break; + + default: /* All others verbatim. Note that spaces do */ + bufr[i++] = c; /* not advance . This allows trimming */ + if( !isspace( c ) ) /* of whitespace at the end of the line. */ + end = i; + c = getc( InFile ); + break; + } + } + bufr[end] = '\0'; /* End of value. */ + + return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */ + } /* Parameter */ + +static BOOL Parse( FILE *InFile, + BOOL (*sfunc)(char *), + BOOL (*pfunc)(char *, char *) ) + /* ------------------------------------------------------------------------ ** + * 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. + * + * ------------------------------------------------------------------------ ** + */ + { + int c; + char *func = "params.c:Parse() -"; + + 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( InFile, sfunc ) ) + return( False ); + c = EatWhitespace( InFile ); + break; + + case '\\': /* Bogus backslash. */ + c = EatWhitespace( InFile ); + break; + + default: /* Parameter line. */ + if( !Parameter( InFile, pfunc, c ) ) + return( False ); + c = EatWhitespace( InFile ); + break; + } + } + return( True ); + } /* Parse */ + +static FILE *OpenConfFile( char *FileName ) + /* ------------------------------------------------------------------------ ** + * Open a configuration file. + * + * Input: FileName - The pathname of the config file to be opened. + * + * Output: A pointer of type (FILE *) to the opened file, or NULL if the + * file could not be opened. + * + * ------------------------------------------------------------------------ ** + */ + { + FILE *OpenedFile; + char *func = "params.c:OpenConfFile() -"; + + if( NULL == FileName || 0 == *FileName ) + { + DEBUG( 0, ("%s No configuration filename specified.\n", func) ); + return( NULL ); + } + + OpenedFile = fopen( FileName, "r" ); + if( NULL == OpenedFile ) + { + DEBUG( 0, + ("%s Unable to open configuration file \"%s\":\n\t%s\n", + func, FileName, strerror(errno)) ); + } + + return( OpenedFile ); + } /* OpenConfFile */ + +BOOL pm_process( char *FileName, + BOOL (*sfunc)(char *), + BOOL (*pfunc)(char *, char *) ) + /* ------------------------------------------------------------------------ ** + * 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. + * + * ------------------------------------------------------------------------ ** + */ + { + int result; + FILE *InFile; + char *func = "params.c:pm_process() -"; + + InFile = OpenConfFile( FileName ); /* Open the config file. */ + if( NULL == InFile ) + return( False ); + + DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); + + if( NULL != bufr ) /* If we already have a buffer */ + result = Parse( InFile, sfunc, pfunc ); /* (recursive call), then just */ + /* use it. */ + + else /* If we don't have a buffer */ + { /* allocate one, then parse, */ + bSize = BUFR_INC; /* then free. */ + bufr = (char *)malloc( bSize ); + if( NULL == bufr ) + { + DEBUG(0,("%s memory allocation failure.\n", func)); + return( False ); + } + result = Parse( InFile, sfunc, pfunc ); + free( bufr ); + bufr = NULL; + bSize = 0; + } + + if( !result ) /* Generic failure. */ + { + DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); + return( False ); + } + + return( True ); /* Generic success. */ + } /* pm_process */ + +/* -------------------------------------------------------------------------- */ -- cgit From 2e92be3aaf01c574d32d1a10e1359888638b68bc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Oct 1997 17:52:25 +0000 Subject: client.c: Changed shadowed variable. locking.c: Removed USE_OPLOCKS - now the default. params.c: Removed unused variable. proto.h: Updated. reply.c: Removed USE_OPLOCKS - now the default. server.c: Removed USE_OPLOCKS - now the default. smb.h: Removed USE_OPLOCKS - now the default. smbparse.c: Changed shadowed variable. status.c: Removed USE_OPLOCKS - now the default. util.c: Removed USE_OPLOCKS - now the default. Jeremy (jallison@whistle.com) (This used to be commit b93509846d6291771787af457500eec8984ee6bd) --- source3/param/params.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 8c41eef789..4d1c191b47 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -441,7 +441,6 @@ static BOOL Parse( FILE *InFile, */ { int c; - char *func = "params.c:Parse() -"; c = EatWhitespace( InFile ); while( (EOF != c) && (c > 0) ) -- cgit From 23c68038b9cc7817e3d90d2b4ae3b97b16f2fa63 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 31 Oct 1997 04:27:55 +0000 Subject: pm_process() never closed the file (a memory and file descriptor leak) (This used to be commit 0d9b0d0fffc2b11fe4897b8b99f321fc7d9a143c) --- source3/param/params.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 4d1c191b47..a0a259c007 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -546,6 +546,7 @@ BOOL pm_process( char *FileName, if( NULL == bufr ) { DEBUG(0,("%s memory allocation failure.\n", func)); + fclose(InFile); return( False ); } result = Parse( InFile, sfunc, pfunc ); @@ -554,6 +555,8 @@ BOOL pm_process( char *FileName, bSize = 0; } + fclose(InFile); + if( !result ) /* Generic failure. */ { DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); -- cgit From 55f400bd84f26027f5ec9b7fa06b22895de7557c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jan 1998 13:27:43 +0000 Subject: This is *not* a big change (although it looks like one). This is merely updating the Copyright statements from 1997 to 1998. It's a once a year thing :-). NO OTHER CHANGES WERE MADE. Jeremy. (This used to be commit b9c16977231efb274e08856f7f3f4408dad6d96c) --- source3/param/params.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index a0a259c007..2a0a253f20 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -1,11 +1,11 @@ /* -------------------------------------------------------------------------- ** * Microsoft Network Services for Unix, AKA., Andrew Tridgell's SAMBA. * - * This module Copyright (C) 1990, 1991, 1992, 1993, 1994 Karl Auer + * This module Copyright (C) 1990-1998 Karl Auer * * Rewritten almost completely by Christopher R. Hertel * at the University of Minnesota, September, 1997. - * This module Copyright (C) 1997 by the University of Minnesota + * This module Copyright (C) 1997-1998 by the University of Minnesota * -------------------------------------------------------------------------- ** * * This program is free software; you can redistribute it and/or modify -- cgit From ca3d1b9bf01a56755a5c248a808ffafdce3e1a82 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Oct 1998 02:55:53 +0000 Subject: removed requirement of having a smb.conf for smbwrapper to work. (This used to be commit af58bf2ff8ddbf974dbafa36cf1b679226371e09) --- source3/param/params.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 2a0a253f20..2f54b72131 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -490,17 +490,19 @@ static FILE *OpenConfFile( char *FileName ) { FILE *OpenedFile; char *func = "params.c:OpenConfFile() -"; + extern BOOL in_client; + int lvl = in_client?1:0; if( NULL == FileName || 0 == *FileName ) { - DEBUG( 0, ("%s No configuration filename specified.\n", func) ); + DEBUG( lvl, ("%s No configuration filename specified.\n", func) ); return( NULL ); } OpenedFile = fopen( FileName, "r" ); if( NULL == OpenedFile ) { - DEBUG( 0, + DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n", func, FileName, strerror(errno)) ); } -- cgit From 768761820e8d7481c586c4e0ab4ac7cb36d18c4b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 17 Nov 1998 20:50:07 +0000 Subject: Added the same open()/fopen()/creat()/mmap() -> sys_XXX calls. Tidied up some of the mess (no other word for it). Still doesn't compile cleanly. There are calls with incorrect parameters that don't seem to be doing the right thing. This code still needs surgery :-(. Jeremy. (This used to be commit 18ff93a9abbf68ee8c59c0af3e57c63e4a015dac) --- source3/param/params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 2f54b72131..74dd3d7a25 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -499,7 +499,7 @@ static FILE *OpenConfFile( char *FileName ) return( NULL ); } - OpenedFile = fopen( FileName, "r" ); + OpenedFile = sys_fopen( FileName, "r" ); if( NULL == OpenedFile ) { DEBUG( lvl, -- cgit From e004340f715743e16f599bd0be3e9dad4c53bf2d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 21 Dec 1999 02:15:53 +0000 Subject: Fix based on code from monyo@home.monyo.com to fix multibyte continuation issues. Jeremy. (This used to be commit 023f90e7664d358ddf73272597e75041f5413e9f) --- source3/param/params.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 74dd3d7a25..944bc3d1b4 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -157,28 +157,42 @@ static int EatComment( FILE *InFile ) return( c ); } /* EatComment */ +/***************************************************************************** + * 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( char *line, int pos ) - /* ------------------------------------------------------------------------ ** - * 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. - * - * ------------------------------------------------------------------------ ** - */ - { +{ + int pos2 = 0; + pos--; while( (pos >= 0) && isspace(line[pos]) ) pos--; - return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); - } /* Continuation */ + /* we should recognize if `\` is part of a multibyte character or not. */ + while(pos2 <= pos) { + size_t skip = 0; + skip = skip_multibyte_char(line[pos2]); + if (skip) { + pos2 += skip; + } else if (pos == pos2) { + return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); + } else { + pos2++; + } + } + return (-1); +} static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) ) -- cgit From d867b86721e988dee56d5e9382b32c870ccb2790 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 26 Jan 2000 00:12:35 +0000 Subject: Second set of inline optimisation fixes from Ying Chen . Stop makeing function calls for every use of skip_multibyte_char. This function is called several *million* times during a NetBench run :-). Jeremy. (This used to be commit e5a3deba46ea2d4cb49a6c4b73edd766fe8b5a5c) --- source3/param/params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 944bc3d1b4..3ecdcdc92b 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -182,7 +182,7 @@ static int Continuation( char *line, int pos ) /* we should recognize if `\` is part of a multibyte character or not. */ while(pos2 <= pos) { size_t skip = 0; - skip = skip_multibyte_char(line[pos2]); + skip = get_character_len(line[pos2]); if (skip) { pos2 += skip; } else if (pos == pos2) { -- cgit From 19f946ba6fe442544ac9b0f71bcd33112fc79995 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Apr 2000 11:00:21 +0000 Subject: converted a bunch more functions to use a fd instead of a FILE* to support some of this I added the following functions in util_file.c file_lines_pload : load lines from a pipe file_pload : load a pipe into memory (This used to be commit a09470817c5b21dba42f9ef4ce5e8b768a254c0b) --- source3/param/params.c | 78 +++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 29 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 3ecdcdc92b..8e92621791 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -103,11 +103,32 @@ extern int DEBUGLEVEL; static char *bufr = NULL; static int bSize = 0; +/* 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; +} myFILE; + +static int mygetc(myFILE *f) +{ + if (f->p >= f->buf+f->size) return EOF; + return (int)*(f->p++); +} + +static void myfile_close(myFILE *f) +{ + if (!f) return; + if (f->buf) free(f->buf); + free(f); +} + /* -------------------------------------------------------------------------- ** * Functions... */ -static int EatWhitespace( FILE *InFile ) +static int EatWhitespace( myFILE *InFile ) /* ------------------------------------------------------------------------ ** * Scan past whitespace (see ctype(3C)) and return the first non-whitespace * character, or newline, or EOF. @@ -127,12 +148,12 @@ static int EatWhitespace( FILE *InFile ) { int c; - for( c = getc( InFile ); isspace( c ) && ('\n' != c); c = getc( InFile ) ) + for( c = mygetc( InFile ); isspace( c ) && ('\n' != c); c = mygetc( InFile ) ) ; return( c ); } /* EatWhitespace */ -static int EatComment( FILE *InFile ) +static int EatComment( myFILE *InFile ) /* ------------------------------------------------------------------------ ** * Scan to the end of a comment. * @@ -152,7 +173,7 @@ static int EatComment( FILE *InFile ) { int c; - for( c = getc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = getc( InFile ) ) + for( c = mygetc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = mygetc( InFile ) ) ; return( c ); } /* EatComment */ @@ -195,7 +216,7 @@ static int Continuation( char *line, int pos ) } -static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) ) +static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) /* ------------------------------------------------------------------------ ** * Scan a section name, and pass the name to function sfunc(). * @@ -264,7 +285,7 @@ static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) ) return( False ); } end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); - c = getc( InFile ); /* Continue with next line. */ + c = mygetc( InFile ); /* Continue with next line. */ break; default: /* All else are a valid name chars. */ @@ -278,7 +299,7 @@ static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) ) { bufr[i++] = c; end = i; - c = getc( InFile ); + c = mygetc( InFile ); } } } @@ -288,7 +309,7 @@ static BOOL Section( FILE *InFile, BOOL (*sfunc)(char *) ) return( False ); } /* Section */ -static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c ) +static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) /* ------------------------------------------------------------------------ ** * Scan a parameter name and value, and pass these two fields to pfunc(). * @@ -357,7 +378,7 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c ) return( True ); } end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); - c = getc( InFile ); /* Read past eoln. */ + c = mygetc( InFile ); /* Read past eoln. */ break; case '\0': /* Shouldn't have EOF within param name. */ @@ -377,7 +398,7 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c ) { bufr[i++] = c; end = i; - c = getc( InFile ); + c = mygetc( InFile ); } } } @@ -401,7 +422,7 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c ) switch( c ) { case '\r': /* Explicitly remove '\r' because the older */ - c = getc( InFile ); /* version called fgets_slash() which also */ + c = mygetc( InFile ); /* version called fgets_slash() which also */ break; /* removes them. */ case '\n': /* Marks end of value unless there's a '\'. */ @@ -412,7 +433,7 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c ) { for( end = i; (end >= 0) && isspace(bufr[end]); end-- ) ; - c = getc( InFile ); + c = mygetc( InFile ); } break; @@ -420,7 +441,7 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c ) bufr[i++] = c; /* not advance . This allows trimming */ if( !isspace( c ) ) /* of whitespace at the end of the line. */ end = i; - c = getc( InFile ); + c = mygetc( InFile ); break; } } @@ -429,7 +450,7 @@ static BOOL Parameter( FILE *InFile, BOOL (*pfunc)(char *, char *), int c ) return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */ } /* Parameter */ -static BOOL Parse( FILE *InFile, +static BOOL Parse( myFILE *InFile, BOOL (*sfunc)(char *), BOOL (*pfunc)(char *, char *) ) /* ------------------------------------------------------------------------ ** @@ -490,38 +511,37 @@ static BOOL Parse( FILE *InFile, return( True ); } /* Parse */ -static FILE *OpenConfFile( char *FileName ) +static myFILE *OpenConfFile( char *FileName ) /* ------------------------------------------------------------------------ ** * Open a configuration file. * * Input: FileName - The pathname of the config file to be opened. * - * Output: A pointer of type (FILE *) to the opened file, or NULL if the - * file could not be opened. + * Output: A pointer of type (char **) to the lines of the file * * ------------------------------------------------------------------------ ** */ { - FILE *OpenedFile; char *func = "params.c:OpenConfFile() -"; extern BOOL in_client; int lvl = in_client?1:0; + myFILE *ret; - if( NULL == FileName || 0 == *FileName ) - { - DEBUG( lvl, ("%s No configuration filename specified.\n", func) ); - return( NULL ); - } + ret = (myFILE *)malloc(sizeof(*ret)); + if (!ret) return NULL; - OpenedFile = sys_fopen( FileName, "r" ); - if( NULL == OpenedFile ) + ret->buf = file_load(FileName, &ret->size); + if( NULL == ret->buf ) { DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n", func, FileName, strerror(errno)) ); + free(ret); + ret = NULL; } - return( OpenedFile ); + ret->p = ret->buf; + return( ret ); } /* OpenConfFile */ BOOL pm_process( char *FileName, @@ -542,7 +562,7 @@ BOOL pm_process( char *FileName, */ { int result; - FILE *InFile; + myFILE *InFile; char *func = "params.c:pm_process() -"; InFile = OpenConfFile( FileName ); /* Open the config file. */ @@ -562,7 +582,7 @@ BOOL pm_process( char *FileName, if( NULL == bufr ) { DEBUG(0,("%s memory allocation failure.\n", func)); - fclose(InFile); + myfile_close(InFile); return( False ); } result = Parse( InFile, sfunc, pfunc ); @@ -571,7 +591,7 @@ BOOL pm_process( char *FileName, bSize = 0; } - fclose(InFile); + myfile_close(InFile); if( !result ) /* Generic failure. */ { -- cgit From c7ddaacd269528dd10aabdc5ce5ad05b6c66a601 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 5 May 2000 04:18:22 +0000 Subject: Fix for crash bug in OpenConfFile() if no smb.conf exists. (This used to be commit b531ddb2657e9eac1c1e9f32344b67c3963ce30a) --- source3/param/params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 8e92621791..1cf3aa9eb1 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -537,7 +537,7 @@ static myFILE *OpenConfFile( char *FileName ) ("%s Unable to open configuration file \"%s\":\n\t%s\n", func, FileName, strerror(errno)) ); free(ret); - ret = NULL; + return NULL; } ret->p = ret->buf; -- cgit From db2f46df1ea7d2f639169187bdaf905f7928f586 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 16 Jun 2000 15:53:13 +0000 Subject: more update. (This used to be commit ac91ef30932e3e472a16c4c756f6dfddc1b18487) --- source3/param/params.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 1cf3aa9eb1..25f9004c27 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -203,7 +203,6 @@ static int Continuation( char *line, int pos ) /* we should recognize if `\` is part of a multibyte character or not. */ while(pos2 <= pos) { size_t skip = 0; - skip = get_character_len(line[pos2]); if (skip) { pos2 += skip; } else if (pos == pos2) { -- cgit From c89f1ae0cf5856c30172c11fb935ee68f15f8be7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 16 Jun 2000 23:57:09 +0000 Subject: reverted lukes changes in param/ apparently they were not deliberate, they were probably a result of Luke accidentally copying a CVS directory from one spot to another in error (This used to be commit 2d35d0cf1d152438c20648d863f5993e672337dc) --- source3/param/params.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 25f9004c27..1cf3aa9eb1 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -203,6 +203,7 @@ static int Continuation( char *line, int pos ) /* we should recognize if `\` is part of a multibyte character or not. */ while(pos2 <= pos) { size_t skip = 0; + skip = get_character_len(line[pos2]); if (skip) { pos2 += skip; } else if (pos == pos2) { -- cgit From f0bd621a504082e9b16ff1b5a56c8987e6f94e30 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 18 Oct 2000 01:36:26 +0000 Subject: Bug report that on some systems extended characters are being returned as negative values from the mygetc() function. I've modified the return line so that it should return values in the 0..255 range for legitimate characters. This change should probably be copied into SAMBA_2_2 but I haven't checked that tree out yet. Chris -)----- (This used to be commit e2ce5ce0fdaca0e38d953baa2da4c3542b0503ee) --- source3/param/params.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 1cf3aa9eb1..9cb6412b96 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -114,7 +114,8 @@ typedef struct { static int mygetc(myFILE *f) { if (f->p >= f->buf+f->size) return EOF; - return (int)*(f->p++); + /* be sure to return chars >127 as positive values */ + return (int)( *(f->p++) & 0x00FF ); } static void myfile_close(myFILE *f) -- cgit From 792ca5d98938c3c52ff4e598bcb55056565dc202 Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Wed, 17 Jan 2001 18:47:46 +0000 Subject: Changes from APPLIANCE_HEAD: source/rpc_server/srv_spoolss_nt.c - Unrolled construct_notify_jobs_info() loop to only fetch printer info_2 structure once rather than num_print_jobs times. - convert command to unix codepage. - remove lp_remove_service() call as it prevents lp_killservice() from working. - Modified some DEBUG and DEBUGADD statements. source/param/loadparm.c source/param/params.c - change printer, preload, auto services to FLAG_DOS_STRING, reverted earlier changes to szPrintername et al, add comments. source/printing/load.c - fix bug with lp_auto_services() and strtok() source/printing/nt_printing.c source/printing/printing.c - remove redundant test that used SERVICE(snum) source/printing/pcap.c - add unix_to_dos() calls, add notes wrt FIXMEs for xxx_printer_fn() functions. source/web/swat.c - added FIXME comment. source/smbd/service.c - added comment re: dos codepage (This used to be commit 7b774b72c2857af9519012106714a9e2cb099da3) --- source3/param/params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 9cb6412b96..b359b269d4 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -271,7 +271,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) DEBUG(0, ("%s Empty section name in configuration file.\n", func )); return( False ); } - if( !sfunc( bufr ) ) /* Got a valid name. Deal with it. */ + if( !sfunc( unix_to_dos(bufr,True) ) ) /* Got a valid name. Deal with it. */ return( False ); (void)EatComment( InFile ); /* Finish off the line. */ return( True ); -- cgit From 87fbb7092b8f8b2f0db0f361c3d625e19de57cd9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:15:53 +0000 Subject: The big character set handling changeover! This commit gets rid of all our old codepage handling and replaces it with iconv. All internal strings in Samba are now in "unix" charset, which may be multi-byte. See internals.doc and my posting to samba-technical for a more complete explanation. (This used to be commit debb471267960e56005a741817ebd227ecfc512a) --- source3/param/params.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index b359b269d4..4e74953889 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -195,25 +195,12 @@ static int EatComment( myFILE *InFile ) static int Continuation( char *line, int pos ) { - int pos2 = 0; - - pos--; - while( (pos >= 0) && isspace(line[pos]) ) - pos--; - - /* we should recognize if `\` is part of a multibyte character or not. */ - while(pos2 <= pos) { - size_t skip = 0; - skip = get_character_len(line[pos2]); - if (skip) { - pos2 += skip; - } else if (pos == pos2) { - return( ((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); - } else { - pos2++; - } - } - return (-1); + pos--; + while( (pos >= 0) && isspace(line[pos]) ) + pos--; + + return (((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); + return (-1); } @@ -271,7 +258,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) DEBUG(0, ("%s Empty section name in configuration file.\n", func )); return( False ); } - if( !sfunc( unix_to_dos(bufr,True) ) ) /* Got a valid name. Deal with it. */ + if( !sfunc(bufr) ) /* Got a valid name. Deal with it. */ return( False ); (void)EatComment( InFile ); /* Finish off the line. */ return( True ); -- cgit From ca3b64fca4ffaec307fe8f37ffe27aded4fde0b1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 5 Jul 2001 11:46:36 +0000 Subject: removed an unreachable statement (This used to be commit 6503f53abe2642b002d8c9c64a2e0534c2b39b8c) --- source3/param/params.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 4e74953889..61baf9517c 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -200,7 +200,6 @@ static int Continuation( char *line, int pos ) pos--; return (((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); - return (-1); } -- cgit From 2e783a47076bd0994b6ce86df7ec967bc1c2da63 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 12 Aug 2001 17:30:01 +0000 Subject: this is a big global fix for the ptr = Realloc(ptr, size) bug. many possible mem leaks, and segfaults fixed. someone should port this fix to 2.2 also. (This used to be commit fa8e55b8b465114ce209344965c1ca0333b84db9) --- source3/param/params.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 61baf9517c..9416965919 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -238,13 +238,16 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) /* Check that the buffer is big enough for the next character. */ if( i > (bSize - 2) ) { - bSize += BUFR_INC; - bufr = Realloc( bufr, bSize ); - if( NULL == bufr ) + char *tb; + + tb = Realloc( bufr, bSize +BUFR_INC ); + if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } + bufr = tb; + bSize += BUFR_INC; } /* Handle a single character. */ @@ -332,13 +335,16 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) if( i > (bSize - 2) ) /* Ensure there's space for next char. */ { - bSize += BUFR_INC; - bufr = Realloc( bufr, bSize ); - if( NULL == bufr ) + char *tb; + + tb = Realloc( bufr, bSize + BUFR_INC ); + if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } + bufr = tb; + bSize += BUFR_INC; } switch( c ) @@ -397,13 +403,16 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) if( i > (bSize - 2) ) /* Make sure there's enough room. */ { - bSize += BUFR_INC; - bufr = Realloc( bufr, bSize ); - if( NULL == bufr ) + char *tb; + + tb = Realloc( bufr, bSize + BUFR_INC ); + if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } + bufr = tb; + bSize += BUFR_INC; } switch( c ) -- cgit From 84ab9d2cb369dc0b2af0da4d2dc66c03c0a3f0a2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 04:58:38 +0000 Subject: move to SAFE_FREE() (This used to be commit fb0984e60fd69100d9866304b83b4f3c85e9aea2) --- source3/param/params.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 9416965919..d12081fb32 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -121,8 +121,8 @@ static int mygetc(myFILE *f) static void myfile_close(myFILE *f) { if (!f) return; - if (f->buf) free(f->buf); - free(f); + SAFE_FREE(f->buf); + SAFE_FREE(f); } /* -------------------------------------------------------------------------- ** @@ -532,7 +532,7 @@ static myFILE *OpenConfFile( char *FileName ) DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n", func, FileName, strerror(errno)) ); - free(ret); + SAFE_FREE(ret); return NULL; } @@ -582,7 +582,7 @@ BOOL pm_process( char *FileName, return( False ); } result = Parse( InFile, sfunc, pfunc ); - free( bufr ); + SAFE_FREE( bufr ); bufr = NULL; bSize = 0; } -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/param/params.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index d12081fb32..7aceb1b9da 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -98,8 +98,6 @@ * bSize - The size of the global buffer . */ -extern int DEBUGLEVEL; - static char *bufr = NULL; static int bSize = 0; -- cgit From 0eedf59a4721d14df09e295290705b8025cdd827 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 20 Dec 2001 10:04:32 +0000 Subject: fixed more warnings on irix (This used to be commit 2ffefba86997c9d6bc2a9b6dac1e576f4b64c777) --- source3/param/params.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 7aceb1b9da..bc93a1fedf 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -191,10 +191,10 @@ static int EatComment( myFILE *InFile ) * *****************************************************************************/ -static int Continuation( char *line, int pos ) +static int Continuation(char *line, int pos ) { pos--; - while( (pos >= 0) && isspace(line[pos]) ) + while( (pos >= 0) && isspace((int)line[pos])) pos--; return (((pos >= 0) && ('\\' == line[pos])) ? pos : -1 ); @@ -425,7 +425,7 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) c = 0; else { - for( end = i; (end >= 0) && isspace(bufr[end]); end-- ) + for( end = i; (end >= 0) && isspace((int)bufr[end]); end-- ) ; c = mygetc( InFile ); } -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/param/params.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index bc93a1fedf..892e5476cc 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -201,7 +201,7 @@ static int Continuation(char *line, int pos ) } -static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) +static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) /* ------------------------------------------------------------------------ ** * Scan a section name, and pass the name to function sfunc(). * @@ -219,7 +219,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) int c; int i; int end; - char *func = "params.c:Section() -"; + const char *func = "params.c:Section() -"; i = 0; /* is the offset of the next free byte in bufr[] and */ end = 0; /* is the current "end of string" offset. In most */ @@ -297,7 +297,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) return( False ); } /* Section */ -static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) +static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *), int c ) /* ------------------------------------------------------------------------ ** * Scan a parameter name and value, and pass these two fields to pfunc(). * @@ -325,7 +325,7 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) 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. */ - char *func = "params.c:Parameter() -"; + const char *func = "params.c:Parameter() -"; /* Read the parameter name. */ while( 0 == vstart ) /* Loop until we've found the start of the value. */ @@ -445,8 +445,8 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) } /* Parameter */ static BOOL Parse( myFILE *InFile, - BOOL (*sfunc)(char *), - BOOL (*pfunc)(char *, char *) ) + BOOL (*sfunc)(const char *), + BOOL (*pfunc)(const char *, const char *) ) /* ------------------------------------------------------------------------ ** * Scan & parse the input. * @@ -505,7 +505,7 @@ static BOOL Parse( myFILE *InFile, return( True ); } /* Parse */ -static myFILE *OpenConfFile( char *FileName ) +static myFILE *OpenConfFile( const char *FileName ) /* ------------------------------------------------------------------------ ** * Open a configuration file. * @@ -516,7 +516,7 @@ static myFILE *OpenConfFile( char *FileName ) * ------------------------------------------------------------------------ ** */ { - char *func = "params.c:OpenConfFile() -"; + const char *func = "params.c:OpenConfFile() -"; extern BOOL in_client; int lvl = in_client?1:0; myFILE *ret; @@ -538,9 +538,9 @@ static myFILE *OpenConfFile( char *FileName ) return( ret ); } /* OpenConfFile */ -BOOL pm_process( char *FileName, - BOOL (*sfunc)(char *), - BOOL (*pfunc)(char *, char *) ) +BOOL pm_process( const char *FileName, + BOOL (*sfunc)(const char *), + BOOL (*pfunc)(const char *, const char *) ) /* ------------------------------------------------------------------------ ** * Process the named parameter file. * @@ -557,7 +557,7 @@ BOOL pm_process( char *FileName, { int result; myFILE *InFile; - char *func = "params.c:pm_process() -"; + const char *func = "params.c:pm_process() -"; InFile = OpenConfFile( FileName ); /* Open the config file. */ if( NULL == InFile ) -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/param/params.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 892e5476cc..2d6fe56716 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -238,7 +238,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) { char *tb; - tb = Realloc( bufr, bSize +BUFR_INC ); + tb = SMB_REALLOC( bufr, bSize +BUFR_INC ); if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); @@ -335,7 +335,7 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *) { char *tb; - tb = Realloc( bufr, bSize + BUFR_INC ); + tb = SMB_REALLOC( bufr, bSize + BUFR_INC ); if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); @@ -403,7 +403,7 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *) { char *tb; - tb = Realloc( bufr, bSize + BUFR_INC ); + tb = SMB_REALLOC( bufr, bSize + BUFR_INC ); if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); @@ -521,7 +521,7 @@ static myFILE *OpenConfFile( const char *FileName ) int lvl = in_client?1:0; myFILE *ret; - ret = (myFILE *)malloc(sizeof(*ret)); + ret = SMB_MALLOC_P(myFILE); if (!ret) return NULL; ret->buf = file_load(FileName, &ret->size); @@ -572,7 +572,7 @@ BOOL pm_process( const char *FileName, else /* If we don't have a buffer */ { /* allocate one, then parse, */ bSize = BUFR_INC; /* then free. */ - bufr = (char *)malloc( bSize ); + bufr = (char *)SMB_MALLOC( bSize ); if( NULL == bufr ) { DEBUG(0,("%s memory allocation failure.\n", func)); -- cgit From 26d81332de11fd115b081cb438f0c698b81b9bb1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Feb 2005 02:19:17 +0000 Subject: r5535: Reformat so I can actually maintain this code and eventually convert to MB safe. Jeremy. (This used to be commit 0285754c1408b4155e115a5f76b1f5ff481c9d7e) --- source3/param/params.c | 778 ++++++++++++++++++++++++------------------------- 1 file changed, 377 insertions(+), 401 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 2d6fe56716..192223605a 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -111,14 +111,16 @@ typedef struct { static int mygetc(myFILE *f) { - if (f->p >= f->buf+f->size) return EOF; + 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; + if (!f) + return; SAFE_FREE(f->buf); SAFE_FREE(f); } @@ -126,8 +128,6 @@ static void myfile_close(myFILE *f) /* -------------------------------------------------------------------------- ** * Functions... */ - -static int EatWhitespace( myFILE *InFile ) /* ------------------------------------------------------------------------ ** * Scan past whitespace (see ctype(3C)) and return the first non-whitespace * character, or newline, or EOF. @@ -144,15 +144,16 @@ static int EatWhitespace( myFILE *InFile ) * * ------------------------------------------------------------------------ ** */ - { - int c; + +static int EatWhitespace( myFILE *InFile ) +{ + int c; - for( c = mygetc( InFile ); isspace( c ) && ('\n' != c); c = mygetc( InFile ) ) - ; - return( c ); - } /* EatWhitespace */ + for( c = mygetc( InFile ); isspace( c ) && ('\n' != c); c = mygetc( InFile ) ) + ; + return( c ); +} -static int EatComment( myFILE *InFile ) /* ------------------------------------------------------------------------ ** * Scan to the end of a comment. * @@ -169,13 +170,15 @@ static int EatComment( myFILE *InFile ) * * ------------------------------------------------------------------------ ** */ - { - int c; - for( c = mygetc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = mygetc( InFile ) ) - ; - return( c ); - } /* EatComment */ +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 @@ -200,400 +203,373 @@ static int Continuation(char *line, int 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 + * . False if failed or if a lexical error was + * encountered. + * + * ------------------------------------------------------------------------ ** + */ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) - /* ------------------------------------------------------------------------ ** - * 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 - * . False if failed or if a lexical error was - * encountered. - * - * ------------------------------------------------------------------------ ** - */ - { - int c; - int i; - int end; - const char *func = "params.c:Section() -"; - - i = 0; /* is the offset of the next free byte in bufr[] and */ - end = 0; /* 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 */ - /* will be one less than . */ - - 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 > (bSize - 2) ) - { - char *tb; +{ + int c; + int i; + int end; + const char *func = "params.c:Section() -"; + + i = 0; /* is the offset of the next free byte in bufr[] and */ + end = 0; /* 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 */ + /* will be one less than . */ + + 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 > (bSize - 2) ) { + char *tb; - tb = SMB_REALLOC( bufr, bSize +BUFR_INC ); - if( NULL == tb ) - { - DEBUG(0, ("%s Memory re-allocation failure.", func) ); - return( False ); - } - bufr = tb; - bSize += BUFR_INC; - } - - /* Handle a single character. */ - switch( c ) - { - case ']': /* Found the closing bracket. */ - bufr[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(bufr) ) /* Got a valid name. Deal with it. */ - return( False ); - (void)EatComment( InFile ); /* Finish off the line. */ - return( True ); - - case '\n': /* Got newline before closing ']'. */ - i = Continuation( bufr, i ); /* Check for line continuation. */ - if( i < 0 ) - { - bufr[end] = '\0'; - DEBUG(0, ("%s Badly formed line in configuration file: %s\n", - func, bufr )); - return( False ); - } - end = ( (i > 0) && (' ' == bufr[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. */ - { - bufr[end] = ' '; - i = end + 1; - c = EatWhitespace( InFile ); - } - else /* All others copy verbatim. */ - { - bufr[i++] = c; - end = i; - c = mygetc( InFile ); - } - } - } - - /* 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, bufr )); - return( False ); - } /* Section */ + tb = SMB_REALLOC( bufr, bSize +BUFR_INC ); + if( NULL == tb ) { + DEBUG(0, ("%s Memory re-allocation failure.", func) ); + return False; + } + bufr = tb; + bSize += BUFR_INC; + } + + /* Handle a single character. */ + switch( c ) { + case ']': /* Found the closing bracket. */ + bufr[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(bufr) ) /* Got a valid name. Deal with it. */ + return False; + EatComment( InFile ); /* Finish off the line. */ + return True; + + case '\n': /* Got newline before closing ']'. */ + i = Continuation( bufr, i ); /* Check for line continuation. */ + if( i < 0 ) { + bufr[end] = '\0'; + DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, bufr )); + return False; + } + end = ( (i > 0) && (' ' == bufr[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. */ + bufr[end] = ' '; + i = end + 1; + c = EatWhitespace( InFile ); + } else { + bufr[i++] = c; + end = i; + c = mygetc( InFile ); + } + } + } + + /* 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, bufr )); + 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( myFILE *InFile, BOOL (*pfunc)(const char *, const char *), int c ) - /* ------------------------------------------------------------------------ ** - * 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. - * - * ------------------------------------------------------------------------ ** - */ - { - 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 > (bSize - 2) ) /* Ensure there's space for next char. */ - { - char *tb; - - tb = SMB_REALLOC( bufr, bSize + BUFR_INC ); - if( NULL == tb ) - { - DEBUG(0, ("%s Memory re-allocation failure.", func) ); - return( False ); - } - bufr = tb; - bSize += 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 ); - } - bufr[end++] = '\0'; /* Mark end of string & advance. */ - i = end; /* New string starts here. */ - vstart = end; /* New string is parameter value. */ - bufr[i] = '\0'; /* New string is nul, for now. */ - break; - - case '\n': /* Find continuation char, else error. */ - i = Continuation( bufr, i ); - if( i < 0 ) - { - bufr[end] = '\0'; - DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", - func, bufr )); - return( True ); - } - end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); - c = mygetc( InFile ); /* Read past eoln. */ - break; - - case '\0': /* Shouldn't have EOF within param name. */ - case EOF: - bufr[i] = '\0'; - DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr )); - return( True ); - - default: - if( isspace( c ) ) /* One ' ' per whitespace region. */ - { - bufr[end] = ' '; - i = end + 1; - c = EatWhitespace( InFile ); - } - else /* All others verbatim. */ - { - bufr[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 > (bSize - 2) ) /* Make sure there's enough room. */ - { - char *tb; - - tb = SMB_REALLOC( bufr, bSize + BUFR_INC ); - if( NULL == tb ) - { - DEBUG(0, ("%s Memory re-allocation failure.", func) ); - return( False ); - } - bufr = tb; - bSize += 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( bufr, i ); - if( i < 0 ) - c = 0; - else - { - for( end = i; (end >= 0) && isspace((int)bufr[end]); end-- ) - ; - c = mygetc( InFile ); - } - break; - - default: /* All others verbatim. Note that spaces do */ - bufr[i++] = c; /* not advance . This allows trimming */ - if( !isspace( c ) ) /* of whitespace at the end of the line. */ - end = i; - c = mygetc( InFile ); - break; - } - } - bufr[end] = '\0'; /* End of value. */ - - return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */ - } /* Parameter */ +{ + 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 > (bSize - 2) ) { + /* Ensure there's space for next char. */ + char *tb = SMB_REALLOC( bufr, bSize + BUFR_INC ); + if( NULL == tb ) { + DEBUG(0, ("%s Memory re-allocation failure.", func) ); + return False; + } + bufr = tb; + bSize += 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; + } + bufr[end++] = '\0'; /* Mark end of string & advance. */ + i = end; /* New string starts here. */ + vstart = end; /* New string is parameter value. */ + bufr[i] = '\0'; /* New string is nul, for now. */ + break; + + case '\n': /* Find continuation char, else error. */ + i = Continuation( bufr, i ); + if( i < 0 ) { + bufr[end] = '\0'; + DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, bufr )); + return True; + } + end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); + c = mygetc( InFile ); /* Read past eoln. */ + break; + + case '\0': /* Shouldn't have EOF within param name. */ + case EOF: + bufr[i] = '\0'; + DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr )); + return True; + + default: + if(isspace( c )) { + /* One ' ' per whitespace region. */ + bufr[end] = ' '; + i = end + 1; + c = EatWhitespace( InFile ); + } else { + bufr[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 > (bSize - 2) ) { + /* Make sure there's enough room. */ + char *tb = SMB_REALLOC( bufr, bSize + BUFR_INC ); + if( NULL == tb ) { + DEBUG(0, ("%s Memory re-allocation failure.", func)); + return False; + } + bufr = tb; + bSize += 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( bufr, i ); + if( i < 0 ) { + c = 0; + } else { + for( end = i; (end >= 0) && isspace((int)bufr[end]); end-- ) + ; + c = mygetc( InFile ); + } + break; + + default: /* All others verbatim. Note that spaces do not advance . This allows trimming */ + bufr[i++] = c; + if( !isspace( c ) ) /* of whitespace at the end of the line. */ + end = i; + c = mygetc( InFile ); + break; + } + } + bufr[end] = '\0'; /* End of value. */ + + return( pfunc( bufr, &bufr[vstart] ) ); /* 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( myFILE *InFile, BOOL (*sfunc)(const char *), BOOL (*pfunc)(const char *, const char *) ) - /* ------------------------------------------------------------------------ ** - * 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. - * - * ------------------------------------------------------------------------ ** - */ - { - 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( InFile, sfunc ) ) - return( False ); - c = EatWhitespace( InFile ); - break; - - case '\\': /* Bogus backslash. */ - c = EatWhitespace( InFile ); - break; - - default: /* Parameter line. */ - if( !Parameter( InFile, pfunc, c ) ) - return( False ); - c = EatWhitespace( InFile ); - break; - } - } - return( True ); - } /* Parse */ +{ + 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( InFile, sfunc ) ) + return False; + c = EatWhitespace( InFile ); + break; + + case '\\': /* Bogus backslash. */ + c = EatWhitespace( InFile ); + break; + + default: /* Parameter line. */ + if( !Parameter( InFile, pfunc, c ) ) + 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 ) - /* ------------------------------------------------------------------------ ** - * 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 - * - * ------------------------------------------------------------------------ ** - */ - { - const char *func = "params.c:OpenConfFile() -"; - extern BOOL in_client; - int lvl = in_client?1:0; - myFILE *ret; - - ret = SMB_MALLOC_P(myFILE); - if (!ret) return NULL; - - ret->buf = file_load(FileName, &ret->size); - 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; - return( ret ); - } /* OpenConfFile */ +{ + const char *func = "params.c:OpenConfFile() -"; + extern BOOL in_client; + int lvl = in_client?1:0; + myFILE *ret; + + ret = SMB_MALLOC_P(myFILE); + if (!ret) + return NULL; + + ret->buf = file_load(FileName, &ret->size); + 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; + 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 *), - BOOL (*pfunc)(const char *, const char *) ) - /* ------------------------------------------------------------------------ ** - * 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. - * - * ------------------------------------------------------------------------ ** - */ - { - int result; - myFILE *InFile; - const char *func = "params.c:pm_process() -"; - - InFile = OpenConfFile( FileName ); /* Open the config file. */ - if( NULL == InFile ) - return( False ); - - DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); - - if( NULL != bufr ) /* If we already have a buffer */ - result = Parse( InFile, sfunc, pfunc ); /* (recursive call), then just */ - /* use it. */ - - else /* If we don't have a buffer */ - { /* allocate one, then parse, */ - bSize = BUFR_INC; /* then free. */ - bufr = (char *)SMB_MALLOC( bSize ); - if( NULL == bufr ) - { - DEBUG(0,("%s memory allocation failure.\n", func)); - myfile_close(InFile); - return( False ); - } - result = Parse( InFile, sfunc, pfunc ); - SAFE_FREE( bufr ); - bufr = NULL; - bSize = 0; - } - - myfile_close(InFile); - - if( !result ) /* Generic failure. */ - { - DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); - return( False ); - } - - return( True ); /* Generic success. */ - } /* pm_process */ - -/* -------------------------------------------------------------------------- */ + BOOL (*sfunc)(const char *), + BOOL (*pfunc)(const char *, const char *) ) +{ + int result; + myFILE *InFile; + const char *func = "params.c:pm_process() -"; + + InFile = OpenConfFile( FileName ); /* Open the config file. */ + if( NULL == InFile ) + return False; + + DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); + + if( NULL != bufr ) { + /* If we already have a buffer */ + /* (recursive call), then just */ + /* use it. */ + result = Parse( InFile, sfunc, pfunc ); + } else { + bSize = BUFR_INC; + bufr = (char *)SMB_MALLOC( bSize ); + if( NULL == bufr ) { + DEBUG(0,("%s memory allocation failure.\n", func)); + myfile_close(InFile); + return False; + } + + result = Parse( InFile, sfunc, pfunc ); + SAFE_FREE( bufr ); + bufr = NULL; + bSize = 0; + } + + myfile_close(InFile); + + if( !result ) { + DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func)); + return False; + } + + return True; +} -- cgit From 413eb87493d5f4c2ed8e1f674b223e270fcb3667 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 24 Feb 2005 21:06:11 +0000 Subject: r5543: Fix for bug #962 - using MB sharenames containing a ']' character. Processing a share name is now MB safe so long as the correct unix charset is in scope. Jeremy. (This used to be commit 5bd027e9ed095c01fc176178ff51b5839fe0c140) --- source3/param/params.c | 54 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 192223605a..9d21d25a24 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -107,6 +107,7 @@ typedef struct { char *buf; char *p; size_t size; + char *end_section_p; } myFILE; static int mygetc(myFILE *f) @@ -125,6 +126,22 @@ static void myfile_close(myFILE *f) 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... */ @@ -230,6 +247,13 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) /* character written to bufr[] is a space, then */ /* will be one less than . */ + + /* 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. */ @@ -247,20 +271,8 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) bSize += BUFR_INC; } - /* Handle a single character. */ + /* Handle a single character other than section end. */ switch( c ) { - case ']': /* Found the closing bracket. */ - bufr[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(bufr) ) /* Got a valid name. Deal with it. */ - return False; - EatComment( InFile ); /* Finish off the line. */ - return True; - case '\n': /* Got newline before closing ']'. */ i = Continuation( bufr, i ); /* Check for line continuation. */ if( i < 0 ) { @@ -284,6 +296,21 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) c = mygetc( InFile ); } } + + if (AtSectionEnd(InFile)) { + /* Got to the closing bracket. */ + bufr[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(bufr) ) /* 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. */ @@ -513,6 +540,7 @@ static myFILE *OpenConfFile( const char *FileName ) } ret->p = ret->buf; + ret->end_section_p = NULL; return( ret ); } -- cgit From 978ca8486031e43754a3c23757f361bf3a85f335 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 6 Apr 2005 16:28:04 +0000 Subject: r6225: get rid of warnings from my compiler about nested externs (This used to be commit efea76ac71412f8622cd233912309e91b9ea52da) --- source3/param/params.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 9d21d25a24..3b736113be 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -81,6 +81,8 @@ #include "includes.h" +extern BOOL in_client; + /* -------------------------------------------------------------------------- ** * Constants... */ @@ -523,7 +525,6 @@ static BOOL Parse( myFILE *InFile, static myFILE *OpenConfFile( const char *FileName ) { const char *func = "params.c:OpenConfFile() -"; - extern BOOL in_client; int lvl = in_client?1:0; myFILE *ret; -- cgit From 19ca97a70f6b7b41d251eaa76e4d3c980c6eedff Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 24 Jun 2005 20:25:18 +0000 Subject: r7882: Looks like a large patch - but what it actually does is make Samba safe for using our headers and linking with C++ modules. Stops us from using C++ reserved keywords in our code. Jeremy (This used to be commit 9506b8e145982b1160a2f0aee5c9b7a54980940a) --- source3/param/params.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 3b736113be..2a6c8b3e65 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -264,7 +264,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) if( i > (bSize - 2) ) { char *tb; - tb = SMB_REALLOC( bufr, bSize +BUFR_INC ); + tb = (char *)SMB_REALLOC( bufr, bSize +BUFR_INC ); if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return False; @@ -356,7 +356,7 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *) /* Loop until we've found the start of the value. */ if( i > (bSize - 2) ) { /* Ensure there's space for next char. */ - char *tb = SMB_REALLOC( bufr, bSize + BUFR_INC ); + char *tb = (char *)SMB_REALLOC( bufr, bSize + BUFR_INC ); if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return False; @@ -414,7 +414,7 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *) while( (EOF !=c) && (c > 0) ) { if( i > (bSize - 2) ) { /* Make sure there's enough room. */ - char *tb = SMB_REALLOC( bufr, bSize + BUFR_INC ); + char *tb = (char *)SMB_REALLOC( bufr, bSize + BUFR_INC ); if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func)); return False; -- cgit From 0af1500fc0bafe61019f1b2ab1d9e1d369221240 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Feb 2006 22:19:41 +0000 Subject: r13316: Let the carnage begin.... Sync with trunk as off r13315 (This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f) --- source3/param/params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 2a6c8b3e65..f5ce6bdb64 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -532,7 +532,7 @@ static myFILE *OpenConfFile( const char *FileName ) if (!ret) return NULL; - ret->buf = file_load(FileName, &ret->size); + 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)) ); -- cgit From 894358a8f3e338b339b6c37233edef794b312087 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Mar 2006 06:31:04 +0000 Subject: r13915: Fixed a very interesting class of realloc() bugs found by Coverity. realloc can return NULL in one of two cases - (1) the realloc failed, (2) realloc succeeded but the new size requested was zero, in which case this is identical to a free() call. The error paths dealing with these two cases should be different, but mostly weren't. Secondly the standard idiom for dealing with realloc when you know the new size is non-zero is the following : tmp = realloc(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } However, there were *many* *many* places in Samba where we were using the old (broken) idiom of : p = realloc(p, size) if (!p) { return error; } which will leak the memory pointed to by p on realloc fail. This commit (hopefully) fixes all these cases by moving to a standard idiom of : p = SMB_REALLOC(p, size) if (!p) { return error; } Where if the realloc returns null due to the realloc failing or size == 0 we *guarentee* that the storage pointed to by p has been freed. This allows me to remove a lot of code that was dealing with the standard (more verbose) method that required a tmp pointer. This is almost always what you want. When a realloc fails you never usually want the old memory, you want to free it and get into your error processing asap. For the 11 remaining cases where we really do need to keep the old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR, which can be used as follows : tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the pointer p, even on size == 0 or realloc fail. All this is done by a hidden extra argument to Realloc(), BOOL free_old_on_error which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR macros (and their array counterparts). It remains to be seen what this will do to our Coverity bug count :-). Jeremy. (This used to be commit 1d710d06a214f3f1740e80e0bffd6aab44aac2b0) --- source3/param/params.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index f5ce6bdb64..6669e80191 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -262,10 +262,8 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) while( (EOF != c) && (c > 0) ) { /* Check that the buffer is big enough for the next character. */ if( i > (bSize - 2) ) { - char *tb; - - tb = (char *)SMB_REALLOC( bufr, bSize +BUFR_INC ); - if( NULL == tb ) { + char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize +BUFR_INC ); + if(!tb) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return False; } @@ -356,8 +354,8 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *) /* Loop until we've found the start of the value. */ if( i > (bSize - 2) ) { /* Ensure there's space for next char. */ - char *tb = (char *)SMB_REALLOC( bufr, bSize + BUFR_INC ); - if( NULL == tb ) { + char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize + BUFR_INC ); + if (!tb) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return False; } @@ -414,8 +412,8 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *) while( (EOF !=c) && (c > 0) ) { if( i > (bSize - 2) ) { /* Make sure there's enough room. */ - char *tb = (char *)SMB_REALLOC( bufr, bSize + BUFR_INC ); - if( NULL == tb ) { + char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize + BUFR_INC ); + if (!tb) { DEBUG(0, ("%s Memory re-allocation failure.", func)); return False; } -- cgit From 98118545c19ea4236dff9a2ec002efcfe60d81ff Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 27 Jun 2006 17:58:55 +0000 Subject: r16570: Corrected the copyright notice. I had requested and received permission from my management at the University to release under my own copyright. My mistake for entering the wrong info. (This used to be commit c65ebeb02810fb4039555c55779ec62a4a8de564) --- source3/param/params.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 6669e80191..6d036e40f6 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -3,9 +3,9 @@ * * This module Copyright (C) 1990-1998 Karl Auer * - * Rewritten almost completely by Christopher R. Hertel - * at the University of Minnesota, September, 1997. - * This module Copyright (C) 1997-1998 by the University of Minnesota + * 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 -- cgit From c3bbcc608e292397b7f9f12189572f463bb1e322 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 27 Aug 2006 16:24:03 +0000 Subject: r17852: Remove a pointless NULL assignment (This used to be commit 9f27824257924485a39bb60f00c9de02f869c4ff) --- source3/param/params.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 6d036e40f6..c4ca5bb906 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -587,7 +587,6 @@ BOOL pm_process( const char *FileName, result = Parse( InFile, sfunc, pfunc ); SAFE_FREE( bufr ); - bufr = NULL; bSize = 0; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/param/params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index c4ca5bb906..887afff86b 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -10,7 +10,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 153cfb9c83534b09f15cc16205d7adb19b394928 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 87c91e4362c51819032bfbebbb273c52e203b227) --- source3/param/params.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 887afff86b..08c35d0967 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -19,8 +19,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 . * * -------------------------------------------------------------------------- ** * -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/param/params.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 08c35d0967..24bef0a506 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -80,7 +80,7 @@ #include "includes.h" -extern BOOL in_client; +extern bool in_client; /* -------------------------------------------------------------------------- ** * Constants... @@ -235,7 +235,7 @@ static int Continuation(char *line, int pos ) * ------------------------------------------------------------------------ ** */ -static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) +static bool Section( myFILE *InFile, bool (*sfunc)(const char *) ) { int c; int i; @@ -341,7 +341,7 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(const char *) ) * ------------------------------------------------------------------------ ** */ -static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *), int c ) +static bool Parameter( myFILE *InFile, bool (*pfunc)(const char *, const char *), int c ) { int i = 0; /* Position within bufr. */ int end = 0; /* bufr[end] is current end-of-string. */ @@ -471,9 +471,9 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(const char *, const char *) * ------------------------------------------------------------------------ ** */ -static BOOL Parse( myFILE *InFile, - BOOL (*sfunc)(const char *), - BOOL (*pfunc)(const char *, const char *) ) +static bool Parse( myFILE *InFile, + bool (*sfunc)(const char *), + bool (*pfunc)(const char *, const char *) ) { int c; @@ -556,9 +556,9 @@ static myFILE *OpenConfFile( const char *FileName ) * ------------------------------------------------------------------------ ** */ -BOOL pm_process( const char *FileName, - BOOL (*sfunc)(const char *), - BOOL (*pfunc)(const char *, const char *) ) +bool pm_process( const char *FileName, + bool (*sfunc)(const char *), + bool (*pfunc)(const char *, const char *) ) { int result; myFILE *InFile; -- cgit From ff1a79f24bd0dcc69f7f38b13d6780255174a2b6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 9 Dec 2007 17:40:48 +0100 Subject: Remove two completely unnecessary globals Can someone look over this? To me it looks as if bufr was only made static to save a malloc during an included smb.conf file. I think that's pretty much pointless. (This used to be commit 068e8de72ceb49ef2e02cca1913b6d2197bab5e0) --- source3/param/params.c | 112 ++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 61 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 24bef0a506..44b44d99b6 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -99,9 +99,6 @@ extern bool in_client; * bSize - The size of the global buffer . */ -static char *bufr = NULL; -static int bSize = 0; - /* we can't use FILE* due to the 256 fd limit - use this cheap hack instead */ typedef struct { @@ -212,7 +209,7 @@ static int EatComment( myFILE *InFile ) * *****************************************************************************/ -static int Continuation(char *line, int pos ) +static int Continuation(uint8_t *line, int pos ) { pos--; while( (pos >= 0) && isspace((int)line[pos])) @@ -235,7 +232,7 @@ static int Continuation(char *line, int pos ) * ------------------------------------------------------------------------ ** */ -static bool Section( myFILE *InFile, bool (*sfunc)(const char *) ) +static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *) ) { int c; int i; @@ -260,37 +257,37 @@ static bool Section( myFILE *InFile, bool (*sfunc)(const char *) ) while( (EOF != c) && (c > 0) ) { /* Check that the buffer is big enough for the next character. */ - if( i > (bSize - 2) ) { - char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize +BUFR_INC ); + 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; } - bufr = tb; - bSize += BUFR_INC; + 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( bufr, i ); /* Check for line continuation. */ + i = Continuation( buf->data, i ); /* Check for line continuation. */ if( i < 0 ) { - bufr[end] = '\0'; - DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, bufr )); + buf->data[end] = '\0'; + DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, buf->data )); return False; } - end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); + 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. */ - bufr[end] = ' '; + buf->data[end] = ' '; i = end + 1; c = EatWhitespace( InFile ); } else { - bufr[i++] = c; + buf->data[i++] = c; end = i; c = mygetc( InFile ); } @@ -298,13 +295,13 @@ static bool Section( myFILE *InFile, bool (*sfunc)(const char *) ) if (AtSectionEnd(InFile)) { /* Got to the closing bracket. */ - bufr[end] = '\0'; + 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(bufr) ) /* Got a valid name. Deal with it. */ + if( !sfunc((char *)buf->data) ) /* Got a valid name. Deal with it. */ return False; EatComment( InFile ); /* Finish off the line. */ return True; @@ -313,7 +310,7 @@ static bool Section( myFILE *InFile, bool (*sfunc)(const char *) ) } /* 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, bufr )); + DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, buf->data )); return False; } @@ -341,7 +338,7 @@ static bool Section( myFILE *InFile, bool (*sfunc)(const char *) ) * ------------------------------------------------------------------------ ** */ -static bool Parameter( myFILE *InFile, bool (*pfunc)(const char *, const char *), int c ) +static bool Parameter( DATA_BLOB *buf, myFILE *InFile, bool (*pfunc)(const char *, const char *), int c ) { int i = 0; /* Position within bufr. */ int end = 0; /* bufr[end] is current end-of-string. */ @@ -351,15 +348,15 @@ static bool Parameter( myFILE *InFile, bool (*pfunc)(const char *, const char *) /* Read the parameter name. */ while( 0 == vstart ) { /* Loop until we've found the start of the value. */ - if( i > (bSize - 2) ) { + if( i > (buf->length - 2) ) { /* Ensure there's space for next char. */ - char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize + BUFR_INC ); + 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; } - bufr = tb; - bSize += BUFR_INC; + buf->data = tb; + buf->length += BUFR_INC; } switch(c) { @@ -369,37 +366,37 @@ static bool Parameter( myFILE *InFile, bool (*pfunc)(const char *, const char *) DEBUG(0, ("%s Invalid parameter name in config. file.\n", func )); return False; } - bufr[end++] = '\0'; /* Mark end of string & advance. */ + buf->data[end++] = '\0'; /* Mark end of string & advance. */ i = end; /* New string starts here. */ vstart = end; /* New string is parameter value. */ - bufr[i] = '\0'; /* New string is nul, for now. */ + buf->data[i] = '\0'; /* New string is nul, for now. */ break; case '\n': /* Find continuation char, else error. */ - i = Continuation( bufr, i ); + i = Continuation( buf->data, i ); if( i < 0 ) { - bufr[end] = '\0'; - DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, bufr )); + buf->data[end] = '\0'; + DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, buf->data )); return True; } - end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i); + 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: - bufr[i] = '\0'; - DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr )); + 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. */ - bufr[end] = ' '; + buf->data[end] = ' '; i = end + 1; c = EatWhitespace( InFile ); } else { - bufr[i++] = c; + buf->data[i++] = c; end = i; c = mygetc( InFile ); } @@ -409,15 +406,15 @@ static bool Parameter( myFILE *InFile, bool (*pfunc)(const char *, const char *) /* Now parse the value. */ c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */ while( (EOF !=c) && (c > 0) ) { - if( i > (bSize - 2) ) { + if( i > (buf->length - 2) ) { /* Make sure there's enough room. */ - char *tb = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR( bufr, bSize + BUFR_INC ); + 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; } - bufr = tb; - bSize += BUFR_INC; + buf->data = tb; + buf->length += BUFR_INC; } switch(c) { @@ -426,27 +423,27 @@ static bool Parameter( myFILE *InFile, bool (*pfunc)(const char *, const char *) break; /* removes them. */ case '\n': /* Marks end of value unless there's a '\'. */ - i = Continuation( bufr, i ); + i = Continuation( buf->data, i ); if( i < 0 ) { c = 0; } else { - for( end = i; (end >= 0) && isspace((int)bufr[end]); end-- ) + 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 . This allows trimming */ - bufr[i++] = c; + buf->data[i++] = c; if( !isspace( c ) ) /* of whitespace at the end of the line. */ end = i; c = mygetc( InFile ); break; } } - bufr[end] = '\0'; /* End of value. */ + buf->data[end] = '\0'; /* End of value. */ - return( pfunc( bufr, &bufr[vstart] ) ); /* Pass name & value to pfunc(). */ + return( pfunc( (char *)buf->data, (char *)&buf->data[vstart] ) ); /* Pass name & value to pfunc(). */ } /* ------------------------------------------------------------------------ ** @@ -471,7 +468,7 @@ static bool Parameter( myFILE *InFile, bool (*pfunc)(const char *, const char *) * ------------------------------------------------------------------------ ** */ -static bool Parse( myFILE *InFile, +static bool Parse( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *), bool (*pfunc)(const char *, const char *) ) { @@ -490,7 +487,7 @@ static bool Parse( myFILE *InFile, break; case '[': /* Section Header. */ - if( !Section( InFile, sfunc ) ) + if( !Section( buf, InFile, sfunc ) ) return False; c = EatWhitespace( InFile ); break; @@ -500,7 +497,7 @@ static bool Parse( myFILE *InFile, break; default: /* Parameter line. */ - if( !Parameter( InFile, pfunc, c ) ) + if( !Parameter( buf, InFile, pfunc, c ) ) return False; c = EatWhitespace( InFile ); break; @@ -563,6 +560,7 @@ bool pm_process( const char *FileName, int result; myFILE *InFile; const char *func = "params.c:pm_process() -"; + DATA_BLOB buf; InFile = OpenConfFile( FileName ); /* Open the config file. */ if( NULL == InFile ) @@ -570,25 +568,17 @@ bool pm_process( const char *FileName, DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) ); - if( NULL != bufr ) { - /* If we already have a buffer */ - /* (recursive call), then just */ - /* use it. */ - result = Parse( InFile, sfunc, pfunc ); - } else { - bSize = BUFR_INC; - bufr = (char *)SMB_MALLOC( bSize ); - if( NULL == bufr ) { - DEBUG(0,("%s memory allocation failure.\n", func)); - myfile_close(InFile); - return False; - } + buf = data_blob(NULL, 256); - result = Parse( InFile, sfunc, pfunc ); - SAFE_FREE( bufr ); - bSize = 0; + if (buf.data == NULL) { + DEBUG(0,("%s memory allocation failure.\n", func)); + myfile_close(InFile); + return False; } + result = Parse( &buf, InFile, sfunc, pfunc ); + data_blob_free(&buf); + myfile_close(InFile); if( !result ) { -- cgit From 914cd3e483bd83fb4d8e769b90d9136336ea51e9 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 6 Mar 2008 10:41:42 -0500 Subject: Eliminate global variable in_client and a plethora of extern declarations. Derrell (This used to be commit b7f34e7ef2907b498a0645ce68f2773ed7d60cdc) --- source3/param/params.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index 44b44d99b6..e69715e4a3 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -80,8 +80,6 @@ #include "includes.h" -extern bool in_client; - /* -------------------------------------------------------------------------- ** * Constants... */ @@ -519,7 +517,7 @@ static bool Parse( DATA_BLOB *buf, myFILE *InFile, static myFILE *OpenConfFile( const char *FileName ) { const char *func = "params.c:OpenConfFile() -"; - int lvl = in_client?1:0; + int lvl = lp_is_in_client() ? 1 : 0; myFILE *ret; ret = SMB_MALLOC_P(myFILE); -- cgit From 2b84aea424410a1c4d5b29849bfe4ee411c78fac Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 25 Mar 2008 22:53:47 +0100 Subject: loadparm: add userdata parameter to do_section() and do_parameter(). The userdata is currently unused. It can be used in the future for passing a context like in samba4 code. Michael (This used to be commit 31b31171bd88c41443268d3300c492e2347b9e73) --- source3/param/params.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'source3/param/params.c') diff --git a/source3/param/params.c b/source3/param/params.c index e69715e4a3..478376c9e9 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -230,7 +230,7 @@ static int Continuation(uint8_t *line, int pos ) * ------------------------------------------------------------------------ ** */ -static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *) ) +static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *, void *), void *userdata ) { int c; int i; @@ -299,7 +299,7 @@ static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *) DEBUG(0, ("%s Empty section name in configuration file.\n", func )); return False; } - if( !sfunc((char *)buf->data) ) /* Got a valid name. Deal with it. */ + if( !sfunc((char *)buf->data, userdata) ) /* Got a valid name. Deal with it. */ return False; EatComment( InFile ); /* Finish off the line. */ return True; @@ -336,7 +336,7 @@ static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *) * ------------------------------------------------------------------------ ** */ -static bool Parameter( DATA_BLOB *buf, myFILE *InFile, bool (*pfunc)(const char *, const char *), int c ) +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. */ @@ -441,7 +441,7 @@ static bool Parameter( DATA_BLOB *buf, myFILE *InFile, bool (*pfunc)(const char } buf->data[end] = '\0'; /* End of value. */ - return( pfunc( (char *)buf->data, (char *)&buf->data[vstart] ) ); /* Pass name & value to pfunc(). */ + return( pfunc( (char *)buf->data, (char *)&buf->data[vstart], userdata ) ); /* Pass name & value to pfunc(). */ } /* ------------------------------------------------------------------------ ** @@ -467,8 +467,9 @@ static bool Parameter( DATA_BLOB *buf, myFILE *InFile, bool (*pfunc)(const char */ static bool Parse( DATA_BLOB *buf, myFILE *InFile, - bool (*sfunc)(const char *), - bool (*pfunc)(const char *, const char *) ) + bool (*sfunc)(const char *, void *), + bool (*pfunc)(const char *, const char *, void *), + void *userdata) { int c; @@ -485,7 +486,7 @@ static bool Parse( DATA_BLOB *buf, myFILE *InFile, break; case '[': /* Section Header. */ - if( !Section( buf, InFile, sfunc ) ) + if( !Section( buf, InFile, sfunc, userdata ) ) return False; c = EatWhitespace( InFile ); break; @@ -495,7 +496,7 @@ static bool Parse( DATA_BLOB *buf, myFILE *InFile, break; default: /* Parameter line. */ - if( !Parameter( buf, InFile, pfunc, c ) ) + if( !Parameter( buf, InFile, pfunc, c, userdata ) ) return False; c = EatWhitespace( InFile ); break; @@ -552,8 +553,9 @@ static myFILE *OpenConfFile( const char *FileName ) */ bool pm_process( const char *FileName, - bool (*sfunc)(const char *), - bool (*pfunc)(const char *, const char *) ) + bool (*sfunc)(const char *, void *), + bool (*pfunc)(const char *, const char *, void *), + void *userdata) { int result; myFILE *InFile; @@ -574,7 +576,7 @@ bool pm_process( const char *FileName, return False; } - result = Parse( &buf, InFile, sfunc, pfunc ); + result = Parse( &buf, InFile, sfunc, pfunc, userdata ); data_blob_free(&buf); myfile_close(InFile); -- cgit