summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-10-18 18:30:10 +0200
committerJelmer Vernooij <jelmer@samba.org>2008-10-18 18:30:10 +0200
commit2243479b7415942604284028cd34a20aa0ba79c0 (patch)
tree9d13b463baaccdcab307943f6896592f8385a677
parent6a89b59ca6187ef6e06124c2aa729be18b43bb75 (diff)
parent4f9b6fdce4340a1022f659daaa035d0336ff6b53 (diff)
downloadsamba-2243479b7415942604284028cd34a20aa0ba79c0.tar.gz
samba-2243479b7415942604284028cd34a20aa0ba79c0.tar.bz2
samba-2243479b7415942604284028cd34a20aa0ba79c0.zip
Merge branch 'master' of ssh://git.samba.org/data/git/samba
-rw-r--r--.gitignore6
-rw-r--r--lib/util/README6
-rw-r--r--lib/util/config.mk1
-rw-r--r--lib/util/substitute.c165
-rw-r--r--lib/util/util_str.c138
-rw-r--r--source3/Makefile.in2
-rw-r--r--source3/include/proto.h4
-rw-r--r--source3/lib/dbwrap_ctdb.c4
-rw-r--r--source3/lib/dbwrap_file.c2
-rw-r--r--source3/lib/dbwrap_tdb.c6
-rw-r--r--source3/lib/util_str.c25
-rw-r--r--source3/param/loadparm.c6
-rw-r--r--source3/param/params.c590
-rw-r--r--source3/param/test_lp_load.c2
-rw-r--r--source3/rpcclient/cmd_spoolss.c2
-rw-r--r--source3/utils/ntlm_auth.c8
-rw-r--r--source3/utils/testparm.c2
-rw-r--r--source3/web/swat.c3
18 files changed, 197 insertions, 775 deletions
diff --git a/.gitignore b/.gitignore
index b61bf4e501..e617400cc5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -181,7 +181,7 @@ source4/libcli/composite/proto.h
source4/libcli/finddcs.h
source4/libcli/ldap/ldap_proto.h
source4/libcli/libcli_proto.h
-source4/libcli/nbt/nbtname.h
+libcli/nbt/nbtname.h
source4/libcli/nbt/nbt_proto.h
source4/libcli/ndr_netlogon_proto.h
source4/libcli/netlogon_proto.h
@@ -196,7 +196,7 @@ source4/libcli/util/proto.h
source4/libcli/wrepl/winsrepl_proto.h
source4/lib/cmdline/credentials.h
source4/lib/cmdline/popt_credentials.h
-source4/lib/crypto/test_proto.h
+lib/crypto/test_proto.h
source4/lib/db_wrap_proto.h
source4/lib/ldb/bin
source4/lib/ldb/examples/ldbreader
@@ -230,7 +230,7 @@ source4/lib/tdb/bin/tdbdump
source4/lib/tdb/bin/tdbtool
source4/lib/tdb/bin/tdbtorture
source4/lib/tdr/tdr_proto.h
-source4/lib/util/apidocs
+lib/util/apidocs
lib/util/asn1_proto.h
lib/util/pidfile.h
lib/util/unix_privs.h
diff --git a/lib/util/README b/lib/util/README
new file mode 100644
index 0000000000..fffd44d580
--- /dev/null
+++ b/lib/util/README
@@ -0,0 +1,6 @@
+This directory contains libutil (until we can think of a better name)
+
+The idea is that this library contains simple but useful data structures
+and support functions that are generally useful; not just for Samba but for
+other projects as well. Functions here should not depend on any external
+libraries, just on libc (perhaps partially provided by libreplace).
diff --git a/lib/util/config.mk b/lib/util/config.mk
index aa3c94ccae..5488534f26 100644
--- a/lib/util/config.mk
+++ b/lib/util/config.mk
@@ -14,6 +14,7 @@ LIBSAMBA-UTIL_OBJ_FILES = $(addprefix $(libutilsrcdir)/, \
genrand.o \
dprintf.o \
util_str.o \
+ substitute.o \
util_strlist.o \
util_file.o \
data_blob.o \
diff --git a/lib/util/substitute.c b/lib/util/substitute.c
new file mode 100644
index 0000000000..84514ac714
--- /dev/null
+++ b/lib/util/substitute.c
@@ -0,0 +1,165 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+
+ Copyright (C) Andrew Tridgell 1992-2001
+ Copyright (C) Simo Sorce 2001-2002
+ Copyright (C) Martin Pool 2003
+ Copyright (C) James Peach 2005
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+
+/**
+ * @file
+ * @brief Substitute utilities.
+ **/
+
+/**
+ Substitute a string for a pattern in another string. Make sure there is
+ enough room!
+
+ This routine looks for pattern in s and replaces it with
+ insert. It may do multiple replacements.
+
+ Any of " ; ' $ or ` in the insert string are replaced with _
+ if len==0 then the string cannot be extended. This is different from the old
+ use of len==0 which was for no length checks to be done.
+**/
+
+_PUBLIC_ void string_sub(char *s, const char *pattern, const char *insert, size_t len)
+{
+ char *p;
+ ssize_t ls, lp, li, i;
+
+ if (!insert || !pattern || !*pattern || !s)
+ return;
+
+ ls = (ssize_t)strlen(s);
+ lp = (ssize_t)strlen(pattern);
+ li = (ssize_t)strlen(insert);
+
+ if (len == 0)
+ len = ls + 1; /* len is number of *bytes* */
+
+ while (lp <= ls && (p = strstr(s, pattern))) {
+ if (ls + (li-lp) >= len) {
+ DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n",
+ (int)(ls + (li-lp) - len),
+ pattern, (int)len));
+ break;
+ }
+ if (li != lp) {
+ memmove(p+li,p+lp,strlen(p+lp)+1);
+ }
+ for (i=0;i<li;i++) {
+ switch (insert[i]) {
+ case '`':
+ case '"':
+ case '\'':
+ case ';':
+ case '$':
+ case '%':
+ case '\r':
+ case '\n':
+ p[i] = '_';
+ break;
+ default:
+ p[i] = insert[i];
+ }
+ }
+ s = p + li;
+ ls += (li-lp);
+ }
+}
+
+/**
+ * Talloc'ed version of string_sub
+ */
+_PUBLIC_ char *string_sub_talloc(TALLOC_CTX *mem_ctx, const char *s,
+ const char *pattern, const char *insert)
+{
+ const char *p;
+ char *ret;
+ size_t len, alloc_len;
+
+ if (insert == NULL || pattern == NULL || !*pattern || s == NULL)
+ return NULL;
+
+ /* determine length needed */
+ len = strlen(s);
+
+ for (p = strstr(s, pattern); p != NULL;
+ p = strstr(p+strlen(pattern), pattern)) {
+ len += strlen(insert) - strlen(pattern);
+ }
+
+ alloc_len = MAX(len, strlen(s))+1;
+ ret = talloc_array(mem_ctx, char, alloc_len);
+ if (ret == NULL)
+ return NULL;
+ strncpy(ret, s, alloc_len);
+ string_sub(ret, pattern, insert, alloc_len);
+
+ ret = talloc_realloc(mem_ctx, ret, char, len+1);
+ if (ret == NULL)
+ return NULL;
+
+ SMB_ASSERT(ret[len] == '\0');
+
+ return ret;
+}
+
+/**
+ Similar to string_sub() but allows for any character to be substituted.
+ Use with caution!
+ if len==0 then the string cannot be extended. This is different from the old
+ use of len==0 which was for no length checks to be done.
+**/
+
+_PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len)
+{
+ char *p;
+ ssize_t ls,lp,li;
+
+ if (!insert || !pattern || !s)
+ return;
+
+ ls = (ssize_t)strlen(s);
+ lp = (ssize_t)strlen(pattern);
+ li = (ssize_t)strlen(insert);
+
+ if (!*pattern)
+ return;
+
+ if (len == 0)
+ len = ls + 1; /* len is number of *bytes* */
+
+ while (lp <= ls && (p = strstr(s,pattern))) {
+ if (ls + (li-lp) >= len) {
+ DEBUG(0,("ERROR: string overflow by %d in all_string_sub(%.50s, %d)\n",
+ (int)(ls + (li-lp) - len),
+ pattern, (int)len));
+ break;
+ }
+ if (li != lp) {
+ memmove(p+li,p+lp,strlen(p+lp)+1);
+ }
+ memcpy(p, insert, li);
+ s = p + li;
+ ls += (li-lp);
+ }
+}
diff --git a/lib/util/util_str.c b/lib/util/util_str.c
index 389b289bfb..afa772a8a8 100644
--- a/lib/util/util_str.c
+++ b/lib/util/util_str.c
@@ -260,144 +260,6 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_
}
/**
- Substitute a string for a pattern in another string. Make sure there is
- enough room!
-
- This routine looks for pattern in s and replaces it with
- insert. It may do multiple replacements.
-
- Any of " ; ' $ or ` in the insert string are replaced with _
- if len==0 then the string cannot be extended. This is different from the old
- use of len==0 which was for no length checks to be done.
-**/
-
-_PUBLIC_ void string_sub(char *s, const char *pattern, const char *insert, size_t len)
-{
- char *p;
- ssize_t ls, lp, li, i;
-
- if (!insert || !pattern || !*pattern || !s)
- return;
-
- ls = (ssize_t)strlen(s);
- lp = (ssize_t)strlen(pattern);
- li = (ssize_t)strlen(insert);
-
- if (len == 0)
- len = ls + 1; /* len is number of *bytes* */
-
- while (lp <= ls && (p = strstr(s, pattern))) {
- if (ls + (li-lp) >= len) {
- DEBUG(0,("ERROR: string overflow by %d in string_sub(%.50s, %d)\n",
- (int)(ls + (li-lp) - len),
- pattern, (int)len));
- break;
- }
- if (li != lp) {
- memmove(p+li,p+lp,strlen(p+lp)+1);
- }
- for (i=0;i<li;i++) {
- switch (insert[i]) {
- case '`':
- case '"':
- case '\'':
- case ';':
- case '$':
- case '%':
- case '\r':
- case '\n':
- p[i] = '_';
- break;
- default:
- p[i] = insert[i];
- }
- }
- s = p + li;
- ls += (li-lp);
- }
-}
-
-/**
- * Talloc'ed version of string_sub
- */
-_PUBLIC_ char *string_sub_talloc(TALLOC_CTX *mem_ctx, const char *s,
- const char *pattern, const char *insert)
-{
- const char *p;
- char *ret;
- size_t len, alloc_len;
-
- if (insert == NULL || pattern == NULL || !*pattern || s == NULL)
- return NULL;
-
- /* determine length needed */
- len = strlen(s);
-
- for (p = strstr(s, pattern); p != NULL;
- p = strstr(p+strlen(pattern), pattern)) {
- len += strlen(insert) - strlen(pattern);
- }
-
- alloc_len = MAX(len, strlen(s))+1;
- ret = talloc_array(mem_ctx, char, alloc_len);
- if (ret == NULL)
- return NULL;
- strncpy(ret, s, alloc_len);
- string_sub(ret, pattern, insert, alloc_len);
-
- ret = talloc_realloc(mem_ctx, ret, char, len+1);
- if (ret == NULL)
- return NULL;
-
- SMB_ASSERT(ret[len] == '\0');
-
- return ret;
-}
-
-/**
- Similar to string_sub() but allows for any character to be substituted.
- Use with caution!
- if len==0 then the string cannot be extended. This is different from the old
- use of len==0 which was for no length checks to be done.
-**/
-
-_PUBLIC_ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len)
-{
- char *p;
- ssize_t ls,lp,li;
-
- if (!insert || !pattern || !s)
- return;
-
- ls = (ssize_t)strlen(s);
- lp = (ssize_t)strlen(pattern);
- li = (ssize_t)strlen(insert);
-
- if (!*pattern)
- return;
-
- if (len == 0)
- len = ls + 1; /* len is number of *bytes* */
-
- while (lp <= ls && (p = strstr(s,pattern))) {
- if (ls + (li-lp) >= len) {
- DEBUG(0,("ERROR: string overflow by %d in all_string_sub(%.50s, %d)\n",
- (int)(ls + (li-lp) - len),
- pattern, (int)len));
- break;
- }
- if (li != lp) {
- memmove(p+li,p+lp,strlen(p+lp)+1);
- }
- memcpy(p, insert, li);
- s = p + li;
- ls += (li-lp);
- }
-}
-
-
-
-/**
Unescape a URL encoded string, in place.
**/
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 1b460f414e..c880f79eb5 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -360,7 +360,7 @@ READLINE_OBJ = lib/readline.o
# Be sure to include them into your application
POPT_LIB_OBJ = lib/popt_common.o
-PARAM_WITHOUT_REG_OBJ = dynconfig.o param/loadparm.o param/params.o param/util.o lib/sharesec.o lib/ldap_debug_handler.o
+PARAM_WITHOUT_REG_OBJ = dynconfig.o param/loadparm.o ../lib/util/params.o param/util.o lib/sharesec.o lib/ldap_debug_handler.o
PARAM_REG_ADD_OBJ = $(REG_SMBCONF_OBJ) $(LIBSMBCONF_OBJ) $(PRIVILEGES_BASIC_OBJ)
PARAM_OBJ = $(PARAM_WITHOUT_REG_OBJ) $(PARAM_REG_ADD_OBJ)
diff --git a/source3/include/proto.h b/source3/include/proto.h
index cab294d8b1..ba84574653 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1614,7 +1614,7 @@ char *alpha_strcpy_fn(const char *fn,
char *StrnCpy_fn(const char *fn, int line,char *dest,const char *src,size_t n);
size_t strhex_to_str(char *buf, size_t buf_len, const char *strhex, size_t strhex_len);
DATA_BLOB strhex_to_data_blob(TALLOC_CTX *mem_ctx, const char *strhex);
-char *hex_encode(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len);
+char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len);
bool in_list(const char *s, const char *list, bool casesensitive);
void string_free(char **s);
bool string_set(char **dest,const char *src);
@@ -1664,7 +1664,7 @@ char *binary_string(char *buf, int len);
int fstr_sprintf(fstring s, const char *fmt, ...);
char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep);
char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
-bool str_list_compare(char **list1, char **list2);
+bool str_list_equal(const char **list1, const char **list2);
size_t str_list_length( const char * const*list );
bool str_list_sub_basic( char **list, const char *smb_name,
const char *domain_name );
diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c
index 2818634b14..38daa61b33 100644
--- a/source3/lib/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap_ctdb.c
@@ -821,7 +821,7 @@ static int db_ctdb_record_destr(struct db_record* data)
? "Unlocking db %u key %s\n"
: "Unlocking db %u key %.20s\n",
(int)crec->ctdb_ctx->db_id,
- hex_encode(data, (unsigned char *)data->key.dptr,
+ hex_encode_talloc(data, (unsigned char *)data->key.dptr,
data->key.dsize)));
if (tdb_chainunlock(crec->ctdb_ctx->wtdb->tdb, data->key) != 0) {
@@ -871,7 +871,7 @@ static struct db_record *fetch_locked_internal(struct db_ctdb_ctx *ctx,
again:
if (DEBUGLEVEL >= 10) {
- char *keystr = hex_encode(result, key.dptr, key.dsize);
+ char *keystr = hex_encode_talloc(result, key.dptr, key.dsize);
DEBUG(10, (DEBUGLEVEL > 10
? "Locking db %u key %s\n"
: "Locking db %u key %.20s\n",
diff --git a/source3/lib/dbwrap_file.c b/source3/lib/dbwrap_file.c
index e3779de1e4..69ad8e4b20 100644
--- a/source3/lib/dbwrap_file.c
+++ b/source3/lib/dbwrap_file.c
@@ -105,7 +105,7 @@ static struct db_record *db_file_fetch_locked(struct db_context *db,
/* Cut to 8 bits */
file->hash = fsh(key.dptr, key.dsize);
- file->name = hex_encode(file, (unsigned char *)key.dptr, key.dsize);
+ file->name = hex_encode_talloc(file, (unsigned char *)key.dptr, key.dsize);
if (file->name == NULL) {
DEBUG(0, ("hex_encode failed\n"));
TALLOC_FREE(result);
diff --git a/source3/lib/dbwrap_tdb.c b/source3/lib/dbwrap_tdb.c
index 7bdadd3770..4860c61ab0 100644
--- a/source3/lib/dbwrap_tdb.c
+++ b/source3/lib/dbwrap_tdb.c
@@ -31,14 +31,14 @@ static int db_tdb_record_destr(struct db_record* data)
struct db_tdb_ctx *ctx =
talloc_get_type_abort(data->private_data, struct db_tdb_ctx);
- /* This hex_encode() call allocates memory on data context. By way how current
+ /* This hex_encode_talloc() call allocates memory on data context. By way how current
__talloc_free() code works, it is OK to allocate in the destructor as
the children of data will be freed after call to the destructor and this
new 'child' will be caught and freed correctly.
*/
DEBUG(10, (DEBUGLEVEL > 10
? "Unlocking key %s\n" : "Unlocking key %.20s\n",
- hex_encode(data, (unsigned char *)data->key.dptr,
+ hex_encode_talloc(data, (unsigned char *)data->key.dptr,
data->key.dsize)));
if (tdb_chainunlock(ctx->wtdb->tdb, data->key) != 0) {
@@ -94,7 +94,7 @@ static struct db_record *db_tdb_fetch_locked(struct db_context *db,
/* Do not accidently allocate/deallocate w/o need when debug level is lower than needed */
if(DEBUGLEVEL >= 10) {
- char *keystr = hex_encode(NULL, (unsigned char*)key.dptr, key.dsize);
+ char *keystr = hex_encode_talloc(NULL, (unsigned char*)key.dptr, key.dsize);
DEBUG(10, (DEBUGLEVEL > 10
? "Locking key %s\n" : "Locking key %.20s\n",
keystr));
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c
index 5d1893a85b..f6783f10ff 100644
--- a/source3/lib/util_str.c
+++ b/source3/lib/util_str.c
@@ -939,7 +939,7 @@ DATA_BLOB strhex_to_data_blob(TALLOC_CTX *mem_ctx, const char *strhex)
* Routine to print a buffer as HEX digits, into an allocated string.
*/
-char *hex_encode(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len)
+char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len)
{
int i;
char *hex_buffer;
@@ -1843,29 +1843,6 @@ int fstr_sprintf(fstring s, const char *fmt, ...)
#define S_LIST_ABS 16 /* List Allocation Block Size */
-/**
- * Return true if all the elements of the list match exactly.
- **/
-bool str_list_compare(char **list1, char **list2)
-{
- int num;
-
- if (!list1 || !list2)
- return (list1 == list2);
-
- for (num = 0; list1[num]; num++) {
- if (!list2[num])
- return false;
- if (!strcsequal(list1[num], list2[num]))
- return false;
- }
- if (list2[num])
- return false; /* if list2 has more elements than list1 fail */
-
- return true;
-}
-
-
/******************************************************************************
version of standard_sub_basic() for string lists; uses talloc_sub_basic()
for the work
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 3401bd16a0..d91d34d29b 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -7423,7 +7423,7 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
return (*((char *)ptr1) == *((char *)ptr2));
case P_LIST:
- return str_list_compare(*(char ***)ptr1, *(char ***)ptr2);
+ return str_list_equal(*(const char ***)ptr1, *(const char ***)ptr2);
case P_STRING:
case P_USTRING:
@@ -7512,8 +7512,8 @@ static bool is_default(int i)
return False;
switch (parm_table[i].type) {
case P_LIST:
- return str_list_compare (parm_table[i].def.lvalue,
- *(char ***)parm_table[i].ptr);
+ return str_list_equal((const char **)parm_table[i].def.lvalue,
+ *(const char ***)parm_table[i].ptr);
case P_STRING:
case P_USTRING:
return strequal(parm_table[i].def.svalue,
diff --git a/source3/param/params.c b/source3/param/params.c
deleted file mode 100644
index 97db613fc4..0000000000
--- a/source3/param/params.c
+++ /dev/null
@@ -1,590 +0,0 @@
-/* -------------------------------------------------------------------------- **
- * Microsoft Network Services for Unix, AKA., Andrew Tridgell's SAMBA.
- *
- * This module Copyright (C) 1990-1998 Karl Auer
- *
- * Rewritten almost completely by Christopher R. Hertel, 1997.
- * This module Copyright (C) 1997-1998 by Christopher R. Hertel
- *
- * -------------------------------------------------------------------------- **
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
- * -------------------------------------------------------------------------- **
- *
- * Module name: params
- *
- * -------------------------------------------------------------------------- **
- *
- * This module performs lexical analysis and initial parsing of a
- * Windows-like parameter file. It recognizes and handles four token
- * types: section-name, parameter-name, parameter-value, and
- * end-of-file. Comments and line continuation are handled
- * internally.
- *
- * The entry point to the module is function pm_process(). This
- * function opens the source file, calls the Parse() function to parse
- * the input, and then closes the file when either the EOF is reached
- * or a fatal error is encountered.
- *
- * A sample parameter file might look like this:
- *
- * [section one]
- * parameter one = value string
- * parameter two = another value
- * [section two]
- * new parameter = some value or t'other
- *
- * The parameter file is divided into sections by section headers:
- * section names enclosed in square brackets (eg. [section one]).
- * Each section contains parameter lines, each of which consist of a
- * parameter name and value delimited by an equal sign. Roughly, the
- * syntax is:
- *
- * <file> :== { <section> } EOF
- *
- * <section> :== <section header> { <parameter line> }
- *
- * <section header> :== '[' NAME ']'
- *
- * <parameter line> :== NAME '=' VALUE '\n'
- *
- * Blank lines and comment lines are ignored. Comment lines are lines
- * beginning with either a semicolon (';') or a pound sign ('#').
- *
- * All whitespace in section names and parameter names is compressed
- * to single spaces. Leading and trailing whitespace is stipped from
- * both names and values.
- *
- * Only the first equals sign in a parameter line is significant.
- * Parameter values may contain equals signs, square brackets and
- * semicolons. Internal whitespace is retained in parameter values,
- * with the exception of the '\r' character, which is stripped for
- * historic reasons. Parameter names may not start with a left square
- * bracket, an equal sign, a pound sign, or a semicolon, because these
- * are used to identify other tokens.
- *
- * -------------------------------------------------------------------------- **
- */
-
-#include "includes.h"
-
-/* -------------------------------------------------------------------------- **
- * Constants...
- */
-
-#define BUFR_INC 1024
-
-
-/* -------------------------------------------------------------------------- **
- * Variables...
- *
- * DEBUGLEVEL - The ubiquitous DEBUGLEVEL. This determines which DEBUG()
- * messages will be produced.
- * bufr - pointer to a global buffer. This is probably a kludge,
- * but it was the nicest kludge I could think of (for now).
- * bSize - The size of the global buffer <bufr>.
- */
-
-/* we can't use FILE* due to the 256 fd limit - use this cheap hack
- instead */
-typedef struct {
- char *buf;
- char *p;
- size_t size;
- char *end_section_p;
-} myFILE;
-
-static int mygetc(myFILE *f)
-{
- if (f->p >= f->buf+f->size)
- return EOF;
- /* be sure to return chars >127 as positive values */
- return (int)( *(f->p++) & 0x00FF );
-}
-
-static void myfile_close(myFILE *f)
-{
- if (!f)
- return;
- TALLOC_FREE(f->buf);
- SAFE_FREE(f);
-}
-
-/* Find the end of the section. We must use mb functions for this. */
-static int FindSectionEnd(myFILE *f)
-{
- f->end_section_p = strchr_m(f->p, ']');
- return f->end_section_p ? 1 : 0;
-}
-
-static int AtSectionEnd(myFILE *f)
-{
- if (f->p == f->end_section_p + 1) {
- f->end_section_p = NULL;
- return 1;
- }
- return 0;
-}
-
-/* -------------------------------------------------------------------------- **
- * Functions...
- */
- /* ------------------------------------------------------------------------ **
- * Scan past whitespace (see ctype(3C)) and return the first non-whitespace
- * character, or newline, or EOF.
- *
- * Input: InFile - Input source.
- *
- * Output: The next non-whitespace character in the input stream.
- *
- * Notes: Because the config files use a line-oriented grammar, we
- * explicitly exclude the newline character from the list of
- * whitespace characters.
- * - Note that both EOF (-1) and the nul character ('\0') are
- * considered end-of-file markers.
- *
- * ------------------------------------------------------------------------ **
- */
-
-static int EatWhitespace( myFILE *InFile )
-{
- int c;
-
- for( c = mygetc( InFile ); isspace( c ) && ('\n' != c); c = mygetc( InFile ) )
- ;
- return( c );
-}
-
- /* ------------------------------------------------------------------------ **
- * Scan to the end of a comment.
- *
- * Input: InFile - Input source.
- *
- * Output: The character that marks the end of the comment. Normally,
- * this will be a newline, but it *might* be an EOF.
- *
- * Notes: Because the config files use a line-oriented grammar, we
- * explicitly exclude the newline character from the list of
- * whitespace characters.
- * - Note that both EOF (-1) and the nul character ('\0') are
- * considered end-of-file markers.
- *
- * ------------------------------------------------------------------------ **
- */
-
-static int EatComment( myFILE *InFile )
-{
- int c;
-
- for( c = mygetc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = mygetc( InFile ) )
- ;
- return( c );
-}
-
-/*****************************************************************************
- * Scan backards within a string to discover if the last non-whitespace
- * character is a line-continuation character ('\\').
- *
- * Input: line - A pointer to a buffer containing the string to be
- * scanned.
- * pos - This is taken to be the offset of the end of the
- * string. This position is *not* scanned.
- *
- * Output: The offset of the '\\' character if it was found, or -1 to
- * indicate that it was not.
- *
- *****************************************************************************/
-
-static int Continuation(uint8_t *line, int pos )
-{
- pos--;
- while( (pos >= 0) && isspace((int)line[pos]))
- pos--;
-
- return (((pos >= 0) && ('\\' == line[pos])) ? pos : -1 );
-}
-
-/* ------------------------------------------------------------------------ **
- * Scan a section name, and pass the name to function sfunc().
- *
- * Input: InFile - Input source.
- * sfunc - Pointer to the function to be called if the section
- * name is successfully read.
- *
- * Output: True if the section name was read and True was returned from
- * <sfunc>. False if <sfunc> failed or if a lexical error was
- * encountered.
- *
- * ------------------------------------------------------------------------ **
- */
-
-static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *, void *), void *userdata )
-{
- int c;
- int i;
- int end;
- const char *func = "params.c:Section() -";
-
- i = 0; /* <i> is the offset of the next free byte in bufr[] and */
- end = 0; /* <end> is the current "end of string" offset. In most */
- /* cases these will be the same, but if the last */
- /* character written to bufr[] is a space, then <end> */
- /* will be one less than <i>. */
-
-
- /* Find the end of the section. We must use mb functions for this. */
- if (!FindSectionEnd(InFile)) {
- DEBUG(0, ("%s No terminating ']' character in section.\n", func) );
- return False;
- }
-
- c = EatWhitespace( InFile ); /* We've already got the '['. Scan */
- /* past initial white space. */
-
- while( (EOF != c) && (c > 0) ) {
- /* Check that the buffer is big enough for the next character. */
- if( i > (buf->length - 2) ) {
- uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR(buf->data, buf->length+BUFR_INC );
- if(!tb) {
- DEBUG(0, ("%s Memory re-allocation failure.", func) );
- return False;
- }
- buf->data = tb;
- buf->length += BUFR_INC;
- }
-
- /* Handle a single character other than section end. */
- switch( c ) {
- case '\n': /* Got newline before closing ']'. */
- i = Continuation( buf->data, i ); /* Check for line continuation. */
- if( i < 0 ) {
- buf->data[end] = '\0';
- DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, buf->data ));
- return False;
- }
- end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i);
- c = mygetc( InFile ); /* Continue with next line. */
- break;
-
- default: /* All else are a valid name chars. */
- if(isspace( c )) {
- /* One space per whitespace region. */
- buf->data[end] = ' ';
- i = end + 1;
- c = EatWhitespace( InFile );
- } else {
- buf->data[i++] = c;
- end = i;
- c = mygetc( InFile );
- }
- }
-
- if (AtSectionEnd(InFile)) {
- /* Got to the closing bracket. */
- buf->data[end] = '\0';
- if( 0 == end ) {
- /* Don't allow an empty name. */
- DEBUG(0, ("%s Empty section name in configuration file.\n", func ));
- return False;
- }
- if( !sfunc((char *)buf->data, userdata) ) /* Got a valid name. Deal with it. */
- return False;
- EatComment( InFile ); /* Finish off the line. */
- return True;
- }
-
- }
-
- /* We arrive here if we've met the EOF before the closing bracket. */
- DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, buf->data ));
- return False;
-}
-
-/* ------------------------------------------------------------------------ **
- * Scan a parameter name and value, and pass these two fields to pfunc().
- *
- * Input: InFile - The input source.
- * pfunc - A pointer to the function that will be called to
- * process the parameter, once it has been scanned.
- * c - The first character of the parameter name, which
- * would have been read by Parse(). Unlike a comment
- * line or a section header, there is no lead-in
- * character that can be discarded.
- *
- * Output: True if the parameter name and value were scanned and processed
- * successfully, else False.
- *
- * Notes: This function is in two parts. The first loop scans the
- * parameter name. Internal whitespace is compressed, and an
- * equal sign (=) terminates the token. Leading and trailing
- * whitespace is discarded. The second loop scans the parameter
- * value. When both have been successfully identified, they are
- * passed to pfunc() for processing.
- *
- * ------------------------------------------------------------------------ **
- */
-
-static bool Parameter( DATA_BLOB *buf, myFILE *InFile, bool (*pfunc)(const char *, const char *, void *), int c, void *userdata )
-{
- int i = 0; /* Position within bufr. */
- int end = 0; /* bufr[end] is current end-of-string. */
- int vstart = 0; /* Starting position of the parameter value. */
- const char *func = "params.c:Parameter() -";
-
- /* Read the parameter name. */
- while( 0 == vstart ) {
- /* Loop until we've found the start of the value. */
- if( i > (buf->length - 2) ) {
- /* Ensure there's space for next char. */
- uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR( buf->data, buf->length + BUFR_INC );
- if (!tb) {
- DEBUG(0, ("%s Memory re-allocation failure.", func) );
- return False;
- }
- buf->data = tb;
- buf->length += BUFR_INC;
- }
-
- switch(c) {
- case '=': /* Equal sign marks end of param name. */
- if( 0 == end ) {
- /* Don't allow an empty name. */
- DEBUG(0, ("%s Invalid parameter name in config. file.\n", func ));
- return False;
- }
- buf->data[end++] = '\0'; /* Mark end of string & advance. */
- i = end; /* New string starts here. */
- vstart = end; /* New string is parameter value. */
- buf->data[i] = '\0'; /* New string is nul, for now. */
- break;
-
- case '\n': /* Find continuation char, else error. */
- i = Continuation( buf->data, i );
- if( i < 0 ) {
- buf->data[end] = '\0';
- DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, buf->data ));
- return True;
- }
- end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i);
- c = mygetc( InFile ); /* Read past eoln. */
- break;
-
- case '\0': /* Shouldn't have EOF within param name. */
- case EOF:
- buf->data[i] = '\0';
- DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, buf->data ));
- return True;
-
- default:
- if(isspace( c )) {
- /* One ' ' per whitespace region. */
- buf->data[end] = ' ';
- i = end + 1;
- c = EatWhitespace( InFile );
- } else {
- buf->data[i++] = c;
- end = i;
- c = mygetc( InFile );
- }
- }
- }
-
- /* Now parse the value. */
- c = EatWhitespace( InFile ); /* Again, trim leading whitespace. */
- while( (EOF !=c) && (c > 0) ) {
- if( i > (buf->length - 2) ) {
- /* Make sure there's enough room. */
- uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR( buf->data, buf->length + BUFR_INC );
- if (!tb) {
- DEBUG(0, ("%s Memory re-allocation failure.", func));
- return False;
- }
- buf->data = tb;
- buf->length += BUFR_INC;
- }
-
- switch(c) {
- case '\r': /* Explicitly remove '\r' because the older */
- c = mygetc( InFile ); /* version called fgets_slash() which also */
- break; /* removes them. */
-
- case '\n': /* Marks end of value unless there's a '\'. */
- i = Continuation( buf->data, i );
- if( i < 0 ) {
- c = 0;
- } else {
- for( end = i; (end >= 0) && isspace((int)buf->data[end]); end-- )
- ;
- c = mygetc( InFile );
- }
- break;
-
- default: /* All others verbatim. Note that spaces do not advance <end>. This allows trimming */
- buf->data[i++] = c;
- if( !isspace( c ) ) /* of whitespace at the end of the line. */
- end = i;
- c = mygetc( InFile );
- break;
- }
- }
- buf->data[end] = '\0'; /* End of value. */
-
- return( pfunc( (char *)buf->data, (char *)&buf->data[vstart], userdata ) ); /* Pass name & value to pfunc(). */
-}
-
-/* ------------------------------------------------------------------------ **
- * Scan & parse the input.
- *
- * Input: InFile - Input source.
- * sfunc - Function to be called when a section name is scanned.
- * See Section().
- * pfunc - Function to be called when a parameter is scanned.
- * See Parameter().
- *
- * Output: True if the file was successfully scanned, else False.
- *
- * Notes: The input can be viewed in terms of 'lines'. There are four
- * types of lines:
- * Blank - May contain whitespace, otherwise empty.
- * Comment - First non-whitespace character is a ';' or '#'.
- * The remainder of the line is ignored.
- * Section - First non-whitespace character is a '['.
- * Parameter - The default case.
- *
- * ------------------------------------------------------------------------ **
- */
-
-static bool Parse( DATA_BLOB *buf, myFILE *InFile,
- bool (*sfunc)(const char *, void *),
- bool (*pfunc)(const char *, const char *, void *),
- void *userdata)
-{
- int c;
-
- c = EatWhitespace( InFile );
- while( (EOF != c) && (c > 0) ) {
- switch( c ) {
- case '\n': /* Blank line. */
- c = EatWhitespace( InFile );
- break;
-
- case ';': /* Comment line. */
- case '#':
- c = EatComment( InFile );
- break;
-
- case '[': /* Section Header. */
- if( !Section( buf, InFile, sfunc, userdata ) )
- return False;
- c = EatWhitespace( InFile );
- break;
-
- case '\\': /* Bogus backslash. */
- c = EatWhitespace( InFile );
- break;
-
- default: /* Parameter line. */
- if( !Parameter( buf, InFile, pfunc, c, userdata ) )
- return False;
- c = EatWhitespace( InFile );
- break;
- }
- }
- return True;
-}
-
-/* ------------------------------------------------------------------------ **
- * Open a configuration file.
- *
- * Input: FileName - The pathname of the config file to be opened.
- *
- * Output: A pointer of type (char **) to the lines of the file
- *
- * ------------------------------------------------------------------------ **
- */
-
-static myFILE *OpenConfFile( const char *FileName )
-{
- const char *func = "params.c:OpenConfFile() -";
- int lvl = lp_is_in_client() ? 1 : 0;
- myFILE *ret;
-
- ret = SMB_MALLOC_P(myFILE);
- if (!ret)
- return NULL;
-
- ret->buf = file_load(FileName, &ret->size, 0, NULL);
- if( NULL == ret->buf ) {
- DEBUG( lvl, ("%s Unable to open configuration file \"%s\":\n\t%s\n",
- func, FileName, strerror(errno)) );
- SAFE_FREE(ret);
- return NULL;
- }
-
- ret->p = ret->buf;
- ret->end_section_p = NULL;
- return( ret );
-}
-
-/* ------------------------------------------------------------------------ **
- * Process the named parameter file.
- *
- * Input: FileName - The pathname of the parameter file to be opened.
- * sfunc - A pointer to a function that will be called when
- * a section name is discovered.
- * pfunc - A pointer to a function that will be called when
- * a parameter name and value are discovered.
- *
- * Output: TRUE if the file was successfully parsed, else FALSE.
- *
- * ------------------------------------------------------------------------ **
- */
-
-bool pm_process( const char *FileName,
- bool (*sfunc)(const char *, void *),
- bool (*pfunc)(const char *, const char *, void *),
- void *userdata)
-{
- int result;
- myFILE *InFile;
- const char *func = "params.c:pm_process() -";
- DATA_BLOB buf;
-
- InFile = OpenConfFile( FileName ); /* Open the config file. */
- if( NULL == InFile )
- return False;
-
- DEBUG( 3, ("%s Processing configuration file \"%s\"\n", func, FileName) );
-
- buf = data_blob(NULL, 256);
-
- if (buf.data == NULL) {
- DEBUG(0,("%s memory allocation failure.\n", func));
- myfile_close(InFile);
- return False;
- }
-
- result = Parse( &buf, InFile, sfunc, pfunc, userdata );
- data_blob_free(&buf);
-
- myfile_close(InFile);
-
- if( !result ) {
- DEBUG(0,("%s Failed. Error returned from params.c:parse().\n", func));
- return False;
- }
-
- return True;
-}
diff --git a/source3/param/test_lp_load.c b/source3/param/test_lp_load.c
index db1bad4726..1ec123e70a 100644
--- a/source3/param/test_lp_load.c
+++ b/source3/param/test_lp_load.c
@@ -81,8 +81,8 @@ int main(int argc, const char **argv)
done:
- TALLOC_FREE(frame);
gfree_loadparm();
+ TALLOC_FREE(frame);
return ret;
}
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 2a9f2b82bb..378ec891a7 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -691,7 +691,7 @@ static void display_reg_value(REGISTRY_VALUE value)
printf("%s: REG_SZ: %s\n", value.valuename, text ? text : "");
break;
case REG_BINARY: {
- char *hex = hex_encode(NULL, value.data_p, value.size);
+ char *hex = hex_encode_talloc(NULL, value.data_p, value.size);
size_t i, len;
printf("%s: REG_BINARY:", value.valuename);
len = strlen(hex);
diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c
index 4586086d73..0a76761cb2 100644
--- a/source3/utils/ntlm_auth.c
+++ b/source3/utils/ntlm_auth.c
@@ -1813,7 +1813,7 @@ static void manage_ntlm_server_1_request(struct ntlm_auth_state *state,
if (ntlm_server_1_lm_session_key
&& (memcmp(zeros, lm_key,
sizeof(lm_key)) != 0)) {
- hex_lm_key = hex_encode(NULL,
+ hex_lm_key = hex_encode_talloc(NULL,
(const unsigned char *)lm_key,
sizeof(lm_key));
x_fprintf(x_stdout, "LANMAN-Session-Key: %s\n", hex_lm_key);
@@ -1823,7 +1823,7 @@ static void manage_ntlm_server_1_request(struct ntlm_auth_state *state,
if (ntlm_server_1_user_session_key
&& (memcmp(zeros, user_session_key,
sizeof(user_session_key)) != 0)) {
- hex_user_session_key = hex_encode(NULL,
+ hex_user_session_key = hex_encode_talloc(NULL,
(const unsigned char *)user_session_key,
sizeof(user_session_key));
x_fprintf(x_stdout, "User-Session-Key: %s\n", hex_user_session_key);
@@ -2262,7 +2262,7 @@ static bool check_auth_crap(void)
if (request_lm_key
&& (memcmp(zeros, lm_key,
sizeof(lm_key)) != 0)) {
- hex_lm_key = hex_encode(NULL, (const unsigned char *)lm_key,
+ hex_lm_key = hex_encode_talloc(NULL, (const unsigned char *)lm_key,
sizeof(lm_key));
x_fprintf(x_stdout, "LM_KEY: %s\n", hex_lm_key);
TALLOC_FREE(hex_lm_key);
@@ -2270,7 +2270,7 @@ static bool check_auth_crap(void)
if (request_user_session_key
&& (memcmp(zeros, user_session_key,
sizeof(user_session_key)) != 0)) {
- hex_user_session_key = hex_encode(NULL, (const unsigned char *)user_session_key,
+ hex_user_session_key = hex_encode_talloc(NULL, (const unsigned char *)user_session_key,
sizeof(user_session_key));
x_fprintf(x_stdout, "NT_KEY: %s\n", hex_user_session_key);
TALLOC_FREE(hex_user_session_key);
diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c
index 05682efe5d..da129cf7c0 100644
--- a/source3/utils/testparm.c
+++ b/source3/utils/testparm.c
@@ -436,8 +436,8 @@ rameter is ignored when using CUPS libraries.\n",
}
done:
- TALLOC_FREE(frame);
gfree_loadparm();
+ TALLOC_FREE(frame);
return ret;
}
diff --git a/source3/web/swat.c b/source3/web/swat.c
index 23fc43f776..27c4b54e2f 100644
--- a/source3/web/swat.c
+++ b/source3/web/swat.c
@@ -384,7 +384,8 @@ static void show_parameters(int snum, int allparameters, unsigned int parm_filte
break;
case P_LIST:
- if (!str_list_compare(*(char ***)ptr, (char **)(parm->def.lvalue))) continue;
+ if (!str_list_equal(*(const char ***)ptr,
+ (const char **)(parm->def.lvalue))) continue;
break;
case P_STRING: