xref: /netbsd-src/external/bsd/openldap/dist/include/ldap_log.h (revision deb6f0161a9109e7de9b519dc8dfb9478668dcdd)
1 /*	$NetBSD: ldap_log.h,v 1.1.1.6 2018/02/06 01:53:05 christos Exp $	*/
2 
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2017 The OpenLDAP Foundation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms are permitted
21  * provided that this notice is preserved and that due credit is given
22  * to the University of Michigan at Ann Arbor. The name of the University
23  * may not be used to endorse or promote products derived from this
24  * software without specific prior written permission. This software
25  * is provided ``as is'' without express or implied warranty.
26  */
27 
28 #ifndef LDAP_LOG_H
29 #define LDAP_LOG_H
30 
31 #include <stdio.h>
32 #include <ldap_cdefs.h>
33 
34 LDAP_BEGIN_DECL
35 
36 /*
37  * debug reporting levels.
38  *
39  * They start with the syslog levels, and
40  * go down in importance.  The normal
41  * debugging levels begin with LDAP_LEVEL_ENTRY
42  *
43  */
44 
45 /*
46  * The "OLD_DEBUG" means that all logging occurs at LOG_DEBUG
47  */
48 
49 #ifdef OLD_DEBUG
50 /* original behavior: all logging occurs at the same severity level */
51 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
52 #define LDAP_LEVEL_EMERG	ldap_syslog_level
53 #define LDAP_LEVEL_ALERT	ldap_syslog_level
54 #define LDAP_LEVEL_CRIT		ldap_syslog_level
55 #define LDAP_LEVEL_ERR		ldap_syslog_level
56 #define LDAP_LEVEL_WARNING	ldap_syslog_level
57 #define LDAP_LEVEL_NOTICE	ldap_syslog_level
58 #define LDAP_LEVEL_INFO		ldap_syslog_level
59 #define LDAP_LEVEL_DEBUG	ldap_syslog_level
60 #else /* !LDAP_DEBUG || !LDAP_SYSLOG */
61 #define LDAP_LEVEL_EMERG	(7)
62 #define LDAP_LEVEL_ALERT	(7)
63 #define LDAP_LEVEL_CRIT		(7)
64 #define LDAP_LEVEL_ERR		(7)
65 #define LDAP_LEVEL_WARNING	(7)
66 #define LDAP_LEVEL_NOTICE	(7)
67 #define LDAP_LEVEL_INFO		(7)
68 #define LDAP_LEVEL_DEBUG	(7)
69 #endif /* !LDAP_DEBUG || !LDAP_SYSLOG */
70 
71 #else /* ! OLD_DEBUG */
72 /* map syslog onto LDAP severity levels */
73 #ifdef LOG_DEBUG
74 #define LDAP_LEVEL_EMERG	LOG_EMERG
75 #define LDAP_LEVEL_ALERT	LOG_ALERT
76 #define LDAP_LEVEL_CRIT		LOG_CRIT
77 #define LDAP_LEVEL_ERR		LOG_ERR
78 #define LDAP_LEVEL_WARNING	LOG_WARNING
79 #define LDAP_LEVEL_NOTICE	LOG_NOTICE
80 #define LDAP_LEVEL_INFO		LOG_INFO
81 #define LDAP_LEVEL_DEBUG	LOG_DEBUG
82 #else /* ! LOG_DEBUG */
83 #define LDAP_LEVEL_EMERG	(0)
84 #define LDAP_LEVEL_ALERT	(1)
85 #define LDAP_LEVEL_CRIT		(2)
86 #define LDAP_LEVEL_ERR		(3)
87 #define LDAP_LEVEL_WARNING	(4)
88 #define LDAP_LEVEL_NOTICE	(5)
89 #define LDAP_LEVEL_INFO		(6)
90 #define LDAP_LEVEL_DEBUG	(7)
91 #endif /* ! LOG_DEBUG */
92 #endif /* ! OLD_DEBUG */
93 #if 0
94 /* in case we need to reuse the unused bits of severity */
95 #define	LDAP_LEVEL_MASK(s)	((s) & 0x7)
96 #else
97 #define	LDAP_LEVEL_MASK(s)	(s)
98 #endif
99 
100 /* (yet) unused */
101 #define LDAP_LEVEL_ENTRY	(0x08)	/* log function entry points */
102 #define LDAP_LEVEL_ARGS		(0x10)	/* log function call parameters */
103 #define LDAP_LEVEL_RESULTS	(0x20)	/* Log function results */
104 #define LDAP_LEVEL_DETAIL1	(0x40)	/* log level 1 function operational details */
105 #define LDAP_LEVEL_DETAIL2	(0x80)	/* Log level 2 function operational details */
106 /* end of (yet) unused */
107 
108 /* original subsystem selection mechanism */
109 #define LDAP_DEBUG_TRACE	0x0001
110 #define LDAP_DEBUG_PACKETS	0x0002
111 #define LDAP_DEBUG_ARGS		0x0004
112 #define LDAP_DEBUG_CONNS	0x0008
113 #define LDAP_DEBUG_BER		0x0010
114 #define LDAP_DEBUG_FILTER	0x0020
115 #define LDAP_DEBUG_CONFIG	0x0040
116 #define LDAP_DEBUG_ACL		0x0080
117 #define LDAP_DEBUG_STATS	0x0100
118 #define LDAP_DEBUG_STATS2	0x0200
119 #define LDAP_DEBUG_SHELL	0x0400
120 #define LDAP_DEBUG_PARSE	0x0800
121 #if 0 /* no longer used (nor supported) */
122 #define LDAP_DEBUG_CACHE	0x1000
123 #define LDAP_DEBUG_INDEX	0x2000
124 #endif
125 #define LDAP_DEBUG_SYNC		0x4000
126 
127 #define LDAP_DEBUG_NONE		0x8000
128 #define LDAP_DEBUG_ANY		(-1)
129 
130 /* debugging stuff */
131 #ifdef LDAP_DEBUG
132     /*
133      * This is a bogus extern declaration for the compiler. No need to ensure
134      * a 'proper' dllimport.
135      */
136 #ifndef ldap_debug
137 extern int	ldap_debug;
138 #endif /* !ldap_debug */
139 
140 #ifdef LDAP_SYSLOG
141 extern int	ldap_syslog;
142 extern int	ldap_syslog_level;
143 
144 #ifdef HAVE_EBCDIC
145 #define syslog	eb_syslog
146 extern void eb_syslog(int pri, const char *fmt, ...);
147 #endif /* HAVE_EBCDIC */
148 
149 #endif /* LDAP_SYSLOG */
150 
151 /* this doesn't below as part of ldap.h */
152 #ifdef LDAP_SYSLOG
153 #define Log0( level, severity, fmt )	\
154 	do { \
155 		if ( ldap_debug & (level) ) \
156 			lutil_debug( ldap_debug, (level), (fmt) ); \
157 		if ( ldap_syslog & (level) ) \
158 			syslog( LDAP_LEVEL_MASK((severity)), (fmt) ); \
159 	} while ( 0 )
160 #define Log1( level, severity, fmt, arg1 )	\
161 	do { \
162 		if ( ldap_debug & (level) ) \
163 			lutil_debug( ldap_debug, (level), (fmt), (arg1) ); \
164 		if ( ldap_syslog & (level) ) \
165 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1) ); \
166 	} while ( 0 )
167 #define Log2( level, severity, fmt, arg1, arg2 ) \
168 	do { \
169 		if ( ldap_debug & (level) ) \
170 			lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2) ); \
171 		if ( ldap_syslog & (level) ) \
172 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2) ); \
173 	} while ( 0 )
174 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) \
175 	do { \
176 		if ( ldap_debug & (level) ) \
177 			lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
178 		if ( ldap_syslog & (level) ) \
179 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3) ); \
180 	} while ( 0 )
181 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) \
182 	do { \
183 		if ( ldap_debug & (level) ) \
184 			lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
185 		if ( ldap_syslog & (level) ) \
186 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
187 	} while ( 0 )
188 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) \
189 	do { \
190 		if ( ldap_debug & (level) ) \
191 			lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
192 		if ( ldap_syslog & (level) ) \
193 			syslog( LDAP_LEVEL_MASK((severity)), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
194 	} while ( 0 )
195 #define Debug( level, fmt, arg1, arg2, arg3 )	\
196 	Log3( (level), ldap_syslog_level, (fmt), (arg1), (arg2), (arg3) )
197 #define LogTest(level) ( ( ldap_debug | ldap_syslog ) & (level) )
198 
199 #else /* ! LDAP_SYSLOG */
200 #define Log0( level, severity, fmt ) \
201 	do { \
202 		if ( ldap_debug & (level) ) \
203 	    		lutil_debug( ldap_debug, (level), (fmt) ); \
204 	} while ( 0 )
205 #define Log1( level, severity, fmt, arg1 ) \
206 	do { \
207 		if ( ldap_debug & (level) ) \
208 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1) ); \
209 	} while ( 0 )
210 #define Log2( level, severity, fmt, arg1, arg2 ) \
211 	do { \
212 		if ( ldap_debug & (level) ) \
213 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2) ); \
214 	} while ( 0 )
215 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) \
216 	do { \
217 		if ( ldap_debug & (level) ) \
218 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3) ); \
219 	} while ( 0 )
220 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) \
221 	do { \
222 		if ( ldap_debug & (level) ) \
223 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4) ); \
224 	} while ( 0 )
225 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) \
226 	do { \
227 		if ( ldap_debug & (level) ) \
228 	    		lutil_debug( ldap_debug, (level), (fmt), (arg1), (arg2), (arg3), (arg4), (arg5) ); \
229 	} while ( 0 )
230 #define Debug( level, fmt, arg1, arg2, arg3 ) \
231 		Log3( (level), 0, (fmt), (arg1), (arg2), (arg3) )
232 #define LogTest(level) ( ldap_debug & (level) )
233 #endif /* ! LDAP_SYSLOG */
234 #else /* ! LDAP_DEBUG */
235 /* TODO: in case LDAP_DEBUG is undefined, make sure logs with appropriate
236  * severity gets thru anyway */
237 #define Log0( level, severity, fmt ) ((void)0)
238 #define Log1( level, severity, fmt, arg1 ) ((void)0)
239 #define Log2( level, severity, fmt, arg1, arg2 ) ((void)0)
240 #define Log3( level, severity, fmt, arg1, arg2, arg3 ) ((void)0)
241 #define Log4( level, severity, fmt, arg1, arg2, arg3, arg4 ) ((void)0)
242 #define Log5( level, severity, fmt, arg1, arg2, arg3, arg4, arg5 ) ((void)0)
243 #define Debug( level, fmt, arg1, arg2, arg3 ) ((void)0)
244 #define LogTest(level) ( 0 )
245 #endif /* ! LDAP_DEBUG */
246 
247 /* Actually now in liblber/debug.c */
248 LDAP_LUTIL_F(int) lutil_debug_file LDAP_P(( FILE *file ));
249 
250 LDAP_LUTIL_F(void) lutil_debug LDAP_P((
251 	int debug, int level,
252 	const char* fmt, ... )) LDAP_GCCATTR((format(printf, 3, 4)));
253 
254 #ifdef LDAP_DEFINE_LDAP_DEBUG
255 /* This struct matches the head of ldapoptions in <ldap-int.h> */
256 struct ldapoptions_prefix {
257 	short	ldo_valid;
258 	int		ldo_debug;
259 };
260 #define ldap_debug \
261 	(*(int *) ((char *)&ldap_int_global_options \
262 		 + offsetof(struct ldapoptions_prefix, ldo_debug)))
263 
264 struct ldapoptions;
265 LDAP_V ( struct ldapoptions ) ldap_int_global_options;
266 #endif /* LDAP_DEFINE_LDAP_DEBUG */
267 
268 LDAP_END_DECL
269 
270 #endif /* LDAP_LOG_H */
271