[PATCH] Cleanup patches

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Apr 28 07:32:46 MDT 2015


Hi!

Attached find a few cleanup patches.

Review&push appreciated!

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From fbb15802840465622b386a3a78564e4b52d055ac Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 28 Apr 2015 08:38:43 +0200
Subject: [PATCH 1/3] lib: Fix a typo

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/lib/gencache.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 19fafe1..90eafaa 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -273,7 +273,7 @@ static int last_stabilize_parser(TDB_DATA key, TDB_DATA data,
  * @param blob DATA_BLOB value being cached
  * @param timeout time when the value is expired
  *
- * @retval true when entry is successfuly stored
+ * @retval true when entry is successfully stored
  * @retval false on failure
  **/
 
-- 
1.7.9.5


From a76d79222518d239aa24d62ca205821ea02c14a6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 2 Jan 2015 11:02:45 +0100
Subject: [PATCH 2/3] lib: Simplify dom_sid_parse_length

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 libcli/security/dom_sid.c |   11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/libcli/security/dom_sid.c b/libcli/security/dom_sid.c
index 836979e..2910434 100644
--- a/libcli/security/dom_sid.c
+++ b/libcli/security/dom_sid.c
@@ -243,14 +243,9 @@ struct dom_sid *dom_sid_parse_talloc(TALLOC_CTX *mem_ctx, const char *sidstr)
 */
 struct dom_sid *dom_sid_parse_length(TALLOC_CTX *mem_ctx, const DATA_BLOB *sid)
 {
-	struct dom_sid *ret;
-	char *p = talloc_strndup(mem_ctx, (char *)sid->data, sid->length);
-	if (!p) {
-		return NULL;
-	}
-	ret = dom_sid_parse_talloc(mem_ctx, p);
-	talloc_free(p);
-	return ret;
+	char p[sid->length+1];
+	memcpy(p, sid->data, sizeof(p));
+	return dom_sid_parse_talloc(mem_ctx, p);
 }
 
 /*
-- 
1.7.9.5


From c4d2ddff2741b6968a29ef9d9898db1c33c5a855 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 28 Apr 2015 11:30:58 +0000
Subject: [PATCH 3/3] lib: Remove server_id_str()

Call server_id_str_buf instead

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/util/samba_util.h                     |    1 -
 lib/util/server_id.c                      |   19 +-----------
 source3/locking/brlock.c                  |    7 +++--
 source3/locking/share_mode_lock.c         |    3 +-
 source3/smbd/oplock.c                     |    6 ++--
 source3/smbd/scavenger.c                  |   47 ++++++++++++++++++-----------
 source3/smbd/sesssetup.c                  |    3 +-
 source3/smbd/smbXsrv_open.c               |    7 +++--
 source3/smbd/smbXsrv_session.c            |    4 ++-
 source3/smbd/smbXsrv_tcon.c               |    3 +-
 source3/utils/dbwrap_tool.c               |    5 ++-
 source3/utils/net_g_lock.c                |    7 ++---
 source3/utils/net_serverid.c              |   30 ++++++++++--------
 source3/utils/status.c                    |    7 ++---
 source4/dsdb/samdb/ldb_modules/ridalloc.c |    4 ++-
 source4/smb_server/smb/receive.c          |   10 +++---
 source4/smbd/service_stream.c             |    3 +-
 17 files changed, 87 insertions(+), 79 deletions(-)

diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index 6941308..176930b 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -876,7 +876,6 @@ char *server_id_str_buf(struct server_id id, struct server_id_buf *dst);
 bool server_id_same_process(const struct server_id *p1,
 			    const struct server_id *p2);
 bool server_id_equal(const struct server_id *p1, const struct server_id *p2);
-char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id);
 struct server_id server_id_from_string(uint32_t local_vnn,
 				       const char *pid_string);
 
diff --git a/lib/util/server_id.c b/lib/util/server_id.c
index 308ee2a..60b5235 100644
--- a/lib/util/server_id.c
+++ b/lib/util/server_id.c
@@ -65,23 +65,6 @@ char *server_id_str_buf(struct server_id id, struct server_id_buf *dst)
 	return dst->buf;
 }
 
-char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id)
-{
-	struct server_id_buf tmp;
-	char *result;
-
-	result = talloc_strdup(mem_ctx, server_id_str_buf(*id, &tmp));
-	if (result == NULL) {
-		return NULL;
-	}
-
-	/*
-	 * beautify the talloc_report output
-	 */
-	talloc_set_name_const(result, result);
-	return result;
-}
-
 struct server_id server_id_from_string(uint32_t local_vnn,
 				       const char *pid_string)
 {
@@ -93,7 +76,7 @@ struct server_id server_id_from_string(uint32_t local_vnn,
 
 	/*
 	 * We accept various forms with 1, 2 or 3 component forms
-	 * because the server_id_str() can print different forms, and
+	 * because the server_id_str_buf() can print different forms, and
 	 * we want backwards compatibility for scripts that may call
 	 * smbclient.
 	 */
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 5dee91c..0738464 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -58,11 +58,13 @@ struct byte_range_lock {
 
 static void print_lock_struct(unsigned int i, const struct lock_struct *pls)
 {
+	struct server_id_buf tmp;
+
 	DEBUG(10,("[%u]: smblctx = %llu, tid = %u, pid = %s, ",
 			i,
 			(unsigned long long)pls->context.smblctx,
 			(unsigned int)pls->context.tid,
-			server_id_str(talloc_tos(), &pls->context.pid) ));
+			server_id_str_buf(pls->context.pid, &tmp) ));
 
 	DEBUG(10, ("start = %ju, size = %ju, fnum = %ju, %s %s\n",
 		   (uintmax_t)pls->start,
@@ -2243,10 +2245,11 @@ bool brl_cleanup_disconnected(struct file_id fid, uint64_t open_persistent_id)
 		struct lock_context *ctx = &lock[n].context;
 
 		if (!server_id_is_disconnected(&ctx->pid)) {
+			struct server_id_buf tmp;
 			DEBUG(5, ("brl_cleanup_disconnected: byte range lock "
 				  "%s used by server %s, do not cleanup\n",
 				  file_id_string(frame, &fid),
-				  server_id_str(frame, &ctx->pid)));
+				  server_id_str_buf(ctx->pid, &tmp)));
 			goto done;
 		}
 
diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index 79efb70..5eedcc5 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -792,6 +792,7 @@ bool share_mode_cleanup_disconnected(struct file_id fid,
 		struct share_mode_entry *entry = &data->share_modes[n];
 
 		if (!server_id_is_disconnected(&entry->pid)) {
+			struct server_id_buf tmp;
 			DEBUG(5, ("share_mode_cleanup_disconnected: "
 				  "file (file-id='%s', servicepath='%s', "
 				  "base_name='%s%s%s') "
@@ -803,7 +804,7 @@ bool share_mode_cleanup_disconnected(struct file_id fid,
 				  ? "" : "', stream_name='",
 				  (data->stream_name == NULL)
 				  ? "" : data->stream_name,
-				  server_id_str(frame, &entry->pid)));
+				  server_id_str_buf(entry->pid, &tmp)));
 			goto done;
 		}
 		if (open_persistent_id != entry->share_file_id) {
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 8f318f5..e29b5b1 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -776,6 +776,7 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
 	uint16_t break_from;
 	uint16_t break_to;
 	bool break_needed = true;
+	struct server_id_buf tmp;
 
 	if (data->data == NULL) {
 		DEBUG(0, ("Got NULL buffer\n"));
@@ -792,7 +793,7 @@ static void process_oplock_break_message(struct messaging_context *msg_ctx,
 	break_to = msg.op_type;
 
 	DEBUG(10, ("Got oplock break to %u message from pid %s: %s/%llu\n",
-		   (unsigned)break_to, server_id_str(talloc_tos(), &src),
+		   (unsigned)break_to, server_id_str_buf(src, &tmp),
 		   file_id_string_tos(&msg.id),
 		   (unsigned long long)msg.share_file_id));
 
@@ -970,6 +971,7 @@ static void process_kernel_oplock_break(struct messaging_context *msg_ctx,
 	struct smbd_server_connection *sconn =
 		talloc_get_type_abort(private_data,
 		struct smbd_server_connection);
+	struct server_id_buf tmp;
 
 	if (data->data == NULL) {
 		DEBUG(0, ("Got NULL buffer\n"));
@@ -986,7 +988,7 @@ static void process_kernel_oplock_break(struct messaging_context *msg_ctx,
 	file_id = (unsigned long)IVAL(data->data, 24);
 
 	DEBUG(10, ("Got kernel oplock break message from pid %s: %s/%u\n",
-		   server_id_str(talloc_tos(), &src), file_id_string_tos(&id),
+		   server_id_str_buf(src, &tmp), file_id_string_tos(&id),
 		   (unsigned int)file_id));
 
 	fsp = initial_break_processing(sconn, id, file_id);
diff --git a/source3/smbd/scavenger.c b/source3/smbd/scavenger.c
index 19f9b43..3691ba0 100644
--- a/source3/smbd/scavenger.c
+++ b/source3/smbd/scavenger.c
@@ -49,9 +49,11 @@ struct scavenger_message {
 
 static int smbd_scavenger_main(struct smbd_scavenger_state *state)
 {
+	struct server_id_buf tmp1, tmp2;
+
 	DEBUG(10, ("scavenger: %s started, parent: %s\n",
-		   server_id_str(talloc_tos(), state->scavenger_id),
-		   server_id_str(talloc_tos(), &state->parent_id)));
+		   server_id_str_buf(*state->scavenger_id, &tmp1),
+		   server_id_str_buf(state->parent_id, &tmp2)));
 
 	while (true) {
 		TALLOC_CTX *frame = talloc_stackframe();
@@ -66,7 +68,7 @@ static int smbd_scavenger_main(struct smbd_scavenger_state *state)
 		}
 
 		DEBUG(10, ("scavenger: %s event loop iteration\n",
-			   server_id_str(talloc_tos(), state->scavenger_id)));
+			   server_id_str_buf(*state->scavenger_id, &tmp1)));
 		TALLOC_FREE(frame);
 	}
 
@@ -78,9 +80,10 @@ static void smbd_scavenger_done(struct tevent_context *event_ctx, struct tevent_
 {
 	struct smbd_scavenger_state *state = talloc_get_type_abort(
 		private_data, struct smbd_scavenger_state);
+	struct server_id_buf tmp;
 
 	DEBUG(2, ("scavenger: %s died\n",
-		  server_id_str(talloc_tos(), state->scavenger_id)));
+		  server_id_str_buf(*state->scavenger_id, &tmp)));
 
 	TALLOC_FREE(state->scavenger_id);
 }
@@ -91,10 +94,11 @@ static void smbd_scavenger_parent_dead(struct tevent_context *event_ctx,
 {
 	struct smbd_scavenger_state *state = talloc_get_type_abort(
 		private_data, struct smbd_scavenger_state);
+	struct server_id_buf tmp1, tmp2;
 
 	DEBUG(2, ("scavenger: %s parent %s died\n",
-		  server_id_str(talloc_tos(), state->scavenger_id),
-		  server_id_str(talloc_tos(), &state->parent_id)));
+		  server_id_str_buf(*state->scavenger_id, &tmp1),
+		  server_id_str_buf(state->parent_id, &tmp2)));
 
 	exit_server("smbd_scavenger_parent_dead");
 }
@@ -143,6 +147,7 @@ static bool scavenger_say_hello(int fd, struct server_id self)
 	const uint8_t *msg = (const uint8_t *)&self;
 	size_t remaining = sizeof(self);
 	size_t ofs = 0;
+	struct server_id_buf tmp;
 
 	while (remaining > 0) {
 		ssize_t ret;
@@ -157,7 +162,7 @@ static bool scavenger_say_hello(int fd, struct server_id self)
 	}
 
 	DEBUG(4, ("scavenger_say_hello: self[%s]\n",
-		  server_id_str(talloc_tos(), &self)));
+		  server_id_str_buf(self, &tmp)));
 	return true;
 }
 
