summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/sssd.spec.in1
-rw-r--r--server/Makefile.am4
-rw-r--r--server/conf_macros.m417
-rw-r--r--server/confdb/confdb.h1
-rw-r--r--server/configure.ac1
-rw-r--r--server/man/sssd.8.xml12
-rw-r--r--server/monitor/monitor.c18
-rw-r--r--server/providers/data_provider.c4
-rw-r--r--server/providers/data_provider_be.c4
-rw-r--r--server/responder/nss/nsssrv.c4
-rw-r--r--server/responder/pam/pamsrv.c4
-rw-r--r--server/sysv/sssd2
-rw-r--r--server/util/debug.c37
-rw-r--r--server/util/server.c26
-rw-r--r--server/util/util.h5
15 files changed, 129 insertions, 11 deletions
diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in
index 79448e622..771f1900a 100644
--- a/contrib/sssd.spec.in
+++ b/contrib/sssd.spec.in
@@ -128,6 +128,7 @@ rm -rf $RPM_BUILD_ROOT
%attr(700,root,root) %dir %{dbpath}
%attr(755,root,root) %dir %{pipepath}
%attr(700,root,root) %dir %{pipepath}/private
+%attr(750,root,root) %dir %{_var}/log/%{name}
%dir %{_sysconfdir}/sssd
%config(noreplace) %{_sysconfdir}/sssd/sssd.conf
%{_mandir}/man5/sssd.conf.5*
diff --git a/server/Makefile.am b/server/Makefile.am
index a5555204f..f43cf188a 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -20,7 +20,7 @@ pluginpath = @pluginpath@
pidpath = @pidpath@
pipepath = @pipepath@
initdir = @initdir@
-shadow_utils_path = @shadow_utils_path@
+logpath = @logpath@
AM_CFLAGS =
if WANT_AUX_INFO
@@ -555,7 +555,7 @@ installsssddirs::
$(DESTDIR)$(dbpath) \
$(DESTDIR)$(pidpath) \
$(DESTDIR)$(initdir) \
- $(DESTDIR)$(shadow_utils_path)
+ $(DESTDIR)$(logpath)
install-exec-hook: installsssddirs
diff --git a/server/conf_macros.m4 b/server/conf_macros.m4
index 9ab2003e9..410914e7e 100644
--- a/server/conf_macros.m4
+++ b/server/conf_macros.m4
@@ -49,6 +49,23 @@ AC_DEFUN([WITH_PID_PATH],
AC_DEFINE_UNQUOTED(PID_PATH, "$config_pidpath", [Where to store pid files for the SSSD])
])
+AC_DEFUN([WITH_LOG_PATH],
+ [ AC_ARG_WITH([log-path],
+ [AC_HELP_STRING([--with-log-path=PATH],
+ [Where to store log files for the SSSD [/var/log/sssd]]
+ )
+ ]
+ )
+ config_logpath="\"VARDIR\"/log/sssd"
+ logpath="${localstatedir}/log/sssd"
+ if test x"$with_log_path" != x; then
+ config_logpath=$with_log_path
+ logpath=$with_log_path
+ fi
+ AC_SUBST(logpath)
+ AC_DEFINE_UNQUOTED(LOG_PATH, "$config_logpath", [Where to store log files for the SSSD])
+ ])
+
AC_DEFUN([WITH_PIPE_PATH],
[ AC_ARG_WITH([pipe-path],
[AC_HELP_STRING([--with-pipe-path=PATH],
diff --git a/server/confdb/confdb.h b/server/confdb/confdb.h
index 7ca85507c..eef9a260b 100644
--- a/server/confdb/confdb.h
+++ b/server/confdb/confdb.h
@@ -41,6 +41,7 @@
#define CONFDB_SERVICE_COMMAND "command"
#define CONFDB_SERVICE_DEBUG_LEVEL "debug_level"
#define CONFDB_SERVICE_DEBUG_TIMESTAMPS "debug_timestamps"
+#define CONFDB_SERVICE_DEBUG_TO_FILES "debug_to_files"
#define CONFDB_SERVICE_TIMEOUT "timeout"
#define CONFDB_SERVICE_RECON_RETRIES "reconnection_retries"
diff --git a/server/configure.ac b/server/configure.ac
index 03d2885ac..31dd87d83 100644
--- a/server/configure.ac
+++ b/server/configure.ac
@@ -42,6 +42,7 @@ m4_include(conf_macros.m4)
WITH_DB_PATH
WITH_PLUGIN_PATH
WITH_PID_PATH
+WITH_LOG_PATH
WITH_PIPE_PATH
WITH_INIT_DIR
WITH_SHADOW_UTILS_PATH
diff --git a/server/man/sssd.8.xml b/server/man/sssd.8.xml
index f6f71c6c4..880cf769b 100644
--- a/server/man/sssd.8.xml
+++ b/server/man/sssd.8.xml
@@ -56,6 +56,18 @@
</varlistentry>
<varlistentry>
<term>
+ <option>-f</option>,<option>--debug-to-files</option>
+ </term>
+ <listitem>
+ <para>
+ Send the debug output to files instead of stderr. By default, the
+ log files are stored in <filename>/var/log/sssd</filename> and
+ there are separate log files for every SSSD service and domain.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
<option>-D</option>,<option>--daemon</option>
</term>
<listitem>
diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c
index b78a768c3..9972397e9 100644
--- a/server/monitor/monitor.c
+++ b/server/monitor/monitor.c
@@ -938,11 +938,13 @@ static int get_service_config(struct mt_ctx *ctx, const char *name,
}
if (!svc->command) {
- svc->command = talloc_asprintf(svc, "%s/sssd_%s -d %d%s",
+ svc->command = talloc_asprintf(svc, "%s/sssd_%s -d %d%s%s",
SSSD_LIBEXEC_PATH,
svc->name, debug_level,
(debug_timestamps?
- " --debug-timestamps":""));
+ " --debug-timestamps":""),
+ (debug_to_file ?
+ " --debug-to-files":""));
if (!svc->command) {
talloc_free(svc);
return ENOMEM;
@@ -1053,9 +1055,10 @@ static int get_provider_config(struct mt_ctx *ctx, const char *name,
/* if there are no custom commands, build a default one */
if (!svc->command) {
svc->command = talloc_asprintf(svc,
- "%s/sssd_be -d %d%s --domain %s",
+ "%s/sssd_be -d %d%s%s --domain %s",
SSSD_LIBEXEC_PATH, debug_level,
(debug_timestamps?" --debug-timestamps":""),
+ (debug_to_file?" --debug-to-files":""),
svc->name);
if (!svc->command) {
talloc_free(svc);
@@ -2427,6 +2430,15 @@ int main(int argc, const char *argv[])
/* we want a pid file check */
flags |= FLAGS_PID_FILE;
+ /* Open before server_setup() does to have logging
+ * during configuration checking */
+ if (debug_to_file) {
+ ret = open_debug_file();
+ if (ret) {
+ return 7;
+ }
+ }
+
/* Parse config file, fail if cannot be done */
ret = load_configuration(tmp_ctx, config_file, &monitor);
if (ret != EOK) return 4;
diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c
index f727c5559..0838cd021 100644
--- a/server/providers/data_provider.c
+++ b/server/providers/data_provider.c
@@ -992,7 +992,9 @@ int main(int argc, const char *argv[])
poptFreeContext(pc);
- /* set up things like debug , signals, daemonization, etc... */
+ /* set up things like debug, signals, daemonization, etc... */
+ debug_log_file = "sssd_dp";
+
ret = server_setup("sssd[dp]", 0, CONFDB_DP_CONF_ENTRY, &main_ctx);
if (ret != EOK) return 2;
diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c
index 62ce7bbe5..29d6fa0e3 100644
--- a/server/providers/data_provider_be.c
+++ b/server/providers/data_provider_be.c
@@ -947,7 +947,11 @@ int main(int argc, const char *argv[])
poptFreeContext(pc);
+
/* set up things like debug , signals, daemonization, etc... */
+ debug_log_file = talloc_asprintf(NULL, "sssd_%s", be_domain);
+ if (!debug_log_file) return 2;
+
srv_name = talloc_asprintf(NULL, "sssd[be[%s]]", be_domain);
if (!srv_name) return 2;
diff --git a/server/responder/nss/nsssrv.c b/server/responder/nss/nsssrv.c
index e000dfa18..6cdd19a92 100644
--- a/server/responder/nss/nsssrv.c
+++ b/server/responder/nss/nsssrv.c
@@ -353,7 +353,9 @@ int main(int argc, const char *argv[])
poptFreeContext(pc);
- /* set up things like debug , signals, daemonization, etc... */
+ /* set up things like debug, signals, daemonization, etc... */
+ debug_log_file = "sssd_nss";
+
ret = server_setup("sssd[nss]", 0, CONFDB_NSS_CONF_ENTRY, &main_ctx);
if (ret != EOK) return 2;
diff --git a/server/responder/pam/pamsrv.c b/server/responder/pam/pamsrv.c
index 50acc26ce..dbc8ec12d 100644
--- a/server/responder/pam/pamsrv.c
+++ b/server/responder/pam/pamsrv.c
@@ -190,7 +190,9 @@ int main(int argc, const char *argv[])
poptFreeContext(pc);
- /* set up things like debug , signals, daemonization, etc... */
+ /* set up things like debug, signals, daemonization, etc... */
+ debug_log_file = "sssd_pam";
+
ret = server_setup("sssd[pam]", 0, CONFDB_PAM_CONF_ENTRY, &main_ctx);
if (ret != EOK) return 2;
diff --git a/server/sysv/sssd b/server/sysv/sssd
index 138540166..6ef7862cb 100644
--- a/server/sysv/sssd
+++ b/server/sysv/sssd
@@ -38,7 +38,7 @@ PID_FILE=/var/run/sssd.pid
start() {
[ -x $SSSD ] || exit 5
echo -n $"Starting $prog: "
- daemon $SSSD -D 2>/dev/null && success || failure
+ daemon $SSSD -f -D && success || failure
RETVAL=$?
echo
[ "$RETVAL" = 0 ] && touch $LOCK_FILE
diff --git a/server/util/debug.c b/server/util/debug.c
index a7b3a0916..c6aa27c92 100644
--- a/server/util/debug.c
+++ b/server/util/debug.c
@@ -24,12 +24,19 @@
#include <stdarg.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
#include "util/util.h"
const char *debug_prg_name = "sssd";
int debug_level = 0;
int debug_timestamps = 0;
+int debug_to_file = 0;
+const char *debug_log_file = "sssd";
+FILE *debug_file = NULL;
+
void debug_fn(const char *format, ...)
{
va_list ap;
@@ -47,7 +54,8 @@ void debug_fn(const char *format, ...)
va_end(ap);
/*write(state.fd, s, strlen(s));*/
- fprintf(stderr, s);
+ fprintf(debug_file ? debug_file : stderr, s);
+ fflush(debug_file ? debug_file : stderr);
free(s);
}
@@ -90,3 +98,30 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level,
}
free(message);
}
+
+int open_debug_file()
+{
+ FILE *f = NULL;
+ char *logpath;
+ mode_t old_umask;
+ int ret;
+
+ ret = asprintf(&logpath, "%s/%s.log", LOG_PATH, debug_log_file);
+ if (ret == -1) {
+ return ENOMEM;
+ }
+
+ if (debug_file) fclose(debug_file);
+
+ old_umask = umask(0177);
+ f = fopen(logpath, "a");
+ if (f == NULL) {
+ free(logpath);
+ return EIO;
+ }
+ umask(old_umask);
+
+ debug_file = f;
+ free(logpath);
+ return EOK;
+}
diff --git a/server/util/server.c b/server/util/server.c
index a8c502409..e8daf87cb 100644
--- a/server/util/server.c
+++ b/server/util/server.c
@@ -298,6 +298,7 @@ int server_setup(const char *name, int flags,
char *conf_db;
int ret = EOK;
bool dt;
+ bool dl;
debug_prg_name = strdup(name);
if (!debug_prg_name) {
@@ -352,7 +353,6 @@ int server_setup(const char *name, int flags,
DEBUG(0,("Out of memory, aborting!\n"));
return ENOMEM;
}
- DEBUG(3, ("CONFDB: %s\n", conf_db));
ret = confdb_init(ctx, &ctx->confdb_ctx, conf_db);
if (ret != EOK) {
@@ -382,6 +382,30 @@ int server_setup(const char *name, int flags,
}
if (dt) debug_timestamps = 1;
+ /* same for debug to file */
+ dl = (debug_to_file != 0);
+ ret = confdb_get_bool(ctx->confdb_ctx, ctx, conf_entry,
+ CONFDB_SERVICE_DEBUG_TO_FILES,
+ dl, &dl);
+ if (ret != EOK) {
+ DEBUG(0, ("Error reading from confdb (%d) [%s]\n",
+ ret, strerror(ret)));
+ return ret;
+ }
+ if (dl) debug_to_file = 1;
+
+ /* open log file if told so */
+ if (debug_to_file) {
+ ret = open_debug_file();
+ if (ret != EOK) {
+ DEBUG(0, ("Error setting up logging (%d) [%s]\n",
+ ret, strerror(ret)));
+ return ret;
+ }
+ }
+
+ DEBUG(3, ("CONFDB: %s\n", conf_db));
+
if (flags & FLAGS_INTERACTIVE) {
/* terminate when stdin goes away */
stdin_event_flags = TEVENT_FD_READ;
diff --git a/server/util/util.h b/server/util/util.h
index ea7f44e83..0212df062 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -43,11 +43,15 @@ typedef int errno_t;
extern const char *debug_prg_name;
extern int debug_level;
extern int debug_timestamps;
+extern int debug_to_file;
+extern const char *debug_log_file;
void debug_fn(const char *format, ...);
#define SSSD_DEBUG_OPTS \
{"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \
"Debug level", NULL}, \
+ {"debug-to-files", 'f', POPT_ARG_NONE, &debug_to_file, 0, \
+ "Send the debug output to files instead of stderr", NULL }, \
{"debug-timestamps", 0, POPT_ARG_NONE, &debug_timestamps, 0, \
"Add debug timestamps", NULL},
@@ -133,6 +137,7 @@ void debug_fn(const char *format, ...);
/* From debug.c */
void ldb_debug_messages(void *context, enum ldb_debug_level level,
const char *fmt, va_list ap);
+int open_debug_file(void);
/* from server.c */
struct main_context {