summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/providers/ad/ad_gpo.c23
-rw-r--r--src/providers/krb5/krb5_init_shared.c24
-rw-r--r--src/providers/ldap/sdap_child_helpers.c22
-rw-r--r--src/util/child_common.c29
-rw-r--r--src/util/child_common.h2
5 files changed, 42 insertions, 58 deletions
diff --git a/src/providers/ad/ad_gpo.c b/src/providers/ad/ad_gpo.c
index 80b0d45c2..83edbe4fb 100644
--- a/src/providers/ad/ad_gpo.c
+++ b/src/providers/ad/ad_gpo.c
@@ -1313,29 +1313,10 @@ ad_gpo_access_check(TALLOC_CTX *mem_ctx,
}
#define GPO_CHILD_LOG_FILE "gpo_child"
+
static errno_t gpo_child_init(void)
{
- int ret;
- FILE *debug_filep;
-
- if (debug_to_file != 0 && gpo_child_debug_fd == -1) {
- ret = open_debug_file_ex(GPO_CHILD_LOG_FILE, &debug_filep, false);
- if (ret != EOK) {
- DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n",
- ret, strerror(ret));
- return ret;
- }
-
- gpo_child_debug_fd = fileno(debug_filep);
- if (gpo_child_debug_fd == -1) {
- DEBUG(SSSDBG_FATAL_FAILURE,
- "fileno failed [%d][%s]\n", errno, strerror(errno));
- ret = errno;
- return ret;
- }
- }
-
- return EOK;
+ return child_debug_init(GPO_CHILD_LOG_FILE, &gpo_child_debug_fd);
}
/*
diff --git a/src/providers/krb5/krb5_init_shared.c b/src/providers/krb5/krb5_init_shared.c
index 340eab1f0..3b4bf096e 100644
--- a/src/providers/krb5/krb5_init_shared.c
+++ b/src/providers/krb5/krb5_init_shared.c
@@ -30,7 +30,6 @@ errno_t krb5_child_init(struct krb5_ctx *krb5_auth_ctx,
struct be_ctx *bectx)
{
errno_t ret;
- FILE *debug_filep;
time_t renew_intv = 0;
krb5_deltat renew_interval_delta;
char *renew_interval_str;
@@ -83,23 +82,16 @@ errno_t krb5_child_init(struct krb5_ctx *krb5_auth_ctx,
goto done;
}
- if (debug_to_file != 0) {
- ret = open_debug_file_ex(KRB5_CHILD_LOG_FILE, &debug_filep, false);
- if (ret != EOK) {
- DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n",
- ret, strerror(ret));
- goto done;
- }
-
- krb5_auth_ctx->child_debug_fd = fileno(debug_filep);
- if (krb5_auth_ctx->child_debug_fd == -1) {
- DEBUG(SSSDBG_FATAL_FAILURE,
- "fileno failed [%d][%s]\n", errno, strerror(errno));
- ret = errno;
- goto done;
- }
+ krb5_auth_ctx->child_debug_fd = -1; /* -1 means not initialized */
+ ret = child_debug_init(KRB5_CHILD_LOG_FILE,
+ &krb5_auth_ctx->child_debug_fd);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "Could not set krb5_child debugging!\n");
+ goto done;
}
+ ret = EOK;
+
done:
return ret;
}
diff --git a/src/providers/ldap/sdap_child_helpers.c b/src/providers/ldap/sdap_child_helpers.c
index e5d46b9b7..400109890 100644
--- a/src/providers/ldap/sdap_child_helpers.c
+++ b/src/providers/ldap/sdap_child_helpers.c
@@ -466,25 +466,5 @@ static errno_t set_tgt_child_timeout(struct tevent_req *req,
/* Setup child logging */
int sdap_setup_child(void)
{
- int ret;
- FILE *debug_filep;
-
- if (debug_to_file != 0 && ldap_child_debug_fd == -1) {
- ret = open_debug_file_ex(LDAP_CHILD_LOG_FILE, &debug_filep, false);
- if (ret != EOK) {
- DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n",
- ret, strerror(ret));
- return ret;
- }
-
- ldap_child_debug_fd = fileno(debug_filep);
- if (ldap_child_debug_fd == -1) {
- DEBUG(SSSDBG_FATAL_FAILURE,
- "fileno failed [%d][%s]\n", errno, strerror(errno));
- ret = errno;
- return ret;
- }
- }
-
- return EOK;
+ return child_debug_init(LDAP_CHILD_LOG_FILE, &ldap_child_debug_fd);
}
diff --git a/src/util/child_common.c b/src/util/child_common.c
index e4a885b6e..cc6a8fa75 100644
--- a/src/util/child_common.c
+++ b/src/util/child_common.c
@@ -801,3 +801,32 @@ int child_io_destructor(void *ptr)
return EOK;
}
+
+errno_t child_debug_init(const char *logfile, int *debug_fd)
+{
+ int ret;
+ FILE *debug_filep;
+
+ if (debug_fd == NULL) {
+ return EOK;
+ }
+
+ if (debug_to_file != 0 && *debug_fd == -1) {
+ ret = open_debug_file_ex(logfile, &debug_filep, false);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_FATAL_FAILURE, "Error setting up logging (%d) [%s]\n",
+ ret, sss_strerror(ret));
+ return ret;
+ }
+
+ *debug_fd = fileno(debug_filep);
+ if (*debug_fd == -1) {
+ DEBUG(SSSDBG_FATAL_FAILURE,
+ "fileno failed [%d][%s]\n", errno, strerror(errno));
+ ret = errno;
+ return ret;
+ }
+ }
+
+ return EOK;
+}
diff --git a/src/util/child_common.h b/src/util/child_common.h
index 261da7f9c..e159719a2 100644
--- a/src/util/child_common.h
+++ b/src/util/child_common.h
@@ -120,4 +120,6 @@ void child_cleanup(int readfd, int writefd);
int child_io_destructor(void *ptr);
+errno_t child_debug_init(const char *logfile, int *debug_fd);
+
#endif /* __CHILD_COMMON_H__ */