mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-11 12:20:00 -04:00
check that state and state->log are non NULL before calling state->log
(cherry picked from commit 7bf6750330)
This commit is contained in:
parent
be71d9cc43
commit
8f2227a423
1 changed files with 43 additions and 63 deletions
|
|
@ -40,6 +40,13 @@
|
|||
goto failure; \
|
||||
} while (0)
|
||||
|
||||
#define loginfo(...) \
|
||||
({ if ((state != NULL) && (state->log != NULL)) \
|
||||
state->log(ISC_LOG_INFO, __VA_ARGS__); })
|
||||
#define logerr(...) \
|
||||
({ if ((state != NULL) && (state->log != NULL)) \
|
||||
state->log(ISC_LOG_ERROR, __VA_ARGS__); })
|
||||
|
||||
/* For this simple example, use fixed sized strings */
|
||||
struct record {
|
||||
char name[100];
|
||||
|
|
@ -109,9 +116,7 @@ add_name(struct dlz_example_data *state, struct record *list,
|
|||
i = first_empty;
|
||||
}
|
||||
if (i == MAX_RECORDS) {
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_ERROR,
|
||||
"dlz_example: out of record space");
|
||||
logerr("dlz_example: out of record space");
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -244,9 +249,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
|
|||
va_end(ap);
|
||||
|
||||
if (argc < 2 || argv[1][0] == '\0') {
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_ERROR,
|
||||
"dlz_example: please specify a zone name");
|
||||
logerr("dlz_example: please specify a zone name");
|
||||
dlz_destroy(state);
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
|
|
@ -282,9 +285,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
|
|||
add_name(state, &state->current[0], state->zone_name,
|
||||
"a", 1800, "10.53.0.1");
|
||||
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: started for zone %s",
|
||||
state->zone_name);
|
||||
loginfo("dlz_example: started for zone %s", state->zone_name);
|
||||
|
||||
*dbdata = state;
|
||||
return (ISC_R_SUCCESS);
|
||||
|
|
@ -302,10 +303,7 @@ void
|
|||
dlz_destroy(void *dbdata) {
|
||||
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
|
||||
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO,
|
||||
"dlz_example: shutting down zone %s",
|
||||
state->zone_name);
|
||||
loginfo("dlz_example: shutting down zone %s", state->zone_name);
|
||||
free(state->zone_name);
|
||||
free(state);
|
||||
}
|
||||
|
|
@ -333,10 +331,8 @@ dlz_findzonedb(void *dbdata, const char *name,
|
|||
fmt_address(src, addrbuf, sizeof(addrbuf));
|
||||
}
|
||||
|
||||
state->log(ISC_LOG_INFO,
|
||||
"dlz_example: dlz_findzonedb called with name '%s' "
|
||||
"in zone DB '%s' from %s",
|
||||
name, state->zone_name, addrbuf);
|
||||
loginfo("dlz_example: dlz_findzonedb called with name '%s' "
|
||||
"in zone DB '%s' from %s", name, state->zone_name, addrbuf);
|
||||
|
||||
/*
|
||||
* Returning ISC_R_NOTFOUND will cause the query logic to
|
||||
|
|
@ -436,7 +432,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
|
|||
count = 1;
|
||||
memcpy(last, full_name, size + 1);
|
||||
}
|
||||
state->log(ISC_LOG_INFO, "lookup #%d for %s", count, full_name);
|
||||
loginfo("lookup #%d for %s", count, full_name);
|
||||
|
||||
/*
|
||||
* If we need to know the database version (as set in
|
||||
|
|
@ -456,10 +452,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
|
|||
if (clientinfo != NULL &&
|
||||
clientinfo->version >= DNS_CLIENTINFO_VERSION) {
|
||||
dbversion = clientinfo->dbversion;
|
||||
if (dbversion != NULL && *(bool *)dbversion)
|
||||
state->log(ISC_LOG_INFO,
|
||||
"dlz_example: lookup against live "
|
||||
"transaction");
|
||||
if (dbversion != NULL && *(bool *)dbversion) {
|
||||
loginfo("dlz_example: lookup against live transaction");
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(name, "source-addr") == 0) {
|
||||
|
|
@ -474,8 +469,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
|
|||
fmt_address(src, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
state->log(ISC_LOG_INFO,
|
||||
"dlz_example: lookup connection from %s", buf);
|
||||
loginfo("dlz_example: lookup connection from %s", buf);
|
||||
|
||||
found = true;
|
||||
result = state->putrr(lookup, "TXT", 0, buf);
|
||||
|
|
@ -536,10 +530,15 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
|
|||
*/
|
||||
isc_result_t
|
||||
dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
|
||||
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
|
||||
isc_result_t result;
|
||||
|
||||
loginfo("dlz_example: dlz_allowzonexfr called for %s", name);
|
||||
|
||||
result = dlz_findzonedb(dbdata, name, NULL, NULL);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
loginfo("dlz_example: findzonedb returned %s",
|
||||
isc_result_totext(result));
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
|
@ -548,9 +547,12 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
|
|||
* is effective.
|
||||
*/
|
||||
if (strcmp(client, "10.53.0.5") == 0) {
|
||||
loginfo("dlz_example: disallow transfer to 10.53.0.5");
|
||||
return (ISC_R_NOPERM);
|
||||
}
|
||||
|
||||
loginfo("dlz_example: transfer allowed for %s", name);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
@ -592,10 +594,8 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) {
|
|||
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
|
||||
|
||||
if (state->transaction_started) {
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO,
|
||||
"dlz_example: transaction already "
|
||||
"started for zone %s", zone);
|
||||
loginfo("dlz_example: transaction already started for zone %s",
|
||||
zone);
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -615,9 +615,8 @@ dlz_closeversion(const char *zone, bool commit,
|
|||
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
|
||||
|
||||
if (!state->transaction_started) {
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: transaction not "
|
||||
"started for zone %s", zone);
|
||||
loginfo("dlz_example: transaction not started for zone %s",
|
||||
zone);
|
||||
*versionp = NULL;
|
||||
return;
|
||||
}
|
||||
|
|
@ -628,9 +627,7 @@ dlz_closeversion(const char *zone, bool commit,
|
|||
|
||||
if (commit) {
|
||||
int i;
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: committing "
|
||||
"transaction on zone %s", zone);
|
||||
loginfo("dlz_example: committing transaction on zone %s", zone);
|
||||
for (i = 0; i < MAX_RECORDS; i++) {
|
||||
if (strlen(state->deletes[i].name) > 0U) {
|
||||
(void)del_name(state, &state->current[0],
|
||||
|
|
@ -650,9 +647,7 @@ dlz_closeversion(const char *zone, bool commit,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: cancelling "
|
||||
"transaction on zone %s", zone);
|
||||
loginfo("dlz_example: cancelling transaction on zone %s", zone);
|
||||
}
|
||||
memset(state->adds, 0, sizeof(state->adds));
|
||||
memset(state->deletes, 0, sizeof(state->deletes));
|
||||
|
|
@ -667,27 +662,21 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata) {
|
|||
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
|
||||
isc_result_t result;
|
||||
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: starting configure");
|
||||
loginfo("dlz_example: starting configure");
|
||||
|
||||
if (state->writeable_zone == NULL) {
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: no "
|
||||
"writeable_zone method available");
|
||||
loginfo("dlz_example: no writeable_zone method available");
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
result = state->writeable_zone(view, dlzdb, state->zone_name);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_ERROR, "dlz_example: failed to "
|
||||
"configure zone %s", state->zone_name);
|
||||
loginfo("dlz_example: failed to configure zone %s",
|
||||
state->zone_name);
|
||||
return (result);
|
||||
}
|
||||
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: configured writeable "
|
||||
"zone %s", state->zone_name);
|
||||
loginfo("dlz_example: configured writeable zone %s", state->zone_name);
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
@ -708,14 +697,11 @@ dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr,
|
|||
UNUSED(keydata);
|
||||
|
||||
if (strncmp(name, "deny.", 5) == 0) {
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: denying update "
|
||||
"of name=%s by %s", name, signer);
|
||||
loginfo("dlz_example: denying update of name=%s by %s",
|
||||
name, signer);
|
||||
return (false);
|
||||
}
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: allowing update of "
|
||||
"name=%s by %s", name, signer);
|
||||
loginfo("dlz_example: allowing update of name=%s by %s", name, signer);
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
|
@ -786,9 +772,7 @@ dlz_addrdataset(const char *name, const char *rdatastr,
|
|||
if (version != (void *) &state->transaction_started)
|
||||
return (ISC_R_FAILURE);
|
||||
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: adding rdataset %s '%s'",
|
||||
name, rdatastr);
|
||||
loginfo("dlz_example: adding rdataset %s '%s'", name, rdatastr);
|
||||
|
||||
return (modrdataset(state, name, rdatastr, &state->adds[0]));
|
||||
}
|
||||
|
|
@ -802,9 +786,7 @@ dlz_subrdataset(const char *name, const char *rdatastr,
|
|||
if (version != (void *) &state->transaction_started)
|
||||
return (ISC_R_FAILURE);
|
||||
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: subtracting rdataset "
|
||||
"%s '%s'", name, rdatastr);
|
||||
loginfo("dlz_example: subtracting rdataset %s '%s'", name, rdatastr);
|
||||
|
||||
return (modrdataset(state, name, rdatastr, &state->deletes[0]));
|
||||
}
|
||||
|
|
@ -818,9 +800,7 @@ dlz_delrdataset(const char *name, const char *type,
|
|||
if (version != (void *) &state->transaction_started)
|
||||
return (ISC_R_FAILURE);
|
||||
|
||||
if (state->log != NULL)
|
||||
state->log(ISC_LOG_INFO, "dlz_example: deleting rdataset %s "
|
||||
"of type %s", name, type);
|
||||
loginfo("dlz_example: deleting rdataset %s of type %s", name, type);
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue