/*
Authors:
Simo Sorce <ssorce@redhat.com>
Stephen Gallagher <sgallagh@redhat.com>
Copyright (C) 2009 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <fcntl.h>
#ifdef WITH_JOURNALD
#include <systemd/sd-journal.h>
#endif
int debug_to_file = 0;
int debug_to_stderr = 0;
const char *sss_logger_str[] = {
[STDERR_LOGGER] = "stderr",
[FILES_LOGGER] = "files",
#ifdef WITH_JOURNALD
[JOURNALD_LOGGER] = "journald",
#endif
NULL,
};
#ifdef WITH_JOURNALD
#else
#endif
{
/* use old flags */
if (debug_to_stderr != 0) {
}
/* It is never described what should be used in case of
* debug_to_stderr == 1 && debug_to_file == 1. Because neither
* of binaries provide both command line arguments.
* Let files have higher priority.
*/
if (debug_to_file != 0) {
}
#ifdef WITH_JOURNALD
if (debug_to_file == 0 && debug_to_stderr == 0) {
}
#endif
} else {
#ifdef WITH_JOURNALD
#endif
} else {
/* unexpected value */
}
}
}
{
errno = 0;
"Could not open debug file descriptor [%d]. "
"Debug messages will not be written to the file "
"for this child process [%s][%s]\n",
return ret;
}
debug_file = dummy;
return EOK;
}
int get_fd_from_debug_file(void)
{
if (debug_file == NULL) {
return STDERR_FILENO;
}
return fileno(debug_file);
}
{
return old_level;
if (old_level <= 0)
return new_level;
if (old_level >= 1)
if (old_level >= 2)
if (old_level >= 3)
if (old_level >= 4)
if (old_level >= 5)
if (old_level >= 6)
if (old_level >= 7)
if (old_level >= 8)
if (old_level >= 9)
return new_level;
}
static void debug_fflush(void)
{
}
{
}
static void debug_printf(const char *format, ...)
{
}
#ifdef WITH_JOURNALD
long line,
const char *function,
int level,
const char *format,
{
int res;
const char *domain;
/* First, evaluate the message to be sent */
if (ret == -1) {
/* ENOMEM, just return */
return ENOMEM;
}
if (res == -1) {
goto journal_done;
}
if (res == -1) {
goto journal_done;
}
/* If this log message was sent from a provider,
* track the domain.
*/
domain = "";
}
/* Send the log message to journald, specifying the
* source code location and other tracking data.
*/
"MESSAGE=%s", message,
"PRIORITY=%i", LOG_DEBUG,
"SSSD_DOMAIN=%s", domain,
"SSSD_PRG_NAME=%s", debug_prg_name,
"SSSD_DEBUG_LEVEL=%x", level,
NULL);
return ret;
}
#endif /* WiTH_JOURNALD */
long line,
const char *function,
int level,
int flags,
const char *format,
{
int year;
#ifdef WITH_JOURNALD
if (sss_logger == JOURNALD_LOGGER) {
/* If we are not outputting logs to files, we should be sending them
* to journald.
* from system services anyway. The only difference here is that we
* can also provide extra structuring data to make it more easily
* searchable.
*/
/* Emergency fallback, send to STDERR */
debug_fflush();
}
return;
}
#endif
if (debug_timestamps) {
/* get date time without year */
if (debug_microseconds) {
debug_printf("(%s:%.6ld %d) [%s] [%s] (%#.4x): ",
} else {
debug_printf("(%s %d) [%s] [%s] (%#.4x): ",
}
} else {
debug_printf("[%s] [%s] (%#.4x): ",
}
if (flags & APPEND_LINE_FEED) {
debug_printf("\n");
}
debug_fflush();
}
long line,
const char *function,
int level,
const char *format, ...)
{
}
{
switch(level) {
case LDB_DEBUG_FATAL:
break;
case LDB_DEBUG_ERROR:
break;
case LDB_DEBUG_WARNING:
break;
case LDB_DEBUG_TRACE:
break;
}
if (DEBUG_IS_SET(loglevel)) {
}
}
/* In cases SSSD used to run as the root user, but runs as the SSSD user now,
* we need to chown the log files
*/
{
char *logpath;
const char *log_file;
} else {
}
if (ret == -1) {
return ENOMEM;
}
if (ret != 0) {
/* Log does not exist. We might log to journald
* or starting for first time.
* It's not a failure. */
return EOK;
}
return ret;
}
return EOK;
}
{
char *logpath;
const char *log_file;
int ret;
int debug_fd;
int flags;
} else {
}
if (ret == -1) {
return ENOMEM;
}
errno = 0;
if (f == NULL) {
return EIO;
}
if (debug_fd == -1) {
fclose(f);
return EIO;
}
if(want_cloexec) {
}
debug_file = f;
} else {
*filep = f;
}
return EOK;
}
int open_debug_file(void)
{
}
int rotate_debug_files(void)
{
int ret;
do {
error = 0;
if (ret != 0) {
}
/* Check for EINTR, which means we should retry
* because the system call was interrupted by a
* signal
*/
if (error != 0) {
/* Even if we were unable to close the debug log, we need to make
* sure that we open up a new one. Log rotation will remove the
* current file, so all debug messages will be disappearing.
*
* We should write an error to the syslog warning of the resource
* leak and then proceed with opening the new file.
*/
"Be aware that this is a resource leak\n");
}
debug_file = NULL;
return open_debug_file();
}
{
}