1999-10-22 19:33:40 +00:00
|
|
|
/*
|
2006-06-09 00:54:09 +00:00
|
|
|
* Copyright (C) 2004-2006 Internet Systems Consortium, Inc. ("ISC")
|
2004-03-05 05:14:21 +00:00
|
|
|
* Copyright (C) 1999-2002 Internet Software Consortium.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
1999-10-22 19:33:40 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2004-03-05 05:14:21 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
1999-10-22 19:33:40 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-09 00:54:09 +00:00
|
|
|
/* $Id: log.c,v 1.43 2006/06/09 00:54:09 marka Exp $ */
|
2005-04-27 04:57:32 +00:00
|
|
|
|
|
|
|
/*! \file */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
1999-10-22 19:33:40 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-08-25 01:08:20 +00:00
|
|
|
#include <isc/result.h>
|
|
|
|
|
2001-03-04 21:21:39 +00:00
|
|
|
#include <isccfg/log.h>
|
|
|
|
|
1999-10-22 19:33:40 +00:00
|
|
|
#include <named/log.h>
|
|
|
|
|
2001-11-23 01:15:07 +00:00
|
|
|
#ifndef ISC_FACILITY
|
|
|
|
#define ISC_FACILITY LOG_DAEMON
|
|
|
|
#endif
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
1999-10-22 19:33:40 +00:00
|
|
|
* When adding a new category, be sure to add the appropriate
|
2004-11-09 21:24:20 +00:00
|
|
|
* #define to <named/log.h> and to update the list in
|
|
|
|
* bin/check/check-tool.c.
|
1999-10-22 19:33:40 +00:00
|
|
|
*/
|
|
|
|
static isc_logcategory_t categories[] = {
|
2000-03-23 00:55:12 +00:00
|
|
|
{ "", 0 },
|
1999-10-22 19:33:40 +00:00
|
|
|
{ "client", 0 },
|
|
|
|
{ "network", 0 },
|
1999-10-23 00:44:40 +00:00
|
|
|
{ "update", 0 },
|
2000-11-23 01:32:48 +00:00
|
|
|
{ "queries", 0 },
|
2001-05-28 05:17:05 +00:00
|
|
|
{ "unmatched", 0 },
|
2002-06-12 06:29:49 +00:00
|
|
|
{ "update-security", 0 },
|
1999-10-22 19:33:40 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*%
|
1999-10-22 19:33:40 +00:00
|
|
|
* When adding a new module, be sure to add the appropriate
|
|
|
|
* #define to <dns/log.h>.
|
|
|
|
*/
|
|
|
|
static isc_logmodule_t modules[] = {
|
|
|
|
{ "main", 0 },
|
|
|
|
{ "client", 0 },
|
|
|
|
{ "server", 0 },
|
|
|
|
{ "query", 0 },
|
|
|
|
{ "interfacemgr", 0 },
|
1999-10-23 00:44:40 +00:00
|
|
|
{ "update", 0 },
|
|
|
|
{ "xfer-in", 0 },
|
|
|
|
{ "xfer-out", 0 },
|
1999-12-14 07:47:35 +00:00
|
|
|
{ "notify", 0 },
|
2001-03-27 00:44:59 +00:00
|
|
|
{ "control", 0 },
|
2000-06-16 01:39:02 +00:00
|
|
|
{ "lwresd", 0 },
|
1999-10-22 19:33:40 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
isc_result_t
|
2000-05-02 18:45:08 +00:00
|
|
|
ns_log_init(isc_boolean_t safe) {
|
1999-10-22 19:33:40 +00:00
|
|
|
isc_result_t result;
|
2000-11-25 01:33:11 +00:00
|
|
|
isc_logconfig_t *lcfg = NULL;
|
1999-10-22 19:33:40 +00:00
|
|
|
|
|
|
|
ns_g_categories = categories;
|
|
|
|
ns_g_modules = modules;
|
|
|
|
|
1999-10-23 00:32:48 +00:00
|
|
|
/*
|
|
|
|
* Setup a logging context.
|
|
|
|
*/
|
2000-02-26 19:57:02 +00:00
|
|
|
result = isc_log_create(ns_g_mctx, &ns_g_lctx, &lcfg);
|
1999-10-22 19:33:40 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2006-06-07 02:28:28 +00:00
|
|
|
/*
|
|
|
|
* named-checktool.c:setup_logging() needs to be kept in sync.
|
|
|
|
*/
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_log_registercategories(ns_g_lctx, ns_g_categories);
|
1999-10-22 19:33:40 +00:00
|
|
|
isc_log_registermodules(ns_g_lctx, ns_g_modules);
|
2000-05-03 21:11:40 +00:00
|
|
|
isc_log_setcontext(ns_g_lctx);
|
2000-02-26 19:57:02 +00:00
|
|
|
dns_log_init(ns_g_lctx);
|
2000-05-03 21:11:40 +00:00
|
|
|
dns_log_setcontext(ns_g_lctx);
|
2001-03-13 03:04:09 +00:00
|
|
|
cfg_log_init(ns_g_lctx);
|
1999-10-23 00:32:48 +00:00
|
|
|
|
2000-05-02 18:45:08 +00:00
|
|
|
if (safe)
|
|
|
|
result = ns_log_setsafechannels(lcfg);
|
|
|
|
else
|
|
|
|
result = ns_log_setdefaultchannels(lcfg);
|
2000-04-28 18:53:45 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
2000-05-02 18:45:08 +00:00
|
|
|
|
2000-04-28 18:53:45 +00:00
|
|
|
result = ns_log_setdefaultcategory(lcfg);
|
2000-03-01 00:40:54 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
isc_log_destroy(&ns_g_lctx);
|
2000-09-26 22:12:13 +00:00
|
|
|
isc_log_setcontext(NULL);
|
|
|
|
dns_log_setcontext(NULL);
|
2000-03-01 00:40:54 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2000-04-28 18:53:45 +00:00
|
|
|
ns_log_setdefaultchannels(isc_logconfig_t *lcfg) {
|
2000-03-01 00:40:54 +00:00
|
|
|
isc_result_t result;
|
|
|
|
isc_logdestination_t destination;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-10-23 00:32:48 +00:00
|
|
|
/*
|
2000-03-01 20:40:14 +00:00
|
|
|
* By default, the logging library makes "default_debug" log to
|
|
|
|
* stderr. In BIND, we want to override this and log to named.run
|
|
|
|
* instead, unless the the -g option was given.
|
1999-10-23 00:32:48 +00:00
|
|
|
*/
|
2000-03-01 20:40:14 +00:00
|
|
|
if (! ns_g_logstderr) {
|
|
|
|
destination.file.stream = NULL;
|
|
|
|
destination.file.name = "named.run";
|
2000-01-26 17:35:16 +00:00
|
|
|
destination.file.versions = ISC_LOG_ROLLNEVER;
|
|
|
|
destination.file.maximum_size = 0;
|
2000-03-01 20:40:14 +00:00
|
|
|
result = isc_log_createchannel(lcfg, "default_debug",
|
2000-12-11 19:24:30 +00:00
|
|
|
ISC_LOG_TOFILE,
|
|
|
|
ISC_LOG_DYNAMIC,
|
|
|
|
&destination,
|
|
|
|
ISC_LOG_PRINTTIME|
|
2000-03-01 20:40:14 +00:00
|
|
|
ISC_LOG_DEBUGONLY);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
2000-01-26 17:35:16 +00:00
|
|
|
}
|
2000-03-01 20:40:14 +00:00
|
|
|
|
2001-11-23 01:15:07 +00:00
|
|
|
#if ISC_FACILITY != LOG_DAEMON
|
|
|
|
destination.facility = ISC_FACILITY;
|
|
|
|
result = isc_log_createchannel(lcfg, "default_syslog",
|
|
|
|
ISC_LOG_TOSYSLOG, ISC_LOG_INFO,
|
|
|
|
&destination, 0);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
#endif
|
|
|
|
|
2000-04-28 18:53:45 +00:00
|
|
|
/*
|
|
|
|
* Set the initial debug level.
|
|
|
|
*/
|
|
|
|
isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
|
|
|
|
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-05-02 18:45:08 +00:00
|
|
|
isc_result_t
|
|
|
|
ns_log_setsafechannels(isc_logconfig_t *lcfg) {
|
|
|
|
isc_result_t result;
|
2005-05-20 01:19:43 +00:00
|
|
|
#if ISC_FACILITY != LOG_DAEMON
|
|
|
|
isc_logdestination_t destination;
|
|
|
|
#endif
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-05-02 18:45:08 +00:00
|
|
|
if (! ns_g_logstderr) {
|
|
|
|
result = isc_log_createchannel(lcfg, "default_debug",
|
2000-12-11 19:24:30 +00:00
|
|
|
ISC_LOG_TONULL,
|
|
|
|
ISC_LOG_DYNAMIC,
|
|
|
|
NULL, 0);
|
2000-05-02 18:45:08 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
|
2001-06-14 14:14:17 +00:00
|
|
|
/*
|
|
|
|
* Setting the debug level to zero should get the output
|
|
|
|
* discarded a bit faster.
|
|
|
|
*/
|
|
|
|
isc_log_setdebuglevel(ns_g_lctx, 0);
|
|
|
|
} else {
|
|
|
|
isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
|
|
|
|
}
|
2000-05-02 18:45:08 +00:00
|
|
|
|
2005-05-20 01:19:43 +00:00
|
|
|
#if ISC_FACILITY != LOG_DAEMON
|
|
|
|
destination.facility = ISC_FACILITY;
|
|
|
|
result = isc_log_createchannel(lcfg, "default_syslog",
|
|
|
|
ISC_LOG_TOSYSLOG, ISC_LOG_INFO,
|
|
|
|
&destination, 0);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
#endif
|
|
|
|
|
2000-05-02 18:45:08 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-04-28 18:53:45 +00:00
|
|
|
isc_result_t
|
|
|
|
ns_log_setdefaultcategory(isc_logconfig_t *lcfg) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
2001-10-31 17:42:04 +00:00
|
|
|
if (! ns_g_logstderr) {
|
|
|
|
result = isc_log_usechannel(lcfg, "default_syslog",
|
|
|
|
ISC_LOGCATEGORY_DEFAULT, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2000-03-01 20:40:14 +00:00
|
|
|
|
2000-03-04 16:41:48 +00:00
|
|
|
result = isc_log_usechannel(lcfg, "default_debug",
|
|
|
|
ISC_LOGCATEGORY_DEFAULT, NULL);
|
1999-10-22 19:33:40 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
1999-10-23 00:32:48 +00:00
|
|
|
|
2000-04-28 18:53:45 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
1999-10-22 19:33:40 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2001-05-28 05:17:05 +00:00
|
|
|
isc_result_t
|
|
|
|
ns_log_setunmatchedcategory(isc_logconfig_t *lcfg) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = isc_log_usechannel(lcfg, "null",
|
|
|
|
NS_LOGCATEGORY_UNMATCHED, NULL);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-10-22 19:33:40 +00:00
|
|
|
void
|
|
|
|
ns_log_shutdown(void) {
|
|
|
|
isc_log_destroy(&ns_g_lctx);
|
2000-09-26 22:12:13 +00:00
|
|
|
isc_log_setcontext(NULL);
|
|
|
|
dns_log_setcontext(NULL);
|
1999-10-22 19:33:40 +00:00
|
|
|
}
|