sssd  2.2.3
About: SSSD provides a set of daemons to manage access to remote directories and authentication mechanisms such as LDAP, Kerberos or FreeIPA. It provides also an NSS and PAM interface toward the system.
  Fossies Dox: sssd-2.2.3.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

debug.h
Go to the documentation of this file.
1 /*
2  Authors:
3  Simo Sorce <ssorce@redhat.com>
4 
5  Copyright (C) 2009 Red Hat
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef __SSSD_DEBUG_H__
22 #define __SSSD_DEBUG_H__
23 
24 #include "config.h"
25 
26 #include <stdarg.h>
27 
28 #ifdef HAVE_FUNCTION_ATTRIBUTE_FORMAT
29 #define SSS_ATTRIBUTE_PRINTF(a1, a2) __attribute__((format (printf, a1, a2)))
30 #else
31 #define SSS_ATTRIBUTE_PRINTF(a1, a2)
32 #endif
33 
34 #define APPEND_LINE_FEED 0x1
35 
39 #ifdef WITH_JOURNALD
40  JOURNALD_LOGGER,
41 #endif
42 };
43 
44 extern const char *sss_logger_str[];
45 extern const char *debug_prg_name;
46 extern int debug_level;
47 extern int debug_timestamps;
48 extern int debug_microseconds;
49 extern int debug_to_file;
50 extern int debug_to_stderr;
51 extern enum sss_logger_t sss_logger;
52 extern const char *debug_log_file;
53 
54 void sss_set_logger(const char *logger);
55 
56 void sss_vdebug_fn(const char *file,
57  long line,
58  const char *function,
59  int level,
60  int flags,
61  const char *format,
62  va_list ap);
63 void sss_debug_fn(const char *file,
64  long line,
65  const char *function,
66  int level,
67  const char *format, ...) SSS_ATTRIBUTE_PRINTF(5, 6);
68 int debug_convert_old_level(int old_level);
69 errno_t set_debug_file_from_fd(const int fd);
70 int get_fd_from_debug_file(void);
71 
72 #define SSS_DOM_ENV "_SSS_DOM"
73 
74 #define SSSDBG_FATAL_FAILURE 0x0010 /* level 0 */
75 #define SSSDBG_CRIT_FAILURE 0x0020 /* level 1 */
76 #define SSSDBG_OP_FAILURE 0x0040 /* level 2 */
77 #define SSSDBG_MINOR_FAILURE 0x0080 /* level 3 */
78 #define SSSDBG_CONF_SETTINGS 0x0100 /* level 4 */
79 #define SSSDBG_FUNC_DATA 0x0200 /* level 5 */
80 #define SSSDBG_TRACE_FUNC 0x0400 /* level 6 */
81 #define SSSDBG_TRACE_LIBS 0x1000 /* level 7 */
82 #define SSSDBG_TRACE_INTERNAL 0x2000 /* level 8 */
83 #define SSSDBG_TRACE_ALL 0x4000 /* level 9 */
84 #define SSSDBG_BE_FO 0x8000 /* level 9 */
85 #define SSSDBG_IMPORTANT_INFO SSSDBG_OP_FAILURE
86 
87 #define SSSDBG_INVALID -1
88 #define SSSDBG_UNRESOLVED 0
89 #define SSSDBG_MASK_ALL 0xFFF0 /* enable all debug levels */
90 #define SSSDBG_DEFAULT SSSDBG_FATAL_FAILURE
91 
92 #define SSSDBG_TIMESTAMP_UNRESOLVED -1
93 #define SSSDBG_TIMESTAMP_DEFAULT 1
94 
95 #define SSSDBG_MICROSECONDS_UNRESOLVED -1
96 #define SSSDBG_MICROSECONDS_DEFAULT 0
97 
98 #define SSSD_LOGGER_OPTS \
99  {"logger", '\0', POPT_ARG_STRING, &opt_logger, 0, \
100  _("Set logger"), "stderr|files|journald"},
101 
102 
103 #define SSSD_DEBUG_OPTS \
104  {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \
105  _("Debug level"), NULL}, \
106  {"debug-to-files", 'f', POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, &debug_to_file, 0, \
107  _("Send the debug output to files instead of stderr"), NULL }, \
108  {"debug-to-stderr", 0, POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, &debug_to_stderr, 0, \
109  _("Send the debug output to stderr directly."), NULL }, \
110  {"debug-timestamps", 0, POPT_ARG_INT, &debug_timestamps, 0, \
111  _("Add debug timestamps"), NULL}, \
112  {"debug-microseconds", 0, POPT_ARG_INT, &debug_microseconds, 0, \
113  _("Show timestamps with microseconds"), NULL},
114 
123 #define DEBUG(level, format, ...) do { \
124  int __debug_macro_level = level; \
125  if (DEBUG_IS_SET(__debug_macro_level)) { \
126  sss_debug_fn(__FILE__, __LINE__, __FUNCTION__, \
127  __debug_macro_level, \
128  format, ##__VA_ARGS__); \
129  } \
130 } while (0)
131 
137 #define DEBUG_IS_SET(level) (debug_level & (level) || \
138  (debug_level == SSSDBG_UNRESOLVED && \
139  (level & (SSSDBG_FATAL_FAILURE | \
140  SSSDBG_CRIT_FAILURE))))
141 
142 #define DEBUG_INIT(dbg_lvl) do { \
143  if (dbg_lvl != SSSDBG_INVALID) { \
144  debug_level = debug_convert_old_level(dbg_lvl); \
145  } else { \
146  debug_level = SSSDBG_UNRESOLVED; \
147  } \
148 \
149  talloc_set_log_fn(talloc_log_fn); \
150 } while (0)
151 
152 /* CLI tools shall debug to stderr even when SSSD was compiled with journald
153  * support
154  */
155 #define DEBUG_CLI_INIT(dbg_lvl) do { \
156  DEBUG_INIT(dbg_lvl); \
157  debug_to_stderr = 1; \
158 } while (0)
159 
160 #define PRINT(fmt, ...) fprintf(stdout, gettext(fmt), ##__VA_ARGS__)
161 #define ERROR(fmt, ...) fprintf(stderr, gettext(fmt), ##__VA_ARGS__)
162 
163 #endif /* __SSSD_DEBUG_H__ */
debug_log_file
const char * debug_log_file
Definition: debug.c:47
sss_logger_t
sss_logger_t
Definition: debug.h:36
STDERR_LOGGER
@ STDERR_LOGGER
Definition: debug.h:37
debug_timestamps
int debug_timestamps
Definition: debug.c:42
sss_set_logger
void sss_set_logger(const char *logger)
Definition: debug.c:65
sss_logger
enum sss_logger_t sss_logger
Definition: debug.c:46
debug_level
int debug_level
Definition: sss_certmap.c:35
logger
static void logger(pam_handle_t *pamh, int level, const char *fmt,...)
Definition: pam_sss.c:75
sss_logger_str
const char * sss_logger_str[]
Definition: debug.c:50
errno_t
int errno_t
Definition: hbac_evaluator.c:36
debug_prg_name
const char * debug_prg_name
Definition: debug.c:39
FILES_LOGGER
@ FILES_LOGGER
Definition: debug.h:38
get_fd_from_debug_file
int get_fd_from_debug_file(void)
Definition: debug.c:127
sss_vdebug_fn
void sss_vdebug_fn(const char *file, long line, const char *function, int level, int flags, const char *format, va_list ap)
Definition: debug.c:263
SSS_ATTRIBUTE_PRINTF
#define SSS_ATTRIBUTE_PRINTF(a1, a2)
Definition: debug.h:31
debug_microseconds
int debug_microseconds
Definition: debug.c:43
sss_debug_fn
void sss_debug_fn(const char *file, long line, const char *function, int level, const char *format,...)
Definition: sss_certmap.c:36
debug_convert_old_level
int debug_convert_old_level(int old_level)
Definition: debug.c:136
debug_to_stderr
int debug_to_stderr
Definition: debug.c:45
debug_to_file
int debug_to_file
Definition: debug.c:44
set_debug_file_from_fd
errno_t set_debug_file_from_fd(const int fd)
Definition: debug.c:103