@@ -166,6 +171,7 @@ static bool scavenger_wait_hello(int fd, struct server_id *child)
 	uint8_t *msg = (uint8_t *)child;
 	size_t remaining = sizeof(*child);
 	size_t ofs = 0;
+	struct server_id_buf tmp;
 
 	while (remaining > 0) {
 		ssize_t ret;
@@ -180,7 +186,7 @@ static bool scavenger_wait_hello(int fd, struct server_id *child)
 	}
 
 	DEBUG(4, ("scavenger_say_hello: child[%s]\n",
-		  server_id_str(talloc_tos(), child)));
+		  server_id_str_buf(*child, &tmp)));
 	return true;
 }
 
@@ -196,16 +202,18 @@ static bool smbd_scavenger_start(struct smbd_scavenger_state *state)
 	SMB_ASSERT(server_id_equal(&state->parent_id, &self));
 
 	if (smbd_scavenger_running(state)) {
+		struct server_id_buf tmp;
 		DEBUG(10, ("scavenger %s already running\n",
-			   server_id_str(talloc_tos(),
-					 state->scavenger_id)));
+			   server_id_str_buf(*state->scavenger_id,
+					     &tmp)));
 		return true;
 	}
 
 	if (state->scavenger_id != NULL) {
+		struct server_id_buf tmp;
 		DEBUG(10, ("scavenger zombie %s, cleaning up\n",
-			   server_id_str(talloc_tos(),
-					 state->scavenger_id)));
+			   server_id_str_buf(*state->scavenger_id,
+					     &tmp)));
 		TALLOC_FREE(state->scavenger_id);
 	}
 
