summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c24
-rw-r--r--source4/lib/ldb/common/ldb_debug.c84
-rw-r--r--source4/lib/ldb/common/ldb_ldif.c10
3 files changed, 110 insertions, 8 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 86d0dd9e9b..b8f61e017a 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -68,6 +68,7 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
*/
int ldb_close(struct ldb_context *ldb)
{
+ ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_close");
return ldb->ops->close(ldb);
}
@@ -83,7 +84,12 @@ int ldb_search(struct ldb_context *ldb,
const char *expression,
char * const *attrs, struct ldb_message ***res)
{
- return ldb->ops->search(ldb, base, scope, expression, attrs, res);
+ int ret;
+ ret = ldb->ops->search(ldb, base, scope, expression, attrs, res);
+
+ ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_search(%s) -> %d records\n",
+ expression, ret);
+ return ret;
}
/*
@@ -102,7 +108,10 @@ int ldb_search_free(struct ldb_context *ldb, struct ldb_message **msgs)
int ldb_add(struct ldb_context *ldb,
const struct ldb_message *message)
{
- return ldb->ops->add_record(ldb, message);
+ int ret;
+ ret = ldb->ops->add_record(ldb, message);
+ ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_add(%s) -> %d\n", message->dn, ret);
+ return ret;
}
/*
@@ -111,7 +120,11 @@ int ldb_add(struct ldb_context *ldb,
int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message)
{
- return ldb->ops->modify_record(ldb, message);
+ int ret;
+ ret = ldb->ops->modify_record(ldb, message);
+ ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_modify(%s) -> %d\n",
+ message->dn, ret);
+ return ret;
}
@@ -120,7 +133,10 @@ int ldb_modify(struct ldb_context *ldb,
*/
int ldb_delete(struct ldb_context *ldb, const char *dn)
{
- return ldb->ops->delete_record(ldb, dn);
+ int ret;
+ ret = ldb->ops->delete_record(ldb, dn);
+ ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_delete(%s) -> %d\n", dn, ret);
+ return ret;
}
/*
diff --git a/source4/lib/ldb/common/ldb_debug.c b/source4/lib/ldb/common/ldb_debug.c
new file mode 100644
index 0000000000..d59f9284b0
--- /dev/null
+++ b/source4/lib/ldb/common/ldb_debug.c
@@ -0,0 +1,84 @@
+/*
+ ldb database library
+
+ Copyright (C) Andrew Tridgell 2004
+
+ ** NOTE! The following LGPL license applies to the ldb
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ 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.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ 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
+*/
+
+/*
+ * Name: ldb
+ *
+ * Component: ldb debug
+ *
+ * Description: functions for printing debug messages
+ *
+ * Author: Andrew Tridgell
+ */
+
+#include "includes.h"
+
+
+/*
+ this allows the user to choose their own debug function
+*/
+int ldb_set_debug(struct ldb_context *ldb,
+ void (*debug)(void *context, enum ldb_debug_level level,
+ const char *fmt, va_list ap),
+ void *context)
+{
+ ldb->debug_ops.debug = debug;
+ ldb->debug_ops.context = context;
+ return 0;
+}
+
+/*
+ debug function for ldb_set_debug_stderr
+*/
+static void ldb_debug_stderr(void *context, enum ldb_debug_level level,
+ const char *fmt, va_list ap)
+{
+ if (level <= LDB_DEBUG_WARNING) {
+ vfprintf(stderr, fmt, ap);
+ }
+}
+
+/*
+ convenience function to setup debug messages on stderr
+ messages of level LDB_DEBUG_WARNING and higher are printed
+*/
+int ldb_set_debug_stderr(struct ldb_context *ldb)
+{
+ return ldb_set_debug(ldb, ldb_debug_stderr, ldb);
+}
+
+/*
+ log a message
+*/
+void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...)
+{
+ va_list ap;
+ if (ldb->debug_ops.debug == NULL) {
+ return;
+ }
+ va_start(ap, fmt);
+ ldb->debug_ops.debug(ldb->debug_ops.context, level, fmt, ap);
+ va_end(ap);
+}
+
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c
index 451276c48d..513e2dd365 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/lib/ldb/common/ldb_ldif.c
@@ -217,7 +217,8 @@ int ldif_write(struct ldb_context *ldb,
}
}
if (!ldb_changetypes[i].name) {
- fprintf(stderr,"Invalid changetype\n");
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "Error: Invalid ldif changetype %d\n",
+ ldif->changetype);
return -1;
}
ret = fprintf_fn(private_data, "changetype: %s\n", ldb_changetypes[i].name);
@@ -493,7 +494,8 @@ struct ldb_ldif *ldif_read(struct ldb_context *ldb,
/* first line must be a dn */
if (ldb_attr_cmp(attr, "dn") != 0) {
- fprintf(stderr, "First line must be a dn not '%s'\n", attr);
+ ldb_debug(ldb, LDB_DEBUG_ERROR, "Error: First line of ldif must be a dn not '%s'\n",
+ attr);
goto failed;
}
@@ -512,8 +514,8 @@ struct ldb_ldif *ldif_read(struct ldb_context *ldb,
}
}
if (!ldb_changetypes[i].name) {
- fprintf(stderr,"Bad changetype '%s'\n",
- (char *)value.data);
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Error: Bad ldif changetype '%s'\n",(char *)value.data);
}
flags = 0;
continue;