xref: /netbsd-src/external/bsd/openldap/dist/libraries/liblber/debug.c (revision 549b59ed3ccf0d36d3097190a0db27b770f3a839)
1 /*	$NetBSD: debug.c,v 1.3 2021/08/14 16:14:55 christos Exp $	*/
2 
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2021 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 the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 
18 #include <sys/cdefs.h>
19 __RCSID("$NetBSD: debug.c,v 1.3 2021/08/14 16:14:55 christos Exp $");
20 
21 #include "portable.h"
22 
23 #include <stdio.h>
24 
25 #include <ac/stdarg.h>
26 #include <ac/stdlib.h>
27 #include <ac/string.h>
28 #include <ac/time.h>
29 #include <ac/ctype.h>
30 
31 #ifdef LDAP_SYSLOG
32 #include <ac/syslog.h>
33 #endif
34 
35 #include "ldap_log.h"
36 #include "ldap_defaults.h"
37 #include "lber.h"
38 #include "ldap_pvt.h"
39 
lutil_debug_file(FILE * file)40 int lutil_debug_file( FILE *file )
41 {
42 	ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file );
43 
44 	return 0;
45 }
46 
47 void (lutil_debug)( int debug, int level, const char *fmt, ... )
48 {
49 	char buffer[4096];
50 	va_list vl;
51 
52 	if ( !(level & debug ) ) return;
53 
54 	va_start( vl, fmt );
55 	vsnprintf( buffer, sizeof(buffer), fmt, vl );
56 	va_end( vl );
57 	ber_pvt_log_print( buffer );
58 }
59 
60 #if defined(HAVE_EBCDIC) && defined(LDAP_SYSLOG)
61 #undef syslog
eb_syslog(int pri,const char * fmt,...)62 void eb_syslog( int pri, const char *fmt, ... )
63 {
64 	char buffer[4096];
65 	va_list vl;
66 
67 	va_start( vl, fmt );
68 	vsnprintf( buffer, sizeof(buffer), fmt, vl );
69 	buffer[sizeof(buffer)-1] = '\0';
70 
71 	/* The syslog function appears to only work with pure EBCDIC */
72 	__atoe(buffer);
73 #pragma convlit(suspend)
74 	syslog( pri, "%s", buffer );
75 #pragma convlit(resume)
76 	va_end( vl );
77 }
78 #endif
79