Fix the mess with ldb includes.
[metze/samba/wip.git] / source4 / lib / ldb / ldb_tdb / ldb_tdb_wrap.c
index 7f81949fdc910a107582d61f6cf286574b909e87..6ee8417e25409f865ec23c6524785c7d65e1d400 100644 (file)
@@ -10,7 +10,7 @@
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
-   version 2 of the License, or (at your option) any later version.
+   version 3 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "includes.h"
-#include "ldb/include/includes.h"
-
-#include "ldb/ldb_tdb/ldb_tdb.h"
+#include "ldb_tdb.h"
 
 /*
   the purpose of this code is to work around the braindead posix locking
@@ -58,7 +54,6 @@ static int ltdb_wrap_destructor(struct ltdb_wrap *w)
        return 0;
 }                               
 
-#if (_SAMBA_BUILD_ >= 4)
 static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
 static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
 {
@@ -67,6 +62,10 @@ static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, con
        struct ldb_context *ldb = talloc_get_type(tdb_get_logging_private(tdb), struct ldb_context);
        enum ldb_debug_level ldb_level;
        char *message; 
+
+       if (ldb == NULL)
+               return;
+
        va_start(ap, fmt);
        message = talloc_vasprintf(ldb, fmt, ap);
        va_end(ap);
@@ -91,22 +90,6 @@ static void ltdb_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, con
        ldb_debug(ldb, ldb_level, "ltdb: tdb(%s): %s", name, message);
        talloc_free(message);
 }
-#else
-static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
-static void ltdb_log_fn(struct tdb_context *tdb, int level, const char *fmt, ...)
-{
-       /* until we merge the tdb debug changes into samba3, we don't know 
-          how serious the error is, and we can't go via the ldb loggin code */
-       va_list ap;
-       const char *name = tdb_name(tdb);
-       char *message; 
-       va_start(ap, fmt);
-       message = talloc_vasprintf(NULL, fmt, ap);
-       va_end(ap);
-       DEBUG(3, ("ltdb: tdb(%s): %s", name, message));
-       talloc_free(message);
-}
-#endif
 
 /*
   wrapped connection to a tdb database. The caller should _not_ free
@@ -122,19 +105,17 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
 {
        struct ltdb_wrap *w;
        struct stat st;
-#if (_SAMBA_BUILD_ >= 4)
        struct tdb_logging_context log_ctx;
-       struct tdb_logging_context log_ctx_p = &log_ctx;
+
        log_ctx.log_fn = ltdb_log_fn;
        log_ctx.log_private = ldb;
-#else
-       tdb_log_func log_ctx_p = ltdb_log_fn;
-#endif
 
        if (stat(path, &st) == 0) {
                for (w=tdb_list;w;w=w->next) {
                        if (st.st_dev == w->device && st.st_ino == w->inode) {
-                               talloc_reference(mem_ctx, w);
+                               if (!talloc_reference(mem_ctx, w)) {
+                                       return NULL;
+                               }
                                return w->tdb;
                        }
                }
@@ -145,7 +126,7 @@ struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
-       w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, log_ctx_p, NULL);
+       w->tdb = tdb_open_ex(path, hash_size, tdb_flags, open_flags, mode, &log_ctx, NULL);
        if (w->tdb == NULL) {
                talloc_free(w);
                return NULL;