@@ -328,10 +336,11 @@ static void smbd_scavenger_msg(struct messaging_context *msg_ctx,
 	TALLOC_CTX *frame = talloc_stackframe();
 	struct server_id self = messaging_server_id(msg_ctx);
 	struct scavenger_message *msg = NULL;
+	struct server_id_buf tmp1, tmp2;
 
 	DEBUG(10, ("smbd_scavenger_msg: %s got message from %s\n",
-		   server_id_str(talloc_tos(), &self),
-		   server_id_str(talloc_tos(), &src)));
+		   server_id_str_buf(self, &tmp1),
+		   server_id_str_buf(src, &tmp2)));
 
 	if (server_id_equal(&state->parent_id, &self)) {
 		NTSTATUS status;
@@ -416,6 +425,7 @@ void scavenger_schedule_disconnected(struct files_struct *fsp)
 	uint64_t timeout_usec;
 	struct scavenger_message msg;
 	DATA_BLOB msg_blob;
+	struct server_id_buf tmp;
 
 	if (fsp->op == NULL) {
 		return;
@@ -433,7 +443,7 @@ void scavenger_schedule_disconnected(struct files_struct *fsp)
 
 	DEBUG(10, ("smbd: %s mark file %s as disconnected at %s with timeout "
 		   "at %s in %fs\n",
-		   server_id_str(talloc_tos(), &self),
+		   server_id_str_buf(self, &tmp),
 		   file_id_string_tos(&fsp->file_id),
 		   timeval_string(talloc_tos(), &disconnect_time, true),
 		   timeval_string(talloc_tos(), &until, true),
@@ -451,11 +461,12 @@ void scavenger_schedule_disconnected(struct files_struct *fsp)
 				MSG_SMB_SCAVENGER,
 				&msg_blob);
 	if (!NT_STATUS_IS_OK(status)) {
+		struct server_id_buf tmp1, tmp2;
 		DEBUG(2, ("Failed to send message to parent smbd %s "
 			  "from %s: %s\n",
-			  server_id_str(talloc_tos(),
-					&smbd_scavenger_state->parent_id),
-			  server_id_str(talloc_tos(), &self),
+			  server_id_str_buf(smbd_scavenger_state->parent_id,
+					    &tmp1),
+			  server_id_str_buf(self, &tmp2),
 			  nt_errstr(status)));
 	}
 }
diff --git a/source3/smbd/sesssetup.c b/source3/smbd/sesssetup.c
index b261704..f41f8e3 100644
--- a/source3/smbd/sesssetup.c
+++ b/source3/smbd/sesssetup.c
@@ -511,9 +511,10 @@ static int shutdown_other_smbds(struct smbXsrv_session_global0 *session,
 	struct server_id self_pid = messaging_server_id(state->msg_ctx);
 	struct server_id pid = session->channels[0].server_id;
 	const char *addr = session->channels[0].remote_address;
+	struct server_id_buf tmp;
 
 	DEBUG(10, ("shutdown_other_smbds: %s, %s\n",
-		   server_id_str(talloc_tos(), &pid), addr));
+		   server_id_str_buf(pid, &tmp), addr));
 
 	if (!process_exists(pid)) {
 		DEBUG(10, ("process does not exist\n"));
diff --git a/source3/smbd/smbXsrv_open.c b/source3/smbd/smbXsrv_open.c
index 2440ecb..1fe8b1b 100644
--- a/source3/smbd/smbXsrv_open.c
+++ b/source3/smbd/smbXsrv_open.c
@@ -630,10 +630,11 @@ static void smbXsrv_open_global_verify_record(struct db_record *db_rec,
 		exists = serverid_exists(&global->server_id);
 	}
 	if (!exists) {
+		struct server_id_buf idbuf;
 		DEBUG(2,("smbXsrv_open_global_verify_record: "
 			 "key '%s' server_id %s does not exist.\n",
 			 hex_encode_talloc(frame, key.dptr, key.dsize),
-			 server_id_str(frame, &global->server_id)));
+			 server_id_str_buf(global->server_id, &idbuf)));
 		if (CHECK_DEBUGLVL(2)) {
 			NDR_PRINT_DEBUG(smbXsrv_open_globalB, &global_blob);
 		}
@@ -1453,9 +1454,11 @@ NTSTATUS smbXsrv_open_cleanup(uint64_t persistent_id)
 			   op->durable_timeout_msec / 1000,
 			   delete_open ? "" : " not"));
 	} else if (!serverid_exists(&op->server_id)) {
+		struct server_id_buf idbuf;
 		DEBUG(10, ("smbXsrv_open_cleanup[global: 0x%08x] "
 			   "server[%s] does not exist\n",
-			   global_id, server_id_str(frame, &op->server_id)));
+			   global_id,
+			   server_id_str_buf(op->server_id, &idbuf)));
 		delete_open = true;
 	}
 
