From 3daaae467b5c08e75169e197e3d2348496f4416e Mon Sep 17 00:00:00 2001 From: Puran Chand Date: Wed, 29 Nov 2017 13:41:05 +0530 Subject: [PATCH] Added smbc_SetLogCallback which lets third party code to capture libsmbclient logs Signed-off-by: Puran Chand --- source3/include/libsmbclient.h | 9 +++++++++ source3/libsmb/libsmb_setget.c | 7 +++++++ source3/libsmb/wscript | 2 +- source4/torture/libsmbclient/libsmbclient.c | 8 ++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h index b41a2924abd..e2a15096295 100644 --- a/source3/include/libsmbclient.h +++ b/source3/include/libsmbclient.h @@ -129,6 +129,11 @@ struct smbc_dirent char name[1]; }; +/* + * Logging callback function + */ +typedef void (*debug_callback_fn)(void *private_ptr, int level, const char *msg); + /* * Flags for smbc_setxattr() * Specify a bitwise OR of these, or 0 to add or replace as necessary @@ -470,6 +475,10 @@ smbc_getDebug(SMBCCTX *c); void smbc_setDebug(SMBCCTX *c, int debug); +/** set log callback function to capture logs from libsmbclient, this is applied at global level */ + void + smbc_setLogCallback(SMBCCTX *c, void *private_ptr, debug_callback_fn fn); + /** Get the netbios name used for making connections */ char * smbc_getNetbiosName(SMBCCTX *c); diff --git a/source3/libsmb/libsmb_setget.c b/source3/libsmb/libsmb_setget.c index 591cb39c28f..0d18d75559f 100644 --- a/source3/libsmb/libsmb_setget.c +++ b/source3/libsmb/libsmb_setget.c @@ -98,6 +98,13 @@ smbc_setDebug(SMBCCTX *c, int debug) TALLOC_FREE(frame); } +/** set callback function which will be called for logging */ +void +smbc_setLogCallback(SMBCCTX *c, void *private_ptr, debug_callback_fn fn) +{ + debug_set_callback(private_ptr, fn); +} + /** * Get the timeout used for waiting on connections and response data * (in milliseconds) diff --git a/source3/libsmb/wscript b/source3/libsmb/wscript index c6ad6861190..f4c15cab093 100644 --- a/source3/libsmb/wscript +++ b/source3/libsmb/wscript @@ -27,5 +27,5 @@ def build(bld): public_headers='../include/libsmbclient.h', abi_directory='ABI', abi_match='smbc_*', - vnum='0.3.0', + vnum='0.3.1', pc_files='smbclient.pc') diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c index a56a5de55d7..6843c36e1c4 100644 --- a/source4/torture/libsmbclient/libsmbclient.c +++ b/source4/torture/libsmbclient/libsmbclient.c @@ -24,6 +24,12 @@ #include #include "torture/libsmbclient/proto.h" +//Dummy log callback function +static void debug_callback(void *private_ptr, int level, const char *msg) +{ + +} + bool torture_libsmbclient_init_context(struct torture_context *tctx, SMBCCTX **ctx_p) { @@ -33,6 +39,8 @@ bool torture_libsmbclient_init_context(struct torture_context *tctx, torture_assert(tctx, ctx, "failed to get new context"); torture_assert(tctx, smbc_init_context(ctx), "failed to init context"); + smbc_setLogCallback(ctx, NULL, debug_callback); + smbc_setDebug(ctx, DEBUGLEVEL); smbc_setOptionDebugToStderr(ctx, 1);