2000-02-28 18:38:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1999, 2000 Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <named/log.h>
|
|
|
|
#include <named/logconf.h>
|
|
|
|
|
|
|
|
#define CHECK(op) \
|
|
|
|
do { result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) goto cleanup; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a logging category according to the named.conf data
|
|
|
|
* in 'ccat' and add it to 'lctx'.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
2000-04-25 23:44:37 +00:00
|
|
|
category_fromconf(dns_c_logcat_t *ccat, isc_logconfig_t *lctx) {
|
2000-02-28 18:38:44 +00:00
|
|
|
isc_result_t result;
|
|
|
|
unsigned int i;
|
2000-03-04 16:41:48 +00:00
|
|
|
isc_logcategory_t *category;
|
|
|
|
isc_logmodule_t *module;
|
2000-02-28 18:38:44 +00:00
|
|
|
|
2000-03-04 16:41:48 +00:00
|
|
|
category = isc_log_categorybyname(ns_g_lctx, ccat->catname);
|
2000-03-04 01:08:05 +00:00
|
|
|
#ifdef notyet
|
2000-03-04 16:41:48 +00:00
|
|
|
module = isc_log_modulebyname(ns_g_lctx, ccat->modname);
|
2000-03-04 01:08:05 +00:00
|
|
|
#else
|
2000-03-04 16:41:48 +00:00
|
|
|
module = NULL;
|
2000-03-04 01:08:05 +00:00
|
|
|
#endif
|
2000-03-04 16:41:48 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ccat->nextcname; i++) {
|
|
|
|
char *channelname = ccat->channel_names[i];
|
|
|
|
|
2000-03-04 01:08:05 +00:00
|
|
|
result = isc_log_usechannel(lctx, channelname, category,
|
|
|
|
module);
|
2000-03-01 20:40:33 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_log_write(ns_g_lctx, DNS_LOGCATEGORY_CONFIG,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
2000-03-23 00:51:29 +00:00
|
|
|
"logging channel '%s': %s", channelname,
|
2000-03-01 20:40:33 +00:00
|
|
|
isc_result_totext(result));
|
2000-02-28 18:38:44 +00:00
|
|
|
return (result);
|
2000-03-01 20:40:33 +00:00
|
|
|
}
|
2000-02-28 18:38:44 +00:00
|
|
|
}
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a logging channel according to the named.conf data
|
|
|
|
* in 'cchan' and add it to 'lctx'.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
2000-04-25 23:44:37 +00:00
|
|
|
channel_fromconf(dns_c_logchan_t *cchan, isc_logconfig_t *lctx) {
|
2000-02-28 18:38:44 +00:00
|
|
|
isc_result_t result;
|
|
|
|
isc_logdestination_t dest;
|
|
|
|
unsigned int type;
|
|
|
|
int flags = 0;
|
|
|
|
int level;
|
|
|
|
|
2000-02-28 19:18:13 +00:00
|
|
|
type = ISC_LOG_TONULL;
|
2000-02-28 18:38:44 +00:00
|
|
|
switch (cchan->ctype) {
|
|
|
|
case dns_c_logchan_file:
|
|
|
|
type = ISC_LOG_TOFILE;
|
|
|
|
{
|
|
|
|
const char *path = NULL;
|
2000-03-23 22:51:53 +00:00
|
|
|
isc_uint32_t versions = ISC_LOG_ROLLNEVER;
|
2000-02-28 18:38:44 +00:00
|
|
|
isc_uint32_t size = 0;
|
2000-04-25 23:44:37 +00:00
|
|
|
(void)dns_c_logchan_getpath(cchan, &path);
|
2000-02-28 18:38:44 +00:00
|
|
|
if (path == NULL) {
|
|
|
|
isc_log_write(ns_g_lctx,
|
2000-03-01 20:40:33 +00:00
|
|
|
DNS_LOGCATEGORY_CONFIG,
|
2000-02-28 18:38:44 +00:00
|
|
|
NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_ERROR,
|
|
|
|
"file log channel has "
|
|
|
|
"no file name");
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
2000-04-25 23:44:37 +00:00
|
|
|
(void)dns_c_logchan_getversions(cchan, &versions);
|
|
|
|
(void)dns_c_logchan_getsize(cchan, &size);
|
2000-02-28 18:38:44 +00:00
|
|
|
dest.file.stream = NULL;
|
|
|
|
dest.file.name = cchan->u.filec.path;
|
2000-03-23 22:51:53 +00:00
|
|
|
dest.file.versions = (int)versions;
|
2000-02-28 18:38:44 +00:00
|
|
|
dest.file.maximum_size = size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_c_logchan_syslog:
|
|
|
|
type = ISC_LOG_TOSYSLOG;
|
|
|
|
{
|
|
|
|
int facility = LOG_DAEMON;
|
2000-04-25 23:44:37 +00:00
|
|
|
(void)dns_c_logchan_getfacility(cchan, &facility);
|
2000-02-28 18:38:44 +00:00
|
|
|
dest.facility = facility;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_c_logchan_null:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Munge flags.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
isc_boolean_t printcat = ISC_FALSE;
|
|
|
|
isc_boolean_t printsev = ISC_FALSE;
|
|
|
|
isc_boolean_t printtime = ISC_FALSE;
|
|
|
|
|
2000-04-25 23:44:37 +00:00
|
|
|
(void)dns_c_logchan_getprintcat(cchan, &printcat);
|
|
|
|
(void)dns_c_logchan_getprintsev(cchan, &printsev);
|
|
|
|
(void)dns_c_logchan_getprinttime(cchan, &printtime);
|
2000-02-28 18:38:44 +00:00
|
|
|
|
|
|
|
if (printcat)
|
|
|
|
flags |= ISC_LOG_PRINTCATEGORY;
|
|
|
|
if (printtime)
|
|
|
|
flags |= ISC_LOG_PRINTTIME;
|
|
|
|
if (printsev)
|
|
|
|
flags |= ISC_LOG_PRINTLEVEL;
|
|
|
|
/* XXX ISC_LOG_PRINTMODULE */
|
|
|
|
}
|
|
|
|
|
|
|
|
level = ISC_LOG_INFO;
|
2000-04-25 23:44:37 +00:00
|
|
|
(void)dns_c_logchan_getdebuglevel(cchan, &level);
|
2000-02-28 18:38:44 +00:00
|
|
|
|
|
|
|
result = isc_log_createchannel(lctx, cchan->name,
|
|
|
|
type, level, &dest, flags);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2000-04-25 23:44:37 +00:00
|
|
|
ns_log_configure(isc_logconfig_t *lcctx, dns_c_logginglist_t *clog) {
|
2000-02-28 18:38:44 +00:00
|
|
|
isc_result_t result;
|
|
|
|
dns_c_logchan_t *cchan;
|
|
|
|
dns_c_logcat_t *ccat;
|
2000-03-04 16:41:48 +00:00
|
|
|
isc_boolean_t default_set = ISC_FALSE;
|
2000-02-28 18:38:44 +00:00
|
|
|
|
2000-04-28 18:53:45 +00:00
|
|
|
CHECK(ns_log_setdefaultchannels(lcctx));
|
|
|
|
|
2000-02-28 18:38:44 +00:00
|
|
|
for (cchan = ISC_LIST_HEAD(clog->channels);
|
|
|
|
cchan != NULL;
|
2000-03-04 16:41:48 +00:00
|
|
|
cchan = ISC_LIST_NEXT(cchan, next)) {
|
2000-02-28 18:38:44 +00:00
|
|
|
CHECK(channel_fromconf(cchan, lcctx));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ccat = ISC_LIST_HEAD(clog->categories);
|
|
|
|
ccat != NULL;
|
2000-03-04 16:41:48 +00:00
|
|
|
ccat = ISC_LIST_NEXT(ccat, next)) {
|
2000-02-28 18:38:44 +00:00
|
|
|
CHECK(category_fromconf(ccat, lcctx));
|
2000-03-04 16:41:48 +00:00
|
|
|
if (! default_set)
|
|
|
|
default_set =
|
|
|
|
ISC_TF(strcmp(ccat->catname, "default") == 0);
|
2000-02-28 18:38:44 +00:00
|
|
|
}
|
|
|
|
|
2000-03-04 16:41:48 +00:00
|
|
|
if (! default_set)
|
2000-04-28 18:53:45 +00:00
|
|
|
CHECK(ns_log_setdefaultcategory(lcctx));
|
2000-03-04 16:41:48 +00:00
|
|
|
|
2000-02-28 18:38:44 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (lcctx != NULL)
|
|
|
|
isc_logconfig_destroy(&lcctx);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|