diff --git a/source3/smbd/smbXsrv_session.c b/source3/smbd/smbXsrv_session.c
index c5b7b79..a49e246 100644
--- a/source3/smbd/smbXsrv_session.c
+++ b/source3/smbd/smbXsrv_session.c
@@ -782,10 +782,12 @@ static void smbXsrv_session_global_verify_record(struct db_record *db_rec,
 
 	exists = serverid_exists(&global->channels[0].server_id);
 	if (!exists) {
+		struct server_id_buf idbuf;
 		DEBUG(2,("smbXsrv_session_global_verify_record: "
 			 "key '%s' server_id %s does not exist.\n",
 			 hex_encode_talloc(frame, key.dptr, key.dsize),
-			 server_id_str(frame, &global->channels[0].server_id)));
+			 server_id_str_buf(global->channels[0].server_id,
+					   &idbuf)));
 		if (DEBUGLVL(2)) {
 			NDR_PRINT_DEBUG(smbXsrv_session_globalB, &global_blob);
 		}
diff --git a/source3/smbd/smbXsrv_tcon.c b/source3/smbd/smbXsrv_tcon.c
index 89a25e8..1d2a141 100644
--- a/source3/smbd/smbXsrv_tcon.c
+++ b/source3/smbd/smbXsrv_tcon.c
@@ -604,10 +604,11 @@ static void smbXsrv_tcon_global_verify_record(struct db_record *db_rec,
 
 	exists = serverid_exists(&global->server_id);
 	if (!exists) {
+		struct server_id_buf idbuf;
 		DEBUG(2,("smbXsrv_tcon_global_verify_record: "
 			 "key '%s' server_id %s does not exist.\n",
 			 hex_encode_talloc(frame, key.dptr, key.dsize),
-			 server_id_str(frame, &global->server_id)));
+			 server_id_str_buf(global->server_id, &idbuf)));
 		if (DEBUGLVL(2)) {
 			NDR_PRINT_DEBUG(smbXsrv_tcon_globalB, &global_blob);
 		}
diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index 7492af1..aefc04c 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -353,9 +353,8 @@ static int dbwrap_tool_listwatchers_cb(const uint8_t *db_id, size_t db_id_len,
 	dump_data_file(key.dptr, key.dsize, false, stdout);
 
 	for (i=0; i<num_watchers; i++) {
-		char *str = server_id_str(talloc_tos(), &watchers[i]);
-		printf("%s\n", str);
-		TALLOC_FREE(str);
+		struct server_id_buf idbuf;
+		printf("%s\n", server_id_str_buf(watchers[i], &idbuf));
 	}
 	printf("\n");
 	return 0;
diff --git a/source3/utils/net_g_lock.c b/source3/utils/net_g_lock.c
index 8de5c7c..5ac832a 100644
--- a/source3/utils/net_g_lock.c
+++ b/source3/utils/net_g_lock.c
@@ -111,12 +111,9 @@ done:
 static int net_g_lock_dump_fn(struct server_id pid, enum g_lock_type lock_type,
 			      void *private_data)
 {
-	char *pidstr;
-
-	pidstr = server_id_str(talloc_tos(), &pid);
-	d_printf("%s: %s\n", pidstr,
+	struct server_id_buf idbuf;
+	d_printf("%s: %s\n", server_id_str_buf(pid, &idbuf),
 		 (lock_type & 1) ? "WRITE" : "READ");
-	TALLOC_FREE(pidstr);
 	return 0;
 }
 
diff --git a/source3/utils/net_serverid.c b/source3/utils/net_serverid.c
index cf2c33f..9eb1cf4 100644
--- a/source3/utils/net_serverid.c
+++ b/source3/utils/net_serverid.c
@@ -30,10 +30,10 @@
 static int net_serverid_list_fn(const struct server_id *id,
 				uint32_t msg_flags, void *priv)
 {
-	char *str = server_id_str(talloc_tos(), id);
-	d_printf("%s %llu 0x%x\n", str, (unsigned long long)id->unique_id,
+	struct server_id_buf idbuf;
+	d_printf("%s %llu 0x%x\n", server_id_str_buf(*id, &idbuf),
+		 (unsigned long long)id->unique_id,
 		 (unsigned int)msg_flags);
-	TALLOC_FREE(str);
 	return 0;
 }
 
@@ -55,10 +55,9 @@ static int net_serverid_wipe_fn(struct db_record *rec,
 	}
 	status = dbwrap_record_delete(rec);
 	if (!NT_STATUS_IS_OK(status)) {
-		char *str = server_id_str(talloc_tos(), id);
+		struct server_id_buf idbuf;
 		DEBUG(1, ("Could not delete serverid.tdb record %s: %s\n",
-			  str, nt_errstr(status)));
-		TALLOC_FREE(str);
+			  server_id_str_buf(*id, &idbuf), nt_errstr(status)));
 	}
 	return 0;
 }
