1999-09-08 15:06:24 -04:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-25 18:17:08 -05:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
|
*
|
2008-01-07 19:19:56 -05:00
|
|
|
* Copyright 1998-2008 The OpenLDAP Foundation.
|
2003-11-25 18:17:08 -05:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
|
* Public License.
|
|
|
|
|
*
|
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1999-08-17 15:00:59 -04:00
|
|
|
*/
|
1999-06-21 18:52:28 -04:00
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include <ac/stdarg.h>
|
2001-12-17 20:24:31 -05:00
|
|
|
#include <ac/stdlib.h>
|
1999-06-21 18:52:28 -04:00
|
|
|
#include <ac/string.h>
|
2000-10-12 16:01:12 -04:00
|
|
|
#include <ac/time.h>
|
2002-07-11 16:33:24 -04:00
|
|
|
#include <ac/ctype.h>
|
1999-06-21 18:52:28 -04:00
|
|
|
|
2002-05-10 13:48:54 -04:00
|
|
|
#ifdef LDAP_SYSLOG
|
|
|
|
|
#include <ac/syslog.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-06-21 18:52:28 -04:00
|
|
|
#include "ldap_log.h"
|
|
|
|
|
#include "ldap_defaults.h"
|
2000-05-11 05:39:33 -04:00
|
|
|
#include "lber.h"
|
2002-07-11 19:26:34 -04:00
|
|
|
#include "ldap_pvt.h"
|
1999-06-21 18:52:28 -04:00
|
|
|
|
2000-10-17 20:29:21 -04:00
|
|
|
static FILE *log_file = NULL;
|
|
|
|
|
|
1999-06-21 18:52:28 -04:00
|
|
|
int lutil_debug_file( FILE *file )
|
|
|
|
|
{
|
1999-09-02 03:40:25 -04:00
|
|
|
log_file = file;
|
2000-05-11 05:39:33 -04:00
|
|
|
ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, file );
|
1999-06-21 18:52:28 -04:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-14 23:48:27 -04:00
|
|
|
void (lutil_debug)( int debug, int level, const char *fmt, ... )
|
1999-06-21 18:52:28 -04:00
|
|
|
{
|
|
|
|
|
char buffer[4096];
|
|
|
|
|
va_list vl;
|
|
|
|
|
|
2003-07-07 23:46:20 -04:00
|
|
|
if ( !(level & debug ) ) return;
|
1999-06-21 18:52:28 -04:00
|
|
|
|
|
|
|
|
#ifdef HAVE_WINSOCK
|
2000-09-14 23:08:05 -04:00
|
|
|
if( log_file == NULL ) {
|
1999-06-21 18:59:23 -04:00
|
|
|
log_file = fopen( LDAP_RUNDIR LDAP_DIRSEP "openldap.log", "w" );
|
1999-06-21 18:52:28 -04:00
|
|
|
|
2003-07-07 23:46:20 -04:00
|
|
|
if ( log_file == NULL ) {
|
1999-06-21 18:59:23 -04:00
|
|
|
log_file = fopen( "openldap.log", "w" );
|
2003-07-07 23:46:20 -04:00
|
|
|
if ( log_file == NULL ) return;
|
|
|
|
|
}
|
2000-05-11 05:39:33 -04:00
|
|
|
|
2000-09-14 23:08:05 -04:00
|
|
|
ber_set_option( NULL, LBER_OPT_LOG_PRINT_FILE, log_file );
|
1999-06-21 18:52:28 -04:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-12-07 00:12:36 -05:00
|
|
|
va_start( vl, fmt );
|
1999-06-21 18:52:28 -04:00
|
|
|
vsnprintf( buffer, sizeof(buffer), fmt, vl );
|
|
|
|
|
buffer[sizeof(buffer)-1] = '\0';
|
|
|
|
|
if( log_file != NULL ) {
|
|
|
|
|
fputs( buffer, log_file );
|
|
|
|
|
fflush( log_file );
|
|
|
|
|
}
|
2002-07-25 22:56:01 -04:00
|
|
|
fputs( buffer, stderr );
|
1999-06-21 18:52:28 -04:00
|
|
|
va_end( vl );
|
|
|
|
|
}
|
2004-02-02 22:58:38 -05:00
|
|
|
|
|
|
|
|
#if defined(HAVE_EBCDIC) && defined(LDAP_SYSLOG)
|
2004-02-04 17:53:17 -05:00
|
|
|
#undef syslog
|
2004-02-02 22:58:38 -05:00
|
|
|
void eb_syslog( int pri, const char *fmt, ... )
|
|
|
|
|
{
|
|
|
|
|
char buffer[4096];
|
|
|
|
|
va_list vl;
|
|
|
|
|
|
|
|
|
|
va_start( vl, fmt );
|
|
|
|
|
vsnprintf( buffer, sizeof(buffer), fmt, vl );
|
|
|
|
|
buffer[sizeof(buffer)-1] = '\0';
|
|
|
|
|
|
2004-02-04 17:53:17 -05:00
|
|
|
/* The syslog function appears to only work with pure EBCDIC */
|
2004-02-02 22:58:38 -05:00
|
|
|
__atoe(buffer);
|
2004-02-04 17:53:17 -05:00
|
|
|
#pragma convlit(suspend)
|
2004-02-02 22:58:38 -05:00
|
|
|
syslog( pri, "%s", buffer );
|
2004-02-04 17:53:17 -05:00
|
|
|
#pragma convlit(resume)
|
2004-02-02 22:58:38 -05:00
|
|
|
va_end( vl );
|
|
|
|
|
}
|
|
|
|
|
#endif
|