version 1.2.2.2, 2018/09/06 06:54:11 |
version 1.2.2.3, 2019/01/18 08:49:20 |
|
|
|
|
#include <config.h> |
#include <config.h> |
|
|
|
#include <stdbool.h> |
#include <stdio.h> |
#include <stdio.h> |
|
#include <inttypes.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdarg.h> |
#include <stdarg.h> |
|
|
|
|
|
|
#include "driver.h" |
#include "driver.h" |
|
|
#ifdef WIN32 |
|
#define STRTOK_R(a, b, c) strtok_s(a, b, c) |
|
#elif defined(_REENTRANT) |
|
#define STRTOK_R(a, b, c) strtok_r(a, b, c) |
|
#else |
|
#define STRTOK_R(a, b, c) strtok(a, b) |
|
#endif |
|
|
|
#define CHECK(x) \ |
#define CHECK(x) \ |
do { \ |
do { \ |
result = (x); \ |
result = (x); \ |
Line 68 struct dlz_example_data { |
|
Line 62 struct dlz_example_data { |
|
struct record adds[MAX_RECORDS]; |
struct record adds[MAX_RECORDS]; |
struct record deletes[MAX_RECORDS]; |
struct record deletes[MAX_RECORDS]; |
|
|
isc_boolean_t transaction_started; |
bool transaction_started; |
|
|
/* Helper functions from the dlz_dlopen driver */ |
/* Helper functions from the dlz_dlopen driver */ |
log_t *log; |
log_t *log; |
Line 77 struct dlz_example_data { |
|
Line 71 struct dlz_example_data { |
|
dns_dlz_writeablezone_t *writeable_zone; |
dns_dlz_writeablezone_t *writeable_zone; |
}; |
}; |
|
|
static isc_boolean_t |
static bool |
single_valued(const char *type) { |
single_valued(const char *type) { |
const char *single[] = { "soa", "cname", NULL }; |
const char *single[] = { "soa", "cname", NULL }; |
int i; |
int i; |
|
|
for (i = 0; single[i]; i++) { |
for (i = 0; single[i]; i++) { |
if (strcasecmp(single[i], type) == 0) { |
if (strcasecmp(single[i], type) == 0) { |
return (ISC_TRUE); |
return (true); |
} |
} |
} |
} |
return (ISC_FALSE); |
return (false); |
} |
} |
|
|
/* |
/* |
Line 98 add_name(struct dlz_example_data *state, |
|
Line 92 add_name(struct dlz_example_data *state, |
|
const char *name, const char *type, dns_ttl_t ttl, const char *data) |
const char *name, const char *type, dns_ttl_t ttl, const char *data) |
{ |
{ |
int i; |
int i; |
isc_boolean_t single = single_valued(type); |
bool single = single_valued(type); |
int first_empty = -1; |
int first_empty = -1; |
|
|
for (i = 0; i < MAX_RECORDS; i++) { |
for (i = 0; i < MAX_RECORDS; i++) { |
Line 173 static isc_result_t |
|
Line 167 static isc_result_t |
|
fmt_address(isc_sockaddr_t *addr, char *buffer, size_t size) { |
fmt_address(isc_sockaddr_t *addr, char *buffer, size_t size) { |
char addr_buf[100]; |
char addr_buf[100]; |
const char *ret; |
const char *ret; |
isc_uint16_t port = 0; |
uint16_t port = 0; |
|
|
switch (addr->type.sa.sa_family) { |
switch (addr->type.sa.sa_family) { |
case AF_INET: |
case AF_INET: |
Line 402 dlz_lookup(const char *zone, const char |
|
Line 396 dlz_lookup(const char *zone, const char |
|
{ |
{ |
isc_result_t result; |
isc_result_t result; |
struct dlz_example_data *state = (struct dlz_example_data *)dbdata; |
struct dlz_example_data *state = (struct dlz_example_data *)dbdata; |
isc_boolean_t found = ISC_FALSE; |
bool found = false; |
void *dbversion = NULL; |
void *dbversion = NULL; |
isc_sockaddr_t *src; |
isc_sockaddr_t *src; |
char full_name[256]; |
char full_name[256]; |
Line 464 dlz_lookup(const char *zone, const char |
|
Line 458 dlz_lookup(const char *zone, const char |
|
if (clientinfo != NULL && |
if (clientinfo != NULL && |
clientinfo->version >= DNS_CLIENTINFO_VERSION) { |
clientinfo->version >= DNS_CLIENTINFO_VERSION) { |
dbversion = clientinfo->dbversion; |
dbversion = clientinfo->dbversion; |
if (dbversion != NULL && *(isc_boolean_t *)dbversion) |
if (dbversion != NULL && *(bool *)dbversion) |
state->log(ISC_LOG_INFO, |
state->log(ISC_LOG_INFO, |
"dlz_example: lookup against live " |
"dlz_example: lookup against live " |
"transaction"); |
"transaction"); |
Line 485 dlz_lookup(const char *zone, const char |
|
Line 479 dlz_lookup(const char *zone, const char |
|
state->log(ISC_LOG_INFO, |
state->log(ISC_LOG_INFO, |
"dlz_example: lookup connection from %s", buf); |
"dlz_example: lookup connection from %s", buf); |
|
|
found = ISC_TRUE; |
found = true; |
result = state->putrr(lookup, "TXT", 0, buf); |
result = state->putrr(lookup, "TXT", 0, buf); |
if (result != ISC_R_SUCCESS) |
if (result != ISC_R_SUCCESS) |
return (result); |
return (result); |
Line 497 dlz_lookup(const char *zone, const char |
|
Line 491 dlz_lookup(const char *zone, const char |
|
for (i = 0; i < 511; i++) |
for (i = 0; i < 511; i++) |
buf[i] = 'x'; |
buf[i] = 'x'; |
buf[i] = '\0'; |
buf[i] = '\0'; |
found = ISC_TRUE; |
found = true; |
result = state->putrr(lookup, "TXT", 0, buf); |
result = state->putrr(lookup, "TXT", 0, buf); |
if (result != ISC_R_SUCCESS) |
if (result != ISC_R_SUCCESS) |
return (result); |
return (result); |
Line 506 dlz_lookup(const char *zone, const char |
|
Line 500 dlz_lookup(const char *zone, const char |
|
/* Tests for DLZ redirection zones */ |
/* Tests for DLZ redirection zones */ |
if (strcmp(name, "*") == 0 && strcmp(zone, ".") == 0) { |
if (strcmp(name, "*") == 0 && strcmp(zone, ".") == 0) { |
result = state->putrr(lookup, "A", 0, "100.100.100.2"); |
result = state->putrr(lookup, "A", 0, "100.100.100.2"); |
found = ISC_TRUE; |
found = true; |
if (result != ISC_R_SUCCESS) |
if (result != ISC_R_SUCCESS) |
return (result); |
return (result); |
} |
} |
Line 515 dlz_lookup(const char *zone, const char |
|
Line 509 dlz_lookup(const char *zone, const char |
|
strcmp(zone, ".") == 0) |
strcmp(zone, ".") == 0) |
{ |
{ |
result = state->putrr(lookup, "A", 0, "100.100.100.3"); |
result = state->putrr(lookup, "A", 0, "100.100.100.3"); |
found = ISC_TRUE; |
found = true; |
if (result != ISC_R_SUCCESS) |
if (result != ISC_R_SUCCESS) |
return (result); |
return (result); |
} |
} |
Line 523 dlz_lookup(const char *zone, const char |
|
Line 517 dlz_lookup(const char *zone, const char |
|
/* Answer from current records */ |
/* Answer from current records */ |
for (i = 0; i < MAX_RECORDS; i++) { |
for (i = 0; i < MAX_RECORDS; i++) { |
if (strcasecmp(state->current[i].name, full_name) == 0) { |
if (strcasecmp(state->current[i].name, full_name) == 0) { |
found = ISC_TRUE; |
found = true; |
result = state->putrr(lookup, state->current[i].type, |
result = state->putrr(lookup, state->current[i].type, |
state->current[i].ttl, |
state->current[i].ttl, |
state->current[i].data); |
state->current[i].data); |
Line 595 dlz_newversion(const char *zone, void *d |
|
Line 589 dlz_newversion(const char *zone, void *d |
|
return (ISC_R_FAILURE); |
return (ISC_R_FAILURE); |
} |
} |
|
|
state->transaction_started = ISC_TRUE; |
state->transaction_started = true; |
*versionp = (void *) &state->transaction_started; |
*versionp = (void *) &state->transaction_started; |
|
|
return (ISC_R_SUCCESS); |
return (ISC_R_SUCCESS); |
Line 605 dlz_newversion(const char *zone, void *d |
|
Line 599 dlz_newversion(const char *zone, void *d |
|
* End a transaction |
* End a transaction |
*/ |
*/ |
void |
void |
dlz_closeversion(const char *zone, isc_boolean_t commit, |
dlz_closeversion(const char *zone, bool commit, |
void *dbdata, void **versionp) |
void *dbdata, void **versionp) |
{ |
{ |
struct dlz_example_data *state = (struct dlz_example_data *)dbdata; |
struct dlz_example_data *state = (struct dlz_example_data *)dbdata; |
Line 618 dlz_closeversion(const char *zone, isc_b |
|
Line 612 dlz_closeversion(const char *zone, isc_b |
|
return; |
return; |
} |
} |
|
|
state->transaction_started = ISC_FALSE; |
state->transaction_started = false; |
|
|
*versionp = NULL; |
*versionp = NULL; |
|
|
Line 690 dlz_configure(dns_view_t *view, dns_dlzd |
|
Line 684 dlz_configure(dns_view_t *view, dns_dlzd |
|
/* |
/* |
* Authorize a zone update |
* Authorize a zone update |
*/ |
*/ |
isc_boolean_t |
bool |
dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr, |
dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr, |
const char *type, const char *key, isc_uint32_t keydatalen, |
const char *type, const char *key, uint32_t keydatalen, |
unsigned char *keydata, void *dbdata) |
unsigned char *keydata, void *dbdata) |
{ |
{ |
struct dlz_example_data *state = (struct dlz_example_data *)dbdata; |
struct dlz_example_data *state = (struct dlz_example_data *)dbdata; |
Line 707 dlz_ssumatch(const char *signer, const c |
|
Line 701 dlz_ssumatch(const char *signer, const c |
|
if (state->log != NULL) |
if (state->log != NULL) |
state->log(ISC_LOG_INFO, "dlz_example: denying update " |
state->log(ISC_LOG_INFO, "dlz_example: denying update " |
"of name=%s by %s", name, signer); |
"of name=%s by %s", name, signer); |
return (ISC_FALSE); |
return (false); |
} |
} |
if (state->log != NULL) |
if (state->log != NULL) |
state->log(ISC_LOG_INFO, "dlz_example: allowing update of " |
state->log(ISC_LOG_INFO, "dlz_example: allowing update of " |
"name=%s by %s", name, signer); |
"name=%s by %s", name, signer); |
return (ISC_TRUE); |
return (true); |
} |
} |
|
|
|
|
Line 723 modrdataset(struct dlz_example_data *sta |
|
Line 717 modrdataset(struct dlz_example_data *sta |
|
char *full_name, *dclass, *type, *data, *ttlstr, *buf; |
char *full_name, *dclass, *type, *data, *ttlstr, *buf; |
char absolute[1024]; |
char absolute[1024]; |
isc_result_t result; |
isc_result_t result; |
#if defined(WIN32) || defined(_REENTRANT) |
|
char *saveptr = NULL; |
char *saveptr = NULL; |
#endif |
|
|
|
buf = strdup(rdatastr); |
buf = strdup(rdatastr); |
if (buf == NULL) |
if (buf == NULL) |
Line 739 modrdataset(struct dlz_example_data *sta |
|
Line 731 modrdataset(struct dlz_example_data *sta |
|
* for the type used by dig |
* for the type used by dig |
*/ |
*/ |
|
|
full_name = STRTOK_R(buf, "\t", &saveptr); |
full_name = strtok_r(buf, "\t", &saveptr); |
if (full_name == NULL) |
if (full_name == NULL) |
goto error; |
goto error; |
|
|
ttlstr = STRTOK_R(NULL, "\t", &saveptr); |
ttlstr = strtok_r(NULL, "\t", &saveptr); |
if (ttlstr == NULL) |
if (ttlstr == NULL) |
goto error; |
goto error; |
|
|
dclass = STRTOK_R(NULL, "\t", &saveptr); |
dclass = strtok_r(NULL, "\t", &saveptr); |
if (dclass == NULL) |
if (dclass == NULL) |
goto error; |
goto error; |
|
|
type = STRTOK_R(NULL, "\t", &saveptr); |
type = strtok_r(NULL, "\t", &saveptr); |
if (type == NULL) |
if (type == NULL) |
goto error; |
goto error; |
|
|
data = STRTOK_R(NULL, "\t", &saveptr); |
data = strtok_r(NULL, "\t", &saveptr); |
if (data == NULL) |
if (data == NULL) |
goto error; |
goto error; |
|
|