@@ -125,34 +124,39 @@ static struct wipedbs_server_data *get_server_data(struct wipedbs_state *state,
 		ret = *(struct wipedbs_server_data**) val.dptr;
 		TALLOC_FREE(val.dptr);
 	} else if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+		struct server_id_buf idbuf;
+
+		server_id_str_buf(*id, &idbuf);
+
 		ret = talloc_zero(state->id2server_data,
 				  struct wipedbs_server_data);
 		if (ret == NULL) {
 			DEBUG(0, ("Failed to allocate server entry for %s\n",
-				  server_id_str(talloc_tos(), id)));
+				  idbuf.buf));
 			goto done;
 		}
 		ret->server_id = *id;
-		ret->server_id_str = server_id_str(ret, id);
+		ret->server_id_str = talloc_strdup(ret, idbuf.buf);
 		ret->exists = true;
 		val = make_tdb_data((const void*)&ret, sizeof(ret));
 		status = dbwrap_store(state->id2server_data,
 				      key, val, TDB_INSERT);
 		if (!NT_STATUS_IS_OK(status)) {
 			DEBUG(0, ("Failed to store server entry for %s: %s\n",
-				  server_id_str(talloc_tos(), id),
-				  nt_errstr(status)));
+				  idbuf.buf, nt_errstr(status)));
 		}
 		goto done;
 	} else {
+		struct server_id_buf idbuf;
 		DEBUG(0, ("Failed to fetch server entry for %s: %s\n",
-			  server_id_str(talloc_tos(), id), nt_errstr(status)));
+			  server_id_str_buf(*id, &idbuf), nt_errstr(status)));
 		goto done;
 	}
 	if (!server_id_equal(id, &ret->server_id)) {
+		struct server_id_buf idbuf1, idbuf2;
 		DEBUG(0, ("uniq id collision for %s and %s\n",
-			  server_id_str(talloc_tos(), id),
-			  server_id_str(talloc_tos(), &ret->server_id)));
+			  server_id_str_buf(*id, &idbuf1),
+			  server_id_str_buf(ret->server_id, &idbuf2)));
 		smb_panic("server_id->unique_id not unique!");
 	}
 done:
