>From 22dd44538559c3d2a7a6119c5bf58b52c526c797 Mon Sep 17 00:00:00 2001
From: Michal Zidek <mzidek@redhat.com>
Date: Mon, 15 Oct 2012 15:24:15 +0200
Subject: [PATCH] Include talloc log in our debug facility

https://fedorahosted.org/sssd/ticket/1495
---
 src/monitor/monitor.c                        |  3 +++
 src/providers/data_provider_be.c             |  2 ++
 src/providers/krb5/krb5_child.c              |  3 +++
 src/providers/ldap/ldap_child.c              |  3 +++
 src/providers/proxy/proxy_child.c            |  3 +++
 src/responder/autofs/autofssrv.c             |  3 +++
 src/responder/nss/nsssrv.c                   |  3 +++
 src/responder/pac/pacsrv.c                   |  3 +++
 src/responder/pam/pamsrv.c                   |  3 +++
 src/responder/ssh/sshsrv.c                   |  3 +++
 src/responder/sudo/sudosrv.c                 |  3 +++
 src/sss_client/ssh/sss_ssh_authorizedkeys.c  |  3 +++
 src/sss_client/ssh/sss_ssh_knownhostsproxy.c |  3 +++
 src/tools/sss_cache.c                        |  3 +++
 src/tools/sss_debuglevel.c                   |  3 +++
 src/tools/sss_groupadd.c                     |  3 +++
 src/tools/sss_groupdel.c                     |  3 +++
 src/tools/sss_groupmod.c                     |  3 +++
 src/tools/sss_groupshow.c                    |  3 +++
 src/tools/sss_seed.c                         |  3 +++
 src/tools/sss_useradd.c                      |  3 +++
 src/tools/sss_userdel.c                      |  3 +++
 src/tools/sss_usermod.c                      |  3 +++
 src/util/debug.c                             | 12 ++++++++++++
 src/util/util.h                              |  1 +
 25 files changed, 81 insertions(+)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index a565399..8d42a2c 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -2499,6 +2499,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     if (opt_version) {
         puts(VERSION""DISTRO_VERSION""PRERELEASE_VERSION);
         return EXIT_SUCCESS;
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 4e4bdab..1c5127d 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -2390,6 +2390,8 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
 
     /* set up things like debug , signals, daemonization, etc... */
     debug_log_file = talloc_asprintf(NULL, "sssd_%s", be_domain);
diff --git a/src/providers/krb5/krb5_child.c b/src/providers/krb5/krb5_child.c
index a92ba57..2b13ee6 100644
--- a/src/providers/krb5/krb5_child.c
+++ b/src/providers/krb5/krb5_child.c
@@ -1919,6 +1919,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     debug_prg_name = talloc_asprintf(NULL, "[sssd[krb5_child[%d]]]", getpid());
     if (!debug_prg_name) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_asprintf failed.\n"));
diff --git a/src/providers/ldap/ldap_child.c b/src/providers/ldap/ldap_child.c
index e0529db..73eb938 100644
--- a/src/providers/ldap/ldap_child.c
+++ b/src/providers/ldap/ldap_child.c
@@ -457,6 +457,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     debug_prg_name = talloc_asprintf(NULL, "[sssd[ldap_child[%d]]]", getpid());
     if (!debug_prg_name) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_asprintf failed.\n"));
diff --git a/src/providers/proxy/proxy_child.c b/src/providers/proxy/proxy_child.c
index 8aa1d76..117982b 100644
--- a/src/providers/proxy/proxy_child.c
+++ b/src/providers/proxy/proxy_child.c
@@ -512,6 +512,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* set up things like debug , signals, daemonization, etc... */
     debug_log_file = talloc_asprintf(NULL, "proxy_child_%s", domain);
     if (!debug_log_file) return 2;
diff --git a/src/responder/autofs/autofssrv.c b/src/responder/autofs/autofssrv.c
index dcb188f..995f9a7 100644
--- a/src/responder/autofs/autofssrv.c
+++ b/src/responder/autofs/autofssrv.c
@@ -200,6 +200,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* set up things like debug, signals, daemonization, etc... */
     debug_log_file = "sssd_autofs";
 
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
index 1156c45..df1d07f 100644
--- a/src/responder/nss/nsssrv.c
+++ b/src/responder/nss/nsssrv.c
@@ -474,6 +474,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* set up things like debug, signals, daemonization, etc... */
     debug_log_file = "sssd_nss";
 
diff --git a/src/responder/pac/pacsrv.c b/src/responder/pac/pacsrv.c
index 348fc6f..5ccf34e 100644
--- a/src/responder/pac/pacsrv.c
+++ b/src/responder/pac/pacsrv.c
@@ -237,6 +237,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* set up things like debug, signals, daemonization, etc... */
     debug_log_file = "sssd_pac";
 
diff --git a/src/responder/pam/pamsrv.c b/src/responder/pam/pamsrv.c
index c94596c..52f0e36 100644
--- a/src/responder/pam/pamsrv.c
+++ b/src/responder/pam/pamsrv.c
@@ -238,6 +238,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* set up things like debug, signals, daemonization, etc... */
     debug_log_file = "sssd_pam";
 
diff --git a/src/responder/ssh/sshsrv.c b/src/responder/ssh/sshsrv.c
index fe01f81..d9276e2 100644
--- a/src/responder/ssh/sshsrv.c
+++ b/src/responder/ssh/sshsrv.c
@@ -188,6 +188,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* set up things like debug, signals, daemonization, etc... */
     debug_log_file = "sssd_ssh";
 
diff --git a/src/responder/sudo/sudosrv.c b/src/responder/sudo/sudosrv.c
index b4f8f88..3afe88d 100644
--- a/src/responder/sudo/sudosrv.c
+++ b/src/responder/sudo/sudosrv.c
@@ -178,6 +178,9 @@ int main(int argc, const char *argv[])
 
     CONVERT_AND_SET_DEBUG_LEVEL(debug_level);
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* set up things like debug, signals, daemonization, etc... */
     debug_log_file = "sssd_sudo";
 
diff --git a/src/sss_client/ssh/sss_ssh_authorizedkeys.c b/src/sss_client/ssh/sss_ssh_authorizedkeys.c
index 902b4a0..1bcede9 100644
--- a/src/sss_client/ssh/sss_ssh_authorizedkeys.c
+++ b/src/sss_client/ssh/sss_ssh_authorizedkeys.c
@@ -51,6 +51,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE,
diff --git a/src/sss_client/ssh/sss_ssh_knownhostsproxy.c b/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
index 76356bd..4ec759f 100644
--- a/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
+++ b/src/sss_client/ssh/sss_ssh_knownhostsproxy.c
@@ -207,6 +207,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE,
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
index 73d9965..1d7dbee 100644
--- a/src/tools/sss_cache.c
+++ b/src/tools/sss_cache.c
@@ -102,6 +102,9 @@ int main(int argc, const char *argv[])
     bool skipped;
     FILE *clear_mc_flag;
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = init_context(argc, argv, &tctx);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE,
diff --git a/src/tools/sss_debuglevel.c b/src/tools/sss_debuglevel.c
index 74a63eb..ac4a955 100644
--- a/src/tools/sss_debuglevel.c
+++ b/src/tools/sss_debuglevel.c
@@ -75,6 +75,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* parse parameters */
     pc = poptGetContext(argv[0], argc, argv, long_options, 0);
     poptSetOtherOptionHelp(pc, "DEBUG_LEVEL_TO_SET");
diff --git a/src/tools/sss_groupadd.c b/src/tools/sss_groupadd.c
index 2a01f39..e7d4b53 100644
--- a/src/tools/sss_groupadd.c
+++ b/src/tools/sss_groupadd.c
@@ -52,6 +52,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
diff --git a/src/tools/sss_groupdel.c b/src/tools/sss_groupdel.c
index 70030ca..6bcef0e 100644
--- a/src/tools/sss_groupdel.c
+++ b/src/tools/sss_groupdel.c
@@ -46,6 +46,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
diff --git a/src/tools/sss_groupmod.c b/src/tools/sss_groupmod.c
index c210bad..a5e1fb2 100644
--- a/src/tools/sss_groupmod.c
+++ b/src/tools/sss_groupmod.c
@@ -59,6 +59,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
diff --git a/src/tools/sss_groupshow.c b/src/tools/sss_groupshow.c
index 2ba495c..4020e24 100644
--- a/src/tools/sss_groupshow.c
+++ b/src/tools/sss_groupshow.c
@@ -656,6 +656,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
diff --git a/src/tools/sss_seed.c b/src/tools/sss_seed.c
index 18d0b9d..7e12fcd 100644
--- a/src/tools/sss_seed.c
+++ b/src/tools/sss_seed.c
@@ -783,6 +783,9 @@ int main(int argc, const char **argv)
     struct user_ctx *input_uctx = NULL;
     int ret = EOK;
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     /* initialize seed context and parse options */
     ret = seed_init(sctx, argc, argv, &sctx);
     if (ret != EOK) {
diff --git a/src/tools/sss_useradd.c b/src/tools/sss_useradd.c
index 1bf174c..8453976 100644
--- a/src/tools/sss_useradd.c
+++ b/src/tools/sss_useradd.c
@@ -67,6 +67,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
diff --git a/src/tools/sss_userdel.c b/src/tools/sss_userdel.c
index 0d1c63e..5f7ac67 100644
--- a/src/tools/sss_userdel.c
+++ b/src/tools/sss_userdel.c
@@ -142,6 +142,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
diff --git a/src/tools/sss_usermod.c b/src/tools/sss_usermod.c
index a45005c..c268c82 100644
--- a/src/tools/sss_usermod.c
+++ b/src/tools/sss_usermod.c
@@ -68,6 +68,9 @@ int main(int argc, const char **argv)
 
     debug_prg_name = argv[0];
 
+    /* Turn on talloc log feature */
+    use_talloc_logs();
+
     ret = set_locale();
     if (ret != EOK) {
         DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
diff --git a/src/util/debug.c b/src/util/debug.c
index e57656d..4d52f8d 100644
--- a/src/util/debug.c
+++ b/src/util/debug.c
@@ -256,3 +256,15 @@ int rotate_debug_files(void)
 
     return open_debug_file();
 }
+
+static void talloc_log_fn(const char *message)
+{
+    DEBUG(SSSDBG_FATAL_FAILURE, (message));
+}
+
+/* Call this function to turn on talloc error message logging */
+void use_talloc_logs(void)
+{
+    talloc_set_log_fn(talloc_log_fn);
+}
+
diff --git a/src/util/util.h b/src/util/util.h
index a96f519..82841f9 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -341,6 +341,7 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level,
 int open_debug_file_ex(const char *filename, FILE **filep);
 int open_debug_file(void);
 int rotate_debug_files(void);
+void use_talloc_logs(void);
 
 /* From sss_log.c */
 #define SSS_LOG_EMERG   0   /* system is unusable */
-- 
1.7.11.2

