summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorSeonah Moon <seonah1.moon@samsung.com>2021-01-18 18:38:22 +0900
committerSeonah Moon <seonah1.moon@samsung.com>2021-01-18 18:39:10 +0900
commita586e92f2093407d29582430ebb69ebfc4756f06 (patch)
tree28652241164cb1f04a44d7b709ad45bf79d50598 /contrib
parent5341f72ee3d82cab6a4e3459f6f19ee3ecbc6f6c (diff)
downloadbind-a586e92f2093407d29582430ebb69ebfc4756f06.tar.gz
bind-a586e92f2093407d29582430ebb69ebfc4756f06.tar.bz2
bind-a586e92f2093407d29582430ebb69ebfc4756f06.zip
Imported Upstream version 9.16.8upstream/9.16.8
Change-Id: I122b98d3f939c6e8533ee78070a065b6bec17085
Diffstat (limited to 'contrib')
-rw-r--r--contrib/dlz/bin/dlzbdb/Makefile.in14
-rw-r--r--contrib/dlz/bin/dlzbdb/dlzbdb.c561
-rw-r--r--contrib/dlz/config.dlz.in2
-rw-r--r--contrib/dlz/drivers/dlz_bdb_driver.c334
-rw-r--r--contrib/dlz/drivers/dlz_bdbhpt_driver.c376
-rw-r--r--contrib/dlz/drivers/dlz_drivers.c86
-rw-r--r--contrib/dlz/drivers/dlz_filesystem_driver.c465
-rw-r--r--contrib/dlz/drivers/dlz_ldap_driver.c478
-rw-r--r--contrib/dlz/drivers/dlz_mysql_driver.c367
-rw-r--r--contrib/dlz/drivers/dlz_odbc_driver.c572
-rw-r--r--contrib/dlz/drivers/dlz_postgres_driver.c396
-rw-r--r--contrib/dlz/drivers/dlz_stub_driver.c146
l---------contrib/dlz/drivers/include/.clang-format1
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h2
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h2
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_drivers.h1
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h2
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h2
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h2
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h2
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h2
-rw-r--r--contrib/dlz/drivers/include/dlz/dlz_stub_driver.h2
-rw-r--r--contrib/dlz/drivers/include/dlz/sdlz_helper.h57
-rw-r--r--contrib/dlz/drivers/sdlz_helper.c165
-rw-r--r--contrib/dlz/example/README4
-rw-r--r--contrib/dlz/example/dlz_example.c356
-rw-r--r--contrib/dlz/example/named.conf2
-rw-r--r--contrib/dlz/example/win32/DLLMain.c52
-rw-r--r--contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c491
-rwxr-xr-xcontrib/dlz/modules/bdbhpt/testing/bdbhpt-populate.pl4
-rw-r--r--contrib/dlz/modules/common/dlz_dbi.c194
-rw-r--r--contrib/dlz/modules/filesystem/dir.c29
-rw-r--r--contrib/dlz/modules/filesystem/dir.h14
-rw-r--r--contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c421
l---------contrib/dlz/modules/include/.clang-format1
-rw-r--r--contrib/dlz/modules/include/dlz_dbi.h48
-rw-r--r--contrib/dlz/modules/include/dlz_list.h40
-rw-r--r--contrib/dlz/modules/include/dlz_minimal.h149
-rw-r--r--contrib/dlz/modules/include/dlz_pthread.h18
-rw-r--r--contrib/dlz/modules/ldap/dlz_ldap_dynamic.c598
-rw-r--r--contrib/dlz/modules/mysql/dlz_mysql_dynamic.c480
-rw-r--r--contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c638
-rw-r--r--contrib/dlz/modules/perl/dlz_perl_driver.c309
-rw-r--r--contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c419
-rw-r--r--contrib/dlz/modules/wildcard/README2
-rw-r--r--contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c341
-rw-r--r--contrib/dnspriv/nginx.conf2
-rw-r--r--contrib/kasp/kasp2policy.py109
-rw-r--r--contrib/scripts/catzhash.py32
-rw-r--r--contrib/scripts/check-secure-delegation.pl.in2
-rw-r--r--contrib/scripts/named-bootconf.sh2
-rw-r--r--contrib/scripts/nanny.pl2
-rw-r--r--contrib/scripts/zone-edit.sh.in2
53 files changed, 4537 insertions, 4261 deletions
diff --git a/contrib/dlz/bin/dlzbdb/Makefile.in b/contrib/dlz/bin/dlzbdb/Makefile.in
index 0dcf434c..3100e8c8 100644
--- a/contrib/dlz/bin/dlzbdb/Makefile.in
+++ b/contrib/dlz/bin/dlzbdb/Makefile.in
@@ -21,7 +21,7 @@ CDEFINES = @CONTRIB_DLZ@
CWARNINGS =
DLZLIBS = @DLZ_DRIVER_LIBS@
-ISCLIBS = ../../../../lib/isc/libisc.@A@ @OPENSSL_LIBS@
+ISCLIBS = ../../../../lib/isc/libisc.@A@ @NO_LIBTOOL_ISCLIBS@
DEPLIBS = ${ISCDEPLIBS}
@@ -31,12 +31,6 @@ TARGETS = dlzbdb
SRCS = dlzbdb.c
-#MANPAGES =
-
-#HTMLPAGES =
-
-#MANOBJS = ${MANPAGES} ${HTMLPAGES}
-
@BIND9_MAKE_RULES@
dlzbdb.@O@: dlzbdb.c
@@ -46,17 +40,11 @@ dlzbdb.@O@: dlzbdb.c
dlzbdb: dlzbdb.@O@ ${DEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} -o $@ dlzbdb.@O@ ${LIBS}
-doc man:: ${MANOBJS}
-
-#docclean manclean maintainer-clean::
-# rm -f ${MANOBJS}
-
clean distclean maintainer-clean::
rm -f ${TARGETS}
installdirs:
$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${sbindir}
-# $(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man8
install:: dlzbdb installdirs
${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} dlzbdb ${DESTDIR}${sbindir}
diff --git a/contrib/dlz/bin/dlzbdb/dlzbdb.c b/contrib/dlz/bin/dlzbdb/dlzbdb.c
index 49ade159..f77ebb15 100644
--- a/contrib/dlz/bin/dlzbdb/dlzbdb.c
+++ b/contrib/dlz/bin/dlzbdb/dlzbdb.c
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
- *
+ *
* 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 STICHTING NLNET
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
@@ -14,15 +14,15 @@
* 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.
- *
+ *
* The development of Dynamically Loadable Zones (DLZ) for Bind 9 was
* conceived and contributed by Rob Butler.
- *
+ *
* 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 ROB BUTLER
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
@@ -52,12 +52,11 @@
* 4 Unable to allocate memory for, or create lexer.
* 5 unable to perform BDB cursor operation
*/
-
-#include <config.h>
+#include <db.h>
#include <stdbool.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <isc/buffer.h>
#include <isc/commandline.h>
@@ -68,8 +67,6 @@
#include <isc/string.h>
#include <isc/util.h>
-#include <db.h>
-
/* shut up compiler warnings about no previous prototype */
static void
@@ -114,9 +111,8 @@ operation_bulk(void);
void
operation_listOrDelete(bool dlt);
-
/*%
- * Maximum length of a single data line that
+ * Maximum length of a single data line that
* may be inserted into database by this program.
* If you need to insert a line of data that is more
* than 10,000 characters change this definition.
@@ -126,15 +122,14 @@ operation_listOrDelete(bool dlt);
/*%
* BDB database names. If you want to use different
- * database names change them here.
+ * database names change them here.
*/
-#define dlz_data "dns_data"
-#define dlz_zone "dns_zone"
-#define dlz_host "dns_host"
+#define dlz_data "dns_data"
+#define dlz_zone "dns_zone"
+#define dlz_host "dns_host"
#define dlz_client "dns_client"
-
/*%
* Error code returned by BDB secondary index callback functions.
* This error is returned if the callback function could not create
@@ -146,31 +141,33 @@ operation_listOrDelete(bool dlt);
/* A struct to hold all the relevant info about the database */
typedef struct bdb_instance {
- DB_ENV *dbenv; /* BDB environment */
- DB *data; /* dns_data database handle */
- DBC *cursor; /* database cursor */
- DBC *cursor2; /* second cursor used during list operation. */
- DBC *cursor3; /* third cursor used during list operation */
- DBC *cursor4; /* fourth cursor used during list operation */
- DB *zone; /* zone database handle */
- DB *host; /* host database handle */
- DB *client; /* client database handle */
+ DB_ENV *dbenv; /* BDB environment */
+ DB *data; /* dns_data database handle */
+ DBC *cursor; /* database cursor */
+ DBC *cursor2; /* second cursor used during list operation. */
+ DBC *cursor3; /* third cursor used during list operation */
+ DBC *cursor4; /* fourth cursor used during list operation */
+ DB *zone; /* zone database handle */
+ DB *host; /* host database handle */
+ DB *client; /* client database handle */
} bdb_instance_t;
/* Possible operations */
-#define list 1 /* list data */
-#define dele 2 /* delete data */
-#define add 3 /* add a single piece of data */
-#define bulk 4 /* bulk load data */
-
+#define list 1 /* list data */
+#define dele 2 /* delete data */
+#define add 3 /* add a single piece of data */
+#define bulk 4 /* bulk load data */
/*%
- * quit macro is used instead of exit. quit always trys to close the lexer
+ * quit macro is used instead of exit. quit always tries to close the lexer
* and the BDB database before exiting.
*/
-#define quit(i) close_lexer(); bdb_cleanup(); exit(i);
+#define quit(i) \
+ close_lexer(); \
+ bdb_cleanup(); \
+ exit(i);
/*%
* checkOp is used to verify that only one operation (list, del, add,
@@ -179,8 +176,12 @@ typedef struct bdb_instance {
* line, which would make no sense anyway.
*/
-#define checkOp(x) if (x != 0) {fprintf(stderr, "\nonly one operation "\
- "(l e d a f s) may be specified\n"); quit(2);}
+#define checkOp(x) \
+ if (x != 0) { \
+ fprintf(stderr, "\nonly one operation " \
+ "(l e d a f s) may be specified\n"); \
+ quit(2); \
+ }
/*%
* checkParam is used to only allow a parameter to be specified once.
@@ -188,53 +189,70 @@ typedef struct bdb_instance {
* any attempt to use it twice causes an error.
*/
-#define checkParam(x, y) if (x != NULL) {fprintf(stderr, "\n%s may only "\
- "be specified once\n", y); quit(2);}
+#define checkParam(x, y) \
+ if (x != NULL) { \
+ fprintf(stderr, \
+ "\n%s may only " \
+ "be specified once\n", \
+ y); \
+ quit(2); \
+ }
/*%
- * checkInvalidParam is used to only allow paramters which make sense for
+ * checkInvalidParam is used to only allow parameters which make sense for
* the operation selected. I.E. passing the key parameter makes no sense
* for the add operation, and thus it isn't allowed.
*/
-#define checkInvalidParam(x, y, z) if (x != NULL) {fprintf(stderr, "\n%s "\
- "may not be specified %s\n", y, z); quit(2);}
+#define checkInvalidParam(x, y, z) \
+ if (x != NULL) { \
+ fprintf(stderr, \
+ "\n%s " \
+ "may not be specified %s\n", \
+ y, z); \
+ quit(2); \
+ }
/*%
- * checkInvalidOption is used to only allow paramters which make sense for
+ * checkInvalidOption is used to only allow parameters which make sense for
* the operation selected - but checks boolean options.
* I.E. passing the "b" bare_list parameter makes no sense for the add
* operation, and thus it isn't allowed.
* if w == x then output error message "flag", "message"
*/
-#define checkInvalidOption(w, x, y, z) if (w == x) {fprintf(stderr, "\n%s "\
- "may not be specified %s\n", y, z); quit(2);}
+#define checkInvalidOption(w, x, y, z) \
+ if (w == x) { \
+ fprintf(stderr, \
+ "\n%s " \
+ "may not be specified %s\n", \
+ y, z); \
+ quit(2); \
+ }
/* Global Variables */
-int operation = 0; /*%< operation to perform. */
+int operation = 0; /*%< operation to perform. */
/*% allow new lock files or DB to be created. */
bool create_allowed = false;
-char *key = NULL; /*%< key to use in list & del operations */
+char *key = NULL; /*%< key to use in list & del operations */
/*% dump DB in DLZBDB bulk format */
-bool list_everything = false;
+bool list_everything = false;
unsigned int key_val; /*%< key as unsigned int used in list & del operations */
-char *zone = NULL; /*%< zone to use in list operations */
-char *host = NULL; /*%< host to use in list operations */
-char *c_zone = NULL; /*%< client zone to use in list operations */
-char *c_ip = NULL; /*%< client IP to use in list operations */
-char *a_data = NULL; /*%< data in add operation */
-char *bulk_file = NULL; /*%< bulk data file to load */
-char *db_envdir = NULL; /*%< BDB environment location */
-char *db_file = NULL; /*%< BDB database file location. */
-bdb_instance_t db; /* BDB instance we are operating on */
-isc_lex_t *lexer = NULL; /*%< lexer for use to use in parsing input */
-isc_mem_t *lex_mctx = NULL; /*%< memory context for lexer */
+char *zone = NULL; /*%< zone to use in list operations */
+char *host = NULL; /*%< host to use in list operations */
+char *c_zone = NULL; /*%< client zone to use in list operations */
+char *c_ip = NULL; /*%< client IP to use in list operations */
+char *a_data = NULL; /*%< data in add operation */
+char *bulk_file = NULL; /*%< bulk data file to load */
+char *db_envdir = NULL; /*%< BDB environment location */
+char *db_file = NULL; /*%< BDB database file location. */
+bdb_instance_t db; /* BDB instance we are operating on */
+isc_lex_t *lexer = NULL; /*%< lexer for use to use in parsing input */
+isc_mem_t *lex_mctx = NULL; /*%< memory context for lexer */
char lex_data_buf[max_data_len]; /*%< data array to use for lex_buffer below */
-isc_buffer_t lex_buffer; /*%< buffer for lexer during add operation */
-
+isc_buffer_t lex_buffer; /*%< buffer for lexer during add operation */
/*%
* Displays usage message
@@ -279,10 +297,9 @@ d mynm.com @ SOA 10 ns1.mynm.com. root.mynm.com. 2 28800 7200 604800 86400\n\
c mynm.com 127.0.0.1\n\
c mynm.com 192.168.0.10\n\
");
-quit(1);
+ quit(1);
}
-
/*% BDB callback to create zone secondary index */
int
@@ -293,18 +310,18 @@ getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
UNUSED(pkey);
if ((token = strtok_r(pdata->data, " ", &last)) == NULL) {
- return BDBparseErr;
+ return (BDBparseErr);
}
/* copy string for "zone" secondary index */
if ((skey->data = strdup(token)) == NULL) {
- return BDBparseErr;
+ return (BDBparseErr);
}
/* set required values for BDB */
skey->size = strlen(skey->data);
skey->flags = DB_DBT_APPMALLOC;
- return 0;
+ return (0);
}
/*%
@@ -320,23 +337,23 @@ gethost(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
/* we don't care about first token. */
if ((token = strtok_r(right, " ", &last)) == NULL) {
- return BDBparseErr;
+ return (BDBparseErr);
}
/* get "host" from data string */
if ((token = strtok_r(NULL, " ", &last)) == NULL) {
- return BDBparseErr;
+ return (BDBparseErr);
}
-
+
/* copy string for "host" secondary index */
if ((skey->data = strdup(token)) == NULL) {
- return BDBparseErr;
+ return (BDBparseErr);
}
/* set required values for BDB */
skey->size = strlen(skey->data);
skey->flags = DB_DBT_APPMALLOC;
- return 0;
+ return (0);
}
/*%
@@ -347,7 +364,6 @@ gethost(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
void
bdb_cleanup(void) {
-
/* close cursors */
if (db.cursor4 != NULL) {
db.cursor4->c_close(db.cursor4);
@@ -398,36 +414,40 @@ bdb_cleanup(void) {
isc_result_t
bdb_opendb(DBTYPE db_type, DB **db_out, const char *db_name, int flags) {
-
int result;
int createFlag = 0;
/* Initialize the database. */
if ((result = db_create(db_out, db.dbenv, 0)) != 0) {
- fprintf(stderr, "BDB could not initialize %s database. BDB error: %s",
+ fprintf(stderr,
+ "BDB could not initialize %s database. BDB error: %s",
db_name, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* set database flags. */
if ((result = (*db_out)->set_flags(*db_out, flags)) != 0) {
- fprintf(stderr, "BDB could not set flags for %s database. BDB error: %s",
+ fprintf(stderr,
+ "BDB could not set flags for %s database. BDB error: "
+ "%s",
db_name, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
- if (create_allowed == true) {
+ if (create_allowed) {
createFlag = DB_CREATE;
}
/* open the database. */
if ((result = (*db_out)->open(*db_out, NULL, db_file, db_name, db_type,
- createFlag, 0)) != 0) {
- fprintf(stderr, "BDB could not open %s database in %s. BDB error: %s",
+ createFlag, 0)) != 0)
+ {
+ fprintf(stderr,
+ "BDB could not open %s database in %s. BDB error: %s",
db_name, db_file, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
}
/*%
@@ -439,7 +459,6 @@ bdb_opendb(DBTYPE db_type, DB **db_out, const char *db_name, int flags) {
void
put_data(bool dns_data, char *input_key, char *input_data) {
-
int bdbres;
DBT key, data;
@@ -475,50 +494,57 @@ put_data(bool dns_data, char *input_key, char *input_data) {
void
insert_data(void) {
- unsigned int opt =
- ISC_LEXOPT_EOL | /* Want end-of-line token. */
- ISC_LEXOPT_EOF | /* Want end-of-file token. */
- ISC_LEXOPT_QSTRING | /* Recognize qstrings. */
- ISC_LEXOPT_QSTRINGMULTILINE; /* Allow multiline "" strings */
+ unsigned int opt = ISC_LEXOPT_EOL | /* Want end-of-line token. */
+ ISC_LEXOPT_EOF | /* Want end-of-file token. */
+ ISC_LEXOPT_QSTRING | /* Recognize qstrings. */
+ ISC_LEXOPT_QSTRINGMULTILINE; /* Allow multiline ""
+ * strings */
isc_result_t result;
- isc_token_t token; /* token from lexer */
+ isc_token_t token; /* token from lexer */
bool loop = true;
bool have_czone = false;
char data_arr[max_data_len];
isc_buffer_t buf;
char data_arr2[max_data_len];
isc_buffer_t buf2;
- char data_type = 'u'; /* u =unknown, b =bad token, d/D =DNS, c/C =client IP */
+ char data_type = 'u'; /* u =unknown, b =bad token, d/D =DNS, c/C =client
+ * IP */
/* Initialize buffers */
isc_buffer_init(&buf, &data_arr, max_data_len);
isc_buffer_init(&buf2, &data_arr2, max_data_len);
while (loop) {
- result = isc_lex_gettoken(lexer, opt, &token);
- if (result != ISC_R_SUCCESS)
+ result = isc_lex_gettoken(lexer, opt, &token);
+ if (result != ISC_R_SUCCESS) {
goto data_cleanup;
+ }
- switch(token.type) {
+ switch (token.type) {
case isc_tokentype_string:
if (data_type == 'u') {
/* store data_type */
strncpy(&data_type, token.value.as_pointer, 1);
- /* verify data_type was specified correctly on input */
- if (strlen(token.value.as_pointer) > 1 || (
- data_type != 'd' && data_type != 'D' &&
- data_type != 'c' && data_type != 'C') ) {
- /* if not, set to 'b' so this line is ignored. */
+ /* verify data_type was specified correctly on
+ * input */
+ if (strlen(token.value.as_pointer) > 1 ||
+ (data_type != 'd' && data_type != 'D' &&
+ data_type != 'c' && data_type != 'C'))
+ {
+ /* if not, set to 'b' so this line is
+ * ignored. */
data_type = 'b';
}
} else if (data_type == 'c' || data_type == 'C') {
- if (have_czone == true) {
- isc_buffer_putstr(&buf2, token.value.as_pointer);
+ if (have_czone) {
+ isc_buffer_putstr(
+ &buf2, token.value.as_pointer);
/* add string terminator to buffer */
isc_buffer_putmem(&buf2, "\0", 1);
} else {
- isc_buffer_putstr(&buf, token.value.as_pointer);
+ isc_buffer_putstr(
+ &buf, token.value.as_pointer);
/* add string terminator to buffer */
isc_buffer_putmem(&buf, "\0", 1);
have_czone = true;
@@ -535,34 +561,45 @@ insert_data(void) {
break;
case isc_tokentype_eol:
case isc_tokentype_eof:
-
- if ((data_type != 'u' && isc_buffer_usedlength(&buf) > 0) || data_type == 'b') {
+
+ if ((data_type != 'u' &&
+ isc_buffer_usedlength(&buf) > 0) ||
+ data_type == 'b') {
/* perform insert operation */
if (data_type == 'd' || data_type == 'D') {
/* add string terminator to buffer */
isc_buffer_putmem(&buf, "\0", 1);
- put_data(true, NULL, (char *) &data_arr);
- } else if (data_type == 'c' || data_type == 'C') {
- put_data(false, (char *) &data_arr,
- (char *) &data_arr2);
+ put_data(true, NULL, (char *)&data_arr);
+ } else if (data_type == 'c' || data_type == 'C')
+ {
+ put_data(false, (char *)&data_arr,
+ (char *)&data_arr2);
} else if (data_type == 'b') {
- fprintf(stderr, "Bad / unknown token encountered on line %lu."\
- " Skipping line.", isc_lex_getsourceline(lexer) - 1);
+ fprintf(stderr,
+ "Bad / unknown token "
+ "encountered on line %lu."
+ " Skipping line.",
+ isc_lex_getsourceline(lexer) -
+ 1);
} else {
- fprintf(stderr, "Bad / unknown db data type encountered on " \
- "line %lu. Skipping line\n", isc_lex_getsourceline(lexer) - 1);
+ fprintf(stderr,
+ "Bad / unknown db data type "
+ "encountered on "
+ "line %lu. Skipping line\n",
+ isc_lex_getsourceline(lexer) -
+ 1);
}
}
if (token.type == isc_tokentype_eof) {
loop = false;
- }
+ }
/* reset buffer for next insert */
isc_buffer_clear(&buf);
isc_buffer_clear(&buf2);
have_czone = false;
- data_type ='u';
+ data_type = 'u';
break;
default:
data_type = 'b';
@@ -572,17 +609,16 @@ insert_data(void) {
return;
- data_cleanup:
+data_cleanup:
/* let user know we had problems */
- fprintf(stderr, "Unknown error processing tokens during \"add\" or " \
- "\"bulk\" operation.\nStoped processing on line %lu.",
+ fprintf(stderr,
+ "Unknown error processing tokens during \"add\" or "
+ "\"bulk\" operation.\nStoped processing on line %lu.",
isc_lex_getsourceline(lexer));
}
-
isc_result_t
openBDB(void) {
-
int bdbres;
isc_result_t result;
@@ -590,24 +626,28 @@ openBDB(void) {
/* Basically BDB allocates and assigns memory to db->dbenv */
bdbres = db_env_create(&db.dbenv, 0);
if (bdbres != 0) {
- fprintf(stderr, "BDB environment could not be created. BDB error: %s",
+ fprintf(stderr,
+ "BDB environment could not be created. BDB error: %s",
db_strerror(bdbres));
result = ISC_R_FAILURE;
goto openBDB_cleanup;
}
/* open BDB environment */
- if (create_allowed == true) {
+ if (create_allowed) {
/* allowed to create new files */
- bdbres = db.dbenv->open(db.dbenv, db_envdir,
- DB_INIT_CDB | DB_INIT_MPOOL | DB_CREATE, 0);
- } else { /* not allowed to create new files. */
- bdbres = db.dbenv->open(db.dbenv, db_envdir,
+ bdbres = db.dbenv->open(db.dbenv, db_envdir,
+ DB_INIT_CDB | DB_INIT_MPOOL | DB_CREATE,
+ 0);
+ } else { /* not allowed to create new files. */
+ bdbres = db.dbenv->open(db.dbenv, db_envdir,
DB_INIT_CDB | DB_INIT_MPOOL, 0);
}
if (bdbres != 0) {
- fprintf(stderr, "BDB environment at '%s' could not be opened. BDB " \
- "error: %s", db_envdir, db_strerror(bdbres));
+ fprintf(stderr,
+ "BDB environment at '%s' could not be opened. BDB "
+ "error: %s",
+ db_envdir, db_strerror(bdbres));
result = ISC_R_FAILURE;
goto openBDB_cleanup;
}
@@ -615,29 +655,36 @@ openBDB(void) {
/* open dlz_data database. */
result = bdb_opendb(DB_RECNO, &db.data, dlz_data, 0);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto openBDB_cleanup;
-
+ }
+
/* open dlz_host database */
result = bdb_opendb(DB_BTREE, &db.host, dlz_host, DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto openBDB_cleanup;
+ }
/* open dlz_zone database. */
result = bdb_opendb(DB_BTREE, &db.zone, dlz_zone, DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto openBDB_cleanup;
+ }
/* open dlz_client database. */
- result = bdb_opendb(DB_BTREE, &db.client, dlz_client, DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ result = bdb_opendb(DB_BTREE, &db.client, dlz_client,
+ DB_DUP | DB_DUPSORT);
+ if (result != ISC_R_SUCCESS) {
goto openBDB_cleanup;
+ }
/* associate the host secondary database with the primary database */
bdbres = db.data->associate(db.data, NULL, db.host, gethost, 0);
if (bdbres != 0) {
- fprintf(stderr, "BDB could not associate %s database with %s. BDB "\
- "error: %s", dlz_host, dlz_data, db_strerror(bdbres));
+ fprintf(stderr,
+ "BDB could not associate %s database with %s. BDB "
+ "error: %s",
+ dlz_host, dlz_data, db_strerror(bdbres));
result = ISC_R_FAILURE;
goto openBDB_cleanup;
}
@@ -645,18 +692,20 @@ openBDB(void) {
/* associate the zone secondary database with the primary database */
bdbres = db.data->associate(db.data, NULL, db.zone, getzone, 0);
if (bdbres != 0) {
- fprintf(stderr, "BDB could not associate %s database with %s. BDB "\
- "error: %s", dlz_zone, dlz_data, db_strerror(bdbres));
+ fprintf(stderr,
+ "BDB could not associate %s database with %s. BDB "
+ "error: %s",
+ dlz_zone, dlz_data, db_strerror(bdbres));
result = ISC_R_FAILURE;
goto openBDB_cleanup;
}
- return result;
+ return (result);
- openBDB_cleanup:
+openBDB_cleanup:
bdb_cleanup();
- return result;
+ return (result);
}
/*% Create & open lexer to parse input data */
@@ -666,36 +715,39 @@ open_lexer(void) {
isc_result_t result;
/* check if we already opened the lexer, if we did, return success */
- if (lexer != NULL)
- return ISC_R_SUCCESS;
+ if (lexer != NULL) {
+ return (ISC_R_SUCCESS);
+ }
/* allocate memory for lexer, and verify it was allocated */
- result = isc_mem_create(0, 0, &lex_mctx);
- if (result != ISC_R_SUCCESS) {
- fprintf(stderr, "unexpected error creating lexer\n");
- return result;
- }
+ isc_mem_create(&lex_mctx);
/* create lexer */
result = isc_lex_create(lex_mctx, 1500, &lexer);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
fprintf(stderr, "unexpected error creating lexer\n");
+ }
/* set allowed commenting style */
- isc_lex_setcomments(lexer, ISC_LEXCOMMENT_C | /* Allow C comments */
- ISC_LEXCOMMENT_CPLUSPLUS | /* Allow C++ comments */
- ISC_LEXCOMMENT_SHELL); /* Allow shellcomments */
+ isc_lex_setcomments(lexer,
+ ISC_LEXCOMMENT_C | /* Allow C comments */
+ ISC_LEXCOMMENT_CPLUSPLUS | /* Allow
+ * C++
+ * comments
+ */
+ ISC_LEXCOMMENT_SHELL); /* Allow
+ * shellcomments
+ */
isc_buffer_init(&lex_buffer, &lex_data_buf, max_data_len);
- return result;
+ return (result);
}
/*% Close the lexer, and cleanup memory */
void
close_lexer(void) {
-
/* If lexer is still open, close it & destroy it. */
if (lexer != NULL) {
isc_lex_close(lexer);
@@ -703,8 +755,9 @@ close_lexer(void) {
}
/* if lexer memory is still allocated, destroy it. */
- if (lex_mctx != NULL)
+ if (lex_mctx != NULL) {
isc_mem_destroy(&lex_mctx);
+ }
}
/*% Perform add operation */
@@ -717,24 +770,24 @@ operation_add(void) {
checkInvalidParam(host, "h", "for add operation");
checkInvalidParam(c_zone, "c", "for add operation");
checkInvalidParam(c_ip, "i", "for add operation");
- checkInvalidOption(list_everything, true, "e",
- "for add operation");
+ checkInvalidOption(list_everything, true, "e", "for add operation");
- /* if open lexer fails it alread prints error messages. */
+ /* if open lexer fails it already prints error messages. */
if (open_lexer() != ISC_R_SUCCESS) {
quit(4);
}
-
+
/* copy input data to buffer */
isc_buffer_putstr(&lex_buffer, a_data);
-
+
/* tell lexer to use buffer as input */
if (isc_lex_openbuffer(lexer, &lex_buffer) != ISC_R_SUCCESS) {
fprintf(stderr, "unexpected error opening lexer buffer");
quit(4);
}
- /*common logic for "add" & "bulk" operations are handled by insert_data */
+ /*common logic for "add" & "bulk" operations are handled by insert_data
+ */
insert_data();
}
@@ -758,21 +811,23 @@ operation_bulk(void) {
if (bulk_file == NULL) {
if (isc_lex_openstream(lexer, stdin) != ISC_R_SUCCESS) {
- fprintf(stderr, "unexpected error opening stdin by lexer.");
- quit(4);
+ fprintf(stderr, "unexpected error opening stdin by "
+ "lexer.");
+ quit(4);
}
} else if (isc_lex_openfile(lexer, bulk_file) != ISC_R_SUCCESS) {
- fprintf(stderr, "unexpected error opening %s by lexer.", bulk_file);
+ fprintf(stderr, "unexpected error opening %s by lexer.",
+ bulk_file);
quit(4);
}
- /* common logic for "add" & "bulk" operations are handled by insert_data */
- insert_data();
+ /* common logic for "add" & "bulk" operations are handled by insert_data
+ */
+ insert_data();
}
isc_result_t
bulk_write(char type, DB *database, DBC *dbcursor, DBT *bdbkey, DBT *bdbdata) {
-
int bdbres;
db_recno_t recNum;
char *retkey = NULL, *retdata;
@@ -781,13 +836,13 @@ bulk_write(char type, DB *database, DBC *dbcursor, DBT *bdbkey, DBT *bdbdata) {
/* use a 5MB buffer for the bulk dump */
int buffer_size = 5 * 1024 * 1024;
-
+
/* try to allocate a 5 MB buffer, if we fail write err msg, die. */
bdbdata->data = malloc(buffer_size);
if (bdbdata->data == NULL) {
- fprintf(stderr,
- "Unable to allocate 5 MB buffer for bulk database dump\n");
- return ISC_R_FAILURE;
+ fprintf(stderr, "Unable to allocate 5 MB buffer for bulk "
+ "database dump\n");
+ return (ISC_R_FAILURE);
}
bdbdata->ulen = buffer_size;
bdbdata->flags = DB_DBT_USERMEM;
@@ -795,50 +850,56 @@ bulk_write(char type, DB *database, DBC *dbcursor, DBT *bdbkey, DBT *bdbdata) {
/* get a cursor, make sure it worked. */
bdbres = database->cursor(database, NULL, &dbcursor, 0);
if (bdbres != 0) {
- fprintf(stderr, "Unexpected error. BDB Error: %s\n",db_strerror(bdbres));
+ fprintf(stderr, "Unexpected error. BDB Error: %s\n",
+ db_strerror(bdbres));
free(bdbdata->data);
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* loop and dump all data */
for (;;) {
-
/* loop through data until DB_NOTFOUND is returned */
- bdbres = dbcursor->c_get(dbcursor, bdbkey, bdbdata,
+ bdbres = dbcursor->c_get(dbcursor, bdbkey, bdbdata,
DB_MULTIPLE_KEY | DB_NEXT);
/* if not successful did we encounter DB_NOTFOUND, or */
/* have a different problem. */
if (bdbres != 0) {
if (bdbres != DB_NOTFOUND) {
- fprintf(stderr, "Unexpected error. BDB Error: %s\n",
+ fprintf(stderr,
+ "Unexpected error. BDB Error: %s\n",
db_strerror(bdbres));
free(bdbdata->data);
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* Hit DB_NOTFOUND which means end of data. */
break;
} /* end of if (bdbres !=0) */
for (DB_MULTIPLE_INIT(p, bdbdata);;) {
- if (type == 'c')
- DB_MULTIPLE_KEY_NEXT(p, bdbdata, retkey, retklen, retdata, retdlen);
- else
- DB_MULTIPLE_RECNO_NEXT(p, bdbdata, recNum, retdata, retdlen);
+ if (type == 'c') {
+ DB_MULTIPLE_KEY_NEXT(p, bdbdata, retkey,
+ retklen, retdata, retdlen);
+ } else {
+ DB_MULTIPLE_RECNO_NEXT(p, bdbdata, recNum,
+ retdata, retdlen);
+ }
- if (p == NULL)
+ if (p == NULL) {
break;
- if (type == 'c')
- printf("c %.*s %.*s\n",(int)retklen, retkey,(int)retdlen, retdata);
- else
- printf("d %.*s\n", (int)retdlen, retdata);
+ }
+ if (type == 'c') {
+ printf("c %.*s %.*s\n", (int)retklen, retkey,
+ (int)retdlen, retdata);
+ } else {
+ printf("d %.*s\n", (int)retdlen, retdata);
+ }
} /* end of for (DB_MULTIPLE_INIT....) */
-
- } /* end of for (;;) */
+ } /* end of for (;;) */
/* free the buffer we created earlier */
free(bdbdata->data);
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
}
/*%
@@ -849,16 +910,14 @@ bulk_write(char type, DB *database, DBC *dbcursor, DBT *bdbkey, DBT *bdbdata) {
void
operation_listOrDelete(bool dlt) {
-
int bdbres = 0;
DBC *curList[3];
DBT bdbkey, bdbdata;
db_recno_t recno;
int curIndex = 0;
-
/* verify that only allowed parameters were passed. */
- if (dlt == true) {
+ if (dlt) {
checkInvalidParam(zone, "z", "for delete operation");
checkInvalidParam(host, "h", "for delete operation");
checkInvalidOption(list_everything, true, "e",
@@ -866,8 +925,10 @@ operation_listOrDelete(bool dlt) {
checkInvalidOption(create_allowed, true, "n",
"for delete operation");
} else if (key != NULL || zone != NULL || host != NULL) {
- checkInvalidParam(c_zone, "c", "for list when k, z or h are specified");
- checkInvalidParam(c_ip, "i", "for list when k, z, or h are specified");
+ checkInvalidParam(c_zone, "c",
+ "for list when k, z or h are specified");
+ checkInvalidParam(c_ip, "i",
+ "for list when k, z, or h are specified");
checkInvalidOption(list_everything, true, "e",
"for list when k, z, or h are specified");
checkInvalidOption(create_allowed, true, "n",
@@ -883,10 +944,11 @@ operation_listOrDelete(bool dlt) {
memset(&bdbdata, 0, sizeof(bdbdata));
/* Dump database in "dlzbdb" bulk format */
- if (list_everything == true) {
- if (bulk_write('c', db.client, db.cursor, &bdbkey, &bdbdata)
- != ISC_R_SUCCESS)
+ if (list_everything) {
+ if (bulk_write('c', db.client, db.cursor, &bdbkey, &bdbdata) !=
+ ISC_R_SUCCESS) {
return;
+ }
memset(&bdbkey, 0, sizeof(bdbkey));
memset(&bdbdata, 0, sizeof(bdbdata));
bulk_write('d', db.data, db.cursor2, &bdbkey, &bdbdata);
@@ -907,24 +969,25 @@ operation_listOrDelete(bool dlt) {
bdbkey.data = &recno;
bdbkey.size = sizeof(recno);
- if (dlt == true) {
+ if (dlt) {
bdbres = db.data->del(db.data, NULL, &bdbkey, 0);
} else {
bdbdata.flags = DB_DBT_REALLOC;
- bdbres = db.data->get(db.data, NULL, &bdbkey, &bdbdata, 0);
+ bdbres = db.data->get(db.data, NULL, &bdbkey, &bdbdata,
+ 0);
if (bdbres == 0) {
printf("KEY | DATA\n");
- printf("%lu | %.*s\n", *(u_long *) bdbkey.data,
+ printf("%lu | %.*s\n", *(u_long *)bdbkey.data,
(int)bdbdata.size, (char *)bdbdata.data);
}
} /* closes else of if (dlt == true) */
if (bdbres == DB_NOTFOUND) {
printf("Key not found in database");
}
- } /* closes if (key != NULL) */
+ } /* closes if (key != NULL) */
- /* if zone is passed */
+ /* if zone is passed */
if (zone != NULL) {
/* create a cursor and make sure it worked */
bdbres = db.zone->cursor(db.zone, NULL, &db.cursor2, 0);
@@ -936,10 +999,12 @@ operation_listOrDelete(bool dlt) {
bdbkey.data = zone;
bdbkey.size = strlen(zone);
- bdbres = db.cursor2->c_get(db.cursor2, &bdbkey, &bdbdata, DB_SET);
+ bdbres = db.cursor2->c_get(db.cursor2, &bdbkey, &bdbdata,
+ DB_SET);
if (bdbres != 0) {
if (bdbres != DB_NOTFOUND) {
- fprintf(stderr, "Unexpected error. BDB Error: %s\n",
+ fprintf(stderr,
+ "Unexpected error. BDB Error: %s\n",
db_strerror(bdbres));
} else {
printf("Zone not found in database");
@@ -953,7 +1018,6 @@ operation_listOrDelete(bool dlt) {
/* if host is passed */
if (host != NULL) {
-
/* create a cursor and make sure it worked. */
bdbres = db.host->cursor(db.host, NULL, &db.cursor3, 0);
if (bdbres != 0) {
@@ -963,10 +1027,12 @@ operation_listOrDelete(bool dlt) {
}
bdbkey.data = host;
bdbkey.size = strlen(host);
- bdbres = db.cursor3->c_get(db.cursor3, &bdbkey, &bdbdata, DB_SET);
+ bdbres = db.cursor3->c_get(db.cursor3, &bdbkey, &bdbdata,
+ DB_SET);
if (bdbres != 0) {
if (bdbres != DB_NOTFOUND) {
- fprintf(stderr, "Unexpected error. BDB Error: %s\n",
+ fprintf(stderr,
+ "Unexpected error. BDB Error: %s\n",
db_strerror(bdbres));
} else {
printf("Host not found in database");
@@ -978,9 +1044,7 @@ operation_listOrDelete(bool dlt) {
curList[curIndex++] = db.cursor3;
}
-
if (zone != NULL || host != NULL) {
-
/* join any cursors */
bdbres = db.data->join(db.data, curList, &db.cursor4, 0);
if (bdbres != 0) {
@@ -997,33 +1061,35 @@ operation_listOrDelete(bool dlt) {
/* print a header to explain the output */
printf("KEY | DATA\n");
/* loop and list all results. */
- while (bdbres == 0) {
+ while (bdbres == 0) {
/* get data */
- bdbres = db.cursor4->c_get(db.cursor4, &bdbkey, &bdbdata, 0);
+ bdbres = db.cursor4->c_get(db.cursor4, &bdbkey,
+ &bdbdata, 0);
/* verify call had no errors */
if (bdbres != 0) {
break;
}
- printf("%lu | %.*s\n", *(u_long *) bdbkey.data,
+ printf("%lu | %.*s\n", *(u_long *)bdbkey.data,
(int)bdbdata.size, (char *)bdbdata.data);
} /* closes while loop */
}
if (c_ip != NULL && c_zone == NULL) {
- fprintf(stderr, "i may only be specified when c is also specified\n");
+ fprintf(stderr, "i may only be specified when c is also "
+ "specified\n");
quit(2);
}
/* if client_zone was passed */
if (c_zone != NULL) {
-
/* create a cursor and make sure it worked. */
- if (dlt == true) {
+ if (dlt) {
/* open read-write cursor */
bdbres = db.client->cursor(db.client, NULL, &db.cursor,
DB_WRITECURSOR);
} else {
/* open read only cursor */
- bdbres = db.client->cursor(db.client, NULL, &db.cursor, 0);
+ bdbres = db.client->cursor(db.client, NULL, &db.cursor,
+ 0);
/* print a header to explain the output */
printf("CLIENT_ZONE | CLIENT_IP\n");
}
@@ -1034,27 +1100,33 @@ operation_listOrDelete(bool dlt) {
if (c_ip != NULL) {
bdbdata.data = c_ip;
bdbdata.size = strlen(c_ip);
- bdbres = db.cursor->c_get(db.cursor, &bdbkey, &bdbdata, DB_GET_BOTH);
+ bdbres = db.cursor->c_get(db.cursor, &bdbkey, &bdbdata,
+ DB_GET_BOTH);
if (bdbres == DB_NOTFOUND) {
- printf("Client zone & IP not found in database");
+ printf("Client zone & IP not found in "
+ "database");
}
} else {
bdbdata.flags = DB_DBT_REALLOC;
- bdbres = db.cursor->c_get(db.cursor, &bdbkey, &bdbdata, DB_SET);
+ bdbres = db.cursor->c_get(db.cursor, &bdbkey, &bdbdata,
+ DB_SET);
if (bdbres == DB_NOTFOUND) {
printf("Client zone not found in database");
}
}
while (bdbres == 0) {
- if (dlt == false) {
- printf("%.*s | %.*s\n", (int)bdbkey.size, (char *) bdbkey.data,
- (int)bdbdata.size, (char *) bdbdata.data);
+ if (!dlt) {
+ printf("%.*s | %.*s\n", (int)bdbkey.size,
+ (char *)bdbkey.data, (int)bdbdata.size,
+ (char *)bdbdata.data);
} else {
/* delete record. */
bdbres = db.cursor->c_del(db.cursor, 0);
if (bdbres != 0) {
- fprintf(stderr, "Unexpected error. BDB Error: %s\n",
+ fprintf(stderr,
+ "Unexpected error. BDB Error: "
+ "%s\n",
db_strerror(bdbres));
break;
}
@@ -1062,17 +1134,19 @@ operation_listOrDelete(bool dlt) {
if (c_ip != NULL) {
break;
}
- bdbres = db.cursor->c_get(db.cursor, &bdbkey, &bdbdata, DB_NEXT_DUP);
+ bdbres = db.cursor->c_get(db.cursor, &bdbkey, &bdbdata,
+ DB_NEXT_DUP);
if (bdbres != 0) {
break;
}
} /* end while loop */
}
-
if (bdbres != 0 && bdbres != DB_NOTFOUND) {
- fprintf(stderr, "Unexpected error during list operation " \
- "BDB error: %s", db_strerror(bdbres));
+ fprintf(stderr,
+ "Unexpected error during list operation "
+ "BDB error: %s",
+ db_strerror(bdbres));
}
if (bdbkey.flags == DB_DBT_REALLOC && bdbkey.data != NULL) {
@@ -1083,19 +1157,19 @@ operation_listOrDelete(bool dlt) {
}
}
-
int
main(int argc, char **argv) {
-
int ch;
char *endp;
/* there has to be at least 2 args, some operations require more */
- if (argc < 2)
+ if (argc < 2) {
show_usage();
+ }
/* use the ISC commandline parser to get all the program arguments */
- while ((ch= isc_commandline_parse(argc, argv, "ldesna:f:k:z:h:c:i:")) != -1) {
+ while ((ch = isc_commandline_parse(argc, argv,
+ "ldesna:f:k:z:h:c:i:")) != -1) {
switch (ch) {
case 'n':
create_allowed = true;
@@ -1111,7 +1185,7 @@ main(int argc, char **argv) {
case 'a':
checkOp(operation);
operation = add;
- a_data = isc_commandline_argument;
+ a_data = isc_commandline_argument;
break;
case 'f':
checkOp(operation);
@@ -1127,7 +1201,8 @@ main(int argc, char **argv) {
key = isc_commandline_argument;
key_val = strtoul(key, &endp, 10);
if (*endp != '\0' || key_val < 1) {
- fprintf(stderr, "Error converting key to integer");
+ fprintf(stderr, "Error converting key to "
+ "integer");
}
break;
case 'z':
@@ -1156,7 +1231,8 @@ main(int argc, char **argv) {
break;
default:
/* should never reach this point */
- fprintf(stderr, "unexpected error parsing command arguments\n");
+ fprintf(stderr, "unexpected error parsing command "
+ "arguments\n");
quit(1);
break;
}
@@ -1166,17 +1242,21 @@ main(int argc, char **argv) {
argv += isc_commandline_index;
/* argc & argv have been modified, so now only "extra" parameters are */
- /* left in argc & argv. "Extra" parameters are any parameters that were */
- /* not passed using a command line flag. Exactly 2 args should be left. */
- /* The first should be the BDB environment path, the second should be the */
+ /* left in argc & argv. "Extra" parameters are any parameters that were
+ */
+ /* not passed using a command line flag. Exactly 2 args should be left.
+ */
+ /* The first should be the BDB environment path, the second should be
+ * the */
/* BDB database. The BDB database path can be either relative to the */
/* BDB environment path, or absolute. */
if (argc < 2) {
- fprintf(stderr, "Both a Berkeley DB environment and file "\
- "must be specified");
+ fprintf(stderr, "Both a Berkeley DB environment and file "
+ "must be specified");
quit(2);
} else if (argc > 2) {
- fprintf(stderr, "Too many parameters. Check command line for errors.");
+ fprintf(stderr, "Too many parameters. Check command line for "
+ "errors.");
quit(2);
}
@@ -1190,7 +1270,7 @@ main(int argc, char **argv) {
quit(3);
}
- switch(operation) {
+ switch (operation) {
case list:
operation_listOrDelete(false);
break;
@@ -1204,13 +1284,12 @@ main(int argc, char **argv) {
operation_bulk();
break;
default:
- fprintf(stderr, "\nNo operation was selected. "\
- "Select an operation (l d a f)");
+ fprintf(stderr, "\nNo operation was selected. "
+ "Select an operation (l d a f)");
quit(2);
break;
}
quit(0);
}
-#endif
-
+#endif /* ifdef DLZ_BDB */
diff --git a/contrib/dlz/config.dlz.in b/contrib/dlz/config.dlz.in
index 5ddde180..f769cf1f 100644
--- a/contrib/dlz/config.dlz.in
+++ b/contrib/dlz/config.dlz.in
@@ -251,7 +251,7 @@ case "$use_dlz_bdb" in
AC_MSG_RESULT( )
for dd in $bdbdirs
do
- # Skip nonexistant directories
+ # Skip nonexistent directories
if test ! -d "$dd"
then
continue
diff --git a/contrib/dlz/drivers/dlz_bdb_driver.c b/contrib/dlz/drivers/dlz_bdb_driver.c
index c9c5bd27..0ae6de25 100644
--- a/contrib/dlz/drivers/dlz_bdb_driver.c
+++ b/contrib/dlz/drivers/dlz_bdb_driver.c
@@ -35,33 +35,29 @@
/*
* Copyright (C) 1999-2001, 2016 Internet Systems Consortium, Inc. ("ISC")
- *
+ *
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifdef DLZ_BDB
-
-#include <config.h>
+#include <db.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-
-#include <dns/log.h>
-#include <dns/sdlz.h>
-#include <dns/result.h>
+#include <string.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/util.h>
-#include <named/globals.h>
+#include <dns/log.h>
+#include <dns/result.h>
+#include <dns/sdlz.h>
#include <dlz/dlz_bdb_driver.h>
-
-#include <db.h>
+#include <named/globals.h>
static dns_sdlzimplementation_t *dlz_bdb = NULL;
@@ -69,9 +65,9 @@ static dns_sdlzimplementation_t *dlz_bdb = NULL;
#define bdb_threads DB_THREAD
/* BDB database names */
-#define dlz_data "dns_data"
-#define dlz_zone "dns_zone"
-#define dlz_host "dns_host"
+#define dlz_data "dns_data"
+#define dlz_zone "dns_zone"
+#define dlz_host "dns_host"
#define dlz_client "dns_client"
/*%
@@ -80,13 +76,12 @@ static dns_sdlzimplementation_t *dlz_bdb = NULL;
*/
typedef struct bdb_instance {
- DB_ENV *dbenv; /*%< BDB environment */
- DB *data; /*%< dns_data database handle */
- DB *zone; /*%< zone database handle */
- DB *host; /*%< host database handle */
- DB *client; /*%< client database handle */
- isc_mem_t *mctx; /*%< memory context */
-
+ DB_ENV *dbenv; /*%< BDB environment */
+ DB *data; /*%< dns_data database handle */
+ DB *zone; /*%< zone database handle */
+ DB *host; /*%< host database handle */
+ DB *client; /*%< client database handle */
+ isc_mem_t *mctx; /*%< memory context */
} bdb_instance_t;
typedef struct parsed_data {
@@ -97,7 +92,6 @@ typedef struct parsed_data {
char *data;
} parsed_data_t;
-
/* forward reference */
static isc_result_t
@@ -114,13 +108,12 @@ bdb_findzone(void *driverarg, void *dbdata, const char *name,
static isc_result_t
bdb_parse_data(char *in, parsed_data_t *pd) {
-
char *endp, *ttlStr;
char *tmp = in;
- char *lastchar = (char *) &tmp[strlen(tmp) + 1];
+ char *lastchar = (char *)&tmp[strlen(tmp) + 1];
/*%
- * String should be formated as:
+ * String should be formatted as:
* zone(a space)host(a space)ttl(a space)type(a space)remaining data
* examples:
* example.com www 10 A 127.0.0.1
@@ -134,13 +127,15 @@ bdb_parse_data(char *in, parsed_data_t *pd) {
/* find space after zone and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to host */
pd->host = tmp;
@@ -148,13 +143,15 @@ bdb_parse_data(char *in, parsed_data_t *pd) {
/* find space after type and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to dns type */
pd->type = tmp;
@@ -162,13 +159,15 @@ bdb_parse_data(char *in, parsed_data_t *pd) {
/* find space after type and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to dns ttl */
ttlStr = tmp;
@@ -176,13 +175,15 @@ bdb_parse_data(char *in, parsed_data_t *pd) {
/* find space after ttl and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to remainder of DNS data */
pd->data = tmp;
@@ -192,12 +193,12 @@ bdb_parse_data(char *in, parsed_data_t *pd) {
if (*endp != '\0' || pd->ttl < 0) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "BDB driver ttl must be a postive number");
- return ISC_R_FAILURE;
+ "BDB driver ttl must be a positive number");
+ return (ISC_R_FAILURE);
}
/* if we get this far everything should have worked. */
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
}
/*
@@ -206,17 +207,17 @@ bdb_parse_data(char *in, parsed_data_t *pd) {
static isc_result_t
bdb_allowzonexfr(void *driverarg, void *dbdata, const char *name,
- const char *client)
-{
+ const char *client) {
isc_result_t result;
- bdb_instance_t *db = (bdb_instance_t *) dbdata;
+ bdb_instance_t *db = (bdb_instance_t *)dbdata;
DBC *client_cursor = NULL;
DBT key, data;
/* check to see if we are authoritative for the zone first. */
result = bdb_findzone(driverarg, dbdata, name, NULL, NULL);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
memset(&key, 0, sizeof(DBT));
key.flags = DB_DBT_MALLOC;
@@ -242,7 +243,7 @@ bdb_allowzonexfr(void *driverarg, void *dbdata, const char *name,
goto xfr_cleanup;
}
- switch(client_cursor->c_get(client_cursor, &key, &data, DB_GET_BOTH)) {
+ switch (client_cursor->c_get(client_cursor, &key, &data, DB_GET_BOTH)) {
case DB_NOTFOUND:
case DB_SECONDARY_BAD:
result = ISC_R_NOTFOUND;
@@ -254,31 +255,31 @@ bdb_allowzonexfr(void *driverarg, void *dbdata, const char *name,
result = ISC_R_FAILURE;
}
- xfr_cleanup:
+xfr_cleanup:
/* free any memory duplicate string in the key field */
- if (key.data != NULL)
+ if (key.data != NULL) {
free(key.data);
+ }
/* free any memory allocated to the data field. */
- if (data.data != NULL)
+ if (data.data != NULL) {
free(data.data);
+ }
/* get rid of zone_cursor */
- if (client_cursor != NULL)
+ if (client_cursor != NULL) {
client_cursor->c_close(client_cursor);
+ }
- return result;
-
+ return (result);
}
static isc_result_t
bdb_allnodes(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
-
+ dns_sdlzallnodes_t *allnodes) {
isc_result_t result = ISC_R_NOTFOUND;
- bdb_instance_t *db = (bdb_instance_t *) dbdata;
+ bdb_instance_t *db = (bdb_instance_t *)dbdata;
DBC *zone_cursor = NULL;
DBT key, data;
int flags;
@@ -293,8 +294,9 @@ bdb_allnodes(const char *zone, void *driverarg, void *dbdata,
key.data = tmp_zone = strdup(zone);
- if (key.data == NULL)
+ if (key.data == NULL) {
return (ISC_R_NOMEMORY);
+ }
key.size = strlen(key.data);
@@ -306,43 +308,46 @@ bdb_allnodes(const char *zone, void *driverarg, void *dbdata,
flags = DB_SET;
- while ((bdbres = zone_cursor->c_get(zone_cursor, &key, &data,
- flags)) == 0) {
-
+ while ((bdbres = zone_cursor->c_get(zone_cursor, &key, &data, flags)) ==
+ 0) {
flags = DB_NEXT_DUP;
tmp = realloc(tmp, data.size + 1);
- if (tmp == NULL)
+ if (tmp == NULL) {
goto allnodes_cleanup;
+ }
strncpy(tmp, data.data, data.size);
tmp[data.size] = '\0';
- if (bdb_parse_data(tmp, &pd) != ISC_R_SUCCESS)
+ if (bdb_parse_data(tmp, &pd) != ISC_R_SUCCESS) {
goto allnodes_cleanup;
+ }
- result = dns_sdlz_putnamedrr(allnodes, pd.host, pd.type,
- pd.ttl, pd.data);
- if (result != ISC_R_SUCCESS)
+ result = dns_sdlz_putnamedrr(allnodes, pd.host, pd.type, pd.ttl,
+ pd.data);
+ if (result != ISC_R_SUCCESS) {
goto allnodes_cleanup;
-
+ }
} /* end while loop */
- allnodes_cleanup:
+allnodes_cleanup:
- if (tmp != NULL)
+ if (tmp != NULL) {
free(tmp);
+ }
/* free any memory duplicate string in the key field */
- if (tmp_zone != NULL)
+ if (tmp_zone != NULL) {
free(tmp_zone);
+ }
/* get rid of zone_cursor */
- if (zone_cursor != NULL)
+ if (zone_cursor != NULL) {
zone_cursor->c_close(zone_cursor);
+ }
- return result;
-
+ return (result);
}
/*%
@@ -353,40 +358,41 @@ bdb_allnodes(const char *zone, void *driverarg, void *dbdata,
static void
bdb_cleanup(bdb_instance_t *db) {
-
isc_mem_t *mctx;
/* close databases */
- if (db->data != NULL)
+ if (db->data != NULL) {
db->data->close(db->data, 0);
- if (db->host != NULL)
+ }
+ if (db->host != NULL) {
db->host->close(db->host, 0);
- if (db->zone != NULL)
+ }
+ if (db->zone != NULL) {
db->zone->close(db->zone, 0);
- if (db->client != NULL)
+ }
+ if (db->client != NULL) {
db->client->close(db->client, 0);
+ }
/* close environment */
- if (db->dbenv != NULL)
+ if (db->dbenv != NULL) {
db->dbenv->close(db->dbenv, 0);
+ }
/* cleanup memory */
if (db->mctx != NULL) {
/* save mctx for later */
mctx = db->mctx;
/* return, and detach the memory */
- isc_mem_put(mctx, db, sizeof(bdb_instance_t));
- isc_mem_detach(&mctx);
+ isc_mem_putanddetach(&mctx, db, sizeof(bdb_instance_t));
}
}
static isc_result_t
bdb_findzone(void *driverarg, void *dbdata, const char *name,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
-
+ dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) {
isc_result_t result;
- bdb_instance_t *db = (bdb_instance_t *) dbdata;
+ bdb_instance_t *db = (bdb_instance_t *)dbdata;
DBC *zone_cursor = NULL;
DBT key, data;
@@ -400,8 +406,9 @@ bdb_findzone(void *driverarg, void *dbdata, const char *name,
key.data = strdup(name);
- if (key.data == NULL)
+ if (key.data == NULL) {
return (ISC_R_NOMEMORY);
+ }
key.size = strlen(key.data);
@@ -411,7 +418,7 @@ bdb_findzone(void *driverarg, void *dbdata, const char *name,
goto findzone_cleanup;
}
- switch(zone_cursor->c_get(zone_cursor, &key, &data, DB_SET)) {
+ switch (zone_cursor->c_get(zone_cursor, &key, &data, DB_SET)) {
case DB_NOTFOUND:
case DB_SECONDARY_BAD:
result = ISC_R_NOTFOUND;
@@ -423,31 +430,32 @@ bdb_findzone(void *driverarg, void *dbdata, const char *name,
result = ISC_R_FAILURE;
}
- findzone_cleanup:
+findzone_cleanup:
/* free any memory duplicate string in the key field */
- if (key.data != NULL)
+ if (key.data != NULL) {
free(key.data);
+ }
/* free any memory allocated to the data field. */
- if (data.data != NULL)
+ if (data.data != NULL) {
free(data.data);
+ }
/* get rid of zone_cursor */
- if (zone_cursor != NULL)
+ if (zone_cursor != NULL) {
zone_cursor->c_close(zone_cursor);
+ }
- return result;
+ return (result);
}
static isc_result_t
-bdb_lookup(const char *zone, const char *name, void *driverarg,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
-
+bdb_lookup(const char *zone, const char *name, void *driverarg, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result = ISC_R_NOTFOUND;
- bdb_instance_t *db = (bdb_instance_t *) dbdata;
+ bdb_instance_t *db = (bdb_instance_t *)dbdata;
DBC *zone_cursor = NULL;
DBC *host_cursor = NULL;
DBC *join_cursor = NULL;
@@ -511,56 +519,62 @@ bdb_lookup(const char *zone, const char *name, void *driverarg,
db->data->join(db->data, cur_arr, &join_cursor, 0);
- while ((bdbres = join_cursor->c_get(join_cursor, &key,
- &data, 0)) == 0) {
-
+ while ((bdbres = join_cursor->c_get(join_cursor, &key, &data, 0)) == 0)
+ {
tmp = realloc(tmp, data.size + 1);
- if (tmp == NULL)
+ if (tmp == NULL) {
goto lookup_cleanup;
+ }
strncpy(tmp, data.data, data.size);
tmp[data.size] = '\0';
- if (bdb_parse_data(tmp, &pd) != ISC_R_SUCCESS)
+ if (bdb_parse_data(tmp, &pd) != ISC_R_SUCCESS) {
goto lookup_cleanup;
+ }
result = dns_sdlz_putrr(lookup, pd.type, pd.ttl, pd.data);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto lookup_cleanup;
+ }
} /* end while loop */
- lookup_cleanup:
+lookup_cleanup:
- if (tmp != NULL)
+ if (tmp != NULL) {
free(tmp);
- if (tmp_zone != NULL)
+ }
+ if (tmp_zone != NULL) {
free(tmp_zone);
- if (tmp_host != NULL)
+ }
+ if (tmp_host != NULL) {
free(tmp_host);
+ }
/* get rid of the joined cusor */
- if (join_cursor != NULL)
+ if (join_cursor != NULL) {
join_cursor->c_close(join_cursor);
+ }
/* get rid of zone_cursor */
- if (zone_cursor != NULL)
+ if (zone_cursor != NULL) {
zone_cursor->c_close(zone_cursor);
+ }
/* get rid of host_cursor */
- if (host_cursor != NULL)
+ if (host_cursor != NULL) {
host_cursor->c_close(host_cursor);
+ }
- return result;
+ return (result);
}
-
/*% Initializes, sets flags and then opens Berkeley databases. */
static isc_result_t
bdb_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name,
char *db_file, int flags) {
-
int result;
/* Initialize the database. */
@@ -570,7 +584,7 @@ bdb_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name,
"BDB could not initialize %s database. "
"BDB error: %s",
db_name, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* set database flags. */
@@ -580,27 +594,27 @@ bdb_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name,
"BDB could not set flags for %s database. "
"BDB error: %s",
db_name, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* open the database. */
if ((result = (*db)->open(*db, NULL, db_file, db_name, db_type,
- DB_RDONLY | bdb_threads, 0)) != 0) {
+ DB_RDONLY | bdb_threads, 0)) != 0)
+ {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"BDB could not open %s database in %s. "
"BDB error: %s",
db_name, db_file, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
}
static isc_result_t
bdb_create(const char *dlzname, unsigned int argc, char *argv[],
- void *driverarg, void **dbdata)
-{
+ void *driverarg, void **dbdata) {
isc_result_t result;
int bdbres;
bdb_instance_t *db = NULL;
@@ -619,13 +633,6 @@ bdb_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate and zero memory for driver structure */
db = isc_mem_get(named_g_mctx, sizeof(bdb_instance_t));
- if (db == NULL) {
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "Could not allocate memory for "
- "database instance object.");
- return (ISC_R_NOMEMORY);
- }
memset(db, 0, sizeof(bdb_instance_t));
/* attach to the memory context */
@@ -646,10 +653,9 @@ bdb_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* open BDB environment */
- bdbres = db->dbenv->open(db->dbenv, argv[1],
- DB_INIT_CDB | DB_INIT_MPOOL |
- bdb_threads | DB_CREATE,
- 0);
+ bdbres = db->dbenv->open(
+ db->dbenv, argv[1],
+ DB_INIT_CDB | DB_INIT_MPOOL | bdb_threads | DB_CREATE, 0);
if (bdbres != 0) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
@@ -661,30 +667,32 @@ bdb_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* open dlz_data database. */
- result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->data,
- dlz_data, argv[2], 0);
- if (result != ISC_R_SUCCESS)
+ result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->data, dlz_data, argv[2],
+ 0);
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
/* open dlz_host database. */
- result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->host,
- dlz_host, argv[2],
+ result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->host, dlz_host, argv[2],
DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
/* open dlz_zone database. */
- result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->zone,
- dlz_zone, argv[2],
+ result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->zone, dlz_zone, argv[2],
DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
/* open dlz_client database. */
- result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->client,
- dlz_client, argv[2], DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->client, dlz_client,
+ argv[2], DB_DUP | DB_DUPSORT);
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
/* associate the host secondary database with the primary database */
bdbres = db->data->associate(db->data, NULL, db->host, NULL, 0);
@@ -712,20 +720,19 @@ bdb_create(const char *dlzname, unsigned int argc, char *argv[],
*dbdata = db;
- return(ISC_R_SUCCESS);
+ return (ISC_R_SUCCESS);
- init_cleanup:
+init_cleanup:
bdb_cleanup(db);
- return result;
+ return (result);
}
static void
-bdb_destroy(void *driverarg, void *dbdata)
-{
+bdb_destroy(void *driverarg, void *dbdata) {
UNUSED(driverarg);
- bdb_cleanup((bdb_instance_t *) dbdata);
+ bdb_cleanup((bdb_instance_t *)dbdata);
}
/* bdb_authority not needed as authority data is returned by lookup */
@@ -756,14 +763,13 @@ dlz_bdb_init(void) {
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Registering DLZ bdb driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Registering DLZ bdb driver.");
result = dns_sdlzregister("bdb", &dlz_bdb_methods, NULL,
DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA |
- DNS_SDLZFLAG_THREADSAFE,
+ DNS_SDLZFLAG_RELATIVERDATA |
+ DNS_SDLZFLAG_THREADSAFE,
named_g_mctx, &dlz_bdb);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
@@ -772,8 +778,7 @@ dlz_bdb_init(void) {
result = ISC_R_UNEXPECTED;
}
-
- return result;
+ return (result);
}
/*%
@@ -781,16 +786,15 @@ dlz_bdb_init(void) {
*/
void
dlz_bdb_clear(void) {
-
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unregistering DLZ bdb driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unregistering DLZ bdb driver.");
- if (dlz_bdb != NULL)
+ if (dlz_bdb != NULL) {
dns_sdlzunregister(&dlz_bdb);
+ }
}
-#endif
+#endif /* ifdef DLZ_BDB */
diff --git a/contrib/dlz/drivers/dlz_bdbhpt_driver.c b/contrib/dlz/drivers/dlz_bdbhpt_driver.c
index 09f00829..80f4330b 100644
--- a/contrib/dlz/drivers/dlz_bdbhpt_driver.c
+++ b/contrib/dlz/drivers/dlz_bdbhpt_driver.c
@@ -42,26 +42,22 @@
*/
#ifdef DLZ_BDB
-
-#include <config.h>
+#include <db.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-
-#include <dns/log.h>
-#include <dns/sdlz.h>
-#include <dns/result.h>
+#include <string.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/util.h>
-#include <named/globals.h>
+#include <dns/log.h>
+#include <dns/result.h>
+#include <dns/sdlz.h>
#include <dlz/dlz_bdbhpt_driver.h>
-
-#include <db.h>
+#include <named/globals.h>
static dns_sdlzimplementation_t *dlz_bdbhpt = NULL;
@@ -69,23 +65,22 @@ static dns_sdlzimplementation_t *dlz_bdbhpt = NULL;
#define bdbhpt_threads DB_THREAD
/* bdbhpt database names */
-#define dlz_data "dns_data"
-#define dlz_zone "dns_zone"
-#define dlz_xfr "dns_xfr"
+#define dlz_data "dns_data"
+#define dlz_zone "dns_zone"
+#define dlz_xfr "dns_xfr"
#define dlz_client "dns_client"
- /* This structure contains all the Berkeley DB handles
- * for this instance of the bdbhpt driver.
- */
+/* This structure contains all the Berkeley DB handles
+ * for this instance of the bdbhpt driver.
+ */
typedef struct bdbhpt_instance {
- DB_ENV *dbenv; /*%< bdbhpt environment */
- DB *data; /*%< dns_data database handle */
- DB *zone; /*%< zone database handle */
- DB *xfr; /*%< zone xfr database handle */
- DB *client; /*%< client database handle */
- isc_mem_t *mctx; /*%< memory context */
-
+ DB_ENV *dbenv; /*%< bdbhpt environment */
+ DB *data; /*%< dns_data database handle */
+ DB *zone; /*%< zone database handle */
+ DB *xfr; /*%< zone xfr database handle */
+ DB *client; /*%< client database handle */
+ isc_mem_t *mctx; /*%< memory context */
} bdbhpt_instance_t;
typedef struct bdbhpt_parsed_data {
@@ -95,7 +90,6 @@ typedef struct bdbhpt_parsed_data {
char *data;
} bdbhpt_parsed_data_t;
-
/* forward reference */
static isc_result_t
@@ -106,19 +100,19 @@ bdbhpt_findzone(void *driverarg, void *dbdata, const char *name,
* Reverses a string in place.
*/
-static char *bdbhpt_strrev(char *str)
-{
+static char *
+bdbhpt_strrev(char *str) {
char *p1, *p2;
- if (! str || ! *str)
- return str;
- for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2)
- {
+ if (!str || !*str) {
+ return (str);
+ }
+ for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) {
*p1 ^= *p2;
*p2 ^= *p1;
*p1 ^= *p2;
}
- return str;
+ return (str);
}
/*%
@@ -131,13 +125,12 @@ static char *bdbhpt_strrev(char *str)
static isc_result_t
bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) {
-
char *endp, *ttlStr;
char *tmp = in;
- char *lastchar = (char *) &tmp[strlen(tmp)];
+ char *lastchar = (char *)&tmp[strlen(tmp)];
/*%
- * String should be formated as:
+ * String should be formatted as:
* replication_id
* (a space)
* host_name
@@ -163,11 +156,13 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) {
/* find space after replication id */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to host */
pd->host = tmp;
@@ -175,13 +170,15 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) {
/* find space after host and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to ttl string */
ttlStr = tmp;
@@ -189,13 +186,15 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) {
/* find space after ttl and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to dns type */
pd->type = tmp;
@@ -203,13 +202,15 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) {
/* find space after type and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to remainder of DNS data */
pd->data = tmp;
@@ -219,12 +220,12 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) {
if (*endp != '\0' || pd->ttl < 0) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "bdbhpt driver ttl must be a postive number");
- return ISC_R_FAILURE;
+ "bdbhpt driver ttl must be a positive number");
+ return (ISC_R_FAILURE);
}
/* if we get this far everything should have worked. */
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
}
/*
@@ -233,16 +234,16 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) {
static isc_result_t
bdbhpt_allowzonexfr(void *driverarg, void *dbdata, const char *name,
- const char *client)
-{
+ const char *client) {
isc_result_t result;
- bdbhpt_instance_t *db = (bdbhpt_instance_t *) dbdata;
+ bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata;
DBT key, data;
/* check to see if we are authoritative for the zone first. */
result = bdbhpt_findzone(driverarg, dbdata, name, NULL, NULL);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
memset(&key, 0, sizeof(DBT));
key.flags = DB_DBT_MALLOC;
@@ -262,7 +263,7 @@ bdbhpt_allowzonexfr(void *driverarg, void *dbdata, const char *name,
}
data.size = strlen(data.data);
- switch(db->client->get(db->client, NULL, &key, &data, DB_GET_BOTH)) {
+ switch (db->client->get(db->client, NULL, &key, &data, DB_GET_BOTH)) {
case DB_NOTFOUND:
result = ISC_R_NOTFOUND;
break;
@@ -273,18 +274,19 @@ bdbhpt_allowzonexfr(void *driverarg, void *dbdata, const char *name,
result = ISC_R_FAILURE;
}
- xfr_cleanup:
+xfr_cleanup:
/* free any memory duplicate string in the key field */
- if (key.data != NULL)
+ if (key.data != NULL) {
free(key.data);
+ }
/* free any memory allocated to the data field. */
- if (data.data != NULL)
+ if (data.data != NULL) {
free(data.data);
+ }
- return result;
-
+ return (result);
}
/*%
@@ -315,11 +317,9 @@ bdbhpt_allowzonexfr(void *driverarg, void *dbdata, const char *name,
static isc_result_t
bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
-
+ dns_sdlzallnodes_t *allnodes) {
isc_result_t result = ISC_R_NOTFOUND;
- bdbhpt_instance_t *db = (bdbhpt_instance_t *) dbdata;
+ bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata;
DBC *xfr_cursor = NULL;
DBC *dns_cursor = NULL;
DBT xfr_key, xfr_data, dns_key, dns_data;
@@ -337,8 +337,9 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata,
memset(&dns_data, 0, sizeof(DBT));
xfr_key.data = tmp_zone = strdup(zone);
- if (xfr_key.data == NULL)
+ if (xfr_key.data == NULL) {
return (ISC_R_NOMEMORY);
+ }
xfr_key.size = strlen(xfr_key.data);
@@ -358,8 +359,8 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata,
/* loop through xfr table for specified zone. */
while ((bdbhptres = xfr_cursor->c_get(xfr_cursor, &xfr_key, &xfr_data,
- xfr_flags)) == 0) {
-
+ xfr_flags)) == 0)
+ {
xfr_flags = DB_NEXT_DUP;
/* +1 to allow for space between zone and host names */
@@ -367,8 +368,9 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata,
/* +1 to allow for null term at end of string. */
dns_key.data = tmp_zone_host = malloc(dns_key.size + 1);
- if (dns_key.data == NULL)
+ if (dns_key.data == NULL) {
goto allnodes_cleanup;
+ }
/*
* construct search key for dns_data.
@@ -381,30 +383,32 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata,
dns_flags = DB_SET;
while ((bdbhptres = dns_cursor->c_get(dns_cursor, &dns_key,
- &dns_data,
- dns_flags)) == 0) {
-
+ &dns_data, dns_flags)) ==
+ 0)
+ {
dns_flags = DB_NEXT_DUP;
/* +1 to allow for null term at end of string. */
tmp = realloc(tmp, dns_data.size + 1);
- if (tmp == NULL)
+ if (tmp == NULL) {
goto allnodes_cleanup;
+ }
/* copy data to tmp string, and append null term. */
strncpy(tmp, dns_data.data, dns_data.size);
tmp[dns_data.size] = '\0';
/* split string into dns data parts. */
- if (bdbhpt_parse_data(tmp, &pd) != ISC_R_SUCCESS)
+ if (bdbhpt_parse_data(tmp, &pd) != ISC_R_SUCCESS) {
goto allnodes_cleanup;
+ }
- result = dns_sdlz_putnamedrr(allnodes, pd.host,
- pd.type, pd.ttl, pd.data);
- if (result != ISC_R_SUCCESS)
+ result = dns_sdlz_putnamedrr(allnodes, pd.host, pd.type,
+ pd.ttl, pd.data);
+ if (result != ISC_R_SUCCESS) {
goto allnodes_cleanup;
-
- } /* end inner while loop */
+ }
+ } /* end inner while loop */
/* clean up memory */
if (tmp_zone_host != NULL) {
@@ -413,26 +417,31 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata,
}
} /* end outer while loop */
- allnodes_cleanup:
+allnodes_cleanup:
/* free any memory */
- if (tmp != NULL)
+ if (tmp != NULL) {
free(tmp);
+ }
- if (tmp_zone_host != NULL)
+ if (tmp_zone_host != NULL) {
free(tmp_zone_host);
+ }
- if (tmp_zone != NULL)
+ if (tmp_zone != NULL) {
free(tmp_zone);
+ }
/* get rid of cursors */
- if (xfr_cursor != NULL)
+ if (xfr_cursor != NULL) {
xfr_cursor->c_close(xfr_cursor);
+ }
- if (dns_cursor != NULL)
+ if (dns_cursor != NULL) {
dns_cursor->c_close(dns_cursor);
+ }
- return result;
+ return (result);
}
/*%
@@ -443,40 +452,42 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata,
static void
bdbhpt_cleanup(bdbhpt_instance_t *db) {
-
isc_mem_t *mctx;
/* close databases */
- if (db->data != NULL)
+ if (db->data != NULL) {
db->data->close(db->data, 0);
- if (db->xfr != NULL)
+ }
+ if (db->xfr != NULL) {
db->xfr->close(db->xfr, 0);
- if (db->zone != NULL)
+ }
+ if (db->zone != NULL) {
db->zone->close(db->zone, 0);
- if (db->client != NULL)
+ }
+ if (db->client != NULL) {
db->client->close(db->client, 0);
+ }
/* close environment */
- if (db->dbenv != NULL)
+ if (db->dbenv != NULL) {
db->dbenv->close(db->dbenv, 0);
+ }
/* cleanup memory */
if (db->mctx != NULL) {
/* save mctx for later */
mctx = db->mctx;
/* return, and detach the memory */
- isc_mem_put(mctx, db, sizeof(bdbhpt_instance_t));
- isc_mem_detach(&mctx);
+ isc_mem_putanddetach(&mctx, db, sizeof(bdbhpt_instance_t));
}
}
static isc_result_t
bdbhpt_findzone(void *driverarg, void *dbdata, const char *name,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
-
+ dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
- bdbhpt_instance_t *db = (bdbhpt_instance_t *) dbdata;
+ bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata;
DBT key, data;
UNUSED(driverarg);
@@ -489,18 +500,19 @@ bdbhpt_findzone(void *driverarg, void *dbdata, const char *name,
key.data = strdup(name);
- if (key.data == NULL)
+ if (key.data == NULL) {
return (ISC_R_NOMEMORY);
+ }
/*
* reverse string to take advantage of BDB locality of reference
- * if we need futher lookups because the zone doesn't match the
+ * if we need further lookups because the zone doesn't match the
* first time.
*/
key.data = bdbhpt_strrev(key.data);
key.size = strlen(key.data);
- switch(db->zone->get(db->zone, NULL, &key, &data, 0)) {
+ switch (db->zone->get(db->zone, NULL, &key, &data, 0)) {
case DB_NOTFOUND:
result = ISC_R_NOTFOUND;
break;
@@ -512,24 +524,24 @@ bdbhpt_findzone(void *driverarg, void *dbdata, const char *name,
}
/* free any memory duplicate string in the key field */
- if (key.data != NULL)
+ if (key.data != NULL) {
free(key.data);
+ }
/* free any memory allocated to the data field. */
- if (data.data != NULL)
+ if (data.data != NULL) {
free(data.data);
+ }
- return result;
+ return (result);
}
static isc_result_t
-bdbhpt_lookup(const char *zone, const char *name, void *driverarg,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
-
+bdbhpt_lookup(const char *zone, const char *name, void *driverarg, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result = ISC_R_NOTFOUND;
- bdbhpt_instance_t *db = (bdbhpt_instance_t *) dbdata;
+ bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata;
DBC *data_cursor = NULL;
DBT key, data;
int bdbhptres;
@@ -551,8 +563,9 @@ bdbhpt_lookup(const char *zone, const char *name, void *driverarg,
/* allocate mem for key */
key.data = keyStr = malloc((key.size + 1) * sizeof(char));
- if (keyStr == NULL)
- return ISC_R_NOMEMORY;
+ if (keyStr == NULL) {
+ return (ISC_R_NOMEMORY);
+ }
strcpy(keyStr, zone);
strcat(keyStr, " ");
@@ -569,36 +582,39 @@ bdbhpt_lookup(const char *zone, const char *name, void *driverarg,
flags = DB_SET;
while ((bdbhptres = data_cursor->c_get(data_cursor, &key, &data,
flags)) == 0) {
-
flags = DB_NEXT_DUP;
tmp = realloc(tmp, data.size + 1);
- if (tmp == NULL)
+ if (tmp == NULL) {
goto lookup_cleanup;
+ }
strncpy(tmp, data.data, data.size);
tmp[data.size] = '\0';
- if (bdbhpt_parse_data(tmp, &pd) != ISC_R_SUCCESS)
+ if (bdbhpt_parse_data(tmp, &pd) != ISC_R_SUCCESS) {
goto lookup_cleanup;
+ }
result = dns_sdlz_putrr(lookup, pd.type, pd.ttl, pd.data);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto lookup_cleanup;
+ }
} /* end while loop */
- lookup_cleanup:
+lookup_cleanup:
/* get rid of cursor */
- if (data_cursor != NULL)
+ if (data_cursor != NULL) {
data_cursor->c_close(data_cursor);
+ }
- if (keyStr != NULL)
- free(keyStr);
- if (tmp != NULL)
+ free(keyStr);
+ if (tmp != NULL) {
free(tmp);
+ }
- return result;
+ return (result);
}
/*% Initializes, sets flags and then opens Berkeley databases. */
@@ -606,7 +622,6 @@ bdbhpt_lookup(const char *zone, const char *name, void *driverarg,
static isc_result_t
bdbhpt_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name,
char *db_file, int flags) {
-
int result;
/* Initialize the database. */
@@ -616,7 +631,7 @@ bdbhpt_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name,
"bdbhpt could not initialize %s database. "
"bdbhpt error: %s",
db_name, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* set database flags. */
@@ -626,27 +641,27 @@ bdbhpt_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name,
"bdbhpt could not set flags for %s database. "
"bdbhpt error: %s",
db_name, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* open the database. */
if ((result = (*db)->open(*db, NULL, db_file, db_name, db_type,
- DB_RDONLY | bdbhpt_threads, 0)) != 0) {
+ DB_RDONLY | bdbhpt_threads, 0)) != 0)
+ {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"bdbhpt could not open %s database in %s. "
"bdbhpt error: %s",
db_name, db_file, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
}
static isc_result_t
bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[],
- void *driverarg, void **dbdata)
-{
+ void *driverarg, void **dbdata) {
isc_result_t result;
int bdbhptres;
int bdbFlags = 0;
@@ -664,22 +679,22 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_FAILURE);
}
- switch((char) *argv[1]) {
- /*
- * Transactional mode. Highest safety - lowest speed.
- */
+ switch ((char)*argv[1]) {
+ /*
+ * Transactional mode. Highest safety - lowest speed.
+ */
case 'T':
case 't':
- bdbFlags = DB_INIT_MPOOL | DB_INIT_LOCK |
- DB_INIT_LOG | DB_INIT_TXN;
+ bdbFlags = DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_LOG |
+ DB_INIT_TXN;
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
"bdbhpt driver using transactional mode.");
break;
- /*
- * Concurrent mode. Lower safety (no rollback) -
- * higher speed.
- */
+ /*
+ * Concurrent mode. Lower safety (no rollback) -
+ * higher speed.
+ */
case 'C':
case 'c':
bdbFlags = DB_INIT_CDB | DB_INIT_MPOOL;
@@ -687,10 +702,10 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[],
DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
"bdbhpt driver using concurrent mode.");
break;
- /*
- * Private mode. No inter-process communication & no locking.
- * Lowest saftey - highest speed.
- */
+ /*
+ * Private mode. No inter-process communication & no locking.
+ * Lowest safety - highest speed.
+ */
case 'P':
case 'p':
bdbFlags = DB_PRIVATE | DB_INIT_MPOOL;
@@ -709,13 +724,6 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate and zero memory for driver structure */
db = isc_mem_get(named_g_mctx, sizeof(bdbhpt_instance_t));
- if (db == NULL) {
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "Could not allocate memory for "
- "database instance object.");
- return (ISC_R_NOMEMORY);
- }
memset(db, 0, sizeof(bdbhpt_instance_t));
/* attach to the memory context */
@@ -750,45 +758,48 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* open dlz_data database. */
- result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->data,
- dlz_data, argv[3], DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->data, dlz_data,
+ argv[3], DB_DUP | DB_DUPSORT);
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
/* open dlz_xfr database. */
- result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->xfr,
- dlz_xfr, argv[3], DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->xfr, dlz_xfr,
+ argv[3], DB_DUP | DB_DUPSORT);
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
/* open dlz_zone database. */
- result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->zone,
- dlz_zone, argv[3], 0);
- if (result != ISC_R_SUCCESS)
+ result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->zone, dlz_zone,
+ argv[3], 0);
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
/* open dlz_client database. */
- result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->client,
- dlz_client, argv[3], DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->client, dlz_client,
+ argv[3], DB_DUP | DB_DUPSORT);
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
*dbdata = db;
- return(ISC_R_SUCCESS);
+ return (ISC_R_SUCCESS);
- init_cleanup:
+init_cleanup:
bdbhpt_cleanup(db);
- return result;
+ return (result);
}
static void
-bdbhpt_destroy(void *driverarg, void *dbdata)
-{
+bdbhpt_destroy(void *driverarg, void *dbdata) {
UNUSED(driverarg);
- bdbhpt_cleanup((bdbhpt_instance_t *) dbdata);
+ bdbhpt_cleanup((bdbhpt_instance_t *)dbdata);
}
/*
@@ -821,14 +832,13 @@ dlz_bdbhpt_init(void) {
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Registering DLZ bdbhpt driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Registering DLZ bdbhpt driver.");
result = dns_sdlzregister("bdbhpt", &dlz_bdbhpt_methods, NULL,
DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA |
- DNS_SDLZFLAG_THREADSAFE,
+ DNS_SDLZFLAG_RELATIVERDATA |
+ DNS_SDLZFLAG_THREADSAFE,
named_g_mctx, &dlz_bdbhpt);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
@@ -837,8 +847,7 @@ dlz_bdbhpt_init(void) {
result = ISC_R_UNEXPECTED;
}
-
- return result;
+ return (result);
}
/*%
@@ -846,16 +855,15 @@ dlz_bdbhpt_init(void) {
*/
void
dlz_bdbhpt_clear(void) {
-
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unregistering DLZ bdbhpt driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unregistering DLZ bdbhpt driver.");
- if (dlz_bdbhpt != NULL)
+ if (dlz_bdbhpt != NULL) {
dns_sdlzunregister(&dlz_bdbhpt);
+ }
}
-#endif
+#endif /* ifdef DLZ_BDB */
diff --git a/contrib/dlz/drivers/dlz_drivers.c b/contrib/dlz/drivers/dlz_drivers.c
index 4e42d803..5f5b66e8 100644
--- a/contrib/dlz/drivers/dlz_drivers.c
+++ b/contrib/dlz/drivers/dlz_drivers.c
@@ -14,11 +14,8 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-
/*! \file */
-#include <config.h>
-
#include <isc/result.h>
/*
@@ -33,32 +30,32 @@
#ifdef DLZ_STUB
#include <dlz/dlz_stub_driver.h>
-#endif
+#endif /* ifdef DLZ_STUB */
#ifdef DLZ_POSTGRES
#include <dlz/dlz_postgres_driver.h>
-#endif
+#endif /* ifdef DLZ_POSTGRES */
#ifdef DLZ_MYSQL
#include <dlz/dlz_mysql_driver.h>
-#endif
+#endif /* ifdef DLZ_MYSQL */
#ifdef DLZ_FILESYSTEM
#include <dlz/dlz_filesystem_driver.h>
-#endif
+#endif /* ifdef DLZ_FILESYSTEM */
#ifdef DLZ_BDB
#include <dlz/dlz_bdb_driver.h>
#include <dlz/dlz_bdbhpt_driver.h>
-#endif
+#endif /* ifdef DLZ_BDB */
#ifdef DLZ_LDAP
#include <dlz/dlz_ldap_driver.h>
-#endif
+#endif /* ifdef DLZ_LDAP */
#ifdef DLZ_ODBC
#include <dlz/dlz_odbc_driver.h>
-#endif
+#endif /* ifdef DLZ_ODBC */
/*%
* Call init functions for all relevant DLZ drivers.
@@ -66,53 +63,60 @@
isc_result_t
dlz_drivers_init(void) {
-
isc_result_t result = ISC_R_SUCCESS;
#ifdef DLZ_STUB
result = dlz_stub_init();
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
-#endif
+ }
+#endif /* ifdef DLZ_STUB */
#ifdef DLZ_POSTGRES
result = dlz_postgres_init();
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
-#endif
+ }
+#endif /* ifdef DLZ_POSTGRES */
#ifdef DLZ_MYSQL
result = dlz_mysql_init();
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
-#endif
+ }
+#endif /* ifdef DLZ_MYSQL */
#ifdef DLZ_FILESYSTEM
result = dlz_fs_init();
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
-#endif
+ }
+#endif /* ifdef DLZ_FILESYSTEM */
#ifdef DLZ_BDB
result = dlz_bdb_init();
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
result = dlz_bdbhpt_init();
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
-#endif
+ }
+#endif /* ifdef DLZ_BDB */
#ifdef DLZ_LDAP
result = dlz_ldap_init();
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
-#endif
+ }
+#endif /* ifdef DLZ_LDAP */
#ifdef DLZ_ODBC
result = dlz_odbc_init();
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
-#endif
+ }
+#endif /* ifdef DLZ_ODBC */
return (result);
}
@@ -123,34 +127,32 @@ dlz_drivers_init(void) {
void
dlz_drivers_clear(void) {
-
#ifdef DLZ_STUB
dlz_stub_clear();
-#endif
+#endif /* ifdef DLZ_STUB */
#ifdef DLZ_POSTGRES
- dlz_postgres_clear();
-#endif
+ dlz_postgres_clear();
+#endif /* ifdef DLZ_POSTGRES */
#ifdef DLZ_MYSQL
- dlz_mysql_clear();
-#endif
+ dlz_mysql_clear();
+#endif /* ifdef DLZ_MYSQL */
#ifdef DLZ_FILESYSTEM
- dlz_fs_clear();
-#endif
+ dlz_fs_clear();
+#endif /* ifdef DLZ_FILESYSTEM */
#ifdef DLZ_BDB
- dlz_bdb_clear();
- dlz_bdbhpt_clear();
-#endif
+ dlz_bdb_clear();
+ dlz_bdbhpt_clear();
+#endif /* ifdef DLZ_BDB */
#ifdef DLZ_LDAP
- dlz_ldap_clear();
-#endif
+ dlz_ldap_clear();
+#endif /* ifdef DLZ_LDAP */
#ifdef DLZ_ODBC
- dlz_odbc_clear();
-#endif
-
+ dlz_odbc_clear();
+#endif /* ifdef DLZ_ODBC */
}
diff --git a/contrib/dlz/drivers/dlz_filesystem_driver.c b/contrib/dlz/drivers/dlz_filesystem_driver.c
index a136e650..8ed1af1b 100644
--- a/contrib/dlz/drivers/dlz_filesystem_driver.c
+++ b/contrib/dlz/drivers/dlz_filesystem_driver.c
@@ -42,19 +42,12 @@
*/
#ifdef DLZ_FILESYSTEM
-
-#include <config.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <sys/stat.h>
-#include <dns/log.h>
-#include <dns/sdlz.h>
-#include <dns/result.h>
-
#include <isc/dir.h>
#include <isc/mem.h>
#include <isc/platform.h>
@@ -63,30 +56,33 @@
#include <isc/string.h>
#include <isc/util.h>
-#include <named/globals.h>
+#include <dns/log.h>
+#include <dns/result.h>
+#include <dns/sdlz.h>
#include <dlz/dlz_filesystem_driver.h>
+#include <named/globals.h>
static dns_sdlzimplementation_t *dlz_fs = NULL;
typedef struct config_data {
- char *basedir;
- int basedirsize;
- char *datadir;
- int datadirsize;
- char *xfrdir;
- int xfrdirsize;
- int splitcnt;
- char separator;
- char pathsep;
- isc_mem_t *mctx;
+ char *basedir;
+ int basedirsize;
+ char *datadir;
+ int datadirsize;
+ char *xfrdir;
+ int xfrdirsize;
+ int splitcnt;
+ char separator;
+ char pathsep;
+ isc_mem_t *mctx;
} config_data_t;
typedef struct dir_entry dir_entry_t;
struct dir_entry {
char dirpath[PATH_MAX];
- ISC_LINK(dir_entry_t) link;
+ ISC_LINK(dir_entry_t) link;
};
typedef ISC_LIST(dir_entry_t) dlist_t;
@@ -105,49 +101,58 @@ is_safe(const char *input) {
unsigned int i;
unsigned int len = strlen(input);
- /* check that only allowed characters are in the domain name */
- for (i=0; i < len; i++) {
+ /* check that only allowed characters are in the domain name */
+ for (i = 0; i < len; i++) {
/* '.' is allowed, but has special requirements */
if (input[i] == '.') {
/* '.' is not allowed as first char */
- if (i == 0)
+ if (i == 0) {
return (false);
+ }
/* '..', two dots together is not allowed. */
- if (input[i-1] == '.')
+ if (input[i - 1] == '.') {
return (false);
+ }
/* '.' is not allowed as last char */
- if (i == len - 1)
+ if (i == len - 1) {
return (false);
+ }
/* only 1 dot in ok location, continue at next char */
continue;
}
/* '-' is allowed, continue at next char */
- if (input[i] == '-')
+ if (input[i] == '-') {
continue;
+ }
/* 0-9 is allowed, continue at next char */
- if (input[i] >= '0' && input[i] <= '9')
+ if (input[i] >= '0' && input[i] <= '9') {
continue;
+ }
/* A-Z uppercase is allowed, continue at next char */
- if (input[i] >= 'A' && input[i] <= 'Z')
+ if (input[i] >= 'A' && input[i] <= 'Z') {
continue;
+ }
/* a-z lowercase is allowed, continue at next char */
- if (input[i] >= 'a' && input[i] <= 'z')
+ if (input[i] >= 'a' && input[i] <= 'z') {
continue;
+ }
/*
* colon needs to be allowed for IPV6 client
* addresses. Not dangerous in domain names, as not a
* special char.
*/
- if (input[i] == ':')
+ if (input[i] == ':') {
continue;
+ }
/*
* '@' needs to be allowed for in zone data. Not
* dangerous in domain names, as not a special char.
*/
- if (input[i] == '@')
+ if (input[i] == '@') {
continue;
+ }
/*
* if we reach this point we have encountered a
@@ -155,19 +160,17 @@ is_safe(const char *input) {
*/
return (false);
}
- /* everything ok. */
+ /* everything ok. */
return (true);
}
-static isc_result_t
+static void
create_path_helper(char *out, const char *in, config_data_t *cd) {
char *tmpString;
char *tmpPtr;
int i;
tmpString = isc_mem_strdup(named_g_mctx, in);
- if (tmpString == NULL)
- return (ISC_R_NOMEMORY);
/*
* don't forget is_safe guarantees '.' will NOT be the
@@ -175,42 +178,46 @@ create_path_helper(char *out, const char *in, config_data_t *cd) {
*/
while ((tmpPtr = strrchr(tmpString, '.')) != NULL) {
i = 0;
- while (tmpPtr[i+1] != '\0') {
- if (cd->splitcnt < 1)
- strcat(out, (char *) &tmpPtr[i+1]);
- else
- strncat(out, (char *) &tmpPtr[i+1],
+ while (tmpPtr[i + 1] != '\0') {
+ if (cd->splitcnt < 1) {
+ strcat(out, (char *)&tmpPtr[i + 1]);
+ } else {
+ strncat(out, (char *)&tmpPtr[i + 1],
cd->splitcnt);
- strncat(out, (char *) &cd->pathsep, 1);
- if (cd->splitcnt == 0)
+ }
+ strncat(out, (char *)&cd->pathsep, 1);
+ if (cd->splitcnt == 0) {
break;
- if (strlen((char *) &tmpPtr[i+1]) <=
- (unsigned int) cd->splitcnt)
+ }
+ if (strlen((char *)&tmpPtr[i + 1]) <=
+ (unsigned int)cd->splitcnt) {
break;
+ }
i += cd->splitcnt;
}
tmpPtr[0] = '\0';
}
/* handle the "first" label properly */
- i=0;
+ i = 0;
tmpPtr = tmpString;
while (tmpPtr[i] != '\0') {
- if (cd->splitcnt < 1)
- strcat(out, (char *) &tmpPtr[i]);
- else
- strncat(out, (char *) &tmpPtr[i], cd->splitcnt);
- strncat(out, (char *) &cd->pathsep, 1);
- if (cd->splitcnt == 0)
+ if (cd->splitcnt < 1) {
+ strcat(out, (char *)&tmpPtr[i]);
+ } else {
+ strncat(out, (char *)&tmpPtr[i], cd->splitcnt);
+ }
+ strncat(out, (char *)&cd->pathsep, 1);
+ if (cd->splitcnt == 0) {
break;
- if (strlen((char *) &tmpPtr[i]) <=
- (unsigned int) cd->splitcnt)
+ }
+ if (strlen((char *)&tmpPtr[i]) <= (unsigned int)cd->splitcnt) {
break;
+ }
i += cd->splitcnt;
}
isc_mem_free(named_g_mctx, tmpString);
- return (ISC_R_SUCCESS);
}
/*%
@@ -221,13 +228,10 @@ create_path_helper(char *out, const char *in, config_data_t *cd) {
static isc_result_t
create_path(const char *zone, const char *host, const char *client,
- config_data_t *cd, char **path)
-{
-
+ config_data_t *cd, char **path) {
char *tmpPath;
int pathsize;
int len;
- isc_result_t result;
bool isroot = false;
/* we require a zone & cd parameter */
@@ -239,57 +243,53 @@ create_path(const char *zone, const char *host, const char *client,
* client and host may both be NULL, but they can't both be
* NON-NULL
*/
- REQUIRE( (host == NULL && client == NULL) ||
- (host != NULL && client == NULL) ||
- (host == NULL && client != NULL) );
+ REQUIRE((host == NULL && client == NULL) ||
+ (host != NULL && client == NULL) ||
+ (host == NULL && client != NULL));
/* special case for root zone */
- if (strcmp(zone, ".") == 0)
+ if (strcmp(zone, ".") == 0) {
isroot = true;
+ }
/* if the requested zone is "unsafe", return error */
- if (!isroot && !is_safe(zone))
+ if (!isroot && !is_safe(zone)) {
return (ISC_R_FAILURE);
+ }
/* if host was passed, verify that it is safe */
- if (host != NULL && !is_safe(host))
+ if (host != NULL && !is_safe(host)) {
return (ISC_R_FAILURE);
+ }
/* if client was passed, verify that it is safe */
- if (client != NULL && !is_safe(client))
+ if (client != NULL && !is_safe(client)) {
return (ISC_R_FAILURE);
+ }
/* Determine how much memory the split up string will require */
- if (host != NULL)
+ if (host != NULL) {
len = strlen(zone) + strlen(host);
- else if (client != NULL)
+ } else if (client != NULL) {
len = strlen(zone) + strlen(client);
- else
+ } else {
len = strlen(zone);
+ }
/*
* even though datadir and xfrdir will never be in the same
* string we only waste a few bytes by allocating for both,
* and then we are safe from buffer overruns.
*/
- pathsize = len + cd->basedirsize +
- cd->datadirsize + cd->xfrdirsize + 4;
+ pathsize = len + cd->basedirsize + cd->datadirsize + cd->xfrdirsize + 4;
/* if we are splitting names, we will need extra space. */
- if (cd->splitcnt > 0)
- pathsize += len/cd->splitcnt;
-
- tmpPath = isc_mem_allocate(named_g_mctx , pathsize * sizeof(char));
- if (tmpPath == NULL) {
- /* write error message */
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "Filesystem driver unable to "
- "allocate memory in create_path().");
- result = ISC_R_NOMEMORY;
- goto cleanup_mem;
+ if (cd->splitcnt > 0) {
+ pathsize += len / cd->splitcnt;
}
+ tmpPath = isc_mem_allocate(named_g_mctx, pathsize * sizeof(char));
+
/*
* build path string.
* start out with base directory.
@@ -298,9 +298,7 @@ create_path(const char *zone, const char *host, const char *client,
/* add zone name - parsed properly */
if (!isroot) {
- result = create_path_helper(tmpPath, zone, cd);
- if (result != ISC_R_SUCCESS)
- goto cleanup_mem;
+ create_path_helper(tmpPath, zone, cd);
}
/*
@@ -326,7 +324,7 @@ create_path(const char *zone, const char *host, const char *client,
/* if client is passed append xfr dir, otherwise append data dir */
if (client != NULL) {
strcat(tmpPath, cd->xfrdir);
- strncat(tmpPath, (char *) &cd->pathsep, 1);
+ strncat(tmpPath, (char *)&cd->pathsep, 1);
strcat(tmpPath, client);
} else {
strcat(tmpPath, cd->datadir);
@@ -334,37 +332,22 @@ create_path(const char *zone, const char *host, const char *client,
/* if host not null, add it. */
if (host != NULL) {
- strncat(tmpPath, (char *) &cd->pathsep, 1);
- if ((result = create_path_helper(tmpPath, host,
- cd)) != ISC_R_SUCCESS)
- goto cleanup_mem;
+ strncat(tmpPath, (char *)&cd->pathsep, 1);
+ create_path_helper(tmpPath, host, cd);
}
/* return the path we built. */
*path = tmpPath;
- /* return success */
- result = ISC_R_SUCCESS;
-
- cleanup_mem:
- /* cleanup memory */
-
- /* free tmpPath memory */
- if (tmpPath != NULL && result != ISC_R_SUCCESS)
- isc_mem_free(named_g_mctx, tmpPath);
-
- /* free tmpPath memory */
- return (result);
+ return (ISC_R_SUCCESS);
}
static isc_result_t
process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
- dlist_t *dir_list, unsigned int basedirlen)
-{
-
+ dlist_t *dir_list, unsigned int basedirlen) {
char tmp[PATH_MAX + NAME_MAX];
int astPos;
- struct stat sb;
+ struct stat sb;
isc_result_t result = ISC_R_FAILURE;
char *endp;
char *type;
@@ -394,8 +377,8 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
/* if splitcnt == 0, determine host from path. */
if (cd->splitcnt == 0) {
if (strlen(tmp) - 3 > basedirlen) {
- tmp[astPos-1] = '\0';
- tmpString = (char *) &tmp[basedirlen+1];
+ tmp[astPos - 1] = '\0';
+ tmpString = (char *)&tmp[basedirlen + 1];
/* handle filesystem's special wildcard "-" */
if (strcmp(tmpString, "-") == 0) {
strcpy(host, "*");
@@ -403,22 +386,22 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
/*
* not special wildcard -- normal name
*/
- while ((tmpPtr = strrchr(tmpString,
- cd->pathsep))
- != NULL)
- {
+ while ((tmpPtr = strrchr(
+ tmpString,
+ cd->pathsep)) != NULL) {
if ((strlen(host) +
- strlen(tmpPtr + 1) + 2)
- > NAME_MAX)
+ strlen(tmpPtr + 1) + 2) >
+ NAME_MAX) {
continue;
+ }
strcat(host, tmpPtr + 1);
strcat(host, ".");
tmpPtr[0] = '\0';
}
- if ((strlen(host) +
- strlen(tmpString) + 1)
- <= NAME_MAX)
+ if ((strlen(host) + strlen(tmpString) +
+ 1) <= NAME_MAX) {
strcat(host, tmpString);
+ }
}
foundHost = true;
@@ -431,20 +414,21 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
* ".host" directory entry
*/
while (isc_dir_read(dir) == ISC_R_SUCCESS) {
- if (strncasecmp(".host",
- dir->entry.name, 5) == 0) {
+ if (strncasecmp(".host", dir->entry.name, 5) ==
+ 0) {
/*
* handle filesystem's special
* wildcard "-"
*/
- if (strcmp((char *) &dir->entry.name[6],
- "-") == 0)
- {
- strlcpy(host, "*", sizeof(host));
+ if (strcmp((char *)&dir->entry.name[6],
+ "-") == 0) {
+ strlcpy(host, "*",
+ sizeof(host));
} else {
strlcpy(host,
- (char *) &dir->entry.name[6],
- sizeof(host));
+ (char *)&dir->entry
+ .name[6],
+ sizeof(host));
}
foundHost = true;
break;
@@ -456,7 +440,6 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
}
while (isc_dir_read(dir) == ISC_R_SUCCESS) {
-
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
"Filesystem driver Dir name:"
@@ -464,8 +447,9 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
dir->dirname, dir->entry.name);
/* skip any entries starting with "." */
- if (dir->entry.name[0] == '.')
+ if (dir->entry.name[0] == '.') {
continue;
+ }
/*
* get rid of '*', set to NULL. Effectively trims
@@ -480,7 +464,7 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
strcat(tmp, dir->entry.name);
/* make sure we can stat entry */
- if (stat(tmp, &sb) == 0 ) {
+ if (stat(tmp, &sb) == 0) {
/* if entry is a directory */
if ((sb.st_mode & S_IFDIR) != 0) {
/*
@@ -488,11 +472,9 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
* dir list
*/
if (dir_list != NULL) {
- direntry =
- isc_mem_get(named_g_mctx,
- sizeof(dir_entry_t));
- if (direntry == NULL)
- return (ISC_R_NOMEMORY);
+ direntry = isc_mem_get(
+ named_g_mctx,
+ sizeof(dir_entry_t));
strcpy(direntry->dirpath, tmp);
ISC_LINK_INIT(direntry, link);
ISC_LIST_APPEND(*dir_list, direntry,
@@ -507,16 +489,15 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
* are performing a zone xfr and we
* could not find a host entry.
*/
-
- } else if (dir_list != NULL &&
- foundHost == false) {
+ } else if (dir_list != NULL && !foundHost) {
continue;
}
- } else /* if we cannot stat entry, skip it. */
+ } else { /* if we cannot stat entry, skip it. */
continue;
+ }
type = dir->entry.name;
- ttlStr = strchr(type, cd->separator);
+ ttlStr = strchr(type, cd->separator);
if (ttlStr == NULL) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
@@ -529,7 +510,7 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
/* replace separator char with NULL to split string */
ttlStr[0] = '\0';
/* start string after NULL of previous string */
- ttlStr = (char *) &ttlStr[1];
+ ttlStr = (char *)&ttlStr[1];
data = strchr(ttlStr, cd->separator);
if (data == NULL) {
@@ -545,14 +526,15 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
data[0] = '\0';
/* start string after NULL of previous string */
- data = (char *) &data[1];
+ data = (char *)&data[1];
/* replace all cd->separator chars with a space. */
len = strlen(data);
- for (i=0; i < len; i++) {
- if (data[i] == cd->separator)
+ for (i = 0; i < len; i++) {
+ if (data[i] == cd->separator) {
data[i] = ' ';
+ }
}
/* convert text to int, make sure it worked right */
@@ -561,22 +543,23 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Filesystem driver "
- "ttl must be a postive number");
+ "ttl must be a positive number");
}
/* pass data back to Bind */
- if (dir_list == NULL)
- result = dns_sdlz_putrr((dns_sdlzlookup_t *) passback,
+ if (dir_list == NULL) {
+ result = dns_sdlz_putrr((dns_sdlzlookup_t *)passback,
type, ttl, data);
- else
- result = dns_sdlz_putnamedrr((dns_sdlzallnodes_t *)
- passback,
- (char *) host,
- type, ttl, data);
+ } else {
+ result = dns_sdlz_putnamedrr(
+ (dns_sdlzallnodes_t *)passback, (char *)host,
+ type, ttl, data);
+ }
/* if error, return error right away */
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
} /* end of while loop */
return (result);
@@ -588,18 +571,16 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd,
static isc_result_t
fs_allowzonexfr(void *driverarg, void *dbdata, const char *name,
- const char *client)
-{
-
+ const char *client) {
isc_result_t result;
char *path;
- struct stat sb;
+ struct stat sb;
config_data_t *cd;
path = NULL;
UNUSED(driverarg);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
if (create_path(name, NULL, client, cd, &path) != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
@@ -617,22 +598,20 @@ fs_allowzonexfr(void *driverarg, void *dbdata, const char *name,
result = ISC_R_NOTFOUND;
- complete_AXFR:
+complete_AXFR:
isc_mem_free(named_g_mctx, path);
return (result);
}
static isc_result_t
fs_allnodes(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
-
+ dns_sdlzallnodes_t *allnodes) {
isc_result_t result;
dlist_t *dir_list;
config_data_t *cd;
char *basepath;
unsigned int basepathlen;
- struct stat sb;
+ struct stat sb;
isc_dir_t dir;
dir_entry_t *dir_entry;
dir_entry_t *next_de;
@@ -643,14 +622,10 @@ fs_allnodes(const char *zone, void *driverarg, void *dbdata,
UNUSED(driverarg);
UNUSED(allnodes);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
/* allocate memory for list */
dir_list = isc_mem_get(named_g_mctx, sizeof(dlist_t));
- if (dir_list == NULL) {
- result = ISC_R_NOTFOUND;
- goto complete_allnds;
- }
/* initialize list */
ISC_LIST_INIT(*dir_list);
@@ -693,13 +668,13 @@ fs_allnodes(const char *zone, void *driverarg, void *dbdata,
/* close the directory */
isc_dir_close(&dir);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto complete_allnds;
+ }
/* get first dir entry from list. */
dir_entry = ISC_LIST_HEAD(*dir_list);
while (dir_entry != NULL) {
-
result = isc_dir_open(&dir, dir_entry->dirpath);
/* if directory open failed, return error. */
if (result != ISC_R_SUCCESS) {
@@ -718,51 +693,50 @@ fs_allnodes(const char *zone, void *driverarg, void *dbdata,
/* close the directory */
isc_dir_close(&dir);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto complete_allnds;
+ }
dir_entry = ISC_LIST_NEXT(dir_entry, link);
} /* end while */
- complete_allnds:
- if (dir_list != NULL) {
- /* clean up entries from list. */
- dir_entry = ISC_LIST_HEAD(*dir_list);
- while (dir_entry != NULL) {
- next_de = ISC_LIST_NEXT(dir_entry, link);
- isc_mem_put(named_g_mctx, dir_entry, sizeof(dir_entry_t));
- dir_entry = next_de;
- } /* end while */
- isc_mem_put(named_g_mctx, dir_list, sizeof(dlist_t));
- }
+complete_allnds:
+ /* clean up entries from list. */
+ dir_entry = ISC_LIST_HEAD(*dir_list);
+ while (dir_entry != NULL) {
+ next_de = ISC_LIST_NEXT(dir_entry, link);
+ isc_mem_put(named_g_mctx, dir_entry, sizeof(dir_entry_t));
+ dir_entry = next_de;
+ } /* end while */
+ isc_mem_put(named_g_mctx, dir_list, sizeof(dlist_t));
- if (basepath != NULL)
+ if (basepath != NULL) {
isc_mem_free(named_g_mctx, basepath);
+ }
return (result);
}
static isc_result_t
fs_findzone(void *driverarg, void *dbdata, const char *name,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
-
+ dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) {
isc_result_t result;
char *path;
- struct stat sb;
+ struct stat sb;
path = NULL;
UNUSED(driverarg);
UNUSED(methods);
UNUSED(clientinfo);
- if (create_path(name, NULL, NULL, (config_data_t *) dbdata,
- &path) != ISC_R_SUCCESS) {
+ if (create_path(name, NULL, NULL, (config_data_t *)dbdata, &path) !=
+ ISC_R_SUCCESS)
+ {
return (ISC_R_NOTFOUND);
}
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1),
"Filesystem driver Findzone() Checking for path: '%s'\n",
path);
@@ -778,20 +752,19 @@ fs_findzone(void *driverarg, void *dbdata, const char *name,
result = ISC_R_NOTFOUND;
- complete_FZ:
+complete_FZ:
isc_mem_free(named_g_mctx, path);
return (result);
}
static isc_result_t
-fs_lookup(const char *zone, const char *name, void *driverarg,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
+fs_lookup(const char *zone, const char *name, void *driverarg, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
char *path;
- struct stat sb;
+ struct stat sb;
isc_dir_t dir;
path = NULL;
@@ -800,29 +773,29 @@ fs_lookup(const char *zone, const char *name, void *driverarg,
UNUSED(methods);
UNUSED(clientinfo);
- if (strcmp(name, "*") == 0)
+ if (strcmp(name, "*") == 0) {
/*
* handle filesystem's special wildcard "-"
*/
- result = create_path(zone, "-", NULL,
- (config_data_t *) dbdata, &path);
- else
- result = create_path(zone, name, NULL,
- (config_data_t *) dbdata, &path);
+ result = create_path(zone, "-", NULL, (config_data_t *)dbdata,
+ &path);
+ } else {
+ result = create_path(zone, name, NULL, (config_data_t *)dbdata,
+ &path);
+ }
- if ( result != ISC_R_SUCCESS) {
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
}
/* remove path separator at end of path so stat works properly */
- path[strlen(path)-1] = '\0';
+ path[strlen(path) - 1] = '\0';
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1),
"Filesystem driver lookup() Checking for path: '%s'\n",
path);
-
if (stat(path, &sb) != 0) {
result = ISC_R_NOTFOUND;
goto complete_lkup;
@@ -848,21 +821,20 @@ fs_lookup(const char *zone, const char *name, void *driverarg,
}
/* process any records in the directory */
- result = process_dir(&dir, lookup, (config_data_t *) dbdata, NULL, 0);
+ result = process_dir(&dir, lookup, (config_data_t *)dbdata, NULL, 0);
/* close the directory */
isc_dir_close(&dir);
- complete_lkup:
+complete_lkup:
isc_mem_free(named_g_mctx, path);
return (result);
}
static isc_result_t
-fs_create(const char *dlzname, unsigned int argc, char *argv[],
- void *driverarg, void **dbdata)
-{
+fs_create(const char *dlzname, unsigned int argc, char *argv[], void *driverarg,
+ void **dbdata) {
config_data_t *cd;
char *endp;
int len;
@@ -890,7 +862,7 @@ fs_create(const char *dlzname, unsigned int argc, char *argv[],
/* verify base dir ends with '/' or '\' */
len = strlen(argv[1]);
- if (argv[1][len-1] != '\\' && argv[1][len-1] != '/') {
+ if (argv[1][len - 1] != '\\' && argv[1][len - 1] != '/') {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Base dir parameter for filesystem driver "
@@ -900,15 +872,14 @@ fs_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* determine and save path separator for later */
- if (argv[1][len-1] == '\\')
+ if (argv[1][len - 1] == '\\') {
pathsep = '\\';
- else
+ } else {
pathsep = '/';
+ }
/* allocate memory for our config data */
cd = isc_mem_get(named_g_mctx, sizeof(config_data_t));
- if (cd == NULL)
- goto no_mem;
/* zero the memory */
memset(cd, 0, sizeof(config_data_t));
@@ -917,20 +888,14 @@ fs_create(const char *dlzname, unsigned int argc, char *argv[],
/* get and store our base directory */
cd->basedir = isc_mem_strdup(named_g_mctx, argv[1]);
- if (cd->basedir == NULL)
- goto no_mem;
cd->basedirsize = strlen(cd->basedir);
/* get and store our data sub-dir */
cd->datadir = isc_mem_strdup(named_g_mctx, argv[2]);
- if (cd->datadir == NULL)
- goto no_mem;
cd->datadirsize = strlen(cd->datadir);
/* get and store our zone xfr sub-dir */
cd->xfrdir = isc_mem_strdup(named_g_mctx, argv[3]);
- if (cd->xfrdir == NULL)
- goto no_mem;
cd->xfrdirsize = strlen(cd->xfrdir);
/* get and store our directory split count */
@@ -939,7 +904,7 @@ fs_create(const char *dlzname, unsigned int argc, char *argv[],
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Directory split count must be zero (0) "
- "or a postive number");
+ "or a positive number");
}
/* get and store our separator character */
@@ -953,55 +918,38 @@ fs_create(const char *dlzname, unsigned int argc, char *argv[],
/* return success */
return (ISC_R_SUCCESS);
-
- /* handle no memory error */
- no_mem:
-
- /* if we allocated a config data object clean it up */
- if (cd != NULL)
- fs_destroy(NULL, cd);
-
- /* write error message */
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "Filesystem driver unable to "
- "allocate memory for config data.");
-
- /* return error */
- return (ISC_R_NOMEMORY);
}
static void
-fs_destroy(void *driverarg, void *dbdata)
-{
+fs_destroy(void *driverarg, void *dbdata) {
isc_mem_t *mctx;
config_data_t *cd;
UNUSED(driverarg);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
/*
* free memory for each section of config data that was
* allocated
*/
- if (cd->basedir != NULL)
+ if (cd->basedir != NULL) {
isc_mem_free(named_g_mctx, cd->basedir);
+ }
- if (cd->datadir != NULL)
+ if (cd->datadir != NULL) {
isc_mem_free(named_g_mctx, cd->datadir);
+ }
- if (cd->xfrdir != NULL)
+ if (cd->xfrdir != NULL) {
isc_mem_free(named_g_mctx, cd->xfrdir);
+ }
/* hold memory context to use later */
mctx = cd->mctx;
/* free config data memory */
- isc_mem_put(mctx, cd, sizeof(config_data_t));
-
- /* detach memory from context */
- isc_mem_detach(&mctx);
+ isc_mem_putanddetach(&mctx, cd, sizeof(config_data_t));
}
static dns_sdlzmethods_t dlz_fs_methods = {
@@ -1025,20 +973,18 @@ static dns_sdlzmethods_t dlz_fs_methods = {
* Wrapper around dns_sdlzregister().
*/
isc_result_t
-dlz_fs_init(void)
-{
+dlz_fs_init(void) {
isc_result_t result;
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Registering DLZ filesystem driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Registering DLZ filesystem driver.");
result = dns_sdlzregister("filesystem", &dlz_fs_methods, NULL,
DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA,
+ DNS_SDLZFLAG_RELATIVERDATA,
named_g_mctx, &dlz_fs);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
@@ -1055,16 +1001,15 @@ dlz_fs_init(void)
*/
void
dlz_fs_clear(void) {
-
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unregistering DLZ filesystem driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unregistering DLZ filesystem driver.");
- if (dlz_fs != NULL)
+ if (dlz_fs != NULL) {
dns_sdlzunregister(&dlz_fs);
+ }
}
-#endif
+#endif /* ifdef DLZ_FILESYSTEM */
diff --git a/contrib/dlz/drivers/dlz_ldap_driver.c b/contrib/dlz/drivers/dlz_ldap_driver.c
index 845f012b..ead23668 100644
--- a/contrib/dlz/drivers/dlz_ldap_driver.c
+++ b/contrib/dlz/drivers/dlz_ldap_driver.c
@@ -35,24 +35,18 @@
/*
* Copyright (C) 1999-2001, 2016 Internet Systems Consortium, Inc. ("ISC")
- *
+ *
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifdef DLZ_LDAP
-
-#include <config.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <dns/log.h>
-#include <dns/sdlz.h>
-#include <dns/result.h>
-
#include <isc/mem.h>
#include <isc/platform.h>
#include <isc/print.h>
@@ -60,10 +54,13 @@
#include <isc/string.h>
#include <isc/util.h>
-#include <named/globals.h>
+#include <dns/log.h>
+#include <dns/result.h>
+#include <dns/sdlz.h>
-#include <dlz/sdlz_helper.h>
#include <dlz/dlz_ldap_driver.h>
+#include <dlz/sdlz_helper.h>
+#include <named/globals.h>
/*
* Need older API functions from ldap.h.
@@ -73,33 +70,33 @@
#include <ldap.h>
#define SIMPLE "simple"
-#define KRB41 "krb41"
-#define KRB42 "krb42"
-#define V2 "v2"
-#define V3 "v3"
+#define KRB41 "krb41"
+#define KRB42 "krb42"
+#define V2 "v2"
+#define V3 "v3"
static dns_sdlzimplementation_t *dlz_ldap = NULL;
#define dbc_search_limit 30
-#define ALLNODES 1
-#define ALLOWXFR 2
-#define AUTHORITY 3
-#define FINDZONE 4
-#define LOOKUP 5
+#define ALLNODES 1
+#define ALLOWXFR 2
+#define AUTHORITY 3
+#define FINDZONE 4
+#define LOOKUP 5
/*%
- * Structure to hold everthing needed by this "instance" of the LDAP
+ * Structure to hold everything needed by this "instance" of the LDAP
* driver remember, the driver code is only loaded once, but may have
* many separate instances.
*/
typedef struct {
- db_list_t *db; /*%< handle to a list of DB */
- int method; /*%< security authentication method */
- char *user; /*%< who is authenticating */
- char *cred; /*%< password for simple authentication method */
- int protocol; /*%< LDAP communication protocol version */
- char *hosts; /*%< LDAP server hosts */
+ db_list_t *db; /*%< handle to a list of DB */
+ int method; /*%< security authentication method */
+ char *user; /*%< who is authenticating */
+ char *cred; /*%< password for simple authentication method */
+ int protocol; /*%< LDAP communication protocol version */
+ char *hosts; /*%< LDAP server hosts */
} ldap_instance_t;
/* forward references */
@@ -166,7 +163,7 @@ dlz_ldap_checkURL(char *URL, int attrCnt, const char *msg) {
goto cleanup;
}
- if (ldap_url->lud_dn == NULL || strlen (ldap_url->lud_dn) < 1) {
+ if (ldap_url->lud_dn == NULL || strlen(ldap_url->lud_dn) < 1) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%s query must specify a search base", msg);
@@ -184,9 +181,10 @@ dlz_ldap_checkURL(char *URL, int attrCnt, const char *msg) {
goto cleanup;
}
- cleanup:
- if (ldap_url != NULL)
+cleanup:
+ if (ldap_url != NULL) {
ldap_free_urldesc(ldap_url);
+ }
return (result);
}
@@ -199,7 +197,7 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
/* if we have a connection, get ride of it. */
if (dbc->dbconn != NULL) {
- ldap_unbind_s((LDAP *) dbc->dbconn);
+ ldap_unbind_s((LDAP *)dbc->dbconn);
dbc->dbconn = NULL;
}
@@ -207,11 +205,12 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
/* initialize. */
dbc->dbconn = ldap_init(dbi->hosts, LDAP_PORT);
- if (dbc->dbconn == NULL)
+ if (dbc->dbconn == NULL) {
return (ISC_R_NOMEMORY);
+ }
/* set protocol version. */
- ldap_result = ldap_set_option((LDAP *) dbc->dbconn,
+ ldap_result = ldap_set_option((LDAP *)dbc->dbconn,
LDAP_OPT_PROTOCOL_VERSION,
&(dbi->protocol));
if (ldap_result != LDAP_SUCCESS) {
@@ -220,8 +219,8 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
}
/* "bind" to server. i.e. send username / pass */
- ldap_result = ldap_bind_s((LDAP *) dbc->dbconn, dbi->user,
- dbi->cred, dbi->method);
+ ldap_result = ldap_bind_s((LDAP *)dbc->dbconn, dbi->user, dbi->cred,
+ dbi->method);
if (ldap_result != LDAP_SUCCESS) {
result = ISC_R_FAILURE;
goto cleanup;
@@ -229,11 +228,11 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
/* cleanup if failure. */
if (dbc->dbconn != NULL) {
- ldap_unbind_s((LDAP *) dbc->dbconn);
+ ldap_unbind_s((LDAP *)dbc->dbconn);
dbc->dbconn = NULL;
}
@@ -259,8 +258,9 @@ ldap_destroy_dblist(db_list_t *dblist) {
/* get the next DBI in the list */
ndbi = ISC_LIST_NEXT(dbi, link);
/* release DB connection */
- if (dbi->dbconn != NULL)
- ldap_unbind_s((LDAP *) dbi->dbconn);
+ if (dbi->dbconn != NULL) {
+ ldap_unbind_s((LDAP *)dbi->dbconn);
+ }
/* release all memory that comprised a DBI */
destroy_sqldbinstance(dbi);
}
@@ -290,9 +290,9 @@ ldap_find_avail_conn(db_list_t *dblist) {
/* loop through list */
while (count < dbc_search_limit) {
/* try to lock on the mutex */
- if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS)
+ if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) {
return (dbi); /* success, return the DBI for use. */
-
+ }
/* not successful, keep trying */
dbi = ISC_LIST_NEXT(dbi, link);
@@ -302,8 +302,8 @@ ldap_find_avail_conn(db_list_t *dblist) {
dbi = head;
}
}
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_INFO,
"LDAP driver unable to find available connection "
"after searching %d times",
count);
@@ -311,9 +311,8 @@ ldap_find_avail_conn(db_list_t *dblist) {
}
static isc_result_t
-ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
- void *ptr, bool allnodes)
-{
+ldap_process_results(LDAP *dbc, LDAPMessage *msg, char **attrs, void *ptr,
+ bool allnodes) {
isc_result_t result = ISC_R_SUCCESS;
int i = 0;
int j;
@@ -352,8 +351,9 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
/* get the list of values for this attribute. */
vals = ldap_get_values(dbc, entry, attrs[j]);
/* skip empty attributes. */
- if (vals == NULL || ldap_count_values(vals) < 1)
+ if (vals == NULL || ldap_count_values(vals) < 1) {
continue;
+ }
/*
* we only use the first value. this driver
* does not support multi-valued attributes.
@@ -365,14 +365,6 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
/* allocate memory for data string */
data = isc_mem_allocate(named_g_mctx, len + 1);
- if (data == NULL) {
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "LDAP driver unable to allocate memory "
- "while processing results");
- result = ISC_R_FAILURE;
- goto cleanup;
- }
/*
* Make sure data is null termed at the beginning so
@@ -390,7 +382,7 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
/* skip empty attributes. */
if (vals == NULL || vals[0] == NULL) {
- /* increment attibute pointer */
+ /* increment attribute pointer */
attribute = attrs[++i];
/* start loop over */
continue;
@@ -401,7 +393,7 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
* set a field that way next loop will set
* next field.
*/
- switch(j) {
+ switch (j) {
case 0:
j++;
/*
@@ -415,7 +407,7 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
DNS_LOGMODULE_DLZ,
ISC_LOG_ERROR,
"LDAP driver ttl must "
- "be a postive number");
+ "be a positive number");
goto cleanup;
}
break;
@@ -425,17 +417,18 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
break;
case 2:
j++;
- if (allnodes)
+ if (allnodes) {
host = isc_mem_strdup(named_g_mctx,
vals[0]);
- else
+ } else {
strcpy(data, vals[0]);
+ }
break;
case 3:
j++;
- if (allnodes)
+ if (allnodes) {
strcpy(data, vals[0]);
- else {
+ } else {
strcat(data, " ");
strcat(data, vals[0]);
}
@@ -450,9 +443,9 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
ldap_value_free(vals);
vals = NULL;
- /* increment attibute pointer */
+ /* increment attribute pointer */
attribute = attrs[++i];
- } /* end while (attribute != NULL) */
+ } /* end while (attribute != NULL) */
if (type == NULL) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
@@ -473,33 +466,36 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
}
if (allnodes && host != NULL) {
- if (strcasecmp(host, "~") == 0)
+ if (strcasecmp(host, "~") == 0) {
result = dns_sdlz_putnamedrr(
- (dns_sdlzallnodes_t *) ptr,
- "*", type, ttl, data);
- else
+ (dns_sdlzallnodes_t *)ptr, "*", type,
+ ttl, data);
+ } else {
result = dns_sdlz_putnamedrr(
- (dns_sdlzallnodes_t *) ptr,
- host, type, ttl, data);
- if (result != ISC_R_SUCCESS)
+ (dns_sdlzallnodes_t *)ptr, host, type,
+ ttl, data);
+ }
+ if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx,
- DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "dlz-ldap: putnamedrr failed "
- "for \"%s %s %u %s\", %s",
- host, type, ttl, data,
- isc_result_totext(result));
+ DNS_LOGCATEGORY_DATABASE,
+ DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
+ "dlz-ldap: putnamedrr failed "
+ "for \"%s %s %u %s\", %s",
+ host, type, ttl, data,
+ isc_result_totext(result));
+ }
} else {
- result = dns_sdlz_putrr((dns_sdlzlookup_t *) ptr,
- type, ttl, data);
- if (result != ISC_R_SUCCESS)
+ result = dns_sdlz_putrr((dns_sdlzlookup_t *)ptr, type,
+ ttl, data);
+ if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx,
- DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "dlz-ldap: putrr failed "
- "for \"%s %u %s\", %s",
- type, ttl, data,
- isc_result_totext(result));
+ DNS_LOGCATEGORY_DATABASE,
+ DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
+ "dlz-ldap: putrr failed "
+ "for \"%s %u %s\", %s",
+ type, ttl, data,
+ isc_result_totext(result));
+ }
}
if (result != ISC_R_SUCCESS) {
@@ -513,23 +509,28 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
/* free memory for type, data and host for next loop */
isc_mem_free(named_g_mctx, type);
isc_mem_free(named_g_mctx, data);
- if (host != NULL)
+ if (host != NULL) {
isc_mem_free(named_g_mctx, host);
+ }
/* get the next entry to process */
entry = ldap_next_entry(dbc, entry);
} /* end while (entry != NULL) */
- cleanup:
+cleanup:
/* de-allocate memory */
- if (vals != NULL)
+ if (vals != NULL) {
ldap_value_free(vals);
- if (host != NULL)
+ }
+ if (host != NULL) {
isc_mem_free(named_g_mctx, host);
- if (type != NULL)
+ }
+ if (type != NULL) {
isc_mem_free(named_g_mctx, type);
- if (data != NULL)
+ }
+ if (data != NULL) {
isc_mem_free(named_g_mctx, data);
+ }
return (result);
}
@@ -547,10 +548,8 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char ** attrs,
* obtain a result set.
*/
static isc_result_t
-ldap_get_results(const char *zone, const char *record,
- const char *client, unsigned int query,
- void *dbdata, void *ptr)
-{
+ldap_get_results(const char *zone, const char *record, const char *client,
+ unsigned int query, void *dbdata, void *ptr) {
isc_result_t result;
dbinstance_t *dbi = NULL;
char *querystring = NULL;
@@ -562,44 +561,33 @@ ldap_get_results(const char *zone, const char *record,
/* get db instance / connection */
/* find an available DBI from the list */
- dbi = ldap_find_avail_conn((db_list_t *)
- ((ldap_instance_t *)dbdata)->db);
+ dbi = ldap_find_avail_conn(
+ (db_list_t *)((ldap_instance_t *)dbdata)->db);
/* if DBI is null, can't do anything else */
- if (dbi == NULL)
+ if (dbi == NULL) {
return (ISC_R_FAILURE);
+ }
/* set fields */
if (zone != NULL) {
dbi->zone = isc_mem_strdup(named_g_mctx, zone);
- if (dbi->zone == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
} else {
dbi->zone = NULL;
}
if (record != NULL) {
dbi->record = isc_mem_strdup(named_g_mctx, record);
- if (dbi->record == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
} else {
dbi->record = NULL;
}
if (client != NULL) {
dbi->client = isc_mem_strdup(named_g_mctx, client);
- if (dbi->client == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
} else {
dbi->client = NULL;
}
/* what type of query are we going to run? */
- switch(query) {
+ switch (query) {
case ALLNODES:
/*
* if the query was not passed in from the config file
@@ -612,7 +600,7 @@ ldap_get_results(const char *zone, const char *record,
goto cleanup;
} else {
querystring = build_querystring(named_g_mctx,
- dbi->allnodes_q);
+ dbi->allnodes_q);
}
break;
case ALLOWXFR:
@@ -622,7 +610,7 @@ ldap_get_results(const char *zone, const char *record,
goto cleanup;
} else {
querystring = build_querystring(named_g_mctx,
- dbi->allowxfr_q);
+ dbi->allowxfr_q);
}
break;
case AUTHORITY:
@@ -632,7 +620,7 @@ ldap_get_results(const char *zone, const char *record,
goto cleanup;
} else {
querystring = build_querystring(named_g_mctx,
- dbi->authority_q);
+ dbi->authority_q);
}
break;
case FINDZONE:
@@ -646,7 +634,7 @@ ldap_get_results(const char *zone, const char *record,
goto cleanup;
} else {
querystring = build_querystring(named_g_mctx,
- dbi->findzone_q);
+ dbi->findzone_q);
}
break;
case LOOKUP:
@@ -676,7 +664,7 @@ ldap_get_results(const char *zone, const char *record,
}
/* if the querystring is null, Bummer, outta RAM. UPGRADE TIME!!! */
- if (querystring == NULL) {
+ if (querystring == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
@@ -685,11 +673,10 @@ ldap_get_results(const char *zone, const char *record,
* output the full query string during debug so we can see
* what lame error the query has.
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
- "\nQuery String: %s\n", querystring);
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1), "\nQuery String: %s\n", querystring);
- /* break URL down into it's component parts, if error cleanup */
+ /* break URL down into it's component parts, if error cleanup */
ldap_result = ldap_url_parse(querystring, &ldap_url);
if (ldap_result != LDAP_SUCCESS || ldap_url == NULL) {
result = ISC_R_FAILURE;
@@ -697,7 +684,6 @@ ldap_get_results(const char *zone, const char *record,
}
for (i = 0; i < 3; i++) {
-
/*
* dbi->dbconn may be null if trying to reconnect on a
* previous query failed.
@@ -707,7 +693,7 @@ ldap_get_results(const char *zone, const char *record,
DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
"LDAP driver attempting to re-connect");
- result = dlz_ldap_connect((ldap_instance_t *) dbdata,
+ result = dlz_ldap_connect((ldap_instance_t *)dbdata,
dbi);
if (result != ISC_R_SUCCESS) {
result = ISC_R_FAILURE;
@@ -715,27 +701,26 @@ ldap_get_results(const char *zone, const char *record,
}
}
- /* perform ldap search syncronously */
- ldap_result = ldap_search_s((LDAP *) dbi->dbconn,
- ldap_url->lud_dn,
- ldap_url->lud_scope,
- ldap_url->lud_filter,
- ldap_url->lud_attrs, 0, &ldap_msg);
+ /* perform ldap search synchronously */
+ ldap_result =
+ ldap_search_s((LDAP *)dbi->dbconn, ldap_url->lud_dn,
+ ldap_url->lud_scope, ldap_url->lud_filter,
+ ldap_url->lud_attrs, 0, &ldap_msg);
/*
* check return code. No such object is ok, just
* didn't find what we wanted
*/
- switch(ldap_result) {
+ switch (ldap_result) {
case LDAP_NO_SUCH_OBJECT:
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
"No object found matching "
"query requirements");
result = ISC_R_NOTFOUND;
goto cleanup;
break;
- case LDAP_SUCCESS: /* on success do nothing */
+ case LDAP_SUCCESS: /* on success do nothing */
result = ISC_R_SUCCESS;
i = 3;
break;
@@ -743,17 +728,18 @@ ldap_get_results(const char *zone, const char *record,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
"LDAP driver attempting to re-connect");
- result = dlz_ldap_connect((ldap_instance_t *) dbdata,
+ result = dlz_ldap_connect((ldap_instance_t *)dbdata,
dbi);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
result = ISC_R_FAILURE;
+ }
break;
default:
/*
* other errors not ok. Log error message and
* get out
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"LDAP error: %s",
ldap_err2string(ldap_result));
@@ -761,40 +747,41 @@ ldap_get_results(const char *zone, const char *record,
goto cleanup;
break;
} /* close switch(ldap_result) */
- } /* end for (int i = 0 i < 3; i++) */
+ } /* end for (int i = 0 i < 3; i++) */
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup;
+ }
- switch(query) {
+ switch (query) {
case ALLNODES:
- result = ldap_process_results((LDAP *) dbi->dbconn, ldap_msg,
- ldap_url->lud_attrs,
- ptr, true);
+ result = ldap_process_results((LDAP *)dbi->dbconn, ldap_msg,
+ ldap_url->lud_attrs, ptr, true);
break;
case AUTHORITY:
case LOOKUP:
- result = ldap_process_results((LDAP *) dbi->dbconn, ldap_msg,
- ldap_url->lud_attrs,
- ptr, false);
+ result = ldap_process_results((LDAP *)dbi->dbconn, ldap_msg,
+ ldap_url->lud_attrs, ptr, false);
break;
case ALLOWXFR:
- entries = ldap_count_entries((LDAP *) dbi->dbconn, ldap_msg);
- if (entries == 0)
+ entries = ldap_count_entries((LDAP *)dbi->dbconn, ldap_msg);
+ if (entries == 0) {
result = ISC_R_NOPERM;
- else if (entries > 0)
+ } else if (entries > 0) {
result = ISC_R_SUCCESS;
- else
+ } else {
result = ISC_R_FAILURE;
+ }
break;
case FINDZONE:
- entries = ldap_count_entries((LDAP *) dbi->dbconn, ldap_msg);
- if (entries == 0)
+ entries = ldap_count_entries((LDAP *)dbi->dbconn, ldap_msg);
+ if (entries == 0) {
result = ISC_R_NOTFOUND;
- else if (entries > 0)
+ } else if (entries > 0) {
result = ISC_R_SUCCESS;
- else
+ } else {
result = ISC_R_FAILURE;
+ }
break;
default:
/*
@@ -807,30 +794,36 @@ ldap_get_results(const char *zone, const char *record,
result = ISC_R_UNEXPECTED;
}
- cleanup:
+cleanup:
/* it's always good to cleanup after yourself */
- /* if we retrieved results, free them */
- if (ldap_msg != NULL)
+ /* if we retrieved results, free them */
+ if (ldap_msg != NULL) {
ldap_msgfree(ldap_msg);
+ }
- if (ldap_url != NULL)
+ if (ldap_url != NULL) {
ldap_free_urldesc(ldap_url);
+ }
/* cleanup */
- if (dbi->zone != NULL)
+ if (dbi->zone != NULL) {
isc_mem_free(named_g_mctx, dbi->zone);
- if (dbi->record != NULL)
+ }
+ if (dbi->record != NULL) {
isc_mem_free(named_g_mctx, dbi->record);
- if (dbi->client != NULL)
+ }
+ if (dbi->client != NULL) {
isc_mem_free(named_g_mctx, dbi->client);
+ }
/* release the lock so another thread can use this dbi */
isc_mutex_unlock(&dbi->instance_lock);
- /* release query string */
- if (querystring != NULL)
- isc_mem_free(named_g_mctx, querystring );
+ /* release query string */
+ if (querystring != NULL) {
+ isc_mem_free(named_g_mctx, querystring);
+ }
/* return result */
return (result);
@@ -841,8 +834,7 @@ ldap_get_results(const char *zone, const char *record,
*/
static isc_result_t
dlz_ldap_allowzonexfr(void *driverarg, void *dbdata, const char *name,
- const char *client)
-{
+ const char *client) {
isc_result_t result;
UNUSED(driverarg);
@@ -853,23 +845,21 @@ dlz_ldap_allowzonexfr(void *driverarg, void *dbdata, const char *name,
return (result);
}
- /* get all the zone data */
+ /* get all the zone data */
result = ldap_get_results(name, NULL, client, ALLOWXFR, dbdata, NULL);
return (result);
}
static isc_result_t
dlz_ldap_allnodes(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
+ dns_sdlzallnodes_t *allnodes) {
UNUSED(driverarg);
return (ldap_get_results(zone, NULL, NULL, ALLNODES, dbdata, allnodes));
}
static isc_result_t
dlz_ldap_authority(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzlookup_t *lookup)
-{
+ dns_sdlzlookup_t *lookup) {
UNUSED(driverarg);
return (ldap_get_results(zone, NULL, NULL, AUTHORITY, dbdata, lookup));
}
@@ -877,8 +867,7 @@ dlz_ldap_authority(const char *zone, void *driverarg, void *dbdata,
static isc_result_t
dlz_ldap_findzone(void *driverarg, void *dbdata, const char *name,
dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+ dns_clientinfo_t *clientinfo) {
UNUSED(driverarg);
UNUSED(methods);
UNUSED(clientinfo);
@@ -888,28 +877,27 @@ dlz_ldap_findzone(void *driverarg, void *dbdata, const char *name,
static isc_result_t
dlz_ldap_lookup(const char *zone, const char *name, void *driverarg,
void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
+ dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
UNUSED(driverarg);
UNUSED(methods);
UNUSED(clientinfo);
- if (strcmp(name, "*") == 0)
- result = ldap_get_results(zone, "~", NULL, LOOKUP,
- dbdata, lookup);
- else
- result = ldap_get_results(zone, name, NULL, LOOKUP,
- dbdata, lookup);
+ if (strcmp(name, "*") == 0) {
+ result = ldap_get_results(zone, "~", NULL, LOOKUP, dbdata,
+ lookup);
+ } else {
+ result = ldap_get_results(zone, name, NULL, LOOKUP, dbdata,
+ lookup);
+ }
return (result);
}
-
static isc_result_t
dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
- void *driverarg, void **dbdata)
-{
+ void *driverarg, void **dbdata) {
isc_result_t result;
ldap_instance_t *ldap_inst = NULL;
dbinstance_t *dbi = NULL;
@@ -917,17 +905,15 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
int method;
int dbcount;
char *endp;
-/* db_list_t *dblist = NULL; */
+ /* db_list_t *dblist = NULL; */
int i;
-
UNUSED(dlzname);
UNUSED(driverarg);
/* if debugging, let user know we are multithreaded. */
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
- "LDAP driver running multithreaded");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1), "LDAP driver running multithreaded");
if (argc < 9) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
@@ -986,28 +972,33 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* check that LDAP URL parameters make sense */
- switch(argc) {
+ switch (argc) {
case 12:
result = dlz_ldap_checkURL(argv[11], 0, "allow zone transfer");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
case 11:
result = dlz_ldap_checkURL(argv[10], 3, "all nodes");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
case 10:
if (strlen(argv[9]) > 0) {
result = dlz_ldap_checkURL(argv[9], 3, "authority");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
}
case 9:
result = dlz_ldap_checkURL(argv[8], 3, "lookup");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
result = dlz_ldap_checkURL(argv[7], 0, "find zone");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
break;
default:
/* not really needed, should shut up compiler. */
@@ -1016,35 +1007,17 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate memory for LDAP instance */
ldap_inst = isc_mem_get(named_g_mctx, sizeof(ldap_instance_t));
- if (ldap_inst == NULL)
- return (ISC_R_NOMEMORY);
memset(ldap_inst, 0, sizeof(ldap_instance_t));
/* store info needed to automatically re-connect. */
ldap_inst->protocol = protocol;
ldap_inst->method = method;
ldap_inst->hosts = isc_mem_strdup(named_g_mctx, argv[6]);
- if (ldap_inst->hosts == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
ldap_inst->user = isc_mem_strdup(named_g_mctx, argv[4]);
- if (ldap_inst->user == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
ldap_inst->cred = isc_mem_strdup(named_g_mctx, argv[5]);
- if (ldap_inst->cred == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
/* allocate memory for database connection list */
ldap_inst->db = isc_mem_get(named_g_mctx, sizeof(db_list_t));
- if (ldap_inst->db == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
/* initialize DB connection list */
ISC_LIST_INIT(*(ldap_inst->db));
@@ -1054,9 +1027,8 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
* append each new DBI to the end of the list
*/
for (i = 0; i < dbcount; i++) {
-
/* how many queries were passed in from config file? */
- switch(argc) {
+ switch (argc) {
case 9:
result = build_sqldbinstance(named_g_mctx, NULL, NULL,
NULL, argv[7], argv[8],
@@ -1068,15 +1040,14 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
NULL, &dbi);
break;
case 11:
- result = build_sqldbinstance(named_g_mctx, argv[10], NULL,
- argv[9], argv[7], argv[8],
- NULL, &dbi);
+ result = build_sqldbinstance(named_g_mctx, argv[10],
+ NULL, argv[9], argv[7],
+ argv[8], NULL, &dbi);
break;
case 12:
result = build_sqldbinstance(named_g_mctx, argv[10],
- argv[11], argv[9],
- argv[7], argv[8],
- NULL, &dbi);
+ argv[11], argv[9], argv[7],
+ argv[8], NULL, &dbi);
break;
default:
/* not really needed, should shut up compiler. */
@@ -1106,26 +1077,26 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
* if db connection cannot be created, log err msg and
* cleanup.
*/
- switch(result) {
- /* success, do nothing */
+ switch (result) {
+ /* success, do nothing */
case ISC_R_SUCCESS:
break;
- /*
- * no memory means ldap_init could not
- * allocate memory
- */
+ /*
+ * no memory means ldap_init could not
+ * allocate memory
+ */
case ISC_R_NOMEMORY:
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"LDAP driver could not allocate memory "
"for connection number %u",
- i+1);
+ i + 1);
goto cleanup;
break;
- /*
- * no perm means ldap_set_option could not set
- * protocol version
- */
+ /*
+ * no perm means ldap_set_option could not set
+ * protocol version
+ */
case ISC_R_NOPERM:
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
@@ -1134,19 +1105,19 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
result = ISC_R_FAILURE;
goto cleanup;
break;
- /* failure means couldn't connect to ldap server */
+ /* failure means couldn't connect to ldap server */
case ISC_R_FAILURE:
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"LDAP driver could not "
"bind connection number %u to server.",
- i+1);
+ i + 1);
goto cleanup;
break;
- /*
- * default should never happen. If it does,
- * major errors.
- */
+ /*
+ * default should never happen. If it does,
+ * major errors.
+ */
default:
UNEXPECTED_ERROR(__FILE__, __LINE__,
"dlz_ldap_create() failed: %s",
@@ -1158,19 +1129,18 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[],
/* set DBI = null for next loop through. */
dbi = NULL;
- } /* end for loop */
-
+ } /* end for loop */
/* set dbdata to the ldap_instance we created. */
*dbdata = ldap_inst;
/* hey, we got through all of that ok, return success. */
- return(ISC_R_SUCCESS);
+ return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
dlz_ldap_destroy(NULL, ldap_inst);
- return(ISC_R_FAILURE);
+ return (ISC_R_FAILURE);
}
void
@@ -1179,20 +1149,23 @@ dlz_ldap_destroy(void *driverarg, void *dbdata) {
if (dbdata != NULL) {
/* cleanup the list of DBI's */
- ldap_destroy_dblist((db_list_t *)
- ((ldap_instance_t *)dbdata)->db);
+ ldap_destroy_dblist(
+ (db_list_t *)((ldap_instance_t *)dbdata)->db);
- if (((ldap_instance_t *)dbdata)->hosts != NULL)
+ if (((ldap_instance_t *)dbdata)->hosts != NULL) {
isc_mem_free(named_g_mctx,
((ldap_instance_t *)dbdata)->hosts);
+ }
- if (((ldap_instance_t *)dbdata)->user != NULL)
+ if (((ldap_instance_t *)dbdata)->user != NULL) {
isc_mem_free(named_g_mctx,
((ldap_instance_t *)dbdata)->user);
+ }
- if (((ldap_instance_t *)dbdata)->cred != NULL)
+ if (((ldap_instance_t *)dbdata)->cred != NULL) {
isc_mem_free(named_g_mctx,
((ldap_instance_t *)dbdata)->cred);
+ }
isc_mem_put(named_g_mctx, dbdata, sizeof(ldap_instance_t));
}
@@ -1225,13 +1198,12 @@ dlz_ldap_init(void) {
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Registering DLZ ldap driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Registering DLZ ldap driver.");
result = dns_sdlzregister("ldap", &dlz_ldap_methods, NULL,
DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA,
+ DNS_SDLZFLAG_RELATIVERDATA,
named_g_mctx, &dlz_ldap);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
@@ -1251,12 +1223,12 @@ dlz_ldap_clear(void) {
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unregistering DLZ ldap driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unregistering DLZ ldap driver.");
- if (dlz_ldap != NULL)
+ if (dlz_ldap != NULL) {
dns_sdlzunregister(&dlz_ldap);
+ }
}
-#endif
+#endif /* ifdef DLZ_LDAP */
diff --git a/contrib/dlz/drivers/dlz_mysql_driver.c b/contrib/dlz/drivers/dlz_mysql_driver.c
index 22750487..86a7f59e 100644
--- a/contrib/dlz/drivers/dlz_mysql_driver.c
+++ b/contrib/dlz/drivers/dlz_mysql_driver.c
@@ -42,15 +42,10 @@
*/
#ifdef DLZ_MYSQL
-
-#include <config.h>
+#include <mysql.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-
-#include <dns/log.h>
-#include <dns/sdlz.h>
-#include <dns/result.h>
+#include <string.h>
#include <isc/mem.h>
#include <isc/platform.h>
@@ -59,22 +54,27 @@
#include <isc/string.h>
#include <isc/util.h>
-#include <named/globals.h>
+#include <dns/log.h>
+#include <dns/result.h>
+#include <dns/sdlz.h>
-#include <dlz/sdlz_helper.h>
#include <dlz/dlz_mysql_driver.h>
+#include <dlz/sdlz_helper.h>
+#include <named/globals.h>
-#include <mysql.h>
+#if !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000
+typedef bool my_bool;
+#endif /* !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 */
static dns_sdlzimplementation_t *dlz_mysql = NULL;
#define dbc_search_limit 30
-#define ALLNODES 1
-#define ALLOWXFR 2
-#define AUTHORITY 3
-#define FINDZONE 4
-#define COUNTZONE 5
-#define LOOKUP 6
+#define ALLNODES 1
+#define ALLOWXFR 2
+#define AUTHORITY 3
+#define FINDZONE 4
+#define COUNTZONE 5
+#define LOOKUP 6
#define safeGet(in) in == NULL ? "" : in
@@ -92,22 +92,20 @@ static dns_sdlzimplementation_t *dlz_mysql = NULL;
static char *
mysqldrv_escape_string(MYSQL *mysql, const char *instr) {
-
char *outstr;
unsigned int len;
- if (instr == NULL)
- return NULL;
+ if (instr == NULL) {
+ return (NULL);
+ }
len = strlen(instr);
- outstr = isc_mem_allocate(named_g_mctx ,(2 * len * sizeof(char)) + 1);
- if (outstr == NULL)
- return NULL;
+ outstr = isc_mem_allocate(named_g_mctx, (2 * len * sizeof(char)) + 1);
mysql_real_escape_string(mysql, outstr, instr, len);
- return outstr;
+ return (outstr);
}
/*%
@@ -121,10 +119,8 @@ mysqldrv_escape_string(MYSQL *mysql, const char *instr) {
*/
static isc_result_t
-mysql_get_resultset(const char *zone, const char *record,
- const char *client, unsigned int query,
- void *dbdata, MYSQL_RES **rs)
-{
+mysql_get_resultset(const char *zone, const char *record, const char *client,
+ unsigned int query, void *dbdata, MYSQL_RES **rs) {
isc_result_t result;
dbinstance_t *dbi = NULL;
char *querystring = NULL;
@@ -132,22 +128,22 @@ mysql_get_resultset(const char *zone, const char *record,
unsigned int j = 0;
int qres = 0;
- if (query != COUNTZONE)
+ if (query != COUNTZONE) {
REQUIRE(*rs == NULL);
- else
+ } else {
REQUIRE(rs == NULL);
+ }
/* get db instance / connection */
- dbi = (dbinstance_t *) dbdata;
+ dbi = (dbinstance_t *)dbdata;
/* if DBI is null, can't do anything else */
if (dbi == NULL) {
- result = ISC_R_FAILURE;
- goto cleanup;
+ return (ISC_R_FAILURE);
}
/* what type of query are we going to run? */
- switch(query) {
+ switch (query) {
case ALLNODES:
/*
* if the query was not passed in from the config file
@@ -215,19 +211,17 @@ mysql_get_resultset(const char *zone, const char *record,
goto cleanup;
}
-
/*
* was a zone string passed? If so, make it safe for use in
* queries.
*/
if (zone != NULL) {
- dbi->zone = mysqldrv_escape_string((MYSQL *) dbi->dbconn,
- zone);
+ dbi->zone = mysqldrv_escape_string((MYSQL *)dbi->dbconn, zone);
if (dbi->zone == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->zone = NULL;
}
@@ -236,13 +230,13 @@ mysql_get_resultset(const char *zone, const char *record,
* queries.
*/
if (record != NULL) {
- dbi->record = mysqldrv_escape_string((MYSQL *) dbi->dbconn,
+ dbi->record = mysqldrv_escape_string((MYSQL *)dbi->dbconn,
record);
if (dbi->record == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->record = NULL;
}
@@ -251,13 +245,13 @@ mysql_get_resultset(const char *zone, const char *record,
* queries.
*/
if (client != NULL) {
- dbi->client = mysqldrv_escape_string((MYSQL *) dbi->dbconn,
+ dbi->client = mysqldrv_escape_string((MYSQL *)dbi->dbconn,
client);
if (dbi->client == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->client = NULL;
}
@@ -265,7 +259,7 @@ mysql_get_resultset(const char *zone, const char *record,
* what type of query are we going to run? this time we build
* the actual query to run.
*/
- switch(query) {
+ switch (query) {
case ALLNODES:
querystring = build_querystring(named_g_mctx, dbi->allnodes_q);
break;
@@ -306,56 +300,56 @@ mysql_get_resultset(const char *zone, const char *record,
* output the full query string during debug so we can see
* what lame error the query has.
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
- "\nQuery String: %s\n", querystring);
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1), "\nQuery String: %s\n", querystring);
/* attempt query up to 3 times. */
- for (i=0; i < 3; i++) {
- qres = mysql_query((MYSQL *) dbi->dbconn, querystring);
- if (qres == 0)
+ for (i = 0; i < 3; i++) {
+ qres = mysql_query((MYSQL *)dbi->dbconn, querystring);
+ if (qres == 0) {
break;
- for (j=0; mysql_ping((MYSQL *) dbi->dbconn) != 0 && j < 4; j++)
+ }
+ for (j = 0; mysql_ping((MYSQL *)dbi->dbconn) != 0 && j < 4; j++)
;
}
if (qres == 0) {
result = ISC_R_SUCCESS;
if (query != COUNTZONE) {
- *rs = mysql_store_result((MYSQL *) dbi->dbconn);
- if (*rs == NULL)
+ *rs = mysql_store_result((MYSQL *)dbi->dbconn);
+ if (*rs == NULL) {
result = ISC_R_FAILURE;
+ }
}
} else {
result = ISC_R_FAILURE;
}
-
- cleanup:
+cleanup:
/* it's always good to cleanup after yourself */
- /* if we couldn't even get DBI, just return NULL */
- if (dbi == NULL)
- return ISC_R_FAILURE;
-
/* free dbi->zone string */
- if (dbi->zone != NULL)
+ if (dbi->zone != NULL) {
isc_mem_free(named_g_mctx, dbi->zone);
+ }
/* free dbi->record string */
- if (dbi->record != NULL)
+ if (dbi->record != NULL) {
isc_mem_free(named_g_mctx, dbi->record);
+ }
/* free dbi->client string */
- if (dbi->client != NULL)
+ if (dbi->client != NULL) {
isc_mem_free(named_g_mctx, dbi->client);
+ }
/* release query string */
- if (querystring != NULL)
+ if (querystring != NULL) {
isc_mem_free(named_g_mctx, querystring);
+ }
/* return result */
- return result;
+ return (result);
}
/*%
@@ -365,8 +359,7 @@ mysql_get_resultset(const char *zone, const char *record,
*/
static isc_result_t
-mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs)
-{
+mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs) {
isc_result_t result = ISC_R_NOTFOUND;
MYSQL_ROW row;
unsigned int fields;
@@ -376,10 +369,10 @@ mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs)
char *endp;
int ttl;
- row = mysql_fetch_row(rs); /* get a row from the result set */
- fields = mysql_num_fields(rs); /* how many columns in result set */
+ row = mysql_fetch_row(rs); /* get a row from the result set */
+ fields = mysql_num_fields(rs); /* how many columns in result set */
while (row != NULL) {
- switch(fields) {
+ switch (fields) {
case 1:
/*
* one column in rs, it's the data field. use
@@ -409,7 +402,7 @@ mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs)
DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver ttl must be "
- "a postive number");
+ "a positive number");
}
result = dns_sdlz_putrr(lookup, safeGet(row[1]), ttl,
safeGet(row[2]));
@@ -420,7 +413,7 @@ mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs)
* ones together. figure out how long to make
* string.
*/
- for (j=2, len=0; j < fields; j++) {
+ for (j = 2, len = 0; j < fields; j++) {
len += strlen(safeGet(row[j])) + 1;
}
/*
@@ -428,26 +421,14 @@ mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs)
* term string
*/
tmpString = isc_mem_allocate(named_g_mctx, len + 1);
- if (tmpString == NULL) {
- /* major bummer, need more ram */
- isc_log_write(dns_lctx,
- DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "mysql driver unable "
- "to allocate memory for "
- "temporary string");
- mysql_free_result(rs);
- return (ISC_R_FAILURE); /* Yeah, I'd say! */
- }
/* copy field to tmpString */
strcpy(tmpString, safeGet(row[2]));
-
/*
* concat the rest of fields together, space
* between each one.
*/
- for (j=3; j < fields; j++) {
+ for (j = 3; j < fields; j++) {
strcat(tmpString, " ");
strcat(tmpString, safeGet(row[j]));
}
@@ -458,11 +439,11 @@ mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs)
DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver ttl must be "
- "a postive number");
+ "a positive number");
}
/* ok, now tell Bind about it. */
- result = dns_sdlz_putrr(lookup, safeGet(row[1]),
- ttl, tmpString);
+ result = dns_sdlz_putrr(lookup, safeGet(row[1]), ttl,
+ tmpString);
/* done, get rid of this thing. */
isc_mem_free(named_g_mctx, tmpString);
}
@@ -477,14 +458,14 @@ mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs)
isc_result_totext(result));
return (ISC_R_FAILURE);
}
- row = mysql_fetch_row(rs); /* get next row */
+ row = mysql_fetch_row(rs); /* get next row */
}
/* free result set memory */
mysql_free_result(rs);
/* return result code */
- return result;
+ return (result);
}
/*
@@ -495,8 +476,7 @@ mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs)
static isc_result_t
mysql_findzone(void *driverarg, void *dbdata, const char *name,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
+ dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) {
isc_result_t result;
MYSQL_RES *rs = NULL;
my_ulonglong rows;
@@ -509,8 +489,9 @@ mysql_findzone(void *driverarg, void *dbdata, const char *name,
result = mysql_get_resultset(name, NULL, NULL, FINDZONE, dbdata, &rs);
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS || rs == NULL) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver unable to return "
@@ -535,8 +516,7 @@ mysql_findzone(void *driverarg, void *dbdata, const char *name,
/*% Determine if the client is allowed to perform a zone transfer */
static isc_result_t
mysql_allowzonexfr(void *driverarg, void *dbdata, const char *name,
- const char *client)
-{
+ const char *client) {
isc_result_t result;
MYSQL_RES *rs = NULL;
my_ulonglong rows;
@@ -545,8 +525,9 @@ mysql_allowzonexfr(void *driverarg, void *dbdata, const char *name,
/* first check if the zone is supported by the database. */
result = mysql_findzone(driverarg, dbdata, name, NULL, NULL);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
/*
* if we get to this point we know the zone is supported by
@@ -556,15 +537,16 @@ mysql_allowzonexfr(void *driverarg, void *dbdata, const char *name,
*
* Run our query, and get a result set from the database.
*/
- result = mysql_get_resultset(name, NULL, client, ALLOWXFR,
- dbdata, &rs);
+ result = mysql_get_resultset(name, NULL, client, ALLOWXFR, dbdata, &rs);
/* if we get "not implemented", send it along. */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS || rs == NULL) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver unable to return "
@@ -577,8 +559,9 @@ mysql_allowzonexfr(void *driverarg, void *dbdata, const char *name,
mysql_free_result(rs);
/* if we returned any rows, zone xfr is allowed. */
- if (rows > 0)
+ if (rows > 0) {
return (ISC_R_SUCCESS);
+ }
/* no rows returned, zone xfr not allowed */
return (ISC_R_NOPERM);
@@ -591,8 +574,7 @@ mysql_allowzonexfr(void *driverarg, void *dbdata, const char *name,
*/
static isc_result_t
mysql_allnodes(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
+ dns_sdlzallnodes_t *allnodes) {
isc_result_t result;
MYSQL_RES *rs = NULL;
MYSQL_ROW row;
@@ -608,12 +590,14 @@ mysql_allnodes(const char *zone, void *driverarg, void *dbdata,
/* run the query and get the result set from the database. */
result = mysql_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs);
/* if we get "not implemented", send it along */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver unable to return "
@@ -623,10 +607,10 @@ mysql_allnodes(const char *zone, void *driverarg, void *dbdata,
result = ISC_R_NOTFOUND;
- row = mysql_fetch_row(rs); /* get a row from the result set */
- fields = mysql_num_fields(rs); /* how many columns in result set */
+ row = mysql_fetch_row(rs); /* get a row from the result set */
+ fields = mysql_num_fields(rs); /* how many columns in result set */
while (row != NULL) {
- if (fields < 4) { /* gotta have at least 4 columns */
+ if (fields < 4) { /* gotta have at least 4 columns */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver too few fields returned "
@@ -638,7 +622,7 @@ mysql_allnodes(const char *zone, void *driverarg, void *dbdata,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver ttl must be "
- "a postive number");
+ "a positive number");
}
if (fields == 4) {
/* tell Bind about it. */
@@ -651,32 +635,22 @@ mysql_allnodes(const char *zone, void *driverarg, void *dbdata,
* ones together. figure out how long to make
* string.
*/
- for (j=3, len=0; j < fields; j++) {
+ for (j = 3, len = 0; j < fields; j++) {
len += strlen(safeGet(row[j])) + 1;
}
/* allocate memory, allow for NULL to term string */
tmpString = isc_mem_allocate(named_g_mctx, len + 1);
- if (tmpString == NULL) { /* we need more ram. */
- isc_log_write(dns_lctx,
- DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "mysql driver unable "
- "to allocate memory for "
- "temporary string");
- mysql_free_result(rs);
- return (ISC_R_FAILURE);
- }
/* copy this field to tmpString */
strcpy(tmpString, safeGet(row[3]));
- /* concatonate the rest, with spaces between */
- for (j=4; j < fields; j++) {
+ /* concatenate the rest, with spaces between */
+ for (j = 4; j < fields; j++) {
strcat(tmpString, " ");
strcat(tmpString, safeGet(row[j]));
}
/* tell Bind about it. */
result = dns_sdlz_putnamedrr(allnodes, safeGet(row[2]),
- safeGet(row[1]),
- ttl, tmpString);
+ safeGet(row[1]), ttl,
+ tmpString);
isc_mem_free(named_g_mctx, tmpString);
}
/* if we weren't successful, log err msg */
@@ -696,7 +670,7 @@ mysql_allnodes(const char *zone, void *driverarg, void *dbdata,
/* free result set memory */
mysql_free_result(rs);
- return result;
+ return (result);
}
/*% if the lookup function does not return SOA or NS records for the zone,
@@ -705,8 +679,7 @@ mysql_allnodes(const char *zone, void *driverarg, void *dbdata,
static isc_result_t
mysql_authority(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzlookup_t *lookup)
-{
+ dns_sdlzlookup_t *lookup) {
isc_result_t result;
MYSQL_RES *rs = NULL;
@@ -715,12 +688,14 @@ mysql_authority(const char *zone, void *driverarg, void *dbdata,
/* run the query and get the result set from the database. */
result = mysql_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata, &rs);
/* if we get "not implemented", send it along */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver unable to return "
@@ -731,15 +706,14 @@ mysql_authority(const char *zone, void *driverarg, void *dbdata,
* lookup and authority result sets are processed in the same
* manner mysql_process_rs does the job for both functions.
*/
- return mysql_process_rs(lookup, rs);
+ return (mysql_process_rs(lookup, rs));
}
/*% if zone is supported, lookup up a (or multiple) record(s) in it */
static isc_result_t
-mysql_lookup(const char *zone, const char *name, void *driverarg,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
+mysql_lookup(const char *zone, const char *name, void *driverarg, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
MYSQL_RES *rs = NULL;
@@ -751,8 +725,9 @@ mysql_lookup(const char *zone, const char *name, void *driverarg,
result = mysql_get_resultset(zone, name, NULL, LOOKUP, dbdata, &rs);
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"mysql driver unable to return "
@@ -763,7 +738,7 @@ mysql_lookup(const char *zone, const char *name, void *driverarg,
* lookup and authority result sets are processed in the same manner
* mysql_process_rs does the job for both functions.
*/
- return mysql_process_rs(lookup, rs);
+ return (mysql_process_rs(lookup, rs));
}
/*%
@@ -774,8 +749,7 @@ mysql_lookup(const char *zone, const char *name, void *driverarg,
*/
static isc_result_t
mysql_create(const char *dlzname, unsigned int argc, char *argv[],
- void *driverarg, void **dbdata)
-{
+ void *driverarg, void **dbdata) {
isc_result_t result;
dbinstance_t *dbi = NULL;
char *tmp = NULL;
@@ -789,9 +763,6 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
char *endp;
int j;
unsigned int flags = 0;
-#if MYSQL_VERSION_ID >= 50000
- my_bool auto_reconnect = 1;
-#endif
UNUSED(driverarg);
UNUSED(dlzname);
@@ -814,7 +785,7 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_FAILURE);
}
- /* parse connection string and get paramters. */
+ /* parse connection string and get parameters. */
/* get db name - required */
dbname = getParameterValue(argv[1], "dbname=");
@@ -845,7 +816,7 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* how many queries were passed in from config file? */
- switch(argc) {
+ switch (argc) {
case 4:
result = build_sqldbinstance(named_g_mctx, NULL, NULL, NULL,
argv[2], argv[3], NULL, &dbi);
@@ -855,18 +826,19 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
argv[2], argv[3], NULL, &dbi);
break;
case 6:
- result = build_sqldbinstance(named_g_mctx, argv[5], NULL, argv[4],
- argv[2], argv[3], NULL, &dbi);
+ result = build_sqldbinstance(named_g_mctx, argv[5], NULL,
+ argv[4], argv[2], argv[3], NULL,
+ &dbi);
break;
case 7:
- result = build_sqldbinstance(named_g_mctx, argv[5],
- argv[6], argv[4],
- argv[2], argv[3], NULL, &dbi);
+ result = build_sqldbinstance(named_g_mctx, argv[5], argv[6],
+ argv[4], argv[2], argv[3], NULL,
+ &dbi);
break;
case 8:
- result = build_sqldbinstance(named_g_mctx, argv[5],
- argv[6], argv[4],
- argv[2], argv[3], argv[7], &dbi);
+ result = build_sqldbinstance(named_g_mctx, argv[5], argv[6],
+ argv[4], argv[2], argv[3], argv[7],
+ &dbi);
break;
default:
/* not really needed, should shut up compiler. */
@@ -898,22 +870,25 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
tmp = getParameterValue(argv[1], "compress=");
if (tmp != NULL) {
- if (strcasecmp(tmp, "true") == 0)
+ if (strcasecmp(tmp, "true") == 0) {
flags = CLIENT_COMPRESS;
+ }
isc_mem_free(named_g_mctx, tmp);
}
tmp = getParameterValue(argv[1], "ssl=");
if (tmp != NULL) {
- if (strcasecmp(tmp, "true") == 0)
+ if (strcasecmp(tmp, "true") == 0) {
flags = flags | CLIENT_SSL;
+ }
isc_mem_free(named_g_mctx, tmp);
}
tmp = getParameterValue(argv[1], "space=");
if (tmp != NULL) {
- if (strcasecmp(tmp, "ignore") == 0)
+ if (strcasecmp(tmp, "ignore") == 0) {
flags = flags | CLIENT_IGNORE_SPACE;
+ }
isc_mem_free(named_g_mctx, tmp);
}
@@ -923,21 +898,21 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
pass = getParameterValue(argv[1], "pass=");
socket = getParameterValue(argv[1], "socket=");
-#if MYSQL_VERSION_ID >= 50000
/* enable automatic reconnection. */
- if (mysql_options((MYSQL *) dbi->dbconn, MYSQL_OPT_RECONNECT,
- &auto_reconnect) != 0) {
+ if (mysql_options((MYSQL *)dbi->dbconn, MYSQL_OPT_RECONNECT,
+ &(my_bool){ 1 }) != 0)
+ {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_WARNING,
"mysql driver failed to set "
- "MYSQL_OPT_RECONNECT option, continuing");
+ "MYSQL_OPT_RECONNECT option, "
+ "continuing");
}
-#endif
- for (j=0; dbc == NULL && j < 4; j++)
- dbc = mysql_real_connect((MYSQL *) dbi->dbconn, host,
- user, pass, dbname, port, socket,
- flags);
+ for (j = 0; dbc == NULL && j < 4; j++) {
+ dbc = mysql_real_connect((MYSQL *)dbi->dbconn, host, user, pass,
+ dbname, port, socket, flags);
+ }
/* let user know if we couldn't connect. */
if (dbc == NULL) {
@@ -955,26 +930,31 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
result = ISC_R_SUCCESS;
goto cleanup;
- full_cleanup:
+full_cleanup:
- if (dbi != NULL)
+ if (dbi != NULL) {
destroy_sqldbinstance(dbi);
+ }
- cleanup:
+cleanup:
- if (dbname != NULL)
+ if (dbname != NULL) {
isc_mem_free(named_g_mctx, dbname);
- if (host != NULL)
+ }
+ if (host != NULL) {
isc_mem_free(named_g_mctx, host);
- if (user != NULL)
+ }
+ if (user != NULL) {
isc_mem_free(named_g_mctx, user);
- if (pass != NULL)
+ }
+ if (pass != NULL) {
isc_mem_free(named_g_mctx, pass);
- if (socket != NULL)
+ }
+ if (socket != NULL) {
isc_mem_free(named_g_mctx, socket);
+ }
-
- return result;
+ return (result);
}
/*%
@@ -985,17 +965,17 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[],
*/
static void
-mysql_destroy(void *driverarg, void *dbdata)
-{
+mysql_destroy(void *driverarg, void *dbdata) {
dbinstance_t *dbi;
UNUSED(driverarg);
- dbi = (dbinstance_t *) dbdata;
+ dbi = (dbinstance_t *)dbdata;
/* release DB connection */
- if (dbi->dbconn != NULL)
- mysql_close((MYSQL *) dbi->dbconn);
+ if (dbi->dbconn != NULL) {
+ mysql_close((MYSQL *)dbi->dbconn);
+ }
/* destroy DB instance */
destroy_sqldbinstance(dbi);
@@ -1031,20 +1011,19 @@ dlz_mysql_init(void) {
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Registering DLZ mysql driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Registering DLZ mysql driver.");
/* Driver is always threadsafe. Because of the way MySQL handles
- * threads the MySQL driver can only be used when bind is run single
- * threaded. Using MySQL with Bind running multi-threaded is not
- * allowed. When using the MySQL driver "-n1" should always be
- * passed to Bind to guarantee single threaded operation.
+ * threads the MySQL driver can only be used when bind is run single
+ * threaded. Using MySQL with Bind running multi-threaded is not
+ * allowed. When using the MySQL driver "-n1" should always be
+ * passed to Bind to guarantee single threaded operation.
*/
result = dns_sdlzregister("mysql", &dlz_mysql_methods, NULL,
DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA |
- DNS_SDLZFLAG_THREADSAFE,
+ DNS_SDLZFLAG_RELATIVERDATA |
+ DNS_SDLZFLAG_THREADSAFE,
named_g_mctx, &dlz_mysql);
/* if we can't register the driver, there are big problems. */
if (result != ISC_R_SUCCESS) {
@@ -1054,8 +1033,7 @@ dlz_mysql_init(void) {
result = ISC_R_UNEXPECTED;
}
-
- return result;
+ return (result);
}
/*%
@@ -1063,17 +1041,16 @@ dlz_mysql_init(void) {
*/
void
dlz_mysql_clear(void) {
-
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unregistering DLZ mysql driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unregistering DLZ mysql driver.");
/* unregister the driver. */
- if (dlz_mysql != NULL)
+ if (dlz_mysql != NULL) {
dns_sdlzunregister(&dlz_mysql);
+ }
}
-#endif
+#endif /* ifdef DLZ_MYSQL */
diff --git a/contrib/dlz/drivers/dlz_odbc_driver.c b/contrib/dlz/drivers/dlz_odbc_driver.c
index 2acd4049..d251721b 100644
--- a/contrib/dlz/drivers/dlz_odbc_driver.c
+++ b/contrib/dlz/drivers/dlz_odbc_driver.c
@@ -35,22 +35,19 @@
/*
* Copyright (C) 1999-2001, 2016 Internet Systems Consortium, Inc. ("ISC")
- *
+ *
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifdef DLZ_ODBC
-
-#include <config.h>
+#include <sql.h>
+#include <sqlext.h>
+#include <sqltypes.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-
-#include <dns/log.h>
-#include <dns/sdlz.h>
-#include <dns/result.h>
+#include <string.h>
#include <isc/mem.h>
#include <isc/platform.h>
@@ -59,23 +56,22 @@
#include <isc/string.h>
#include <isc/util.h>
-#include <named/globals.h>
+#include <dns/log.h>
+#include <dns/result.h>
+#include <dns/sdlz.h>
-#include <dlz/sdlz_helper.h>
#include <dlz/dlz_odbc_driver.h>
-
-#include <sql.h>
-#include <sqlext.h>
-#include <sqltypes.h>
+#include <dlz/sdlz_helper.h>
+#include <named/globals.h>
static dns_sdlzimplementation_t *dlz_odbc = NULL;
#define dbc_search_limit 30
-#define ALLNODES 1
-#define ALLOWXFR 2
-#define AUTHORITY 3
-#define FINDZONE 4
-#define LOOKUP 5
+#define ALLNODES 1
+#define ALLOWXFR 2
+#define AUTHORITY 3
+#define FINDZONE 4
+#define LOOKUP 5
#define sqlOK(a) ((a == SQL_SUCCESS || a == SQL_SUCCESS_WITH_INFO) ? -1 : 0)
@@ -87,23 +83,23 @@ static dns_sdlzimplementation_t *dlz_odbc = NULL;
* structure to hold ODBC connection & statement
*/
-typedef struct{
- SQLHDBC dbc;
- SQLHSTMT stmnt;
+typedef struct {
+ SQLHDBC dbc;
+ SQLHSTMT stmnt;
} odbc_db_t;
/*
- * Structure to hold everthing needed by this "instance" of the odbc driver
+ * Structure to hold everything needed by this "instance" of the odbc driver
* remember, the driver code is only loaded once, but may have many separate
* instances
*/
typedef struct {
- db_list_t *db; /* handle to a list of DB */
- SQLHENV sql_env; /* handle to SQL environment */
- SQLCHAR *dsn;
- SQLCHAR *user;
- SQLCHAR *pass;
+ db_list_t *db; /* handle to a list of DB */
+ SQLHENV sql_env; /* handle to SQL environment */
+ SQLCHAR *dsn;
+ SQLCHAR *user;
+ SQLCHAR *pass;
} odbc_instance_t;
/* forward reference */
@@ -117,12 +113,13 @@ odbc_makesafe(char *to, const char *from, size_t length);
static SQLSMALLINT
safeLen(void *a) {
- if (a == NULL)
- return 0;
- return strlen((char *) a);
+ if (a == NULL) {
+ return (0);
+ }
+ return (strlen((char *)a));
}
-/*% propertly cleans up an odbc_instance_t */
+/*% properly cleans up an odbc_instance_t */
static void
destroy_odbc_instance(odbc_instance_t *odbc_inst) {
@@ -141,21 +138,20 @@ destroy_odbc_instance(odbc_instance_t *odbc_inst) {
/* if we have a connection / statement object in memory */
if (dbi->dbconn != NULL) {
/* free statement handle */
- if (((odbc_db_t *) (dbi->dbconn))->stmnt != NULL) {
- SQLFreeHandle(SQL_HANDLE_STMT,
- ((odbc_db_t *)
- (dbi->dbconn))->stmnt);
- ((odbc_db_t *) (dbi->dbconn))->stmnt = NULL;
+ if (((odbc_db_t *)(dbi->dbconn))->stmnt != NULL) {
+ SQLFreeHandle(
+ SQL_HANDLE_STMT,
+ ((odbc_db_t *)(dbi->dbconn))->stmnt);
+ ((odbc_db_t *)(dbi->dbconn))->stmnt = NULL;
}
/* disconnect from database & free connection handle */
- if (((odbc_db_t *) (dbi->dbconn))->dbc != NULL) {
- SQLDisconnect(((odbc_db_t *)
- dbi->dbconn)->dbc);
- SQLFreeHandle(SQL_HANDLE_DBC,
- ((odbc_db_t *)
- (dbi->dbconn))->dbc);
- ((odbc_db_t *) (dbi->dbconn))->dbc = NULL;
+ if (((odbc_db_t *)(dbi->dbconn))->dbc != NULL) {
+ SQLDisconnect(((odbc_db_t *)dbi->dbconn)->dbc);
+ SQLFreeHandle(
+ SQL_HANDLE_DBC,
+ ((odbc_db_t *)(dbi->dbconn))->dbc);
+ ((odbc_db_t *)(dbi->dbconn))->dbc = NULL;
}
/* free memory that held connection & statement. */
@@ -168,28 +164,31 @@ destroy_odbc_instance(odbc_instance_t *odbc_inst) {
isc_mem_put(named_g_mctx, odbc_inst->db, sizeof(db_list_t));
/* free sql environment */
- if (odbc_inst->sql_env != NULL)
+ if (odbc_inst->sql_env != NULL) {
SQLFreeHandle(SQL_HANDLE_ENV, odbc_inst->sql_env);
+ }
/* free ODBC instance strings */
- if (odbc_inst->dsn != NULL)
+ if (odbc_inst->dsn != NULL) {
isc_mem_free(named_g_mctx, odbc_inst->dsn);
- if (odbc_inst->pass != NULL)
+ }
+ if (odbc_inst->pass != NULL) {
isc_mem_free(named_g_mctx, odbc_inst->pass);
- if (odbc_inst->user != NULL)
+ }
+ if (odbc_inst->user != NULL) {
isc_mem_free(named_g_mctx, odbc_inst->user);
+ }
/* free memory for odbc_inst */
- if (odbc_inst != NULL)
+ if (odbc_inst != NULL) {
isc_mem_put(named_g_mctx, odbc_inst, sizeof(odbc_instance_t));
-
+ }
}
/*% Connects to database, and creates ODBC statements */
static isc_result_t
odbc_connect(odbc_instance_t *dbi, odbc_db_t **dbc) {
-
odbc_db_t *ndb = *dbc;
SQLRETURN sqlRes;
isc_result_t result = ISC_R_SUCCESS;
@@ -211,12 +210,6 @@ odbc_connect(odbc_instance_t *dbi, odbc_db_t **dbc) {
}
} else {
ndb = isc_mem_allocate(named_g_mctx, sizeof(odbc_db_t));
- if (ndb == NULL) {
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "Odbc driver unable to allocate memory");
- return ISC_R_NOMEMORY;
- }
memset(ndb, 0, sizeof(odbc_db_t));
}
@@ -250,12 +243,11 @@ odbc_connect(odbc_instance_t *dbi, odbc_db_t **dbc) {
*dbc = ndb;
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
if (ndb != NULL) {
-
/* if statement handle != null free it */
if (ndb->stmnt != NULL) {
SQLFreeHandle(SQL_HANDLE_STMT, ndb->stmnt);
@@ -272,7 +264,7 @@ odbc_connect(odbc_instance_t *dbi, odbc_db_t **dbc) {
isc_mem_free(named_g_mctx, ndb);
}
- return result;
+ return (result);
}
/*%
@@ -287,8 +279,7 @@ odbc_connect(odbc_instance_t *dbi, odbc_db_t **dbc) {
*/
static dbinstance_t *
-odbc_find_avail_conn(db_list_t *dblist)
-{
+odbc_find_avail_conn(db_list_t *dblist) {
dbinstance_t *dbi = NULL;
dbinstance_t *head;
int count = 0;
@@ -299,9 +290,9 @@ odbc_find_avail_conn(db_list_t *dblist)
/* loop through list */
while (count < dbc_search_limit) {
/* try to lock on the mutex */
- if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS)
- return dbi; /* success, return the DBI for use. */
-
+ if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) {
+ return (dbi); /* success, return the DBI for use. */
+ }
/* not successful, keep trying */
dbi = ISC_LIST_NEXT(dbi, link);
@@ -311,12 +302,12 @@ odbc_find_avail_conn(db_list_t *dblist)
dbi = head;
}
}
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_INFO,
"Odbc driver unable to find available "
"connection after searching %d times",
count);
- return NULL;
+ return (NULL);
}
/*% Allocates memory for a new string, and then constructs the new
@@ -328,22 +319,20 @@ odbc_find_avail_conn(db_list_t *dblist)
static char *
odbc_escape_string(const char *instr) {
-
char *outstr;
unsigned int len;
- if (instr == NULL)
- return NULL;
+ if (instr == NULL) {
+ return (NULL);
+ }
len = strlen(instr);
- outstr = isc_mem_allocate(named_g_mctx ,(2 * len * sizeof(char)) + 1);
- if (outstr == NULL)
- return NULL;
+ outstr = isc_mem_allocate(named_g_mctx, (2 * len * sizeof(char)) + 1);
odbc_makesafe(outstr, instr, len);
- return outstr;
+ return (outstr);
}
/* ---------------
@@ -365,33 +354,30 @@ odbc_escape_string(const char *instr) {
*/
static size_t
-odbc_makesafe(char *to, const char *from, size_t length)
-{
+odbc_makesafe(char *to, const char *from, size_t length) {
const char *source = from;
- char *target = to;
+ char *target = to;
unsigned int remaining = length;
- while (remaining > 0)
- {
- switch (*source)
- {
- case '\\':
- *target = '\\';
- target++;
- *target = '\\';
- /* target and remaining are updated below. */
- break;
+ while (remaining > 0) {
+ switch (*source) {
+ case '\\':
+ *target = '\\';
+ target++;
+ *target = '\\';
+ /* target and remaining are updated below. */
+ break;
- case '\'':
- *target = '\'';
- target++;
- *target = '\'';
- /* target and remaining are updated below. */
- break;
+ case '\'':
+ *target = '\'';
+ target++;
+ *target = '\'';
+ /* target and remaining are updated below. */
+ break;
- default:
- *target = *source;
- /* target and remaining are updated below. */
+ default:
+ *target = *source;
+ /* target and remaining are updated below. */
}
source++;
target++;
@@ -401,7 +387,7 @@ odbc_makesafe(char *to, const char *from, size_t length)
/* Write the terminating NUL character. */
*target = '\0';
- return target - to;
+ return (target - to);
}
/*%
@@ -416,18 +402,14 @@ odbc_makesafe(char *to, const char *from, size_t length)
* database instance (DBI). It will then run the query and hopefully
* obtain a result set. The data base instance that is used is returned
* to the caller so they can get the data from the result set from it.
- * If successfull, it will be the responsibility of the caller to close
+ * If successful, it will be the responsibility of the caller to close
* the cursor, and unlock the mutex of the DBI when they are done with it.
- * If not successfull, this function will perform all the cleanup.
+ * If not successful, this function will perform all the cleanup.
*/
-
static isc_result_t
-odbc_get_resultset(const char *zone, const char *record,
- const char *client, unsigned int query,
- void *dbdata, dbinstance_t **r_dbi)
-{
-
+odbc_get_resultset(const char *zone, const char *record, const char *client,
+ unsigned int query, void *dbdata, dbinstance_t **r_dbi) {
isc_result_t result;
dbinstance_t *dbi = NULL;
char *querystring = NULL;
@@ -439,16 +421,15 @@ odbc_get_resultset(const char *zone, const char *record,
/* get db instance / connection */
/* find an available DBI from the list */
- dbi = odbc_find_avail_conn(((odbc_instance_t *) dbdata)->db);
+ dbi = odbc_find_avail_conn(((odbc_instance_t *)dbdata)->db);
/* if DBI is null, can't do anything else */
if (dbi == NULL) {
- result = ISC_R_FAILURE;
- goto cleanup;
+ return (ISC_R_FAILURE);
}
/* what type of query are we going to run? */
- switch(query) {
+ switch (query) {
case ALLNODES:
/*
* if the query was not passed in from the config file
@@ -509,7 +490,6 @@ odbc_get_resultset(const char *zone, const char *record,
goto cleanup;
}
-
/*
* was a zone string passed? If so, make it safe for use in
* queries.
@@ -520,7 +500,7 @@ odbc_get_resultset(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->zone = NULL;
}
@@ -534,7 +514,7 @@ odbc_get_resultset(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->record = NULL;
}
@@ -548,7 +528,7 @@ odbc_get_resultset(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->client = NULL;
}
@@ -556,7 +536,7 @@ odbc_get_resultset(const char *zone, const char *record,
* what type of query are we going to run?
* this time we build the actual query to run.
*/
- switch(query) {
+ switch (query) {
case ALLNODES:
querystring = build_querystring(named_g_mctx, dbi->allnodes_q);
break;
@@ -585,35 +565,35 @@ odbc_get_resultset(const char *zone, const char *record,
}
/* if the querystring is null, Bummer, outta RAM. UPGRADE TIME!!! */
- if (querystring == NULL) {
+ if (querystring == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
/* output the full query string during debug so we can see */
/* what lame error the query has. */
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
- "\nQuery String: %s\n", querystring);
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1), "\nQuery String: %s\n", querystring);
/* attempt query up to 3 times. */
- for (j=0; j < 3; j++) {
+ for (j = 0; j < 3; j++) {
/* try to get result set */
- sqlRes = SQLExecDirect(((odbc_db_t *) dbi->dbconn)->stmnt,
- (SQLCHAR *) querystring,
- (SQLINTEGER) strlen(querystring));
+ sqlRes = SQLExecDirect(((odbc_db_t *)dbi->dbconn)->stmnt,
+ (SQLCHAR *)querystring,
+ (SQLINTEGER)strlen(querystring));
/* if error, reset DB connection */
if (!sqlOK(sqlRes)) {
/* close cursor */
- SQLCloseCursor(((odbc_db_t *) dbi->dbconn)->stmnt);
+ SQLCloseCursor(((odbc_db_t *)dbi->dbconn)->stmnt);
/* attempt to reconnect */
- result = odbc_connect((odbc_instance_t *) dbdata,
- (odbc_db_t **) &(dbi->dbconn));
+ result = odbc_connect((odbc_instance_t *)dbdata,
+ (odbc_db_t **)&(dbi->dbconn));
/* check if we reconnected */
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
break;
- /* incase this is the last time through the loop */
+ }
+ /* in case this is the last time through the loop */
result = ISC_R_FAILURE;
} else {
result = ISC_R_SUCCESS;
@@ -622,77 +602,78 @@ odbc_get_resultset(const char *zone, const char *record,
/* result set ok, break loop */
break;
}
- } /* end for loop */
-
- cleanup: /* it's always good to cleanup after yourself */
+ } /* end for loop */
- /* if we couldn't even allocate DBI, just return NULL */
- if (dbi == NULL)
- return ISC_R_FAILURE;
+cleanup: /* it's always good to cleanup after yourself */
/* free dbi->zone string */
- if (dbi->zone != NULL)
+ if (dbi->zone != NULL) {
isc_mem_free(named_g_mctx, dbi->zone);
+ }
/* free dbi->record string */
- if (dbi->record != NULL)
+ if (dbi->record != NULL) {
isc_mem_free(named_g_mctx, dbi->record);
+ }
/* free dbi->client string */
- if (dbi->client != NULL)
+ if (dbi->client != NULL) {
isc_mem_free(named_g_mctx, dbi->client);
+ }
/* if we are done using this dbi, release the lock */
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
isc_mutex_unlock(&dbi->instance_lock);
+ }
/* release query string */
- if (querystring != NULL)
- isc_mem_free(named_g_mctx, querystring );
+ if (querystring != NULL) {
+ isc_mem_free(named_g_mctx, querystring);
+ }
/* return result */
- return result;
-
+ return (result);
}
/*%
* Gets a single field from the ODBC statement. The memory for the
* returned data is dynamically allocated. If this method is successful
- * it is the reponsibility of the caller to free the memory using
+ * it is the responsibility of the caller to free the memory using
* isc_mem_free(named_g_mctx, *ptr);
*/
static isc_result_t
odbc_getField(SQLHSTMT *stmnt, SQLSMALLINT field, char **data) {
-
SQLLEN size;
REQUIRE(data != NULL && *data == NULL);
- if (sqlOK(SQLColAttribute(stmnt, field, SQL_DESC_DISPLAY_SIZE,
- NULL, 0, NULL, &size)) && size > 0) {
+ if (sqlOK(SQLColAttribute(stmnt, field, SQL_DESC_DISPLAY_SIZE, NULL, 0,
+ NULL, &size)) &&
+ size > 0)
+ {
*data = isc_mem_allocate(named_g_mctx, size + 1);
if (data != NULL) {
- if (sqlOK(SQLGetData(stmnt, field, SQL_C_CHAR,
- *data, size + 1,&size)))
- return ISC_R_SUCCESS;
+ if (sqlOK(SQLGetData(stmnt, field, SQL_C_CHAR, *data,
+ size + 1, &size))) {
+ return (ISC_R_SUCCESS);
+ }
isc_mem_free(named_g_mctx, *data);
}
}
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/*%
* Gets multiple fields from the ODBC statement. The memory for the
* returned data is dynamically allocated. If this method is successful
- * it is the reponsibility of the caller to free the memory using
+ * it is the responsibility of the caller to free the memory using
* isc_mem_free(named_g_mctx, *ptr);
*/
static isc_result_t
odbc_getManyFields(SQLHSTMT *stmnt, SQLSMALLINT startField,
SQLSMALLINT endField, char **retData) {
-
isc_result_t result;
SQLLEN size;
int totSize = 0;
@@ -704,26 +685,30 @@ odbc_getManyFields(SQLHSTMT *stmnt, SQLSMALLINT startField,
REQUIRE(startField > 0 && startField <= endField);
/* determine how large the data is */
- for (i=startField; i <= endField; i++)
- if (sqlOK(SQLColAttribute(stmnt, i, SQL_DESC_DISPLAY_SIZE,
- NULL, 0, NULL, &size)) && size > 0) {
- /* always allow for a " " (space) character */
- totSize += (size + 1);
- /* after the data item */
+ for (i = startField; i <= endField; i++) {
+ if (sqlOK(SQLColAttribute(stmnt, i, SQL_DESC_DISPLAY_SIZE, NULL,
+ 0, NULL, &size)) &&
+ size > 0)
+ {
+ {
+ /* always allow for a " " (space) character */
+ totSize += (size + 1);
+ /* after the data item */
+ }
}
+ }
- if (totSize < 1)
- return ISC_R_FAILURE;
+ if (totSize < 1) {
+ return (ISC_R_FAILURE);
+ }
/* allow for a "\n" at the end of the string/ */
data = isc_mem_allocate(named_g_mctx, ++totSize);
- if (data == NULL)
- return ISC_R_NOMEMORY;
result = ISC_R_FAILURE;
/* get the data and concat all fields into a large string */
- for (i=startField; i <= endField; i++) {
+ for (i = startField; i <= endField; i++) {
if (sqlOK(SQLGetData(stmnt, i, SQL_C_CHAR, &(data[j]),
totSize - j, &size))) {
if (size > 0) {
@@ -734,18 +719,17 @@ odbc_getManyFields(SQLHSTMT *stmnt, SQLSMALLINT startField,
}
} else {
isc_mem_free(named_g_mctx, data);
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
}
if (result != ISC_R_SUCCESS) {
isc_mem_free(named_g_mctx, data);
- return result;
+ return (result);
}
*retData = data;
- return ISC_R_SUCCESS;
-
+ return (ISC_R_SUCCESS);
}
/*%
@@ -755,13 +739,10 @@ odbc_getManyFields(SQLHSTMT *stmnt, SQLSMALLINT startField,
*/
static isc_result_t
-odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
-{
-
-
+odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi) {
isc_result_t result;
SQLSMALLINT fields;
- SQLHSTMT *stmnt;
+ SQLHSTMT *stmnt;
char *ttl_s;
char *type;
char *data;
@@ -770,7 +751,7 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
REQUIRE(dbi != NULL);
- stmnt = ((odbc_db_t *) (dbi->dbconn))->stmnt;
+ stmnt = ((odbc_db_t *)(dbi->dbconn))->stmnt;
/* get number of columns */
if (!sqlOK(SQLNumResultCols(stmnt, &fields))) {
@@ -785,11 +766,10 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
result = ISC_R_FAILURE;
while (sqlOK(SQLFetch(stmnt))) {
-
/* set to null for next pass through */
data = type = ttl_s = NULL;
- switch(fields) {
+ switch (fields) {
case 1:
/*
* one column in rs, it's the data field. use
@@ -797,10 +777,10 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
* of 86400. attempt to get data, & tell bind
* about it.
*/
- if ((result = odbc_getField(stmnt, 1,
- &data)) == ISC_R_SUCCESS) {
- result = dns_sdlz_putrr(lookup, "a",
- 86400, data);
+ if ((result = odbc_getField(stmnt, 1, &data)) ==
+ ISC_R_SUCCESS) {
+ result = dns_sdlz_putrr(lookup, "a", 86400,
+ data);
}
break;
case 2:
@@ -809,12 +789,13 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
* use default TTL of 86400. attempt to get
* DNS type & data, then tell bind about it.
*/
- if ((result = odbc_getField(stmnt, 1,
- &type)) == ISC_R_SUCCESS &&
- (result = odbc_getField(stmnt, 2,
- &data)) == ISC_R_SUCCESS) {
- result = dns_sdlz_putrr(lookup, type,
- 86400, data);
+ if ((result = odbc_getField(stmnt, 1, &type)) ==
+ ISC_R_SUCCESS &&
+ (result = odbc_getField(stmnt, 2, &data)) ==
+ ISC_R_SUCCESS)
+ {
+ result = dns_sdlz_putrr(lookup, type, 86400,
+ data);
}
break;
default:
@@ -823,13 +804,13 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
* together. attempt to get DNS ttl, type,
* data then tell Bind about them.
*/
- if ((result = odbc_getField(stmnt, 1, &ttl_s))
- == ISC_R_SUCCESS &&
- (result = odbc_getField(stmnt, 2, &type))
- == ISC_R_SUCCESS &&
- (result = odbc_getManyFields(stmnt, 3,
- fields, &data))
- == ISC_R_SUCCESS) {
+ if ((result = odbc_getField(stmnt, 1, &ttl_s)) ==
+ ISC_R_SUCCESS &&
+ (result = odbc_getField(stmnt, 2, &type)) ==
+ ISC_R_SUCCESS &&
+ (result = odbc_getManyFields(
+ stmnt, 3, fields, &data)) == ISC_R_SUCCESS)
+ {
/* try to convert ttl string to int */
ttl = strtol(ttl_s, &endp, 10);
/* failure converting ttl. */
@@ -839,7 +820,7 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
DNS_LOGMODULE_DLZ,
ISC_LOG_ERROR,
"Odbc driver ttl must "
- "be a postive number");
+ "be a positive number");
result = ISC_R_FAILURE;
} else {
/*
@@ -850,15 +831,18 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
ttl, data);
}
} /* closes bid if () */
- } /* closes switch(fields) */
+ } /* closes switch(fields) */
/* clean up mem */
- if (ttl_s != NULL)
+ if (ttl_s != NULL) {
isc_mem_free(named_g_mctx, ttl_s);
- if (type != NULL)
+ }
+ if (type != NULL) {
isc_mem_free(named_g_mctx, type);
- if (data != NULL)
+ }
+ if (data != NULL) {
isc_mem_free(named_g_mctx, data);
+ }
/* I sure hope we were successful */
if (result != ISC_R_SUCCESS) {
@@ -872,15 +856,15 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
}
} /* closes while loop */
- process_rs_cleanup:
+process_rs_cleanup:
/* close cursor */
- SQLCloseCursor(((odbc_db_t *) (dbi->dbconn))->stmnt);
+ SQLCloseCursor(((odbc_db_t *)(dbi->dbconn))->stmnt);
/* free lock on dbi so someone else can use it. */
isc_mutex_unlock(&dbi->instance_lock);
- return result;
+ return (result);
}
/*
@@ -891,9 +875,7 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi)
static isc_result_t
odbc_findzone(void *driverarg, void *dbdata, const char *name,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
-
+ dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) {
isc_result_t result;
dbinstance_t *dbi = NULL;
@@ -908,26 +890,26 @@ odbc_findzone(void *driverarg, void *dbdata, const char *name,
/* Check that we got a result set with data */
if (result == ISC_R_SUCCESS &&
- !sqlOK(SQLFetch(((odbc_db_t *) (dbi->dbconn))->stmnt))) {
+ !sqlOK(SQLFetch(((odbc_db_t *)(dbi->dbconn))->stmnt)))
+ {
result = ISC_R_NOTFOUND;
}
if (dbi != NULL) {
/* get rid of result set, we are done with it. */
- SQLCloseCursor(((odbc_db_t *) (dbi->dbconn))->stmnt);
+ SQLCloseCursor(((odbc_db_t *)(dbi->dbconn))->stmnt);
/* free lock on dbi so someone else can use it. */
isc_mutex_unlock(&dbi->instance_lock);
}
- return result;
+ return (result);
}
/*% Determine if the client is allowed to perform a zone transfer */
static isc_result_t
odbc_allowzonexfr(void *driverarg, void *dbdata, const char *name,
- const char *client)
-{
+ const char *client) {
isc_result_t result;
dbinstance_t *dbi = NULL;
@@ -935,8 +917,9 @@ odbc_allowzonexfr(void *driverarg, void *dbdata, const char *name,
/* first check if the zone is supported by the database. */
result = odbc_findzone(driverarg, dbdata, name, NULL, NULL);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
/*
* if we get to this point we know the zone is supported by
@@ -948,29 +931,29 @@ odbc_allowzonexfr(void *driverarg, void *dbdata, const char *name,
* result != ISC_R_SUCCESS cursor and mutex already cleaned
* up, so we don't have to do it here.
*/
- result = odbc_get_resultset(name, NULL, client, ALLOWXFR,
- dbdata, &dbi);
+ result = odbc_get_resultset(name, NULL, client, ALLOWXFR, dbdata, &dbi);
/* if we get "not implemented", send it along. */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* Check that we got a result set with data */
if (result == ISC_R_SUCCESS &&
- !sqlOK(SQLFetch(((odbc_db_t *) (dbi->dbconn))->stmnt))) {
+ !sqlOK(SQLFetch(((odbc_db_t *)(dbi->dbconn))->stmnt)))
+ {
result = ISC_R_NOPERM;
}
if (dbi != NULL) {
/* get rid of result set, we are done with it. */
- SQLCloseCursor(((odbc_db_t *) (dbi->dbconn))->stmnt);
+ SQLCloseCursor(((odbc_db_t *)(dbi->dbconn))->stmnt);
/* free lock on dbi so someone else can use it. */
isc_mutex_unlock(&dbi->instance_lock);
-
}
- return result;
+ return (result);
}
/*%
@@ -981,12 +964,10 @@ odbc_allowzonexfr(void *driverarg, void *dbdata, const char *name,
static isc_result_t
odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
-
+ dns_sdlzallnodes_t *allnodes) {
isc_result_t result;
dbinstance_t *dbi = NULL;
- SQLHSTMT *stmnt;
+ SQLHSTMT *stmnt;
SQLSMALLINT fields;
char *data;
char *type;
@@ -1001,8 +982,9 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
result = odbc_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &dbi);
/* if we get "not implemented", send it along */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
@@ -1013,7 +995,7 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
return (ISC_R_FAILURE);
}
- stmnt = ((odbc_db_t *) (dbi->dbconn))->stmnt;
+ stmnt = ((odbc_db_t *)(dbi->dbconn))->stmnt;
/* get number of columns */
if (!sqlOK(SQLNumResultCols(stmnt, &fields))) {
@@ -1024,7 +1006,7 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
goto allnodes_cleanup;
}
- if (fields < 4) { /* gotta have at least 4 columns */
+ if (fields < 4) { /* gotta have at least 4 columns */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Odbc driver too few fields returned by "
@@ -1037,7 +1019,6 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
result = ISC_R_FAILURE;
while (sqlOK(SQLFetch(stmnt))) {
-
/* set to null for next pass through */
data = host = type = ttl_s = NULL;
@@ -1045,14 +1026,15 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
* attempt to get DNS ttl, type, host, data then tell
* Bind about them
*/
- if ((result = odbc_getField(stmnt, 1,
- &ttl_s)) == ISC_R_SUCCESS &&
- (result = odbc_getField(stmnt, 2,
- &type)) == ISC_R_SUCCESS &&
- (result = odbc_getField(stmnt, 3,
- &host)) == ISC_R_SUCCESS &&
- (result = odbc_getManyFields(stmnt, 4, fields,
- &data)) == ISC_R_SUCCESS) {
+ if ((result = odbc_getField(stmnt, 1, &ttl_s)) ==
+ ISC_R_SUCCESS &&
+ (result = odbc_getField(stmnt, 2, &type)) ==
+ ISC_R_SUCCESS &&
+ (result = odbc_getField(stmnt, 3, &host)) ==
+ ISC_R_SUCCESS &&
+ (result = odbc_getManyFields(stmnt, 4, fields, &data)) ==
+ ISC_R_SUCCESS)
+ {
/* convert ttl string to int */
ttl = strtol(ttl_s, &endp, 10);
/* failure converting ttl. */
@@ -1061,7 +1043,7 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Odbc driver ttl must be "
- "a postive number");
+ "a positive number");
result = ISC_R_FAILURE;
} else {
/* successful converting TTL, tell Bind */
@@ -1071,14 +1053,18 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
} /* closes big if () */
/* clean up mem */
- if (ttl_s != NULL)
+ if (ttl_s != NULL) {
isc_mem_free(named_g_mctx, ttl_s);
- if (type != NULL)
+ }
+ if (type != NULL) {
isc_mem_free(named_g_mctx, type);
- if (host != NULL)
+ }
+ if (host != NULL) {
isc_mem_free(named_g_mctx, host);
- if (data != NULL)
+ }
+ if (data != NULL) {
isc_mem_free(named_g_mctx, data);
+ }
/* if we weren't successful, log err msg */
if (result != ISC_R_SUCCESS) {
@@ -1092,15 +1078,15 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
}
} /* closes while loop */
- allnodes_cleanup:
+allnodes_cleanup:
/* close cursor */
- SQLCloseCursor(((odbc_db_t *) (dbi->dbconn))->stmnt);
+ SQLCloseCursor(((odbc_db_t *)(dbi->dbconn))->stmnt);
/* free lock on dbi so someone else can use it. */
isc_mutex_unlock(&dbi->instance_lock);
- return result;
+ return (result);
}
/*%
@@ -1110,8 +1096,7 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata,
static isc_result_t
odbc_authority(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzlookup_t *lookup)
-{
+ dns_sdlzlookup_t *lookup) {
isc_result_t result;
dbinstance_t *dbi = NULL;
@@ -1120,8 +1105,9 @@ odbc_authority(const char *zone, void *driverarg, void *dbdata,
/* run the query and get the result set from the database. */
result = odbc_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata, &dbi);
/* if we get "not implemented", send it along */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
@@ -1132,16 +1118,15 @@ odbc_authority(const char *zone, void *driverarg, void *dbdata,
}
/* lookup and authority result sets are processed in the same manner */
/* odbc_process_rs does the job for both functions. */
- return odbc_process_rs(lookup, dbi);
+ return (odbc_process_rs(lookup, dbi));
}
/*% if zone is supported, lookup up a (or multiple) record(s) in it */
static isc_result_t
-odbc_lookup(const char *zone, const char *name, void *driverarg,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
+odbc_lookup(const char *zone, const char *name, void *driverarg, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
dbinstance_t *dbi = NULL;
@@ -1161,7 +1146,7 @@ odbc_lookup(const char *zone, const char *name, void *driverarg,
}
/* lookup and authority result sets are processed in the same manner */
/* odbc_process_rs does the job for both functions. */
- return odbc_process_rs(lookup, dbi);
+ return (odbc_process_rs(lookup, dbi));
}
/*%
@@ -1172,8 +1157,7 @@ odbc_lookup(const char *zone, const char *name, void *driverarg,
*/
static isc_result_t
odbc_create(const char *dlzname, unsigned int argc, char *argv[],
- void *driverarg, void **dbdata)
-{
+ void *driverarg, void **dbdata) {
isc_result_t result;
odbc_instance_t *odbc_inst = NULL;
dbinstance_t *db = NULL;
@@ -1186,9 +1170,8 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
UNUSED(driverarg);
/* if debugging, let user know we are multithreaded. */
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
- "Odbc driver running multithreaded");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1), "Odbc driver running multithreaded");
/* verify we have at least 5 arg's passed to the driver */
if (argc < 5) {
@@ -1221,15 +1204,12 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate memory for odbc instance */
odbc_inst = isc_mem_get(named_g_mctx, sizeof(odbc_instance_t));
- if (odbc_inst == NULL)
- return (ISC_R_NOMEMORY);
memset(odbc_inst, 0, sizeof(odbc_instance_t));
- /* parse connection string and get paramters. */
+ /* parse connection string and get parameters. */
/* get odbc database dsn - required */
- odbc_inst->dsn = (SQLCHAR *) getParameterValue(argv[2],
- "dsn=");
+ odbc_inst->dsn = (SQLCHAR *)getParameterValue(argv[2], "dsn=");
if (odbc_inst->dsn == NULL) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
@@ -1239,12 +1219,11 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* get odbc database username */
/* if no username was passed, set odbc_inst.user = NULL; */
- odbc_inst->user = (SQLCHAR *) getParameterValue(argv[2],
- "user=");
+ odbc_inst->user = (SQLCHAR *)getParameterValue(argv[2], "user=");
/* get odbc database password */
/* if no password was passed, set odbc_inst.pass = NULL; */
- odbc_inst->pass = (SQLCHAR *) getParameterValue(argv[2], "pass=");
+ odbc_inst->pass = (SQLCHAR *)getParameterValue(argv[2], "pass=");
/* create odbc environment & set environment to ODBC V3 */
if (odbc_inst->sql_env == NULL) {
@@ -1261,7 +1240,7 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
/*set ODBC version = 3 */
sqlRes = SQLSetEnvAttr(odbc_inst->sql_env,
SQL_ATTR_ODBC_VERSION,
- (void *) SQL_OV_ODBC3, 0);
+ (void *)SQL_OV_ODBC3, 0);
if (!sqlOK(sqlRes)) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
@@ -1273,21 +1252,15 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate memory for database connection list */
odbc_inst->db = isc_mem_get(named_g_mctx, sizeof(db_list_t));
- if (odbc_inst->db == NULL) {
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
-
/* initialize DB connection list */
ISC_LIST_INIT(*odbc_inst->db);
/* create the appropriate number of database instances (DBI) */
/* append each new DBI to the end of the list */
- for (i=0; i < dbcount; i++) {
-
+ for (i = 0; i < dbcount; i++) {
/* how many queries were passed in from config file? */
- switch(argc) {
+ switch (argc) {
case 5:
result = build_sqldbinstance(named_g_mctx, NULL, NULL,
NULL, argv[3], argv[4],
@@ -1299,9 +1272,9 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
NULL, &db);
break;
case 7:
- result = build_sqldbinstance(named_g_mctx, argv[6], NULL,
- argv[5], argv[3], argv[4],
- NULL, &db);
+ result = build_sqldbinstance(named_g_mctx, argv[6],
+ NULL, argv[5], argv[3],
+ argv[4], NULL, &db);
break;
case 8:
result = build_sqldbinstance(named_g_mctx, argv[6],
@@ -1326,10 +1299,9 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
ISC_LINK_INIT(db, link);
ISC_LIST_APPEND(*odbc_inst->db, db, link);
- result = odbc_connect(odbc_inst, (odbc_db_t **) &(db->dbconn));
+ result = odbc_connect(odbc_inst, (odbc_db_t **)&(db->dbconn));
if (result != ISC_R_SUCCESS) {
-
/*
* if multi threaded, let user know which
* connection failed. user could be
@@ -1341,26 +1313,25 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Odbc driver failed to create database "
"connection number %u after 3 attempts",
- i+1);
+ i + 1);
goto cleanup;
}
/* set DB = null for next loop through. */
db = NULL;
-
- } /* end for loop */
+ } /* end for loop */
/* set dbdata to the odbc_instance we created. */
*dbdata = odbc_inst;
/* hey, we got through all of that ok, return success. */
- return(ISC_R_SUCCESS);
+ return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
destroy_odbc_instance(odbc_inst);
- return result;
+ return (result);
}
/*%
@@ -1371,14 +1342,12 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[],
*/
static void
-odbc_destroy(void *driverarg, void *dbdata)
-{
+odbc_destroy(void *driverarg, void *dbdata) {
UNUSED(driverarg);
- destroy_odbc_instance((odbc_instance_t *) dbdata);
+ destroy_odbc_instance((odbc_instance_t *)dbdata);
}
-
/* pointers to all our runtime methods. */
/* this is used during driver registration */
/* i.e. in dlz_odbc_init below. */
@@ -1409,9 +1378,8 @@ dlz_odbc_init(void) {
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Registering DLZ odbc driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Registering DLZ odbc driver.");
/*
* Driver is always threadsafe. When multithreaded all
@@ -1422,8 +1390,8 @@ dlz_odbc_init(void) {
*/
result = dns_sdlzregister("odbc", &dlz_odbc_methods, NULL,
DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA |
- DNS_SDLZFLAG_THREADSAFE,
+ DNS_SDLZFLAG_RELATIVERDATA |
+ DNS_SDLZFLAG_THREADSAFE,
named_g_mctx, &dlz_odbc);
/* if we can't register the driver, there are big problems. */
if (result != ISC_R_SUCCESS) {
@@ -1433,8 +1401,7 @@ dlz_odbc_init(void) {
result = ISC_R_UNEXPECTED;
}
-
- return result;
+ return (result);
}
/*%
@@ -1442,17 +1409,16 @@ dlz_odbc_init(void) {
*/
void
dlz_odbc_clear(void) {
-
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unregistering DLZ odbc driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unregistering DLZ odbc driver.");
/* unregister the driver. */
- if (dlz_odbc != NULL)
+ if (dlz_odbc != NULL) {
dns_sdlzunregister(&dlz_odbc);
+ }
}
-#endif
+#endif /* ifdef DLZ_ODBC */
diff --git a/contrib/dlz/drivers/dlz_postgres_driver.c b/contrib/dlz/drivers/dlz_postgres_driver.c
index b50771fd..d5a46c51 100644
--- a/contrib/dlz/drivers/dlz_postgres_driver.c
+++ b/contrib/dlz/drivers/dlz_postgres_driver.c
@@ -42,15 +42,9 @@
*/
#ifdef DLZ_POSTGRES
-
-#include <config.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-
-#include <dns/log.h>
-#include <dns/sdlz.h>
-#include <dns/result.h>
+#include <string.h>
#include <isc/mem.h>
#include <isc/platform.h>
@@ -59,24 +53,26 @@
#include <isc/string.h>
#include <isc/util.h>
-#include <named/globals.h>
+#include <dns/log.h>
+#include <dns/result.h>
+#include <dns/sdlz.h>
-#include <dlz/sdlz_helper.h>
#include <dlz/dlz_postgres_driver.h>
+#include <dlz/sdlz_helper.h>
+#include <named/globals.h>
/* temporarily include time. */
-#include <time.h>
-
#include <libpq-fe.h>
+#include <time.h>
static dns_sdlzimplementation_t *dlz_postgres = NULL;
#define dbc_search_limit 30
-#define ALLNODES 1
-#define ALLOWXFR 2
-#define AUTHORITY 3
-#define FINDZONE 4
-#define LOOKUP 5
+#define ALLNODES 1
+#define ALLOWXFR 2
+#define AUTHORITY 3
+#define FINDZONE 4
+#define LOOKUP 5
/*
* Private methods
@@ -110,16 +106,13 @@ static dns_sdlzimplementation_t *dlz_postgres = NULL;
*/
static size_t
-postgres_makesafe(char *to, const char *from, size_t length)
-{
+postgres_makesafe(char *to, const char *from, size_t length) {
const char *source = from;
- char *target = to;
+ char *target = to;
unsigned int remaining = length;
- while (remaining > 0)
- {
- switch (*source)
- {
+ while (remaining > 0) {
+ switch (*source) {
case '\\':
*target = '\\';
target++;
@@ -146,7 +139,7 @@ postgres_makesafe(char *to, const char *from, size_t length)
/* Write the terminating NUL character. */
*target = '\0';
- return target - to;
+ return (target - to);
}
/*%
@@ -155,9 +148,7 @@ postgres_makesafe(char *to, const char *from, size_t length)
* multithreaded operation.
*/
static void
-postgres_destroy_dblist(db_list_t *dblist)
-{
-
+postgres_destroy_dblist(db_list_t *dblist) {
dbinstance_t *ndbi = NULL;
dbinstance_t *dbi = NULL;
@@ -170,8 +161,9 @@ postgres_destroy_dblist(db_list_t *dblist)
/* get the next DBI in the list */
ndbi = ISC_LIST_NEXT(dbi, link);
/* release DB connection */
- if (dbi->dbconn != NULL)
- PQfinish((PGconn *) dbi->dbconn);
+ if (dbi->dbconn != NULL) {
+ PQfinish((PGconn *)dbi->dbconn);
+ }
/* release all memory that comprised a DBI */
destroy_sqldbinstance(dbi);
}
@@ -191,8 +183,7 @@ postgres_destroy_dblist(db_list_t *dblist)
*/
static dbinstance_t *
-postgres_find_avail_conn(db_list_t *dblist)
-{
+postgres_find_avail_conn(db_list_t *dblist) {
dbinstance_t *dbi = NULL;
dbinstance_t *head;
int count = 0;
@@ -203,9 +194,9 @@ postgres_find_avail_conn(db_list_t *dblist)
/* loop through list */
while (count < dbc_search_limit) {
/* try to lock on the mutex */
- if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS)
- return dbi; /* success, return the DBI for use. */
-
+ if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) {
+ return (dbi); /* success, return the DBI for use. */
+ }
/* not successful, keep trying */
dbi = ISC_LIST_NEXT(dbi, link);
@@ -215,12 +206,12 @@ postgres_find_avail_conn(db_list_t *dblist)
dbi = head;
}
}
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_INFO,
"Postgres driver unable to find available connection "
"after searching %d times",
count);
- return NULL;
+ return (NULL);
}
/*%
@@ -233,23 +224,21 @@ postgres_find_avail_conn(db_list_t *dblist)
static char *
postgres_escape_string(const char *instr) {
-
char *outstr;
unsigned int len;
- if (instr == NULL)
- return NULL;
+ if (instr == NULL) {
+ return (NULL);
+ }
len = strlen(instr);
- outstr = isc_mem_allocate(named_g_mctx ,(2 * len * sizeof(char)) + 1);
- if (outstr == NULL)
- return NULL;
+ outstr = isc_mem_allocate(named_g_mctx, (2 * len * sizeof(char)) + 1);
postgres_makesafe(outstr, instr, len);
/* PQescapeString(outstr, instr, len); */
- return outstr;
+ return (outstr);
}
/*%
@@ -269,10 +258,8 @@ postgres_escape_string(const char *instr) {
* it up properly.
*/
static isc_result_t
-postgres_get_resultset(const char *zone, const char *record,
- const char *client, unsigned int query,
- void *dbdata, PGresult **rs)
-{
+postgres_get_resultset(const char *zone, const char *record, const char *client,
+ unsigned int query, void *dbdata, PGresult **rs) {
isc_result_t result;
dbinstance_t *dbi = NULL;
char *querystring = NULL;
@@ -281,8 +268,10 @@ postgres_get_resultset(const char *zone, const char *record,
#if 0
/* temporarily get a unique thread # */
- unsigned int dlz_thread_num = 1+(int) (1000.0*rand()/(RAND_MAX+1.0));
-#endif
+ unsigned int dlz_thread_num = 1 +
+ (int) (1000.0 * rand() /
+ (RAND_MAX + 1.0));
+#endif /* if 0 */
REQUIRE(*rs == NULL);
@@ -291,28 +280,27 @@ postgres_get_resultset(const char *zone, const char *record,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d Getting DBI", dlz_thread_num);
-#endif
+#endif /* if 0 */
/* get db instance / connection */
/* find an available DBI from the list */
- dbi = postgres_find_avail_conn((db_list_t *) dbdata);
+ dbi = postgres_find_avail_conn((db_list_t *)dbdata);
#if 0
/* temporary logging message */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d Got DBI - checking query", dlz_thread_num);
-#endif
+#endif /* if 0 */
/* if DBI is null, can't do anything else */
if (dbi == NULL) {
- result = ISC_R_FAILURE;
- goto cleanup;
+ return (ISC_R_FAILURE);
}
/* what type of query are we going to run? */
- switch(query) {
+ switch (query) {
case ALLNODES:
/*
* if the query was not passed in from the config file
@@ -378,7 +366,7 @@ postgres_get_resultset(const char *zone, const char *record,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d checked query", dlz_thread_num);
-#endif
+#endif /* if 0 */
/*
* was a zone string passed? If so, make it safe for use in
@@ -390,7 +378,7 @@ postgres_get_resultset(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->zone = NULL;
}
@@ -399,7 +387,7 @@ postgres_get_resultset(const char *zone, const char *record,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d did zone", dlz_thread_num);
-#endif
+#endif /* if 0 */
/*
* was a record string passed? If so, make it safe for use in
@@ -411,17 +399,16 @@ postgres_get_resultset(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->record = NULL;
}
-
#if 0
/* temporary logging message */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d did record", dlz_thread_num);
-#endif
+#endif /* if 0 */
/*
* was a client string passed? If so, make it safe for use in
@@ -433,22 +420,22 @@ postgres_get_resultset(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else { /* no string passed, set the string pointer to NULL */
+ } else { /* no string passed, set the string pointer to NULL */
dbi->client = NULL;
}
#if 0
/* temporary logging message */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
+ DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d did client", dlz_thread_num);
-#endif
+#endif /* if 0 */
/*
* what type of query are we going to run?
* this time we build the actual query to run.
*/
- switch(query) {
+ switch (query) {
case ALLNODES:
querystring = build_querystring(named_g_mctx, dbi->allnodes_q);
break;
@@ -481,10 +468,10 @@ postgres_get_resultset(const char *zone, const char *record,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d built query", dlz_thread_num);
-#endif
+#endif /* if 0 */
/* if the querystring is null, Bummer, outta RAM. UPGRADE TIME!!! */
- if (querystring == NULL) {
+ if (querystring == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
@@ -494,54 +481,54 @@ postgres_get_resultset(const char *zone, const char *record,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d query is '%s'", dlz_thread_num, querystring);
-#endif
+#endif /* if 0 */
/*
* output the full query string during debug so we can see
* what lame error the query has.
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
- "\nQuery String: %s\n", querystring);
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1), "\nQuery String: %s\n", querystring);
/* attempt query up to 3 times. */
- for (j=0; j < 3; j++) {
+ for (j = 0; j < 3; j++) {
#if 0
/* temporary logging message */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d executing query for %d time",
dlz_thread_num, j);
-#endif
+#endif /* if 0 */
/* try to get result set */
- *rs = PQexec((PGconn *)dbi->dbconn, querystring );
+ *rs = PQexec((PGconn *)dbi->dbconn, querystring);
result = ISC_R_SUCCESS;
/*
* if result set is null, reset DB connection, max 3
* attempts.
*/
- for (i=0; *rs == NULL && i < 3; i++) {
+ for (i = 0; *rs == NULL && i < 3; i++) {
#if 0
/* temporary logging message */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d resetting connection",
dlz_thread_num);
-#endif
+#endif /* if 0 */
result = ISC_R_FAILURE;
- PQreset((PGconn *) dbi->dbconn);
+ PQreset((PGconn *)dbi->dbconn);
/* connection ok, break inner loop */
- if (PQstatus((PGconn *) dbi->dbconn) == CONNECTION_OK)
+ if (PQstatus((PGconn *)dbi->dbconn) == CONNECTION_OK) {
break;
+ }
}
- /* result set ok, break outter loop */
+ /* result set ok, break outer loop */
if (PQresultStatus(*rs) == PGRES_TUPLES_OK) {
#if 0
/* temporary logging message */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d rs ok", dlz_thread_num);
-#endif
+#endif /* if 0 */
break;
} else {
/* we got a result set object, but it's not right. */
@@ -550,15 +537,15 @@ postgres_get_resultset(const char *zone, const char *record,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d clearing rs", dlz_thread_num);
-#endif
- PQclear(*rs); /* get rid of it */
+#endif /* if 0 */
+ PQclear(*rs); /* get rid of it */
/* in case this was the last attempt */
*rs = NULL;
result = ISC_R_FAILURE;
}
}
- cleanup:
+cleanup:
/* it's always good to cleanup after yourself */
#if 0
@@ -566,47 +553,47 @@ postgres_get_resultset(const char *zone, const char *record,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d cleaning up", dlz_thread_num);
-#endif
-
- /* if we couldn't even allocate DBI, just return NULL */
- if (dbi == NULL)
- return ISC_R_FAILURE;
+#endif /* if 0 */
/* free dbi->zone string */
- if (dbi->zone != NULL)
+ if (dbi->zone != NULL) {
isc_mem_free(named_g_mctx, dbi->zone);
+ }
/* free dbi->record string */
- if (dbi->record != NULL)
+ if (dbi->record != NULL) {
isc_mem_free(named_g_mctx, dbi->record);
+ }
/* free dbi->client string */
- if (dbi->client != NULL)
+ if (dbi->client != NULL) {
isc_mem_free(named_g_mctx, dbi->client);
+ }
#if 0
/* temporary logging message */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d unlocking mutex", dlz_thread_num);
-#endif
+#endif /* if 0 */
/* release the lock so another thread can use this dbi */
isc_mutex_unlock(&dbi->instance_lock);
/* release query string */
- if (querystring != NULL)
- isc_mem_free(named_g_mctx, querystring );
+ if (querystring != NULL) {
+ isc_mem_free(named_g_mctx, querystring);
+ }
#if 0
/* temporary logging message */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"%d returning", dlz_thread_num);
-#endif
+#endif /* if 0 */
/* return result */
- return result;
+ return (result);
}
/*%
@@ -616,8 +603,7 @@ postgres_get_resultset(const char *zone, const char *record,
*/
static isc_result_t
-postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs)
-{
+postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs) {
isc_result_t result;
unsigned int i;
unsigned int rows;
@@ -629,9 +615,9 @@ postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs)
int ttl;
rows = PQntuples(rs); /* how many rows in result set */
- fields = PQnfields(rs); /* how many columns in result set */
- for (i=0; i < rows; i++) {
- switch(fields) {
+ fields = PQnfields(rs); /* how many columns in result set */
+ for (i = 0; i < rows; i++) {
+ switch (fields) {
case 1:
/*
* one column in rs, it's the data field. use
@@ -665,12 +651,12 @@ postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs)
ttl, PQgetvalue(rs, i, 2));
break;
default:
- /*
+ /*
* more than 3 fields, concatenate the last
* ones together. figure out how long to make
* string
*/
- for (j=2, len=0; j < fields; j++) {
+ for (j = 2, len = 0; j < fields; j++) {
len += strlen(PQgetvalue(rs, i, j)) + 1;
}
/*
@@ -678,24 +664,13 @@ postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs)
* term string
*/
tmpString = isc_mem_allocate(named_g_mctx, len + 1);
- if (tmpString == NULL) {
- /* major bummer, need more ram */
- isc_log_write(dns_lctx,
- DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "Postgres driver unable to "
- "allocate memory for "
- "temporary string");
- PQclear(rs);
- return (ISC_R_FAILURE); /* Yeah, I'd say! */
- }
/* copy field to tmpString */
strcpy(tmpString, PQgetvalue(rs, i, 2));
/*
* concat the rest of fields together, space
* between each one.
*/
- for (j=3; j < fields; j++) {
+ for (j = 3; j < fields; j++) {
strcat(tmpString, " ");
strcat(tmpString, PQgetvalue(rs, i, j));
}
@@ -706,7 +681,7 @@ postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs)
DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver ttl must be "
- "a postive number");
+ "a positive number");
}
/* ok, now tell Bind about it. */
result = dns_sdlz_putrr(lookup, PQgetvalue(rs, i, 1),
@@ -731,8 +706,9 @@ postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs)
PQclear(rs);
/* if we did return results, we are successful */
- if (rows > 0)
+ if (rows > 0) {
return (ISC_R_SUCCESS);
+ }
/* empty result set, no data found */
return (ISC_R_NOTFOUND);
@@ -747,8 +723,7 @@ postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs)
static isc_result_t
postgres_findzone(void *driverarg, void *dbdata, const char *name,
dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
PGresult *rs = NULL;
unsigned int rows;
@@ -758,12 +733,13 @@ postgres_findzone(void *driverarg, void *dbdata, const char *name,
UNUSED(clientinfo);
/* run the query and get the result set from the database. */
- result = postgres_get_resultset(name, NULL, NULL,
- FINDZONE, dbdata, &rs);
+ result = postgres_get_resultset(name, NULL, NULL, FINDZONE, dbdata,
+ &rs);
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
PQclear(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to return "
@@ -776,8 +752,9 @@ postgres_findzone(void *driverarg, void *dbdata, const char *name,
PQclear(rs);
/* if we returned any rows, zone is supported. */
- if (rows > 0)
+ if (rows > 0) {
return (ISC_R_SUCCESS);
+ }
/* no rows returned, zone is not supported. */
return (ISC_R_NOTFOUND);
@@ -786,8 +763,7 @@ postgres_findzone(void *driverarg, void *dbdata, const char *name,
/*% Determine if the client is allowed to perform a zone transfer */
static isc_result_t
postgres_allowzonexfr(void *driverarg, void *dbdata, const char *name,
- const char *client)
-{
+ const char *client) {
isc_result_t result;
PGresult *rs = NULL;
unsigned int rows;
@@ -795,8 +771,9 @@ postgres_allowzonexfr(void *driverarg, void *dbdata, const char *name,
/* first check if the zone is supported by the database. */
result = postgres_findzone(driverarg, dbdata, name, NULL, NULL);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
/*
* if we get to this point we know the zone is supported by
@@ -806,15 +783,17 @@ postgres_allowzonexfr(void *driverarg, void *dbdata, const char *name,
*
* Run our query, and get a result set from the database.
*/
- result = postgres_get_resultset(name, NULL, client,
- ALLOWXFR, dbdata, &rs);
+ result = postgres_get_resultset(name, NULL, client, ALLOWXFR, dbdata,
+ &rs);
/* if we get "not implemented", send it along. */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
PQclear(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to return "
@@ -827,8 +806,9 @@ postgres_allowzonexfr(void *driverarg, void *dbdata, const char *name,
PQclear(rs);
/* if we returned any rows, zone xfr is allowed. */
- if (rows > 0)
+ if (rows > 0) {
return (ISC_R_SUCCESS);
+ }
/* no rows returned, zone xfr not allowed */
return (ISC_R_NOPERM);
@@ -841,8 +821,7 @@ postgres_allowzonexfr(void *driverarg, void *dbdata, const char *name,
*/
static isc_result_t
postgres_allnodes(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
+ dns_sdlzallnodes_t *allnodes) {
isc_result_t result;
PGresult *rs = NULL;
unsigned int i;
@@ -857,15 +836,17 @@ postgres_allnodes(const char *zone, void *driverarg, void *dbdata,
UNUSED(driverarg);
/* run the query and get the result set from the database. */
- result = postgres_get_resultset(zone, NULL, NULL,
- ALLNODES, dbdata, &rs);
+ result = postgres_get_resultset(zone, NULL, NULL, ALLNODES, dbdata,
+ &rs);
/* if we get "not implemented", send it along */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
PQclear(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to return "
@@ -874,9 +855,9 @@ postgres_allnodes(const char *zone, void *driverarg, void *dbdata,
}
rows = PQntuples(rs); /* how many rows in result set */
- fields = PQnfields(rs); /* how many columns in result set */
- for (i=0; i < rows; i++) {
- if (fields < 4) { /* gotta have at least 4 columns */
+ fields = PQnfields(rs); /* how many columns in result set */
+ for (i = 0; i < rows; i++) {
+ if (fields < 4) { /* gotta have at least 4 columns */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver too few fields "
@@ -888,14 +869,13 @@ postgres_allnodes(const char *zone, void *driverarg, void *dbdata,
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver ttl must be "
- "a postive number");
+ "a positive number");
}
if (fields == 4) {
/* tell Bind about it. */
result = dns_sdlz_putnamedrr(allnodes,
PQgetvalue(rs, i, 2),
- PQgetvalue(rs, i, 1),
- ttl,
+ PQgetvalue(rs, i, 1), ttl,
PQgetvalue(rs, i, 3));
} else {
/*
@@ -903,33 +883,22 @@ postgres_allnodes(const char *zone, void *driverarg, void *dbdata,
* ones together. figure out how long to make
* string
*/
- for (j=3, len=0; j < fields; j++) {
+ for (j = 3, len = 0; j < fields; j++) {
len += strlen(PQgetvalue(rs, i, j)) + 1;
}
/* allocate memory, allow for NULL to term string */
tmpString = isc_mem_allocate(named_g_mctx, len + 1);
- if (tmpString == NULL) { /* we need more ram. */
- isc_log_write(dns_lctx,
- DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "Postgres driver unable to "
- "allocate memory for "
- "temporary string");
- PQclear(rs);
- return (ISC_R_FAILURE);
- }
/* copy this field to tmpString */
strcpy(tmpString, PQgetvalue(rs, i, 3));
- /* concatonate the rest, with spaces between */
- for (j=4; j < fields; j++) {
+ /* concatenate the rest, with spaces between */
+ for (j = 4; j < fields; j++) {
strcat(tmpString, " ");
strcat(tmpString, PQgetvalue(rs, i, j));
}
/* tell Bind about it. */
- result = dns_sdlz_putnamedrr(allnodes,
- PQgetvalue(rs, i, 2),
- PQgetvalue(rs, i, 1),
- ttl, tmpString);
+ result = dns_sdlz_putnamedrr(
+ allnodes, PQgetvalue(rs, i, 2),
+ PQgetvalue(rs, i, 1), ttl, tmpString);
isc_mem_free(named_g_mctx, tmpString);
}
/* if we weren't successful, log err msg */
@@ -948,8 +917,9 @@ postgres_allnodes(const char *zone, void *driverarg, void *dbdata,
PQclear(rs);
/* if we did return results, we are successful */
- if (rows > 0)
+ if (rows > 0) {
return (ISC_R_SUCCESS);
+ }
/* empty result set, no data found */
return (ISC_R_NOTFOUND);
@@ -962,23 +932,24 @@ postgres_allnodes(const char *zone, void *driverarg, void *dbdata,
static isc_result_t
postgres_authority(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzlookup_t *lookup)
-{
+ dns_sdlzlookup_t *lookup) {
isc_result_t result;
PGresult *rs = NULL;
UNUSED(driverarg);
/* run the query and get the result set from the database. */
- result = postgres_get_resultset(zone, NULL, NULL,
- AUTHORITY, dbdata, &rs);
+ result = postgres_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata,
+ &rs);
/* if we get "not implemented", send it along */
- if (result == ISC_R_NOTIMPLEMENTED)
- return result;
+ if (result == ISC_R_NOTIMPLEMENTED) {
+ return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
PQclear(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to return "
@@ -990,15 +961,15 @@ postgres_authority(const char *zone, void *driverarg, void *dbdata,
* manner postgres_process_rs does the job for both
* functions.
*/
- return postgres_process_rs(lookup, rs);
+ return (postgres_process_rs(lookup, rs));
}
/*% if zone is supported, lookup up a (or multiple) record(s) in it */
static isc_result_t
postgres_lookup(const char *zone, const char *name, void *driverarg,
void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
+ dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
PGresult *rs = NULL;
@@ -1010,8 +981,9 @@ postgres_lookup(const char *zone, const char *name, void *driverarg,
result = postgres_get_resultset(zone, name, NULL, LOOKUP, dbdata, &rs);
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
PQclear(rs);
+ }
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver unable to "
@@ -1022,7 +994,7 @@ postgres_lookup(const char *zone, const char *name, void *driverarg,
* lookup and authority result sets are processed in the same
* manner postgres_process_rs does the job for both functions.
*/
- return postgres_process_rs(lookup, rs);
+ return (postgres_process_rs(lookup, rs));
}
/*%
@@ -1033,8 +1005,7 @@ postgres_lookup(const char *zone, const char *name, void *driverarg,
*/
static isc_result_t
postgres_create(const char *dlzname, unsigned int argc, char *argv[],
- void *driverarg, void **dbdata)
-{
+ void *driverarg, void **dbdata) {
isc_result_t result;
dbinstance_t *dbi = NULL;
unsigned int j;
@@ -1048,13 +1019,12 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
UNUSED(driverarg);
UNUSED(dlzname);
-/* seed random # generator */
- srand( (unsigned)time( NULL ) );
-
+ /* seed random # generator */
+ srand((unsigned)time(NULL));
/* if debugging, let user know we are multithreaded. */
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(1),
"Postgres driver running multithreaded");
/* verify we have at least 5 arg's passed to the driver */
@@ -1089,8 +1059,6 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate memory for database connection list */
dblist = isc_mem_get(named_g_mctx, sizeof(db_list_t));
- if (dblist == NULL)
- return (ISC_R_NOMEMORY);
/* initialize DB connection list */
ISC_LIST_INIT(*dblist);
@@ -1099,10 +1067,9 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
* create the appropriate number of database instances (DBI)
* append each new DBI to the end of the list
*/
- for (i=0; i < dbcount; i++) {
-
+ for (i = 0; i < dbcount; i++) {
/* how many queries were passed in from config file? */
- switch(argc) {
+ switch (argc) {
case 5:
result = build_sqldbinstance(named_g_mctx, NULL, NULL,
NULL, argv[3], argv[4],
@@ -1114,9 +1081,9 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
NULL, &dbi);
break;
case 7:
- result = build_sqldbinstance(named_g_mctx, argv[6], NULL,
- argv[5], argv[3], argv[4],
- NULL, &dbi);
+ result = build_sqldbinstance(named_g_mctx, argv[6],
+ NULL, argv[5], argv[3],
+ argv[4], NULL, &dbi);
break;
case 8:
result = build_sqldbinstance(named_g_mctx, argv[6],
@@ -1128,7 +1095,6 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
result = ISC_R_FAILURE;
}
-
if (result == ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
@@ -1162,11 +1128,9 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
/* if we cannot connect the first time, try 3 more times. */
for (j = 0;
- PQstatus((PGconn *) dbi->dbconn) != CONNECTION_OK &&
- j < 3;
+ PQstatus((PGconn *)dbi->dbconn) != CONNECTION_OK && j < 3;
j++)
- PQreset((PGconn *) dbi->dbconn);
-
+ PQreset((PGconn *)dbi->dbconn);
/*
* if multi threaded, let user know which connection
@@ -1174,7 +1138,7 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
* connections and for some reason the db backend only
* allows 9
*/
- if (PQstatus((PGconn *) dbi->dbconn) != CONNECTION_OK) {
+ if (PQstatus((PGconn *)dbi->dbconn) != CONNECTION_OK) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
"Postgres driver failed to create "
@@ -1186,15 +1150,15 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
/* set DBI = null for next loop through. */
dbi = NULL;
- } /* end for loop */
+ } /* end for loop */
- /* set dbdata to the list we created. */
+ /* set dbdata to the list we created. */
*dbdata = dblist;
/* hey, we got through all of that ok, return success. */
- return(ISC_R_SUCCESS);
+ return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
/*
* if multithreaded, we could fail because only 1 connection
@@ -1203,7 +1167,7 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
*/
postgres_destroy_dblist(dblist);
- return(ISC_R_FAILURE);
+ return (ISC_R_FAILURE);
}
/*%
@@ -1213,11 +1177,10 @@ postgres_create(const char *dlzname, unsigned int argc, char *argv[],
* so we really only need to clean it up since we are not using driverarg.
*/
static void
-postgres_destroy(void *driverarg, void *dbdata)
-{
+postgres_destroy(void *driverarg, void *dbdata) {
UNUSED(driverarg);
/* cleanup the list of DBI's */
- postgres_destroy_dblist((db_list_t *) dbdata);
+ postgres_destroy_dblist((db_list_t *)dbdata);
}
/* pointers to all our runtime methods. */
@@ -1250,9 +1213,8 @@ dlz_postgres_init(void) {
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Registering DLZ postgres driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Registering DLZ postgres driver.");
/*
* Driver is always threadsafe. When multithreaded all
@@ -1263,8 +1225,8 @@ dlz_postgres_init(void) {
*/
result = dns_sdlzregister("postgres", &dlz_postgres_methods, NULL,
DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA |
- DNS_SDLZFLAG_THREADSAFE,
+ DNS_SDLZFLAG_RELATIVERDATA |
+ DNS_SDLZFLAG_THREADSAFE,
named_g_mctx, &dlz_postgres);
/* if we can't register the driver, there are big problems. */
if (result != ISC_R_SUCCESS) {
@@ -1274,8 +1236,7 @@ dlz_postgres_init(void) {
result = ISC_R_UNEXPECTED;
}
-
- return result;
+ return (result);
}
/*%
@@ -1283,17 +1244,16 @@ dlz_postgres_init(void) {
*/
void
dlz_postgres_clear(void) {
-
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unregistering DLZ postgres driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unregistering DLZ postgres driver.");
/* unregister the driver. */
- if (dlz_postgres != NULL)
+ if (dlz_postgres != NULL) {
dns_sdlzunregister(&dlz_postgres);
+ }
}
-#endif
+#endif /* ifdef DLZ_POSTGRES */
diff --git a/contrib/dlz/drivers/dlz_stub_driver.c b/contrib/dlz/drivers/dlz_stub_driver.c
index 5d7aab6d..26b5aa8c 100644
--- a/contrib/dlz/drivers/dlz_stub_driver.c
+++ b/contrib/dlz/drivers/dlz_stub_driver.c
@@ -42,32 +42,29 @@
*/
#ifdef DLZ_STUB
-
-#include <config.h>
#include <stdio.h>
-#include <string.h>
#include <stdlib.h>
-
-#include <dns/log.h>
-#include <dns/sdlz.h>
-#include <dns/result.h>
+#include <string.h>
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/result.h>
#include <isc/util.h>
-#include <named/globals.h>
+#include <dns/log.h>
+#include <dns/result.h>
+#include <dns/sdlz.h>
#include <dlz/dlz_stub_driver.h>
+#include <named/globals.h>
static dns_sdlzimplementation_t *dlz_stub = NULL;
typedef struct config_data {
- char *myzone;
- char *myname;
- char *myip;
- isc_mem_t *mctx;
+ char *myzone;
+ char *myname;
+ char *myip;
+ isc_mem_t *mctx;
} config_data_t;
/*
@@ -76,40 +73,41 @@ typedef struct config_data {
static isc_result_t
stub_dlz_allnodes(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
+ dns_sdlzallnodes_t *allnodes) {
config_data_t *cd;
isc_result_t result;
UNUSED(zone);
UNUSED(driverarg);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
result = dns_sdlz_putnamedrr(allnodes, cd->myname, "soa", 86400,
"web root.localhost. "
"0 28800 7200 604800 86400");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
+ }
result = dns_sdlz_putnamedrr(allnodes, "ns", "ns", 86400, cd->myname);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
+ }
result = dns_sdlz_putnamedrr(allnodes, cd->myname, "a", 1, cd->myip);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
+ }
return (ISC_R_SUCCESS);
}
static isc_result_t
stub_dlz_allowzonexfr(void *driverarg, void *dbdata, const char *name,
- const char *client)
-{
+ const char *client) {
config_data_t *cd;
UNUSED(driverarg);
UNUSED(client);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
if (strcmp(name, cd->myname) == 0) {
return (ISC_R_SUCCESS);
@@ -119,24 +117,25 @@ stub_dlz_allowzonexfr(void *driverarg, void *dbdata, const char *name,
static isc_result_t
stub_dlz_authority(const char *zone, void *driverarg, void *dbdata,
- dns_sdlzlookup_t *lookup)
-{
+ dns_sdlzlookup_t *lookup) {
isc_result_t result;
config_data_t *cd;
UNUSED(driverarg);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
if (strcmp(zone, cd->myzone) == 0) {
- result = dns_sdlz_putsoa(lookup, cd->myname,
- "root.localhost.", 0);
- if (result != ISC_R_SUCCESS)
+ result = dns_sdlz_putsoa(lookup, cd->myname, "root.localhost.",
+ 0);
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
+ }
result = dns_sdlz_putrr(lookup, "ns", 86400, cd->myname);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
+ }
return (ISC_R_SUCCESS);
}
@@ -146,34 +145,32 @@ stub_dlz_authority(const char *zone, void *driverarg, void *dbdata,
static isc_result_t
stub_dlz_findzonedb(void *driverarg, void *dbdata, const char *name,
dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
-
+ dns_clientinfo_t *clientinfo) {
config_data_t *cd;
UNUSED(driverarg);
UNUSED(methods);
UNUSED(clientinfo);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
/* Write info message to log */
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "dlz_stub findzone looking for '%s'", name);
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "dlz_stub findzone looking for '%s'",
+ name);
- if (strcmp(cd->myzone, name) == 0)
+ if (strcmp(cd->myzone, name) == 0) {
return (ISC_R_SUCCESS);
- else
+ } else {
return (ISC_R_NOTFOUND);
+ }
}
-
static isc_result_t
stub_dlz_lookup(const char *zone, const char *name, void *driverarg,
void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo)
-{
+ dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
config_data_t *cd;
@@ -182,36 +179,34 @@ stub_dlz_lookup(const char *zone, const char *name, void *driverarg,
UNUSED(methods);
UNUSED(clientinfo);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
if (strcmp(name, cd->myname) == 0) {
result = dns_sdlz_putrr(lookup, "a", 1, cd->myip);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
+ }
return (ISC_R_SUCCESS);
}
return (ISC_R_FAILURE);
-
}
-
static isc_result_t
stub_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void *driverarg, void **dbdata)
-{
-
+ void *driverarg, void **dbdata) {
config_data_t *cd;
UNUSED(driverarg);
- if (argc < 4)
+ if (argc < 4) {
return (ISC_R_FAILURE);
+ }
/*
* Write info message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_INFO,
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_INFO,
"Loading '%s' using DLZ_stub driver. "
"Zone: %s, Name: %s IP: %s",
dlzname, argv[1], argv[2], argv[3]);
@@ -224,56 +219,38 @@ stub_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
memset(cd, 0, sizeof(config_data_t));
cd->myzone = isc_mem_strdup(named_g_mctx, argv[1]);
- if (cd->myzone == NULL) {
- isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
- return (ISC_R_NOMEMORY);
- }
cd->myname = isc_mem_strdup(named_g_mctx, argv[2]);
- if (cd->myname == NULL) {
- isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
- isc_mem_free(named_g_mctx, cd->myzone);
- return (ISC_R_NOMEMORY);
- }
cd->myip = isc_mem_strdup(named_g_mctx, argv[3]);
- if (cd->myip == NULL) {
- isc_mem_put(named_g_mctx, cd, sizeof(config_data_t));
- isc_mem_free(named_g_mctx, cd->myname);
- isc_mem_free(named_g_mctx, cd->myzone);
- return (ISC_R_NOMEMORY);
- }
isc_mem_attach(named_g_mctx, &cd->mctx);
*dbdata = cd;
- return(ISC_R_SUCCESS);
+ return (ISC_R_SUCCESS);
}
static void
-stub_dlz_destroy(void *driverarg, void *dbdata)
-{
+stub_dlz_destroy(void *driverarg, void *dbdata) {
config_data_t *cd;
isc_mem_t *mctx;
UNUSED(driverarg);
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unloading DLZ_stub driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unloading DLZ_stub driver.");
isc_mem_free(named_g_mctx, cd->myzone);
isc_mem_free(named_g_mctx, cd->myname);
isc_mem_free(named_g_mctx, cd->myip);
mctx = cd->mctx;
- isc_mem_put(mctx, cd, sizeof(config_data_t));
- isc_mem_detach(&mctx);
+ isc_mem_putanddetach(&mctx, cd, sizeof(config_data_t));
}
static dns_sdlzmethods_t dlz_stub_methods = {
@@ -303,13 +280,12 @@ dlz_stub_init(void) {
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Registering DLZ_stub driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Registering DLZ_stub driver.");
result = dns_sdlzregister("dlz_stub", &dlz_stub_methods, NULL,
DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA,
+ DNS_SDLZFLAG_RELATIVERDATA,
named_g_mctx, &dlz_stub);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
@@ -318,8 +294,7 @@ dlz_stub_init(void) {
result = ISC_R_UNEXPECTED;
}
-
- return result;
+ return (result);
}
/*
@@ -327,16 +302,15 @@ dlz_stub_init(void) {
*/
void
dlz_stub_clear(void) {
-
/*
* Write debugging message to log
*/
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2),
- "Unregistering DLZ_stub driver.");
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ,
+ ISC_LOG_DEBUG(2), "Unregistering DLZ_stub driver.");
- if (dlz_stub != NULL)
+ if (dlz_stub != NULL) {
dns_sdlzunregister(&dlz_stub);
+ }
}
-#endif
+#endif /* ifdef DLZ_STUB */
diff --git a/contrib/dlz/drivers/include/.clang-format b/contrib/dlz/drivers/include/.clang-format
new file mode 120000
index 00000000..e919bbad
--- /dev/null
+++ b/contrib/dlz/drivers/include/.clang-format
@@ -0,0 +1 @@
+../../../../.clang-format.headers \ No newline at end of file
diff --git a/contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h b/contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h
index 1d706fc8..b180832c 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h
@@ -42,4 +42,4 @@ dlz_bdb_init(void);
void
dlz_bdb_clear(void);
-#endif
+#endif /* ifndef DLZ_BDB_DRIVER_H */
diff --git a/contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h b/contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h
index 0ccbc8da..65a2b84d 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h
@@ -42,4 +42,4 @@ dlz_bdbhpt_init(void);
void
dlz_bdbhpt_clear(void);
-#endif
+#endif /* ifndef DLZ_BDBHPT_DRIVER_H */
diff --git a/contrib/dlz/drivers/include/dlz/dlz_drivers.h b/contrib/dlz/drivers/include/dlz/dlz_drivers.h
index 58ffadad..483285c6 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_drivers.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_drivers.h
@@ -14,7 +14,6 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-
#ifndef DLZ_DRIVERS_H
#define DLZ_DRIVERS_H 1
diff --git a/contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h b/contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h
index 627427d9..a13c7033 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h
@@ -42,4 +42,4 @@ dlz_fs_init(void);
void
dlz_fs_clear(void);
-#endif
+#endif /* ifndef DLZ_FILESYSTEM_DRIVER_H */
diff --git a/contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h b/contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h
index 51efbf49..3df72858 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h
@@ -42,4 +42,4 @@ dlz_ldap_init(void);
void
dlz_ldap_clear(void);
-#endif
+#endif /* ifndef DLZ_LDAP_DRIVER_H */
diff --git a/contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h b/contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h
index b742838b..68a0b540 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h
@@ -42,4 +42,4 @@ dlz_mysql_init(void);
void
dlz_mysql_clear(void);
-#endif
+#endif /* ifndef DLZ_MYSQL_DRIVER_H */
diff --git a/contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h b/contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h
index 5a072d8c..b3ed620b 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h
@@ -42,4 +42,4 @@ dlz_odbc_init(void);
void
dlz_odbc_clear(void);
-#endif
+#endif /* ifndef DLZ_ODBC_DRIVER_H */
diff --git a/contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h b/contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h
index 3416dcea..d8e250dc 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h
@@ -42,4 +42,4 @@ dlz_postgres_init(void);
void
dlz_postgres_clear(void);
-#endif
+#endif /* ifndef DLZ_POSTGRES_DRIVER_H */
diff --git a/contrib/dlz/drivers/include/dlz/dlz_stub_driver.h b/contrib/dlz/drivers/include/dlz/dlz_stub_driver.h
index a517c69a..73df7ba2 100644
--- a/contrib/dlz/drivers/include/dlz/dlz_stub_driver.h
+++ b/contrib/dlz/drivers/include/dlz/dlz_stub_driver.h
@@ -42,4 +42,4 @@ dlz_stub_init(void);
void
dlz_stub_clear(void);
-#endif
+#endif /* ifndef DLZ_STUB_DRIVER_H */
diff --git a/contrib/dlz/drivers/include/dlz/sdlz_helper.h b/contrib/dlz/drivers/include/dlz/sdlz_helper.h
index b6add3f1..d46db7c2 100644
--- a/contrib/dlz/drivers/include/dlz/sdlz_helper.h
+++ b/contrib/dlz/drivers/include/dlz/sdlz_helper.h
@@ -41,10 +41,10 @@
/*
* Types
*/
-#define SDLZH_REQUIRE_CLIENT 0x01
-#define SDLZH_REQUIRE_QUERY 0x02
-#define SDLZH_REQUIRE_RECORD 0x04
-#define SDLZH_REQUIRE_ZONE 0x08
+#define SDLZH_REQUIRE_CLIENT 0x01
+#define SDLZH_REQUIRE_QUERY 0x02
+#define SDLZH_REQUIRE_RECORD 0x04
+#define SDLZH_REQUIRE_ZONE 0x08
typedef struct query_segment query_segment_t;
typedef ISC_LIST(query_segment_t) query_list_t;
@@ -57,10 +57,10 @@ typedef struct driverinstance driverinstance_t;
* special tokens are %zone%, %record%, %client%
*/
struct query_segment {
- void *sql;
- unsigned int strlen;
- bool direct;
- ISC_LINK(query_segment_t) link;
+ void * sql;
+ unsigned int strlen;
+ bool direct;
+ ISC_LINK(query_segment_t) link;
};
/*%
@@ -71,20 +71,20 @@ struct query_segment {
* make sure no two threads try to use the same DBI at a time.
*/
struct dbinstance {
- void *dbconn;
- query_list_t *allnodes_q;
- query_list_t *allowxfr_q;
- query_list_t *authority_q;
- query_list_t *findzone_q;
- query_list_t *lookup_q;
- query_list_t *countzone_q;
- char *query_buf;
- char *zone;
- char *record;
- char *client;
- isc_mem_t *mctx;
- isc_mutex_t instance_lock;
- ISC_LINK(dbinstance_t) link;
+ void * dbconn;
+ query_list_t *allnodes_q;
+ query_list_t *allowxfr_q;
+ query_list_t *authority_q;
+ query_list_t *findzone_q;
+ query_list_t *lookup_q;
+ query_list_t *countzone_q;
+ char * query_buf;
+ char * zone;
+ char * record;
+ char * client;
+ isc_mem_t * mctx;
+ isc_mutex_t instance_lock;
+ ISC_LINK(dbinstance_t) link;
};
/*
@@ -106,14 +106,15 @@ void
sdlzh_destroy_sqldbinstance(dbinstance_t *dbi);
char *
-sdlzh_get_parameter_value(isc_mem_t *mctx, const char *input, const char* key);
+sdlzh_get_parameter_value(isc_mem_t *mctx, const char *input, const char *key);
-/* Compatability with existing DLZ drivers */
+/* Compatibility with existing DLZ drivers */
-#define build_querystring sdlzh_build_querystring
-#define build_sqldbinstance sdlzh_build_sqldbinstance
-#define destroy_sqldbinstance sdlzh_destroy_sqldbinstance
+#define build_querystring sdlzh_build_querystring
+#define build_sqldbinstance sdlzh_build_sqldbinstance
+#define destroy_sqldbinstance sdlzh_destroy_sqldbinstance
-#define getParameterValue(x,y) sdlzh_get_parameter_value(named_g_mctx, (x), (y))
+#define getParameterValue(x, y) \
+ sdlzh_get_parameter_value(named_g_mctx, (x), (y))
#endif /* SDLZHELPER_H */
diff --git a/contrib/dlz/drivers/sdlz_helper.c b/contrib/dlz/drivers/sdlz_helper.c
index e08cf89d..e496587f 100644
--- a/contrib/dlz/drivers/sdlz_helper.c
+++ b/contrib/dlz/drivers/sdlz_helper.c
@@ -41,18 +41,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <config.h>
-
#include <stdbool.h>
-#include <dns/log.h>
-#include <dns/result.h>
-
#include <isc/mem.h>
#include <isc/result.h>
#include <isc/string.h>
#include <isc/util.h>
+#include <dns/log.h>
+#include <dns/result.h>
+
#include <dlz/sdlz_helper.h>
/*
@@ -65,28 +63,29 @@
*/
static void
-destroy_querylist(isc_mem_t *mctx, query_list_t **querylist)
-{
+destroy_querylist(isc_mem_t *mctx, query_list_t **querylist) {
query_segment_t *tseg = NULL;
query_segment_t *nseg = NULL;
REQUIRE(mctx != NULL);
/* if query list is null, nothing to do */
- if (*querylist == NULL)
+ if (*querylist == NULL) {
return;
+ }
/* start at the top of the list */
nseg = ISC_LIST_HEAD(**querylist);
- while (nseg != NULL) { /* loop, until end of list */
+ while (nseg != NULL) { /* loop, until end of list */
tseg = nseg;
/*
* free the query segment's text string but only if it
* was really a query segment, and not a pointer to
* %zone%, or %record%, or %client%
- */
- if (tseg->sql != NULL && tseg->direct == true)
+ */
+ if (tseg->sql != NULL && tseg->direct) {
isc_mem_free(mctx, tseg->sql);
+ }
/* get the next query segment, before we destroy this one. */
nseg = ISC_LIST_NEXT(nseg, link);
/* deallocate this query segment. */
@@ -100,8 +99,7 @@ destroy_querylist(isc_mem_t *mctx, query_list_t **querylist)
static isc_result_t
build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
char **record, char **client, query_list_t **querylist,
- unsigned int flags)
-{
+ unsigned int flags) {
isc_result_t result;
bool foundzone = false;
bool foundrecord = false;
@@ -117,19 +115,17 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
/* if query string is null, or zero length */
if (query_str == NULL || strlen(query_str) < 1) {
- if ((flags & SDLZH_REQUIRE_QUERY) == 0)
+ if ((flags & SDLZH_REQUIRE_QUERY) == 0) {
/* we don't need it were ok. */
return (ISC_R_SUCCESS);
- else
+ } else {
/* we did need it, PROBLEM!!! */
return (ISC_R_FAILURE);
+ }
}
/* allocate memory for query list */
tql = isc_mem_get(mctx, sizeof(query_list_t));
- /* couldn't allocate memory. Problem!! */
- if (tql == NULL)
- return (ISC_R_NOMEMORY);
/* initialize the query segment list */
ISC_LIST_INIT(*tql);
@@ -155,10 +151,6 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
/* allocate memory for tseg */
tseg = isc_mem_get(mctx, sizeof(query_segment_t));
- if (tseg == NULL) { /* no memory, clean everything up. */
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
tseg->sql = NULL;
tseg->direct = false;
/* initialize the query segment link */
@@ -167,11 +159,6 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
ISC_LIST_APPEND(*tql, tseg, link);
tseg->sql = isc_mem_strdup(mctx, sql);
- if (tseg->sql == NULL) {
- /* no memory, clean everything up. */
- result = ISC_R_NOMEMORY;
- goto cleanup;
- }
/* tseg->sql points directly to a string. */
tseg->direct = true;
tseg->strlen = strlen(tseg->sql);
@@ -226,7 +213,7 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
*/
/* if this query requires %client%, make sure we found it */
- if (((flags & SDLZH_REQUIRE_CLIENT) != 0) && (!foundclient) ) {
+ if (((flags & SDLZH_REQUIRE_CLIENT) != 0) && (!foundclient)) {
/* Write error message to log */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
@@ -236,7 +223,7 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
}
/* if this query requires %record%, make sure we found it */
- if (((flags & SDLZH_REQUIRE_RECORD) != 0) && (!foundrecord) ) {
+ if (((flags & SDLZH_REQUIRE_RECORD) != 0) && (!foundrecord)) {
/* Write error message to log */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
@@ -246,7 +233,7 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
}
/* if this query requires %zone%, make sure we found it */
- if (((flags & SDLZH_REQUIRE_ZONE) != 0) && (!foundzone) ) {
+ if (((flags & SDLZH_REQUIRE_ZONE) != 0) && (!foundzone)) {
/* Write error message to log */
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
@@ -256,21 +243,21 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
}
/* pass back the query list */
- *querylist = (query_list_t *) tql;
+ *querylist = (query_list_t *)tql;
/* return success */
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
/* get rid of free_me */
- if (free_me != NULL)
+ if (free_me != NULL) {
isc_mem_free(mctx, free_me);
+ }
- flag_fail:
+flag_fail:
/* get rid of what was build of the query list */
- if (tql != NULL)
- destroy_querylist(mctx, &tql);
- return result;
+ destroy_querylist(mctx, &tql);
+ return (result);
}
/*%
@@ -279,8 +266,7 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
* used to be in our queries from named.conf
*/
char *
-sdlzh_build_querystring(isc_mem_t *mctx, query_list_t *querylist)
-{
+sdlzh_build_querystring(isc_mem_t *mctx, query_list_t *querylist) {
query_segment_t *tseg = NULL;
unsigned int length = 0;
char *qs = NULL;
@@ -295,45 +281,42 @@ sdlzh_build_querystring(isc_mem_t *mctx, query_list_t *querylist)
* if this is a query segment, use the
* precalculated string length
*/
- if (tseg->direct == true)
+ if (tseg->direct) {
length += tseg->strlen;
- else /* calculate string length for dynamic segments. */
- length += strlen(* (char**) tseg->sql);
+ } else { /* calculate string length for dynamic segments. */
+ length += strlen(*(char **)tseg->sql);
+ }
/* get the next segment */
tseg = ISC_LIST_NEXT(tseg, link);
}
/* allocate memory for the string */
qs = isc_mem_allocate(mctx, length + 1);
- /* couldn't allocate memory, We need more ram! */
- if (qs == NULL)
- return NULL;
*qs = 0;
/* start at the top of the list again */
tseg = ISC_LIST_HEAD(*querylist);
while (tseg != NULL) {
- if (tseg->direct == true)
+ if (tseg->direct) {
/* query segments */
strcat(qs, tseg->sql);
- else
+ } else {
/* dynamic segments */
- strcat(qs, * (char**) tseg->sql);
+ strcat(qs, *(char **)tseg->sql);
+ }
/* get the next segment */
tseg = ISC_LIST_NEXT(tseg, link);
}
- return qs;
+ return (qs);
}
/*% constructs a sql dbinstance (DBI) */
isc_result_t
sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
- const char *allowxfr_str, const char *authority_str,
- const char *findzone_str, const char *lookup_str,
- const char *countzone_str, dbinstance_t **dbi)
-{
-
+ const char *allowxfr_str, const char *authority_str,
+ const char *findzone_str, const char *lookup_str,
+ const char *countzone_str, dbinstance_t **dbi) {
isc_result_t result;
dbinstance_t *db = NULL;
@@ -342,13 +325,6 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
/* allocate and zero memory for driver structure */
db = isc_mem_get(mctx, sizeof(dbinstance_t));
- if (db == NULL) {
- isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
- DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
- "Could not allocate memory for "
- "database instance object.");
- return (ISC_R_NOMEMORY);
- }
memset(db, 0, sizeof(dbinstance_t));
db->dbconn = NULL;
db->client = NULL;
@@ -370,9 +346,9 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
isc_mutex_init(&db->instance_lock);
/* build the all nodes query list */
- result = build_querylist(mctx, allnodes_str, &db->zone,
- &db->record, &db->client,
- &db->allnodes_q, SDLZH_REQUIRE_ZONE);
+ result = build_querylist(mctx, allnodes_str, &db->zone, &db->record,
+ &db->client, &db->allnodes_q,
+ SDLZH_REQUIRE_ZONE);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
@@ -382,9 +358,8 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
}
/* build the allow zone transfer query list */
- result = build_querylist(mctx, allowxfr_str, &db->zone,
- &db->record, &db->client,
- &db->allowxfr_q,
+ result = build_querylist(mctx, allowxfr_str, &db->zone, &db->record,
+ &db->client, &db->allowxfr_q,
SDLZH_REQUIRE_ZONE | SDLZH_REQUIRE_CLIENT);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
@@ -395,9 +370,9 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
}
/* build the authority query, query list */
- result = build_querylist(mctx, authority_str, &db->zone,
- &db->record, &db->client,
- &db->authority_q, SDLZH_REQUIRE_ZONE);
+ result = build_querylist(mctx, authority_str, &db->zone, &db->record,
+ &db->client, &db->authority_q,
+ SDLZH_REQUIRE_ZONE);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
@@ -407,9 +382,9 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
}
/* build findzone query, query list */
- result = build_querylist(mctx, findzone_str, &db->zone,
- &db->record, &db->client,
- &db->findzone_q, SDLZH_REQUIRE_ZONE);
+ result = build_querylist(mctx, findzone_str, &db->zone, &db->record,
+ &db->client, &db->findzone_q,
+ SDLZH_REQUIRE_ZONE);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
@@ -419,9 +394,9 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
}
/* build countzone query, query list */
- result = build_querylist(mctx, countzone_str, &db->zone,
- &db->record, &db->client,
- &db->countzone_q, SDLZH_REQUIRE_ZONE);
+ result = build_querylist(mctx, countzone_str, &db->zone, &db->record,
+ &db->client, &db->countzone_q,
+ SDLZH_REQUIRE_ZONE);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
@@ -431,9 +406,9 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
}
/* build lookup query, query list */
- result = build_querylist(mctx, lookup_str, &db->zone,
- &db->record, &db->client,
- &db->lookup_q, SDLZH_REQUIRE_RECORD);
+ result = build_querylist(mctx, lookup_str, &db->zone, &db->record,
+ &db->client, &db->lookup_q,
+ SDLZH_REQUIRE_RECORD);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
@@ -443,12 +418,12 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
}
/* pass back the db instance */
- *dbi = (dbinstance_t *) db;
+ *dbi = (dbinstance_t *)db;
/* return success */
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
/* destroy whatever was build of the db instance */
destroy_sqldbinstance(db);
/* return failure */
@@ -456,8 +431,7 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
}
void
-sdlzh_destroy_sqldbinstance(dbinstance_t *dbi)
-{
+sdlzh_destroy_sqldbinstance(dbinstance_t *dbi) {
isc_mem_t *mctx;
/* save mctx for later */
@@ -472,33 +446,34 @@ sdlzh_destroy_sqldbinstance(dbinstance_t *dbi)
destroy_querylist(mctx, &dbi->lookup_q);
/* get rid of the mutex */
- (void) isc_mutex_destroy(&dbi->instance_lock);
+ (void)isc_mutex_destroy(&dbi->instance_lock);
/* return, and detach the memory */
- isc_mem_put(mctx, dbi, sizeof(dbinstance_t));
- isc_mem_detach(&mctx);
+ isc_mem_putanddetach(&mctx, dbi, sizeof(dbinstance_t));
}
char *
-sdlzh_get_parameter_value(isc_mem_t *mctx, const char *input, const char* key)
-{
+sdlzh_get_parameter_value(isc_mem_t *mctx, const char *input, const char *key) {
int keylen;
char *keystart;
char value[255];
int i;
- if (key == NULL || input == NULL || strlen(input) < 1)
- return NULL;
+ if (key == NULL || input == NULL || strlen(input) < 1) {
+ return (NULL);
+ }
keylen = strlen(key);
- if (keylen < 1)
- return NULL;
+ if (keylen < 1) {
+ return (NULL);
+ }
keystart = strstr(input, key);
- if (keystart == NULL)
- return NULL;
+ if (keystart == NULL) {
+ return (NULL);
+ }
REQUIRE(mctx != NULL);
@@ -510,5 +485,5 @@ sdlzh_get_parameter_value(isc_mem_t *mctx, const char *input, const char* key)
}
}
- return isc_mem_strdup(mctx, value);
+ return (isc_mem_strdup(mctx, value));
}
diff --git a/contrib/dlz/example/README b/contrib/dlz/example/README
index 3c6ba8cf..f8667ac5 100644
--- a/contrib/dlz/example/README
+++ b/contrib/dlz/example/README
@@ -1,6 +1,6 @@
OVERVIEW:
-DLZ (Dynamically Loadable Zones) is an extention to BIND 9 that
+DLZ (Dynamically Loadable Zones) is an extension to BIND 9 that
allows zone data to be retrieved directly from an external database.
There is no required format or schema. DLZ drivers exist for several
different database backends including PostgreSQL, MySQL, and LDAP and
@@ -136,7 +136,7 @@ The DLZ dlopen driver provides a set of callback functions:
- isc_result_t writeable_zone(dns_view_t *view, const char *zone_name);
- Allows the DLZ module to inform named that a given zone can recieve
+ Allows the DLZ module to inform named that a given zone can receive
DDNS updates. (Note: This is not currently supported for DLZ
databases that are configured as 'search no;')
diff --git a/contrib/dlz/example/dlz_example.c b/contrib/dlz/example/dlz_example.c
index db19a8c4..cd4db52d 100644
--- a/contrib/dlz/example/dlz_example.c
+++ b/contrib/dlz/example/dlz_example.c
@@ -19,20 +19,20 @@
* driver, with update support.
*/
+#include <inttypes.h>
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
-#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
-#include <stdarg.h>
#include "../modules/include/dlz_minimal.h"
-#define CHECK(x) \
- do { \
- result = (x); \
+#define CHECK(x) \
+ do { \
+ result = (x); \
if (result != ISC_R_SUCCESS) \
- goto failure; \
+ goto failure; \
} while (0)
/* For this simple example, use fixed sized strings */
@@ -79,9 +79,8 @@ single_valued(const char *type) {
* Add a record to a list
*/
static isc_result_t
-add_name(struct dlz_example_data *state, struct record *list,
- const char *name, const char *type, dns_ttl_t ttl, const char *data)
-{
+add_name(struct dlz_example_data *state, struct record *list, const char *name,
+ const char *type, dns_ttl_t ttl, const char *data) {
int i;
bool single = single_valued(type);
int first_empty = -1;
@@ -90,28 +89,34 @@ add_name(struct dlz_example_data *state, struct record *list,
if (first_empty == -1 && strlen(list[i].name) == 0U) {
first_empty = i;
}
- if (strcasecmp(list[i].name, name) != 0)
+ if (strcasecmp(list[i].name, name) != 0) {
continue;
- if (strcasecmp(list[i].type, type) != 0)
+ }
+ if (strcasecmp(list[i].type, type) != 0) {
continue;
- if (!single && strcasecmp(list[i].data, data) != 0)
+ }
+ if (!single && strcasecmp(list[i].data, data) != 0) {
continue;
+ }
break;
}
if (i == MAX_RECORDS && first_empty != -1) {
i = first_empty;
}
if (i == MAX_RECORDS) {
- if (state->log != NULL)
- state->log(ISC_LOG_ERROR,
- "dlz_example: out of record space");
+ if (state->log != NULL) {
+ state->log(ISC_LOG_ERROR, "dlz_example: out of record "
+ "space");
+ }
return (ISC_R_FAILURE);
}
if (strlen(name) >= sizeof(list[i].name) ||
strlen(type) >= sizeof(list[i].type) ||
strlen(data) >= sizeof(list[i].data))
+ {
return (ISC_R_NOSPACE);
+ }
strncpy(list[i].name, name, sizeof(list[i].name));
list[i].name[sizeof(list[i].name) - 1] = '\0';
@@ -131,10 +136,8 @@ add_name(struct dlz_example_data *state, struct record *list,
* Delete a record from a list
*/
static isc_result_t
-del_name(struct dlz_example_data *state, struct record *list,
- const char *name, const char *type, dns_ttl_t ttl,
- const char *data)
-{
+del_name(struct dlz_example_data *state, struct record *list, const char *name,
+ const char *type, dns_ttl_t ttl, const char *data) {
int i;
UNUSED(state);
@@ -142,8 +145,8 @@ del_name(struct dlz_example_data *state, struct record *list,
for (i = 0; i < MAX_RECORDS; i++) {
if (strcasecmp(name, list[i].name) == 0 &&
strcasecmp(type, list[i].type) == 0 &&
- strcasecmp(data, list[i].data) == 0 &&
- ttl == list[i].ttl) {
+ strcasecmp(data, list[i].data) == 0 && ttl == list[i].ttl)
+ {
break;
}
}
@@ -175,8 +178,9 @@ fmt_address(isc_sockaddr_t *addr, char *buffer, size_t size) {
return (ISC_R_FAILURE);
}
- if (ret == NULL)
+ if (ret == NULL) {
return (ISC_R_FAILURE);
+ }
snprintf(buffer, size, "%s#%u", addr_buf, port);
return (ISC_R_SUCCESS);
@@ -195,26 +199,28 @@ dlz_version(unsigned int *flags) {
* Remember a helper function from the bind9 dlz_dlopen driver
*/
static void
-b9_add_helper(struct dlz_example_data *state,
- const char *helper_name, void *ptr)
-{
- if (strcmp(helper_name, "log") == 0)
+b9_add_helper(struct dlz_example_data *state, const char *helper_name,
+ void *ptr) {
+ if (strcmp(helper_name, "log") == 0) {
state->log = (log_t *)ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
state->putrr = (dns_sdlz_putrr_t *)ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
state->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
state->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
+ }
}
/*
* Called to initialize the driver
*/
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
struct dlz_example_data *state;
const char *helper_name;
va_list ap;
@@ -226,8 +232,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
UNUSED(dlzname);
state = calloc(1, sizeof(struct dlz_example_data));
- if (state == NULL)
+ if (state == NULL) {
return (ISC_R_NOMEMORY);
+ }
/* Fill in the helper functions */
va_start(ap, dbdata);
@@ -237,9 +244,10 @@ 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");
+ if (state->log != NULL) {
+ state->log(ISC_LOG_ERROR, "dlz_example: please specify "
+ "a zone name");
+ }
dlz_destroy(state);
return (ISC_R_FAILURE);
}
@@ -250,42 +258,46 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
free(state);
return (ISC_R_NOMEMORY);
}
- if (argv[1][strlen(argv[1]) - 1] == '.')
+ if (argv[1][strlen(argv[1]) - 1] == '.') {
strcpy(state->zone_name, argv[1]);
- else
+ } else {
sprintf(state->zone_name, "%s.", argv[1]);
+ }
- if (strcmp(state->zone_name, ".") == 0)
+ if (strcmp(state->zone_name, ".") == 0) {
extra = ".root";
- else
+ } else {
extra = ".";
+ }
n = sprintf(soa_data, "%s hostmaster%s%s 123 900 600 86400 3600",
state->zone_name, extra, state->zone_name);
- if (n < 0)
+ if (n < 0) {
CHECK(ISC_R_FAILURE);
- if ((unsigned)n >= sizeof(soa_data))
+ }
+ if ((unsigned)n >= sizeof(soa_data)) {
CHECK(ISC_R_NOSPACE);
+ }
- add_name(state, &state->current[0], state->zone_name,
- "soa", 3600, soa_data);
- add_name(state, &state->current[0], state->zone_name,
- "ns", 3600, state->zone_name);
- add_name(state, &state->current[0], state->zone_name,
- "a", 1800, "10.53.0.1");
+ add_name(state, &state->current[0], state->zone_name, "soa", 3600,
+ soa_data);
+ add_name(state, &state->current[0], state->zone_name, "ns", 3600,
+ state->zone_name);
+ add_name(state, &state->current[0], state->zone_name, "a", 1800,
+ "10.53.0.1");
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_INFO, "dlz_example: started for zone %s",
state->zone_name);
+ }
*dbdata = state;
return (ISC_R_SUCCESS);
- failure:
+failure:
free(state);
return (result);
-
}
/*
@@ -295,10 +307,10 @@ 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",
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO, "dlz_example: shutting down zone %s",
state->zone_name);
+ }
free(state->zone_name);
free(state);
}
@@ -307,30 +319,28 @@ dlz_destroy(void *dbdata) {
* See if we handle a given zone
*/
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
isc_sockaddr_t *src;
char addrbuf[100];
char absolute[1024];
strcpy(addrbuf, "unknown");
- if (methods != NULL &&
- methods->sourceip != NULL &&
+ if (methods != NULL && methods->sourceip != NULL &&
methods->version - methods->age <= DNS_CLIENTINFOMETHODS_VERSION &&
DNS_CLIENTINFOMETHODS_VERSION <= methods->version)
{
methods->sourceip(clientinfo, &src);
fmt_address(src, addrbuf, sizeof(addrbuf));
}
- state->log(ISC_LOG_INFO,
- "dlz_example: findzonedb connection from: %s", addrbuf);
+ state->log(ISC_LOG_INFO, "dlz_example: findzonedb connection from: %s",
+ addrbuf);
state->log(ISC_LOG_INFO,
"dlz_example: dlz_findzonedb called with name '%s' "
- "in zone DB '%s'", name, state->zone_name);
+ "in zone DB '%s'",
+ name, state->zone_name);
/*
* Returning ISC_R_NOTFOUND will cause the query logic to
@@ -339,8 +349,9 @@ dlz_findzonedb(void *dbdata, const char *name,
* Returning ISC_R_NOMORE prevents the query logic from doing
* this; it will move onto the next database after a single query.
*/
- if (strcasecmp(name, "test.example.com") == 0)
+ if (strcasecmp(name, "test.example.com") == 0) {
return (ISC_R_NOMORE);
+ }
/*
* For example.net, only return ISC_R_NOMORE when queried
@@ -348,14 +359,18 @@ dlz_findzonedb(void *dbdata, const char *name,
*/
if (strcasecmp(name, "test.example.net") == 0 &&
strncmp(addrbuf, "10.53.0.1", 9) == 0)
+ {
return (ISC_R_NOMORE);
+ }
- if (strcasecmp(state->zone_name, name) == 0)
+ if (strcasecmp(state->zone_name, name) == 0) {
return (ISC_R_SUCCESS);
+ }
snprintf(absolute, sizeof(absolute), "%s.", name);
- if (strcasecmp(state->zone_name, absolute) == 0)
+ if (strcasecmp(state->zone_name, absolute) == 0) {
return (ISC_R_SUCCESS);
+ }
return (ISC_R_NOTFOUND);
}
@@ -373,8 +388,7 @@ dlz_findzonedb(void *dbdata, const char *name,
isc_result_t
dlz_lookup(const char *zone, const char *name, void *dbdata,
dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
bool found = false;
@@ -386,14 +400,16 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
UNUSED(zone);
- if (state->putrr == NULL)
+ if (state->putrr == NULL) {
return (ISC_R_NOTIMPLEMENTED);
+ }
if (strcmp(name, "@") == 0) {
strncpy(full_name, state->zone_name, 255);
full_name[255] = '\0';
- } else
+ } else {
snprintf(full_name, 255, "%s.%s", name, state->zone_name);
+ }
/*
* If we need to know the database version (as set in
@@ -410,19 +426,19 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
* If the DLZ only operates on 'live' data, then version
* wouldn't necessarily be needed.
*/
- if (clientinfo != NULL &&
- clientinfo->version >= DNS_CLIENTINFO_VERSION) {
+ 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\n");
+ if (dbversion != NULL && *(bool *)dbversion) {
+ state->log(ISC_LOG_INFO, "dlz_example: lookup against "
+ "live "
+ "transaction\n");
+ }
}
if (strcmp(name, "source-addr") == 0) {
strcpy(buf, "unknown");
- if (methods != NULL &&
- methods->sourceip != NULL &&
+ if (methods != NULL && methods->sourceip != NULL &&
(methods->version - methods->age <=
DNS_CLIENTINFOMETHODS_VERSION) &&
DNS_CLIENTINFOMETHODS_VERSION <= methods->version)
@@ -436,8 +452,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
found = true;
result = state->putrr(lookup, "TXT", 0, buf);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
}
if (strcmp(name, "too-long") == 0) {
@@ -446,8 +463,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
buf[i] = '\0';
found = true;
result = state->putrr(lookup, "TXT", 0, buf);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
}
for (i = 0; i < MAX_RECORDS; i++) {
@@ -456,18 +474,19 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
result = state->putrr(lookup, state->current[i].type,
state->current[i].ttl,
state->current[i].data);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
}
}
- if (!found)
+ if (!found) {
return (ISC_R_NOTFOUND);
+ }
return (ISC_R_SUCCESS);
}
-
/*
* See if a zone transfer is allowed
*/
@@ -489,8 +508,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
UNUSED(zone);
- if (state->putnamedrr == NULL)
+ if (state->putnamedrr == NULL) {
return (ISC_R_NOTIMPLEMENTED);
+ }
for (i = 0; i < MAX_RECORDS; i++) {
isc_result_t result;
@@ -501,14 +521,14 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
state->current[i].type,
state->current[i].ttl,
state->current[i].data);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
}
return (ISC_R_SUCCESS);
}
-
/*
* Start a transaction
*/
@@ -517,15 +537,17 @@ 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)
+ if (state->log != NULL) {
state->log(ISC_LOG_INFO,
"dlz_example: transaction already "
- "started for zone %s", zone);
+ "started for zone %s",
+ zone);
+ }
return (ISC_R_FAILURE);
}
state->transaction_started = true;
- *versionp = (void *) &state->transaction_started;
+ *versionp = (void *)&state->transaction_started;
return (ISC_R_SUCCESS);
}
@@ -534,15 +556,16 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) {
* End a transaction
*/
void
-dlz_closeversion(const char *zone, bool commit,
- void *dbdata, void **versionp)
-{
+dlz_closeversion(const char *zone, bool commit, 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 not "
- "started for zone %s", zone);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO,
+ "dlz_example: transaction not "
+ "started for zone %s",
+ zone);
+ }
*versionp = NULL;
return;
}
@@ -553,9 +576,12 @@ 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);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO,
+ "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],
@@ -575,15 +601,17 @@ 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);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO,
+ "dlz_example: cancelling "
+ "transaction on zone %s",
+ zone);
+ }
}
memset(state->adds, 0, sizeof(state->adds));
memset(state->deletes, 0, sizeof(state->deletes));
}
-
/*
* Configure a writeable zone
*/
@@ -592,27 +620,36 @@ 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)
+ if (state->log != NULL) {
state->log(ISC_LOG_INFO, "dlz_example: starting configure");
+ }
if (state->writeable_zone == NULL) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_INFO, "dlz_example: no "
- "writeable_zone method available");
+ "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);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_ERROR,
+ "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);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO,
+ "dlz_example: configured writeable "
+ "zone %s",
+ state->zone_name);
+ }
return (ISC_R_SUCCESS);
}
@@ -622,8 +659,7 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata) {
bool
dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr,
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;
UNUSED(tcpaddr);
@@ -633,32 +669,37 @@ 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);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO,
+ "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);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO,
+ "dlz_example: allowing update of "
+ "name=%s by %s",
+ name, signer);
+ }
return (true);
}
-
static isc_result_t
modrdataset(struct dlz_example_data *state, const char *name,
- const char *rdatastr, struct record *list)
-{
+ const char *rdatastr, struct record *list) {
char *full_name, *dclass, *type, *data, *ttlstr, *buf;
char absolute[1024];
isc_result_t result;
#if defined(WIN32) || defined(_REENTRANT)
char *saveptr = NULL;
-#endif
+#endif /* if defined(WIN32) || defined(_REENTRANT) */
buf = strdup(rdatastr);
- if (buf == NULL)
+ if (buf == NULL) {
return (ISC_R_FAILURE);
+ }
/*
* The format is:
@@ -669,85 +710,96 @@ modrdataset(struct dlz_example_data *state, const char *name,
*/
full_name = strtok_r(buf, "\t", &saveptr);
- if (full_name == NULL)
+ if (full_name == NULL) {
goto error;
+ }
ttlstr = strtok_r(NULL, "\t", &saveptr);
- if (ttlstr == NULL)
+ if (ttlstr == NULL) {
goto error;
+ }
dclass = strtok_r(NULL, "\t", &saveptr);
- if (dclass == NULL)
+ if (dclass == NULL) {
goto error;
+ }
type = strtok_r(NULL, "\t", &saveptr);
- if (type == NULL)
+ if (type == NULL) {
goto error;
+ }
data = strtok_r(NULL, "\t", &saveptr);
- if (data == NULL)
+ if (data == NULL) {
goto error;
+ }
if (name[strlen(name) - 1] != '.') {
snprintf(absolute, sizeof(absolute), "%s.", name);
name = absolute;
}
- result = add_name(state, list, name, type,
- strtoul(ttlstr, NULL, 10), data);
+ result = add_name(state, list, name, type, strtoul(ttlstr, NULL, 10),
+ data);
free(buf);
return (result);
- error:
+error:
free(buf);
return (ISC_R_FAILURE);
}
-
isc_result_t
-dlz_addrdataset(const char *name, const char *rdatastr,
- void *dbdata, void *version)
-{
+dlz_addrdataset(const char *name, const char *rdatastr, void *dbdata,
+ void *version) {
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
- if (version != (void *) &state->transaction_started)
+ if (version != (void *)&state->transaction_started) {
return (ISC_R_FAILURE);
+ }
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_INFO, "dlz_example: adding rdataset %s '%s'",
name, rdatastr);
+ }
return (modrdataset(state, name, rdatastr, &state->adds[0]));
}
isc_result_t
-dlz_subrdataset(const char *name, const char *rdatastr,
- void *dbdata, void *version)
-{
+dlz_subrdataset(const char *name, const char *rdatastr, void *dbdata,
+ void *version) {
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
- if (version != (void *) &state->transaction_started)
+ 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);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO,
+ "dlz_example: subtracting rdataset "
+ "%s '%s'",
+ name, rdatastr);
+ }
return (modrdataset(state, name, rdatastr, &state->deletes[0]));
}
isc_result_t
-dlz_delrdataset(const char *name, const char *type,
- void *dbdata, void *version)
-{
+dlz_delrdataset(const char *name, const char *type, void *dbdata,
+ void *version) {
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
- if (version != (void *) &state->transaction_started)
+ 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);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO,
+ "dlz_example: deleting rdataset %s "
+ "of type %s",
+ name, type);
+ }
return (ISC_R_SUCCESS);
}
diff --git a/contrib/dlz/example/named.conf b/contrib/dlz/example/named.conf
index bc68beeb..c10fb57f 100644
--- a/contrib/dlz/example/named.conf
+++ b/contrib/dlz/example/named.conf
@@ -29,7 +29,7 @@
*
* Additionally, a query for 'source-addr.example.nil/TXT' is always
* answered with the source address of the query. This is used to
- * demonstrate the code that retreives client information from the
+ * demonstrate the code that retrieves client information from the
* caller.
*
* To use this driver, "dlz_external.so" must be moved into the working
diff --git a/contrib/dlz/example/win32/DLLMain.c b/contrib/dlz/example/win32/DLLMain.c
index 445905f3..f21ad25e 100644
--- a/contrib/dlz/example/win32/DLLMain.c
+++ b/contrib/dlz/example/win32/DLLMain.c
@@ -1,47 +1,45 @@
/*
- * Copyright (C) 2001, 2004, 2007, 2016 Internet Systems Consortium, Inc. ("ISC")
- *
+ * Copyright (C) 2001, 2004, 2007, 2016 Internet Systems Consortium, Inc.
+ * ("ISC")
+ *
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-
-#include <windows.h>
#include <signal.h>
+#include <windows.h>
/*
* Called when we enter the DLL
*/
-__declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL,
- DWORD fdwReason, LPVOID lpvReserved)
-{
- switch (fdwReason) {
+__declspec(dllexport) BOOL WINAPI
+ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
+ switch (fdwReason) {
/*
- * The DLL is loading due to process
- * initialization or a call to LoadLibrary.
+ * The DLL is loading due to process
+ * initialization or a call to LoadLibrary.
*/
- case DLL_PROCESS_ATTACH:
- break;
-
+ case DLL_PROCESS_ATTACH:
+ break;
+
/* The attached process creates a new thread. */
- case DLL_THREAD_ATTACH:
- break;
-
+ case DLL_THREAD_ATTACH:
+ break;
+
/* The thread of the attached process terminates. */
- case DLL_THREAD_DETACH:
- break;
-
+ case DLL_THREAD_DETACH:
+ break;
+
/*
- * The DLL is unloading from a process due to
- * process termination or a call to FreeLibrary.
+ * The DLL is unloading from a process due to
+ * process termination or a call to FreeLibrary.
*/
- case DLL_PROCESS_DETACH:
- break;
+ case DLL_PROCESS_DETACH:
+ break;
- default:
- break;
- }
+ default:
+ break;
+ }
return (TRUE);
}
-
diff --git a/contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c b/contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c
index 43e54f97..bffd22b2 100644
--- a/contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c
+++ b/contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c
@@ -58,12 +58,11 @@
*
*/
+#include <db.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdarg.h>
-
-#include <db.h>
#include "dlz_minimal.h"
@@ -73,7 +72,7 @@
/* bdbhpt database names */
#define dlz_data "dns_data"
#define dlz_zone "dns_zone"
-#define dlz_xfr "dns_xfr"
+#define dlz_xfr "dns_xfr"
#define dlz_client "dns_client"
#define dlz_bdbhpt_dynamic_version "0.1"
@@ -84,11 +83,11 @@
*
*/
typedef struct bdbhpt_instance {
- DB_ENV *dbenv; /* bdbhpt environment */
- DB *data; /* dns_data database handle */
- DB *zone; /* zone database handle */
- DB *xfr; /* zone xfr database handle */
- DB *client; /* client database handle */
+ DB_ENV *dbenv; /* bdbhpt environment */
+ DB *data; /* dns_data database handle */
+ DB *zone; /* zone database handle */
+ DB *xfr; /* zone xfr database handle */
+ DB *client; /* client database handle */
/* Helper functions from the dlz_dlopen driver */
log_t *log;
@@ -110,18 +109,19 @@ b9_add_helper(struct bdbhpt_instance *db, const char *helper_name, void *ptr);
/*%
* Reverses a string in place.
*/
-static char
-*bdbhpt_strrev(char *str) {
+static char *
+bdbhpt_strrev(char *str) {
char *p1, *p2;
- if (! str || ! *str)
- return str;
+ if (!str || !*str) {
+ return (str);
+ }
for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) {
*p1 ^= *p2;
*p2 ^= *p1;
*p1 ^= *p2;
}
- return str;
+ return (str);
}
/*%
@@ -134,11 +134,10 @@ static char
static isc_result_t
bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) {
-
char *endp, *ttlStr;
char *tmp = in;
- char *lastchar = (char *) &tmp[strlen(tmp)];
-
+ char *lastchar = (char *)&tmp[strlen(tmp)];
+
/*%
* String should be formatted as:
* replication_id
@@ -157,20 +156,22 @@ bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) {
* server1_212 host 10 A 127.0.0.2
* {xxxx-xxxx-xxxx-xxxx-xxxx} host 10 MX 20 mail.example.com
*/
-
+
/*
* we don't need the replication id, so don't
* bother saving a pointer to it.
*/
-
+
/* find space after replication id */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
/* save pointer to host */
pd->host = tmp;
@@ -178,56 +179,61 @@ bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) {
/* find space after host and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
-
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
+
/* save pointer to ttl string */
ttlStr = tmp;
-
+
/* find space after ttl and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
-
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
+
/* save pointer to dns type */
pd->type = tmp;
-
+
/* find space after type and change it to a '\0' */
tmp = strchr(tmp, ' ');
/* verify we found a space */
- if (tmp == NULL)
- return ISC_R_FAILURE;
+ if (tmp == NULL) {
+ return (ISC_R_FAILURE);
+ }
/* change the space to a null (string terminator) */
tmp[0] = '\0';
/* make sure it is safe to increment pointer */
- if (++tmp > lastchar)
- return ISC_R_FAILURE;
-
+ if (++tmp > lastchar) {
+ return (ISC_R_FAILURE);
+ }
+
/* save pointer to remainder of DNS data */
pd->data = tmp;
-
+
/* convert ttl string to integer */
pd->ttl = strtol(ttlStr, &endp, 10);
if (*endp != '\0' || pd->ttl < 0) {
- log(ISC_LOG_ERROR,
- "bdbhpt_dynamic: "
- "ttl must be a positive number");
- return ISC_R_FAILURE;
+ log(ISC_LOG_ERROR, "bdbhpt_dynamic: "
+ "ttl must be a positive number");
+ return (ISC_R_FAILURE);
}
-
+
/* if we get this far everything should have worked. */
- return ISC_R_SUCCESS;
+ return (ISC_R_SUCCESS);
}
/*
@@ -236,18 +242,19 @@ bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) {
isc_result_t
dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
isc_result_t result;
- bdbhpt_instance_t *db = (bdbhpt_instance_t *) dbdata;
+ bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata;
DBT key, data;
-
+
/* check to see if we are authoritative for the zone first. */
#if DLZ_DLOPEN_VERSION >= 3
result = dlz_findzonedb(dbdata, name, NULL, NULL);
-#else
+#else /* if DLZ_DLOPEN_VERSION >= 3 */
result = dlz_findzonedb(dbdata, name);
-#endif
- if (result != ISC_R_SUCCESS)
+#endif /* if DLZ_DLOPEN_VERSION >= 3 */
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
-
+ }
+
memset(&key, 0, sizeof(DBT));
key.flags = DB_DBT_MALLOC;
key.data = strdup(name);
@@ -256,7 +263,7 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
goto xfr_cleanup;
}
key.size = strlen(key.data);
-
+
memset(&data, 0, sizeof(DBT));
data.flags = DB_DBT_MALLOC;
data.data = strdup(client);
@@ -265,8 +272,8 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
goto xfr_cleanup;
}
data.size = strlen(data.data);
-
- switch(db->client->get(db->client, NULL, &key, &data, DB_GET_BOTH)) {
+
+ switch (db->client->get(db->client, NULL, &key, &data, DB_GET_BOTH)) {
case DB_NOTFOUND:
result = ISC_R_NOTFOUND;
break;
@@ -277,16 +284,18 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
result = ISC_R_FAILURE;
}
- xfr_cleanup:
+xfr_cleanup:
/* free any memory duplicate string in the key field */
- if (key.data != NULL)
+ if (key.data != NULL) {
free(key.data);
-
+ }
+
/* free any memory allocated to the data field. */
- if (data.data != NULL)
+ if (data.data != NULL) {
free(data.data);
-
- return result;
+ }
+
+ return (result);
}
/*%
@@ -319,7 +328,7 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
isc_result_t
dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
isc_result_t result = ISC_R_NOTFOUND;
- bdbhpt_instance_t *db = (bdbhpt_instance_t *) dbdata;
+ bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata;
DBC *xfr_cursor = NULL;
DBC *dns_cursor = NULL;
DBT xfr_key, xfr_data, dns_key, dns_data;
@@ -328,46 +337,48 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
int bdbhptres;
bdbhpt_parsed_data_t pd;
char *tmp = NULL, *tmp_zone, *tmp_zone_host = NULL;
-
+
memset(&xfr_key, 0, sizeof(DBT));
memset(&xfr_data, 0, sizeof(DBT));
memset(&dns_key, 0, sizeof(DBT));
memset(&dns_data, 0, sizeof(DBT));
-
+
xfr_key.data = tmp_zone = strdup(zone);
- if (xfr_key.data == NULL)
+ if (xfr_key.data == NULL) {
return (ISC_R_NOMEMORY);
-
+ }
+
xfr_key.size = strlen(xfr_key.data);
-
+
/* get a cursor to loop through dns_xfr table */
if (db->xfr->cursor(db->xfr, NULL, &xfr_cursor, 0) != 0) {
result = ISC_R_FAILURE;
goto allnodes_cleanup;
}
-
+
/* get a cursor to loop through dns_data table */
if (db->data->cursor(db->data, NULL, &dns_cursor, 0) != 0) {
result = ISC_R_FAILURE;
goto allnodes_cleanup;
}
-
+
xfr_flags = DB_SET;
-
+
/* loop through xfr table for specified zone. */
- while ((bdbhptres = xfr_cursor->c_get(xfr_cursor, &xfr_key,
- &xfr_data, xfr_flags)) == 0)
+ while ((bdbhptres = xfr_cursor->c_get(xfr_cursor, &xfr_key, &xfr_data,
+ xfr_flags)) == 0)
{
xfr_flags = DB_NEXT_DUP;
-
+
/* +1 to allow for space between zone and host names */
dns_key.size = xfr_data.size + xfr_key.size + 1;
-
+
/* +1 to allow for null term at end of string. */
dns_key.data = tmp_zone_host = malloc(dns_key.size + 1);
- if (dns_key.data == NULL)
+ if (dns_key.data == NULL) {
goto allnodes_cleanup;
-
+ }
+
/*
* construct search key for dns_data.
* zone_name(a space)host_name
@@ -375,62 +386,68 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
strcpy(dns_key.data, zone);
strcat(dns_key.data, " ");
strncat(dns_key.data, xfr_data.data, xfr_data.size);
-
+
dns_flags = DB_SET;
-
- while ((bdbhptres = dns_cursor->c_get(dns_cursor,
- &dns_key,
- &dns_data,
- dns_flags)) == 0)
+
+ while ((bdbhptres = dns_cursor->c_get(dns_cursor, &dns_key,
+ &dns_data, dns_flags)) ==
+ 0)
{
dns_flags = DB_NEXT_DUP;
-
+
/* +1 to allow for null term at end of string. */
tmp = realloc(tmp, dns_data.size + 1);
- if (tmp == NULL)
+ if (tmp == NULL) {
goto allnodes_cleanup;
-
+ }
+
/* copy data to tmp string, and append null term. */
strncpy(tmp, dns_data.data, dns_data.size);
tmp[dns_data.size] = '\0';
-
+
/* split string into dns data parts. */
- if (bdbhpt_parse_data(db->log,
- tmp, &pd) != ISC_R_SUCCESS)
+ if (bdbhpt_parse_data(db->log, tmp, &pd) !=
+ ISC_R_SUCCESS) {
goto allnodes_cleanup;
- result = db->putnamedrr(allnodes, pd.host,
- pd.type, pd.ttl, pd.data);
- if (result != ISC_R_SUCCESS)
+ }
+ result = db->putnamedrr(allnodes, pd.host, pd.type,
+ pd.ttl, pd.data);
+ if (result != ISC_R_SUCCESS) {
goto allnodes_cleanup;
-
- } /* end inner while loop */
-
+ }
+ } /* end inner while loop */
+
/* clean up memory */
if (tmp_zone_host != NULL) {
free(tmp_zone_host);
tmp_zone_host = NULL;
}
} /* end outer while loop */
-
- allnodes_cleanup:
+
+allnodes_cleanup:
/* free any memory */
- if (tmp != NULL)
+ if (tmp != NULL) {
free(tmp);
-
- if (tmp_zone_host != NULL)
+ }
+
+ if (tmp_zone_host != NULL) {
free(tmp_zone_host);
-
- if (tmp_zone != NULL)
+ }
+
+ if (tmp_zone != NULL) {
free(tmp_zone);
-
+ }
+
/* get rid of cursors */
- if (xfr_cursor != NULL)
+ if (xfr_cursor != NULL) {
xfr_cursor->c_close(xfr_cursor);
-
- if (dns_cursor != NULL)
+ }
+
+ if (dns_cursor != NULL) {
dns_cursor->c_close(dns_cursor);
-
- return result;
+ }
+
+ return (result);
}
/*%
@@ -441,18 +458,23 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
static void
bdbhpt_cleanup(bdbhpt_instance_t *db) {
/* close databases */
- if (db->data != NULL)
+ if (db->data != NULL) {
db->data->close(db->data, 0);
- if (db->xfr != NULL)
+ }
+ if (db->xfr != NULL) {
db->xfr->close(db->xfr, 0);
- if (db->zone != NULL)
+ }
+ if (db->zone != NULL) {
db->zone->close(db->zone, 0);
- if (db->client != NULL)
+ }
+ if (db->client != NULL) {
db->client->close(db->client, 0);
-
+ }
+
/* close environment */
- if (db->dbenv != NULL)
+ if (db->dbenv != NULL) {
db->dbenv->close(db->dbenv, 0);
+ }
}
/*
@@ -461,17 +483,16 @@ bdbhpt_cleanup(bdbhpt_instance_t *db) {
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_findzonedb(void *dbdata, const char *name)
-#else
+#else /* if DLZ_DLOPEN_VERSION < 3 */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-#endif
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo)
+#endif /* if DLZ_DLOPEN_VERSION < 3 */
{
isc_result_t result;
- bdbhpt_instance_t *db = (bdbhpt_instance_t *) dbdata;
+ bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata;
DBT key, data;
-
+
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
data.flags = DB_DBT_MALLOC;
@@ -479,22 +500,23 @@ dlz_findzonedb(void *dbdata, const char *name,
#if DLZ_DLOPEN_VERSION >= 3
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 3 */
key.data = strdup(name);
- if (key.data == NULL)
+ if (key.data == NULL) {
return (ISC_R_NOMEMORY);
+ }
/*
* reverse string to take advantage of BDB locality of reference
- * if we need futher lookups because the zone doesn't match the
+ * if we need further lookups because the zone doesn't match the
* first time.
*/
key.data = bdbhpt_strrev(key.data);
key.size = strlen(key.data);
- switch(db->zone->get(db->zone, NULL, &key, &data, 0)) {
+ switch (db->zone->get(db->zone, NULL, &key, &data, 0)) {
case DB_NOTFOUND:
result = ISC_R_NOTFOUND;
break;
@@ -504,16 +526,18 @@ dlz_findzonedb(void *dbdata, const char *name,
default:
result = ISC_R_FAILURE;
}
-
+
/* free any memory duplicate string in the key field */
- if (key.data != NULL)
+ if (key.data != NULL) {
free(key.data);
-
+ }
+
/* free any memory allocated to the data field. */
- if (data.data != NULL)
+ if (data.data != NULL) {
free(data.data);
-
- return result;
+ }
+
+ return (result);
}
/*
@@ -521,17 +545,18 @@ dlz_findzonedb(void *dbdata, const char *name,
*
*/
#if DLZ_DLOPEN_VERSION == 1
-isc_result_t dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup)
-#else
-isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata,
- dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-#endif
+isc_result_t
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup)
+#else /* if DLZ_DLOPEN_VERSION == 1 */
+isc_result_t
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo)
+#endif /* if DLZ_DLOPEN_VERSION == 1 */
{
isc_result_t result = ISC_R_NOTFOUND;
- bdbhpt_instance_t *db = (bdbhpt_instance_t *) dbdata;
+ bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata;
DBC *data_cursor = NULL;
DBT key, data;
int bdbhptres;
@@ -540,27 +565,28 @@ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata,
bdbhpt_parsed_data_t pd;
char *tmp = NULL;
char *keyStr = NULL;
-
+
#if DLZ_DLOPEN_VERSION >= 2
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 2 */
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
-
+
key.size = strlen(zone) + strlen(name) + 1;
/* allocate mem for key */
key.data = keyStr = malloc((key.size + 1) * sizeof(char));
-
- if (keyStr == NULL)
- return ISC_R_NOMEMORY;
-
+
+ if (keyStr == NULL) {
+ return (ISC_R_NOMEMORY);
+ }
+
strcpy(keyStr, zone);
strcat(keyStr, " ");
strcat(keyStr, name);
-
+
/* get a cursor to loop through data */
if (db->data->cursor(db->data, NULL, &data_cursor, 0) != 0) {
result = ISC_R_FAILURE;
@@ -571,35 +597,38 @@ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata,
flags = DB_SET;
while ((bdbhptres = data_cursor->c_get(data_cursor, &key, &data,
- flags)) == 0)
- {
+ flags)) == 0) {
flags = DB_NEXT_DUP;
tmp = realloc(tmp, data.size + 1);
- if (tmp == NULL)
+ if (tmp == NULL) {
goto lookup_cleanup;
-
+ }
+
strncpy(tmp, data.data, data.size);
tmp[data.size] = '\0';
-
- if (bdbhpt_parse_data(db->log, tmp, &pd) != ISC_R_SUCCESS)
+
+ if (bdbhpt_parse_data(db->log, tmp, &pd) != ISC_R_SUCCESS) {
goto lookup_cleanup;
-
+ }
+
result = db->putrr(lookup, pd.type, pd.ttl, pd.data);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto lookup_cleanup;
+ }
} /* end while loop */
-
- lookup_cleanup:
+
+lookup_cleanup:
/* get rid of cursor */
- if (data_cursor != NULL)
+ if (data_cursor != NULL) {
data_cursor->c_close(data_cursor);
-
- if (keyStr != NULL)
- free(keyStr);
- if (tmp != NULL)
+ }
+
+ free(keyStr);
+ if (tmp != NULL) {
free(tmp);
-
- return result;
+ }
+
+ return (result);
}
/*%
@@ -607,8 +636,7 @@ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata,
*/
static isc_result_t
bdbhpt_opendb(log_t *log, DB_ENV *db_env, DBTYPE db_type, DB **db,
- const char *db_name, char *db_file, int flags)
-{
+ const char *db_name, char *db_file, int flags) {
int result;
/* Initialise the database. */
@@ -617,7 +645,7 @@ bdbhpt_opendb(log_t *log, DB_ENV *db_env, DBTYPE db_type, DB **db,
"bdbhpt_dynamic: could not initialize %s database. "
"BerkeleyDB error: %s",
db_name, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* set database flags. */
@@ -626,35 +654,34 @@ bdbhpt_opendb(log_t *log, DB_ENV *db_env, DBTYPE db_type, DB **db,
"bdbhpt_dynamic: could not set flags for %s database. "
"BerkeleyDB error: %s",
db_name, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
/* open the database. */
if ((result = (*db)->open(*db, NULL, db_file, db_name, db_type,
- DB_RDONLY | bdbhpt_threads, 0)) != 0) {
+ DB_RDONLY | bdbhpt_threads, 0)) != 0)
+ {
log(ISC_LOG_ERROR,
"bdbhpt_dynamic: could not open %s database in %s. "
"BerkeleyDB error: %s",
db_name, db_file, db_strerror(result));
- return ISC_R_FAILURE;
+ return (ISC_R_FAILURE);
}
-
- return ISC_R_SUCCESS;
-}
+ return (ISC_R_SUCCESS);
+}
/*
* Called to initialize the driver
*/
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
isc_result_t result;
int bdbhptres;
int bdbFlags = 0;
bdbhpt_instance_t *db = NULL;
-
+
const char *helper_name;
va_list ap;
@@ -662,64 +689,66 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* Allocate memory for our db structures and helper functions */
db = calloc(1, sizeof(struct bdbhpt_instance));
- if (db == NULL)
+ if (db == NULL) {
return (ISC_R_NOMEMORY);
+ }
/* Fill in the helper functions */
va_start(ap, dbdata);
- while ((helper_name = va_arg(ap, const char *)) != NULL)
- b9_add_helper(db, helper_name, va_arg(ap, void*));
+ while ((helper_name = va_arg(ap, const char *)) != NULL) {
+ b9_add_helper(db, helper_name, va_arg(ap, void *));
+ }
va_end(ap);
/* verify we have 4 arg's passed to the driver */
if (argc != 4) {
db->log(ISC_LOG_ERROR,
"bdbhpt_dynamic: please supply 3 command line args. "
- "You supplied: %s", argc);
+ "You supplied: %s",
+ argc);
return (ISC_R_FAILURE);
}
- switch((char) *argv[1]) {
- /*
- * Transactional mode. Highest safety - lowest speed.
- */
+ switch ((char)*argv[1]) {
+ /*
+ * Transactional mode. Highest safety - lowest speed.
+ */
case 'T':
case 't':
- bdbFlags = DB_INIT_MPOOL | DB_INIT_LOCK |
- DB_INIT_LOG | DB_INIT_TXN;
- db->log(ISC_LOG_INFO,
- "bdbhpt_dynamic: using transactional mode.");
+ bdbFlags = DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_LOG |
+ DB_INIT_TXN;
+ db->log(ISC_LOG_INFO, "bdbhpt_dynamic: using transactional "
+ "mode.");
break;
- /*
- * Concurrent mode. Lower safety (no rollback) -
- * higher speed.
- */
+ /*
+ * Concurrent mode. Lower safety (no rollback) -
+ * higher speed.
+ */
case 'C':
case 'c':
bdbFlags = DB_INIT_CDB | DB_INIT_MPOOL;
- db->log(ISC_LOG_INFO,
- "bdbhpt_dynamic: using concurrent mode.");
+ db->log(ISC_LOG_INFO, "bdbhpt_dynamic: using concurrent mode.");
break;
- /*
- * Private mode. No inter-process communication & no locking.
- * Lowest saftey - highest speed.
- */
+ /*
+ * Private mode. No inter-process communication & no locking.
+ * Lowest safety - highest speed.
+ */
case 'P':
case 'p':
bdbFlags = DB_PRIVATE | DB_INIT_MPOOL;
- db->log(ISC_LOG_INFO,
- "bdbhpt_dynamic: using private mode.");
+ db->log(ISC_LOG_INFO, "bdbhpt_dynamic: using private mode.");
break;
default:
db->log(ISC_LOG_ERROR,
"bdbhpt_dynamic: "
"operating mode must be set to P or C or T. "
- "You specified '%s'", argv[1]);
+ "You specified '%s'",
+ argv[1]);
return (ISC_R_FAILURE);
}
-
+
/*
* create bdbhpt environment
* Basically bdbhpt allocates and assigns memory to db->dbenv
@@ -728,11 +757,12 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
if (bdbhptres != 0) {
db->log(ISC_LOG_ERROR,
"bdbhpt_dynamic: db environment could not be created. "
- "BerkeleyDB error: %s", db_strerror(bdbhptres));
+ "BerkeleyDB error: %s",
+ db_strerror(bdbhptres));
result = ISC_R_FAILURE;
goto init_cleanup;
}
-
+
/* open bdbhpt environment */
bdbhptres = db->dbenv->open(db->dbenv, argv[2],
bdbFlags | bdbhpt_threads | DB_CREATE, 0);
@@ -749,37 +779,40 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* open dlz_data database. */
result = bdbhpt_opendb(db->log, db->dbenv, DB_UNKNOWN, &db->data,
dlz_data, argv[3], DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
+ }
/* open dlz_xfr database. */
result = bdbhpt_opendb(db->log, db->dbenv, DB_UNKNOWN, &db->xfr,
dlz_xfr, argv[3], DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
-
+ }
+
/* open dlz_zone database. */
result = bdbhpt_opendb(db->log, db->dbenv, DB_UNKNOWN, &db->zone,
dlz_zone, argv[3], 0);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
-
+ }
+
/* open dlz_client database. */
result = bdbhpt_opendb(db->log, db->dbenv, DB_UNKNOWN, &db->client,
dlz_client, argv[3], DB_DUP | DB_DUPSORT);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto init_cleanup;
-
+ }
+
*dbdata = db;
- db->log(ISC_LOG_INFO,
- "bdbhpt_dynamic: version %s, started",
+ db->log(ISC_LOG_INFO, "bdbhpt_dynamic: version %s, started",
dlz_bdbhpt_dynamic_version);
- return(ISC_R_SUCCESS);
-
- init_cleanup:
+ return (ISC_R_SUCCESS);
+
+init_cleanup:
bdbhpt_cleanup(db);
- return result;
+ return (result);
}
/*
@@ -788,11 +821,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
void
dlz_destroy(void *dbdata) {
struct bdbhpt_instance *db = (struct bdbhpt_instance *)dbdata;
-
- db->log(ISC_LOG_INFO,
- "dlz_bdbhpt_dynamic (%s): shutting down",
+
+ db->log(ISC_LOG_INFO, "dlz_bdbhpt_dynamic (%s): shutting down",
dlz_bdbhpt_dynamic_version);
- bdbhpt_cleanup((bdbhpt_instance_t *) dbdata);
+ bdbhpt_cleanup((bdbhpt_instance_t *)dbdata);
free(db);
}
@@ -810,13 +842,16 @@ dlz_version(unsigned int *flags) {
*/
static void
b9_add_helper(struct bdbhpt_instance *db, const char *helper_name, void *ptr) {
- if (strcmp(helper_name, "log") == 0)
+ if (strcmp(helper_name, "log") == 0) {
db->log = (log_t *)ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
db->putrr = (dns_sdlz_putrr_t *)ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
db->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
db->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
+ }
}
-
diff --git a/contrib/dlz/modules/bdbhpt/testing/bdbhpt-populate.pl b/contrib/dlz/modules/bdbhpt/testing/bdbhpt-populate.pl
index 909976a2..ec210c31 100755
--- a/contrib/dlz/modules/bdbhpt/testing/bdbhpt-populate.pl
+++ b/contrib/dlz/modules/bdbhpt/testing/bdbhpt-populate.pl
@@ -28,7 +28,7 @@ if (!defined $input_file || $input_file eq '') {
my $zone_list = $opt->{zones};
if (!defined $zone_list || $zone_list eq '') {
- usage('Please specify a space seperated list of zones');
+ usage('Please specify a space separated list of zones');
exit 1;
}
@@ -128,7 +128,7 @@ sub usage {
print STDERR "usage: $0 --bdb=<bdb-file> --input=<input-file> --zones=<zone-list>\n\n";
print STDERR "\tbdb-file: The output BerkeleyDB file you wish to create and use with bdbhpt-dynamic\n\n";
print STDERR "\tinput-file: The input text-file containing records to populate within your zones\n\n";
- print STDERR "\tzone-list: The space-seperated list of zones you wish to create\n\n";
+ print STDERR "\tzone-list: The space-separated list of zones you wish to create\n\n";
}
sub populate_records {
diff --git a/contrib/dlz/modules/common/dlz_dbi.c b/contrib/dlz/modules/common/dlz_dbi.c
index 566e10b2..c31ade45 100644
--- a/contrib/dlz/modules/common/dlz_dbi.c
+++ b/contrib/dlz/modules/common/dlz_dbi.c
@@ -34,25 +34,25 @@
*/
/*
- * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
- *
+ * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc.
+ * ("ISC")
+ *
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <ctype.h>
+#include <errno.h>
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
#include <stdlib.h>
-#include <ctype.h>
-
-#include <sys/errno.h>
+#include <string.h>
-#include <dlz_minimal.h>
-#include <dlz_list.h>
#include <dlz_dbi.h>
+#include <dlz_list.h>
+#include <dlz_minimal.h>
#include <dlz_pthread.h>
/*%
@@ -66,20 +66,22 @@ destroy_querylist(query_list_t **querylist) {
query_segment_t *nseg = NULL;
/* if query list is null, nothing to do */
- if (*querylist == NULL)
+ if (*querylist == NULL) {
return;
+ }
/* start at the top of the list */
nseg = DLZ_LIST_HEAD(**querylist);
- while (nseg != NULL) { /* loop, until end of list */
+ while (nseg != NULL) { /* loop, until end of list */
tseg = nseg;
/*
* free the query segment's text string but only if it
* was really a query segment, and not a pointer to
* %zone%, or %record%, or %client%
- */
- if (tseg->cmd != NULL && tseg->direct == true)
+ */
+ if (tseg->cmd != NULL && tseg->direct) {
free(tseg->cmd);
+ }
/* get the next query segment, before we destroy this one. */
nseg = DLZ_LIST_NEXT(nseg, link);
/* deallocate this query segment. */
@@ -92,9 +94,8 @@ destroy_querylist(query_list_t **querylist) {
/*% constructs a query list by parsing a string into query segments */
isc_result_t
build_querylist(const char *query_str, char **zone, char **record,
- char **client, query_list_t **querylist, unsigned int flags,
- log_t log)
-{
+ char **client, query_list_t **querylist, unsigned int flags,
+ log_t log) {
isc_result_t result;
bool foundzone = false;
bool foundrecord = false;
@@ -107,19 +108,21 @@ build_querylist(const char *query_str, char **zone, char **record,
/* if query string is null, or zero length */
if (query_str == NULL || strlen(query_str) < 1) {
- if ((flags & REQUIRE_QUERY) == 0)
+ if ((flags & REQUIRE_QUERY) == 0) {
/* we don't need it were ok. */
return (ISC_R_SUCCESS);
- else
+ } else {
/* we did need it, PROBLEM!!! */
return (ISC_R_FAILURE);
+ }
}
/* allocate memory for query list */
tql = calloc(1, sizeof(query_list_t));
/* couldn't allocate memory. Problem!! */
- if (tql == NULL)
+ if (tql == NULL) {
return (ISC_R_NOMEMORY);
+ }
/* initialize the query segment list */
DLZ_LIST_INIT(*tql);
@@ -133,13 +136,12 @@ build_querylist(const char *query_str, char **zone, char **record,
}
/* loop through the string and chop it up */
- for (token = strtok_r(right_str, "$", &temp_str);
- token;
+ for (token = strtok_r(right_str, "$", &temp_str); token;
token = strtok_r(NULL, "$", &temp_str))
{
/* allocate memory for tseg */
tseg = calloc(1, sizeof(query_segment_t));
- if (tseg == NULL) { /* no memory, clean everything up. */
+ if (tseg == NULL) { /* no memory, clean everything up. */
result = ISC_R_NOMEMORY;
goto cleanup;
}
@@ -171,7 +173,7 @@ build_querylist(const char *query_str, char **zone, char **record,
*/
free(tseg->cmd);
/* set tseg->cmd to in-direct zone string */
- tseg->cmd = (char**) zone;
+ tseg->cmd = (char **)zone;
tseg->strlen = 0;
/* tseg->cmd points in-directly to a string */
tseg->direct = false;
@@ -184,7 +186,7 @@ build_querylist(const char *query_str, char **zone, char **record,
*/
free(tseg->cmd);
/* set tseg->cmd to in-direct record string */
- tseg->cmd = (char**) record;
+ tseg->cmd = (char **)record;
tseg->strlen = 0;
/* tseg->cmd points in-directly poinsts to a string */
tseg->direct = false;
@@ -197,7 +199,7 @@ build_querylist(const char *query_str, char **zone, char **record,
*/
free(tseg->cmd);
/* set tseg->cmd to in-direct record string */
- tseg->cmd = (char**) client;
+ tseg->cmd = (char **)client;
tseg->strlen = 0;
/* tseg->cmd points in-directly poinsts to a string */
tseg->direct = false;
@@ -214,50 +216,52 @@ build_querylist(const char *query_str, char **zone, char **record,
*/
/* if this query requires %client%, make sure we found it */
- if (((flags & REQUIRE_CLIENT) != 0) && (!foundclient) ) {
+ if (((flags & REQUIRE_CLIENT) != 0) && (!foundclient)) {
/* Write error message to log */
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Required token $client$ not found.");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Required token $client$ not "
+ "found.");
+ }
result = ISC_R_FAILURE;
goto flag_fail;
}
/* if this query requires %record%, make sure we found it */
- if (((flags & REQUIRE_RECORD) != 0) && (!foundrecord) ) {
+ if (((flags & REQUIRE_RECORD) != 0) && (!foundrecord)) {
/* Write error message to log */
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Required token $record$ not found.");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Required token $record$ not "
+ "found.");
+ }
result = ISC_R_FAILURE;
goto flag_fail;
}
/* if this query requires %zone%, make sure we found it */
- if (((flags & REQUIRE_ZONE) != 0) && (!foundzone) ) {
+ if (((flags & REQUIRE_ZONE) != 0) && (!foundzone)) {
/* Write error message to log */
- if (log != NULL)
+ if (log != NULL) {
log(ISC_LOG_ERROR, "Required token $zone$ not found.");
+ }
result = ISC_R_FAILURE;
goto flag_fail;
}
/* pass back the query list */
- *querylist = (query_list_t *) tql;
+ *querylist = (query_list_t *)tql;
/* return success */
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
/* get rid of temp_str */
if (right_str != NULL) {
free(right_str);
}
- flag_fail:
+flag_fail:
/* get rid of what was build of the query list */
- if (tql != NULL)
- destroy_querylist(&tql);
+ destroy_querylist(&tql);
return (result);
}
@@ -279,28 +283,31 @@ build_querystring(query_list_t *querylist) {
* if this is a query segment, use the
* precalculated string length
*/
- if (tseg->direct == true)
+ if (tseg->direct) {
length += tseg->strlen;
- else /* calculate string length for dynamic segments. */
- length += strlen(* (char**) tseg->cmd);
+ } else { /* calculate string length for dynamic segments. */
+ length += strlen(*(char **)tseg->cmd);
+ }
/* get the next segment */
tseg = DLZ_LIST_NEXT(tseg, link);
}
qs = malloc(length + 1);
- if (qs == NULL)
+ if (qs == NULL) {
return (NULL);
+ }
*qs = '\0';
/* start at the top of the list again */
tseg = DLZ_LIST_HEAD(*querylist);
while (tseg != NULL) {
- if (tseg->direct == true)
+ if (tseg->direct) {
/* query segments */
strcat(qs, tseg->cmd);
- else
+ } else {
/* dynamic segments */
- strcat(qs, * (char**) tseg->cmd);
+ strcat(qs, *(char **)tseg->cmd);
+ }
/* get the next segment */
tseg = DLZ_LIST_NEXT(tseg, link);
}
@@ -313,9 +320,7 @@ isc_result_t
build_dbinstance(const char *allnodes_str, const char *allowxfr_str,
const char *authority_str, const char *findzone_str,
const char *lookup_str, const char *countzone_str,
- dbinstance_t **dbi, log_t log)
-{
-
+ dbinstance_t **dbi, log_t log) {
isc_result_t result;
dbinstance_t *db = NULL;
int err;
@@ -323,10 +328,10 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str,
/* allocate and zero memory for driver structure */
db = calloc(1, sizeof(dbinstance_t));
if (db == NULL) {
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Could not allocate memory for "
- "database instance object.");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Could not allocate memory for "
+ "database instance object.");
+ }
return (ISC_R_NOMEMORY);
}
memset(db, 0, sizeof(dbinstance_t));
@@ -354,84 +359,88 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str,
/* build the all nodes query list */
result = build_querylist(allnodes_str, &db->zone, &db->record,
- &db->client, &db->allnodes_q,
- REQUIRE_ZONE, log);
+ &db->client, &db->allnodes_q, REQUIRE_ZONE,
+ log);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Could not build all nodes query list");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Could not build all nodes query "
+ "list");
+ }
goto cleanup;
}
/* build the allow zone transfer query list */
result = build_querylist(allowxfr_str, &db->zone, &db->record,
&db->client, &db->allowxfr_q,
- REQUIRE_ZONE | REQUIRE_CLIENT,
- log);
+ REQUIRE_ZONE | REQUIRE_CLIENT, log);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Could not build allow xfr query list");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Could not build allow xfr query "
+ "list");
+ }
goto cleanup;
}
/* build the authority query, query list */
result = build_querylist(authority_str, &db->zone, &db->record,
- &db->client, &db->authority_q,
- REQUIRE_ZONE, log);
+ &db->client, &db->authority_q, REQUIRE_ZONE,
+ log);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Could not build authority query list");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Could not build authority query "
+ "list");
+ }
goto cleanup;
}
/* build findzone query, query list */
result = build_querylist(findzone_str, &db->zone, &db->record,
- &db->client, &db->findzone_q,
- REQUIRE_ZONE, log);
+ &db->client, &db->findzone_q, REQUIRE_ZONE,
+ log);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Could not build find zone query list");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Could not build find zone query "
+ "list");
+ }
goto cleanup;
}
/* build countzone query, query list */
result = build_querylist(countzone_str, &db->zone, &db->record,
- &db->client, &db->countzone_q,
- REQUIRE_ZONE, log);
+ &db->client, &db->countzone_q, REQUIRE_ZONE,
+ log);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Could not build count zone query list");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Could not build count zone query "
+ "list");
+ }
goto cleanup;
}
/* build lookup query, query list */
result = build_querylist(lookup_str, &db->zone, &db->record,
- &db->client, &db->lookup_q,
- REQUIRE_RECORD, log);
+ &db->client, &db->lookup_q, REQUIRE_RECORD,
+ log);
/* if unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
- if (log != NULL)
- log(ISC_LOG_ERROR,
- "Could not build lookup query list");
+ if (log != NULL) {
+ log(ISC_LOG_ERROR, "Could not build lookup query list");
+ }
goto cleanup;
}
/* pass back the db instance */
- *dbi = (dbinstance_t *) db;
+ *dbi = (dbinstance_t *)db;
/* return success */
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
/* destroy whatever was build of the db instance */
destroy_dbinstance(db);
/* return failure */
@@ -449,31 +458,34 @@ destroy_dbinstance(dbinstance_t *dbi) {
destroy_querylist(&dbi->lookup_q);
/* get rid of the mutex */
- (void) dlz_mutex_destroy(&dbi->lock);
+ (void)dlz_mutex_destroy(&dbi->lock);
/* return, and detach the memory */
free(dbi);
}
char *
-get_parameter_value(const char *input, const char* key) {
+get_parameter_value(const char *input, const char *key) {
int keylen;
char *keystart;
char value[255];
int i;
- if (key == NULL || input == NULL || *input == '\0')
+ if (key == NULL || input == NULL || *input == '\0') {
return (NULL);
+ }
keylen = strlen(key);
- if (keylen < 1)
+ if (keylen < 1) {
return (NULL);
+ }
keystart = strstr(input, key);
- if (keystart == NULL)
+ if (keystart == NULL) {
return (NULL);
+ }
for (i = 0; i < 255; i++) {
value[i] = keystart[keylen + i];
diff --git a/contrib/dlz/modules/filesystem/dir.c b/contrib/dlz/modules/filesystem/dir.c
index 5d0a200c..cc06b3bc 100644
--- a/contrib/dlz/modules/filesystem/dir.c
+++ b/contrib/dlz/modules/filesystem/dir.c
@@ -14,16 +14,15 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-
+#include "dir.h"
#include <ctype.h>
#include <errno.h>
-#include <unistd.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
#include "dlz_minimal.h"
-#include "dir.h"
void
dir_init(dir_t *dir) {
@@ -38,13 +37,15 @@ dir_open(dir_t *dir, const char *dirname) {
char *p;
isc_result_t result = ISC_R_SUCCESS;
- if (strlen(dirname) + 3 > sizeof(dir->dirname))
+ if (strlen(dirname) + 3 > sizeof(dir->dirname)) {
return (ISC_R_NOSPACE);
+ }
strcpy(dir->dirname, dirname);
p = dir->dirname + strlen(dir->dirname);
- if (dir->dirname < p && *(p - 1) != '/')
+ if (dir->dirname < p && *(p - 1) != '/') {
*p++ = '/';
+ }
*p++ = '*';
*p = '\0';
@@ -79,7 +80,7 @@ dir_open(dir_t *dir, const char *dirname) {
/*!
* \brief Return previously retrieved file or get next one.
-
+ *
* Unix's dirent has
* separate open and read functions, but the Win32 and DOS interfaces open
* the dir stream and reads the first file in one operation.
@@ -89,11 +90,13 @@ dir_read(dir_t *dir) {
struct dirent *entry;
entry = readdir(dir->handle);
- if (entry == NULL)
+ if (entry == NULL) {
return (ISC_R_NOMORE);
+ }
- if (sizeof(dir->entry.name) <= strlen(entry->d_name))
- return (ISC_R_UNEXPECTED);
+ if (sizeof(dir->entry.name) <= strlen(entry->d_name)) {
+ return (ISC_R_UNEXPECTED);
+ }
strcpy(dir->entry.name, entry->d_name);
@@ -106,8 +109,8 @@ dir_read(dir_t *dir) {
*/
void
dir_close(dir_t *dir) {
- (void)closedir(dir->handle);
- dir->handle = NULL;
+ (void)closedir(dir->handle);
+ dir->handle = NULL;
}
/*!
diff --git a/contrib/dlz/modules/filesystem/dir.h b/contrib/dlz/modules/filesystem/dir.h
index 66041fac..c8be683b 100644
--- a/contrib/dlz/modules/filesystem/dir.h
+++ b/contrib/dlz/modules/filesystem/dir.h
@@ -14,21 +14,23 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
#include <dirent.h>
+#include <sys/types.h>
+
+#include <dlz_minimal.h>
#define DIR_NAMEMAX 256
#define DIR_PATHMAX 1024
typedef struct direntry {
- char name[DIR_NAMEMAX];
- unsigned int length;
+ char name[DIR_NAMEMAX];
+ unsigned int length;
} direntry_t;
typedef struct dir {
- char dirname[DIR_PATHMAX];
- direntry_t entry;
- DIR * handle;
+ char dirname[DIR_PATHMAX];
+ direntry_t entry;
+ DIR *handle;
} dir_t;
void
diff --git a/contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c b/contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c
index 494bd180..ceb5dfe3 100644
--- a/contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c
+++ b/contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c
@@ -34,7 +34,8 @@
*/
/*
- * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc.
+ * ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -46,28 +47,27 @@
* update support
*/
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
#include <stdlib.h>
-
+#include <string.h>
#include <sys/stat.h>
-#include "dlz_minimal.h"
-#include "dlz_list.h"
#include "dir.h"
+#include "dlz_list.h"
+#include "dlz_minimal.h"
typedef struct config_data {
- char *basedir;
- int basedirsize;
- char *datadir;
- int datadirsize;
- char *xfrdir;
- int xfrdirsize;
- int splitcnt;
- char separator;
- char pathsep;
+ char *basedir;
+ int basedirsize;
+ char *datadir;
+ int datadirsize;
+ char *xfrdir;
+ int xfrdirsize;
+ int splitcnt;
+ char separator;
+ char pathsep;
/* Helper functions from the dlz_dlopen driver */
log_t *log;
@@ -80,7 +80,7 @@ typedef struct dir_entry dir_entry_t;
struct dir_entry {
char dirpath[DIR_PATHMAX];
- DLZ_LINK(dir_entry_t) link;
+ DLZ_LINK(dir_entry_t) link;
};
typedef DLZ_LIST(dir_entry_t) dlist_t;
@@ -98,49 +98,58 @@ is_safe(const char *input) {
unsigned int i;
unsigned int len = strlen(input);
- /* check that only allowed characters are in the domain name */
+ /* check that only allowed characters are in the domain name */
for (i = 0; i < len; i++) {
/* '.' is allowed, but has special requirements */
if (input[i] == '.') {
/* '.' is not allowed as first char */
- if (i == 0)
+ if (i == 0) {
return (false);
+ }
/* '..', two dots together is not allowed. */
- if (input[i-1] == '.')
+ if (input[i - 1] == '.') {
return (false);
+ }
/* '.' is not allowed as last char */
- if (i == len - 1)
+ if (i == len - 1) {
return (false);
+ }
/* only 1 dot in ok location, continue at next char */
continue;
}
/* '-' is allowed, continue at next char */
- if (input[i] == '-')
+ if (input[i] == '-') {
continue;
+ }
/* 0-9 is allowed, continue at next char */
- if (input[i] >= '0' && input[i] <= '9')
+ if (input[i] >= '0' && input[i] <= '9') {
continue;
+ }
/* A-Z uppercase is allowed, continue at next char */
- if (input[i] >= 'A' && input[i] <= 'Z')
+ if (input[i] >= 'A' && input[i] <= 'Z') {
continue;
+ }
/* a-z lowercase is allowed, continue at next char */
- if (input[i] >= 'a' && input[i] <= 'z')
+ if (input[i] >= 'a' && input[i] <= 'z') {
continue;
+ }
/*
* colon needs to be allowed for IPV6 client
* addresses. Not dangerous in domain names, as not a
* special char.
*/
- if (input[i] == ':')
+ if (input[i] == ':') {
continue;
+ }
/*
* '@' needs to be allowed for in zone data. Not
* dangerous in domain names, as not a special char.
*/
- if (input[i] == '@')
+ if (input[i] == '@') {
continue;
+ }
/*
* if we reach this point we have encountered a
@@ -148,7 +157,7 @@ is_safe(const char *input) {
*/
return (false);
}
- /* everything ok. */
+ /* everything ok. */
return (true);
}
@@ -159,8 +168,9 @@ create_path_helper(char *out, const char *in, config_data_t *cd) {
int i;
tmpString = strdup(in);
- if (tmpString == NULL)
+ if (tmpString == NULL) {
return (ISC_R_NOMEMORY);
+ }
/*
* don't forget is_safe guarantees '.' will NOT be the
@@ -168,37 +178,42 @@ create_path_helper(char *out, const char *in, config_data_t *cd) {
*/
while ((tmpPtr = strrchr(tmpString, '.')) != NULL) {
i = 0;
- while (tmpPtr[i+1] != '\0') {
- if (cd->splitcnt < 1)
- strcat(out, (char *) &tmpPtr[i+1]);
- else
- strncat(out, (char *) &tmpPtr[i+1],
+ while (tmpPtr[i + 1] != '\0') {
+ if (cd->splitcnt < 1) {
+ strcat(out, (char *)&tmpPtr[i + 1]);
+ } else {
+ strncat(out, (char *)&tmpPtr[i + 1],
cd->splitcnt);
- strncat(out, (char *) &cd->pathsep, 1);
- if (cd->splitcnt == 0)
+ }
+ strncat(out, (char *)&cd->pathsep, 1);
+ if (cd->splitcnt == 0) {
break;
- if (strlen((char *) &tmpPtr[i+1]) <=
- (unsigned int) cd->splitcnt)
+ }
+ if (strlen((char *)&tmpPtr[i + 1]) <=
+ (unsigned int)cd->splitcnt) {
break;
+ }
i += cd->splitcnt;
}
tmpPtr[0] = '\0';
}
/* handle the "first" label properly */
- i=0;
+ i = 0;
tmpPtr = tmpString;
while (tmpPtr[i] != '\0') {
- if (cd->splitcnt < 1)
- strcat(out, (char *) &tmpPtr[i]);
- else
- strncat(out, (char *) &tmpPtr[i], cd->splitcnt);
- strncat(out, (char *) &cd->pathsep, 1);
- if (cd->splitcnt == 0)
+ if (cd->splitcnt < 1) {
+ strcat(out, (char *)&tmpPtr[i]);
+ } else {
+ strncat(out, (char *)&tmpPtr[i], cd->splitcnt);
+ }
+ strncat(out, (char *)&cd->pathsep, 1);
+ if (cd->splitcnt == 0) {
break;
- if (strlen((char *) &tmpPtr[i]) <=
- (unsigned int) cd->splitcnt)
+ }
+ if (strlen((char *)&tmpPtr[i]) <= (unsigned int)cd->splitcnt) {
break;
+ }
i += cd->splitcnt;
}
@@ -214,9 +229,7 @@ create_path_helper(char *out, const char *in, config_data_t *cd) {
static isc_result_t
create_path(const char *zone, const char *host, const char *client,
- config_data_t *cd, char **path)
-{
-
+ config_data_t *cd, char **path) {
char *tmpPath;
int pathsize;
int len;
@@ -224,47 +237,51 @@ create_path(const char *zone, const char *host, const char *client,
bool isroot = false;
/* special case for root zone */
- if (strcmp(zone, ".") == 0)
+ if (strcmp(zone, ".") == 0) {
isroot = true;
+ }
/* if the requested zone is "unsafe", return error */
- if (!isroot && !is_safe(zone))
+ if (!isroot && !is_safe(zone)) {
return (ISC_R_FAILURE);
+ }
/* if host was passed, verify that it is safe */
- if (host != NULL && !is_safe(host))
+ if (host != NULL && !is_safe(host)) {
return (ISC_R_FAILURE);
+ }
/* if client was passed, verify that it is safe */
- if (client != NULL && !is_safe(client))
+ if (client != NULL && !is_safe(client)) {
return (ISC_R_FAILURE);
+ }
/* Determine how much memory the split up string will require */
- if (host != NULL)
+ if (host != NULL) {
len = strlen(zone) + strlen(host);
- else if (client != NULL)
+ } else if (client != NULL) {
len = strlen(zone) + strlen(client);
- else
+ } else {
len = strlen(zone);
+ }
/*
* even though datadir and xfrdir will never be in the same
* string we only waste a few bytes by allocating for both,
* and then we are safe from buffer overruns.
*/
- pathsize = len + cd->basedirsize +
- cd->datadirsize + cd->xfrdirsize + 4;
+ pathsize = len + cd->basedirsize + cd->datadirsize + cd->xfrdirsize + 4;
/* if we are splitting names, we will need extra space. */
- if (cd->splitcnt > 0)
- pathsize += len/cd->splitcnt;
+ if (cd->splitcnt > 0) {
+ pathsize += len / cd->splitcnt;
+ }
tmpPath = malloc(pathsize * sizeof(char));
if (tmpPath == NULL) {
/* write error message */
- cd->log(ISC_LOG_ERROR,
- "Filesystem driver unable to "
- "allocate memory in create_path().");
+ cd->log(ISC_LOG_ERROR, "Filesystem driver unable to "
+ "allocate memory in create_path().");
result = ISC_R_NOMEMORY;
goto cleanup_mem;
}
@@ -278,8 +295,9 @@ create_path(const char *zone, const char *host, const char *client,
/* add zone name - parsed properly */
if (!isroot) {
result = create_path_helper(tmpPath, zone, cd);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup_mem;
+ }
}
/*
@@ -305,17 +323,19 @@ create_path(const char *zone, const char *host, const char *client,
/* if client is passed append xfr dir, otherwise append data dir */
if (client != NULL) {
strcat(tmpPath, cd->xfrdir);
- strncat(tmpPath, (char *) &cd->pathsep, 1);
+ strncat(tmpPath, (char *)&cd->pathsep, 1);
strcat(tmpPath, client);
- } else
+ } else {
strcat(tmpPath, cd->datadir);
+ }
/* if host not null, add it. */
if (host != NULL) {
- strncat(tmpPath, (char *) &cd->pathsep, 1);
+ strncat(tmpPath, (char *)&cd->pathsep, 1);
result = create_path_helper(tmpPath, host, cd);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup_mem;
+ }
}
/* return the path we built. */
@@ -324,24 +344,23 @@ create_path(const char *zone, const char *host, const char *client,
/* return success */
result = ISC_R_SUCCESS;
- cleanup_mem:
+cleanup_mem:
/* cleanup memory */
/* free tmpPath memory */
- if (tmpPath != NULL && result != ISC_R_SUCCESS)
+ if (tmpPath != NULL && result != ISC_R_SUCCESS) {
free(tmpPath);
+ }
return (result);
}
static isc_result_t
-process_dir(dir_t *dir, void *passback, config_data_t *cd,
- dlist_t *dir_list, unsigned int basedirlen)
-{
-
+process_dir(dir_t *dir, void *passback, config_data_t *cd, dlist_t *dir_list,
+ unsigned int basedirlen) {
char tmp[DIR_PATHMAX + DIR_NAMEMAX];
int astPos;
- struct stat sb;
+ struct stat sb;
isc_result_t result = ISC_R_FAILURE;
char *endp;
char *type;
@@ -371,8 +390,8 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd,
/* if splitcnt == 0, determine host from path. */
if (cd->splitcnt == 0) {
if (strlen(tmp) - 3 > basedirlen) {
- tmp[astPos-1] = '\0';
- tmpString = (char *) &tmp[basedirlen+1];
+ tmp[astPos - 1] = '\0';
+ tmpString = (char *)&tmp[basedirlen + 1];
/* handle filesystem's special wildcard "-" */
if (strcmp(tmpString, "-") == 0) {
strcpy(host, "*");
@@ -380,22 +399,22 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd,
/*
* not special wildcard -- normal name
*/
- while ((tmpPtr = strrchr(tmpString,
- cd->pathsep))
- != NULL)
- {
+ while ((tmpPtr = strrchr(
+ tmpString,
+ cd->pathsep)) != NULL) {
if ((strlen(host) +
- strlen(tmpPtr + 1) + 2)
- > DIR_NAMEMAX)
+ strlen(tmpPtr + 1) + 2) >
+ DIR_NAMEMAX) {
continue;
+ }
strcat(host, tmpPtr + 1);
strcat(host, ".");
tmpPtr[0] = '\0';
}
- if ((strlen(host) +
- strlen(tmpString) + 1)
- <= DIR_NAMEMAX)
+ if ((strlen(host) + strlen(tmpString) +
+ 1) <= DIR_NAMEMAX) {
strcat(host, tmpString);
+ }
}
foundHost = true;
@@ -408,19 +427,20 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd,
* ".host" directory entry
*/
while (dir_read(dir) == ISC_R_SUCCESS) {
- if (strncasecmp(".host",
- dir->entry.name, 5) == 0) {
+ if (strncasecmp(".host", dir->entry.name, 5) ==
+ 0) {
/*
* handle filesystem's special
* wildcard "-"
*/
- if (strcmp((char *) &dir->entry.name[6],
- "-") == 0)
+ if (strcmp((char *)&dir->entry.name[6],
+ "-") == 0) {
strcpy(host, "*");
- else {
+ } else {
strncpy(host,
- (char *) &dir->entry.name[6],
- sizeof(host) - 1);
+ (char *)&dir->entry
+ .name[6],
+ sizeof(host) - 1);
host[255] = '\0';
}
foundHost = true;
@@ -439,8 +459,9 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd,
dir->dirname, dir->entry.name);
/* skip any entries starting with "." */
- if (dir->entry.name[0] == '.')
+ if (dir->entry.name[0] == '.') {
continue;
+ }
/*
* get rid of '*', set to NULL. Effectively trims
@@ -455,7 +476,7 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd,
strcat(tmp, dir->entry.name);
/* make sure we can stat entry */
- if (stat(tmp, &sb) == 0 ) {
+ if (stat(tmp, &sb) == 0) {
/* if entry is a directory */
if ((sb.st_mode & S_IFDIR) != 0) {
/*
@@ -464,8 +485,9 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd,
*/
if (dir_list != NULL) {
direntry = malloc(sizeof(dir_entry_t));
- if (direntry == NULL)
+ if (direntry == NULL) {
return (ISC_R_NOMEMORY);
+ }
strcpy(direntry->dirpath, tmp);
DLZ_LINK_INIT(direntry, link);
DLZ_LIST_APPEND(*dir_list, direntry,
@@ -480,33 +502,34 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd,
* are performing a zone xfr and we
* could not find a host entry.
*/
-
- } else if (dir_list != NULL &&
- foundHost == false) {
+ } else if (dir_list != NULL && !foundHost) {
continue;
}
- } else /* if we cannot stat entry, skip it. */
+ } else { /* if we cannot stat entry, skip it. */
continue;
+ }
type = dir->entry.name;
- ttlStr = strchr(type, cd->separator);
+ ttlStr = strchr(type, cd->separator);
if (ttlStr == NULL) {
cd->log(ISC_LOG_ERROR,
"Filesystem driver: "
- "%s could not be parsed properly", tmp);
+ "%s could not be parsed properly",
+ tmp);
return (ISC_R_FAILURE);
}
/* replace separator char with NULL to split string */
ttlStr[0] = '\0';
/* start string after NULL of previous string */
- ttlStr = (char *) &ttlStr[1];
+ ttlStr = (char *)&ttlStr[1];
data = strchr(ttlStr, cd->separator);
if (data == NULL) {
cd->log(ISC_LOG_ERROR,
"Filesystem driver: "
- "%s could not be parsed properly", tmp);
+ "%s could not be parsed properly",
+ tmp);
return (ISC_R_FAILURE);
}
@@ -514,35 +537,37 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd,
data[0] = '\0';
/* start string after NULL of previous string */
- data = (char *) &data[1];
+ data = (char *)&data[1];
/* replace all cd->separator chars with a space. */
len = strlen(data);
- for (i=0; i < len; i++) {
- if (data[i] == cd->separator)
+ for (i = 0; i < len; i++) {
+ if (data[i] == cd->separator) {
data[i] = ' ';
+ }
}
/* convert text to int, make sure it worked right */
ttl = strtol(ttlStr, &endp, 10);
- if (*endp != '\0' || ttl < 0)
- cd->log(ISC_LOG_ERROR,
- "Filesystem driver "
- "ttl must be a postive number");
+ if (*endp != '\0' || ttl < 0) {
+ cd->log(ISC_LOG_ERROR, "Filesystem driver "
+ "ttl must be a positive number");
+ }
/* pass data back to Bind */
- if (dir_list == NULL)
- result = cd->putrr((dns_sdlzlookup_t *) passback,
- type, ttl, data);
- else
- result = cd->putnamedrr((dns_sdlzallnodes_t *) passback,
- (char *) host,
- type, ttl, data);
+ if (dir_list == NULL) {
+ result = cd->putrr((dns_sdlzlookup_t *)passback, type,
+ ttl, data);
+ } else {
+ result = cd->putnamedrr((dns_sdlzallnodes_t *)passback,
+ (char *)host, type, ttl, data);
+ }
/* if error, return error right away */
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (result);
+ }
} /* end of while loop */
return (result);
@@ -555,11 +580,11 @@ isc_result_t
dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
isc_result_t result;
char *path;
- struct stat sb;
+ struct stat sb;
config_data_t *cd;
path = NULL;
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
if (create_path(name, NULL, client, cd, &path) != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
@@ -577,7 +602,7 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
result = ISC_R_NOTFOUND;
- complete_AXFR:
+complete_AXFR:
free(path);
return (result);
}
@@ -586,16 +611,15 @@ isc_result_t
dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
isc_result_t result;
dlist_t *dir_list;
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
char *basepath;
unsigned int basepathlen;
- struct stat sb;
+ struct stat sb;
dir_t dir;
dir_entry_t *dir_entry;
dir_entry_t *next_de;
basepath = NULL;
- dir_list = NULL;
/* allocate memory for list */
dir_list = malloc(sizeof(dlist_t));
@@ -644,8 +668,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
/* close the directory */
dir_close(&dir);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto complete_allnds;
+ }
/* get first dir entry from list. */
dir_entry = DLZ_LIST_HEAD(*dir_list);
@@ -655,7 +680,8 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
if (result != ISC_R_SUCCESS) {
cd->log(ISC_LOG_ERROR,
"Unable to open %s "
- "directory to read entries.", basepath);
+ "directory to read entries.",
+ basepath);
result = ISC_R_FAILURE;
goto complete_allnds;
}
@@ -666,13 +692,14 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
/* close the directory */
dir_close(&dir);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto complete_allnds;
+ }
dir_entry = DLZ_LIST_NEXT(dir_entry, link);
} /* end while */
- complete_allnds:
+complete_allnds:
if (dir_list != NULL) {
/* clean up entries from list. */
dir_entry = DLZ_LIST_HEAD(*dir_list);
@@ -684,8 +711,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
free(dir_list);
}
- if (basepath != NULL)
+ if (basepath != NULL) {
free(basepath);
+ }
return (result);
}
@@ -693,16 +721,14 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_findzonedb(void *dbdata, const char *name)
-#else
+#else /* if DLZ_DLOPEN_VERSION < 3 */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo)
-#endif
+#endif /* if DLZ_DLOPEN_VERSION < 3 */
{
-
isc_result_t result;
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
char *path;
struct stat sb;
path = NULL;
@@ -710,10 +736,11 @@ dlz_findzonedb(void *dbdata, const char *name,
#if DLZ_DLOPEN_VERSION >= 3
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 3 */
- if (create_path(name, NULL, NULL, cd, &path) != ISC_R_SUCCESS)
+ if (create_path(name, NULL, NULL, cd, &path) != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
cd->log(ISC_LOG_DEBUG(1),
"Filesystem driver Findzone() Checking for path: '%s'\n", path);
@@ -730,7 +757,7 @@ dlz_findzonedb(void *dbdata, const char *name,
result = ISC_R_NOTFOUND;
- complete_FZ:
+complete_FZ:
free(path);
return (result);
@@ -738,18 +765,17 @@ dlz_findzonedb(void *dbdata, const char *name,
#if DLZ_DLOPEN_VERSION == 1
isc_result_t
-dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup)
-#else
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup)
+#else /* if DLZ_DLOPEN_VERSION == 1 */
isc_result_t
-dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods,
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo)
-#endif
+#endif /* if DLZ_DLOPEN_VERSION == 1 */
{
isc_result_t result = ISC_R_NOTFOUND;
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
char *path;
struct stat sb;
dir_t dir;
@@ -759,21 +785,23 @@ dlz_lookup(const char *zone, const char *name,
#if DLZ_DLOPEN_VERSION >= 2
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 2 */
- if (strcmp(name, "*") == 0)
+ if (strcmp(name, "*") == 0) {
/*
* handle filesystem's special wildcard "-"
*/
result = create_path(zone, "-", NULL, cd, &path);
- else
+ } else {
result = create_path(zone, name, NULL, cd, &path);
+ }
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
/* remove path separator at end of path so stat works properly */
- path[strlen(path)-1] = '\0';
+ path[strlen(path) - 1] = '\0';
cd->log(ISC_LOG_DEBUG(1),
"Filesystem driver lookup() Checking for path: '%s'\n", path);
@@ -806,16 +834,15 @@ dlz_lookup(const char *zone, const char *name,
/* close the directory */
dir_close(&dir);
- complete_lkup:
+complete_lkup:
free(path);
return (result);
}
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
isc_result_t result = ISC_R_NOMEMORY;
config_data_t *cd;
char *endp;
@@ -828,38 +855,39 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate memory for our config data and helper functions */
cd = calloc(1, sizeof(config_data_t));
- if (cd == NULL)
+ if (cd == NULL) {
goto no_mem;
+ }
/* zero the memory */
memset(cd, 0, sizeof(config_data_t));
/* Fill in the helper functions */
va_start(ap, dbdata);
- while ((helper_name = va_arg(ap, const char*)) != NULL)
- b9_add_helper(cd, helper_name, va_arg(ap, void*));
+ while ((helper_name = va_arg(ap, const char *)) != NULL) {
+ b9_add_helper(cd, helper_name, va_arg(ap, void *));
+ }
va_end(ap);
/* we require 5 command line args. */
if (argc != 6) {
- cd->log(ISC_LOG_ERROR,
- "Filesystem driver requires "
- "6 command line args.");
+ cd->log(ISC_LOG_ERROR, "Filesystem driver requires "
+ "6 command line args.");
result = ISC_R_FAILURE;
goto free_cd;
}
if (strlen(argv[5]) > 1) {
- cd->log(ISC_LOG_ERROR,
- "Filesystem driver can only "
- "accept a single character for separator.");
+ cd->log(ISC_LOG_ERROR, "Filesystem driver can only "
+ "accept a single character for "
+ "separator.");
result = ISC_R_FAILURE;
goto free_cd;
}
/* verify base dir ends with '/' or '\' */
len = strlen(argv[1]);
- if (argv[1][len-1] != '\\' && argv[1][len-1] != '/') {
+ if (argv[1][len - 1] != '\\' && argv[1][len - 1] != '/') {
cd->log(ISC_LOG_ERROR,
"Base dir parameter for filesystem driver "
"should end with %s",
@@ -869,37 +897,41 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* determine and save path separator for later */
- if (argv[1][len-1] == '\\')
+ if (argv[1][len - 1] == '\\') {
pathsep = '\\';
- else
+ } else {
pathsep = '/';
+ }
cd->pathsep = pathsep;
/* get and store our base directory */
cd->basedir = strdup(argv[1]);
- if (cd->basedir == NULL)
+ if (cd->basedir == NULL) {
goto no_mem;
+ }
cd->basedirsize = strlen(cd->basedir);
/* get and store our data sub-dir */
cd->datadir = strdup(argv[2]);
- if (cd->datadir == NULL)
+ if (cd->datadir == NULL) {
goto no_mem;
+ }
cd->datadirsize = strlen(cd->datadir);
/* get and store our zone xfr sub-dir */
cd->xfrdir = strdup(argv[3]);
- if (cd->xfrdir == NULL)
+ if (cd->xfrdir == NULL) {
goto no_mem;
+ }
cd->xfrdirsize = strlen(cd->xfrdir);
/* get and store our directory split count */
cd->splitcnt = strtol(argv[4], &endp, 10);
- if (*endp != '\0' || cd->splitcnt < 0)
- cd->log(ISC_LOG_ERROR,
- "Directory split count must be zero (0) "
- "or a postive number");
+ if (*endp != '\0' || cd->splitcnt < 0) {
+ cd->log(ISC_LOG_ERROR, "Directory split count must be zero (0) "
+ "or a positive number");
+ }
/* get and store our separator character */
cd->separator = *argv[5];
@@ -911,18 +943,20 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_SUCCESS);
/* handle no memory error */
- no_mem:
+no_mem:
/* write error message */
- if (cd != NULL && cd->log != NULL)
- cd->log(ISC_LOG_ERROR,
- "filesystem_dynamic: Filesystem driver unable to "
- "allocate memory for config data.");
+ if (cd != NULL && cd->log != NULL) {
+ cd->log(ISC_LOG_ERROR, "filesystem_dynamic: Filesystem driver "
+ "unable to "
+ "allocate memory for config data.");
+ }
- free_cd:
+free_cd:
/* if we allocated a config data object clean it up */
- if (cd != NULL)
+ if (cd != NULL) {
dlz_destroy(cd);
+ }
/* return error */
return (result);
@@ -932,20 +966,23 @@ void
dlz_destroy(void *dbdata) {
config_data_t *cd;
- cd = (config_data_t *) dbdata;
+ cd = (config_data_t *)dbdata;
/*
* free memory for each section of config data that was
* allocated
*/
- if (cd->basedir != NULL)
+ if (cd->basedir != NULL) {
free(cd->basedir);
+ }
- if (cd->datadir != NULL)
+ if (cd->datadir != NULL) {
free(cd->datadir);
+ }
- if (cd->xfrdir != NULL)
+ if (cd->xfrdir != NULL) {
free(cd->xfrdir);
+ }
/* free config data memory */
free(cd);
@@ -965,12 +1002,16 @@ dlz_version(unsigned int *flags) {
*/
static void
b9_add_helper(struct config_data *cd, const char *helper_name, void *ptr) {
- if (strcmp(helper_name, "log") == 0)
+ if (strcmp(helper_name, "log") == 0) {
cd->log = (log_t *)ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
cd->putrr = (dns_sdlz_putrr_t *)ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
cd->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
cd->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
+ }
}
diff --git a/contrib/dlz/modules/include/.clang-format b/contrib/dlz/modules/include/.clang-format
new file mode 120000
index 00000000..e919bbad
--- /dev/null
+++ b/contrib/dlz/modules/include/.clang-format
@@ -0,0 +1 @@
+../../../../.clang-format.headers \ No newline at end of file
diff --git a/contrib/dlz/modules/include/dlz_dbi.h b/contrib/dlz/modules/include/dlz_dbi.h
index b0714d35..735359c8 100644
--- a/contrib/dlz/modules/include/dlz_dbi.h
+++ b/contrib/dlz/modules/include/dlz_dbi.h
@@ -35,8 +35,8 @@
#include <stdbool.h>
-#include <dlz_minimal.h>
#include <dlz_list.h>
+#include <dlz_minimal.h>
#include <dlz_pthread.h>
#ifndef DLZ_DBI_H
@@ -45,10 +45,10 @@
/*
* Types
*/
-#define REQUIRE_CLIENT 0x01
-#define REQUIRE_QUERY 0x02
-#define REQUIRE_RECORD 0x04
-#define REQUIRE_ZONE 0x08
+#define REQUIRE_CLIENT 0x01
+#define REQUIRE_QUERY 0x02
+#define REQUIRE_RECORD 0x04
+#define REQUIRE_ZONE 0x08
typedef struct query_segment query_segment_t;
typedef DLZ_LIST(query_segment_t) query_list_t;
@@ -61,10 +61,10 @@ typedef struct driverinstance driverinstance_t;
* special tokens are %zone%, %record%, %client%
*/
struct query_segment {
- void *cmd;
- unsigned int strlen;
- bool direct;
- DLZ_LINK(query_segment_t) link;
+ void * cmd;
+ unsigned int strlen;
+ bool direct;
+ DLZ_LINK(query_segment_t) link;
};
/*%
@@ -75,19 +75,19 @@ struct query_segment {
* make sure no two threads try to use the same DBI at a time.
*/
struct dbinstance {
- void *dbconn;
- query_list_t *allnodes_q;
- query_list_t *allowxfr_q;
- query_list_t *authority_q;
- query_list_t *findzone_q;
- query_list_t *lookup_q;
- query_list_t *countzone_q;
- char *query_buf;
- char *zone;
- char *record;
- char *client;
- dlz_mutex_t lock;
- DLZ_LINK(dbinstance_t) link;
+ void * dbconn;
+ query_list_t *allnodes_q;
+ query_list_t *allowxfr_q;
+ query_list_t *authority_q;
+ query_list_t *findzone_q;
+ query_list_t *lookup_q;
+ query_list_t *countzone_q;
+ char * query_buf;
+ char * zone;
+ char * record;
+ char * client;
+ dlz_mutex_t lock;
+ DLZ_LINK(dbinstance_t) link;
};
/*
@@ -99,7 +99,7 @@ destroy_querylist(query_list_t **querylist);
isc_result_t
build_querylist(const char *query_str, char **zone, char **record,
- char **client, query_list_t **querylist, unsigned int flags,
+ char **client, query_list_t **querylist, unsigned int flags,
log_t log);
char *
@@ -115,6 +115,6 @@ void
destroy_dbinstance(dbinstance_t *dbi);
char *
-get_parameter_value(const char *input, const char* key);
+get_parameter_value(const char *input, const char *key);
#endif /* DLZ_DBI_H */
diff --git a/contrib/dlz/modules/include/dlz_list.h b/contrib/dlz/modules/include/dlz_list.h
index d236105f..74940d02 100644
--- a/contrib/dlz/modules/include/dlz_list.h
+++ b/contrib/dlz/modules/include/dlz_list.h
@@ -1,5 +1,6 @@
/*
- * Copyright (C) 1997-2002, 2004, 2006, 2007, 2011-2013, 2016 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 1997-2002, 2004, 2006, 2007, 2011-2013, 2016 Internet Systems
+ * Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -9,13 +10,22 @@
#ifndef DLZ_LIST_H
#define DLZ_LIST_H 1
-#define DLZ_LIST(type) struct { type *head, *tail; }
-#define DLZ_LIST_INIT(list) \
- do { (list).head = NULL; (list).tail = NULL; } while (0)
+#define DLZ_LIST(type) \
+ struct { \
+ type *head, *tail; \
+ }
+#define DLZ_LIST_INIT(list) \
+ do { \
+ (list).head = NULL; \
+ (list).tail = NULL; \
+ } while (0)
-#define DLZ_LINK(type) struct { type *prev, *next; }
-#define DLZ_LINK_INIT(elt, link) \
- do { \
+#define DLZ_LINK(type) \
+ struct { \
+ type *prev, *next; \
+ }
+#define DLZ_LINK_INIT(elt, link) \
+ do { \
(elt)->link.prev = (void *)(-1); \
(elt)->link.next = (void *)(-1); \
} while (0)
@@ -23,15 +33,15 @@
#define DLZ_LIST_HEAD(list) ((list).head)
#define DLZ_LIST_TAIL(list) ((list).tail)
-#define DLZ_LIST_APPEND(list, elt, link) \
- do { \
- if ((list).tail != NULL) \
+#define DLZ_LIST_APPEND(list, elt, link) \
+ do { \
+ if ((list).tail != NULL) \
(list).tail->link.next = (elt); \
- else \
- (list).head = (elt); \
- (elt)->link.prev = (list).tail; \
- (elt)->link.next = NULL; \
- (list).tail = (elt); \
+ else \
+ (list).head = (elt); \
+ (elt)->link.prev = (list).tail; \
+ (elt)->link.next = NULL; \
+ (list).tail = (elt); \
} while (0)
#define DLZ_LIST_PREV(elt, link) ((elt)->link.prev)
diff --git a/contrib/dlz/modules/include/dlz_minimal.h b/contrib/dlz/modules/include/dlz_minimal.h
index 05ae3b27..bac8ab12 100644
--- a/contrib/dlz/modules/include/dlz_minimal.h
+++ b/contrib/dlz/modules/include/dlz_minimal.h
@@ -28,17 +28,18 @@
#include <inttypes.h>
#include <stdbool.h>
-#include <sys/types.h>
+
#include <sys/socket.h>
+#include <sys/types.h>
#ifdef ISC_PLATFORM_HAVESYSUNH
#include <sys/un.h>
-#endif
+#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */
+#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
typedef unsigned int isc_result_t;
-typedef uint32_t dns_ttl_t;
+typedef uint32_t dns_ttl_t;
/*
* Define DLZ_DLOPEN_VERSION to different values to use older versions
@@ -46,42 +47,45 @@ typedef uint32_t dns_ttl_t;
*/
#ifndef DLZ_DLOPEN_VERSION
#define DLZ_DLOPEN_VERSION 3
-#define DLZ_DLOPEN_AGE 0
-#endif
+#define DLZ_DLOPEN_AGE 0
+#endif /* ifndef DLZ_DLOPEN_VERSION */
/* return these in flags from dlz_version() */
-#define DNS_SDLZFLAG_THREADSAFE 0x00000001U
-#define DNS_SDLZFLAG_RELATIVEOWNER 0x00000002U
-#define DNS_SDLZFLAG_RELATIVERDATA 0x00000004U
+#define DNS_SDLZFLAG_THREADSAFE 0x00000001U
+#define DNS_SDLZFLAG_RELATIVEOWNER 0x00000002U
+#define DNS_SDLZFLAG_RELATIVERDATA 0x00000004U
/* result codes */
-#define ISC_R_SUCCESS 0
-#define ISC_R_NOMEMORY 1
-#define ISC_R_NOPERM 6
-#define ISC_R_NOSPACE 19
-#define ISC_R_NOTFOUND 23
-#define ISC_R_FAILURE 25
-#define ISC_R_NOTIMPLEMENTED 27
-#define ISC_R_NOMORE 29
-#define ISC_R_INVALIDFILE 30
-#define ISC_R_UNEXPECTED 34
-#define ISC_R_FILENOTFOUND 38
+#define ISC_R_SUCCESS 0
+#define ISC_R_NOMEMORY 1
+#define ISC_R_NOPERM 6
+#define ISC_R_NOSPACE 19
+#define ISC_R_NOTFOUND 23
+#define ISC_R_FAILURE 25
+#define ISC_R_NOTIMPLEMENTED 27
+#define ISC_R_NOMORE 29
+#define ISC_R_INVALIDFILE 30
+#define ISC_R_UNEXPECTED 34
+#define ISC_R_FILENOTFOUND 38
/* log levels */
-#define ISC_LOG_INFO (-1)
-#define ISC_LOG_NOTICE (-2)
-#define ISC_LOG_WARNING (-3)
-#define ISC_LOG_ERROR (-4)
-#define ISC_LOG_CRITICAL (-5)
-#define ISC_LOG_DEBUG(level) (level)
+#define ISC_LOG_INFO (-1)
+#define ISC_LOG_NOTICE (-2)
+#define ISC_LOG_WARNING (-3)
+#define ISC_LOG_ERROR (-4)
+#define ISC_LOG_CRITICAL (-5)
+#define ISC_LOG_DEBUG(level) (level)
/* other useful definitions */
#define UNUSED(x) (void)(x)
-#define DE_CONST(konst, var) \
- do { \
- union { const void *k; void *v; } _u; \
- _u.k = konst; \
- var = _u.v; \
+#define DE_CONST(konst, var) \
+ do { \
+ union { \
+ const void *k; \
+ void * v; \
+ } _u; \
+ _u.k = konst; \
+ var = _u.v; \
} while (0)
/* opaque structures */
@@ -97,63 +101,61 @@ typedef void *dns_dlzdb_t;
*/
typedef struct isc_sockaddr {
union {
- struct sockaddr sa;
- struct sockaddr_in sin;
- struct sockaddr_in6 sin6;
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
#ifdef ISC_PLATFORM_HAVESYSUNH
- struct sockaddr_un sunix;
-#endif
- } type;
- unsigned int length;
- void * link;
+ struct sockaddr_un sunix;
+#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */
+ } type;
+ unsigned int length;
+ void * link;
} isc_sockaddr_t;
#define DNS_CLIENTINFO_VERSION 2
typedef struct dns_clientinfo {
uint16_t version;
- void *data;
- void *dbversion;
+ void * data;
+ void * dbversion;
} dns_clientinfo_t;
typedef isc_result_t (*dns_clientinfo_sourceip_t)(dns_clientinfo_t *client,
- isc_sockaddr_t **addrp);
+ isc_sockaddr_t ** addrp);
typedef isc_result_t (*dns_clientinfo_version_t)(dns_clientinfo_t *client,
- void **addrp);
+ void ** addrp);
#define DNS_CLIENTINFOMETHODS_VERSION 2
-#define DNS_CLIENTINFOMETHODS_AGE 1
+#define DNS_CLIENTINFOMETHODS_AGE 1
typedef struct dns_clientinfomethods {
- uint16_t version;
- uint16_t age;
+ uint16_t version;
+ uint16_t age;
dns_clientinfo_sourceip_t sourceip;
- dns_clientinfo_version_t dbversion;
+ dns_clientinfo_version_t dbversion;
} dns_clientinfomethods_t;
#endif /* DLZ_DLOPEN_VERSION > 1 */
/*
* Method definitions for callbacks provided by the dlopen driver
*/
-typedef void log_t(int level, const char *fmt, ...);
+typedef void
+log_t(int level, const char *fmt, ...);
-typedef isc_result_t dns_sdlz_putrr_t(dns_sdlzlookup_t *lookup,
- const char *type,
- dns_ttl_t ttl,
- const char *data);
+typedef isc_result_t
+dns_sdlz_putrr_t(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl,
+ const char *data);
-typedef isc_result_t dns_sdlz_putnamedrr_t(dns_sdlzallnodes_t *allnodes,
- const char *name,
- const char *type,
- dns_ttl_t ttl,
- const char *data);
+typedef isc_result_t
+dns_sdlz_putnamedrr_t(dns_sdlzallnodes_t *allnodes, const char *name,
+ const char *type, dns_ttl_t ttl, const char *data);
#if DLZ_DLOPEN_VERSION < 3
-typedef isc_result_t dns_dlz_writeablezone_t(dns_view_t *view,
- const char *zone_name);
-#else /* DLZ_DLOPEN_VERSION >= 3 */
-typedef isc_result_t dns_dlz_writeablezone_t(dns_view_t *view,
- dns_dlzdb_t *dlzdb,
- const char *zone_name);
+typedef isc_result_t
+dns_dlz_writeablezone_t(dns_view_t *view, const char *zone_name);
+#else /* DLZ_DLOPEN_VERSION >= 3 */
+typedef isc_result_t
+dns_dlz_writeablezone_t(dns_view_t *view, dns_dlzdb_t *dlzdb,
+ const char *zone_name);
#endif /* DLZ_DLOPEN_VERSION */
/*
@@ -174,8 +176,8 @@ dlz_version(unsigned int *flags);
* dlz_create() is required for all DLZ external drivers.
*/
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...);
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...);
/*
* dlz_destroy() is optional, and will be called when the driver is
@@ -190,10 +192,9 @@ dlz_destroy(void *dbdata);
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_findzonedb(void *dbdata, const char *name);
-#else /* DLZ_DLOPEN_VERSION >= 3 */
+#else /* DLZ_DLOPEN_VERSION >= 3 */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo);
#endif /* DLZ_DLOPEN_VERSION */
@@ -204,11 +205,10 @@ dlz_findzonedb(void *dbdata, const char *name,
isc_result_t
dlz_lookup(const char *zone, const char *name, void *dbdata,
dns_sdlzlookup_t *lookup);
-#else /* DLZ_DLOPEN_VERSION > 1 */
+#else /* DLZ_DLOPEN_VERSION > 1 */
isc_result_t
dlz_lookup(const char *zone, const char *name, void *dbdata,
- dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo);
#endif /* DLZ_DLOPEN_VERSION */
@@ -240,13 +240,12 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes);
isc_result_t
dlz_newversion(const char *zone, void *dbdata, void **versionp);
-/*
+/*
* dlz_closeversion() is optional, but must be supplied if you supply a
* dlz_newversion() function
*/
void
-dlz_closeversion(const char *zone, bool commit, void *dbdata,
- void **versionp);
+dlz_closeversion(const char *zone, bool commit, void *dbdata, void **versionp);
/*
* dlz_configure() is optional, but must be supplied if you want to support
@@ -255,7 +254,7 @@ dlz_closeversion(const char *zone, bool commit, void *dbdata,
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_configure(dns_view_t *view, void *dbdata);
-#else /* DLZ_DLOPEN_VERSION >= 3 */
+#else /* DLZ_DLOPEN_VERSION >= 3 */
isc_result_t
dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata);
#endif /* DLZ_DLOPEN_VERSION */
diff --git a/contrib/dlz/modules/include/dlz_pthread.h b/contrib/dlz/modules/include/dlz_pthread.h
index 90d143e5..fd8d5fe8 100644
--- a/contrib/dlz/modules/include/dlz_pthread.h
+++ b/contrib/dlz/modules/include/dlz_pthread.h
@@ -19,23 +19,23 @@
#ifndef PTHREADS
#define PTHREADS 1
-#endif
+#endif /* ifndef PTHREADS */
#ifdef PTHREADS
#include <pthread.h>
-#define dlz_mutex_t pthread_mutex_t
-#define dlz_mutex_init pthread_mutex_init
+#define dlz_mutex_t pthread_mutex_t
+#define dlz_mutex_init pthread_mutex_init
#define dlz_mutex_destroy pthread_mutex_destroy
-#define dlz_mutex_lock pthread_mutex_lock
+#define dlz_mutex_lock pthread_mutex_lock
#define dlz_mutex_trylock pthread_mutex_trylock
-#define dlz_mutex_unlock pthread_mutex_unlock
+#define dlz_mutex_unlock pthread_mutex_unlock
#else /* !PTHREADS */
-#define dlz_mutex_t void
+#define dlz_mutex_t void
#define dlz_mutex_init(a, b) (0)
#define dlz_mutex_destroy(a) (0)
-#define dlz_mutex_lock(a) (0)
+#define dlz_mutex_lock(a) (0)
#define dlz_mutex_trylock(a) (0)
-#define dlz_mutex_unlock(a) (0)
-#endif
+#define dlz_mutex_unlock(a) (0)
+#endif /* ifdef PTHREADS */
#endif /* DLZ_PTHREAD_H */
diff --git a/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c b/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c
index 0915d04a..543a95d7 100644
--- a/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c
+++ b/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c
@@ -34,7 +34,8 @@
*/
/*
- * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc.
+ * ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -46,15 +47,15 @@
* update support
*/
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
#include <stdlib.h>
+#include <string.h>
-#include <dlz_minimal.h>
-#include <dlz_list.h>
#include <dlz_dbi.h>
+#include <dlz_list.h>
+#include <dlz_minimal.h>
#include <dlz_pthread.h>
/*
@@ -65,34 +66,37 @@
#include <ldap.h>
#define SIMPLE "simple"
-#define KRB41 "krb41"
-#define KRB42 "krb42"
-#define V2 "v2"
-#define V3 "v3"
+#define KRB41 "krb41"
+#define KRB42 "krb42"
+#define V2 "v2"
+#define V3 "v3"
#define dbc_search_limit 30
-#define ALLNODES 1
-#define ALLOWXFR 2
-#define AUTHORITY 3
-#define FINDZONE 4
-#define LOOKUP 5
+#define ALLNODES 1
+#define ALLOWXFR 2
+#define AUTHORITY 3
+#define FINDZONE 4
+#define LOOKUP 5
/*%
- * Structure to hold everthing needed by this "instance" of the LDAP
+ * Structure to hold everything needed by this "instance" of the LDAP
* driver remember, the driver code is only loaded once, but may have
* many separate instances.
*/
typedef struct {
#if PTHREADS
- db_list_t *db; /*%< handle to a list of DB */
-#else
+ db_list_t *db; /*%< handle to a list of DB */
+#else /* if PTHREADS */
dbinstance_t *db; /*%< handle to db */
-#endif
- int method; /*%< security authentication method */
- char *user; /*%< who is authenticating */
- char *cred; /*%< password for simple authentication method */
- int protocol; /*%< LDAP communication protocol version */
- char *hosts; /*%< LDAP server hosts */
+#endif /* if PTHREADS */
+ int method; /*%< security authentication
+ * method */
+ char *user; /*%< who is authenticating */
+ char *cred; /*%< password for simple
+ * authentication method */
+ int protocol; /*%< LDAP communication
+ * protocol version */
+ char *hosts; /*%< LDAP server hosts */
/* Helper functions from the dlz_dlopen driver */
log_t *log;
@@ -106,12 +110,11 @@ typedef struct {
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_findzonedb(void *dbdata, const char *name);
-#else
+#else /* if DLZ_DLOPEN_VERSION < 3 */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo);
-#endif
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo);
+#endif /* if DLZ_DLOPEN_VERSION < 3 */
void
dlz_destroy(void *dbdata);
@@ -131,8 +134,7 @@ ldap_checkURL(ldap_instance_t *db, char *URL, int attrCnt, const char *msg) {
LDAPURLDesc *ldap_url = NULL;
if (!ldap_is_ldap_url(URL)) {
- db->log(ISC_LOG_ERROR,
- "%s query is not a valid LDAP URL", msg);
+ db->log(ISC_LOG_ERROR, "%s query is not a valid LDAP URL", msg);
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -147,28 +149,27 @@ ldap_checkURL(ldap_instance_t *db, char *URL, int attrCnt, const char *msg) {
if (ldap_count_values(ldap_url->lud_attrs) < attrCnt) {
db->log(ISC_LOG_ERROR,
"%s query must specify at least "
- "%d attributes to return", msg, attrCnt);
+ "%d attributes to return",
+ msg, attrCnt);
result = ISC_R_FAILURE;
goto cleanup;
}
if (ldap_url->lud_host != NULL) {
- db->log(ISC_LOG_ERROR,
- "%s query must not specify a host", msg);
+ db->log(ISC_LOG_ERROR, "%s query must not specify a host", msg);
result = ISC_R_FAILURE;
goto cleanup;
}
if (ldap_url->lud_port != 389) {
- db->log(ISC_LOG_ERROR,
- "%s query must not specify a port", msg);
+ db->log(ISC_LOG_ERROR, "%s query must not specify a port", msg);
result = ISC_R_FAILURE;
goto cleanup;
}
- if (ldap_url->lud_dn == NULL || strlen (ldap_url->lud_dn) < 1) {
- db->log(ISC_LOG_ERROR,
- "%s query must specify a search base", msg);
+ if (ldap_url->lud_dn == NULL || strlen(ldap_url->lud_dn) < 1) {
+ db->log(ISC_LOG_ERROR, "%s query must specify a search base",
+ msg);
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -176,14 +177,16 @@ ldap_checkURL(ldap_instance_t *db, char *URL, int attrCnt, const char *msg) {
if (ldap_url->lud_exts != NULL || ldap_url->lud_crit_exts != 0) {
db->log(ISC_LOG_ERROR,
"%s uses extensions. "
- "The driver does not support LDAP extensions.", msg);
+ "The driver does not support LDAP extensions.",
+ msg);
result = ISC_R_FAILURE;
goto cleanup;
}
- cleanup:
- if (ldap_url != NULL)
+cleanup:
+ if (ldap_url != NULL) {
ldap_free_urldesc(ldap_url);
+ }
return (result);
}
@@ -196,7 +199,7 @@ ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
/* if we have a connection, get ride of it. */
if (dbc->dbconn != NULL) {
- ldap_unbind_s((LDAP *) dbc->dbconn);
+ ldap_unbind_s((LDAP *)dbc->dbconn);
dbc->dbconn = NULL;
}
@@ -204,11 +207,12 @@ ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
/* initialize. */
dbc->dbconn = ldap_init(dbi->hosts, LDAP_PORT);
- if (dbc->dbconn == NULL)
+ if (dbc->dbconn == NULL) {
return (ISC_R_NOMEMORY);
+ }
/* set protocol version. */
- ldap_result = ldap_set_option((LDAP *) dbc->dbconn,
+ ldap_result = ldap_set_option((LDAP *)dbc->dbconn,
LDAP_OPT_PROTOCOL_VERSION,
&(dbi->protocol));
if (ldap_result != LDAP_SUCCESS) {
@@ -217,8 +221,8 @@ ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
}
/* "bind" to server. i.e. send username / pass */
- ldap_result = ldap_bind_s((LDAP *) dbc->dbconn, dbi->user,
- dbi->cred, dbi->method);
+ ldap_result = ldap_bind_s((LDAP *)dbc->dbconn, dbi->user, dbi->cred,
+ dbi->method);
if (ldap_result != LDAP_SUCCESS) {
result = ISC_R_FAILURE;
goto cleanup;
@@ -226,11 +230,11 @@ ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) {
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
/* cleanup if failure. */
if (dbc->dbconn != NULL) {
- ldap_unbind_s((LDAP *) dbc->dbconn);
+ ldap_unbind_s((LDAP *)dbc->dbconn);
dbc->dbconn = NULL;
}
@@ -257,8 +261,9 @@ ldap_destroy_dblist(db_list_t *dblist) {
/* get the next DBI in the list */
ndbi = DLZ_LIST_NEXT(dbi, link);
/* release DB connection */
- if (dbi->dbconn != NULL)
- ldap_unbind_s((LDAP *) dbi->dbconn);
+ if (dbi->dbconn != NULL) {
+ ldap_unbind_s((LDAP *)dbi->dbconn);
+ }
/* release all memory that comprised a DBI */
destroy_dbinstance(dbi);
}
@@ -288,9 +293,9 @@ ldap_find_avail_conn(ldap_instance_t *ldap) {
/* loop through list */
while (count < dbc_search_limit) {
/* try to lock on the mutex */
- if (dlz_mutex_trylock(&dbi->lock) == 0)
+ if (dlz_mutex_trylock(&dbi->lock) == 0) {
return (dbi); /* success, return the DBI for use. */
-
+ }
/* not successful, keep trying */
dbi = DLZ_LIST_NEXT(dbi, link);
@@ -302,16 +307,16 @@ ldap_find_avail_conn(ldap_instance_t *ldap) {
}
ldap->log(ISC_LOG_INFO,
- "LDAP driver unable to find available connection "
- "after searching %d times", count);
+ "LDAP driver unable to find available connection "
+ "after searching %d times",
+ count);
return (NULL);
}
#endif /* PTHREADS */
static isc_result_t
ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
- char **attrs, void *ptr, bool allnodes)
-{
+ char **attrs, void *ptr, bool allnodes) {
isc_result_t result = ISC_R_SUCCESS;
int i = 0;
int j;
@@ -345,8 +350,9 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
/* get the list of values for this attribute. */
vals = ldap_get_values(dbc, entry, attrs[j]);
/* skip empty attributes. */
- if (vals == NULL || ldap_count_values(vals) < 1)
+ if (vals == NULL || ldap_count_values(vals) < 1) {
continue;
+ }
/*
* we only use the first value. this driver
* does not support multi-valued attributes.
@@ -359,9 +365,9 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
/* allocate memory for data string */
data = malloc(len + 1);
if (data == NULL) {
- db->log(ISC_LOG_ERROR,
- "LDAP driver unable to allocate memory "
- "while processing results");
+ db->log(ISC_LOG_ERROR, "LDAP driver unable to allocate "
+ "memory "
+ "while processing results");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -382,7 +388,7 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
/* skip empty attributes. */
if (vals == NULL || vals[0] == NULL) {
- /* increment attibute pointer */
+ /* increment attribute pointer */
attribute = attrs[++i];
/* start loop over */
continue;
@@ -402,9 +408,10 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
*/
ttl = strtol(vals[0], &endp, 10);
if (*endp != '\0' || ttl < 0) {
- db->log(ISC_LOG_ERROR,
- "LDAP driver ttl must "
- "be a postive number");
+ db->log(ISC_LOG_ERROR, "LDAP driver "
+ "ttl must "
+ "be a positive "
+ "number");
goto cleanup;
}
break;
@@ -414,16 +421,17 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
break;
case 2:
j++;
- if (allnodes)
+ if (allnodes) {
host = strdup(vals[0]);
- else
+ } else {
strcpy(data, vals[0]);
+ }
break;
case 3:
j++;
- if (allnodes)
+ if (allnodes) {
strcpy(data, vals[0]);
- else {
+ } else {
strcat(data, " ");
strcat(data, vals[0]);
}
@@ -438,51 +446,53 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
ldap_value_free(vals);
vals = NULL;
- /* increment attibute pointer */
+ /* increment attribute pointer */
attribute = attrs[++i];
}
if (type == NULL) {
- db->log(ISC_LOG_ERROR,
- "LDAP driver unable to retrieve DNS type");
+ db->log(ISC_LOG_ERROR, "LDAP driver unable to retrieve "
+ "DNS type");
result = ISC_R_FAILURE;
goto cleanup;
}
if (strlen(data) < 1) {
- db->log(ISC_LOG_ERROR,
- "LDAP driver unable to retrieve DNS data");
+ db->log(ISC_LOG_ERROR, "LDAP driver unable to retrieve "
+ "DNS data");
result = ISC_R_FAILURE;
goto cleanup;
}
if (allnodes && host != NULL) {
- dns_sdlzallnodes_t *an = (dns_sdlzallnodes_t *) ptr;
- if (strcasecmp(host, "~") == 0)
- result = db->putnamedrr(an, "*", type,
- ttl, data);
- else
- result = db->putnamedrr(an, host, type,
- ttl, data);
- if (result != ISC_R_SUCCESS)
+ dns_sdlzallnodes_t *an = (dns_sdlzallnodes_t *)ptr;
+ if (strcasecmp(host, "~") == 0) {
+ result = db->putnamedrr(an, "*", type, ttl,
+ data);
+ } else {
+ result = db->putnamedrr(an, host, type, ttl,
+ data);
+ }
+ if (result != ISC_R_SUCCESS) {
db->log(ISC_LOG_ERROR,
"ldap_dynamic: putnamedrr failed "
"for \"%s %s %u %s\" (%d)",
host, type, ttl, data, result);
+ }
} else {
- dns_sdlzlookup_t *lookup = (dns_sdlzlookup_t *) ptr;
+ dns_sdlzlookup_t *lookup = (dns_sdlzlookup_t *)ptr;
result = db->putrr(lookup, type, ttl, data);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
db->log(ISC_LOG_ERROR,
"ldap_dynamic: putrr failed "
"for \"%s %u %s\" (%s)",
type, ttl, data, result);
+ }
}
if (result != ISC_R_SUCCESS) {
- db->log(ISC_LOG_ERROR,
- "LDAP driver failed "
- "while sending data to BIND.");
+ db->log(ISC_LOG_ERROR, "LDAP driver failed "
+ "while sending data to BIND.");
goto cleanup;
}
@@ -502,16 +512,20 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
entry = ldap_next_entry(dbc, entry);
}
- cleanup:
+cleanup:
/* de-allocate memory */
- if (vals != NULL)
+ if (vals != NULL) {
ldap_value_free(vals);
- if (host != NULL)
+ }
+ if (host != NULL) {
free(host);
- if (type != NULL)
+ }
+ if (type != NULL) {
free(type);
- if (data != NULL)
+ }
+ if (data != NULL) {
free(data);
+ }
return (result);
}
@@ -529,10 +543,8 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg,
* obtain a result set.
*/
static isc_result_t
-ldap_get_results(const char *zone, const char *record,
- const char *client, unsigned int query,
- void *dbdata, void *ptr)
-{
+ldap_get_results(const char *zone, const char *record, const char *client,
+ unsigned int query, void *dbdata, void *ptr) {
isc_result_t result;
ldap_instance_t *db = (ldap_instance_t *)dbdata;
dbinstance_t *dbi = NULL;
@@ -547,7 +559,7 @@ ldap_get_results(const char *zone, const char *record,
#if PTHREADS
/* find an available DBI from the list */
dbi = ldap_find_avail_conn(db);
-#else /* PTHREADS */
+#else /* PTHREADS */
/*
* only 1 DBI - no need to lock instance lock either
* only 1 thread in the whole process, no possible contention.
@@ -556,8 +568,9 @@ ldap_get_results(const char *zone, const char *record,
#endif /* PTHREADS */
/* if DBI is null, can't do anything else */
- if (dbi == NULL)
+ if (dbi == NULL) {
return (ISC_R_FAILURE);
+ }
/* set fields */
if (zone != NULL) {
@@ -566,8 +579,9 @@ ldap_get_results(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->zone = NULL;
+ }
if (record != NULL) {
dbi->record = strdup(record);
@@ -575,8 +589,9 @@ ldap_get_results(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->record = NULL;
+ }
if (client != NULL) {
dbi->client = strdup(client);
@@ -584,9 +599,9 @@ ldap_get_results(const char *zone, const char *record,
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->client = NULL;
-
+ }
/* what type of query are we going to run? */
switch (query) {
@@ -600,60 +615,65 @@ ldap_get_results(const char *zone, const char *record,
if (dbi->allnodes_q == NULL) {
result = ISC_R_NOTIMPLEMENTED;
goto cleanup;
- } else
+ } else {
querystring = build_querystring(dbi->allnodes_q);
+ }
break;
case ALLOWXFR:
/* same as comments as ALLNODES */
if (dbi->allowxfr_q == NULL) {
result = ISC_R_NOTIMPLEMENTED;
goto cleanup;
- } else
+ } else {
querystring = build_querystring(dbi->allowxfr_q);
+ }
break;
case AUTHORITY:
/* same as comments as ALLNODES */
if (dbi->authority_q == NULL) {
result = ISC_R_NOTIMPLEMENTED;
goto cleanup;
- } else
+ } else {
querystring = build_querystring(dbi->authority_q);
+ }
break;
case FINDZONE:
/* this is required. It's the whole point of DLZ! */
if (dbi->findzone_q == NULL) {
- db->log(ISC_LOG_DEBUG(2),
- "No query specified for findzone. "
- "Findzone requires a query");
+ db->log(ISC_LOG_DEBUG(2), "No query specified for "
+ "findzone. "
+ "Findzone requires a query");
result = ISC_R_FAILURE;
goto cleanup;
- } else
+ } else {
querystring = build_querystring(dbi->findzone_q);
+ }
break;
case LOOKUP:
/* this is required. It's also a major point of DLZ! */
if (dbi->lookup_q == NULL) {
- db->log(ISC_LOG_DEBUG(2),
- "No query specified for lookup. "
- "Lookup requires a query");
+ db->log(ISC_LOG_DEBUG(2), "No query specified for "
+ "lookup. "
+ "Lookup requires a query");
result = ISC_R_FAILURE;
goto cleanup;
- } else
+ } else {
querystring = build_querystring(dbi->lookup_q);
+ }
break;
default:
/*
* this should never happen. If it does, the code is
* screwed up!
*/
- db->log(ISC_LOG_ERROR,
- "Incorrect query flag passed to ldap_get_results");
+ db->log(ISC_LOG_ERROR, "Incorrect query flag passed to "
+ "ldap_get_results");
result = ISC_R_UNEXPECTED;
goto cleanup;
}
/* if the querystring is null, Bummer, outta RAM. UPGRADE TIME!!! */
- if (querystring == NULL) {
+ if (querystring == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
@@ -677,22 +697,21 @@ ldap_get_results(const char *zone, const char *record,
* previous query failed.
*/
if (dbi->dbconn == NULL) {
- db->log(ISC_LOG_INFO,
- "LDAP driver attempting to re-connect");
+ db->log(ISC_LOG_INFO, "LDAP driver attempting to "
+ "re-connect");
- result = ldap_connect((ldap_instance_t *) dbdata, dbi);
+ result = ldap_connect((ldap_instance_t *)dbdata, dbi);
if (result != ISC_R_SUCCESS) {
result = ISC_R_FAILURE;
continue;
}
}
- /* perform ldap search syncronously */
- ldap_result = ldap_search_s((LDAP *) dbi->dbconn,
- ldap_url->lud_dn,
- ldap_url->lud_scope,
- ldap_url->lud_filter,
- ldap_url->lud_attrs, 0, &ldap_msg);
+ /* perform ldap search synchronously */
+ ldap_result =
+ ldap_search_s((LDAP *)dbi->dbconn, ldap_url->lud_dn,
+ ldap_url->lud_scope, ldap_url->lud_filter,
+ ldap_url->lud_attrs, 0, &ldap_msg);
/*
* check return code. No such object is ok, just
@@ -700,28 +719,29 @@ ldap_get_results(const char *zone, const char *record,
*/
switch (ldap_result) {
case LDAP_NO_SUCH_OBJECT:
- db->log(ISC_LOG_DEBUG(1),
- "No object found matching query requirements");
+ db->log(ISC_LOG_DEBUG(1), "No object found matching "
+ "query requirements");
result = ISC_R_NOTFOUND;
goto cleanup;
break;
- case LDAP_SUCCESS: /* on success do nothing */
+ case LDAP_SUCCESS: /* on success do nothing */
result = ISC_R_SUCCESS;
i = 3;
break;
case LDAP_SERVER_DOWN:
- db->log(ISC_LOG_INFO,
- "LDAP driver attempting to re-connect");
- result = ldap_connect((ldap_instance_t *) dbdata, dbi);
- if (result != ISC_R_SUCCESS)
+ db->log(ISC_LOG_INFO, "LDAP driver attempting to "
+ "re-connect");
+ result = ldap_connect((ldap_instance_t *)dbdata, dbi);
+ if (result != ISC_R_SUCCESS) {
result = ISC_R_FAILURE;
+ }
break;
default:
/*
* other errors not ok. Log error message and
* get out
*/
- db->log(ISC_LOG_ERROR, "LDAP error: %s",
+ db->log(ISC_LOG_ERROR, "LDAP error: %s",
ldap_err2string(ldap_result));
result = ISC_R_FAILURE;
goto cleanup;
@@ -729,74 +749,81 @@ ldap_get_results(const char *zone, const char *record,
}
}
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup;
+ }
switch (query) {
case ALLNODES:
- result = ldap_process_results(db, (LDAP *) dbi->dbconn,
- ldap_msg, ldap_url->lud_attrs,
- ptr, true);
+ result = ldap_process_results(db, (LDAP *)dbi->dbconn, ldap_msg,
+ ldap_url->lud_attrs, ptr, true);
break;
case AUTHORITY:
case LOOKUP:
- result = ldap_process_results(db, (LDAP *) dbi->dbconn,
- ldap_msg, ldap_url->lud_attrs,
- ptr, false);
+ result = ldap_process_results(db, (LDAP *)dbi->dbconn, ldap_msg,
+ ldap_url->lud_attrs, ptr, false);
break;
case ALLOWXFR:
- entries = ldap_count_entries((LDAP *) dbi->dbconn, ldap_msg);
- if (entries == 0)
+ entries = ldap_count_entries((LDAP *)dbi->dbconn, ldap_msg);
+ if (entries == 0) {
result = ISC_R_NOPERM;
- else if (entries > 0)
+ } else if (entries > 0) {
result = ISC_R_SUCCESS;
- else
+ } else {
result = ISC_R_FAILURE;
+ }
break;
case FINDZONE:
- entries = ldap_count_entries((LDAP *) dbi->dbconn, ldap_msg);
- if (entries == 0)
+ entries = ldap_count_entries((LDAP *)dbi->dbconn, ldap_msg);
+ if (entries == 0) {
result = ISC_R_NOTFOUND;
- else if (entries > 0)
+ } else if (entries > 0) {
result = ISC_R_SUCCESS;
- else
+ } else {
result = ISC_R_FAILURE;
+ }
break;
default:
/*
* this should never happen. If it does, the code is
* screwed up!
*/
- db->log(ISC_LOG_ERROR,
- "Incorrect query flag passed to ldap_get_results");
+ db->log(ISC_LOG_ERROR, "Incorrect query flag passed to "
+ "ldap_get_results");
result = ISC_R_UNEXPECTED;
}
- cleanup:
+cleanup:
/* it's always good to cleanup after yourself */
/* if we retrieved results, free them */
- if (ldap_msg != NULL)
+ if (ldap_msg != NULL) {
ldap_msgfree(ldap_msg);
+ }
- if (ldap_url != NULL)
+ if (ldap_url != NULL) {
ldap_free_urldesc(ldap_url);
+ }
/* cleanup */
- if (dbi->zone != NULL)
+ if (dbi->zone != NULL) {
free(dbi->zone);
- if (dbi->record != NULL)
+ }
+ if (dbi->record != NULL) {
free(dbi->record);
- if (dbi->client != NULL)
+ }
+ if (dbi->client != NULL) {
free(dbi->client);
+ }
dbi->zone = dbi->record = dbi->client = NULL;
/* release the lock so another thread can use this dbi */
- (void) dlz_mutex_unlock(&dbi->lock);
+ (void)dlz_mutex_unlock(&dbi->lock);
/* release query string */
- if (querystring != NULL)
+ if (querystring != NULL) {
free(querystring);
+ }
/* return result */
return (result);
@@ -812,9 +839,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
/* check to see if we are authoritative for the zone first */
#if DLZ_DLOPEN_VERSION < 3
result = dlz_findzonedb(dbdata, name);
-#else
+#else /* if DLZ_DLOPEN_VERSION < 3 */
result = dlz_findzonedb(dbdata, name, NULL, NULL);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION < 3 */
if (result != ISC_R_SUCCESS) {
return (result);
}
@@ -825,8 +852,7 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
}
isc_result_t
-dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes)
-{
+dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
return (ldap_get_results(zone, NULL, NULL, ALLNODES, dbdata, allnodes));
}
@@ -838,51 +864,50 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) {
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_findzonedb(void *dbdata, const char *name)
-#else
+#else /* if DLZ_DLOPEN_VERSION < 3 */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo)
-#endif
+#endif /* if DLZ_DLOPEN_VERSION < 3 */
{
#if DLZ_DLOPEN_VERSION >= 3
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 3 */
return (ldap_get_results(name, NULL, NULL, FINDZONE, dbdata, NULL));
}
#if DLZ_DLOPEN_VERSION == 1
-isc_result_t dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup)
-#else
-isc_result_t dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-#endif
+isc_result_t
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup)
+#else /* if DLZ_DLOPEN_VERSION == 1 */
+isc_result_t
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo)
+#endif /* if DLZ_DLOPEN_VERSION == 1 */
{
isc_result_t result;
#if DLZ_DLOPEN_VERSION >= 2
UNUSED(methods);
UNUSED(clientinfo);
-#endif
-
- if (strcmp(name, "*") == 0)
- result = ldap_get_results(zone, "~", NULL, LOOKUP,
- dbdata, lookup);
- else
- result = ldap_get_results(zone, name, NULL, LOOKUP,
- dbdata, lookup);
+#endif /* if DLZ_DLOPEN_VERSION >= 2 */
+
+ if (strcmp(name, "*") == 0) {
+ result = ldap_get_results(zone, "~", NULL, LOOKUP, dbdata,
+ lookup);
+ } else {
+ result = ldap_get_results(zone, name, NULL, LOOKUP, dbdata,
+ lookup);
+ }
return (result);
}
-
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
isc_result_t result = ISC_R_FAILURE;
ldap_instance_t *ldap = NULL;
dbinstance_t *dbi = NULL;
@@ -900,62 +925,63 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate memory for LDAP instance */
ldap = calloc(1, sizeof(ldap_instance_t));
- if (ldap == NULL)
+ if (ldap == NULL) {
return (ISC_R_NOMEMORY);
+ }
memset(ldap, 0, sizeof(ldap_instance_t));
/* Fill in the helper functions */
va_start(ap, dbdata);
- while ((helper_name = va_arg(ap, const char*)) != NULL)
- b9_add_helper(ldap, helper_name, va_arg(ap, void*));
+ while ((helper_name = va_arg(ap, const char *)) != NULL) {
+ b9_add_helper(ldap, helper_name, va_arg(ap, void *));
+ }
va_end(ap);
#if PTHREADS
/* if debugging, let user know we are multithreaded. */
ldap->log(ISC_LOG_DEBUG(1), "LDAP driver running multithreaded");
-#else /* PTHREADS */
+#else /* PTHREADS */
/* if debugging, let user know we are single threaded. */
ldap->log(ISC_LOG_DEBUG(1), "LDAP driver running single threaded");
#endif /* PTHREADS */
if (argc < 9) {
- ldap->log(ISC_LOG_ERROR,
- "LDAP driver requires at least "
- "8 command line args.");
+ ldap->log(ISC_LOG_ERROR, "LDAP driver requires at least "
+ "8 command line args.");
goto cleanup;
}
/* no more than 13 arg's should be passed to the driver */
if (argc > 12) {
- ldap->log(ISC_LOG_ERROR,
- "LDAP driver cannot accept more than "
- "11 command line args.");
+ ldap->log(ISC_LOG_ERROR, "LDAP driver cannot accept more than "
+ "11 command line args.");
goto cleanup;
}
/* determine protocol version. */
- if (strncasecmp(argv[2], V2, strlen(V2)) == 0)
+ if (strncasecmp(argv[2], V2, strlen(V2)) == 0) {
protocol = 2;
- else if (strncasecmp(argv[2], V3, strlen(V3)) == 0)
+ } else if (strncasecmp(argv[2], V3, strlen(V3)) == 0) {
protocol = 3;
- else {
+ } else {
ldap->log(ISC_LOG_ERROR,
- "LDAP driver protocol must be either %s or %s",
- V2, V3);
+ "LDAP driver protocol must be either %s or %s", V2,
+ V3);
goto cleanup;
}
/* determine connection method. */
- if (strncasecmp(argv[3], SIMPLE, strlen(SIMPLE)) == 0)
+ if (strncasecmp(argv[3], SIMPLE, strlen(SIMPLE)) == 0) {
method = LDAP_AUTH_SIMPLE;
- else if (strncasecmp(argv[3], KRB41, strlen(KRB41)) == 0)
+ } else if (strncasecmp(argv[3], KRB41, strlen(KRB41)) == 0) {
method = LDAP_AUTH_KRBV41;
- else if (strncasecmp(argv[3], KRB42, strlen(KRB42)) == 0)
+ } else if (strncasecmp(argv[3], KRB42, strlen(KRB42)) == 0) {
method = LDAP_AUTH_KRBV42;
- else {
+ } else {
ldap->log(ISC_LOG_ERROR,
"LDAP driver authentication method must be "
- "one of %s, %s or %s", SIMPLE, KRB41, KRB42);
+ "one of %s, %s or %s",
+ SIMPLE, KRB41, KRB42);
goto cleanup;
}
@@ -964,37 +990,42 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* check how many db connections we should create */
dbcount = strtol(argv[1], &endp, 10);
if (*endp != '\0' || dbcount < 0) {
- ldap->log(ISC_LOG_ERROR,
- "LDAP driver database connection count "
- "must be positive.");
+ ldap->log(ISC_LOG_ERROR, "LDAP driver database connection "
+ "count "
+ "must be positive.");
goto cleanup;
}
-#endif
+#endif /* if PTHREADS */
/* check that LDAP URL parameters make sense */
switch (argc) {
case 12:
result = ldap_checkURL(ldap, argv[11], 0,
"allow zone transfer");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup;
+ }
case 11:
result = ldap_checkURL(ldap, argv[10], 3, "all nodes");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup;
+ }
case 10:
if (strlen(argv[9]) > 0) {
result = ldap_checkURL(ldap, argv[9], 3, "authority");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup;
+ }
}
case 9:
result = ldap_checkURL(ldap, argv[8], 3, "lookup");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup;
+ }
result = ldap_checkURL(ldap, argv[7], 0, "find zone");
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto cleanup;
+ }
break;
default:
/* not really needed, should shut up compiler. */
@@ -1045,19 +1076,18 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
ldap->log);
break;
case 10:
- result = build_dbinstance(NULL, NULL, argv[9],
- argv[7], argv[8],
- NULL, &dbi, ldap->log);
+ result = build_dbinstance(NULL, NULL, argv[9], argv[7],
+ argv[8], NULL, &dbi,
+ ldap->log);
break;
case 11:
result = build_dbinstance(argv[10], NULL, argv[9],
- argv[7], argv[8],
- NULL, &dbi, ldap->log);
+ argv[7], argv[8], NULL, &dbi,
+ ldap->log);
break;
case 12:
- result = build_dbinstance(argv[10], argv[11],
- argv[9], argv[7],
- argv[8], NULL, &dbi,
+ result = build_dbinstance(argv[10], argv[11], argv[9],
+ argv[7], argv[8], NULL, &dbi,
ldap->log);
break;
default:
@@ -1066,13 +1096,12 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
}
if (result == ISC_R_SUCCESS) {
- ldap->log(ISC_LOG_DEBUG(2),
- "LDAP driver created "
- "database instance object.");
+ ldap->log(ISC_LOG_DEBUG(2), "LDAP driver created "
+ "database instance "
+ "object.");
} else { /* unsuccessful?, log err msg and cleanup. */
- ldap->log(ISC_LOG_ERROR,
- "LDAP driver could not create "
- "database instance object.");
+ ldap->log(ISC_LOG_ERROR, "LDAP driver could not create "
+ "database instance object.");
goto cleanup;
}
@@ -1080,13 +1109,13 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* when multithreaded, build a list of DBI's */
DLZ_LINK_INIT(dbi, link);
DLZ_LIST_APPEND(*(ldap->db), dbi, link);
-#else
- /*
- * when single threaded, hold onto the one connection
- * instance.
- */
- ldap->db = dbi;
-#endif
+#else /* if PTHREADS */
+ /*
+ * when single threaded, hold onto the one connection
+ * instance.
+ */
+ ldap->db = dbi;
+#endif /* if PTHREADS */
/* attempt to connect */
result = ldap_connect(ldap, dbi);
@@ -1095,53 +1124,53 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
* cleanup.
*/
switch (result) {
- /* success, do nothing */
+ /* success, do nothing */
case ISC_R_SUCCESS:
break;
- /*
- * no memory means ldap_init could not
- * allocate memory
- */
+ /*
+ * no memory means ldap_init could not
+ * allocate memory
+ */
case ISC_R_NOMEMORY:
#if PTHREADS
ldap->log(ISC_LOG_ERROR,
"LDAP driver could not allocate memory "
- "for connection number %u", i + 1);
-#else
- ldap->log(ISC_LOG_ERROR,
- "LDAP driver could not allocate memory "
- "for connection");
-#endif
+ "for connection number %u",
+ i + 1);
+#else /* if PTHREADS */
+ ldap->log(ISC_LOG_ERROR, "LDAP driver could not allocate "
+ "memory "
+ "for connection");
+#endif /* if PTHREADS */
goto cleanup;
- /*
- * no perm means ldap_set_option could not set
- * protocol version
- */
+ /*
+ * no perm means ldap_set_option could not set
+ * protocol version
+ */
case ISC_R_NOPERM:
- ldap->log(ISC_LOG_ERROR,
- "LDAP driver could not "
- "set protocol version.");
+ ldap->log(ISC_LOG_ERROR, "LDAP driver could not "
+ "set protocol version.");
result = ISC_R_FAILURE;
goto cleanup;
- /* failure means couldn't connect to ldap server */
+ /* failure means couldn't connect to ldap server */
case ISC_R_FAILURE:
#if PTHREADS
ldap->log(ISC_LOG_ERROR,
"LDAP driver could not bind "
- "connection number %u to server.", i + 1);
-#else
- ldap->log(ISC_LOG_ERROR,
- "LDAP driver could not "
- "bind connection to server.");
-#endif
+ "connection number %u to server.",
+ i + 1);
+#else /* if PTHREADS */
+ ldap->log(ISC_LOG_ERROR, "LDAP driver could not "
+ "bind connection to server.");
+#endif /* if PTHREADS */
goto cleanup;
- /*
- * default should never happen. If it does,
- * major errors.
- */
+ /*
+ * default should never happen. If it does,
+ * major errors.
+ */
default:
- ldap->log(ISC_LOG_ERROR,
- "dlz_create() failed (%d)", result);
+ ldap->log(ISC_LOG_ERROR, "dlz_create() failed (%d)",
+ result);
result = ISC_R_UNEXPECTED;
goto cleanup;
}
@@ -1157,7 +1186,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
dlz_destroy(ldap);
return (result);
@@ -1169,22 +1198,27 @@ dlz_destroy(void *dbdata) {
ldap_instance_t *db = (ldap_instance_t *)dbdata;
#if PTHREADS
/* cleanup the list of DBI's */
- if (db->db != NULL)
+ if (db->db != NULL) {
ldap_destroy_dblist((db_list_t *)(db->db));
-#else /* PTHREADS */
- if (db->db->dbconn != NULL)
+ }
+#else /* PTHREADS */
+ if (db->db->dbconn != NULL) {
ldap_unbind_s((LDAP *)(db->db->dbconn));
+ }
/* destroy single DB instance */
destroy_dbinstance(db->db);
#endif /* PTHREADS */
- if (db->hosts != NULL)
+ if (db->hosts != NULL) {
free(db->hosts);
- if (db->user != NULL)
+ }
+ if (db->user != NULL) {
free(db->user);
- if (db->cred != NULL)
+ }
+ if (db->cred != NULL) {
free(db->cred);
+ }
free(dbdata);
}
}
@@ -1197,9 +1231,9 @@ dlz_version(unsigned int *flags) {
*flags |= DNS_SDLZFLAG_RELATIVERDATA;
#if PTHREADS
*flags |= DNS_SDLZFLAG_THREADSAFE;
-#else
+#else /* if PTHREADS */
*flags &= ~DNS_SDLZFLAG_THREADSAFE;
-#endif
+#endif /* if PTHREADS */
return (DLZ_DLOPEN_VERSION);
}
@@ -1208,12 +1242,16 @@ dlz_version(unsigned int *flags) {
*/
static void
b9_add_helper(ldap_instance_t *db, const char *helper_name, void *ptr) {
- if (strcmp(helper_name, "log") == 0)
+ if (strcmp(helper_name, "log") == 0) {
db->log = (log_t *)ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
db->putrr = (dns_sdlz_putrr_t *)ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
db->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
db->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
+ }
}
diff --git a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c
index a325fc5d..33d30797 100644
--- a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c
+++ b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c
@@ -34,7 +34,8 @@
*/
/*
- * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc.
+ * ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -46,40 +47,44 @@
* update support
*/
-#include <stdio.h>
-#include <string.h>
#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+
+#include <mysql/mysql.h>
-#include <dlz_minimal.h>
-#include <dlz_list.h>
#include <dlz_dbi.h>
+#include <dlz_list.h>
+#include <dlz_minimal.h>
#include <dlz_pthread.h>
-#include <mysql/mysql.h>
+#if !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000
+typedef bool my_bool;
+#endif /* !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 */
#define dbc_search_limit 30
-#define ALLNODES 1
-#define ALLOWXFR 2
-#define AUTHORITY 3
-#define FINDZONE 4
-#define COUNTZONE 5
-#define LOOKUP 6
+#define ALLNODES 1
+#define ALLOWXFR 2
+#define AUTHORITY 3
+#define FINDZONE 4
+#define COUNTZONE 5
+#define LOOKUP 6
#define safeGet(in) in == NULL ? "" : in
/*%
- * Structure to hold everthing needed by this "instance" of the MySQL
+ * Structure to hold everything needed by this "instance" of the MySQL
* module remember, the module code is only loaded once, but may have
* many separate instances.
*/
typedef struct {
#if PTHREADS
- db_list_t *db; /*%< handle to a list of DB */
+ db_list_t *db; /*%< handle to a list of DB */
int dbcount;
-#else
+#else /* if PTHREADS */
dbinstance_t *db; /*%< handle to DB */
-#endif
+#endif /* if PTHREADS */
unsigned int flags;
char *dbname;
@@ -98,8 +103,7 @@ typedef struct {
/* forward references */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo);
void
@@ -115,8 +119,9 @@ b9_add_helper(mysql_instance_t *db, const char *helper_name, void *ptr);
void
mysql_destroy(dbinstance_t *db) {
/* release DB connection */
- if (db->dbconn != NULL)
- mysql_close((MYSQL *) db->dbconn);
+ if (db->dbconn != NULL) {
+ mysql_close((MYSQL *)db->dbconn);
+ }
/* destroy DB instance */
destroy_dbinstance(db);
@@ -166,9 +171,9 @@ mysql_find_avail_conn(mysql_instance_t *mysql) {
/* loop through list */
while (count < dbc_search_limit) {
/* try to lock on the mutex */
- if (dlz_mutex_trylock(&dbi->lock) == 0)
+ if (dlz_mutex_trylock(&dbi->lock) == 0) {
return (dbi); /* success, return the DBI for use. */
-
+ }
/* not successful, keep trying */
dbi = DLZ_LIST_NEXT(dbi, link);
@@ -181,7 +186,8 @@ mysql_find_avail_conn(mysql_instance_t *mysql) {
mysql->log(ISC_LOG_INFO,
"MySQL module unable to find available connection "
- "after searching %d times", count);
+ "after searching %d times",
+ count);
return (NULL);
}
#endif /* PTHREADS */
@@ -195,17 +201,18 @@ mysql_find_avail_conn(mysql_instance_t *mysql) {
*/
static char *
mysqldrv_escape_string(MYSQL *mysql, const char *instr) {
-
char *outstr;
unsigned int len;
- if (instr == NULL)
+ if (instr == NULL) {
return (NULL);
+ }
len = strlen(instr);
outstr = malloc((2 * len * sizeof(char)) + 1);
- if (outstr == NULL)
+ if (outstr == NULL) {
return (NULL);
+ }
mysql_real_escape_string(mysql, outstr, instr, len);
@@ -222,10 +229,8 @@ mysqldrv_escape_string(MYSQL *mysql, const char *instr) {
* a result set.
*/
static isc_result_t
-mysql_get_resultset(const char *zone, const char *record,
- const char *client, unsigned int query,
- void *dbdata, MYSQL_RES **rs)
-{
+mysql_get_resultset(const char *zone, const char *record, const char *client,
+ unsigned int query, void *dbdata, MYSQL_RES **rs) {
isc_result_t result;
dbinstance_t *dbi = NULL;
mysql_instance_t *db = (mysql_instance_t *)dbdata;
@@ -237,7 +242,7 @@ mysql_get_resultset(const char *zone, const char *record,
#if PTHREADS
/* find an available DBI from the list */
dbi = mysql_find_avail_conn(db);
-#else /* PTHREADS */
+#else /* PTHREADS */
/*
* only 1 DBI - no need to lock instance lock either
* only 1 thread in the whole process, no possible contention.
@@ -246,12 +251,11 @@ mysql_get_resultset(const char *zone, const char *record,
#endif /* PTHREADS */
if (dbi == NULL) {
- result = ISC_R_FAILURE;
- goto cleanup;
+ return (ISC_R_FAILURE);
}
/* what type of query are we going to run? */
- switch(query) {
+ switch (query) {
case ALLNODES:
if (dbi->allnodes_q == NULL) {
result = ISC_R_NOTIMPLEMENTED;
@@ -272,9 +276,9 @@ mysql_get_resultset(const char *zone, const char *record,
break;
case FINDZONE:
if (dbi->findzone_q == NULL) {
- db->log(ISC_LOG_DEBUG(2),
- "No query specified for findzone. "
- "Findzone requires a query");
+ db->log(ISC_LOG_DEBUG(2), "No query specified for "
+ "findzone. "
+ "Findzone requires a query");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -287,66 +291,69 @@ mysql_get_resultset(const char *zone, const char *record,
break;
case LOOKUP:
if (dbi->lookup_q == NULL) {
- db->log(ISC_LOG_DEBUG(2),
- "No query specified for lookup. "
- "Lookup requires a query");
+ db->log(ISC_LOG_DEBUG(2), "No query specified for "
+ "lookup. "
+ "Lookup requires a query");
result = ISC_R_FAILURE;
goto cleanup;
}
break;
default:
- db->log(ISC_LOG_ERROR,
- "Incorrect query flag passed to "
- "mysql_get_resultset");
+ db->log(ISC_LOG_ERROR, "Incorrect query flag passed to "
+ "mysql_get_resultset");
result = ISC_R_UNEXPECTED;
goto cleanup;
}
-
if (zone != NULL) {
- if (dbi->zone != NULL)
+ if (dbi->zone != NULL) {
free(dbi->zone);
+ }
- dbi->zone = mysqldrv_escape_string((MYSQL *) dbi->dbconn,
- zone);
+ dbi->zone = mysqldrv_escape_string((MYSQL *)dbi->dbconn, zone);
if (dbi->zone == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->zone = NULL;
+ }
if (record != NULL) {
- if (dbi->record != NULL)
+ if (dbi->record != NULL) {
free(dbi->record);
+ }
- dbi->record = mysqldrv_escape_string((MYSQL *) dbi->dbconn,
+ dbi->record = mysqldrv_escape_string((MYSQL *)dbi->dbconn,
record);
if (dbi->record == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->record = NULL;
+ }
if (client != NULL) {
- if (dbi->client != NULL)
+ if (dbi->client != NULL) {
free(dbi->client);
+ }
- dbi->client = mysqldrv_escape_string((MYSQL *) dbi->dbconn,
+ dbi->client = mysqldrv_escape_string((MYSQL *)dbi->dbconn,
client);
if (dbi->client == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->client = NULL;
+ }
/*
* what type of query are we going to run? this time we build
* the actual query to run.
*/
- switch(query) {
+ switch (query) {
case ALLNODES:
querystring = build_querystring(dbi->allnodes_q);
break;
@@ -366,10 +373,10 @@ mysql_get_resultset(const char *zone, const char *record,
querystring = build_querystring(dbi->lookup_q);
break;
default:
- db->log(ISC_LOG_ERROR,
- "Incorrect query flag passed to "
- "mysql_get_resultset");
- result = ISC_R_UNEXPECTED; goto cleanup;
+ db->log(ISC_LOG_ERROR, "Incorrect query flag passed to "
+ "mysql_get_resultset");
+ result = ISC_R_UNEXPECTED;
+ goto cleanup;
}
if (querystring == NULL) {
@@ -382,28 +389,30 @@ mysql_get_resultset(const char *zone, const char *record,
/* attempt query up to 3 times. */
for (i = 0; i < 3; i++) {
- qres = mysql_query((MYSQL *) dbi->dbconn, querystring);
- if (qres == 0)
+ qres = mysql_query((MYSQL *)dbi->dbconn, querystring);
+ if (qres == 0) {
break;
- for (j = 0; j < 4; j++)
- if (mysql_ping((MYSQL *) dbi->dbconn) == 0)
- break;
+ }
+ for (j = 0; j < 4; j++) {
+ if (mysql_ping((MYSQL *)dbi->dbconn) == 0) {
+ break;
+ }
+ }
}
if (qres == 0) {
result = ISC_R_SUCCESS;
if (query != COUNTZONE) {
- *rs = mysql_store_result((MYSQL *) dbi->dbconn);
- if (*rs == NULL)
+ *rs = mysql_store_result((MYSQL *)dbi->dbconn);
+ if (*rs == NULL) {
result = ISC_R_FAILURE;
+ }
}
- } else
+ } else {
result = ISC_R_FAILURE;
+ }
- cleanup:
- if (dbi == NULL)
- return (ISC_R_FAILURE);
-
+cleanup:
if (dbi->zone != NULL) {
free(dbi->zone);
dbi->zone = NULL;
@@ -418,10 +427,11 @@ mysql_get_resultset(const char *zone, const char *record,
}
/* release the lock so another thread can use this dbi */
- (void) dlz_mutex_unlock(&dbi->lock);
+ (void)dlz_mutex_unlock(&dbi->lock);
- if (querystring != NULL)
+ if (querystring != NULL) {
free(querystring);
+ }
return (result);
}
@@ -433,8 +443,7 @@ mysql_get_resultset(const char *zone, const char *record,
*/
static isc_result_t
mysql_process_rs(mysql_instance_t *db, dns_sdlzlookup_t *lookup,
- MYSQL_RES *rs)
-{
+ MYSQL_RES *rs) {
isc_result_t result = ISC_R_NOTFOUND;
MYSQL_ROW row;
unsigned int fields;
@@ -443,12 +452,12 @@ mysql_process_rs(mysql_instance_t *db, dns_sdlzlookup_t *lookup,
char *endp;
int ttl;
- fields = mysql_num_fields(rs); /* how many columns in result set */
- row = mysql_fetch_row(rs); /* get a row from the result set */
+ fields = mysql_num_fields(rs); /* how many columns in result set */
+ row = mysql_fetch_row(rs); /* get a row from the result set */
while (row != NULL) {
unsigned int len = 0;
- switch(fields) {
+ switch (fields) {
case 1:
/*
* one column in rs, it's the data field. use
@@ -473,14 +482,14 @@ mysql_process_rs(mysql_instance_t *db, dns_sdlzlookup_t *lookup,
*/
ttl = strtol(safeGet(row[0]), &endp, 10);
if (*endp != '\0' || ttl < 0) {
- db->log(ISC_LOG_ERROR,
- "MySQL module ttl must be "
- "a postive number");
+ db->log(ISC_LOG_ERROR, "MySQL module ttl must "
+ "be "
+ "a positive number");
return (ISC_R_FAILURE);
}
result = db->putrr(lookup, safeGet(row[1]), ttl,
- safeGet(row[2]));
+ safeGet(row[2]));
break;
default:
/*
@@ -497,9 +506,10 @@ mysql_process_rs(mysql_instance_t *db, dns_sdlzlookup_t *lookup,
*/
tmpString = malloc(len + 1);
if (tmpString == NULL) {
- db->log(ISC_LOG_ERROR,
- "MySQL module unable to allocate "
- "memory for temporary string");
+ db->log(ISC_LOG_ERROR, "MySQL module unable to "
+ "allocate "
+ "memory for temporary "
+ "string");
mysql_free_result(rs);
return (ISC_R_FAILURE);
}
@@ -512,22 +522,22 @@ mysql_process_rs(mysql_instance_t *db, dns_sdlzlookup_t *lookup,
ttl = strtol(safeGet(row[0]), &endp, 10);
if (*endp != '\0' || ttl < 0) {
- db->log(ISC_LOG_ERROR,
- "MySQL module ttl must be "
- "a postive number");
+ db->log(ISC_LOG_ERROR, "MySQL module ttl must "
+ "be "
+ "a positive number");
free(tmpString);
return (ISC_R_FAILURE);
}
- result = db->putrr(lookup, safeGet(row[1]),
- ttl, tmpString);
+ result = db->putrr(lookup, safeGet(row[1]), ttl,
+ tmpString);
free(tmpString);
}
if (result != ISC_R_SUCCESS) {
mysql_free_result(rs);
- db->log(ISC_LOG_ERROR,
- "putrr returned error: %d", result);
+ db->log(ISC_LOG_ERROR, "putrr returned error: %d",
+ result);
return (ISC_R_FAILURE);
}
@@ -544,10 +554,8 @@ mysql_process_rs(mysql_instance_t *db, dns_sdlzlookup_t *lookup,
/*% determine if the zone is supported by (in) the database */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
MYSQL_RES *rs = NULL;
my_ulonglong rows;
@@ -558,12 +566,12 @@ dlz_findzonedb(void *dbdata, const char *name,
result = mysql_get_resultset(name, NULL, NULL, FINDZONE, dbdata, &rs);
if (result != ISC_R_SUCCESS || rs == NULL) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
+ }
- db->log(ISC_LOG_ERROR,
- "MySQL module unable to return "
- "result set for findzone query");
+ db->log(ISC_LOG_ERROR, "MySQL module unable to return "
+ "result set for findzone query");
return (ISC_R_FAILURE);
}
@@ -591,8 +599,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
/* first check if the zone is supported by the database. */
result = dlz_findzonedb(dbdata, name, NULL, NULL);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
/*
* if we get to this point we know the zone is supported by
@@ -600,17 +609,17 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
* transfer is allowed for this client and did the config file
* have an allow zone xfr query.
*/
- result = mysql_get_resultset(name, NULL, client, ALLOWXFR,
- dbdata, &rs);
- if (result == ISC_R_NOTIMPLEMENTED)
+ result = mysql_get_resultset(name, NULL, client, ALLOWXFR, dbdata, &rs);
+ if (result == ISC_R_NOTIMPLEMENTED) {
return (result);
+ }
if (result != ISC_R_SUCCESS || rs == NULL) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
- db->log(ISC_LOG_ERROR,
- "MySQL module unable to return "
- "result set for allow xfr query");
+ }
+ db->log(ISC_LOG_ERROR, "MySQL module unable to return "
+ "result set for allow xfr query");
return (ISC_R_FAILURE);
}
@@ -620,8 +629,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
*/
rows = mysql_num_rows(rs);
mysql_free_result(rs);
- if (rows > 0)
+ if (rows > 0) {
return (ISC_R_SUCCESS);
+ }
return (ISC_R_NOPERM);
}
@@ -644,35 +654,34 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
int ttl;
result = mysql_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs);
- if (result == ISC_R_NOTIMPLEMENTED)
+ if (result == ISC_R_NOTIMPLEMENTED) {
return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- db->log(ISC_LOG_ERROR,
- "MySQL module unable to return "
- "result set for all nodes query");
+ db->log(ISC_LOG_ERROR, "MySQL module unable to return "
+ "result set for all nodes query");
goto cleanup;
}
result = ISC_R_NOTFOUND;
- fields = mysql_num_fields(rs); /* how many columns in result set */
- row = mysql_fetch_row(rs); /* get a row from the result set */
+ fields = mysql_num_fields(rs); /* how many columns in result set */
+ row = mysql_fetch_row(rs); /* get a row from the result set */
while (row != NULL) {
if (fields < 4) {
- db->log(ISC_LOG_ERROR,
- "MySQL module too few fields returned "
- "by all nodes query");
+ db->log(ISC_LOG_ERROR, "MySQL module too few fields "
+ "returned "
+ "by all nodes query");
result = ISC_R_FAILURE;
goto cleanup;
}
ttl = strtol(safeGet(row[0]), &endp, 10);
if (*endp != '\0' || ttl < 0) {
- db->log(ISC_LOG_ERROR,
- "MySQL module ttl must be "
- "a postive number");
+ db->log(ISC_LOG_ERROR, "MySQL module ttl must be "
+ "a positive number");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -693,9 +702,10 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
tmpString = malloc(len + 1);
if (tmpString == NULL) {
- db->log(ISC_LOG_ERROR,
- "MySQL module unable to allocate "
- "memory for temporary string");
+ db->log(ISC_LOG_ERROR, "MySQL module unable to "
+ "allocate "
+ "memory for temporary "
+ "string");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -707,14 +717,14 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
}
result = db->putnamedrr(allnodes, safeGet(row[2]),
- safeGet(row[1]),
- ttl, tmpString);
+ safeGet(row[1]), ttl,
+ tmpString);
free(tmpString);
}
if (result != ISC_R_SUCCESS) {
- db->log(ISC_LOG_ERROR,
- "putnamedrr returned error: %s", result);
+ db->log(ISC_LOG_ERROR, "putnamedrr returned error: %s",
+ result);
result = ISC_R_FAILURE;
break;
}
@@ -722,9 +732,10 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
row = mysql_fetch_row(rs);
}
- cleanup:
- if (rs != NULL)
+cleanup:
+ if (rs != NULL) {
mysql_free_result(rs);
+ }
return (result);
}
@@ -740,15 +751,16 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) {
mysql_instance_t *db = (mysql_instance_t *)dbdata;
result = mysql_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata, &rs);
- if (result == ISC_R_NOTIMPLEMENTED)
+ if (result == ISC_R_NOTIMPLEMENTED) {
return (result);
+ }
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
- db->log(ISC_LOG_ERROR,
- "MySQL module unable to return "
- "result set for authority query");
+ }
+ db->log(ISC_LOG_ERROR, "MySQL module unable to return "
+ "result set for authority query");
return (ISC_R_FAILURE);
}
@@ -761,11 +773,9 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) {
/*% If zone is supported, lookup up a (or multiple) record(s) in it */
isc_result_t
-dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
MYSQL_RES *rs = NULL;
mysql_instance_t *db = (mysql_instance_t *)dbdata;
@@ -777,11 +787,11 @@ dlz_lookup(const char *zone, const char *name,
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
mysql_free_result(rs);
- db->log(ISC_LOG_ERROR,
- "MySQL module unable to return "
- "result set for lookup query");
+ }
+ db->log(ISC_LOG_ERROR, "MySQL module unable to return "
+ "result set for lookup query");
return (ISC_R_FAILURE);
}
@@ -796,9 +806,8 @@ dlz_lookup(const char *zone, const char *name,
* Create an instance of the module.
*/
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
isc_result_t result = ISC_R_FAILURE;
mysql_instance_t *mysql = NULL;
dbinstance_t *dbi = NULL;
@@ -807,9 +816,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
char *endp;
int j;
const char *helper_name;
-#if MYSQL_VERSION_ID >= 50000
- my_bool auto_reconnect = 1;
-#endif
#if PTHREADS
int dbcount;
int i;
@@ -820,59 +826,58 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate memory for MySQL instance */
mysql = calloc(1, sizeof(mysql_instance_t));
- if (mysql == NULL)
+ if (mysql == NULL) {
return (ISC_R_NOMEMORY);
+ }
memset(mysql, 0, sizeof(mysql_instance_t));
/* Fill in the helper functions */
va_start(ap, dbdata);
- while ((helper_name = va_arg(ap, const char*)) != NULL)
- b9_add_helper(mysql, helper_name, va_arg(ap, void*));
+ while ((helper_name = va_arg(ap, const char *)) != NULL) {
+ b9_add_helper(mysql, helper_name, va_arg(ap, void *));
+ }
va_end(ap);
#if PTHREADS
/* if debugging, let user know we are multithreaded. */
mysql->log(ISC_LOG_DEBUG(1), "MySQL module running multithreaded");
-#else /* PTHREADS */
+#else /* PTHREADS */
/* if debugging, let user know we are single threaded. */
mysql->log(ISC_LOG_DEBUG(1), "MySQL module running single threaded");
#endif /* PTHREADS */
/* verify we have at least 4 arg's passed to the module */
if (argc < 4) {
- mysql->log(ISC_LOG_ERROR,
- "MySQL module requires "
- "at least 4 command line args.");
+ mysql->log(ISC_LOG_ERROR, "MySQL module requires "
+ "at least 4 command line args.");
return (ISC_R_FAILURE);
}
/* no more than 8 arg's should be passed to the module */
if (argc > 8) {
- mysql->log(ISC_LOG_ERROR,
- "MySQL module cannot accept "
- "more than 7 command line args.");
+ mysql->log(ISC_LOG_ERROR, "MySQL module cannot accept "
+ "more than 7 command line args.");
return (ISC_R_FAILURE);
}
/* get db name - required */
mysql->dbname = get_parameter_value(argv[1], "dbname=");
if (mysql->dbname == NULL) {
- mysql->log(ISC_LOG_ERROR,
- "MySQL module requires a dbname parameter.");
+ mysql->log(ISC_LOG_ERROR, "MySQL module requires a dbname "
+ "parameter.");
result = ISC_R_FAILURE;
goto cleanup;
}
/* get db port. Not required, but must be > 0 if specified */
tmp = get_parameter_value(argv[1], "port=");
- if (tmp == NULL)
+ if (tmp == NULL) {
mysql->port = 0;
- else {
+ } else {
mysql->port = strtol(tmp, &endp, 10);
if (*endp != '\0' || mysql->port < 0) {
- mysql->log(ISC_LOG_ERROR,
- "Mysql module: port "
- "must be a positive number.");
+ mysql->log(ISC_LOG_ERROR, "Mysql module: port "
+ "must be a positive number.");
free(tmp);
result = ISC_R_FAILURE;
goto cleanup;
@@ -889,36 +894,39 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
tmp = get_parameter_value(argv[1], "compress=");
if (tmp != NULL) {
- if (strcasecmp(tmp, "true") == 0)
+ if (strcasecmp(tmp, "true") == 0) {
mysql->flags |= CLIENT_COMPRESS;
+ }
free(tmp);
}
tmp = get_parameter_value(argv[1], "ssl=");
if (tmp != NULL) {
- if (strcasecmp(tmp, "true") == 0)
+ if (strcasecmp(tmp, "true") == 0) {
mysql->flags |= CLIENT_SSL;
+ }
free(tmp);
}
tmp = get_parameter_value(argv[1], "space=");
if (tmp != NULL) {
- if (strcasecmp(tmp, "ignore") == 0)
+ if (strcasecmp(tmp, "ignore") == 0) {
mysql->flags |= CLIENT_IGNORE_SPACE;
+ }
free(tmp);
}
#if PTHREADS
/* multithreaded build can have multiple DB connections */
tmp = get_parameter_value(argv[1], "threads=");
- if (tmp == NULL)
+ if (tmp == NULL) {
dbcount = 1;
- else {
+ } else {
dbcount = strtol(tmp, &endp, 10);
if (*endp != '\0' || dbcount < 1) {
- mysql->log(ISC_LOG_ERROR,
- "MySQL database connection count "
- "must be positive.");
+ mysql->log(ISC_LOG_ERROR, "MySQL database connection "
+ "count "
+ "must be positive.");
free(tmp);
result = ISC_R_FAILURE;
goto cleanup;
@@ -942,26 +950,26 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
*/
for (i = 0; i < dbcount; i++) {
#endif /* PTHREADS */
- switch(argc) {
+ switch (argc) {
case 4:
- result = build_dbinstance(NULL, NULL, NULL,
- argv[2], argv[3], NULL,
- &dbi, mysql->log);
+ result = build_dbinstance(NULL, NULL, NULL, argv[2],
+ argv[3], NULL, &dbi,
+ mysql->log);
break;
case 5:
- result = build_dbinstance(NULL, NULL, argv[4],
- argv[2], argv[3], NULL,
- &dbi, mysql->log);
+ result = build_dbinstance(NULL, NULL, argv[4], argv[2],
+ argv[3], NULL, &dbi,
+ mysql->log);
break;
case 6:
result = build_dbinstance(argv[5], NULL, argv[4],
- argv[2], argv[3], NULL,
- &dbi, mysql->log);
+ argv[2], argv[3], NULL, &dbi,
+ mysql->log);
break;
case 7:
result = build_dbinstance(argv[5], argv[6], argv[4],
- argv[2], argv[3], NULL,
- &dbi, mysql->log);
+ argv[2], argv[3], NULL, &dbi,
+ mysql->log);
break;
case 8:
result = build_dbinstance(argv[5], argv[6], argv[4],
@@ -972,11 +980,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
result = ISC_R_FAILURE;
}
-
if (result != ISC_R_SUCCESS) {
- mysql->log(ISC_LOG_ERROR,
- "MySQL module could not create "
- "database instance object.");
+ mysql->log(ISC_LOG_ERROR, "MySQL module could not "
+ "create "
+ "database instance object.");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -985,52 +992,54 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* when multithreaded, build a list of DBI's */
DLZ_LINK_INIT(dbi, link);
DLZ_LIST_APPEND(*(mysql->db), dbi, link);
-#else
- /*
- * when single threaded, hold onto the one connection
- * instance.
- */
- mysql->db = dbi;
-#endif
+#else /* if PTHREADS */
+ /*
+ * when single threaded, hold onto the one connection
+ * instance.
+ */
+ mysql->db = dbi;
+#endif /* if PTHREADS */
/* create and set db connection */
dbi->dbconn = mysql_init(NULL);
if (dbi->dbconn == NULL) {
- mysql->log(ISC_LOG_ERROR,
- "MySQL module could not allocate "
- "memory for database connection");
+ mysql->log(ISC_LOG_ERROR, "MySQL module could not "
+ "allocate "
+ "memory for database "
+ "connection");
result = ISC_R_FAILURE;
goto cleanup;
}
dbc = NULL;
-#if MYSQL_VERSION_ID >= 50000
/* enable automatic reconnection. */
- if (mysql_options((MYSQL *) dbi->dbconn, MYSQL_OPT_RECONNECT,
- &auto_reconnect) != 0) {
- mysql->log(ISC_LOG_WARNING,
- "MySQL module failed to set "
- "MYSQL_OPT_RECONNECT option, continuing");
+ if (mysql_options((MYSQL *)dbi->dbconn, MYSQL_OPT_RECONNECT,
+ &(my_bool){ 1 }) != 0)
+ {
+ mysql->log(ISC_LOG_WARNING, "MySQL module failed to "
+ "set "
+ "MYSQL_OPT_RECONNECT "
+ "option, continuing");
}
-#endif
for (j = 0; dbc == NULL && j < 4; j++) {
- dbc = mysql_real_connect((MYSQL *) dbi->dbconn,
- mysql->host, mysql->user,
- mysql->pass, mysql->dbname,
- mysql->port, mysql->socket,
- mysql->flags);
- if (dbc == NULL)
+ dbc = mysql_real_connect(
+ (MYSQL *)dbi->dbconn, mysql->host, mysql->user,
+ mysql->pass, mysql->dbname, mysql->port,
+ mysql->socket, mysql->flags);
+ if (dbc == NULL) {
mysql->log(ISC_LOG_ERROR,
"MySQL connection failed: %s",
- mysql_error((MYSQL *) dbi->dbconn));
+ mysql_error((MYSQL *)dbi->dbconn));
+ }
}
if (dbc == NULL) {
- mysql->log(ISC_LOG_ERROR,
- "MySQL module failed to create "
- "database connection after 4 attempts");
+ mysql->log(ISC_LOG_ERROR, "MySQL module failed to "
+ "create "
+ "database connection after 4 "
+ "attempts");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -1045,7 +1054,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
dlz_destroy(mysql);
return (result);
@@ -1059,22 +1068,28 @@ dlz_destroy(void *dbdata) {
mysql_instance_t *db = (mysql_instance_t *)dbdata;
#if PTHREADS
/* cleanup the list of DBI's */
- if (db->db != NULL)
+ if (db->db != NULL) {
mysql_destroy_dblist((db_list_t *)(db->db));
-#else /* PTHREADS */
+ }
+#else /* PTHREADS */
mysql_destroy(db);
#endif /* PTHREADS */
- if (db->dbname != NULL)
+ if (db->dbname != NULL) {
free(db->dbname);
- if (db->host != NULL)
+ }
+ if (db->host != NULL) {
free(db->host);
- if (db->user != NULL)
+ }
+ if (db->user != NULL) {
free(db->user);
- if (db->pass != NULL)
+ }
+ if (db->pass != NULL) {
free(db->pass);
- if (db->socket != NULL)
+ }
+ if (db->socket != NULL) {
free(db->socket);
+ }
}
/*
@@ -1082,8 +1097,7 @@ dlz_destroy(void *dbdata) {
*/
int
dlz_version(unsigned int *flags) {
- *flags |= (DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA |
+ *flags |= (DNS_SDLZFLAG_RELATIVEOWNER | DNS_SDLZFLAG_RELATIVERDATA |
DNS_SDLZFLAG_THREADSAFE);
return (DLZ_DLOPEN_VERSION);
}
@@ -1093,12 +1107,16 @@ dlz_version(unsigned int *flags) {
*/
static void
b9_add_helper(mysql_instance_t *db, const char *helper_name, void *ptr) {
- if (strcmp(helper_name, "log") == 0)
+ if (strcmp(helper_name, "log") == 0) {
db->log = (log_t *)ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
db->putrr = (dns_sdlz_putrr_t *)ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
db->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
db->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
+ }
}
diff --git a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c
index 577ae65a..cb0620fd 100644
--- a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c
+++ b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c
@@ -40,27 +40,31 @@
* See README for database schema and usage details.
*/
+#include <ifaddrs.h>
+#include <inttypes.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdarg.h>
-#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
-#include <netinet/in.h>
-#include <inttypes.h>
-#include <pthread.h>
-#include <netdb.h>
-#include <ifaddrs.h>
+#include <unistd.h>
-#include <mysql/mysql.h>
#include <mysql/errmsg.h>
+#include <mysql/mysql.h>
-#include <dlz_minimal.h>
#include <dlz_list.h>
+#include <dlz_minimal.h>
#include <dlz_pthread.h>
+#if !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000
+typedef bool my_bool;
+#endif /* !defined(LIBMARIADB) && MYSQL_VERSION_ID >= 80000 */
+
/*
* The SQL queries that will be used for lookups and updates are defined
* here. They will be processed into queries by the build_query()
@@ -74,8 +78,8 @@
* Get the NS RRset for a zone
* Arguments: zone-name
*/
-#define Q_GETNS \
- "SELECT d.data FROM ZoneData d, Zones z " \
+#define Q_GETNS \
+ "SELECT d.data FROM ZoneData d, Zones z " \
"WHERE UPPER(d.type) = 'NS' AND LOWER(z.domain) = LOWER('%s') " \
"AND z.id = d.zone_id"
@@ -89,14 +93,13 @@
* Find a specific zone
* Arguments: zone-name
*/
-#define Q_FINDZONE \
- "SELECT id FROM Zones WHERE LOWER(domain) = LOWER('%s')"
+#define Q_FINDZONE "SELECT id FROM Zones WHERE LOWER(domain) = LOWER('%s')"
/*
* Get SOA data from zone apex
* Arguments: zone-name
*/
-#define Q_GETSOA \
+#define Q_GETSOA \
"SELECT host, admin, serial, refresh, retry, expire, minimum, ttl " \
"FROM Zones WHERE LOWER(domain) = LOWER('%s')"
@@ -104,27 +107,27 @@
* Get other data from zone apex
* Arguments: zone-name, zone-name (repeated)
*/
-#define Q_GETAPEX \
- "SELECT d.type, d.data, d.ttl FROM ZoneData d, Zones z " \
+#define Q_GETAPEX \
+ "SELECT d.type, d.data, d.ttl FROM ZoneData d, Zones z " \
"WHERE LOWER(z.domain) = LOWER('%s') AND z.id = d.zone_id " \
- "AND LOWER(d.name) IN (LOWER('%s'), '', '@') "\
+ "AND LOWER(d.name) IN (LOWER('%s'), '', '@') " \
"ORDER BY UPPER(d.type) ASC"
/*
* Get data from non-apex nodes
* Arguments: zone-name, node-name (relative to zone name)
*/
-#define Q_GETNODE \
- "SELECT d.type, d.data, d.ttl FROM ZoneData d, Zones z " \
+#define Q_GETNODE \
+ "SELECT d.type, d.data, d.ttl FROM ZoneData d, Zones z " \
"WHERE LOWER(z.domain) = LOWER('%s') AND z.id = d.zone_id " \
- "AND LOWER(d.name) = LOWER('%s') " \
+ "AND LOWER(d.name) = LOWER('%s') " \
"ORDER BY UPPER(d.type) ASC"
/*
* Get all data from a zone, for AXFR
* Arguments: zone-name
*/
-#define Q_GETALL \
+#define Q_GETALL \
"SELECT d.name, d.type, d.data, d.ttl FROM ZoneData d, Zones z " \
"WHERE LOWER(z.domain) = LOWER('%s') AND z.id = d.zone_id"
@@ -132,14 +135,13 @@
* Get SOA serial number for a zone.
* Arguments: zone-name
*/
-#define Q_GETSERIAL \
- "SELECT serial FROM Zones WHERE domain = '%s'"
+#define Q_GETSERIAL "SELECT serial FROM Zones WHERE domain = '%s'"
/*
* Determine whether a zone is writeable, and if so, retrieve zone_id
* Arguments: zone-name
*/
-#define Q_WRITEABLE \
+#define Q_WRITEABLE \
"SELECT id FROM Zones WHERE " \
"LOWER(domain) = LOWER('%s') AND writeable = 1"
@@ -148,7 +150,7 @@
* Arguments: zone-id (from Q_WRITEABLE), node-name (relative to zone-name),
* rrtype, rdata text, TTL (in text format)
*/
-#define I_DATA \
+#define I_DATA \
"INSERT INTO ZoneData (zone_id, name, type, data, ttl) " \
"VALUES (%s, LOWER('%s'), UPPER('%s'), '%s', %s)"
@@ -156,8 +158,7 @@
* Update SOA serial number for a zone
* Arguments: new serial number (in text format), zone-id (from Q_WRITEABLE)
*/
-#define U_SERIAL \
- "UPDATE Zones SET serial = %s WHERE id = %s"
+#define U_SERIAL "UPDATE Zones SET serial = %s WHERE id = %s"
/*
* Delete a specific record (non-SOA) from a zone
@@ -165,8 +166,8 @@
* Arguments: node-name (relative to zone-name), zone-id (from Q_WRITEABLE),
* rrtype, rdata text, TTL (in text format).
*/
-#define D_RECORD \
- "DELETE FROM ZoneData WHERE zone_id = %s AND " \
+#define D_RECORD \
+ "DELETE FROM ZoneData WHERE zone_id = %s AND " \
"LOWER(name) = LOWER('%s') AND UPPER(type) = UPPER('%s') AND " \
"data = '%s' AND ttl = %s"
@@ -175,7 +176,7 @@
* Arguments: node-name (relative to zone-name), zone-id (from Q_WRITEABLE),
* rrtype.
*/
-#define D_RRSET \
+#define D_RRSET \
"DELETE FROM ZoneData WHERE zone_id = %s AND " \
"LOWER(name) = LOWER('%s') AND UPPER(type) = UPPER('%s')"
@@ -262,22 +263,24 @@ db_connect(mysql_data_t *state, mysql_instance_t *dbi) {
*/
mysql_thread_init();
- if (dbi->connected)
+ if (dbi->connected) {
return (true);
+ }
- if (state->log != NULL)
- state->log(ISC_LOG_INFO, "%s: init connection %d ",
- modname, dbi->id);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO, "%s: init connection %d ", modname,
+ dbi->id);
+ }
- conn = mysql_real_connect(dbi->sock, state->db_host,
- state->db_user, state->db_pass,
- state->db_name, 0, NULL,
+ conn = mysql_real_connect(dbi->sock, state->db_host, state->db_user,
+ state->db_pass, state->db_name, 0, NULL,
CLIENT_REMEMBER_OPTIONS);
if (conn == NULL) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_ERROR,
"%s: database connection failed: %s",
modname, mysql_error(dbi->sock));
+ }
dlz_mutex_unlock(&dbi->mutex);
return (false);
@@ -295,14 +298,16 @@ get_dbi(mysql_data_t *state) {
* Find an available dbi
*/
for (i = 0; i < MAX_DBI; i++) {
- if (dlz_mutex_trylock(&state->db[i].mutex) == 0)
+ if (dlz_mutex_trylock(&state->db[i].mutex) == 0) {
break;
+ }
}
if (i == MAX_DBI) {
- if (state->debug && state->log != NULL)
+ if (state->debug && state->log != NULL) {
state->log(ISC_LOG_ERROR,
"%s: No available connections", modname);
+ }
return (NULL);
}
return (&state->db[i]);
@@ -316,10 +321,11 @@ static char *
sanitize(mysql_instance_t *dbi, const char *original) {
char *s;
- if (original == NULL)
+ if (original == NULL) {
return (NULL);
+ }
- s = (char *) malloc((strlen(original) * 2) + 1);
+ s = (char *)malloc((strlen(original) * 2) + 1);
if (s != NULL) {
memset(s, 0, (strlen(original) * 2) + 1);
@@ -339,8 +345,9 @@ additem(mysql_arglist_t *arglist, char **s, size_t *len) {
mysql_arg_t *item;
item = malloc(sizeof(*item));
- if (item == NULL)
+ if (item == NULL) {
return (ISC_R_NOMEMORY);
+ }
DLZ_LINK_INIT(item, link);
item->arg = *s;
@@ -362,9 +369,8 @@ additem(mysql_arglist_t *arglist, char **s, size_t *len) {
* otherwise we use the existing one.
*/
static char *
-build_query(mysql_data_t *state, mysql_instance_t *dbi,
- const char *command, ...)
-{
+build_query(mysql_data_t *state, mysql_instance_t *dbi, const char *command,
+ ...) {
isc_result_t result;
bool localdbi = false;
mysql_arglist_t arglist;
@@ -377,91 +383,108 @@ build_query(mysql_data_t *state, mysql_instance_t *dbi,
/* Get a DB instance if needed */
if (dbi == NULL) {
dbi = get_dbi(state);
- if (dbi == NULL)
+ if (dbi == NULL) {
return (NULL);
+ }
localdbi = true;
}
/* Make sure this instance is connected */
- if (!db_connect(state, dbi))
+ if (!db_connect(state, dbi)) {
goto fail;
+ }
va_start(ap1, command);
DLZ_LIST_INIT(arglist);
q = querystr = strdup(command);
- if (querystr == NULL)
+ if (querystr == NULL) {
goto fail;
+ }
for (;;) {
- if (*q == '\0')
+ if (*q == '\0') {
break;
+ }
p = strstr(q, "%s");
if (p != NULL) {
*p = '\0';
tmp = strdup(q);
- if (tmp == NULL)
+ if (tmp == NULL) {
goto fail;
+ }
result = additem(&arglist, &tmp, &len);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto fail;
+ }
tmp = sanitize(dbi, va_arg(ap1, const char *));
- if (tmp == NULL)
+ if (tmp == NULL) {
goto fail;
+ }
result = additem(&arglist, &tmp, &len);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto fail;
+ }
q = p + 2;
} else {
tmp = strdup(q);
- if (tmp == NULL)
+ if (tmp == NULL) {
goto fail;
+ }
result = additem(&arglist, &tmp, &len);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto fail;
+ }
break;
}
}
- if (len == 0)
+ if (len == 0) {
goto fail;
+ }
query = malloc(len + 1);
- if (query == NULL)
+ if (query == NULL) {
goto fail;
+ }
*query = '\0';
- for (item = DLZ_LIST_HEAD(arglist);
- item != NULL;
+ for (item = DLZ_LIST_HEAD(arglist); item != NULL;
item = DLZ_LIST_NEXT(item, link))
- if (item->arg != NULL)
+ {
+ if (item->arg != NULL) {
strcat(query, item->arg);
+ }
+ }
- fail:
+fail:
va_end(ap1);
- for (item = DLZ_LIST_HEAD(arglist);
- item != NULL;
+ for (item = DLZ_LIST_HEAD(arglist); item != NULL;
item = DLZ_LIST_NEXT(item, link))
{
- if (item->arg != NULL)
+ if (item->arg != NULL) {
free(item->arg);
+ }
free(item);
}
- if (tmp != NULL)
+ if (tmp != NULL) {
free(tmp);
- if (querystr != NULL)
- free (querystr);
+ }
+ if (querystr != NULL) {
+ free(querystr);
+ }
- if (dbi != NULL && localdbi)
+ if (dbi != NULL && localdbi) {
dlz_mutex_unlock(&dbi->mutex);
+ }
return (query);
}
@@ -469,8 +492,9 @@ build_query(mysql_data_t *state, mysql_instance_t *dbi,
/* Does this name end in a dot? */
static bool
isrelative(const char *s) {
- if (s == NULL || s[strlen(s) - 1] == '.')
+ if (s == NULL || s[strlen(s) - 1] == '.') {
return (false);
+ }
return (true);
}
@@ -487,16 +511,18 @@ dot(const char *s) {
*/
static void
fqhn(const char *name, const char *zone, char *dest) {
- if (dest == NULL)
+ if (dest == NULL) {
return;
+ }
- if (strlen(name) == 0 || strcmp(name, "@") == 0)
+ if (strlen(name) == 0 || strcmp(name, "@") == 0) {
sprintf(dest, "%s%s", zone, dot(zone));
- else {
- if (isrelative(name))
+ } else {
+ if (isrelative(name)) {
sprintf(dest, "%s.%s%s", name, zone, dot(zone));
- else
+ } else {
strcpy(dest, name);
+ }
}
}
@@ -510,9 +536,10 @@ relname(const char *name, const char *zone) {
const char *p;
char *new;
- new = (char *) malloc(strlen(name) + 1);
- if (new == NULL)
+ new = (char *)malloc(strlen(name) + 1);
+ if (new == NULL) {
return (NULL);
+ }
nlen = strlen(name);
zlen = strlen(zone);
@@ -527,8 +554,7 @@ relname(const char *name, const char *zone) {
p = name + nlen - zlen;
if (strcasecmp(p, zone) != 0 &&
- (zone[zlen - 1] != '.' ||
- strncasecmp(p, zone, zlen - 1) != 0))
+ (zone[zlen - 1] != '.' || strncasecmp(p, zone, zlen - 1) != 0))
{
strcpy(new, name);
return (new);
@@ -553,8 +579,9 @@ validate_txn(mysql_data_t *state, mysql_transaction_t *txn) {
}
dlz_mutex_unlock(&state->tx_mutex);
- if (result != ISC_R_SUCCESS && state->log != NULL)
+ if (result != ISC_R_SUCCESS && state->log != NULL) {
state->log(ISC_LOG_ERROR, "%s: invalid txn %x", modname, txn);
+ }
return (result);
}
@@ -564,21 +591,23 @@ db_execute(mysql_data_t *state, mysql_instance_t *dbi, const char *query) {
int ret;
/* Make sure this instance is connected. */
- if (!db_connect(state, dbi))
+ if (!db_connect(state, dbi)) {
return (ISC_R_FAILURE);
+ }
ret = mysql_real_query(dbi->sock, query, strlen(query));
if (ret != 0) {
- if (state->debug && state->log != NULL)
- state->log(ISC_LOG_ERROR,
- "%s: query '%s' failed: %s",
+ if (state->debug && state->log != NULL) {
+ state->log(ISC_LOG_ERROR, "%s: query '%s' failed: %s",
modname, query, mysql_error(dbi->sock));
+ }
return (ISC_R_FAILURE);
}
- if (state->debug && state->log != NULL)
- state->log(ISC_LOG_INFO, "%s: execute(%d) %s",
- modname, dbi->id, query);
+ if (state->debug && state->log != NULL) {
+ state->log(ISC_LOG_INFO, "%s: execute(%d) %s", modname, dbi->id,
+ query);
+ }
return (ISC_R_SUCCESS);
}
@@ -589,42 +618,48 @@ db_query(mysql_data_t *state, mysql_instance_t *dbi, const char *query) {
bool localdbi = false;
MYSQL_RES *res = NULL;
- if (query == NULL)
+ if (query == NULL) {
return (NULL);
+ }
/* Get a DB instance if needed */
if (dbi == NULL) {
dbi = get_dbi(state);
- if (dbi == NULL)
+ if (dbi == NULL) {
return (NULL);
+ }
localdbi = true;
}
/* Make sure this instance is connected */
- if (!db_connect(state, dbi))
+ if (!db_connect(state, dbi)) {
goto fail;
+ }
result = db_execute(state, dbi, query);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto fail;
+ }
res = mysql_store_result(dbi->sock);
if (res == NULL) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_ERROR,
- "%s: unable to store result: %s",
- modname, mysql_error(dbi->sock));
+ "%s: unable to store result: %s", modname,
+ mysql_error(dbi->sock));
+ }
goto fail;
}
- if (state->debug && state->log != NULL)
- state->log(ISC_LOG_INFO,
- "%s: query(%d) returned %d rows",
+ if (state->debug && state->log != NULL) {
+ state->log(ISC_LOG_INFO, "%s: query(%d) returned %d rows",
modname, dbi->id, mysql_num_rows(res));
+ }
- fail:
- if (dbi != NULL && localdbi)
+fail:
+ if (dbi != NULL && localdbi) {
dlz_mutex_unlock(&dbi->mutex);
+ }
return (res);
}
@@ -644,10 +679,11 @@ db_query(mysql_data_t *state, mysql_instance_t *dbi, const char *query) {
static unsigned char *
make_notify(const char *zone, int *packetlen) {
int i, j;
- unsigned char *packet = (unsigned char *) malloc(strlen(zone) + 18);
+ unsigned char *packet = (unsigned char *)malloc(strlen(zone) + 18);
- if (packet == NULL)
+ if (packet == NULL) {
return (NULL);
+ }
*packetlen = strlen(zone) + 18;
memset(packet, 0, *packetlen);
@@ -669,13 +705,14 @@ make_notify(const char *zone, int *packetlen) {
/* Question */
packet[12] = '.';
- memcpy(&packet[13], zone, strlen(zone));
+ memmove(&packet[13], zone, strlen(zone));
packet[13 + strlen(zone)] = 0;
/* Make the question into labels */
j = 12;
while (packet[j]) {
- for (i = j + 1; packet[i] != '\0' && packet[i] != '.'; i++);
+ for (i = j + 1; packet[i] != '\0' && packet[i] != '.'; i++)
+ ;
packet[j] = i - j - 1;
j = i;
}
@@ -700,8 +737,9 @@ send_notify(struct sockaddr_in *addr, const unsigned char *p, const int plen) {
addr->sin_family = AF_INET;
addr->sin_port = htons(53);
- if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0)
+ if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
return;
+ }
sendto(s, p, plen, 0, (struct sockaddr *)addr, sizeof(*addr));
close(s);
@@ -725,9 +763,10 @@ notify(mysql_data_t *state, const char *zone, int sn) {
/* Get the name servers from the NS rrset */
query = build_query(state, NULL, Q_GETNS, zone);
res = db_query(state, NULL, query);
- free (query);
- if (res == NULL)
+ free(query);
+ if (res == NULL) {
return;
+ }
/* Create a DNS NOTIFY packet */
packet = make_notify(zone, &packetlen);
@@ -737,8 +776,9 @@ notify(mysql_data_t *state, const char *zone, int sn) {
}
/* Get a list of our own addresses */
- if (getifaddrs(&ifap) < 0)
+ if (getifaddrs(&ifap) < 0) {
ifap = NULL;
+ }
/* Tell each nameserver of the update */
while ((row = mysql_fetch_row(res)) != NULL) {
@@ -752,10 +792,11 @@ notify(mysql_data_t *state, const char *zone, int sn) {
* this to inet_pton/getaddrinfo.)
*/
h = gethostbyname(row[0]);
- if (h == NULL)
+ if (h == NULL) {
continue;
+ }
- memcpy(&addr.sin_addr, h->h_addr, h->h_length);
+ memmove(&addr.sin_addr, h->h_addr, h->h_length);
addrp = &addr.sin_addr;
/* Get the address for the nameserver into a string */
@@ -763,32 +804,36 @@ notify(mysql_data_t *state, const char *zone, int sn) {
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
char ifaddr[INET_ADDRSTRLEN];
- if (ifa->ifa_addr->sa_family != AF_INET)
+ if (ifa->ifa_addr->sa_family != AF_INET) {
continue;
+ }
/* Get local address into a string */
- sin = (struct sockaddr_in *) ifa->ifa_addr;
+ sin = (struct sockaddr_in *)ifa->ifa_addr;
addrp = &sin->sin_addr;
inet_ntop(AF_INET, addrp, ifaddr, INET_ADDRSTRLEN);
/* See if nameserver address matches this one */
- if (strcmp(ifaddr, zaddr) == 0)
+ if (strcmp(ifaddr, zaddr) == 0) {
local = true;
+ }
}
if (!local) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_INFO,
"%s: notify %s zone %s serial %d",
modname, row[0], zone, sn);
+ }
send_notify(&addr, packet, packetlen);
}
}
mysql_free_result(res);
free(packet);
- if (ifap != NULL)
+ if (ifap != NULL) {
freeifaddrs(ifap);
+ }
}
/*
@@ -798,26 +843,29 @@ notify(mysql_data_t *state, const char *zone, int sn) {
static mysql_record_t *
makerecord(mysql_data_t *state, const char *name, const char *rdatastr) {
mysql_record_t *new_record;
- char *real_name, *dclass, *type, *data, *ttlstr, *buf;
+ char *real_name = NULL, *dclass = NULL, *type = NULL;
+ char *data = NULL, *ttlstr = NULL, *buf = NULL;
+ char *saveptr = NULL;
dns_ttl_t ttlvalue;
- new_record = (mysql_record_t *)
- malloc(sizeof(mysql_record_t));
+ new_record = (mysql_record_t *)malloc(sizeof(mysql_record_t));
if (new_record == NULL) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_ERROR,
"%s: makerecord - unable to malloc",
modname);
+ }
return (NULL);
}
buf = strdup(rdatastr);
if (buf == NULL) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_ERROR,
"%s: makerecord - unable to malloc",
modname);
+ }
free(new_record);
return (NULL);
}
@@ -830,24 +878,29 @@ makerecord(mysql_data_t *state, const char *name, const char *rdatastr) {
* for the type used by dig
*/
real_name = strtok_r(buf, "\t", &saveptr);
- if (real_name == NULL)
+ if (real_name == NULL) {
goto error;
+ }
ttlstr = strtok_r(NULL, "\t", &saveptr);
- if (ttlstr == NULL || sscanf(ttlstr, "%d", &ttlvalue) != 1)
+ if (ttlstr == NULL || sscanf(ttlstr, "%d", &ttlvalue) != 1) {
goto error;
+ }
dclass = strtok_r(NULL, "\t", &saveptr);
- if (dclass == NULL)
+ if (dclass == NULL) {
goto error;
+ }
type = strtok_r(NULL, "\t", &saveptr);
- if (type == NULL)
+ if (type == NULL) {
goto error;
+ }
data = strtok_r(NULL, "\t", &saveptr);
- if (data == NULL)
+ if (data == NULL) {
goto error;
+ }
strcpy(new_record->name, name);
strcpy(new_record->type, type);
@@ -857,7 +910,7 @@ makerecord(mysql_data_t *state, const char *name, const char *rdatastr) {
free(buf);
return (new_record);
- error:
+error:
free(buf);
free(new_record);
return (NULL);
@@ -868,14 +921,18 @@ makerecord(mysql_data_t *state, const char *name, const char *rdatastr) {
*/
static void
b9_add_helper(mysql_data_t *state, const char *helper_name, void *ptr) {
- if (strcmp(helper_name, "log") == 0)
+ if (strcmp(helper_name, "log") == 0) {
state->log = (log_t *)ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
state->putrr = (dns_sdlz_putrr_t *)ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
state->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
state->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
+ }
}
/*
@@ -896,9 +953,8 @@ dlz_version(unsigned int *flags) {
* Called to initialize the driver
*/
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
mysql_data_t *state;
const char *helper_name;
va_list ap;
@@ -907,26 +963,31 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
UNUSED(dlzname);
state = calloc(1, sizeof(mysql_data_t));
- if (state == NULL)
+ if (state == NULL) {
return (ISC_R_NOMEMORY);
+ }
dlz_mutex_init(&state->tx_mutex, NULL);
state->transactions = NULL;
/* Fill in the helper functions */
va_start(ap, dbdata);
- while ((helper_name = va_arg(ap, const char *)) != NULL)
+ while ((helper_name = va_arg(ap, const char *)) != NULL) {
b9_add_helper(state, helper_name, va_arg(ap, void *));
+ }
va_end(ap);
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_INFO, "loading %s module", modname);
+ }
if ((argc < 2) || (argc > 6)) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_ERROR,
"%s: missing args <dbname> "
- "[<dbhost> [<user> <pass>]]", modname);
+ "[<dbhost> [<user> <pass>]]",
+ modname);
+ }
dlz_destroy(state);
return (ISC_R_FAILURE);
}
@@ -947,17 +1008,15 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
state->db_pass = strdup("");
}
- if (state->log != NULL)
- state->log(ISC_LOG_INFO,
- "%s: DB=%s, Host=%s, User=%s",
- modname, state->db_name,
- state->db_host, state->db_user);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_INFO, "%s: DB=%s, Host=%s, User=%s", modname,
+ state->db_name, state->db_host, state->db_user);
+ }
/*
* Assign the 'state' to dbdata so we get it in our callbacks
*/
-
dlz_mutex_lock(&state->tx_mutex);
/*
@@ -965,17 +1024,15 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
*/
if (mysql_thread_safe()) {
for (n = 0; n < MAX_DBI; n++) {
- my_bool opt = 1;
dlz_mutex_init(&state->db[n].mutex, NULL);
dlz_mutex_lock(&state->db[n].mutex);
state->db[n].id = n;
state->db[n].connected = 0;
state->db[n].sock = mysql_init(NULL);
mysql_options(state->db[n].sock,
- MYSQL_READ_DEFAULT_GROUP,
- modname);
- mysql_options(state->db[n].sock,
- MYSQL_OPT_RECONNECT, &opt);
+ MYSQL_READ_DEFAULT_GROUP, modname);
+ mysql_options(state->db[n].sock, MYSQL_OPT_RECONNECT,
+ &(my_bool){ 1 });
dlz_mutex_unlock(&state->db[n].mutex);
}
@@ -1001,13 +1058,14 @@ dlz_destroy(void *dbdata) {
mysql_data_t *state = (mysql_data_t *)dbdata;
int i;
- if (state->debug && state->log != NULL)
+ if (state->debug && state->log != NULL) {
state->log(ISC_LOG_INFO, "%s: shutting down", modname);
+ }
for (i = 0; i < MAX_DBI; i++) {
if (state->db[i].sock) {
mysql_close(state->db[i].sock);
- state->db[i].sock=NULL;
+ state->db[i].sock = NULL;
}
}
free(state->db_name);
@@ -1022,10 +1080,8 @@ dlz_destroy(void *dbdata) {
* See if we handle a given zone
*/
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result = ISC_R_SUCCESS;
mysql_data_t *state = (mysql_data_t *)dbdata;
MYSQL_RES *res;
@@ -1034,15 +1090,18 @@ dlz_findzonedb(void *dbdata, const char *name,
/* Query the Zones table to see if this zone is present */
query = build_query(state, NULL, Q_FINDZONE, name);
- if (query == NULL)
+ if (query == NULL) {
return (ISC_R_NOMEMORY);
+ }
res = db_query(state, NULL, query);
- if (res == NULL)
+ if (res == NULL) {
return (ISC_R_FAILURE);
+ }
- if (mysql_num_rows(res) == 0)
+ if (mysql_num_rows(res) == 0) {
result = ISC_R_NOTFOUND;
+ }
mysql_free_result(res);
return (result);
@@ -1054,8 +1113,7 @@ dlz_findzonedb(void *dbdata, const char *name,
isc_result_t
dlz_lookup(const char *zone, const char *name, void *dbdata,
dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
mysql_data_t *state = (mysql_data_t *)dbdata;
bool found = false;
@@ -1067,18 +1125,20 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
mysql_instance_t *dbi = NULL;
if (state->putrr == NULL) {
- if (state->log != NULL)
- state->log(ISC_LOG_ERROR,
- "%s: dlz_lookup - no putrr", modname);
+ if (state->log != NULL) {
+ state->log(ISC_LOG_ERROR, "%s: dlz_lookup - no putrr",
+ modname);
+ }
return (ISC_R_NOTIMPLEMENTED);
}
/* Are we okay to try to find the txn version? */
- if (clientinfo != NULL &&
- clientinfo->version >= DNS_CLIENTINFO_VERSION) {
- txn = (mysql_transaction_t *) clientinfo->dbversion;
- if (txn != NULL && validate_txn(state, txn) == ISC_R_SUCCESS)
+ if (clientinfo != NULL && clientinfo->version >= DNS_CLIENTINFO_VERSION)
+ {
+ txn = (mysql_transaction_t *)clientinfo->dbversion;
+ if (txn != NULL && validate_txn(state, txn) == ISC_R_SUCCESS) {
dbi = txn->dbi;
+ }
if (dbi != NULL) {
state->log(ISC_LOG_DEBUG(1),
"%s: lookup in live transaction %p, DBI %p",
@@ -1087,14 +1147,16 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
}
if (strcmp(name, "@") == 0) {
- real_name = (char *) malloc(strlen(zone) + 1);
- if (real_name == NULL)
+ real_name = (char *)malloc(strlen(zone) + 1);
+ if (real_name == NULL) {
return (ISC_R_NOMEMORY);
+ }
strcpy(real_name, zone);
} else {
- real_name = (char *) malloc(strlen(name) + 1);
- if (real_name == NULL)
+ real_name = (char *)malloc(strlen(name) + 1);
+ if (real_name == NULL) {
return (ISC_R_NOMEMORY);
+ }
strcpy(real_name, name);
}
@@ -1110,7 +1172,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
}
res = db_query(state, dbi, query);
- free (query);
+ free(query);
if (res == NULL) {
free(real_name);
@@ -1118,7 +1180,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
}
while ((row = mysql_fetch_row(res)) != NULL) {
- char host[1024], admin[1024], data[1024];
+ char host[1024], admin[1024], data[4096];
int ttl;
sscanf(row[7], "%d", &ttl);
@@ -1126,9 +1188,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
fqhn(row[1], zone, admin);
/* zone admin serial refresh retry expire min */
- sprintf(data, "%s%s %s%s %s %s %s %s %s",
- host, dot(host), admin, dot(admin),
- row[2], row[3], row[4], row[5], row[6]);
+ snprintf(data, sizeof(data), "%s%s %s%s %s %s %s %s %s",
+ host, dot(host), admin, dot(admin), row[2],
+ row[3], row[4], row[5], row[6]);
result = state->putrr(lookup, "soa", ttl, data);
if (result != ISC_R_SUCCESS) {
@@ -1144,8 +1206,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
* Now we'll get the rest of the apex data
*/
query = build_query(state, dbi, Q_GETAPEX, zone, real_name);
- } else
+ } else {
query = build_query(state, dbi, Q_GETNODE, zone, real_name);
+ }
res = db_query(state, dbi, query);
free(query);
@@ -1168,17 +1231,17 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
found = true;
}
- if (state->debug && state->log != NULL)
- state->log(ISC_LOG_INFO,
- "%s: dlz_lookup %s/%s/%s - (%d rows)",
- modname, name, real_name, zone,
- mysql_num_rows(res));
+ if (state->debug && state->log != NULL) {
+ state->log(ISC_LOG_INFO, "%s: dlz_lookup %s/%s/%s - (%d rows)",
+ modname, name, real_name, zone, mysql_num_rows(res));
+ }
mysql_free_result(res);
free(real_name);
- if (!found)
+ if (!found) {
return (ISC_R_NOTFOUND);
+ }
return (ISC_R_SUCCESS);
}
@@ -1190,9 +1253,10 @@ isc_result_t
dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
mysql_data_t *state = (mysql_data_t *)dbdata;
- if (state->debug && state->log != NULL)
- state->log(ISC_LOG_INFO,
- "dlz_allowzonexfr: %s %s", name, client);
+ if (state->debug && state->log != NULL) {
+ state->log(ISC_LOG_INFO, "dlz_allowzonexfr: %s %s", name,
+ client);
+ }
/* Just say yes for all our zones */
return (dlz_findzonedb(dbdata, name, NULL, NULL));
@@ -1211,23 +1275,27 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
UNUSED(zone);
- if (state->debug && (state->log != NULL))
+ if (state->debug && (state->log != NULL)) {
state->log(ISC_LOG_INFO, "dlz_allnodes: %s", zone);
+ }
- if (state->putnamedrr == NULL)
+ if (state->putnamedrr == NULL) {
return (ISC_R_NOTIMPLEMENTED);
+ }
/*
* Get all the ZoneData for this zone
*/
query = build_query(state, NULL, Q_GETALL, zone);
- if (query == NULL)
+ if (query == NULL) {
return (ISC_R_NOMEMORY);
+ }
res = db_query(state, NULL, query);
free(query);
- if (res == NULL)
+ if (res == NULL) {
return (ISC_R_NOTFOUND);
+ }
while ((row = mysql_fetch_row(res)) != NULL) {
char hostname[1024];
@@ -1235,10 +1303,11 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
sscanf(row[3], "%d", &ttl);
fqhn(row[0], zone, hostname);
- result = state->putnamedrr(allnodes, hostname,
- row[1], ttl, row[2]);
- if (result != ISC_R_SUCCESS)
+ result = state->putnamedrr(allnodes, hostname, row[1], ttl,
+ row[2]);
+ if (result != ISC_R_SUCCESS) {
break;
+ }
}
mysql_free_result(res);
@@ -1251,7 +1320,7 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
isc_result_t
dlz_newversion(const char *zone, void *dbdata, void **versionp) {
isc_result_t result = ISC_R_FAILURE;
- mysql_data_t *state = (mysql_data_t *) dbdata;
+ mysql_data_t *state = (mysql_data_t *)dbdata;
MYSQL_RES *res;
MYSQL_ROW row;
char *query;
@@ -1262,13 +1331,15 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) {
* Check Zone is writable
*/
query = build_query(state, NULL, Q_WRITEABLE, zone);
- if (query == NULL)
+ if (query == NULL) {
return (ISC_R_NOMEMORY);
+ }
res = db_query(state, NULL, query);
free(query);
- if (res == NULL)
+ if (res == NULL) {
return (ISC_R_FAILURE);
+ }
if ((row = mysql_fetch_row(res)) == NULL) {
mysql_free_result(res);
@@ -1284,10 +1355,12 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) {
dlz_mutex_lock(&state->tx_mutex);
for (txn = state->transactions; txn != NULL; txn = txn->next) {
if (strcmp(txn->zone, zone) == 0) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_ERROR,
- "%s: transaction already "
- "started for zone %s", modname, zone);
+ "%s: transaction already "
+ "started for zone %s",
+ modname, zone);
+ }
dlz_mutex_unlock(&state->tx_mutex);
return (ISC_R_FAILURE);
}
@@ -1296,10 +1369,21 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) {
/*
* Create new transaction
*/
- newtx = (mysql_transaction_t *)
- malloc(sizeof(mysql_transaction_t));
+ newtx = (mysql_transaction_t *)calloc(1, sizeof(mysql_transaction_t));
+ if (newtx == NULL) {
+ result = ISC_R_NOMEMORY;
+ goto cleanup;
+ }
newtx->zone = strdup(zone);
+ if (newtx->zone == NULL) {
+ result = ISC_R_NOMEMORY;
+ goto cleanup;
+ }
newtx->zone_id = strdup(zone_id);
+ if (newtx->zone_id == NULL) {
+ result = ISC_R_NOMEMORY;
+ goto cleanup;
+ }
newtx->dbi = get_dbi(state);
newtx->next = NULL;
@@ -1320,18 +1404,25 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) {
newtx->next = state->transactions;
state->transactions = newtx;
- if (state->debug && (state->log != NULL))
+ if (state->debug && (state->log != NULL)) {
state->log(ISC_LOG_INFO, "%s: New tx %x", modname, newtx);
+ }
- cleanup:
+cleanup:
dlz_mutex_unlock(&state->tx_mutex);
if (result == ISC_R_SUCCESS) {
- *versionp = (void *) newtx;
+ *versionp = (void *)newtx;
} else {
dlz_mutex_unlock(&state->tx_mutex);
- free(newtx->zone);
- free(newtx->zone_id);
- free(newtx);
+ if (newtx != NULL) {
+ if (newtx->zone != NULL) {
+ free(newtx->zone);
+ }
+ if (newtx->zone != NULL) {
+ free(newtx->zone_id);
+ }
+ free(newtx);
+ }
}
return (result);
@@ -1341,9 +1432,7 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) {
* End a transaction
*/
void
-dlz_closeversion(const char *zone, bool commit,
- void *dbdata, void **versionp)
-{
+dlz_closeversion(const char *zone, bool commit, void *dbdata, void **versionp) {
isc_result_t result;
mysql_data_t *state = (mysql_data_t *)dbdata;
mysql_transaction_t *txn = (mysql_transaction_t *)*versionp;
@@ -1400,8 +1489,9 @@ dlz_closeversion(const char *zone, bool commit,
res = db_query(state, txn->dbi, query);
if (res != NULL) {
- while ((row = mysql_fetch_row(res)) != NULL)
+ while ((row = mysql_fetch_row(res)) != NULL) {
sscanf(row[0], "%d", &oldsn);
+ }
mysql_free_result(res);
}
@@ -1416,11 +1506,12 @@ dlz_closeversion(const char *zone, bool commit,
return;
}
- if (state->debug && state->log != NULL)
+ if (state->debug && state->log != NULL) {
state->log(ISC_LOG_INFO,
"%s: (%x) committing transaction "
"on zone %s",
modname, txn, zone);
+ }
/*
* Now get the serial number again
@@ -1430,22 +1521,25 @@ dlz_closeversion(const char *zone, bool commit,
free(query);
if (res != NULL) {
- while ((row = mysql_fetch_row(res)) != NULL)
+ while ((row = mysql_fetch_row(res)) != NULL) {
sscanf(row[0], "%d", &newsn);
+ }
mysql_free_result(res);
}
/*
* Look to see if serial numbers have changed
*/
- if (newsn > oldsn)
+ if (newsn > oldsn) {
notify(state, zone, newsn);
+ }
} else {
result = db_execute(state, txn->dbi, "ROLLBACK");
- if (state->debug && (state->log != NULL))
+ if (state->debug && (state->log != NULL)) {
state->log(ISC_LOG_INFO,
"%s: (%x) roll back transaction on zone %s",
modname, txn, zone);
+ }
}
/*
@@ -1467,7 +1561,7 @@ dlz_closeversion(const char *zone, bool commit,
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_configure(dns_view_t *view, void *dbdata)
-#else /* DLZ_DLOPEN_VERSION >= 3 */
+#else /* DLZ_DLOPEN_VERSION >= 3 */
isc_result_t
dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata)
#endif /* DLZ_DLOPEN_VERSION */
@@ -1483,14 +1577,16 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata)
*/
srand(getpid());
- if (state->debug && state->log != NULL)
+ if (state->debug && state->log != NULL) {
state->log(ISC_LOG_INFO, "%s: dlz_confgure", modname);
+ }
if (state->writeable_zone == NULL) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_ERROR,
"%s: no writeable_zone method available",
modname);
+ }
return (ISC_R_FAILURE);
}
@@ -1498,8 +1594,9 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata)
* Get a list of Zones (ignore writeable column at this point)
*/
res = db_query(state, NULL, Q_GETZONES);
- if (res == NULL)
+ if (res == NULL) {
return (ISC_R_FAILURE);
+ }
count = 0;
while ((row = mysql_fetch_row(res)) != NULL) {
@@ -1509,13 +1606,14 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata)
result = state->writeable_zone(view,
#if DLZ_DLOPEN_VERSION >= 3
dlzdb,
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 3 */
row[0]);
if (result != ISC_R_SUCCESS) {
- if (state->log != NULL)
+ if (state->log != NULL) {
state->log(ISC_LOG_ERROR,
"%s: failed to configure zone %s",
modname, row[0]);
+ }
mysql_free_result(res);
return (result);
}
@@ -1523,9 +1621,10 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata)
}
mysql_free_result(res);
- if (state->debug && state->log != NULL)
- state->log(ISC_LOG_INFO,
- "%s: configured %d zones", modname, count);
+ if (state->debug && state->log != NULL) {
+ state->log(ISC_LOG_INFO, "%s: configured %d zones", modname,
+ count);
+ }
return (ISC_R_SUCCESS);
}
@@ -1535,8 +1634,7 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata)
bool
dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr,
const char *type, const char *key, uint32_t keydatalen,
- unsigned char *keydata, void *dbdata)
-{
+ unsigned char *keydata, void *dbdata) {
mysql_data_t *state = (mysql_data_t *)dbdata;
UNUSED(tcpaddr);
@@ -1545,44 +1643,46 @@ dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr,
UNUSED(keydata);
UNUSED(key);
- if (state->debug && state->log != NULL)
- state->log(ISC_LOG_INFO,
- "%s: allowing update of %s by key %s",
+ if (state->debug && state->log != NULL) {
+ state->log(ISC_LOG_INFO, "%s: allowing update of %s by key %s",
modname, name, signer);
+ }
return (true);
}
isc_result_t
-dlz_addrdataset(const char *name, const char *rdatastr,
- void *dbdata, void *version)
-{
+dlz_addrdataset(const char *name, const char *rdatastr, void *dbdata,
+ void *version) {
mysql_data_t *state = (mysql_data_t *)dbdata;
mysql_transaction_t *txn = (mysql_transaction_t *)version;
char *new_name, *query;
mysql_record_t *record;
isc_result_t result;
- if (txn == NULL)
+ if (txn == NULL) {
return (ISC_R_FAILURE);
+ }
new_name = relname(name, txn->zone);
- if (new_name == NULL)
+ if (new_name == NULL) {
return (ISC_R_NOMEMORY);
+ }
- if (state->debug && (state->log != NULL))
- state->log(ISC_LOG_INFO, "%s: add (%x) %s (as %s) %s",
- modname, version, name, new_name, rdatastr);
+ if (state->debug && (state->log != NULL)) {
+ state->log(ISC_LOG_INFO, "%s: add (%x) %s (as %s) %s", modname,
+ version, name, new_name, rdatastr);
+ }
record = makerecord(state, new_name, rdatastr);
free(new_name);
- if (record == NULL)
+ if (record == NULL) {
return (ISC_R_FAILURE);
+ }
/* Write out data to database */
if (strcasecmp(record->type, "SOA") != 0) {
- query = build_query(state, txn->dbi, I_DATA,
- txn->zone_id, record->name,
- record->type, record->data,
+ query = build_query(state, txn->dbi, I_DATA, txn->zone_id,
+ record->name, record->type, record->data,
record->ttl);
if (query == NULL) {
result = ISC_R_FAILURE;
@@ -1608,45 +1708,47 @@ dlz_addrdataset(const char *name, const char *rdatastr,
free(query);
}
- cleanup:
+cleanup:
free(record);
return (result);
}
isc_result_t
-dlz_subrdataset(const char *name, const char *rdatastr,
- void *dbdata, void *version)
-{
+dlz_subrdataset(const char *name, const char *rdatastr, void *dbdata,
+ void *version) {
mysql_data_t *state = (mysql_data_t *)dbdata;
mysql_transaction_t *txn = (mysql_transaction_t *)version;
char *new_name, *query;
mysql_record_t *record;
isc_result_t result;
- if (txn == NULL)
+ if (txn == NULL) {
return (ISC_R_FAILURE);
+ }
new_name = relname(name, txn->zone);
- if (new_name == NULL)
+ if (new_name == NULL) {
return (ISC_R_NOMEMORY);
+ }
- if (state->debug && (state->log != NULL))
- state->log(ISC_LOG_INFO, "%s: sub (%x) %s %s",
- modname, version, name, rdatastr);
+ if (state->debug && (state->log != NULL)) {
+ state->log(ISC_LOG_INFO, "%s: sub (%x) %s %s", modname, version,
+ name, rdatastr);
+ }
record = makerecord(state, new_name, rdatastr);
free(new_name);
- if (record == NULL)
+ if (record == NULL) {
return (ISC_R_FAILURE);
+ }
/*
* If 'type' isn't 'SOA', delete the records
*/
- if (strcasecmp(record->type, "SOA") == 0)
+ if (strcasecmp(record->type, "SOA") == 0) {
result = ISC_R_SUCCESS;
- else {
- query = build_query(state, txn->dbi, D_RECORD,
- txn->zone_id, record->name,
- record->type, record->data,
+ } else {
+ query = build_query(state, txn->dbi, D_RECORD, txn->zone_id,
+ record->name, record->type, record->data,
record->ttl);
if (query == NULL) {
result = ISC_R_NOMEMORY;
@@ -1657,33 +1759,35 @@ dlz_subrdataset(const char *name, const char *rdatastr,
free(query);
}
- cleanup:
+cleanup:
free(record);
return (result);
}
isc_result_t
-dlz_delrdataset(const char *name, const char *type,
- void *dbdata, void *version)
-{
+dlz_delrdataset(const char *name, const char *type, void *dbdata,
+ void *version) {
mysql_data_t *state = (mysql_data_t *)dbdata;
mysql_transaction_t *txn = (mysql_transaction_t *)version;
char *new_name, *query;
isc_result_t result;
- if (txn == NULL)
+ if (txn == NULL) {
return (ISC_R_FAILURE);
+ }
new_name = relname(name, txn->zone);
- if (new_name == NULL)
+ if (new_name == NULL) {
return (ISC_R_NOMEMORY);
+ }
- if (state->debug && (state->log != NULL))
- state->log(ISC_LOG_INFO, "%s: del (%x) %s %s",
- modname, version, name, type);
+ if (state->debug && (state->log != NULL)) {
+ state->log(ISC_LOG_INFO, "%s: del (%x) %s %s", modname, version,
+ name, type);
+ }
- query = build_query(state, txn->dbi, D_RRSET,
- txn->zone_id, new_name, type);
+ query = build_query(state, txn->dbi, D_RRSET, txn->zone_id, new_name,
+ type);
if (query == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
@@ -1692,7 +1796,7 @@ dlz_delrdataset(const char *name, const char *type,
result = db_execute(state, txn->dbi, query);
free(query);
- cleanup:
+cleanup:
free(new_name);
return (result);
}
diff --git a/contrib/dlz/modules/perl/dlz_perl_driver.c b/contrib/dlz/modules/perl/dlz_perl_driver.c
index 2a9a44f5..15d4c9c6 100644
--- a/contrib/dlz/modules/perl/dlz_perl_driver.c
+++ b/contrib/dlz/modules/perl/dlz_perl_driver.c
@@ -57,25 +57,21 @@
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-
-#include <config.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
+#include "dlz_perl_driver.h"
#include <EXTERN.h>
#include <perl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <dlz_minimal.h>
-#include "dlz_perl_driver.h"
-
/* Enable debug logging? */
#if 0
-#define carp(...) cd->log(ISC_LOG_INFO, __VA_ARGS__);
-#else
+#define carp(...) cd->log(ISC_LOG_INFO, __VA_ARGS__);
+#else /* if 0 */
#define carp(...)
-#endif
+#endif /* if 0 */
#ifndef MULTIPLICITY
/* This is a pretty terrible work-around for handling HUP/rndc reconfig, but
@@ -85,12 +81,12 @@
* it properly and link against a perl compiled with multiplicity. */
static PerlInterpreter *global_perl = NULL;
static int global_perl_dont_free = 0;
-#endif
+#endif /* ifndef MULTIPLICITY */
typedef struct config_data {
- PerlInterpreter *perl;
- char *perl_source;
- SV *perl_class;
+ PerlInterpreter *perl;
+ char *perl_source;
+ SV *perl_class;
/* Functions given to us by bind9 */
log_t *log;
@@ -103,20 +99,23 @@ typedef struct config_data {
* is (almost) verbatim from perlembed, and is known to work correctly despite
* the warnings.
*/
-EXTERN_C void xs_init (pTHX);
-EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
-EXTERN_C void boot_DLZ_Perl__clientinfo (pTHX_ CV* cv);
-EXTERN_C void boot_DLZ_Perl (pTHX_ CV* cv);
+EXTERN_C void xs_init(pTHX);
EXTERN_C void
-xs_init(pTHX)
-{
- char *file = __FILE__;
- dXSUB_SYS;
-
- /* DynaLoader is a special case */
- newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
- newXS("DLZ_Perl::clientinfo::bootstrap", boot_DLZ_Perl__clientinfo, file);
- newXS("DLZ_Perl::bootstrap", boot_DLZ_Perl, file);
+boot_DynaLoader(pTHX_ CV *cv);
+EXTERN_C void
+boot_DLZ_Perl__clientinfo(pTHX_ CV *cv);
+EXTERN_C void
+boot_DLZ_Perl(pTHX_ CV *cv);
+EXTERN_C void
+xs_init(pTHX) {
+ char *file = __FILE__;
+ dXSUB_SYS;
+
+ /* DynaLoader is a special case */
+ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
+ newXS("DLZ_Perl::clientinfo::bootstrap", boot_DLZ_Perl__clientinfo,
+ file);
+ newXS("DLZ_Perl::bootstrap", boot_DLZ_Perl, file);
}
/*
@@ -126,27 +125,30 @@ xs_init(pTHX)
/*
* remember a helper function, from the bind9 dlz_dlopen driver
*/
-static void b9_add_helper(config_data_t *state,
- const char *helper_name, void *ptr)
-{
- if (strcmp(helper_name, "log") == 0)
+static void
+b9_add_helper(config_data_t *state, const char *helper_name, void *ptr) {
+ if (strcmp(helper_name, "log") == 0) {
state->log = ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
state->putrr = ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
state->putnamedrr = ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
state->writeable_zone = ptr;
+ }
}
-int dlz_version(unsigned int *flags) {
- return DLZ_DLOPEN_VERSION;
+int
+dlz_version(unsigned int *flags) {
+ return (DLZ_DLOPEN_VERSION);
}
-isc_result_t dlz_allnodes(const char *zone, void *dbdata,
- dns_sdlzallnodes_t *allnodes)
-{
- config_data_t *cd = (config_data_t *) dbdata;
+isc_result_t
+dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
+ config_data_t *cd = (config_data_t *)dbdata;
isc_result_t retval;
int rrcount, r;
SV *record_ref;
@@ -156,27 +158,29 @@ isc_result_t dlz_allnodes(const char *zone, void *dbdata,
SV **rr_data;
#ifdef MULTIPLICITY
PerlInterpreter *my_perl = cd->perl;
-#endif
+#endif /* ifdef MULTIPLICITY */
dSP;
PERL_SET_CONTEXT(cd->perl);
ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(cd->perl_class);
XPUSHs(sv_2mortal(newSVpv(zone, 0)));
PUTBACK;
carp("DLZ Perl: Calling allnodes for zone %s", zone);
- rrcount = call_method("allnodes", G_ARRAY|G_EVAL);
+ rrcount = call_method("allnodes", G_ARRAY | G_EVAL);
carp("DLZ Perl: Call to allnodes returned rrcount of %i", rrcount);
SPAGAIN;
if (SvTRUE(ERRSV)) {
POPs;
- cd->log(ISC_LOG_ERROR, "DLZ Perl: allnodes for zone %s died in eval: %s", zone, SvPV_nolen(ERRSV));
+ cd->log(ISC_LOG_ERROR,
+ "DLZ Perl: allnodes for zone %s died in eval: %s", zone,
+ SvPV_nolen(ERRSV));
retval = ISC_R_FAILURE;
goto CLEAN_UP_AND_RETURN;
}
@@ -190,10 +194,8 @@ isc_result_t dlz_allnodes(const char *zone, void *dbdata,
r = 0;
while (r++ < rrcount) {
record_ref = POPs;
- if (
- (!SvROK(record_ref)) ||
- (SvTYPE(SvRV(record_ref)) != SVt_PVAV)
- ) {
+ if ((!SvROK(record_ref)) ||
+ (SvTYPE(SvRV(record_ref)) != SVt_PVAV)) {
cd->log(ISC_LOG_ERROR,
"DLZ Perl: allnodes for zone %s "
"returned an invalid value "
@@ -205,14 +207,13 @@ isc_result_t dlz_allnodes(const char *zone, void *dbdata,
record_ref = SvRV(record_ref);
- rr_name = av_fetch((AV *) record_ref, 0, 0);
- rr_type = av_fetch((AV *) record_ref, 1, 0);
- rr_ttl = av_fetch((AV *) record_ref, 2, 0);
- rr_data = av_fetch((AV *) record_ref, 3, 0);
+ rr_name = av_fetch((AV *)record_ref, 0, 0);
+ rr_type = av_fetch((AV *)record_ref, 1, 0);
+ rr_ttl = av_fetch((AV *)record_ref, 2, 0);
+ rr_data = av_fetch((AV *)record_ref, 3, 0);
- if (rr_name == NULL || rr_type == NULL ||
- rr_ttl == NULL || rr_data == NULL)
- {
+ if (rr_name == NULL || rr_type == NULL || rr_ttl == NULL ||
+ rr_data == NULL) {
cd->log(ISC_LOG_ERROR,
"DLZ Perl: allnodes for zone %s "
"returned an array that was missing data",
@@ -221,13 +222,11 @@ isc_result_t dlz_allnodes(const char *zone, void *dbdata,
break;
}
- carp("DLZ Perl: Got record %s/%s = %s",
- SvPV_nolen(*rr_name), SvPV_nolen(*rr_type),
- SvPV_nolen(*rr_data));
- retval = cd->putnamedrr(allnodes,
- SvPV_nolen(*rr_name),
- SvPV_nolen(*rr_type),
- SvIV(*rr_ttl), SvPV_nolen(*rr_data));
+ carp("DLZ Perl: Got record %s/%s = %s", SvPV_nolen(*rr_name),
+ SvPV_nolen(*rr_type), SvPV_nolen(*rr_data));
+ retval = cd->putnamedrr(allnodes, SvPV_nolen(*rr_name),
+ SvPV_nolen(*rr_type), SvIV(*rr_ttl),
+ SvPV_nolen(*rr_data));
if (retval != ISC_R_SUCCESS) {
cd->log(ISC_LOG_ERROR,
"DLZ Perl: putnamedrr in allnodes "
@@ -243,33 +242,33 @@ CLEAN_UP_AND_RETURN:
FREETMPS;
LEAVE;
- carp("DLZ Perl: Returning from allnodes, r = %i, retval = %i",
- r, retval);
+ carp("DLZ Perl: Returning from allnodes, r = %i, retval = %i", r,
+ retval);
return (retval);
}
isc_result_t
dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
int r;
isc_result_t retval;
#ifdef MULTIPLICITY
PerlInterpreter *my_perl = cd->perl;
-#endif
+#endif /* ifdef MULTIPLICITY */
dSP;
PERL_SET_CONTEXT(cd->perl);
ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(cd->perl_class);
XPUSHs(sv_2mortal(newSVpv(name, 0)));
XPUSHs(sv_2mortal(newSVpv(client, 0)));
PUTBACK;
- r = call_method("allowzonexfr", G_SCALAR|G_EVAL);
+ r = call_method("allowzonexfr", G_SCALAR | G_EVAL);
SPAGAIN;
if (SvTRUE(ERRSV)) {
@@ -285,12 +284,14 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
retval = ISC_R_FAILURE;
} else if (r == 0) {
/* Client returned nothing -- zone not found. */
- retval = ISC_R_NOTFOUND;
+ retval = ISC_R_NOTFOUND;
} else if (r > 1) {
/* Once again, clean out the stack when possible. */
- while (r--) POPi;
- cd->log(ISC_LOG_ERROR,
- "DLZ Perl: allowzonexfr returned too many parameters!");
+ while (r--) {
+ POPi;
+ }
+ cd->log(ISC_LOG_ERROR, "DLZ Perl: allowzonexfr returned too "
+ "many parameters!");
retval = ISC_R_FAILURE;
} else {
/*
@@ -298,10 +299,11 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
* the zone.
*/
r = POPi;
- if (r)
+ if (r) {
retval = ISC_R_SUCCESS;
- else
+ } else {
retval = ISC_R_NOPERM;
+ }
}
PUTBACK;
@@ -313,24 +315,23 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_findzonedb(void *dbdata, const char *name)
-#else
+#else /* if DLZ_DLOPEN_VERSION < 3 */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo)
-#endif
+#endif /* if DLZ_DLOPEN_VERSION < 3 */
{
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
int r;
isc_result_t retval;
#ifdef MULTIPLICITY
PerlInterpreter *my_perl = cd->perl;
-#endif
+#endif /* ifdef MULTIPLICITY */
#if DLZ_DLOPEN_VERSION >= 3
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 3 */
dSP;
carp("DLZ Perl: findzone looking for '%s'", name);
@@ -338,13 +339,13 @@ dlz_findzonedb(void *dbdata, const char *name,
PERL_SET_CONTEXT(cd->perl);
ENTER;
SAVETMPS;
-
+
PUSHMARK(SP);
XPUSHs(cd->perl_class);
XPUSHs(sv_2mortal(newSVpv(name, 0)));
PUTBACK;
- r = call_method("findzone", G_SCALAR|G_EVAL);
+ r = call_method("findzone", G_SCALAR | G_EVAL);
SPAGAIN;
if (SvTRUE(ERRSV)) {
@@ -354,24 +355,26 @@ dlz_findzonedb(void *dbdata, const char *name,
* caller.
*/
POPs;
- cd->log(ISC_LOG_ERROR,
- "DLZ Perl: findzone died in eval: %s",
+ cd->log(ISC_LOG_ERROR, "DLZ Perl: findzone died in eval: %s",
SvPV_nolen(ERRSV));
retval = ISC_R_FAILURE;
} else if (r == 0) {
- retval = ISC_R_FAILURE;
+ retval = ISC_R_FAILURE;
} else if (r > 1) {
/* Once again, clean out the stack when possible. */
- while (r--) POPi;
- cd->log(ISC_LOG_ERROR,
- "DLZ Perl: findzone returned too many parameters!");
+ while (r--) {
+ POPi;
+ }
+ cd->log(ISC_LOG_ERROR, "DLZ Perl: findzone returned too many "
+ "parameters!");
retval = ISC_R_FAILURE;
} else {
r = POPi;
- if (r)
+ if (r) {
retval = ISC_R_SUCCESS;
- else
+ } else {
retval = ISC_R_NOTFOUND;
+ }
}
PUTBACK;
@@ -380,21 +383,19 @@ dlz_findzonedb(void *dbdata, const char *name,
return (retval);
}
-
#if DLZ_DLOPEN_VERSION == 1
isc_result_t
-dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup)
-#else
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup)
+#else /* if DLZ_DLOPEN_VERSION == 1 */
isc_result_t
-dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods,
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo)
-#endif
+#endif /* if DLZ_DLOPEN_VERSION == 1 */
{
isc_result_t retval;
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
int rrcount, r;
dlz_perl_clientinfo_opaque opaque;
SV *record_ref;
@@ -403,12 +404,12 @@ dlz_lookup(const char *zone, const char *name,
SV **rr_data;
#ifdef MULTIPLICITY
PerlInterpreter *my_perl = cd->perl;
-#endif
+#endif /* ifdef MULTIPLICITY */
#if DLZ_DLOPEN_VERSION >= 2
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 2 */
dSP;
PERL_SET_CONTEXT(cd->perl);
@@ -426,7 +427,7 @@ dlz_lookup(const char *zone, const char *name,
PUTBACK;
carp("DLZ Perl: Searching for name %s in zone %s", name, zone);
- rrcount = call_method("lookup", G_ARRAY|G_EVAL);
+ rrcount = call_method("lookup", G_ARRAY | G_EVAL);
carp("DLZ Perl: Call to lookup returned %i", rrcount);
SPAGAIN;
@@ -449,34 +450,34 @@ dlz_lookup(const char *zone, const char *name,
while (r++ < rrcount) {
record_ref = POPs;
if ((!SvROK(record_ref)) ||
- (SvTYPE(SvRV(record_ref)) != SVt_PVAV))
- {
- cd->log(ISC_LOG_ERROR,
- "DLZ Perl: lookup returned an "
- "invalid value (expected array of arrayrefs)!");
+ (SvTYPE(SvRV(record_ref)) != SVt_PVAV)) {
+ cd->log(ISC_LOG_ERROR, "DLZ Perl: lookup returned an "
+ "invalid value (expected array "
+ "of arrayrefs)!");
retval = ISC_R_FAILURE;
break;
}
record_ref = SvRV(record_ref);
- rr_type = av_fetch((AV *) record_ref, 0, 0);
- rr_ttl = av_fetch((AV *) record_ref, 1, 0);
- rr_data = av_fetch((AV *) record_ref, 2, 0);
+ rr_type = av_fetch((AV *)record_ref, 0, 0);
+ rr_ttl = av_fetch((AV *)record_ref, 1, 0);
+ rr_data = av_fetch((AV *)record_ref, 2, 0);
if (rr_type == NULL || rr_ttl == NULL || rr_data == NULL) {
cd->log(ISC_LOG_ERROR,
"DLZ Perl: lookup for record %s in "
"zone %s returned an array that was "
- "missing data", name, zone);
+ "missing data",
+ name, zone);
retval = ISC_R_FAILURE;
break;
}
- carp("DLZ Perl: Got record %s = %s",
- SvPV_nolen(*rr_type), SvPV_nolen(*rr_data));
- retval = cd->putrr(lookup, SvPV_nolen(*rr_type),
- SvIV(*rr_ttl), SvPV_nolen(*rr_data));
+ carp("DLZ Perl: Got record %s = %s", SvPV_nolen(*rr_type),
+ SvPV_nolen(*rr_data));
+ retval = cd->putrr(lookup, SvPV_nolen(*rr_type), SvIV(*rr_ttl),
+ SvPV_nolen(*rr_data));
if (retval != ISC_R_SUCCESS) {
cd->log(ISC_LOG_ERROR,
@@ -501,21 +502,21 @@ CLEAN_UP_AND_RETURN:
const char *
#ifdef MULTIPLICITY
missing_perl_method(const char *perl_class_name, PerlInterpreter *my_perl)
-#else
+#else /* ifdef MULTIPLICITY */
missing_perl_method(const char *perl_class_name)
-#endif
+#endif /* ifdef MULTIPLICITY */
{
const int BUF_LEN = 64; /* Should be big enough, right? hah */
char full_name[BUF_LEN];
const char *methods[] = { "new", "findzone", "lookup", NULL };
int i = 0;
- while( methods[i] != NULL ) {
- snprintf(full_name, BUF_LEN, "%s::%s",
- perl_class_name, methods[i]);
+ while (methods[i] != NULL) {
+ snprintf(full_name, BUF_LEN, "%s::%s", perl_class_name,
+ methods[i]);
if (get_cv(full_name, 0) == NULL) {
- return methods[i];
+ return (methods[i]);
}
i++;
}
@@ -524,9 +525,8 @@ missing_perl_method(const char *perl_class_name)
}
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
config_data_t *cd;
char *init_args[] = { NULL, NULL };
char *perlrun[] = { "", NULL, "dlz perl", NULL };
@@ -538,40 +538,39 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
char *call_argv_args = NULL;
#ifdef MULTIPLICITY
PerlInterpreter *my_perl;
-#endif
+#endif /* ifdef MULTIPLICITY */
cd = malloc(sizeof(config_data_t));
- if (cd == NULL)
+ if (cd == NULL) {
return (ISC_R_NOMEMORY);
+ }
memset(cd, 0, sizeof(config_data_t));
/* fill in the helper functions */
va_start(ap, dbdata);
while ((helper_name = va_arg(ap, const char *)) != NULL) {
- b9_add_helper(cd, helper_name, va_arg(ap, void*));
+ b9_add_helper(cd, helper_name, va_arg(ap, void *));
}
va_end(ap);
if (argc < 2) {
cd->log(ISC_LOG_ERROR,
- "DLZ Perl '%s': Missing script argument.",
- dlzname);
+ "DLZ Perl '%s': Missing script argument.", dlzname);
free(cd);
return (ISC_R_FAILURE);
}
if (argc < 3) {
cd->log(ISC_LOG_ERROR,
- "DLZ Perl '%s': Missing class name argument.",
- dlzname);
+ "DLZ Perl '%s': Missing class name argument.", dlzname);
free(cd);
return (ISC_R_FAILURE);
}
perl_class_name = argv[2];
cd->log(ISC_LOG_INFO, "DLZ Perl '%s': Loading '%s' from location '%s'",
- dlzname, perl_class_name, argv[1], argc);
+ dlzname, perl_class_name, argv[1], argc);
#ifndef MULTIPLICITY
if (global_perl) {
@@ -586,7 +585,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
global_perl = NULL;
global_perl_dont_free = 1;
}
-#endif
+#endif /* ifndef MULTIPLICITY */
cd->perl = perl_alloc();
if (cd->perl == NULL) {
@@ -595,9 +594,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
}
#ifdef MULTIPLICITY
my_perl = cd->perl;
-#endif
+#endif /* ifdef MULTIPLICITY */
PERL_SET_CONTEXT(cd->perl);
-
+
/*
* We will re-create the interpreter during an rndc reconfig, so we
* must set this variable per perlembed in order to insure we can
@@ -624,10 +623,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* Let Perl know about our callbacks. */
- call_argv("DLZ_Perl::clientinfo::bootstrap",
- G_DISCARD|G_NOARGS, &call_argv_args);
- call_argv("DLZ_Perl::bootstrap",
- G_DISCARD|G_NOARGS, &call_argv_args);
+ call_argv("DLZ_Perl::clientinfo::bootstrap", G_DISCARD | G_NOARGS,
+ &call_argv_args);
+ call_argv("DLZ_Perl::bootstrap", G_DISCARD | G_NOARGS, &call_argv_args);
/*
* Run the script. We don't really need to do this since we have
@@ -642,13 +640,14 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
#ifdef MULTIPLICITY
if (missing_method_name = missing_perl_method(perl_class_name, my_perl))
-#else
+#else /* ifdef MULTIPLICITY */
if (missing_method_name = missing_perl_method(perl_class_name))
-#endif
+#endif /* ifdef MULTIPLICITY */
{
cd->log(ISC_LOG_ERROR,
"DLZ Perl '%s': Missing required function '%s', "
- "aborting", dlzname, missing_method_name);
+ "aborting",
+ dlzname, missing_method_name);
goto CLEAN_UP_PERL_AND_FAIL;
}
@@ -671,11 +670,13 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
PUTBACK;
- r = call_method("new", G_EVAL|G_SCALAR);
+ r = call_method("new", G_EVAL | G_SCALAR);
SPAGAIN;
- if (r) cd->perl_class = SvREFCNT_inc(POPs);
+ if (r) {
+ cd->perl_class = SvREFCNT_inc(POPs);
+ }
PUTBACK;
FREETMPS;
@@ -683,8 +684,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
if (SvTRUE(ERRSV)) {
POPs;
- cd->log(ISC_LOG_ERROR,
- "DLZ Perl '%s': new died in eval: %s",
+ cd->log(ISC_LOG_ERROR, "DLZ Perl '%s': new died in eval: %s",
dlzname, SvPV_nolen(ERRSV));
goto CLEAN_UP_PERL_AND_FAIL;
}
@@ -700,7 +700,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
#ifndef MULTIPLICITY
global_perl = cd->perl;
-#endif
+#endif /* ifndef MULTIPLICITY */
return (ISC_R_SUCCESS);
CLEAN_UP_PERL_AND_FAIL:
@@ -712,17 +712,18 @@ CLEAN_UP_PERL_AND_FAIL:
return (ISC_R_FAILURE);
}
-void dlz_destroy(void *dbdata) {
- config_data_t *cd = (config_data_t *) dbdata;
+void
+dlz_destroy(void *dbdata) {
+ config_data_t *cd = (config_data_t *)dbdata;
#ifdef MULTIPLICITY
PerlInterpreter *my_perl = cd->perl;
-#endif
+#endif /* ifdef MULTIPLICITY */
cd->log(ISC_LOG_INFO, "DLZ Perl: Unloading driver.");
#ifndef MULTIPLICITY
if (!global_perl_dont_free) {
-#endif
+#endif /* ifndef MULTIPLICITY */
PERL_SET_CONTEXT(cd->perl);
PL_perl_destruct_level = 1;
perl_destruct(cd->perl);
@@ -731,7 +732,7 @@ void dlz_destroy(void *dbdata) {
global_perl_dont_free = 0;
global_perl = NULL;
}
-#endif
+#endif /* ifndef MULTIPLICITY */
free(cd->perl_source);
free(cd);
diff --git a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c
index 2d7d0b06..f13cae29 100644
--- a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c
+++ b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c
@@ -34,8 +34,9 @@
*/
/*
- * Copyright (C) 1999-2001, 2013-2014, 2016 Internet Systems Consortium, Inc. ("ISC")
- *
+ * Copyright (C) 1999-2001, 2013-2014, 2016 Internet Systems Consortium, Inc.
+ * ("ISC")
+ *
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
@@ -46,40 +47,39 @@
* update support. Based in part on SQLite code contributed by Tim Tessier.
*/
-#include <stdio.h>
-#include <string.h>
+#include <sqlite3.h>
#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
-#include <dlz_minimal.h>
-#include <dlz_list.h>
#include <dlz_dbi.h>
+#include <dlz_list.h>
+#include <dlz_minimal.h>
#include <dlz_pthread.h>
-#include <sqlite3.h>
-
#define dbc_search_limit 30
-#define ALLNODES 1
-#define ALLOWXFR 2
-#define AUTHORITY 3
-#define FINDZONE 4
-#define COUNTZONE 5
-#define LOOKUP 6
+#define ALLNODES 1
+#define ALLOWXFR 2
+#define AUTHORITY 3
+#define FINDZONE 4
+#define COUNTZONE 5
+#define LOOKUP 6
#define safeGet(in) in == NULL ? "" : in
/*%
- * Structure to hold everthing needed by this "instance" of the SQLite3
+ * Structure to hold everything needed by this "instance" of the SQLite3
* module remember, the module code is only loaded once, but may have
* many separate instances.
*/
typedef struct {
#if PTHREADS
- db_list_t *db; /*%< handle to a list of DB */
+ db_list_t *db; /*%< handle to a list of DB */
int dbcount;
-#else
+#else /* if PTHREADS */
dbinstance_t *db; /*%< handle to DB */
-#endif
+#endif /* if PTHREADS */
char *dbname;
@@ -94,17 +94,16 @@ typedef struct {
* SQLite3 result set
*/
typedef struct {
- char **pazResult; /* Result of the query */
- unsigned int pnRow; /* Number of result rows */
- unsigned int pnColumn; /* Number of result columns */
- unsigned int curRow; /* Current row */
- char *pzErrmsg; /* Error message */
+ char **pazResult; /* Result of the query */
+ unsigned int pnRow; /* Number of result rows */
+ unsigned int pnColumn; /* Number of result columns */
+ unsigned int curRow; /* Current row */
+ char *pzErrmsg; /* Error message */
} sqlite3_res_t;
/* forward references */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo);
void
@@ -120,8 +119,9 @@ b9_add_helper(sqlite3_instance_t *db, const char *helper_name, void *ptr);
void
sqlite3_destroy(dbinstance_t *db) {
/* release DB connection */
- if (db->dbconn != NULL)
- sqlite3_close((sqlite3 *) db->dbconn);
+ if (db->dbconn != NULL) {
+ sqlite3_close((sqlite3 *)db->dbconn);
+ }
sqlite3_shutdown();
/* destroy DB instance */
@@ -172,9 +172,9 @@ sqlite3_find_avail(sqlite3_instance_t *sqlite3) {
/* loop through list */
while (count < dbc_search_limit) {
/* try to lock on the mutex */
- if (dlz_mutex_trylock(&dbi->lock) == 0)
+ if (dlz_mutex_trylock(&dbi->lock) == 0) {
return (dbi); /* success, return the DBI for use. */
-
+ }
/* not successful, keep trying */
dbi = DLZ_LIST_NEXT(dbi, link);
@@ -186,8 +186,9 @@ sqlite3_find_avail(sqlite3_instance_t *sqlite3) {
}
sqlite3->log(ISC_LOG_INFO,
- "SQLite3 module: unable to find available connection "
- "after searching %d times", count);
+ "SQLite3 module: unable to find available connection "
+ "after searching %d times",
+ count);
return (NULL);
}
#endif /* PTHREADS */
@@ -208,20 +209,23 @@ escape_string(const char *instr) {
unsigned int atlen = 0;
unsigned int i;
- if (instr == NULL)
+ if (instr == NULL) {
return (NULL);
+ }
len = strlen(instr);
atlen = (2 * len * sizeof(char)) + 1;
outstr = malloc(atlen);
- if (outstr == NULL)
+ if (outstr == NULL) {
return (NULL);
+ }
ptr = outstr;
for (i = 0; i < len; i++) {
- if (tlen > atlen || instr[i] == '\0')
+ if (tlen > atlen || instr[i] == '\0') {
break;
+ }
- if (instr[i] == '\'') {
+ if (instr[i] == '\'') {
*ptr++ = '\'';
tlen++;
}
@@ -244,10 +248,8 @@ escape_string(const char *instr) {
* a result set.
*/
static isc_result_t
-sqlite3_get_resultset(const char *zone, const char *record,
- const char *client, unsigned int query,
- void *dbdata, sqlite3_res_t **rsp)
-{
+sqlite3_get_resultset(const char *zone, const char *record, const char *client,
+ unsigned int query, void *dbdata, sqlite3_res_t **rsp) {
isc_result_t result;
dbinstance_t *dbi = NULL;
sqlite3_instance_t *db = (sqlite3_instance_t *)dbdata;
@@ -268,7 +270,7 @@ sqlite3_get_resultset(const char *zone, const char *record,
#if PTHREADS
/* find an available DBI from the list */
dbi = sqlite3_find_avail(db);
-#else /* PTHREADS */
+#else /* PTHREADS */
/*
* only 1 DBI - no need to lock instance lock either
* only 1 thread in the whole process, no possible contention.
@@ -277,12 +279,11 @@ sqlite3_get_resultset(const char *zone, const char *record,
#endif /* PTHREADS */
if (dbi == NULL) {
- result = ISC_R_FAILURE;
- goto cleanup;
+ return (ISC_R_FAILURE);
}
/* what type of query are we going to run? */
- switch(query) {
+ switch (query) {
case ALLNODES:
if (dbi->allnodes_q == NULL) {
result = ISC_R_NOTIMPLEMENTED;
@@ -303,9 +304,9 @@ sqlite3_get_resultset(const char *zone, const char *record,
break;
case FINDZONE:
if (dbi->findzone_q == NULL) {
- db->log(ISC_LOG_DEBUG(2),
- "No query specified for findzone. "
- "Findzone requires a query");
+ db->log(ISC_LOG_DEBUG(2), "No query specified for "
+ "findzone. "
+ "Findzone requires a query");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -318,63 +319,67 @@ sqlite3_get_resultset(const char *zone, const char *record,
break;
case LOOKUP:
if (dbi->lookup_q == NULL) {
- db->log(ISC_LOG_DEBUG(2),
- "No query specified for lookup. "
- "Lookup requires a query");
+ db->log(ISC_LOG_DEBUG(2), "No query specified for "
+ "lookup. "
+ "Lookup requires a query");
result = ISC_R_FAILURE;
goto cleanup;
}
break;
default:
- db->log(ISC_LOG_ERROR,
- "Incorrect query flag passed to "
- "sqlite3_get_resultset");
+ db->log(ISC_LOG_ERROR, "Incorrect query flag passed to "
+ "sqlite3_get_resultset");
result = ISC_R_UNEXPECTED;
goto cleanup;
}
-
if (zone != NULL) {
- if (dbi->zone != NULL)
+ if (dbi->zone != NULL) {
free(dbi->zone);
+ }
dbi->zone = escape_string(zone);
if (dbi->zone == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->zone = NULL;
+ }
if (record != NULL) {
- if (dbi->record != NULL)
+ if (dbi->record != NULL) {
free(dbi->record);
+ }
dbi->record = escape_string(record);
if (dbi->record == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->record = NULL;
+ }
if (client != NULL) {
- if (dbi->client != NULL)
+ if (dbi->client != NULL) {
free(dbi->client);
+ }
dbi->client = escape_string(client);
if (dbi->client == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
- } else
+ } else {
dbi->client = NULL;
+ }
/*
* what type of query are we going to run? this time we build
* the actual query to run.
*/
- switch(query) {
+ switch (query) {
case ALLNODES:
querystring = build_querystring(dbi->allnodes_q);
break;
@@ -394,9 +399,8 @@ sqlite3_get_resultset(const char *zone, const char *record,
querystring = build_querystring(dbi->lookup_q);
break;
default:
- db->log(ISC_LOG_ERROR,
- "Incorrect query flag passed to "
- "sqlite3_get_resultset");
+ db->log(ISC_LOG_ERROR, "Incorrect query flag passed to "
+ "sqlite3_get_resultset");
result = ISC_R_UNEXPECTED;
goto cleanup;
}
@@ -431,16 +435,13 @@ sqlite3_get_resultset(const char *zone, const char *record,
result = ISC_R_SUCCESS;
if (query == COUNTZONE) {
sqlite3_free_table(rs->pazResult);
- if (rs == NULL)
- result = ISC_R_FAILURE;
}
- *rsp = rs;
-
- cleanup:
- if (dbi == NULL)
- return (ISC_R_FAILURE);
+ if (rsp != NULL) {
+ *rsp = rs;
+ }
+cleanup:
if (dbi->zone != NULL) {
free(dbi->zone);
dbi->zone = NULL;
@@ -455,10 +456,11 @@ sqlite3_get_resultset(const char *zone, const char *record,
}
/* release the lock so another thread can use this dbi */
- (void) dlz_mutex_unlock(&dbi->lock);
+ (void)dlz_mutex_unlock(&dbi->lock);
- if (querystring != NULL)
+ if (querystring != NULL) {
free(querystring);
+ }
return (result);
}
@@ -485,16 +487,18 @@ sqlite3_fetch_row(sqlite3_res_t *rs) {
unsigned int
sqlite3_num_fields(sqlite3_res_t *rs) {
unsigned int retval = 0;
- if (rs != NULL)
+ if (rs != NULL) {
retval = rs->pnColumn;
+ }
return (retval);
}
unsigned int
sqlite3_num_rows(sqlite3_res_t *rs) {
unsigned int retval = 0;
- if (rs != NULL)
+ if (rs != NULL) {
retval = rs->pnRow;
+ }
return (retval);
}
@@ -508,8 +512,7 @@ sqlite3_free_result(sqlite3_res_t *rs) {
static isc_result_t
sqlite3_process_rs(sqlite3_instance_t *db, dns_sdlzlookup_t *lookup,
- sqlite3_res_t *rs)
-{
+ sqlite3_res_t *rs) {
isc_result_t result = ISC_R_NOTFOUND;
char **row;
unsigned int fields;
@@ -518,12 +521,12 @@ sqlite3_process_rs(sqlite3_instance_t *db, dns_sdlzlookup_t *lookup,
char *endp;
int ttl;
- row = sqlite3_fetch_row(rs); /* get a row from the result set */
+ row = sqlite3_fetch_row(rs); /* get a row from the result set */
fields = sqlite3_num_fields(rs); /* how many columns in result set */
while (row != NULL) {
unsigned int len = 0;
- switch(fields) {
+ switch (fields) {
case 1:
/*
* one column in rs, it's the data field. use
@@ -548,14 +551,14 @@ sqlite3_process_rs(sqlite3_instance_t *db, dns_sdlzlookup_t *lookup,
*/
ttl = strtol(safeGet(row[0]), &endp, 10);
if (*endp != '\0' || ttl < 0) {
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: TTL must be "
- "a postive number");
+ db->log(ISC_LOG_ERROR, "SQLite3 module: TTL "
+ "must be "
+ "a positive number");
return (ISC_R_FAILURE);
}
result = db->putrr(lookup, safeGet(row[1]), ttl,
- safeGet(row[2]));
+ safeGet(row[2]));
break;
default:
/*
@@ -572,9 +575,10 @@ sqlite3_process_rs(sqlite3_instance_t *db, dns_sdlzlookup_t *lookup,
*/
tmpString = malloc(len + 1);
if (tmpString == NULL) {
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: unable to allocate "
- "memory for temporary string");
+ db->log(ISC_LOG_ERROR, "SQLite3 module: unable "
+ "to allocate "
+ "memory for temporary "
+ "string");
sqlite3_free_result(rs);
return (ISC_R_FAILURE);
}
@@ -587,22 +591,22 @@ sqlite3_process_rs(sqlite3_instance_t *db, dns_sdlzlookup_t *lookup,
ttl = strtol(safeGet(row[0]), &endp, 10);
if (*endp != '\0' || ttl < 0) {
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: TTL must be "
- "a postive number");
+ db->log(ISC_LOG_ERROR, "SQLite3 module: TTL "
+ "must be "
+ "a positive number");
free(tmpString);
return (ISC_R_FAILURE);
}
- result = db->putrr(lookup, safeGet(row[1]),
- ttl, tmpString);
+ result = db->putrr(lookup, safeGet(row[1]), ttl,
+ tmpString);
free(tmpString);
}
if (result != ISC_R_SUCCESS) {
sqlite3_free_result(rs);
- db->log(ISC_LOG_ERROR,
- "putrr returned error: %d", result);
+ db->log(ISC_LOG_ERROR, "putrr returned error: %d",
+ result);
return (ISC_R_FAILURE);
}
@@ -619,10 +623,8 @@ sqlite3_process_rs(sqlite3_instance_t *db, dns_sdlzlookup_t *lookup,
/*% determine if the zone is supported by (in) the database */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
sqlite3_res_t *rs = NULL;
sqlite3_uint64 rows;
@@ -633,12 +635,12 @@ dlz_findzonedb(void *dbdata, const char *name,
result = sqlite3_get_resultset(name, NULL, NULL, FINDZONE, dbdata, &rs);
if (result != ISC_R_SUCCESS || rs == NULL) {
- if (rs != NULL)
+ if (rs != NULL) {
sqlite3_free_result(rs);
+ }
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: unable to return "
- "result set for FINDZONE query");
+ db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return "
+ "result set for FINDZONE query");
return (ISC_R_FAILURE);
}
@@ -649,8 +651,8 @@ dlz_findzonedb(void *dbdata, const char *name,
rows = sqlite3_num_rows(rs);
sqlite3_free_result(rs);
if (rows > 0) {
- sqlite3_get_resultset(name, NULL, NULL, COUNTZONE,
- dbdata, NULL);
+ sqlite3_get_resultset(name, NULL, NULL, COUNTZONE, dbdata,
+ NULL);
return (ISC_R_SUCCESS);
}
@@ -667,8 +669,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
/* first check if the zone is supported by the database. */
result = dlz_findzonedb(dbdata, name, NULL, NULL);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND);
+ }
/*
* if we get to this point we know the zone is supported by
@@ -676,17 +679,18 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
* transfer is allowed for this client and did the config file
* have an allow zone xfr query.
*/
- result = sqlite3_get_resultset(name, NULL, client, ALLOWXFR,
- dbdata, &rs);
- if (result == ISC_R_NOTIMPLEMENTED)
+ result = sqlite3_get_resultset(name, NULL, client, ALLOWXFR, dbdata,
+ &rs);
+ if (result == ISC_R_NOTIMPLEMENTED) {
return (result);
+ }
if (result != ISC_R_SUCCESS || rs == NULL) {
- if (rs != NULL)
+ if (rs != NULL) {
sqlite3_free_result(rs);
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: unable to return "
- "result set for ALLOWXFR query");
+ }
+ db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return "
+ "result set for ALLOWXFR query");
return (ISC_R_FAILURE);
}
@@ -696,8 +700,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
*/
rows = sqlite3_num_rows(rs);
sqlite3_free_result(rs);
- if (rows > 0)
+ if (rows > 0) {
return (ISC_R_SUCCESS);
+ }
return (ISC_R_NOPERM);
}
@@ -720,14 +725,14 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
int ttl;
result = sqlite3_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs);
- if (result == ISC_R_NOTIMPLEMENTED)
+ if (result == ISC_R_NOTIMPLEMENTED) {
return (result);
+ }
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: unable to return "
- "result set for all nodes query");
+ db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return "
+ "result set for all nodes query");
goto cleanup;
}
@@ -737,18 +742,17 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
row = sqlite3_fetch_row(rs);
while (row != NULL) {
if (fields < 4) {
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: too few fields returned "
- "by ALLNODES query");
+ db->log(ISC_LOG_ERROR, "SQLite3 module: too few fields "
+ "returned "
+ "by ALLNODES query");
result = ISC_R_FAILURE;
goto cleanup;
}
ttl = strtol(safeGet(row[0]), &endp, 10);
if (*endp != '\0' || ttl < 0) {
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: TTL must be "
- "a postive number");
+ db->log(ISC_LOG_ERROR, "SQLite3 module: TTL must be "
+ "a positive number");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -769,9 +773,10 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
tmpString = malloc(len + 1);
if (tmpString == NULL) {
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: unable to allocate "
- "memory for temporary string");
+ db->log(ISC_LOG_ERROR, "SQLite3 module: unable "
+ "to allocate "
+ "memory for temporary "
+ "string");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -783,14 +788,14 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
}
result = db->putnamedrr(allnodes, safeGet(row[2]),
- safeGet(row[1]),
- ttl, tmpString);
+ safeGet(row[1]), ttl,
+ tmpString);
free(tmpString);
}
if (result != ISC_R_SUCCESS) {
- db->log(ISC_LOG_ERROR,
- "putnamedrr returned error: %s", result);
+ db->log(ISC_LOG_ERROR, "putnamedrr returned error: %s",
+ result);
result = ISC_R_FAILURE;
break;
}
@@ -798,9 +803,10 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
row = sqlite3_fetch_row(rs);
}
- cleanup:
- if (rs != NULL)
+cleanup:
+ if (rs != NULL) {
sqlite3_free_result(rs);
+ }
return (result);
}
@@ -813,19 +819,20 @@ isc_result_t
dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) {
isc_result_t result;
sqlite3_res_t *rs = NULL;
- sqlite3_instance_t *db = (sqlite3_instance_t *) dbdata;
+ sqlite3_instance_t *db = (sqlite3_instance_t *)dbdata;
- result = sqlite3_get_resultset(zone, NULL, NULL, AUTHORITY,
- dbdata, &rs);
- if (result == ISC_R_NOTIMPLEMENTED)
+ result = sqlite3_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata,
+ &rs);
+ if (result == ISC_R_NOTIMPLEMENTED) {
return (result);
+ }
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
sqlite3_free_result(rs);
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: unable to return "
- "result set for AUTHORITY query");
+ }
+ db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return "
+ "result set for AUTHORITY query");
return (ISC_R_FAILURE);
}
@@ -838,14 +845,12 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) {
/*% If zone is supported, lookup up a (or multiple) record(s) in it */
isc_result_t
-dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods,
- dns_clientinfo_t *clientinfo)
-{
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
+ dns_clientinfo_t *clientinfo) {
isc_result_t result;
sqlite3_res_t *rs = NULL;
- sqlite3_instance_t *db = (sqlite3_instance_t *) dbdata;
+ sqlite3_instance_t *db = (sqlite3_instance_t *)dbdata;
UNUSED(methods);
UNUSED(clientinfo);
@@ -854,11 +859,11 @@ dlz_lookup(const char *zone, const char *name,
/* if we didn't get a result set, log an err msg. */
if (result != ISC_R_SUCCESS) {
- if (rs != NULL)
+ if (rs != NULL) {
sqlite3_free_result(rs);
- db->log(ISC_LOG_ERROR,
- "SQLite3 module: unable to return "
- "result set for LOOKUP query");
+ }
+ db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return "
+ "result set for LOOKUP query");
return (ISC_R_FAILURE);
}
@@ -873,9 +878,8 @@ dlz_lookup(const char *zone, const char *name,
* Create an instance of the module.
*/
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
isc_result_t result = ISC_R_FAILURE;
sqlite3_instance_t *s3 = NULL;
dbinstance_t *dbi = NULL;
@@ -883,9 +887,6 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
char *tmp = NULL;
char *endp;
const char *helper_name;
-#if SQLITE3_VERSION_ID >= 50000
- my_bool auto_reconnect = 1;
-#endif
#if PTHREADS
int dbcount;
int i, ret;
@@ -896,45 +897,45 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* allocate memory for SQLite3 instance */
s3 = calloc(1, sizeof(sqlite3_instance_t));
- if (s3 == NULL)
+ if (s3 == NULL) {
return (ISC_R_NOMEMORY);
+ }
memset(s3, 0, sizeof(sqlite3_instance_t));
/* Fill in the helper functions */
va_start(ap, dbdata);
- while ((helper_name = va_arg(ap, const char*)) != NULL)
- b9_add_helper(s3, helper_name, va_arg(ap, void*));
+ while ((helper_name = va_arg(ap, const char *)) != NULL) {
+ b9_add_helper(s3, helper_name, va_arg(ap, void *));
+ }
va_end(ap);
#if PTHREADS
/* if debugging, let user know we are multithreaded. */
s3->log(ISC_LOG_DEBUG(1), "SQLite3 module: running multithreaded");
-#else /* PTHREADS */
+#else /* PTHREADS */
/* if debugging, let user know we are single threaded. */
s3->log(ISC_LOG_DEBUG(1), "SQLite3 module: running single threaded");
#endif /* PTHREADS */
/* verify we have at least 4 arg's passed to the module */
if (argc < 4) {
- s3->log(ISC_LOG_ERROR,
- "SQLite3 module requires "
- "at least 4 command line args.");
+ s3->log(ISC_LOG_ERROR, "SQLite3 module requires "
+ "at least 4 command line args.");
return (ISC_R_FAILURE);
}
/* no more than 8 arg's should be passed to the module */
if (argc > 8) {
- s3->log(ISC_LOG_ERROR,
- "SQLite3 module cannot accept "
- "more than 8 command line args.");
+ s3->log(ISC_LOG_ERROR, "SQLite3 module cannot accept "
+ "more than 8 command line args.");
return (ISC_R_FAILURE);
}
/* get db name - required */
s3->dbname = get_parameter_value(argv[1], "dbname=");
if (s3->dbname == NULL) {
- s3->log(ISC_LOG_ERROR,
- "SQLite3 module requires a dbname parameter.");
+ s3->log(ISC_LOG_ERROR, "SQLite3 module requires a dbname "
+ "parameter.");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -942,14 +943,14 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
#if PTHREADS
/* multithreaded build can have multiple DB connections */
tmp = get_parameter_value(argv[1], "threads=");
- if (tmp == NULL)
+ if (tmp == NULL) {
dbcount = 1;
- else {
+ } else {
dbcount = strtol(tmp, &endp, 10);
if (*endp != '\0' || dbcount < 1) {
- s3->log(ISC_LOG_ERROR,
- "SQLite3 module: database connection count "
- "must be positive.");
+ s3->log(ISC_LOG_ERROR, "SQLite3 module: database "
+ "connection count "
+ "must be positive.");
free(tmp);
result = ISC_R_FAILURE;
goto cleanup;
@@ -973,26 +974,24 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
*/
for (i = 0; i < dbcount; i++) {
#endif /* PTHREADS */
- switch(argc) {
+ switch (argc) {
case 4:
- result = build_dbinstance(NULL, NULL, NULL,
- argv[2], argv[3], NULL,
- &dbi, s3->log);
+ result = build_dbinstance(NULL, NULL, NULL, argv[2],
+ argv[3], NULL, &dbi, s3->log);
break;
case 5:
- result = build_dbinstance(NULL, NULL, argv[4],
- argv[2], argv[3], NULL,
- &dbi, s3->log);
+ result = build_dbinstance(NULL, NULL, argv[4], argv[2],
+ argv[3], NULL, &dbi, s3->log);
break;
case 6:
result = build_dbinstance(argv[5], NULL, argv[4],
- argv[2], argv[3], NULL,
- &dbi, s3->log);
+ argv[2], argv[3], NULL, &dbi,
+ s3->log);
break;
case 7:
result = build_dbinstance(argv[5], argv[6], argv[4],
- argv[2], argv[3], NULL,
- &dbi, s3->log);
+ argv[2], argv[3], NULL, &dbi,
+ s3->log);
break;
case 8:
result = build_dbinstance(argv[5], argv[6], argv[4],
@@ -1003,11 +1002,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
result = ISC_R_FAILURE;
}
-
if (result != ISC_R_SUCCESS) {
- s3->log(ISC_LOG_ERROR,
- "SQLite3 module: could not create "
- "database instance object.");
+ s3->log(ISC_LOG_ERROR, "SQLite3 module: could not "
+ "create "
+ "database instance object.");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -1015,9 +1013,8 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* create and set db connection */
ret = sqlite3_initialize();
if (ret != SQLITE_OK) {
- s3->log(ISC_LOG_ERROR,
- "SQLite3 module: could not "
- "initialize database object.");
+ s3->log(ISC_LOG_ERROR, "SQLite3 module: could not "
+ "initialize database object.");
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -1025,8 +1022,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
ret = sqlite3_open(s3->dbname, &dbc);
if (ret != SQLITE_OK) {
s3->log(ISC_LOG_ERROR,
- "SQLite3 module: could not "
- "open '%s'.", s3->dbname);
+ "SQLite3 module: could not "
+ "open '%s'.",
+ s3->dbname);
result = ISC_R_FAILURE;
goto cleanup;
}
@@ -1035,13 +1033,13 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
/* when multithreaded, build a list of DBI's */
DLZ_LINK_INIT(dbi, link);
DLZ_LIST_APPEND(*(s3->db), dbi, link);
-#else
- /*
- * when single threaded, hold onto the one connection
- * instance.
- */
- s3->db = dbi;
-#endif
+#else /* if PTHREADS */
+ /*
+ * when single threaded, hold onto the one connection
+ * instance.
+ */
+ s3->db = dbi;
+#endif /* if PTHREADS */
dbi->dbconn = dbc;
dbc = NULL;
@@ -1054,7 +1052,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
*dbdata = s3;
return (ISC_R_SUCCESS);
- cleanup:
+cleanup:
dlz_destroy(s3);
return (result);
@@ -1068,14 +1066,16 @@ dlz_destroy(void *dbdata) {
sqlite3_instance_t *db = (sqlite3_instance_t *)dbdata;
#if PTHREADS
/* cleanup the list of DBI's */
- if (db->db != NULL)
+ if (db->db != NULL) {
sqlite3_destroy_dblist((db_list_t *)(db->db));
-#else /* PTHREADS */
+ }
+#else /* PTHREADS */
sqlite3_destroy(db);
#endif /* PTHREADS */
- if (db->dbname != NULL)
+ if (db->dbname != NULL) {
free(db->dbname);
+ }
}
/*
@@ -1083,8 +1083,7 @@ dlz_destroy(void *dbdata) {
*/
int
dlz_version(unsigned int *flags) {
- *flags |= (DNS_SDLZFLAG_RELATIVEOWNER |
- DNS_SDLZFLAG_RELATIVERDATA |
+ *flags |= (DNS_SDLZFLAG_RELATIVEOWNER | DNS_SDLZFLAG_RELATIVERDATA |
DNS_SDLZFLAG_THREADSAFE);
return (DLZ_DLOPEN_VERSION);
}
@@ -1094,12 +1093,16 @@ dlz_version(unsigned int *flags) {
*/
static void
b9_add_helper(sqlite3_instance_t *db, const char *helper_name, void *ptr) {
- if (strcmp(helper_name, "log") == 0)
+ if (strcmp(helper_name, "log") == 0) {
db->log = (log_t *)ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
db->putrr = (dns_sdlz_putrr_t *)ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
db->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
db->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
+ }
}
diff --git a/contrib/dlz/modules/wildcard/README b/contrib/dlz/modules/wildcard/README
index b19009be..ffc2e684 100644
--- a/contrib/dlz/modules/wildcard/README
+++ b/contrib/dlz/modules/wildcard/README
@@ -20,7 +20,7 @@ as "thisexample.com", "exampleofthat.com", or "anexampleoftheotherthing.com".
* 86400 A 192.0.0.100";
};
-For any zone name matchin the wildcard, it would return the data from
+For any zone name matching the wildcard, it would return the data from
the template. "$zone$" is replaced with zone name: i.e., the shortest
possible string of labels in the query name that matches the wildcard.
"$record$" is replaced with the remainder of the query name. In the
diff --git a/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c b/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c
index 26785846..e02c677c 100644
--- a/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c
+++ b/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c
@@ -35,7 +35,8 @@
*/
/*
- * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 1999-2001, 2013, 2016 Internet Systems Consortium, Inc.
+ * ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -46,37 +47,39 @@
* This provides the externally loadable wildcard DLZ module.
*/
+#include <ctype.h>
#include <inttypes.h>
+#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
#include <stdlib.h>
+#include <string.h>
-#include <dlz_minimal.h>
-#include <dlz_list.h>
#include <dlz_dbi.h>
+#include <dlz_list.h>
+#include <dlz_minimal.h>
-#include <ctype.h>
-
-#define DE_CONST(konst, var) \
- do { \
- union { const void *k; void *v; } _u; \
- _u.k = konst; \
- var = _u.v; \
+#define DE_CONST(konst, var) \
+ do { \
+ union { \
+ const void *k; \
+ void *v; \
+ } _u; \
+ _u.k = konst; \
+ var = _u.v; \
} while (0)
/* fnmatch() return values. */
-#define FNM_NOMATCH 1 /* Match failed. */
+#define FNM_NOMATCH 1 /* Match failed. */
/* fnmatch() flags. */
-#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
-#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
-#define FNM_PERIOD 0x04 /* Period must be matched by period. */
-#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
-#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
-#define FNM_IGNORECASE FNM_CASEFOLD
-#define FNM_FILE_NAME FNM_PATHNAME
+#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
+#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
+#define FNM_PERIOD 0x04 /* Period must be matched by period. */
+#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
+#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
+#define FNM_IGNORECASE FNM_CASEFOLD
+#define FNM_FILE_NAME FNM_PATHNAME
/*
* Our data structures.
@@ -86,12 +89,12 @@ typedef struct named_rr nrr_t;
typedef DLZ_LIST(nrr_t) rr_list_t;
typedef struct config_data {
- char *zone_pattern;
- char *axfr_pattern;
- rr_list_t rrs_list;
- char *zone;
- char *record;
- char *client;
+ char *zone_pattern;
+ char *axfr_pattern;
+ rr_list_t rrs_list;
+ char *zone;
+ char *record;
+ char *client;
/* Helper functions from the dlz_dlopen driver */
log_t *log;
@@ -101,11 +104,11 @@ typedef struct config_data {
} config_data_t;
struct named_rr {
- char *name;
- char *type;
- int ttl;
- query_list_t *data;
- DLZ_LINK(nrr_t) link;
+ char *name;
+ char *type;
+ int ttl;
+ query_list_t *data;
+ DLZ_LINK(nrr_t) link;
};
/*
@@ -125,7 +128,7 @@ shortest_match(const char *pattern, const char *string);
isc_result_t
dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
isc_result_t result;
char *querystring = NULL;
nrr_t *nrec;
@@ -134,8 +137,8 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
DE_CONST(zone, cd->zone);
/* Write info message to log */
- cd->log(ISC_LOG_DEBUG(1),
- "dlz_wildcard allnodes called for zone '%s'", zone);
+ cd->log(ISC_LOG_DEBUG(1), "dlz_wildcard allnodes called for zone '%s'",
+ zone);
result = ISC_R_FAILURE;
@@ -157,8 +160,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
result = cd->putnamedrr(allnodes, nrec->name, nrec->type,
nrec->ttl, querystring);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
goto done;
+ }
nrec = DLZ_LIST_NEXT(nrec, link);
}
@@ -166,15 +170,16 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) {
done:
cd->zone = NULL;
- if (querystring != NULL)
+ if (querystring != NULL) {
free(querystring);
+ }
return (result);
}
isc_result_t
dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
UNUSED(name);
@@ -182,55 +187,54 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) {
cd->log(ISC_LOG_DEBUG(1),
"dlz_wildcard allowzonexfr called for client '%s'", client);
- if (fnmatch(cd->axfr_pattern, client, FNM_CASEFOLD) == 0)
+ if (fnmatch(cd->axfr_pattern, client, FNM_CASEFOLD) == 0) {
return (ISC_R_SUCCESS);
- else
+ } else {
return (ISC_R_NOTFOUND);
+ }
}
#if DLZ_DLOPEN_VERSION < 3
isc_result_t
dlz_findzonedb(void *dbdata, const char *name)
-#else
+#else /* if DLZ_DLOPEN_VERSION < 3 */
isc_result_t
-dlz_findzonedb(void *dbdata, const char *name,
- dns_clientinfomethods_t *methods,
+dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo)
-#endif
+#endif /* if DLZ_DLOPEN_VERSION < 3 */
{
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
const char *p;
#if DLZ_DLOPEN_VERSION >= 3
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 3 */
p = shortest_match(cd->zone_pattern, name);
- if (p == NULL)
+ if (p == NULL) {
return (ISC_R_NOTFOUND);
+ }
/* Write info message to log */
- cd->log(ISC_LOG_DEBUG(1),
- "dlz_wildcard findzonedb matched '%s'", p);
+ cd->log(ISC_LOG_DEBUG(1), "dlz_wildcard findzonedb matched '%s'", p);
return (ISC_R_SUCCESS);
}
#if DLZ_DLOPEN_VERSION == 1
isc_result_t
-dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup)
-#else
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup)
+#else /* if DLZ_DLOPEN_VERSION == 1 */
isc_result_t
-dlz_lookup(const char *zone, const char *name,
- void *dbdata, dns_sdlzlookup_t *lookup,
- dns_clientinfomethods_t *methods,
+dlz_lookup(const char *zone, const char *name, void *dbdata,
+ dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo)
-#endif
+#endif /* if DLZ_DLOPEN_VERSION == 1 */
{
isc_result_t result;
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
char *querystring = NULL;
const char *p;
char *namebuf;
@@ -240,11 +244,12 @@ dlz_lookup(const char *zone, const char *name,
#if DLZ_DLOPEN_VERSION >= 2
UNUSED(methods);
UNUSED(clientinfo);
-#endif
+#endif /* if DLZ_DLOPEN_VERSION >= 2 */
p = shortest_match(cd->zone_pattern, zone);
- if (p == NULL)
+ if (p == NULL) {
return (ISC_R_NOTFOUND);
+ }
DE_CONST(name, cd->record);
DE_CONST(p, cd->zone);
@@ -253,14 +258,16 @@ dlz_lookup(const char *zone, const char *name,
{
size_t len = p - zone;
namebuf = malloc(len);
- if (namebuf == NULL)
+ if (namebuf == NULL) {
return (ISC_R_NOMEMORY);
+ }
strncpy(namebuf, zone, len - 1);
namebuf[len - 1] = '\0';
cd->record = namebuf;
origin = false;
- } else if (p == zone)
+ } else if (p == zone) {
cd->record = "@";
+ }
/* Write info message to log */
cd->log(ISC_LOG_DEBUG(1),
@@ -275,8 +282,7 @@ dlz_lookup(const char *zone, const char *name,
if (strcmp(cd->record, nrec->name) == 0) {
/* We handle authority data in dlz_authority() */
if (strcmp(nrec->type, "SOA") == 0 ||
- strcmp(nrec->type, "NS") == 0)
- {
+ strcmp(nrec->type, "NS") == 0) {
nrec = next;
continue;
}
@@ -287,10 +293,11 @@ dlz_lookup(const char *zone, const char *name,
goto done;
}
- result = cd->putrr(lookup, nrec->type,
- nrec->ttl, querystring);
- if (result != ISC_R_SUCCESS)
+ result = cd->putrr(lookup, nrec->type, nrec->ttl,
+ querystring);
+ if (result != ISC_R_SUCCESS) {
goto done;
+ }
result = ISC_R_SUCCESS;
@@ -304,8 +311,9 @@ done:
cd->zone = NULL;
cd->record = NULL;
- if (querystring != NULL)
+ if (querystring != NULL) {
free(querystring);
+ }
return (result);
}
@@ -313,20 +321,21 @@ done:
isc_result_t
dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) {
isc_result_t result;
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
char *querystring = NULL;
nrr_t *nrec;
const char *p, *name = "@";
p = shortest_match(cd->zone_pattern, zone);
- if (p == NULL)
+ if (p == NULL) {
return (ISC_R_NOTFOUND);
+ }
DE_CONST(p, cd->zone);
/* Write info message to log */
- cd->log(ISC_LOG_DEBUG(1),
- "dlz_wildcard_dynamic: authority for '%s'", zone);
+ cd->log(ISC_LOG_DEBUG(1), "dlz_wildcard_dynamic: authority for '%s'",
+ zone);
result = ISC_R_NOTFOUND;
nrec = DLZ_LIST_HEAD(cd->rrs_list);
@@ -341,8 +350,8 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) {
goto done;
}
- presult = cd->putrr(lookup, nrec->type,
- nrec->ttl, querystring);
+ presult = cd->putrr(lookup, nrec->type, nrec->ttl,
+ querystring);
if (presult != ISC_R_SUCCESS) {
result = presult;
goto done;
@@ -359,8 +368,9 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) {
done:
cd->zone = NULL;
- if (querystring != NULL)
+ if (querystring != NULL) {
free(querystring);
+ }
return (result);
}
@@ -376,10 +386,12 @@ destroy_rrlist(config_data_t *cd) {
destroy_querylist(&trec->data);
- if (trec->name != NULL)
+ if (trec->name != NULL) {
free(trec->name);
- if (trec->type != NULL)
+ }
+ if (trec->type != NULL) {
free(trec->type);
+ }
trec->name = trec->type = NULL;
/* Get the next record, before we destroy this one. */
@@ -390,9 +402,8 @@ destroy_rrlist(config_data_t *cd) {
}
isc_result_t
-dlz_create(const char *dlzname, unsigned int argc, char *argv[],
- void **dbdata, ...)
-{
+dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
+ ...) {
config_data_t *cd;
char *endp;
int i, def_ttl;
@@ -401,18 +412,21 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
const char *helper_name;
va_list ap;
- if (argc < 8 || argc % 4 != 0)
+ if (argc < 8 || argc % 4 != 0) {
return (ISC_R_FAILURE);
+ }
cd = calloc(1, sizeof(config_data_t));
- if (cd == NULL)
+ if (cd == NULL) {
return (ISC_R_NOMEMORY);
+ }
memset(cd, 0, sizeof(config_data_t));
/* Fill in the helper functions */
va_start(ap, dbdata);
- while ((helper_name = va_arg(ap, const char*)) != NULL)
- b9_add_helper(cd, helper_name, va_arg(ap, void*));
+ while ((helper_name = va_arg(ap, const char *)) != NULL) {
+ b9_add_helper(cd, helper_name, va_arg(ap, void *));
+ }
va_end(ap);
/*
@@ -443,8 +457,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
result = ISC_R_NOMEMORY;
trec = malloc(sizeof(nrr_t));
- if (trec == NULL)
+ if (trec == NULL) {
goto full_cleanup;
+ }
memset(trec, 0, sizeof(nrr_t));
@@ -454,20 +469,22 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[],
DLZ_LIST_APPEND(cd->rrs_list, trec, link);
trec->name = strdup(argv[i]);
- if (trec->name == NULL)
+ if (trec->name == NULL) {
goto full_cleanup;
+ }
trec->type = strdup(argv[i + 2]);
- if (trec->type == NULL)
+ if (trec->type == NULL) {
goto full_cleanup;
+ }
trec->ttl = strtol(argv[i + 1], &endp, 10);
- if (argv[i + 1][0] == '\0' || *endp != '\0' || trec->ttl < 0)
+ if (argv[i + 1][0] == '\0' || *endp != '\0' || trec->ttl < 0) {
trec->ttl = def_ttl;
+ }
- result = build_querylist(argv[i + 3], &cd->zone,
- &cd->record, &cd->client,
- &trec->data, 0, cd->log);
+ result = build_querylist(argv[i + 3], &cd->zone, &cd->record,
+ &cd->client, &trec->data, 0, cd->log);
/* If unsuccessful, log err msg and cleanup */
if (result != ISC_R_SUCCESS) {
cd->log(ISC_LOG_ERROR,
@@ -485,10 +502,12 @@ full_cleanup:
destroy_rrlist(cd);
cleanup:
- if (cd->zone_pattern != NULL)
+ if (cd->zone_pattern != NULL) {
free(cd->zone_pattern);
- if (cd->axfr_pattern != NULL)
+ }
+ if (cd->axfr_pattern != NULL) {
free(cd->axfr_pattern);
+ }
free(cd);
return (result);
@@ -496,7 +515,7 @@ cleanup:
void
dlz_destroy(void *dbdata) {
- config_data_t *cd = (config_data_t *) dbdata;
+ config_data_t *cd = (config_data_t *)dbdata;
/*
* Write debugging message to log
@@ -510,7 +529,6 @@ dlz_destroy(void *dbdata) {
free(cd);
}
-
/*
* Return the version of the API
*/
@@ -526,31 +544,38 @@ dlz_version(unsigned int *flags) {
*/
static void
b9_add_helper(struct config_data *cd, const char *helper_name, void *ptr) {
- if (strcmp(helper_name, "log") == 0)
+ if (strcmp(helper_name, "log") == 0) {
cd->log = (log_t *)ptr;
- if (strcmp(helper_name, "putrr") == 0)
+ }
+ if (strcmp(helper_name, "putrr") == 0) {
cd->putrr = (dns_sdlz_putrr_t *)ptr;
- if (strcmp(helper_name, "putnamedrr") == 0)
+ }
+ if (strcmp(helper_name, "putnamedrr") == 0) {
cd->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
- if (strcmp(helper_name, "writeable_zone") == 0)
+ }
+ if (strcmp(helper_name, "writeable_zone") == 0) {
cd->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
+ }
}
static const char *
shortest_match(const char *pattern, const char *string) {
const char *p = string;
- if (pattern == NULL || p == NULL || *p == '\0')
+ if (pattern == NULL || p == NULL || *p == '\0') {
return (NULL);
+ }
p += strlen(p);
while (p-- > string) {
if (*p == '.') {
- if (fnmatch(pattern, p + 1, FNM_CASEFOLD) == 0)
+ if (fnmatch(pattern, p + 1, FNM_CASEFOLD) == 0) {
return (p + 1);
+ }
}
}
- if (fnmatch(pattern, string, FNM_CASEFOLD) == 0)
+ if (fnmatch(pattern, string, FNM_CASEFOLD) == 0) {
return (string);
+ }
return (NULL);
}
@@ -563,11 +588,11 @@ shortest_match(const char *pattern, const char *string) {
* in BIND, we want to be thread-safe and don't need multibyte - DNS names are
* always ASCII.
*/
-#define EOS '\0'
+#define EOS '\0'
-#define RANGE_MATCH 1
-#define RANGE_NOMATCH 0
-#define RANGE_ERROR (-1)
+#define RANGE_MATCH 1
+#define RANGE_NOMATCH 0
+#define RANGE_ERROR (-1)
static int
fnmatch(const char *pattern, const char *string, int flags) {
@@ -578,64 +603,83 @@ fnmatch(const char *pattern, const char *string, int flags) {
for (stringstart = string;;)
switch (c = *pattern++) {
case EOS:
- if ((flags & FNM_LEADING_DIR) && *string == '/')
+ if ((flags & FNM_LEADING_DIR) && *string == '/') {
return (0);
+ }
return (*string == EOS ? 0 : FNM_NOMATCH);
case '?':
- if (*string == EOS)
+ if (*string == EOS) {
return (FNM_NOMATCH);
- if (*string == '/' && (flags & FNM_PATHNAME))
+ }
+ if (*string == '/' && (flags & FNM_PATHNAME)) {
return (FNM_NOMATCH);
+ }
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ {
return (FNM_NOMATCH);
+ }
++string;
break;
case '*':
c = *pattern;
/* Collapse multiple stars. */
- while (c == '*')
+ while (c == '*') {
c = *++pattern;
+ }
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ {
return (FNM_NOMATCH);
+ }
/* Optimize for pattern with * at end or before /. */
- if (c == EOS)
- if (flags & FNM_PATHNAME)
+ if (c == EOS) {
+ if (flags & FNM_PATHNAME) {
return ((flags & FNM_LEADING_DIR) ||
- index(string, '/') == NULL ?
- 0 : FNM_NOMATCH);
- else
+ index(string,
+ '/') ==
+ NULL
+ ? 0
+ : FNM_NOMATCH);
+ } else {
return (0);
- else if (c == '/' && flags & FNM_PATHNAME) {
- if ((string = index(string, '/')) == NULL)
+ }
+ } else if (c == '/' && flags & FNM_PATHNAME) {
+ if ((string = index(string, '/')) == NULL) {
return (FNM_NOMATCH);
+ }
break;
}
/* General case, use recursion. */
while ((test = *string) != EOS) {
if (!fnmatch(pattern, string,
- flags & ~FNM_PERIOD))
+ flags & ~FNM_PERIOD)) {
return (0);
- if (test == '/' && flags & FNM_PATHNAME)
+ }
+ if (test == '/' && flags & FNM_PATHNAME) {
break;
+ }
++string;
}
return (FNM_NOMATCH);
case '[':
- if (*string == EOS)
+ if (*string == EOS) {
return (FNM_NOMATCH);
- if (*string == '/' && (flags & FNM_PATHNAME))
+ }
+ if (*string == '/' && (flags & FNM_PATHNAME)) {
return (FNM_NOMATCH);
+ }
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ ((flags & FNM_PATHNAME) && *(string - 1) == '/')))
+ {
return (FNM_NOMATCH);
+ }
switch (rangematch(pattern, *string, flags, &newp)) {
case RANGE_ERROR:
@@ -655,17 +699,17 @@ fnmatch(const char *pattern, const char *string, int flags) {
--pattern;
}
}
- /* FALLTHROUGH */
+ /* FALLTHROUGH */
default:
norm:
- if (c == *string)
- ;
- else if ((flags & FNM_CASEFOLD) &&
- (tolower((unsigned char)c) ==
- tolower((unsigned char)*string)))
- ;
- else
+ if (c == *string) {
+ } else if ((flags & FNM_CASEFOLD) &&
+ (tolower((unsigned char)c) ==
+ tolower((unsigned char)*string)))
+ {
+ } else {
return (FNM_NOMATCH);
+ }
string++;
break;
}
@@ -684,11 +728,13 @@ rangematch(const char *pattern, char test, int flags, char **newp) {
* consistency with the regular expression syntax.
* J.T. Conklin (conklin@ngai.kaleida.com)
*/
- if ( (negate = (*pattern == '!' || *pattern == '^')) )
+ if ((negate = (*pattern == '!' || *pattern == '^'))) {
++pattern;
+ }
- if (flags & FNM_CASEFOLD)
+ if (flags & FNM_CASEFOLD) {
test = tolower((unsigned char)test);
+ }
/*
* A right bracket shall lose its special meaning and represent
@@ -698,32 +744,41 @@ rangematch(const char *pattern, char test, int flags, char **newp) {
ok = 0;
c = *pattern++;
do {
- if (c == '\\' && !(flags & FNM_NOESCAPE))
+ if (c == '\\' && !(flags & FNM_NOESCAPE)) {
c = *pattern++;
- if (c == EOS)
+ }
+ if (c == EOS) {
return (RANGE_ERROR);
+ }
- if (c == '/' && (flags & FNM_PATHNAME))
+ if (c == '/' && (flags & FNM_PATHNAME)) {
return (RANGE_NOMATCH);
+ }
- if (flags & FNM_CASEFOLD)
+ if (flags & FNM_CASEFOLD) {
c = tolower((unsigned char)c);
+ }
- if (*pattern == '-'
- && (c2 = *(pattern+1)) != EOS && c2 != ']') {
+ if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS &&
+ c2 != ']') {
pattern += 2;
- if (c2 == '\\' && !(flags & FNM_NOESCAPE))
+ if (c2 == '\\' && !(flags & FNM_NOESCAPE)) {
c2 = *pattern++;
- if (c2 == EOS)
+ }
+ if (c2 == EOS) {
return (RANGE_ERROR);
+ }
- if (flags & FNM_CASEFOLD)
+ if (flags & FNM_CASEFOLD) {
c2 = tolower((unsigned char)c2);
+ }
- if (c <= test && test <= c2)
+ if (c <= test && test <= c2) {
ok = 1;
- } else if (c == test)
+ }
+ } else if (c == test) {
ok = 1;
+ }
} while ((c = *pattern++) != ']');
*newp = (char *)(uintptr_t)pattern;
diff --git a/contrib/dnspriv/nginx.conf b/contrib/dnspriv/nginx.conf
index 65e38683..763ff35f 100644
--- a/contrib/dnspriv/nginx.conf
+++ b/contrib/dnspriv/nginx.conf
@@ -2,7 +2,7 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
diff --git a/contrib/kasp/kasp2policy.py b/contrib/kasp/kasp2policy.py
index b78a968f..0b54d8ab 100644
--- a/contrib/kasp/kasp2policy.py
+++ b/contrib/kasp/kasp2policy.py
@@ -21,17 +21,21 @@
from xml.etree import cElementTree as ET
from collections import defaultdict
-from isc import dnskey
+import re
import ply.yacc as yacc
import ply.lex as lex
-import re
+from isc import dnskey
+
############################################################################
# Translate KASP duration values into seconds
############################################################################
-class kasptime:
- class ktlex:
- tokens = ( 'P', 'T', 'Y', 'M', 'D', 'H', 'S', 'NUM' )
+class KaspTime:
+ # pylint: disable=invalid-name
+ class KTLex:
+ # pylint: disable=invalid-name
+
+ tokens = ('P', 'T', 'Y', 'M', 'D', 'H', 'S', 'NUM')
t_P = r'(?i)P'
t_T = r'(?i)T'
@@ -41,12 +45,14 @@ class kasptime:
t_H = r'(?i)H'
t_S = r'(?i)S'
- def t_NUM(self, t):
+ @staticmethod
+ def t_NUM(t):
r'\d+'
t.value = int(t.value)
return t
- def t_error(self, t):
+ @staticmethod
+ def t_error(t):
print("Illegal character '%s'" % t.value[0])
t.lexer.skip(1)
@@ -54,7 +60,7 @@ class kasptime:
self.lexer = lex.lex(object=self)
def __init__(self):
- self.lexer = self.ktlex()
+ self.lexer = self.KTLex()
self.tokens = self.lexer.tokens
self.parser = yacc.yacc(debug=False, write_tables=False, module=self)
@@ -62,35 +68,43 @@ class kasptime:
self.lexer.lexer.lineno = 0
return self.parser.parse(text)
- def p_ktime_4(self, p):
+ @staticmethod
+ def p_ktime_4(p):
"ktime : P periods T times"
p[0] = p[2] + p[4]
- def p_ktime_3(self, p):
+ @staticmethod
+ def p_ktime_3(p):
"ktime : P T times"
p[0] = p[3]
- def p_ktime_2(self, p):
+ @staticmethod
+ def p_ktime_2(p):
"ktime : P periods"
p[0] = p[2]
- def p_periods_1(self, p):
+ @staticmethod
+ def p_periods_1(p):
"periods : period"
p[0] = p[1]
- def p_periods_2(self, p):
+ @staticmethod
+ def p_periods_2(p):
"periods : periods period"
p[0] = p[1] + p[2]
- def p_times_1(self, p):
+ @staticmethod
+ def p_times_1(p):
"times : time"
p[0] = p[1]
- def p_times_2(self, p):
+ @staticmethod
+ def p_times_2(p):
"times : times time"
p[0] = p[1] + p[2]
- def p_period(self, p):
+ @staticmethod
+ def p_period(p):
'''period : NUM Y
| NUM M
| NUM D'''
@@ -101,7 +115,8 @@ class kasptime:
elif p[2].lower() == 'd':
p[0] += int(p[1]) * 86400
- def p_time(self, p):
+ @staticmethod
+ def p_time(p):
'''time : NUM H
| NUM M
| NUM S'''
@@ -112,24 +127,28 @@ class kasptime:
elif p[2].lower() == 's':
p[0] = int(p[1])
- def p_error(self, p):
+ @staticmethod
+ def p_error():
print("Syntax error")
+
############################################################################
# Load the contents of a KASP XML file as a python dictionary
############################################################################
-class kasp():
+class Kasp():
+ # pylint: disable=invalid-name
+
@staticmethod
def _todict(t):
d = {t.tag: {} if t.attrib else None}
children = list(t)
if children:
dd = defaultdict(list)
- for dc in map(kasp._todict, children):
+ for dc in map(Kasp._todict, children):
for k, v in dc.iteritems():
dd[k].append(v)
- d = {t.tag:
- {k:v[0] if len(v) == 1 else v for k, v in dd.iteritems()}}
+ k = {k: v[0] if len(v) == 1 else v for k, v in dd.items()}
+ d = {t.tag: k}
if t.attrib:
d[t.tag].update(('@' + k, v) for k, v in t.attrib.iteritems())
if t.text:
@@ -142,7 +161,7 @@ class kasp():
return d
def __init__(self, filename):
- self._dict = kasp._todict(ET.parse(filename).getroot())
+ self._dict = Kasp._todict(ET.parse(filename).getroot())
def __getitem__(self, key):
return self._dict[key]
@@ -156,52 +175,54 @@ class kasp():
def __repr__(self):
return repr(self._dict)
+
############################################################################
# Load the contents of a KASP XML file as a python dictionary
############################################################################
if __name__ == "__main__":
- from pprint import *
import sys
if len(sys.argv) < 2:
print("Usage: kasp2policy <filename>")
- exit(1)
+ sys.exit(1)
+ KINFO = Kasp(sys.argv[1])
try:
- kinfo = kasp(sys.argv[1])
- except:
+ KINFO = Kasp(sys.argv[1])
+ except FileNotFoundError:
print("%s: unable to load KASP file '%s'" % (sys.argv[0], sys.argv[1]))
- exit(1)
+ sys.exit(1)
- kt = kasptime()
- first = True
+ KT = KaspTime()
+ FIRST = True
- for p in kinfo['KASP']['Policy']:
- if not p['@name'] or not p['Keys']: continue
- if not first:
+ for policy in KINFO['KASP']['Policy']:
+ if not policy['@name'] or not policy['Keys']:
+ continue
+ if not FIRST:
print("")
- first = False
- if p['Description']:
- d = p['Description'].strip()
- print("# %s" % re.sub(r"\n\s*", "\n# ", d))
- print("policy %s {" % p['@name'])
- ksk = p['Keys']['KSK']
- zsk = p['Keys']['ZSK']
+ FIRST = False
+ if policy['Description']:
+ desc = policy['Description'].strip()
+ print("# %s" % re.sub(r"\n\s*", "\n# ", desc))
+ print("policy %s {" % policy['@name'])
+ ksk = policy['Keys']['KSK']
+ zsk = policy['Keys']['ZSK']
kalg = ksk['Algorithm']
zalg = zsk['Algorithm']
algnum = kalg['#text'] or zalg['#text']
if algnum:
print("\talgorithm %s;" % dnskey.algstr(int(algnum)))
- if p['Keys']['TTL']:
- print("\tkeyttl %d;" % kt.parse(p['Keys']['TTL']))
+ if policy['Keys']['TTL']:
+ print("\tkeyttl %d;" % KT.parse(policy['Keys']['TTL']))
if kalg['@length']:
print("\tkey-size ksk %d;" % int(kalg['@length']))
if zalg['@length']:
print("\tkey-size zsk %d;" % int(zalg['@length']))
if ksk['Lifetime']:
- print("\troll-period ksk %d;" % kt.parse(ksk['Lifetime']))
+ print("\troll-period ksk %d;" % KT.parse(ksk['Lifetime']))
if zsk['Lifetime']:
- print("\troll-period zsk %d;" % kt.parse(zsk['Lifetime']))
+ print("\troll-period zsk %d;" % KT.parse(zsk['Lifetime']))
if ksk['Standby']:
print("\tstandby ksk %d;" % int(ksk['Standby']))
if zsk['Standby']:
diff --git a/contrib/scripts/catzhash.py b/contrib/scripts/catzhash.py
new file mode 100644
index 00000000..8ad61c39
--- /dev/null
+++ b/contrib/scripts/catzhash.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+# catzhash.py: generate the SHA-1 hash of a domain name in wire format.
+#
+# This can be used to determine the label to use in a catalog zone to
+# represent the specified zone. For example, the zone
+# "domain.example" can be represented in a catalog zone called
+# "catalog.example" by adding the following record:
+#
+# 5960775ba382e7a4e09263fc06e7c00569b6a05c.zones.catalog.example. \
+# IN PTR domain.example.
+#
+# The label "5960775ba382e7a4e09263fc06e7c00569b6a05c" is the output of
+# this script when run with the argument "domain.example".
+
+import sys
+import hashlib
+import dns.name
+
+if len(sys.argv) < 2:
+ print("Usage: %s name" % sys.argv[0])
+
+NAME = dns.name.from_text(sys.argv[1]).to_wire()
+print(hashlib.sha1(NAME).hexdigest())
diff --git a/contrib/scripts/check-secure-delegation.pl.in b/contrib/scripts/check-secure-delegation.pl.in
index 528900ad..8a792435 100644
--- a/contrib/scripts/check-secure-delegation.pl.in
+++ b/contrib/scripts/check-secure-delegation.pl.in
@@ -4,7 +4,7 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
diff --git a/contrib/scripts/named-bootconf.sh b/contrib/scripts/named-bootconf.sh
index 29e41059..cef5f8af 100644
--- a/contrib/scripts/named-bootconf.sh
+++ b/contrib/scripts/named-bootconf.sh
@@ -4,7 +4,7 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
diff --git a/contrib/scripts/nanny.pl b/contrib/scripts/nanny.pl
index cb93441a..380b8711 100644
--- a/contrib/scripts/nanny.pl
+++ b/contrib/scripts/nanny.pl
@@ -4,7 +4,7 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
diff --git a/contrib/scripts/zone-edit.sh.in b/contrib/scripts/zone-edit.sh.in
index 18132f9f..e40f173c 100644
--- a/contrib/scripts/zone-edit.sh.in
+++ b/contrib/scripts/zone-edit.sh.in
@@ -4,7 +4,7 @@
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.