1 /* $NetBSD: debug.c,v 1.4 2025/09/05 21:16:20 christos Exp $ */ 2 3 /* $OpenLDAP$ */ 4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 1998-2024 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.4 2025/09/05 21:16:20 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 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 int len; 52 53 if ( !(level & debug ) ) return; 54 55 va_start( vl, fmt ); 56 len = vsnprintf( buffer, sizeof(buffer), fmt, vl ); 57 va_end( vl ); 58 if ( len >= sizeof(buffer)-2 ) 59 buffer[sizeof(buffer)-2] = '\n'; 60 ber_pvt_log_print( buffer ); 61 } 62 63 #if defined(HAVE_EBCDIC) && defined(LDAP_SYSLOG) 64 #undef syslog 65 void eb_syslog( int pri, const char *fmt, ... ) 66 { 67 char buffer[4096]; 68 va_list vl; 69 70 va_start( vl, fmt ); 71 vsnprintf( buffer, sizeof(buffer), fmt, vl ); 72 buffer[sizeof(buffer)-1] = '\0'; 73 74 /* The syslog function appears to only work with pure EBCDIC */ 75 __atoe(buffer); 76 #pragma convlit(suspend) 77 syslog( pri, "%s", buffer ); 78 #pragma convlit(resume) 79 va_end( vl ); 80 } 81 #endif 82