mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-10 23:00:00 -04:00
'logging' statement partially wired up
This commit is contained in:
parent
fd088dc8c8
commit
353dcaf1cc
5 changed files with 262 additions and 3 deletions
|
|
@ -39,13 +39,13 @@ SUBDIRS = unix
|
|||
TARGETS = named
|
||||
|
||||
OBJS = client.@O@ interfacemgr.@O@ listenlist.@O@ \
|
||||
log.@O@ main.@O@ notify.@O@ omapi.@O@ \
|
||||
log.@O@ logconf.@O@ main.@O@ notify.@O@ omapi.@O@ \
|
||||
query.@O@ server.@O@ update.@O@ xfrout.@O@
|
||||
|
||||
UOBJS = unix/os.@O@
|
||||
|
||||
SRCS = client.c interfacemgr.c listenlist.c \
|
||||
log.c main.c notify.c omapi.c \
|
||||
log.c logconf.c main.c notify.c omapi.c \
|
||||
query.c server.c update.c xfrout.c
|
||||
|
||||
@BIND9_MAKE_RULES@
|
||||
|
|
|
|||
32
bin/named/include/named/logconf.h
Normal file
32
bin/named/include/named/logconf.h
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef NS_LOGCONF_H
|
||||
#define NS_LOGCONF_H 1
|
||||
|
||||
#include <isc/log.h>
|
||||
|
||||
#include <dns/conflog.h>
|
||||
|
||||
isc_result_t
|
||||
ns_logconfig_fromconf(isc_log_t *lctx, dns_c_logginglist_t *clog, isc_logconfig_t **lctxp);
|
||||
/*
|
||||
* Construct a new isc_logconfig_t object for use with the logging context 'lctx',
|
||||
* configuring it according to the named.conf configuration data in 'clog'.
|
||||
*/
|
||||
|
||||
#endif /* NS_LOGCONF_H */
|
||||
198
bin/named/logconf.c
Normal file
198
bin/named/logconf.c
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
/*
|
||||
* 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 <isc/result.h>
|
||||
|
||||
#include <named/globals.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
|
||||
category_fromconf(dns_c_logcat_t *ccat, isc_logconfig_t *lctx)
|
||||
{
|
||||
isc_result_t result;
|
||||
unsigned int i;
|
||||
isc_logcategory_t *cat;
|
||||
|
||||
for (i = 0; i < ccat->nextcname; i++) {
|
||||
char *channelname = ccat->channel_names[i];
|
||||
|
||||
/*
|
||||
* XXX This needs to be completely rewritten.
|
||||
* The list of category names in lib/dns/confcommon.h is
|
||||
* derived from BIND 8 and not directly applicable to
|
||||
* BIND 9, and maintaining such a list in multiple places
|
||||
* is a maintenance nightmare in any case. Instead,
|
||||
* ccat->category should be character string,
|
||||
* and we should look up the category name at runtime.
|
||||
* Using an unknown category in named.conf
|
||||
* should cause a warning, not a syntax error. Also,
|
||||
* this whole function and the named.conf "category" syntax
|
||||
* needs rethinking to integrate the "module" concept.
|
||||
*/
|
||||
|
||||
switch (ccat->category) {
|
||||
case dns_c_cat_default:
|
||||
/*
|
||||
* For now, the default category is the only
|
||||
* one that works
|
||||
*/
|
||||
cat = ISC_LOGCATEGORY_DEFAULT; break;
|
||||
default:
|
||||
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
||||
NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
|
||||
"ignoring unsupported logging category");
|
||||
continue;
|
||||
}
|
||||
|
||||
result = isc_log_usechannel(lctx, channelname, cat,
|
||||
NULL); /* XXX module */
|
||||
if (result != ISC_R_SUCCESS)
|
||||
return (result);
|
||||
}
|
||||
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
|
||||
channel_fromconf(dns_c_logchan_t *cchan, isc_logconfig_t *lctx)
|
||||
{
|
||||
isc_result_t result;
|
||||
isc_logdestination_t dest;
|
||||
unsigned int type;
|
||||
int flags = 0;
|
||||
int level;
|
||||
|
||||
switch (cchan->ctype) {
|
||||
case dns_c_logchan_file:
|
||||
type = ISC_LOG_TOFILE;
|
||||
{
|
||||
const char *path = NULL;
|
||||
int versions = ISC_LOG_ROLLNEVER;
|
||||
isc_uint32_t size = 0;
|
||||
(void) dns_c_logchan_getpath(cchan, &path);
|
||||
if (path == NULL) {
|
||||
isc_log_write(ns_g_lctx,
|
||||
NS_LOGCATEGORY_GENERAL,
|
||||
NS_LOGMODULE_SERVER,
|
||||
ISC_LOG_ERROR,
|
||||
"file log channel has "
|
||||
"no file name");
|
||||
return (ISC_R_UNEXPECTED);
|
||||
}
|
||||
(void) dns_c_logchan_getversions(cchan, &versions);
|
||||
(void) dns_c_logchan_getsize(cchan, &size);
|
||||
dest.file.stream = NULL;
|
||||
dest.file.name = cchan->u.filec.path;
|
||||
dest.file.versions = versions;
|
||||
dest.file.maximum_size = size;
|
||||
}
|
||||
break;
|
||||
|
||||
case dns_c_logchan_syslog:
|
||||
type = ISC_LOG_TOSYSLOG;
|
||||
{
|
||||
int facility = LOG_DAEMON;
|
||||
(void) dns_c_logchan_getfacility(cchan, &facility);
|
||||
dest.facility = facility;
|
||||
}
|
||||
break;
|
||||
|
||||
case dns_c_logchan_null:
|
||||
type = ISC_LOG_TONULL;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Munge flags.
|
||||
*/
|
||||
{
|
||||
isc_boolean_t printcat = ISC_FALSE;
|
||||
isc_boolean_t printsev = ISC_FALSE;
|
||||
isc_boolean_t printtime = ISC_FALSE;
|
||||
|
||||
(void) dns_c_logchan_getprintcat(cchan, &printcat);
|
||||
(void) dns_c_logchan_getprintsev(cchan, &printsev);
|
||||
(void) dns_c_logchan_getprinttime(cchan, &printtime);
|
||||
|
||||
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;
|
||||
(void) dns_c_logchan_getdebuglevel(cchan, &level);
|
||||
|
||||
result = isc_log_createchannel(lctx, cchan->name,
|
||||
type, level, &dest, flags);
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
ns_logconfig_fromconf(isc_log_t *lctx, dns_c_logginglist_t *clog,
|
||||
isc_logconfig_t **lcctxp)
|
||||
{
|
||||
isc_result_t result;
|
||||
dns_c_logchan_t *cchan;
|
||||
dns_c_logcat_t *ccat;
|
||||
isc_logconfig_t *lcctx = NULL;
|
||||
|
||||
CHECK(isc_logconfig_create(lctx, &lcctx));
|
||||
|
||||
for (cchan = ISC_LIST_HEAD(clog->channels);
|
||||
cchan != NULL;
|
||||
cchan = ISC_LIST_NEXT(cchan, next))
|
||||
{
|
||||
CHECK(channel_fromconf(cchan, lcctx));
|
||||
}
|
||||
|
||||
for (ccat = ISC_LIST_HEAD(clog->categories);
|
||||
ccat != NULL;
|
||||
ccat = ISC_LIST_NEXT(ccat, next))
|
||||
{
|
||||
CHECK(category_fromconf(ccat, lcctx));
|
||||
}
|
||||
|
||||
*lcctxp = lcctx;
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
cleanup:
|
||||
if (lcctx != NULL)
|
||||
isc_logconfig_destroy(&lcctx);
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -68,6 +68,7 @@
|
|||
#include <named/interfacemgr.h>
|
||||
#include <named/listenlist.h>
|
||||
#include <named/log.h>
|
||||
#include <named/logconf.h>
|
||||
#include <named/os.h>
|
||||
#include <named/server.h>
|
||||
#include <named/types.h>
|
||||
|
|
@ -925,6 +926,33 @@ load_configuration(const char *filename, ns_server_t *server,
|
|||
server->tkeyctx = t;
|
||||
}
|
||||
|
||||
/*
|
||||
* Configure the logging system.
|
||||
*/
|
||||
{
|
||||
dns_c_logginglist_t *clog = NULL;
|
||||
isc_logconfig_t *logc = NULL;
|
||||
|
||||
/*
|
||||
* dns_c_ctx_getlogging() succeeds even if there
|
||||
* is no logging statement in named.conf;
|
||||
* in that case it returns the default configuration
|
||||
* that was set up in logging_init(). Therefore, we
|
||||
* do not need to provide any defaults of our own here.
|
||||
*/
|
||||
CHECKM(dns_c_ctx_getlogging(configctx, &clog),
|
||||
"getting logging configuration");
|
||||
|
||||
CHECKM(ns_logconfig_fromconf(ns_g_lctx, clog, &logc),
|
||||
"setting up logging configuration");
|
||||
|
||||
result = isc_logconfig_use(ns_g_lctx, logc);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_logconfig_destroy(&logc);
|
||||
CHECKM(result, "intalling logging configuration");
|
||||
}
|
||||
}
|
||||
|
||||
if (first_time)
|
||||
ns_os_changeuser(ns_g_username);
|
||||
|
||||
|
|
@ -1273,4 +1301,3 @@ ns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx,
|
|||
*target = delt;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
./bin/named/include/named/interfacemgr.h C 1999,2000
|
||||
./bin/named/include/named/listenlist.h C 2000
|
||||
./bin/named/include/named/log.h C 1999,2000
|
||||
./bin/named/include/named/logconf.h C 1999,2000
|
||||
./bin/named/include/named/main.h C 1999,2000
|
||||
./bin/named/include/named/notify.h C 1999,2000
|
||||
./bin/named/include/named/omapi.h C 2000
|
||||
|
|
@ -34,6 +35,7 @@
|
|||
./bin/named/interfacemgr.c C 1999,2000
|
||||
./bin/named/listenlist.c C 2000
|
||||
./bin/named/log.c C 1999,2000
|
||||
./bin/named/logconf.c C 1999,2000
|
||||
./bin/named/main.c C 1999,2000
|
||||
./bin/named/named.conf.test X 1999,2000
|
||||
./bin/named/notify.c C 1999,2000
|
||||
|
|
|
|||
Loading…
Reference in a new issue