diff --git a/source3/utils/status.c b/source3/utils/status.c
index 33ca728..afbba69 100644
--- a/source3/utils/status.c
+++ b/source3/utils/status.c
@@ -340,12 +340,11 @@ static void print_notify_recs(const char *path,
 
 	for (i=0; i<num_entries; i++) {
 		struct notify_db_entry *e = &entries[i];
-		char *str;
+		struct server_id_buf idbuf;
 
-		str = server_id_str(talloc_tos(), &e->server);
-		printf("%s %x %x\n", str, (unsigned)e->filter,
+		printf("%s %x %x\n", server_id_str_buf(e->server, &idbuf),
+		       (unsigned)e->filter,
 		       (unsigned)e->subdir_filter);
-		TALLOC_FREE(str);
 	}
 	printf("\n");
 }
diff --git a/source4/dsdb/samdb/ldb_modules/ridalloc.c b/source4/dsdb/samdb/ldb_modules/ridalloc.c
index 05764ee..4c619b7 100644
--- a/source4/dsdb/samdb/ldb_modules/ridalloc.c
+++ b/source4/dsdb/samdb/ldb_modules/ridalloc.c
@@ -101,9 +101,11 @@ static int ridalloc_poke_rid_manager(struct ldb_module *module)
 
 	/* Only error out if an error happened, not on STATUS_MORE_ENTRIES, ie a delayed message */
 	if (NT_STATUS_IS_ERR(status)) {
+		struct server_id_buf idbuf;
 		ldb_asprintf_errstring(ldb_module_get_ctx(module),
 				"Failed to send MSG_DREPL_ALLOCATE_RID to dreplsrv at %s: %s",
-				server_id_str(tmp_ctx, servers), nt_errstr(status));
+				server_id_str_buf(*servers, &idbuf),
+				nt_errstr(status));
 		talloc_free(tmp_ctx);
 		return LDB_ERR_UNWILLING_TO_PERFORM;
 	}
diff --git a/source4/smb_server/smb/receive.c b/source4/smb_server/smb/receive.c
index 3443834..94bd5ce 100644
--- a/source4/smb_server/smb/receive.c
+++ b/source4/smb_server/smb/receive.c
@@ -471,7 +471,7 @@ static void switch_message(int type, struct smbsrv_request *req)
 	int flags;
 	struct smbsrv_connection *smb_conn = req->smb_conn;
 	NTSTATUS status;
-	char *task_id;
+	struct server_id_buf idbuf;
 
 	type &= 0xff;
 
@@ -495,10 +495,10 @@ static void switch_message(int type, struct smbsrv_request *req)
 		req->session = smbsrv_session_find(req->smb_conn, SVAL(req->in.hdr,HDR_UID), req->request_time);
 	}
 
-	task_id = server_id_str(NULL, &req->smb_conn->connection->server_id);
-	DEBUG(5,("switch message %s (task_id %s)\n",
-		 smb_fn_name(type), task_id));
-	talloc_free(task_id);
+	DEBUG(5, ("switch message %s (task_id %s)\n",
+		  smb_fn_name(type),
+		  server_id_str_buf(req->smb_conn->connection->server_id,
+				    &idbuf)));
 
 	/* this must be called before we do any reply */
 	if (flags & SIGNING_NO_REPLY) {
diff --git a/source4/smbd/service_stream.c b/source4/smbd/service_stream.c
index 11e6deb..9aca501 100644
--- a/source4/smbd/service_stream.c
+++ b/source4/smbd/service_stream.c
@@ -215,6 +215,7 @@ static void stream_new_connection(struct tevent_context *ev,
 	{
 		TALLOC_CTX *tmp_ctx;
 		const char *title;
+		struct server_id_buf idbuf;
 
 		tmp_ctx = talloc_new(srv_conn);
 
@@ -222,7 +223,7 @@ static void stream_new_connection(struct tevent_context *ev,
 					stream_socket->ops->name, 
 					tsocket_address_string(srv_conn->remote_address, tmp_ctx),
 					tsocket_address_string(srv_conn->local_address, tmp_ctx),
-					server_id_str(tmp_ctx, &server_id));
+					server_id_str_buf(server_id, &idbuf));
 		if (title) {
 			stream_connection_set_title(srv_conn, title);
 		}
-- 
1.7.9.5



More information about the samba-technical mailing list