Commit 9e12c990 authored by James Brister's avatar James Brister
Browse files

Use logging system.

parent 0ef59eaa
......@@ -19,18 +19,18 @@
#include <isc/assertions.h>
#include <dns/log.h>
#include <dns/confacl.h>
#include <dns/confcommon.h>
static isc_result_t expand_acls(dns_c_acltable_t *table,
dns_c_ipmatchlist_t *list);
static isc_result_t acl_delete(dns_c_acl_t **aclptr);
static isc_result_t acl_delete(isc_log_t *lctx, dns_c_acl_t **aclptr);
isc_result_t
dns_c_acltable_new(isc_mem_t *mem, dns_c_acltable_t **newtable)
dns_c_acltable_new(isc_log_t *lctx,
isc_mem_t *mem, dns_c_acltable_t **newtable)
{
dns_c_acltable_t *table;
......@@ -39,7 +39,9 @@ dns_c_acltable_new(isc_mem_t *mem, dns_c_acltable_t **newtable)
table = isc_mem_get(mem, sizeof *table);
if (table == NULL) {
dns_c_error(0, "Out of memory");
isc_log_write(lctx, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, ISC_LOG_CRITICAL,
"Out of memory");
return (ISC_R_NOMEMORY);
}
......@@ -54,7 +56,8 @@ dns_c_acltable_new(isc_mem_t *mem, dns_c_acltable_t **newtable)
isc_result_t
dns_c_acltable_delete(dns_c_acltable_t **table)
dns_c_acltable_delete(isc_log_t *lctx,
dns_c_acltable_t **table)
{
dns_c_acltable_t *acltable;
......@@ -65,7 +68,7 @@ dns_c_acltable_delete(dns_c_acltable_t **table)
return (ISC_R_SUCCESS);
}
dns_c_acltable_clear(acltable);
dns_c_acltable_clear(lctx, acltable);
isc_mem_put(acltable->mem, acltable, sizeof *acltable);
......@@ -74,7 +77,8 @@ dns_c_acltable_delete(dns_c_acltable_t **table)
void
dns_c_acltable_print(FILE *fp, int indent, dns_c_acltable_t *table)
dns_c_acltable_print(isc_log_t *lctx,
FILE *fp, int indent, dns_c_acltable_t *table)
{
dns_c_acl_t *acl;
dns_c_acl_t *acltmp;
......@@ -90,8 +94,8 @@ dns_c_acltable_print(FILE *fp, int indent, dns_c_acltable_t *table)
while (acl != NULL) {
acltmp = ISC_LIST_NEXT(acl, next);
if (!acl->is_special) { /* don't print specials */
dns_c_acl_print(fp, indent, acl);
if (!acl->is_special) { /* don't print specials */
dns_c_acl_print(lctx, fp, indent, acl);
fprintf(fp, "\n");
}
......@@ -101,7 +105,7 @@ dns_c_acltable_print(FILE *fp, int indent, dns_c_acltable_t *table)
isc_result_t
dns_c_acltable_clear(dns_c_acltable_t *table)
dns_c_acltable_clear(isc_log_t *lctx, dns_c_acltable_t *table)
{
dns_c_acl_t *elem;
dns_c_acl_t *tmpelem;
......@@ -114,9 +118,12 @@ dns_c_acltable_clear(dns_c_acltable_t *table)
tmpelem = ISC_LIST_NEXT(elem, next);
ISC_LIST_UNLINK(table->acl_list, elem, next);
r = acl_delete(&elem);
r = acl_delete(lctx, &elem);
if (r != ISC_R_SUCCESS) {
dns_c_error(r, "Failed to delete acl element.\n");
isc_log_write(lctx, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG,
ISC_LOG_CRITICAL,
"Failed to delete acl element.\n");
return (r);
}
......@@ -128,9 +135,8 @@ dns_c_acltable_clear(dns_c_acltable_t *table)
isc_result_t
dns_c_acltable_getacl(dns_c_acltable_t *table,
const char *aclname,
dns_c_acl_t **retval)
dns_c_acltable_getacl(isc_log_t *lctx, dns_c_acltable_t *table,
const char *aclname, dns_c_acl_t **retval)
{
dns_c_acl_t *elem;
......@@ -139,6 +145,8 @@ dns_c_acltable_getacl(dns_c_acltable_t *table,
REQUIRE(aclname != NULL);
REQUIRE(strlen(aclname) > 0);
(void) lctx;
elem = ISC_LIST_HEAD(table->acl_list);
while (elem != NULL) {
if (strcmp(aclname, elem->name) == 0) {
......@@ -157,7 +165,8 @@ dns_c_acltable_getacl(dns_c_acltable_t *table,
isc_result_t
dns_c_acltable_removeacl(dns_c_acltable_t *table, const char *aclname)
dns_c_acltable_removeacl(isc_log_t *lctx,
dns_c_acltable_t *table, const char *aclname)
{
dns_c_acl_t *acl;
dns_c_acl_t *tmpacl;
......@@ -170,7 +179,7 @@ dns_c_acltable_removeacl(dns_c_acltable_t *table, const char *aclname)
tmpacl = ISC_LIST_NEXT(acl, next);
if (strcmp(aclname, acl->name) == 0) {
ISC_LIST_UNLINK(table->acl_list, acl, next);
acl_delete(&acl);
acl_delete(lctx, &acl);
return (ISC_R_SUCCESS);
}
......@@ -182,7 +191,8 @@ dns_c_acltable_removeacl(dns_c_acltable_t *table, const char *aclname)
isc_result_t
dns_c_acl_new(dns_c_acltable_t *table, const char *aclname,
dns_c_acl_new(isc_log_t *lctx,
dns_c_acltable_t *table, const char *aclname,
isc_boolean_t isspecial, dns_c_acl_t **newacl)
{
dns_c_acl_t *acl;
......@@ -194,6 +204,9 @@ dns_c_acl_new(dns_c_acltable_t *table, const char *aclname,
acl = isc_mem_get(table->mem, sizeof *acl);
if (acl == NULL) {
isc_log_write(lctx, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, ISC_LOG_CRITICAL,
"Not enough memory");
return (ISC_R_NOMEMORY);
}
......@@ -205,7 +218,9 @@ dns_c_acl_new(dns_c_acltable_t *table, const char *aclname,
acl->name = isc_mem_strdup(table->mem, aclname);
if (acl->name == NULL) {
isc_mem_put(table->mem, acl, sizeof *acl);
dns_c_error(0, "Not enough memory");
isc_log_write(lctx, DNS_LOGCATEGORY_CONFIG,
DNS_LOGMODULE_CONFIG, ISC_LOG_CRITICAL,
"Not enough memory");
return (ISC_R_NOMEMORY);
}
......@@ -218,9 +233,10 @@ dns_c_acl_new(dns_c_acltable_t *table, const char *aclname,
void
dns_c_acl_print(FILE *fp, int indent, dns_c_acl_t *acl)
dns_c_acl_print(isc_log_t *lctx,
FILE *fp, int indent, dns_c_acl_t *acl)
{
dns_c_printtabs(fp, indent);
dns_c_printtabs(lctx, fp, indent);
fprintf(fp, "acl ");
if (acl->name == NULL) {
fprintf(fp, "anon-acl-%p ", acl);
......@@ -229,18 +245,18 @@ dns_c_acl_print(FILE *fp, int indent, dns_c_acl_t *acl)
}
if (acl->ipml != NULL) {
dns_c_ipmatchlist_print(fp, indent + 1, acl->ipml);
dns_c_ipmatchlist_print(lctx, fp, indent + 1, acl->ipml);
} else {
fprintf(fp, "{\n");
dns_c_printtabs(fp, indent);
dns_c_printtabs(lctx, fp, indent);
fprintf(fp, "};");
}
}
isc_result_t
dns_c_acl_setipml(dns_c_acl_t *acl, dns_c_ipmatchlist_t *ipml,
isc_boolean_t deepcopy)
dns_c_acl_setipml(isc_log_t *lctx, dns_c_acl_t *acl,
dns_c_ipmatchlist_t *ipml, isc_boolean_t deepcopy)
{
isc_result_t res;
......@@ -248,11 +264,11 @@ dns_c_acl_setipml(dns_c_acl_t *acl, dns_c_ipmatchlist_t *ipml,
REQUIRE(ipml != NULL);
if (acl->ipml != NULL) {
dns_c_ipmatchlist_delete(&acl->ipml);
dns_c_ipmatchlist_delete(lctx, &acl->ipml);
}
if (deepcopy) {
res = dns_c_ipmatchlist_copy(acl->mytable->mem,
res = dns_c_ipmatchlist_copy(lctx, acl->mytable->mem,
&acl->ipml, ipml);
} else {
acl->ipml = ipml;
......@@ -264,8 +280,8 @@ dns_c_acl_setipml(dns_c_acl_t *acl, dns_c_ipmatchlist_t *ipml,
isc_result_t
dns_c_acl_getipmlexpanded(isc_mem_t *mem, dns_c_acl_t *acl,
dns_c_ipmatchlist_t **retval)
dns_c_acl_getipmlexpanded(isc_log_t *lctx, isc_mem_t *mem, dns_c_acl_t *acl,
dns_c_ipmatchlist_t **retval)
{
dns_c_ipmatchlist_t *newlist;
isc_result_t r;
......@@ -274,12 +290,12 @@ dns_c_acl_getipmlexpanded(isc_mem_t *mem, dns_c_acl_t *acl,
newlist = NULL;
r = ISC_R_SUCCESS;
} else {
r = dns_c_ipmatchlist_copy(mem, &newlist, acl->ipml);
r = dns_c_ipmatchlist_copy(lctx, mem, &newlist, acl->ipml);
if (r != ISC_R_SUCCESS) {
return (r);
}
r = expand_acls(acl->mytable, newlist);
r = dns_c_acl_expandacls(lctx, acl->mytable, newlist);
}
*retval = newlist;
......@@ -288,8 +304,9 @@ dns_c_acl_getipmlexpanded(isc_mem_t *mem, dns_c_acl_t *acl,
}
static isc_result_t
expand_acls(dns_c_acltable_t *table, dns_c_ipmatchlist_t *list)
isc_result_t
dns_c_acl_expandacls(isc_log_t *lctx, dns_c_acltable_t *table,
dns_c_ipmatchlist_t *list)
{
dns_c_ipmatchelement_t *elem;
dns_c_ipmatchelement_t *tmpelem;
......@@ -305,20 +322,25 @@ expand_acls(dns_c_acltable_t *table, dns_c_ipmatchlist_t *list)
while (elem != NULL) {
switch (elem->type) {
case dns_c_ipmatch_indirect:
expand_acls(table, elem->u.indirect.list);
dns_c_acl_expandacls(lctx, table,
elem->u.indirect.list);
break;
case dns_c_ipmatch_acl:
r = dns_c_acltable_getacl(table,
elem->u.aclname, &acl);
r = dns_c_acltable_getacl(lctx, table,
elem->u.aclname, &acl);
if (r != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
}
if (acl->ipml != NULL) {
isneg = dns_c_ipmatchelement_isneg(elem);
dns_c_ipmatchlist_append(list,
acl->ipml, isneg);
isneg = dns_c_ipmatchelement_isneg(lctx, elem);
/* XXX I this should be inserted in place and
* not appended
*/
dns_c_ipmatchlist_append(lctx, list,
acl->ipml, isneg);
}
default:
......@@ -342,7 +364,7 @@ expand_acls(dns_c_acltable_t *table, dns_c_ipmatchlist_t *list)
static isc_result_t
acl_delete(dns_c_acl_t **aclptr)
acl_delete(isc_log_t *lctx, dns_c_acl_t **aclptr)
{
dns_c_acl_t *acl;
isc_result_t res;
......@@ -353,7 +375,7 @@ acl_delete(dns_c_acl_t **aclptr)
}
isc_mem_free(acl->mytable->mem, acl->name);
res = dns_c_ipmatchlist_delete(&acl->ipml);
res = dns_c_ipmatchlist_delete(lctx, &acl->ipml);
isc_mem_put(acl->mytable->mem, acl, sizeof *acl);
return (res);
......
......@@ -129,7 +129,7 @@ static struct dns_c_pvt_cntable {
{ dns_c_cat_insist, "insist" },
{ dns_c_cat_maint, "maintenance" },
{ dns_c_cat_load, "load" },
{ dns_c_cat_respchecks, "response-checks" },
{ dns_c_cat_respchecks, "response-checks" },
{ dns_c_cat_control, "control" },
{ 0, NULL }
};
......@@ -149,19 +149,22 @@ FILE *debug_mem_print_stream;
*** FUNCTIONS
***/
#if 0 /* XXXJAB delete this code */
static void default_cfgerror(isc_result_t result, const char *fmt,
va_list args);
#endif
void
dns_c_printinunits(FILE *fp, isc_uint32_t val)
dns_c_printinunits(isc_log_t *lctx, FILE *fp, isc_uint32_t val)
{
isc_uint32_t one_gig = (1024 * 1024 * 1024);
isc_uint32_t one_meg = (1024 * 1024);
isc_uint32_t one_k = 1024;
(void) lctx;
if (val == DNS_C_SIZE_SPEC_DEFAULT)
fprintf(fp, "default");
else if ((val % one_gig) == 0)
......@@ -178,11 +181,13 @@ dns_c_printinunits(FILE *fp, isc_uint32_t val)
void
dns_c_dataclass_tostream(FILE *fp, dns_rdataclass_t rclass)
dns_c_dataclass_tostream(isc_log_t *lctx, FILE *fp, dns_rdataclass_t rclass)
{
char buffer[64];
isc_buffer_t sourceb;
(void) lctx;
isc_buffer_init(&sourceb, buffer, sizeof buffer,
ISC_BUFFERTYPE_GENERIC);
......@@ -197,11 +202,13 @@ dns_c_dataclass_tostream(FILE *fp, dns_rdataclass_t rclass)
void
dns_c_datatype_tostream(FILE *fp, dns_rdatatype_t rtype)
dns_c_datatype_tostream(isc_log_t *lctx, FILE *fp, dns_rdatatype_t rtype)
{
char buffer[64];
isc_buffer_t sourceb;
(void) lctx;
isc_buffer_init(&sourceb, buffer, sizeof buffer,
ISC_BUFFERTYPE_GENERIC);
......@@ -216,8 +223,11 @@ dns_c_datatype_tostream(FILE *fp, dns_rdatatype_t rtype)
void
dns_c_printtabs(FILE *fp, int count)
dns_c_printtabs(isc_log_t *lctx, FILE *fp, int count)
{
(void) lctx;
while (count > 0) {
fputc('\t', fp);
count--;
......@@ -227,10 +237,12 @@ dns_c_printtabs(FILE *fp, int count)
isc_result_t
dns_c_string2ordering(char *name, dns_c_ordering_t *ordering)
dns_c_string2ordering(isc_log_t *lctx, char *name, dns_c_ordering_t *ordering)
{
int i;
isc_result_t rval = ISC_R_FAILURE;
(void) lctx;
for (i = 0 ; ordering_nametable[i].strval != NULL ; i++) {
if (strcmp(ordering_nametable[i].strval, name) == 0) {
......@@ -245,11 +257,14 @@ dns_c_string2ordering(char *name, dns_c_ordering_t *ordering)
const char *
dns_c_ordering2string(dns_c_ordering_t ordering, isc_boolean_t printable)
dns_c_ordering2string(isc_log_t *lctx, dns_c_ordering_t ordering,
isc_boolean_t printable)
{
int i;
const char *rval = NULL;
(void) lctx;
for (i = 0 ; ordering_nametable[i].strval != NULL ; i++) {
if (ordering_nametable[i].val == ordering) {
rval = ordering_nametable[i].strval;
......@@ -262,11 +277,13 @@ dns_c_ordering2string(dns_c_ordering_t ordering, isc_boolean_t printable)
const char *
dns_c_logseverity2string(dns_c_logseverity_t severity,
dns_c_logseverity2string(isc_log_t *lctx, dns_c_logseverity_t severity,
isc_boolean_t printable)
{
int i;
const char *rval = NULL;
(void) lctx;
for (i = 0 ; log_severity_nametable[i].strval != NULL ; i++) {
if (log_severity_nametable[i].val == severity) {
......@@ -280,11 +297,14 @@ dns_c_logseverity2string(dns_c_logseverity_t severity,
isc_result_t
dns_c_string2logseverity(const char *string, dns_c_logseverity_t *result)
dns_c_string2logseverity(isc_log_t *lctx, const char *string,
dns_c_logseverity_t *result)
{
int i;
isc_result_t rval = ISC_R_FAILURE;
(void) lctx;
REQUIRE(result != NULL);
for (i = 0 ; log_severity_nametable[i].strval != NULL ; i++) {
......@@ -300,11 +320,14 @@ dns_c_string2logseverity(const char *string, dns_c_logseverity_t *result)
const char *
dns_c_category2string(dns_c_category_t cat, isc_boolean_t printable)
dns_c_category2string(isc_log_t *lctx, dns_c_category_t cat,
isc_boolean_t printable)
{
int i;
const char *rval = NULL;
(void) lctx;
for (i = 0 ; category_nametable[i].strval != NULL ; i++) {
if (category_nametable[i].val == cat) {
rval = category_nametable[i].strval;
......@@ -317,11 +340,14 @@ dns_c_category2string(dns_c_category_t cat, isc_boolean_t printable)
isc_result_t
dns_c_string2category(const char *string, dns_c_category_t *category)
dns_c_string2category(isc_log_t *lctx, const char *string,
dns_c_category_t *category)
{
int i;
isc_result_t rval = ISC_R_FAILURE;
(void) lctx;
REQUIRE (category != NULL);
for (i = 0 ; category_nametable[i].strval != NULL ; i++) {
......@@ -338,11 +364,13 @@ dns_c_string2category(const char *string, dns_c_category_t *category)
const char *
dns_c_facility2string(int facility, isc_boolean_t printable)
dns_c_facility2string(isc_log_t *lctx, int facility, isc_boolean_t printable)
{
int i;
const char *rval = NULL;
(void) lctx;
for (i = 0 ; syslog_facil_nametable[i].strval != NULL ; i++) {
if (syslog_facil_nametable[i].val == facility) {
rval = syslog_facil_nametable[i].strval;
......@@ -355,10 +383,12 @@ dns_c_facility2string(int facility, isc_boolean_t printable)
isc_result_t
dns_c_string2facility(const char *string, int *result)
dns_c_string2facility(isc_log_t *lctx, const char *string, int *result)
{
int i;
isc_result_t rval = ISC_R_FAILURE;
(void) lctx;
for (i = 0 ; syslog_facil_nametable[i].strval != NULL ; i++) {
if (strcmp(syslog_facil_nametable[i].strval, string) == 0) {
......@@ -373,10 +403,12 @@ dns_c_string2facility(const char *string, int *result)
const char *
dns_c_transformat2string(dns_transfer_format_t tformat,
dns_c_transformat2string(isc_log_t *lctx, dns_transfer_format_t tformat,
isc_boolean_t printable)
{
const char *rval = NULL;
(void) lctx;
switch (tformat) {
case dns_one_answer:
......@@ -395,9 +427,12 @@ dns_c_transformat2string(dns_transfer_format_t tformat,
const char *
dns_c_transport2string(dns_c_trans_t transport, isc_boolean_t printable)
dns_c_transport2string(isc_log_t *lctx, dns_c_trans_t transport,
isc_boolean_t printable)
{
const char *rval = NULL;
(void) lctx;
switch (transport) {
case dns_trans_primary:
......@@ -418,9 +453,12 @@ dns_c_transport2string(dns_c_trans_t transport, isc_boolean_t printable)
const char *
dns_c_nameseverity2string(dns_c_severity_t severity, isc_boolean_t printable)
dns_c_nameseverity2string(isc_log_t *lctx, dns_c_severity_t severity,
isc_boolean_t printable)
{
const char *rval = NULL;
(void) lctx;
switch (severity) {
case dns_c_severity_ignore:
......@@ -441,9 +479,12 @@ dns_c_nameseverity2string(dns_c_severity_t severity, isc_boolean_t printable)
const char *
dns_c_forward2string(dns_c_forw_t forw, isc_boolean_t printable)
dns_c_forward2string(isc_log_t *lctx, dns_c_forw_t forw,
isc_boolean_t printable)
{
const char *rval = NULL;
(void) lctx;
switch (forw) {
case dns_c_forw_only:
......@@ -469,9 +510,11 @@ dns_c_forward2string(dns_c_forw_t forw, isc_boolean_t printable)
int
dns_c_isanyaddr(isc_sockaddr_t *inaddr)
dns_c_isanyaddr(isc_log_t *lctx, isc_sockaddr_t *inaddr)
{
int result = 0;
(void) lctx;
if (inaddr->type.sa.sa_family == AF_INET) {
if (inaddr->type.sin.sin_addr.s_addr == htonl(INADDR_ANY)) {
......@@ -490,14 +533,14 @@ dns_c_isanyaddr(isc_sockaddr_t *inaddr)
void
dns_c_print_ipaddr(FILE *fp, isc_sockaddr_t *inaddr)
dns_c_print_ipaddr(isc_log_t *lctx, FILE *fp, isc_sockaddr_t *inaddr)
{
const char *p;
char tmpaddrstr[64];
int family = inaddr->type.sa.sa_family;
void *addr;
if (dns_c_isanyaddr(inaddr)) {
if (dns_c_isanyaddr(lctx, inaddr)) {
if (family == AF_INET) {
fprintf(fp, "*");
} else {
......@@ -505,8 +548,8 @@ dns_c_print_ipaddr(FILE *fp, isc_sockaddr_t *inaddr)
}
} else {
addr = (family == AF_INET ?
&inaddr->type.sin.sin_addr :
&inaddr->type.sin6.sin6_addr);
(void *)&inaddr->type.sin.sin_addr :
(void *)&inaddr->type.sin6.sin6_addr);
p = inet_ntop(family, addr, tmpaddrstr, sizeof tmpaddrstr);
if (p == NULL) {
......@@ -519,9 +562,11 @@ dns_c_print_ipaddr(FILE *fp, isc_sockaddr_t *inaddr)
isc_boolean_t
dns_c_need_quote(const char *string)
dns_c_need_quote(isc_log_t *lctx, const char *string)
{
isc_boolean_t rval = ISC_FALSE;
(void) lctx;
while (string != NULL && *string != '\0') {
if (!(isalnum(*string) || *string == '_')) {
......@@ -537,7 +582,7 @@ dns_c_need_quote(const char *string)
#if 0 /* XXXJAB remove this code */
/* ************************************************** */
/* ******** CONFIG MODULE ERROR PRINTING ************ */
......@@ -579,6 +624,7 @@ default_cfgerror(isc_result_t result, const char *fmt, va_list args)
fputc('\n', stderr);
}
#endif
/* ************************************************** */
/* ********** MEMORY DEBUGGING ROUTINES. ************ */
......
......@@ -27,7 +27,8 @@
isc_result_t
dns_c_ctrllist_delete(dns_c_ctrllist_t **list)
dns_c_ctrllist_delete(isc_log_t *lctx,
dns_c_ctrllist_t **list)
{
dns_c_ctrl_t *ctrl;
dns_c_ctrl_t *tmpctrl;
......@@ -42,7 +43,7 @@ dns_c_ctrllist_delete(dns_c_ctrllist_t **list)
ctrl = ISC_LIST_HEAD(clist->elements);
while (ctrl != NULL) {
tmpctrl = ISC_LIST_NEXT(ctrl, next);
dns_c_ctrl_delete(&ctrl);
dns_c_ctrl_delete(lctx, &ctrl);
ctrl = tmpctrl;
}
......@@ -55,9 +56,9 @@ dns_c_ctrllist_delete(dns_c_ctrllist_t **list)