1999-10-22 19:33:40 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
1999-10-22 19:33:40 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
2000-08-25 01:08:20 +00:00
|
|
|
#include <isc/result.h>
|
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
#include <dns/log.h>
|
|
|
|
|
2001-03-04 21:21:39 +00:00
|
|
|
#include <isccfg/log.h>
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <ns/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
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifndef ISC_FACILITY */
|
2001-11-23 01:15:07 +00:00
|
|
|
|
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
|
2006-12-22 01:46:19 +00:00
|
|
|
* \#define to <named/log.h> and to update the list in
|
2004-11-09 21:24:20 +00:00
|
|
|
* bin/check/check-tool.c.
|
1999-10-22 19:33:40 +00:00
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
static isc_logcategory_t categories[] = { { "", 0 },
|
|
|
|
{ "unmatched", 0 },
|
|
|
|
{ NULL, 0 } };
|
1999-10-22 19:33:40 +00:00
|
|
|
|
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
|
2006-12-22 01:46:19 +00:00
|
|
|
* \#define to <dns/log.h>.
|
1999-10-22 19:33:40 +00:00
|
|
|
*/
|
|
|
|
static isc_logmodule_t modules[] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
{ "main", 0 }, { "server", 0 }, { "control", 0 }, { NULL, 0 }
|
1999-10-22 19:33:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
named_log_init(bool safe)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
named_g_categories = categories;
|
|
|
|
named_g_modules = modules;
|
1999-10-22 19:33:40 +00:00
|
|
|
|
1999-10-23 00:32:48 +00:00
|
|
|
/*
|
|
|
|
* Setup a logging context.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
result = isc_log_create(named_g_mctx, &named_g_lctx, &lcfg);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-10-22 19:33:40 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
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.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_registercategories(named_g_lctx, named_g_categories);
|
|
|
|
isc_log_registermodules(named_g_lctx, named_g_modules);
|
|
|
|
isc_log_setcontext(named_g_lctx);
|
|
|
|
dns_log_init(named_g_lctx);
|
|
|
|
dns_log_setcontext(named_g_lctx);
|
|
|
|
cfg_log_init(named_g_lctx);
|
|
|
|
ns_log_init(named_g_lctx);
|
|
|
|
ns_log_setcontext(named_g_lctx);
|
1999-10-23 00:32:48 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (safe) {
|
2017-09-08 13:39:09 -07:00
|
|
|
result = named_log_setsafechannels(lcfg);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
result = named_log_setdefaultchannels(lcfg);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-04-28 18:53:45 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-05-02 18:45:08 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
result = named_log_setdefaultcategory(lcfg);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-03-01 00:40:54 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-03-01 00:40:54 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_destroy(&named_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
|
2020-02-12 13:59:18 +01:00
|
|
|
named_log_setdefaultchannels(isc_logconfig_t *lcfg)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
2000-03-01 00:40:54 +00:00
|
|
|
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
|
2009-01-05 23:20:22 +00:00
|
|
|
* instead, unless the -g option was given.
|
1999-10-23 00:32:48 +00:00
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
if (!named_g_logstderr) {
|
2000-03-01 20:40:14 +00:00
|
|
|
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;
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_log_createchannel(
|
|
|
|
lcfg, "default_debug", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC,
|
|
|
|
&destination, ISC_LOG_PRINTTIME | ISC_LOG_DEBUGONLY);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-03-01 20:40:14 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-01-26 17:35:16 +00:00
|
|
|
}
|
2000-03-01 20:40:14 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_logfile != NULL) {
|
2014-04-29 17:17:03 -07:00
|
|
|
destination.file.stream = NULL;
|
2017-09-08 13:39:09 -07:00
|
|
|
destination.file.name = named_g_logfile;
|
2014-04-29 17:17:03 -07:00
|
|
|
destination.file.versions = ISC_LOG_ROLLNEVER;
|
|
|
|
destination.file.maximum_size = 0;
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_log_createchannel(
|
|
|
|
lcfg, "default_logfile", ISC_LOG_TOFILE,
|
|
|
|
ISC_LOG_DYNAMIC, &destination,
|
|
|
|
ISC_LOG_PRINTTIME | ISC_LOG_PRINTCATEGORY |
|
|
|
|
ISC_LOG_PRINTLEVEL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2014-04-29 17:17:03 -07:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-04-29 17:17:03 -07:00
|
|
|
}
|
|
|
|
|
2001-11-23 01:15:07 +00:00
|
|
|
#if ISC_FACILITY != LOG_DAEMON
|
|
|
|
destination.facility = ISC_FACILITY;
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG,
|
|
|
|
ISC_LOG_INFO, &destination, 0);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-11-23 01:15:07 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
#endif /* if ISC_FACILITY != LOG_DAEMON */
|
2001-11-23 01:15:07 +00:00
|
|
|
|
2000-04-28 18:53:45 +00:00
|
|
|
/*
|
|
|
|
* Set the initial debug level.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel);
|
2000-04-28 18:53:45 +00:00
|
|
|
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2000-04-28 18:53:45 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-05-02 18:45:08 +00:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
named_log_setsafechannels(isc_logconfig_t *lcfg)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
2005-05-20 01:19:43 +00:00
|
|
|
isc_logdestination_t destination;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
if (!named_g_logstderr) {
|
2000-05-02 18:45:08 +00:00
|
|
|
result = isc_log_createchannel(lcfg, "default_debug",
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_LOG_TONULL, ISC_LOG_DYNAMIC,
|
2000-12-11 19:24:30 +00:00
|
|
|
NULL, 0);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-05-02 18:45:08 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-05-02 18:45:08 +00:00
|
|
|
|
2001-06-14 14:14:17 +00:00
|
|
|
/*
|
|
|
|
* Setting the debug level to zero should get the output
|
|
|
|
* discarded a bit faster.
|
|
|
|
*/
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_setdebuglevel(named_g_lctx, 0);
|
2001-06-14 14:14:17 +00:00
|
|
|
} else {
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel);
|
2001-06-14 14:14:17 +00:00
|
|
|
}
|
2000-05-02 18:45:08 +00:00
|
|
|
|
2017-09-08 13:39:09 -07:00
|
|
|
if (named_g_logfile != NULL) {
|
2014-04-29 17:17:03 -07:00
|
|
|
destination.file.stream = NULL;
|
2017-09-08 13:39:09 -07:00
|
|
|
destination.file.name = named_g_logfile;
|
2014-04-29 17:17:03 -07:00
|
|
|
destination.file.versions = ISC_LOG_ROLLNEVER;
|
|
|
|
destination.file.maximum_size = 0;
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_log_createchannel(
|
|
|
|
lcfg, "default_logfile", ISC_LOG_TOFILE,
|
|
|
|
ISC_LOG_DYNAMIC, &destination,
|
|
|
|
ISC_LOG_PRINTTIME | ISC_LOG_PRINTCATEGORY |
|
|
|
|
ISC_LOG_PRINTLEVEL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2014-04-29 17:17:03 -07:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-04-29 17:17:03 -07:00
|
|
|
}
|
|
|
|
|
2005-05-20 01:19:43 +00:00
|
|
|
#if ISC_FACILITY != LOG_DAEMON
|
|
|
|
destination.facility = ISC_FACILITY;
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG,
|
|
|
|
ISC_LOG_INFO, &destination, 0);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2005-05-20 01:19:43 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
#endif /* if ISC_FACILITY != LOG_DAEMON */
|
2005-05-20 01:19:43 +00:00
|
|
|
|
2000-05-02 18:45:08 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2000-05-02 18:45:08 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-04-28 18:53:45 +00:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
named_log_setdefaultcategory(isc_logconfig_t *lcfg)
|
|
|
|
{
|
2014-04-29 17:17:03 -07:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
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);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-10-22 19:33:40 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-23 00:32:48 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
if (!named_g_logstderr) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (named_g_logfile != NULL) {
|
2014-04-29 17:17:03 -07:00
|
|
|
result = isc_log_usechannel(lcfg, "default_logfile",
|
|
|
|
ISC_LOGCATEGORY_DEFAULT,
|
|
|
|
NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (!named_g_nosyslog) {
|
2014-04-29 17:17:03 -07:00
|
|
|
result = isc_log_usechannel(lcfg, "default_syslog",
|
|
|
|
ISC_LOGCATEGORY_DEFAULT,
|
|
|
|
NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-04-29 17:17:03 -07:00
|
|
|
}
|
1999-10-22 19:33:40 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
1999-10-22 19:33:40 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2001-05-28 05:17:05 +00:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
named_log_setunmatchedcategory(isc_logconfig_t *lcfg)
|
|
|
|
{
|
2001-05-28 05:17:05 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_log_usechannel(lcfg, "null", NAMED_LOGCATEGORY_UNMATCHED,
|
|
|
|
NULL);
|
2001-05-28 05:17:05 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-10-22 19:33:40 +00:00
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
named_log_shutdown(void)
|
|
|
|
{
|
2017-09-08 13:39:09 -07:00
|
|
|
isc_log_destroy(&named_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
|
|
|
}
|