2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

added support for a search{} clause in the lwres{} statement

This commit is contained in:
Andreas Gustafsson
2000-10-19 01:26:39 +00:00
parent 4913f156c4
commit 5a11763ab2
5 changed files with 261 additions and 98 deletions

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: confctx.c,v 1.92 2000/10/12 00:38:29 bwelling Exp $ */
/* $Id: confctx.c,v 1.93 2000/10/19 01:26:34 gson Exp $ */
#include <config.h>
@@ -2544,7 +2544,7 @@ dns_c_ctx_getlwres(dns_c_ctx_t *cfg,
isc_result_t
dns_c_ctx_setlwres(dns_c_ctx_t *cfg,
dns_c_lwreslist_t *newval, isc_boolean_t deepcopy)
dns_c_lwreslist_t *newval)
{
isc_result_t res;
@@ -2557,9 +2557,6 @@ dns_c_ctx_setlwres(dns_c_ctx_t *cfg,
if (newval == NULL) {
cfg->lwres = NULL;
res = ISC_R_SUCCESS;
} else if (deepcopy) {
res = dns_c_lwreslist_copy(cfg->mem,
&cfg->lwres, newval);
} else {
cfg->lwres = newval;
res = ISC_R_SUCCESS;

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: conflwres.c,v 1.3 2000/10/10 22:04:29 bwelling Exp $ */
/* $Id: conflwres.c,v 1.4 2000/10/19 01:26:36 gson Exp $ */
#include <config.h>
@@ -28,6 +28,9 @@
#include <dns/confcommon.h>
#include <dns/rdataclass.h>
static isc_result_t
search_delete(dns_c_search_t **search);
isc_result_t
dns_c_lwreslist_new(isc_mem_t *mem, dns_c_lwreslist_t **list) {
dns_c_lwreslist_t *newlist;
@@ -81,56 +84,12 @@ dns_c_lwreslist_delete(dns_c_lwreslist_t **list)
isc_result_t
dns_c_lwreslist_append(dns_c_lwreslist_t *list,
dns_c_lwres_t *lwres, isc_boolean_t copy)
dns_c_lwres_t *lwres)
{
dns_c_lwres_t *newe;
isc_result_t res;
REQUIRE(DNS_C_LWLIST_VALID(list));
REQUIRE(DNS_C_LWRES_VALID(lwres));
if (copy) {
res = dns_c_lwres_copy(list->mem, &newe, lwres);
if (res != ISC_R_SUCCESS) {
return (res);
}
} else {
newe = lwres;
}
ISC_LIST_APPEND(list->lwreslist, newe, next);
return (ISC_R_SUCCESS);
}
isc_result_t
dns_c_lwreslist_copy(isc_mem_t *mem, dns_c_lwreslist_t **dest,
dns_c_lwreslist_t *src)
{
dns_c_lwreslist_t *newlist;
dns_c_lwres_t *lwres;
isc_result_t res;
REQUIRE(dest != NULL);
REQUIRE(DNS_C_LWLIST_VALID(src));
res = dns_c_lwreslist_new(mem, &newlist);
if (res != ISC_R_SUCCESS) {
return (res);
}
lwres = ISC_LIST_HEAD(src->lwreslist);
while (lwres != NULL) {
res = dns_c_lwreslist_append(newlist, lwres, ISC_TRUE);
if (res != ISC_R_SUCCESS) {
dns_c_lwreslist_delete(&newlist);
return (res);
}
lwres = ISC_LIST_NEXT(lwres, next);
}
*dest = newlist;
ISC_LIST_APPEND(list->lwreslist, lwres, next);
return (ISC_R_SUCCESS);
}
@@ -152,7 +111,6 @@ dns_c_lwreslist_head (dns_c_lwreslist_t *list) {
return (ISC_LIST_HEAD(list->lwreslist));
}
dns_c_lwres_t *
dns_c_lwreslist_next(dns_c_lwres_t *lwres) {
REQUIRE(DNS_C_LWRES_VALID(lwres));
@@ -199,6 +157,7 @@ dns_c_lwres_new(isc_mem_t *mem, dns_c_lwres_t **lwresp)
lwres->listeners = NULL;
lwres->view = NULL;
lwres->viewclass = dns_rdataclass_in;
lwres->searchlist = NULL;
ISC_LINK_INIT(lwres, next);
@@ -226,6 +185,8 @@ dns_c_lwres_delete(dns_c_lwres_t **lwresp)
isc_mem_free(mem, lwres->view);
if (lwres->listeners != NULL)
dns_c_iplist_detach(&lwres->listeners);
if (lwres->searchlist != NULL)
dns_c_searchlist_delete(&lwres->searchlist);
lwres->mem = NULL;
ISC_LINK_INIT(lwres, next);
@@ -237,39 +198,6 @@ dns_c_lwres_delete(dns_c_lwres_t **lwresp)
return (ISC_R_SUCCESS);
}
isc_result_t dns_c_lwres_copy(isc_mem_t *mem, dns_c_lwres_t **dest,
dns_c_lwres_t *src)
{
dns_c_lwres_t *newlwres;
REQUIRE(dest != NULL);
REQUIRE(DNS_C_LWRES_VALID(src));
newlwres = isc_mem_get(mem, sizeof *newlwres);
if (newlwres == NULL) {
return (ISC_R_NOMEMORY);
}
newlwres->magic = DNS_C_LWRES_MAGIC;
newlwres->listeners = NULL;
newlwres->view = NULL;
if (src->view != NULL) {
newlwres->view = isc_mem_strdup(mem, src->view);
if (newlwres->view == NULL) {
dns_c_lwres_delete(&newlwres);
return (ISC_R_NOMEMORY);
}
}
if (src->listeners != NULL)
dns_c_iplist_attach(src->listeners, &newlwres->listeners);
newlwres->viewclass = src->viewclass;
*dest = newlwres;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_c_lwres_setlistenon(dns_c_lwres_t *lwres, dns_c_iplist_t *listeners) {
if (lwres->listeners != NULL)
@@ -291,6 +219,14 @@ dns_c_lwres_setview(dns_c_lwres_t *lwres, char *view,
return (ISC_R_SUCCESS);
}
isc_result_t dns_c_lwres_setsearchlist(dns_c_lwres_t *lwres,
dns_c_searchlist_t *searchlist) {
if (lwres->searchlist != NULL)
return (ISC_R_EXISTS);
lwres->searchlist = searchlist;
return (ISC_R_SUCCESS);
}
void
dns_c_lwres_print(FILE *fp, int indent, dns_c_lwres_t *lwres)
{
@@ -321,6 +257,148 @@ dns_c_lwres_print(FILE *fp, int indent, dns_c_lwres_t *lwres)
fprintf(fp, ";\n");
}
if (lwres->searchlist != NULL) {
dns_c_searchlist_print(fp, indent, lwres->searchlist);
fprintf(fp, ";\n");
}
dns_c_printtabs(fp, indent);
fprintf(fp, "};\n");
}
isc_result_t
dns_c_searchlist_new(isc_mem_t *mem, dns_c_searchlist_t **list)
{
dns_c_searchlist_t *l;
l = isc_mem_get(mem, sizeof *l);
if (l == NULL) {
return (ISC_R_NOMEMORY);
}
l->magic = DNS_C_SEARCHLIST_MAGIC;
l->mem = mem;
ISC_LIST_INIT(l->searches);
*list = l;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_c_searchlist_delete(dns_c_searchlist_t **list)
{
dns_c_searchlist_t *l;
dns_c_search_t *si, *tmpsi;
isc_result_t r;
REQUIRE(list != NULL);
REQUIRE(DNS_C_SEARCHLIST_VALID(*list));
l = *list;
si = ISC_LIST_HEAD(l->searches);
while (si != NULL) {
tmpsi = ISC_LIST_NEXT(si, next);
ISC_LIST_UNLINK(l->searches, si, next);
r = search_delete(&si);
if (r != ISC_R_SUCCESS) {
return (r);
}
si = tmpsi;
}
l->magic = 0;
isc_mem_put(l->mem, l, sizeof *l);
*list = NULL;
return (ISC_R_SUCCESS);
}
static isc_result_t
search_delete(dns_c_search_t **search)
{
dns_c_search_t *si;
REQUIRE(search != NULL);
REQUIRE(DNS_C_SEARCH_VALID(*search));
si = *search;
isc_mem_free(si->mem, si->search);
si->magic = 0;
isc_mem_put(si->mem, si, sizeof *si);
*search = NULL;
return (ISC_R_SUCCESS);
}
void
dns_c_searchlist_append(dns_c_searchlist_t *list, dns_c_search_t *search)
{
REQUIRE(DNS_C_SEARCHLIST_VALID(list));
REQUIRE(DNS_C_SEARCH_VALID(search));
ISC_LIST_APPEND(list->searches, search, next);
}
void
dns_c_searchlist_print(FILE *fp, int indent,
dns_c_searchlist_t *list)
{
dns_c_search_t *iter;
REQUIRE(fp != NULL);
REQUIRE(DNS_C_SEARCHLIST_VALID(list));
if (ISC_LIST_EMPTY(list->searches)) {
return;
}
dns_c_printtabs(fp, indent);
fprintf(fp, "search {\n");
iter = ISC_LIST_HEAD(list->searches);
if (iter == NULL) {
dns_c_printtabs(fp, indent + 1);
fprintf(fp, "/* no search list defined */\n");
} else {
while (iter != NULL) {
dns_c_printtabs(fp, indent + 1);
fprintf(fp, "\"%s\";\n", iter->search);
iter = ISC_LIST_NEXT(iter, next);
}
}
dns_c_printtabs(fp, indent);
fprintf(fp, "}");
}
isc_result_t
dns_c_search_new(isc_mem_t *mem, const char *val, dns_c_search_t **search)
{
dns_c_search_t *ki;
REQUIRE(val != NULL);
REQUIRE(*val != '\0');
REQUIRE(search != NULL);
ki = isc_mem_get(mem, sizeof *ki);
if (ki == NULL) {
return (ISC_R_NOMEMORY);
}
ki->magic = DNS_C_SEARCH_MAGIC;
ki->mem = mem;
ki->search = isc_mem_strdup(mem, val);
ISC_LINK_INIT(ki, next);
*search = ki;
return (ISC_R_SUCCESS);
}

View File

@@ -17,7 +17,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: confparser.y.dirty,v 1.21 2000/10/17 22:21:34 bwelling Exp $ */
/* $Id: confparser.y.dirty,v 1.22 2000/10/19 01:26:37 gson Exp $ */
#include <config.h>
@@ -228,6 +228,7 @@ static isc_boolean_t int_too_big(isc_uint32_t base, isc_uint32_t mult);
dns_c_ordering_t ordering;
dns_c_iplist_t *iplist;
dns_c_kidlist_t *kidlist;
dns_c_searchlist_t *searchlist;
}
/* Misc */
@@ -367,6 +368,7 @@ static isc_boolean_t int_too_big(isc_uint32_t base, isc_uint32_t mult);
%token L_RESPONSE
%token L_RFC2308_TYPE1
%token L_RRSET_ORDER
%token L_SEARCH
%token L_SECRET
%token L_SEC_KEY
%token L_SELF
@@ -472,6 +474,7 @@ static isc_boolean_t int_too_big(isc_uint32_t base, isc_uint32_t mult);
#endif /* NOMINUM_PUBLIC */
%type <kidlist> control_keys
%type <kidlist> keyid_list
%type <searchlist> searchlist
%type <text> ordering_name
%type <text> secret
%type <tformat> transfer_format
@@ -3100,6 +3103,36 @@ keyid_list: /* nothing */
};
searchlist: /* nothing */
{
dns_c_searchlist_t *searchlist = NULL;
tmpres = dns_c_searchlist_new(currcfg->mem, &searchlist);
if (tmpres != ISC_R_SUCCESS) {
parser_error(ISC_FALSE, "failed to create searchlist");
YYABORT;
}
$$ = searchlist;
}
| searchlist any_string L_EOS
{
dns_c_search_t *search = NULL;
tmpres = dns_c_search_new($$->mem, $2, &search);
if (tmpres != ISC_R_SUCCESS) {
parser_error(ISC_FALSE, "failed to create searchlist item");
dns_c_searchlist_delete(&$$);
$$ = NULL;
YYABORT;
}
isc_mem_free(memctx, $2);
dns_c_searchlist_append($$, search);
};
/*
* Address Matching
*/
@@ -5656,6 +5689,21 @@ lwres_option: L_LISTEN_ON port_ip_list
}
isc_mem_free(memctx, $2);
}
| L_SEARCH L_LBRACE searchlist L_RBRACE
{
dns_c_lwres_t *lwres;
lwres = ISC_LIST_TAIL(currcfg->lwres->lwreslist);
tmpres = dns_c_lwres_setsearchlist(lwres, $3);
if (tmpres == ISC_R_EXISTS) {
parser_error(ISC_FALSE, "cannot redefine searchlist");
dns_c_searchlist_delete(&$3);
YYABORT;
} else if (tmpres != ISC_R_SUCCESS) {
parser_error(ISC_FALSE, "failed to set searchlist");
dns_c_searchlist_delete(&$3);
YYABORT;
}
}
;
@@ -5843,6 +5891,7 @@ static struct token keyword_tokens [] = {
{ "response", L_RESPONSE },
{ "rfc2308-type1", L_RFC2308_TYPE1 },
{ "rrset-order", L_RRSET_ORDER },
{ "search", L_SEARCH },
{ "secret", L_SECRET },
{ "self", L_SELF },
{ "serial-queries", L_SERIAL_QUERIES },

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: confctx.h,v 1.54 2000/10/12 00:38:30 bwelling Exp $ */
/* $Id: confctx.h,v 1.55 2000/10/19 01:26:38 gson Exp $ */
#ifndef DNS_CONFCTX_H
#define DNS_CONFCTX_H 1
@@ -822,8 +822,7 @@ isc_result_t dns_c_ctx_settrustedkeys(dns_c_ctx_t *cfg, dns_c_tkeylist_t *list,
isc_boolean_t copy);
isc_result_t dns_c_ctx_getlwres(dns_c_ctx_t *cfg, dns_c_lwreslist_t **retval);
isc_result_t dns_c_ctx_setlwres(dns_c_ctx_t *cfg, dns_c_lwreslist_t *list,
isc_boolean_t copy);
isc_result_t dns_c_ctx_setlwres(dns_c_ctx_t *cfg, dns_c_lwreslist_t *list);
ISC_LANG_ENDDECLS

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: conflwres.h,v 1.1 2000/10/04 18:47:18 bwelling Exp $ */
/* $Id: conflwres.h,v 1.2 2000/10/19 01:26:39 gson Exp $ */
#ifndef DNS_CONFLWRES_H
#define DNS_CONFLWRES_H 1
@@ -65,9 +65,13 @@
#define DNS_C_LWRES_MAGIC 0x4C575253 /* LWRS */
#define DNS_C_LWLIST_MAGIC 0x4C57524C /* LWRL */
#define DNS_C_SEARCH_MAGIC 0x53524348 /* SRCH */
#define DNS_C_SEARCHLIST_MAGIC 0x5352434C /* SRCL */
#define DNS_C_LWRES_VALID(ptr) ISC_MAGIC_VALID(ptr, DNS_C_LWRES_MAGIC)
#define DNS_C_LWLIST_VALID(ptr) ISC_MAGIC_VALID(ptr, DNS_C_LWLIST_MAGIC)
#define DNS_C_LWRES_VALID(ptr) ISC_MAGIC_VALID(ptr, DNS_C_LWRES_MAGIC)
#define DNS_C_LWLIST_VALID(ptr) ISC_MAGIC_VALID(ptr, DNS_C_LWLIST_MAGIC)
#define DNS_C_SEARCH_VALID(ptr) ISC_MAGIC_VALID(ptr, DNS_C_SEARCH_MAGIC)
#define DNS_C_SEARCHLIST_VALID(ptr) ISC_MAGIC_VALID(ptr, DNS_C_SEARCHLIST_MAGIC)
/***
*** Types
@@ -75,6 +79,8 @@
typedef struct dns_c_lwres dns_c_lwres_t;
typedef struct dns_c_lwres_list dns_c_lwreslist_t;
typedef struct dns_c_search dns_c_search_t;
typedef struct dns_c_search_list dns_c_searchlist_t;
/*
* The type for holding an lwres config structure
@@ -86,6 +92,7 @@ struct dns_c_lwres {
dns_c_iplist_t *listeners;
char *view;
dns_rdataclass_t viewclass;
dns_c_searchlist_t *searchlist;
ISC_LINK(dns_c_lwres_t) next;
};
@@ -101,6 +108,28 @@ struct dns_c_lwres_list {
};
/*
* A search list element.
*/
struct dns_c_search {
isc_uint32_t magic;
isc_mem_t *mem;
char *search;
ISC_LINK(dns_c_search_t) next;
};
/*
* A search list.
*/
struct dns_c_search_list {
isc_uint32_t magic;
isc_mem_t *mem;
ISC_LIST(dns_c_search_t) searches;
};
/***
*** Functions
***/
@@ -113,8 +142,7 @@ isc_result_t dns_c_lwreslist_new(isc_mem_t *mem,
isc_result_t dns_c_lwreslist_delete(dns_c_lwreslist_t **list);
isc_result_t dns_c_lwreslist_append(dns_c_lwreslist_t *list,
dns_c_lwres_t *lwres,
isc_boolean_t copy);
dns_c_lwres_t *lwres);
isc_result_t dns_c_lwreslist_copy(isc_mem_t *mem, dns_c_lwreslist_t **dest,
dns_c_lwreslist_t *src);
@@ -132,17 +160,29 @@ isc_result_t dns_c_lwres_new(isc_mem_t *mem, dns_c_lwres_t **lwresp);
isc_result_t dns_c_lwres_delete(dns_c_lwres_t **lwresp);
isc_result_t dns_c_lwres_copy(isc_mem_t *mem, dns_c_lwres_t **dest,
dns_c_lwres_t *src);
isc_result_t dns_c_lwres_setlistenon(dns_c_lwres_t *lwres,
dns_c_iplist_t *listeners);
isc_result_t dns_c_lwres_setview(dns_c_lwres_t *lwres, char *view,
dns_rdataclass_t rdclass);
isc_result_t dns_c_lwres_setsearchlist(dns_c_lwres_t *lwres,
dns_c_searchlist_t *searchlist);
void dns_c_lwres_print(FILE *fp, int indent, dns_c_lwres_t *lwres);
isc_result_t dns_c_searchlist_new(isc_mem_t *mem, dns_c_searchlist_t **list);
isc_result_t dns_c_searchlist_delete(dns_c_searchlist_t **list);
void dns_c_searchlist_append(dns_c_searchlist_t *list, dns_c_search_t *search);
void dns_c_searchlist_print(FILE *fp, int indent, dns_c_searchlist_t *list);
isc_result_t dns_c_search_new(isc_mem_t *mem, const char *val,
dns_c_search_t **search);
ISC_LANG_ENDDECLS
#endif /* DNS_CONFLWRES_H */