[SSSD] [PATCH] enable debugging of krb5_child

Sumit Bose sbose at redhat.com
Mon Oct 12 13:46:46 UTC 2009


Hi,

Although there are lots of DEBUG calls in krb5_child it always runs with
debug_level=0. This patch starts krb5_child with the debugging options
of the backend.

There is a problem with --debug-to-files. krb5_child runs as the user
requesting the ticket so the path to krb5_child.log needs to have
matching permissions. A possible solution would be to create the file
with 666 permissions during the setup of the kerberos backend. Any other
ideas?

bye,
Sumit
-------------- next part --------------
>From b6b92883b333107e743cb6665716a17e6cdee964 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Mon, 12 Oct 2009 15:38:29 +0200
Subject: [PATCH] enable debugging of krb5_child

---
 server/Makefile.am                 |    2 +
 server/providers/krb5/krb5_auth.c  |   56 ++++++++++++++++++++++++++++++++++-
 server/providers/krb5/krb5_child.c |   41 +++++++++++++++++++++++++-
 3 files changed, 95 insertions(+), 4 deletions(-)

diff --git a/server/Makefile.am b/server/Makefile.am
index a65c9fa..99c6867 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -458,9 +458,11 @@ krb5_child_SOURCES = \
     providers/krb5/krb5_child.c
 krb5_child_CFLAGS = \
     $(AM_CFLAGS) \
+    $(POPT_CFLAGS) \
     $(KRB5_CFLAGS)
 krb5_child_LDADD = \
     $(TALLOC_LIBS) \
+    $(POPT_LIBS) \
     $(KRB5_LIBS)
 
 memberof_la_SOURCES = \
diff --git a/server/providers/krb5/krb5_auth.c b/server/providers/krb5/krb5_auth.c
index 582d013..61c529f 100644
--- a/server/providers/krb5/krb5_auth.c
+++ b/server/providers/krb5/krb5_auth.c
@@ -325,6 +325,51 @@ static void wait_for_child_handler(struct tevent_context *ev,
     return;
 }
 
+static errno_t prepare_child_argv(TALLOC_CTX *mem_ctx, char ***_argv)
+{
+    uint_t argc = 2; /* program name and NULL */
+    char ** argv;
+
+    if (debug_level != 0) argc ++;
+    if (debug_to_file != 0) argc++;
+    if (debug_timestamps != 0) argc++;
+
+    argv  = talloc_array(mem_ctx, char *, argc);
+    if (argv == NULL) {
+        DEBUG(1, ("talloc_array failed.\n"));
+        return ENOMEM;
+    }
+
+    if (argc < 2) goto fail;
+    argv[--argc] = NULL;
+
+    if (debug_level != 0) {
+        if (argc < 2) goto fail;
+        argv[--argc] = talloc_asprintf(argv, "--debug-level=%d", debug_level);
+    }
+
+    if (debug_to_file != 0) {
+        if (argc < 2) goto fail;
+        argv[--argc] = talloc_strdup(argv, "--debug-to-files");
+    }
+
+    if (debug_timestamps != 0) {
+        if (argc < 2) goto fail;
+        argv[--argc] = talloc_strdup(argv, "--debug-timestamps");
+    }
+
+    if (argc != 1) goto fail;
+    argv[0] = talloc_strdup(argv, KRB5_CHILD);
+
+    *_argv = argv;
+
+    return EOK;
+
+fail:
+    talloc_free(*argv);
+    return EINVAL;
+}
+
 static errno_t fork_child(struct krb5child_req *kr)
 {
     int pipefd_to_child[2];
@@ -332,6 +377,7 @@ static errno_t fork_child(struct krb5child_req *kr)
     pid_t pid;
     int ret;
     errno_t err;
+    char **argv;
 
     ret = pipe(pipefd_from_child);
     if (ret == -1) {
@@ -381,10 +427,16 @@ static errno_t fork_child(struct krb5child_req *kr)
             return err;
         }
 
-        ret = execl(KRB5_CHILD, KRB5_CHILD, NULL);
+        ret = prepare_child_argv(kr, &argv);
+        if (ret != EOK) {
+            DEBUG(1, ("prepare_child_argv.\n"));
+            return ret;
+        }
+
+        ret = execv(KRB5_CHILD, argv);
         if (ret == -1) {
             err = errno;
-            DEBUG(1, ("execl failed [%d][%s].\n", errno, strerror(errno)));
+            DEBUG(1, ("execv failed [%d][%s].\n", errno, strerror(errno)));
             return err;
         }
     } else if (pid > 0) { /* parent */
diff --git a/server/providers/krb5/krb5_child.c b/server/providers/krb5/krb5_child.c
index 9b1be9c..70fd6b7 100644
--- a/server/providers/krb5/krb5_child.c
+++ b/server/providers/krb5/krb5_child.c
@@ -25,6 +25,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <popt.h>
 
 #include <security/pam_modules.h>
 
@@ -641,7 +642,7 @@ failed:
     return kerr;
 }
 
-int main(int argc, char *argv[])
+int main(int argc, const char *argv[])
 {
     uint8_t *buf = NULL;
     int ret;
@@ -649,10 +650,46 @@ int main(int argc, char *argv[])
     struct pam_data *pd = NULL;
     struct krb5_req *kr = NULL;
     char *ccname;
+    int opt;
+    poptContext pc;
 
-    debug_prg_name = argv[0];
+    struct poptOption long_options[] = {
+        POPT_AUTOHELP
+        SSSD_DEBUG_OPTS
+        POPT_TABLEEND
+    };
+
+
+    pc = poptGetContext(argv[0], argc, argv, long_options, 0);
+    while((opt = poptGetNextOpt(pc)) != -1) {
+        switch(opt) {
+        default:
+        fprintf(stderr, "\nInvalid option %s: %s\n\n",
+                  poptBadOption(pc, 0), poptStrerror(opt));
+            poptPrintUsage(pc, stderr, 0);
+            _exit(-1);
+        }
+    }
+
+    poptFreeContext(pc);
 
     pd = talloc(NULL, struct pam_data);
+    if (pd == NULL) {
+        DEBUG(1, ("malloc failed.\n"));
+        _exit(-1);
+    }
+
+    debug_log_file = "krb5_child";
+    debug_prg_name = talloc_asprintf(pd, "[sssd[krb5_child[%d]]]", getpid());
+
+    if (debug_to_file) {
+        ret = open_debug_file();
+        if (ret != EOK) {
+            DEBUG(0, ("Error setting up logging (%d) [%s]\n",
+                    ret, strerror(ret)));
+        }
+    }
+
 
     buf = talloc_size(pd, sizeof(uint8_t)*IN_BUF_SIZE);
     if (buf == NULL) {
-- 
1.6.2.5



More information about the sssd-devel mailing list