From da2a9b63f730f25fcccddcdb54d25a57ba481224 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Thu, 28 May 2009 14:41:00 -0400
Subject: [PATCH 1/2] Suppress "rootdse" error messages.

We will trap all LDB debug messages and pipe them into our
internal DEBUG() function. LDB FATAL messages will still be
printed by default, WARNING and TRACE functions will be at debug
level 3 and 9, respectively.
---
 server/confdb/confdb.c |    6 ++++++
 server/db/sysdb.c      |    6 ++++++
 server/util/debug.c    |   24 ++++++++++++++++++++++++
 server/util/util.h     |    5 +++++
 4 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c
index 0c30d47..c133473 100644
--- a/server/confdb/confdb.c
+++ b/server/confdb/confdb.c
@@ -660,6 +660,12 @@ int confdb_init(TALLOC_CTX *mem_ctx,
         talloc_free(cdb);
         return EIO;
     }
+    ret = ldb_set_debug(cdb->ldb, ldb_debug_messages, NULL);
+    if (ret != LDB_SUCCESS) {
+        DEBUG(0,("Could not set up debug fn.\n"));
+        talloc_free(cdb);
+        return EIO;
+    }
 
     *cdb_ctx = cdb;
 
diff --git a/server/db/sysdb.c b/server/db/sysdb.c
index 7a47318..a86a966 100644
--- a/server/db/sysdb.c
+++ b/server/db/sysdb.c
@@ -334,6 +334,12 @@ int sysdb_init(TALLOC_CTX *mem_ctx,
         return EIO;
     }
 
+    ret = ldb_set_debug(ctx->ldb, ldb_debug_messages, NULL);
+    if (ret != LDB_SUCCESS) {
+        talloc_free(ctx);
+        return EIO;
+    }
+
     ret = ldb_connect(ctx->ldb, ctx->ldb_file, 0, NULL);
     if (ret != LDB_SUCCESS) {
         talloc_free(ctx);
diff --git a/server/util/debug.c b/server/util/debug.c
index 1398f80..f7f89f5 100644
--- a/server/util/debug.c
+++ b/server/util/debug.c
@@ -3,6 +3,8 @@
 #include <stdarg.h>
 #include <stdlib.h>
 
+#include "util/util.h"
+
 const char *debug_prg_name = "sssd";
 int debug_level = 0;
 
@@ -19,3 +21,25 @@ void debug_fn(const char *format, ...)
     fprintf(stderr, s);
     free(s);
 }
+
+void ldb_debug_messages(void *context, enum ldb_debug_level level,
+                        const char *fmt, va_list ap)
+{
+    int loglevel = -1;
+    switch(level) {
+    case LDB_DEBUG_FATAL:
+        loglevel = 0;
+        break;
+    case LDB_DEBUG_ERROR:
+        loglevel = 1;
+        break;
+    case LDB_DEBUG_WARNING:
+        loglevel = 3;
+        break;
+    case LDB_DEBUG_TRACE:
+        loglevel = 9;
+        break;
+    }
+
+    DEBUG(loglevel, (fmt, ap));
+}
diff --git a/server/util/util.h b/server/util/util.h
index b3a7c72..d328f3a 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -11,6 +11,7 @@
 #include "config.h"
 #include "talloc.h"
 #include "tevent.h"
+#include "ldb.h"
 
 extern const char *debug_prg_name;
 extern int debug_level;
@@ -54,6 +55,10 @@ struct main_context {
 
 #include "util/dlinklist.h"
 
+/* From debug.c */
+void ldb_debug_messages(void *context, enum ldb_debug_level level,
+                        const char *fmt, va_list ap);
+
 /* from server.c */
 int server_setup(const char *name, int flags,
                  const char *conf_entry,
-- 
1.6.2.2

