[SCM] Samba Shared Repository - branch master updated - 4f9b6fdce4340a1022f659daaa035d0336ff6b53

Jelmer Vernooij jelmer at samba.org
Sat Oct 18 14:27:18 GMT 2008


The branch, master has been updated
       via  4f9b6fdce4340a1022f659daaa035d0336ff6b53 (commit)
       via  f3f9446ec122d633c50a0c3dba9a9bea9f79c2b0 (commit)
       via  63de2d9823f6211668b4b05cb23764ba69a7dc9a (commit)
       via  89c95454300f28b0241a44fc2aa7886304c90824 (commit)
       via  23c95c9119848aba47a5d533a75c92a9d7a0bc95 (commit)
      from  6c83039eaba70fe983325f15359f1bafc40c4ec6 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 4f9b6fdce4340a1022f659daaa035d0336ff6b53
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Oct 18 16:22:24 2008 +0200

    Fix ignore for libcli/nbt/nbtname.h

commit f3f9446ec122d633c50a0c3dba9a9bea9f79c2b0
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Oct 18 16:16:57 2008 +0200

    Rename hex_encode to hex_encode_talloc,for consistency with samba 4 and heimdal.

commit 63de2d9823f6211668b4b05cb23764ba69a7dc9a
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Oct 18 15:56:45 2008 +0200

    Move substitute functions to a different file.

commit 89c95454300f28b0241a44fc2aa7886304c90824
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sat Oct 18 15:56:07 2008 +0200

    Use str_list_equal() rather than str_list_compare().

commit 23c95c9119848aba47a5d533a75c92a9d7a0bc95
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Fri Oct 17 14:13:39 2008 +0200

    Add libutil README file.

-----------------------------------------------------------------------

Summary of changes:
 .gitignore                      |    2 +-
 lib/util/README                 |    6 ++
 lib/util/config.mk              |    1 +
 lib/util/substitute.c           |  165 +++++++++++++++++++++++++++++++++++++++
 lib/util/util_str.c             |  138 --------------------------------
 source3/include/proto.h         |    4 +-
 source3/lib/dbwrap_ctdb.c       |    4 +-
 source3/lib/dbwrap_file.c       |    2 +-
 source3/lib/dbwrap_tdb.c        |    6 +-
 source3/lib/util_str.c          |   25 +------
 source3/param/loadparm.c        |    6 +-
 source3/rpcclient/cmd_spoolss.c |    2 +-
 source3/utils/ntlm_auth.c       |    8 +-
 source3/web/swat.c              |    3 +-
 14 files changed, 192 insertions(+), 180 deletions(-)
 create mode 100644 lib/util/README
 create mode 100644 lib/util/substitute.c


Changeset truncated at 500 lines:

diff --git a/.gitignore b/.gitignore
index 9815f70..e617400 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
diff --git a/lib/util/README b/lib/util/README
new file mode 100644
index 0000000..fffd44d
--- /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 aa3c94c..5488534 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 0000000..84514ac
--- /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 9ea6403..bf4ae4d 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/include/proto.h b/source3/include/proto.h
index cab294d..ba84574 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 2818634..38daa61 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 e3779de..69ad8e4 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 7bdadd3..4860c61 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 5d1893a..f6783f1 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 3401bd1..d91d34d 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:


-- 
Samba Shared Repository


More information about the samba-cvs mailing list