[SCM] Samba Shared Repository - branch master updated

Stefan Metzmacher metze at samba.org
Fri Nov 12 04:23:01 MST 2010


The branch, master has been updated
       via  dedd064 tdb: set tdb->name early, as it's needed for tdb_name()
      from  1ec8d55 s4-kdc: added proxying of kdc requests for RODCs

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


- Log -----------------------------------------------------------------
commit dedd064aa825edd57f992b12218a184398db9586
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Nov 11 09:36:25 2010 +0100

    tdb: set tdb->name early, as it's needed for tdb_name()
    
    tdb_name() might be used within the given log function,
    which might be called from within tdb_open_ex().
    
    metze
    
    Autobuild-User: Stefan Metzmacher <metze at samba.org>
    Autobuild-Date: Fri Nov 12 11:22:21 UTC 2010 on sn-devel-104

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

Summary of changes:
 lib/tdb/common/open.c |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c
index f13df2c..ce8e9f5 100644
--- a/lib/tdb/common/open.c
+++ b/lib/tdb/common/open.c
@@ -197,6 +197,32 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 		tdb->log.log_private = NULL;
 	}
 
+	if (name == NULL && (tdb_flags & TDB_INTERNAL)) {
+		name = "__TDB_INTERNAL__";
+	}
+
+	if (name == NULL) {
+		tdb->name = "__NULL__";
+		TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: called with name == NULL\n"));
+		tdb->name = NULL;
+		errno = EINVAL;
+		goto fail;
+	}
+
+	/* now make a copy of the name, as the caller memory might went away */
+	if (!(tdb->name = (char *)strdup(name))) {
+		/*
+		 * set the name as the given string, so that tdb_name() will
+		 * work in case of an error.
+		 */
+		tdb->name = name;
+		TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: can't strdup(%s)\n",
+			 name));
+		tdb->name = NULL;
+		errno = ENOMEM;
+		goto fail;
+	}
+
 	if (hash_fn) {
 		tdb->hash_fn = hash_fn;
 		hash_alg = "the user defined";
@@ -359,11 +385,6 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 		goto fail;
 	}
 
-	if (!(tdb->name = (char *)strdup(name))) {
-		errno = ENOMEM;
-		goto fail;
-	}
-
 	tdb->map_size = st.st_size;
 	tdb->device = st.st_dev;
 	tdb->inode = st.st_ino;
@@ -436,11 +457,11 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 		else
 			tdb_munmap(tdb);
 	}
-	SAFE_FREE(tdb->name);
 	if (tdb->fd != -1)
 		if (close(tdb->fd) != 0)
 			TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to close tdb->fd on error!\n"));
 	SAFE_FREE(tdb->lockrecs);
+	SAFE_FREE(tdb->name);
 	SAFE_FREE(tdb);
 	errno = save_errno;
 	return NULL;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list