[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-494-g97c9a40

Volker Lendecke vl at sernet.de
Wed Dec 5 13:36:22 GMT 2007


The branch, v3-2-test has been updated
       via  97c9a4042d36178a728b5e0f8923091c7069366d (commit)
       via  31d0a846db08d845e6cdfd85def4ac1c34031e02 (commit)
       via  111502d3a2901abcff25792bed3c4038a7592410 (commit)
       via  8acd4a202f6b4518c2ce9cdd30f5dfb14b86c07c (commit)
      from  51db8d09a4652d626c093f7bacf075c1c168fc33 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit 97c9a4042d36178a728b5e0f8923091c7069366d
Author: Volker Lendecke <vl at sernet.de>
Date:   Sat Nov 24 15:47:04 2007 +0100

    remove some statics

commit 31d0a846db08d845e6cdfd85def4ac1c34031e02
Author: Volker Lendecke <vl at sernet.de>
Date:   Sat Nov 24 17:27:54 2007 +0100

    Remove some globals

commit 111502d3a2901abcff25792bed3c4038a7592410
Author: Volker Lendecke <vl at sernet.de>
Date:   Sat Nov 24 22:50:36 2007 +0100

    Make share_info_db_init static

commit 8acd4a202f6b4518c2ce9cdd30f5dfb14b86c07c
Author: Volker Lendecke <vl at sernet.de>
Date:   Sun Nov 25 09:33:29 2007 +0100

    Remove a static, and "signal_received" needs to be sig_atomic_t

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

Summary of changes:
 source/include/includes.h         |    3 ++
 source/lib/messages_local.c       |   33 +++++++++--------
 source/lib/sharesec.c             |    2 +-
 source/lib/util_str.c             |   73 +++++++++++++++++++++++++------------
 source/libads/dns.c               |    2 +-
 source/libgpo/gpo_util.c          |    4 +-
 source/libsmb/credentials.c       |   12 ++++---
 source/libsmb/dsgetdcname.c       |    3 +-
 source/libsmb/namecache.c         |    6 ++--
 source/libsmb/namequery.c         |    2 +-
 source/libsmb/nmblib.c            |   49 ++++---------------------
 source/libsmb/trustdom_cache.c    |    2 +-
 source/libsmb/unexpected.c        |   43 ++++++++++++----------
 source/param/loadparm.c           |    7 +++-
 source/rpc_server/srv_wkssvc_nt.c |    8 ++--
 source/torture/rpctorture.c       |   34 +++++++++++++++++
 source/utils/net_conf.c           |    6 ++-
 source/web/swat.c                 |   17 ++++++---
 source/winbindd/winbindd_util.c   |    8 ++--
 19 files changed, 182 insertions(+), 132 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/include/includes.h b/source/include/includes.h
index 9079c3a..22530f7 100644
--- a/source/include/includes.h
+++ b/source/include/includes.h
@@ -1042,6 +1042,9 @@ int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
 
 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
 
+int asprintf_strupper_m(char **strp, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
+
 /* we used to use these fns, but now we have good replacements
    for snprintf and vsnprintf */
 #define slprintf snprintf
diff --git a/source/lib/messages_local.c b/source/lib/messages_local.c
index 5f7c46f..0cd4826 100644
--- a/source/lib/messages_local.c
+++ b/source/lib/messages_local.c
@@ -46,7 +46,7 @@
 #include "librpc/gen_ndr/messaging.h"
 #include "librpc/gen_ndr/ndr_messaging.h"
 
-static int received_signal;
+static sig_atomic_t received_signal;
 
 static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
 				   struct server_id pid, int msg_type,
@@ -118,12 +118,14 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx,
  Form a static tdb key from a pid.
 ******************************************************************/
 
-static TDB_DATA message_key_pid(struct server_id pid)
+static TDB_DATA message_key_pid(TALLOC_CTX *mem_ctx, struct server_id pid)
 {
-	static char key[20];
+	char *key;
 	TDB_DATA kbuf;
 
-	slprintf(key, sizeof(key)-1, "PID/%s", procid_str_static(&pid));
+	key = talloc_asprintf(talloc_tos(), "PID/%s", procid_str_static(&pid));
+
+	SMB_ASSERT(key != NULL);
 	
 	kbuf.dptr = (uint8 *)key;
 	kbuf.dsize = strlen(key)+1;
@@ -289,10 +291,10 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
 {
 	struct messaging_array *msg_array;
 	struct messaging_rec *rec;
-	TALLOC_CTX *mem_ctx;
 	NTSTATUS status;
-	TDB_DATA key = message_key_pid(pid);
+	TDB_DATA key;
 	TDB_CONTEXT *tdb = (TDB_CONTEXT *)backend->private_data;
+	TALLOC_CTX *frame = talloc_stackframe();
 
 	/* NULL pointer means implicit length zero. */
 	if (!data->data) {
@@ -306,16 +308,14 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
 
 	SMB_ASSERT(procid_to_pid(&pid) > 0);
 
-	if (!(mem_ctx = talloc_init("message_send_pid"))) {
-		return NT_STATUS_NO_MEMORY;
-	}
+	key = message_key_pid(frame, pid);
 
 	if (tdb_chainlock(tdb, key) == -1) {
-		TALLOC_FREE(mem_ctx);
+		TALLOC_FREE(frame);
 		return NT_STATUS_LOCK_NOT_GRANTED;
 	}
 
-	status = messaging_tdb_fetch(tdb, key, mem_ctx, &msg_array);
+	status = messaging_tdb_fetch(tdb, key, talloc_tos(), &msg_array);
 
 	if (!NT_STATUS_IS_OK(status)) {
 		goto done;
@@ -329,7 +329,7 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
 		goto done;
 	}
 
-	if (!(rec = TALLOC_REALLOC_ARRAY(mem_ctx, msg_array->messages,
+	if (!(rec = TALLOC_REALLOC_ARRAY(talloc_tos(), msg_array->messages,
 					 struct messaging_rec,
 					 msg_array->num_messages+1))) {
 		status = NT_STATUS_NO_MEMORY;
@@ -356,12 +356,12 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
 	if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
 		DEBUG(2, ("pid %s doesn't exist - deleting messages record\n",
 			  procid_str_static(&pid)));
-		tdb_delete(tdb, message_key_pid(pid));
+		tdb_delete(tdb, message_key_pid(talloc_tos(), pid));
 	}
 
  done:
 	tdb_chainunlock(tdb, key);
-	TALLOC_FREE(mem_ctx);
+	TALLOC_FREE(frame);
 	return status;
 }
 
@@ -374,10 +374,11 @@ static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb,
 				      struct messaging_array **presult)
 {
 	struct messaging_array *result;
-	TDB_DATA key = message_key_pid(procid_self());
+	TDB_DATA key = message_key_pid(mem_ctx, procid_self());
 	NTSTATUS status;
 
 	if (tdb_chainlock(msg_tdb, key) == -1) {
+		TALLOC_FREE(key.dptr);
 		return NT_STATUS_LOCK_NOT_GRANTED;
 	}
 
@@ -393,6 +394,8 @@ static NTSTATUS retrieve_all_messages(TDB_CONTEXT *msg_tdb,
 		*presult = result;
 	}
 
+	TALLOC_FREE(key.dptr);
+
 	return status;
 }
 
diff --git a/source/lib/sharesec.c b/source/lib/sharesec.c
index e2320b2..4b1ec55 100644
--- a/source/lib/sharesec.c
+++ b/source/lib/sharesec.c
@@ -37,7 +37,7 @@ static const struct generic_mapping file_generic_mapping = {
 };
 
 
-bool share_info_db_init(void)
+static bool share_info_db_init(void)
 {
 	const char *vstring = "INFO/version";
 	int32 vers_id;
diff --git a/source/lib/util_str.c b/source/lib/util_str.c
index b862299..f26c8b8 100644
--- a/source/lib/util_str.c
+++ b/source/lib/util_str.c
@@ -506,21 +506,6 @@ int strwicmp(const char *psz1, const char *psz2)
 	return (*psz1 - *psz2);
 }
 
-
-/**
- Convert a string to upper case, but don't modify it.
-**/
-
-char *strupper_static(const char *s)
-{
-	static char *str = NULL;
-
-	SAFE_FREE(str);
-	str = SMB_STRDUP(s);
-	strupper_m(str);
-	return str;
-}
-
 /**
  Convert a string to "normal" form.
 **/
@@ -1147,7 +1132,7 @@ bool in_list(const char *s, const char *list, bool casesensitive)
 }
 
 /* this is used to prevent lots of mallocs of size 1 */
-static const char *null_string = "";
+static const char null_string[] = "";
 
 /**
  Set a string value, allocing the space for the string
@@ -1561,13 +1546,17 @@ static void split_at_last_component(char *path, char *front, char sep,
  Write an octal as a string.
 **/
 
-const char *octal_string(int i)
+char *octal_string(int i)
 {
-	static char ret[64];
-	if (i == -1)
-		return "-1";
-	slprintf(ret, sizeof(ret)-1, "0%o", i);
-	return ret;
+	char *result;
+	if (i == -1) {
+		result = talloc_strdup(talloc_tos(), "-1");
+	}
+	else {
+		result = talloc_asprintf(talloc_tos(), "0%o", i);
+	}
+	SMB_ASSERT(result != NULL);
+	return result;
 }
 
 
@@ -2552,7 +2541,7 @@ void rfc1738_unescape(char *buf)
 	}
 }
 
-static const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
 /**
  * Decode a base64 string into a DATA_BLOB - simple and slow algorithm
@@ -2861,6 +2850,44 @@ void sprintf_append(TALLOC_CTX *mem_ctx, char **string, ssize_t *len,
 }
 
 /*
+ * asprintf into a string and strupper_m it after that.
+ */
+
+int asprintf_strupper_m(char **strp, const char *fmt, ...)
+{
+	va_list ap;
+	char *result;
+	int ret;
+
+	va_start(ap, fmt);
+	ret = vasprintf(&result, fmt, ap);
+	va_end(ap);
+
+	if (ret == -1)
+		return -1;
+
+	strupper_m(result);
+	*strp = result;
+	return ret;
+}
+
+char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...)
+{
+	va_list ap;
+	char *ret;
+
+	va_start(ap, fmt);
+	ret = talloc_vasprintf(t, fmt, ap);
+	va_end(ap);
+
+	if (ret == NULL) {
+		return NULL;
+	}
+	strupper_m(ret);
+	return ret;
+}
+
+/*
    Returns the substring from src between the first occurrence of
    the char "front" and the first occurence of the char "back".
    Mallocs the return string which must be freed.  Not for use
diff --git a/source/libads/dns.c b/source/libads/dns.c
index cdc4b44..3239892 100644
--- a/source/libads/dns.c
+++ b/source/libads/dns.c
@@ -709,7 +709,7 @@ static char *sitename_key(const char *realm)
 {
 	char *keystr;
 
-	if (asprintf(&keystr, SITENAME_KEY, strupper_static(realm)) == -1) {
+	if (asprintf_strupper_m(&keystr, SITENAME_KEY, realm) == -1) {
 		return NULL;
 	}
 
diff --git a/source/libgpo/gpo_util.c b/source/libgpo/gpo_util.c
index 126b44c..cd532da 100644
--- a/source/libgpo/gpo_util.c
+++ b/source/libgpo/gpo_util.c
@@ -693,8 +693,8 @@ NTSTATUS gp_find_file(TALLOC_CTX *mem_ctx,
 		return NT_STATUS_OK;
 	}
 
-	tmp = talloc_asprintf(mem_ctx, "%s/%s/%s", filename,
-			      strupper_static(path), suffix);
+	tmp = talloc_asprintf_strupper_m(mem_ctx, "%s/%s/%s", filename, path,
+					 suffix);
 	NT_STATUS_HAVE_NO_MEMORY(tmp);
 
 	if (sys_stat(tmp, &sbuf) == 0) {
diff --git a/source/libsmb/credentials.c b/source/libsmb/credentials.c
index 973bb6a..1256a62 100644
--- a/source/libsmb/credentials.c
+++ b/source/libsmb/credentials.c
@@ -26,11 +26,13 @@
 
 char *credstr(const unsigned char *cred)
 {
-	static fstring buf;
-	slprintf(buf, sizeof(buf) - 1, "%02X%02X%02X%02X%02X%02X%02X%02X",
-		cred[0], cred[1], cred[2], cred[3], 
-		cred[4], cred[5], cred[6], cred[7]);
-	return buf;
+	char *result;
+	result = talloc_asprintf(talloc_tos(),
+				 "%02X%02X%02X%02X%02X%02X%02X%02X",
+				 cred[0], cred[1], cred[2], cred[3],
+				 cred[4], cred[5], cred[6], cred[7]);
+	SMB_ASSERT(result != NULL);
+	return result;
 }
 
 /****************************************************************************
diff --git a/source/libsmb/dsgetdcname.c b/source/libsmb/dsgetdcname.c
index b0870e2..f8089cb 100644
--- a/source/libsmb/dsgetdcname.c
+++ b/source/libsmb/dsgetdcname.c
@@ -265,8 +265,7 @@ static char *DsGetDcName_cache_key(TALLOC_CTX *mem_ctx, const char *domain)
 		return NULL;
 	}
 
-	return talloc_asprintf(mem_ctx, DSGETDCNAME_FMT,
-			       strupper_static(domain));
+	return talloc_asprintf_strupper_m(mem_ctx, DSGETDCNAME_FMT, domain);
 }
 
 /****************************************************************
diff --git a/source/libsmb/namecache.c b/source/libsmb/namecache.c
index 6a675d2..ba706e5 100644
--- a/source/libsmb/namecache.c
+++ b/source/libsmb/namecache.c
@@ -98,7 +98,7 @@ static char* namecache_key(const char *name,
 				int name_type)
 {
 	char *keystr;
-	asprintf(&keystr, NBTKEY_FMT, strupper_static(name), name_type);
+	asprintf_strupper_m(&keystr, NBTKEY_FMT, name, name_type);
 
 	return keystr;
 }
@@ -318,8 +318,8 @@ static char *namecache_status_record_key(const char *name,
 	char *keystr;
 
 	print_sockaddr(addr, sizeof(addr), keyip);
-	asprintf(&keystr, "NBT/%s#%02X.%02X.%s",
-			strupper_static(name), name_type1, name_type2, addr);
+	asprintf_strupper_m(&keystr, "NBT/%s#%02X.%02X.%s", name,
+			    name_type1, name_type2, addr);
 	return keystr;
 }
 
diff --git a/source/libsmb/namequery.c b/source/libsmb/namequery.c
index 71d7096..04db332 100644
--- a/source/libsmb/namequery.c
+++ b/source/libsmb/namequery.c
@@ -39,7 +39,7 @@ static char *saf_key(const char *domain)
 {
 	char *keystr;
 
-	asprintf( &keystr, SAFKEY_FMT, strupper_static(domain) );
+	asprintf_strupper_m(&keystr, SAFKEY_FMT, domain);
 
 	return keystr;
 }
diff --git a/source/libsmb/nmblib.c b/source/libsmb/nmblib.c
index 7e152ab..2ff925e 100644
--- a/source/libsmb/nmblib.c
+++ b/source/libsmb/nmblib.c
@@ -347,20 +347,19 @@ static int put_nmb_name(char *buf,int offset,struct nmb_name *name)
 
 char *nmb_namestr(const struct nmb_name *n)
 {
-	static int i=0;
-	static fstring ret[4];
 	fstring name;
-	char *p = ret[i];
+	char *result;
 
 	pull_ascii_fstring(name, n->name);
 	if (!n->scope[0])
-		slprintf(p,sizeof(fstring)-1, "%s<%02x>",name,n->name_type);
+		result = talloc_asprintf(talloc_tos(), "%s<%02x>", name,
+					 n->name_type);
 	else
-		slprintf(p,sizeof(fstring)-1, "%s<%02x>.%s",
-				name,n->name_type,n->scope);
+		result = talloc_asprintf(talloc_tos(), "%s<%02x>.%s", name,
+					 n->name_type, n->scope);
 
-	i = (i+1)%4;
-	return(p);
+	SMB_ASSERT(result != NULL);
+	return result;
 }
 
 /*******************************************************************
@@ -1239,40 +1238,6 @@ void sort_query_replies(char *data, int n, struct in_addr ip)
 	qsort(data, n, 6, QSORT_CAST name_query_comp);
 }
 
-/*******************************************************************
- Convert, possibly using a stupid microsoft-ism which has destroyed
- the transport independence of netbios (for CIFS vendors that usually
- use the Win95-type methods, not for NT to NT communication, which uses
- DCE/RPC and therefore full-length unicode strings...) a dns name into
- a netbios name.
-
- The netbios name (NOT necessarily null-terminated) is truncated to 15
- characters.
-
- ******************************************************************/
-
-char *dns_to_netbios_name(const char *dns_name)
-{
-	static nstring netbios_name;
-	int i;
-	StrnCpy(netbios_name, dns_name, MAX_NETBIOSNAME_LEN-1);
-	netbios_name[15] = 0;
-
-	/* ok.  this is because of a stupid microsoft-ism.  if the called host
-	   name contains a '.', microsoft clients expect you to truncate the
-	   netbios name up to and including the '.'  this even applies, by
-	   mistake, to workgroup (domain) names, which is _really_ daft.
-	 */
-	for (i = 0; i < 15; i++) {
-		if (netbios_name[i] == '.') {
-			netbios_name[i] = 0;
-			break;
-		}
-	}
-
-	return netbios_name;
-}
-
 /****************************************************************************
  Interpret the weird netbios "name" into a unix fstring. Return the name type.
 ****************************************************************************/
diff --git a/source/libsmb/trustdom_cache.c b/source/libsmb/trustdom_cache.c
index f350cd0..be73381 100644
--- a/source/libsmb/trustdom_cache.c
+++ b/source/libsmb/trustdom_cache.c
@@ -90,7 +90,7 @@ bool trustdom_cache_shutdown(void)
 static char* trustdom_cache_key(const char* name)
 {
 	char* keystr = NULL;
-	asprintf(&keystr, TDOMKEY_FMT, strupper_static(name));
+	asprintf_strupper_m(&keystr, TDOMKEY_FMT, name);
 	
 	return keystr;
 }
diff --git a/source/libsmb/unexpected.c b/source/libsmb/unexpected.c
index f5837f3..92a609c 100644
--- a/source/libsmb/unexpected.c
+++ b/source/libsmb/unexpected.c
@@ -112,18 +112,22 @@ void clear_unexpected(time_t t)
 	tdb_traverse(tdbd, traverse_fn, NULL);
 }
 
-
-static struct packet_struct *matched_packet;
-static int match_id;
-static enum packet_type match_type;
-static const char *match_name;
+struct receive_unexpected_state {
+	struct packet_struct *matched_packet;
+	int match_id;
+	enum packet_type match_type;
+	const char *match_name;
+};
 
 /****************************************************************************
  tdb traversal fn to find a matching 137 packet.
 **************************************************************************/
 
-static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
+static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf,
+			  void *private_data)
 {
+	struct receive_unexpected_state *state =
+		(struct receive_unexpected_state *)private_data;
 	struct unexpected_key key;
 	struct in_addr ip;
 	uint32_t enc_ip;
@@ -132,7 +136,7 @@ static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void
 
 	memcpy(&key, kbuf.dptr, sizeof(key));
 
-	if (key.packet_type != match_type) return 0;
+	if (key.packet_type != state->match_type) return 0;
 
 	if (dbuf.dsize < 6) {
 		return 0;
@@ -145,15 +149,15 @@ static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void
 
 	p = parse_packet((char *)&dbuf.dptr[6],
 			dbuf.dsize-6,
-			match_type,
+			state->match_type,
 			ip,
 			port);
 
-	if ((match_type == NMB_PACKET &&
-	     p->packet.nmb.header.name_trn_id == match_id) ||
-	    (match_type == DGRAM_PACKET &&
-	     match_mailslot_name(p, match_name))) {
-		matched_packet = p;
+	if ((state->match_type == NMB_PACKET &&
+	     p->packet.nmb.header.name_trn_id == state->match_id) ||
+	    (state->match_type == DGRAM_PACKET &&
+	     match_mailslot_name(p, state->match_name))) {
+		state->matched_packet = p;
 		return -1;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list