Add ldap patched bind and dhcp

git-svn-id: https://svn.disconnected-by-peer.at/svn/linamh/trunk/linamh@373 6952d904-891a-0410-993b-d76249ca496b
This commit is contained in:
geos_one
2008-06-08 13:25:18 +00:00
parent 005a694339
commit bc639769e8
60 changed files with 10114 additions and 12 deletions

View File

@@ -0,0 +1 @@
CONFIG_PROTECT="/var/bind"

View File

@@ -0,0 +1,11 @@
$ORIGIN 127.in-addr.arpa.
$TTL 1W
@ 1D IN SOA localhost. root.localhost. (
2002081601 ; serial
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
1D IN NS localhost.
1 1D IN PTR localhost.

View File

@@ -0,0 +1,11 @@
--- configure.in.orig 2005-03-25 23:33:33.000000000 +0300
+++ configure.in 2005-03-25 23:34:04.000000000 +0300
@@ -453,7 +453,7 @@
then
use_dlz_bdb=$d
DLZ_BDB_INCDIR=$use_dlz_bdb/include
- DLB_BDB_LIB="-ldb"
+ DLZ_BDB_LIB="-ldb"
break
fi
done

View File

@@ -0,0 +1,402 @@
diff -uraN bind-9.2.5-dlz/bin/named/include/mysqldb.h bind-9.2.5-dlz-mysql/bin/named/include/mysqldb.h
--- bind-9.2.5-dlz/bin/named/include/mysqldb.h 1970-01-01 03:00:00.000000000 +0300
+++ bind-9.2.5-dlz-mysql/bin/named/include/mysqldb.h 2005-03-25 21:41:25.000000000 +0300
@@ -0,0 +1,7 @@
+
+#include <isc/types.h>
+
+isc_result_t mysqldb_init(void);
+
+void mysqldb_clear(void);
+
diff -uraN bind-9.2.5-dlz/bin/named/main.c bind-9.2.5-dlz-mysql/bin/named/main.c
--- bind-9.2.5-dlz/bin/named/main.c 2005-03-25 21:41:01.000000000 +0300
+++ bind-9.2.5-dlz-mysql/bin/named/main.c 2005-03-25 21:41:25.000000000 +0300
@@ -68,6 +68,7 @@
* Include header files for database drivers here.
*/
/* #include "xxdb.h" */
+#include "mysqldb.h"
#ifdef DLZ_STUB
#include <named/dlz_stub_driver.h>
@@ -594,6 +595,7 @@
* Add calls to register sdb drivers here.
*/
/* xxdb_init(); */
+ mysqldb_init ();
#ifdef DLZ_STUB
dlz_stub_init();
@@ -637,6 +639,7 @@
* Add calls to unregister sdb drivers here.
*/
/* xxdb_clear(); */
+ mysqldb_clear ();
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "exiting");
diff -uraN bind-9.2.5-dlz/bin/named/Makefile.in bind-9.2.5-dlz-mysql/bin/named/Makefile.in
--- bind-9.2.5-dlz/bin/named/Makefile.in 2005-03-25 21:41:01.000000000 +0300
+++ bind-9.2.5-dlz-mysql/bin/named/Makefile.in 2005-03-25 21:41:25.000000000 +0300
@@ -26,10 +26,10 @@
#
# Add database drivers here.
#
-DBDRIVER_OBJS =
-DBDRIVER_SRCS =
-DBDRIVER_INCLUDES =
-DBDRIVER_LIBS =
+DBDRIVER_OBJS = mysqldb.@O@
+DBDRIVER_SRCS = mysqldb.c
+DBDRIVER_INCLUDES = -I/usr/local/include
+DBDRIVER_LIBS = -L/usr/local/lib/mysql -lmysqlclient
DLZINCLUDES = @DLZ_BDB_INC@ @DLZ_POSTGRES_INC@ @DLZ_ODBC_INC@ \
@DLZ_MYSQL_INC@ @DLZ_LDAP_INC@
diff -uraN bind-9.2.5-dlz/bin/named/mysqldb.c bind-9.2.5-dlz-mysql/bin/named/mysqldb.c
--- bind-9.2.5-dlz/bin/named/mysqldb.c 1970-01-01 03:00:00.000000000 +0300
+++ bind-9.2.5-dlz-mysql/bin/named/mysqldb.c 2005-03-25 21:41:25.000000000 +0300
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2002 Mihai Chelaru ( kefren@netbastards.org )
+ *
+ * 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 I DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL I BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS 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.
+ */
+
+
+#include <config.h>
+#include <stdio.h>
+#include <malloc.h>
+#include <mysql/mysql.h>
+#include <isc/mem.h>
+#include <dns/sdb.h>
+#include <dns/result.h>
+#include <named/globals.h>
+
+#include <mysqldb.h>
+
+#define ROWS 20
+#define MAXCOLUMN 200
+
+/*
+#define ONEDATABASE
+#define MDEBUG
+*/
+struct mysqlrow {
+ char *s[ROWS];
+};
+
+static dns_sdbimplementation_t *mysqldb = NULL;
+
+struct mydbinfo {
+ MYSQL *conn;
+ char *database;
+ char *table;
+ char *host;
+ char *user;
+ char *passwd;
+};
+
+/* My internal functions */
+
+int mysql_dbcon(struct mydbinfo *);
+
+int
+mysql_dbcon(struct mydbinfo * dbi)
+{
+#ifdef MDEBUG
+ printf("Connecting\n");
+#endif
+ dbi->conn=mysql_init(NULL);
+ if (dbi->conn == NULL) return 0;
+ if (!mysql_real_connect(dbi->conn, dbi->host, dbi->user, dbi->passwd, dbi->database, 3306, NULL, 0))
+ return 0;
+#ifdef MDEBUG
+ printf("Connected\n");
+#endif
+ return 1;
+}
+
+/* External functions */
+
+static isc_result_t
+mysqldb_lookup(const char *zone, const char *name, void *dbdata, dns_sdblookup_t * lookup)
+{
+ char *querystring = NULL, seclook[150];
+ struct mydbinfo *dbi = (struct mydbinfo *) dbdata;
+ MYSQL_RES *result;
+ struct mysqlrow myrow;
+ int i, j, totlen;
+ MYSQL_ROW row;
+ int num_fields, putrr_success=0;
+#ifdef MDEBUG
+ printf("Lookup in %.200s for %.200s ", zone, name);
+#endif
+ querystring = (char *) malloc(200);
+ if (!querystring)
+ return ISC_R_NOMEMORY;
+ snprintf(querystring, 200, "SELECT TTL,RDTYPE,RDATA FROM %s where name='%.150s'", dbi->table, name);
+#ifdef MDEBUG
+ printf("Query = %s\n", querystring);
+#endif
+ mysql_ping(dbi->conn);
+ if (mysql_query(dbi->conn, querystring)) {
+ printf("Query Error in lookup\n");
+ free(querystring);
+ return ISC_R_FAILURE;
+ }
+ free(querystring);
+ result = mysql_store_result(dbi->conn);
+
+ num_fields = mysql_num_fields(result);
+ if (num_fields > ROWS) {
+ printf("Incorrect database format\n");
+ mysql_free_result(result);
+ return ISC_R_FAILURE;
+ }
+ /* allocate to fetch */
+ for (i = 0; i < ROWS; i++)
+ if (!(myrow.s[i] = (char *) malloc(MAXCOLUMN))) {
+ for (j = 0; j < i; j++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+ return ISC_R_NOMEMORY;
+ }
+ /* Ok. we found no reason why to not let fetch */
+ while ((row = mysql_fetch_row(result))) {
+ unsigned long *lengths;
+ lengths = mysql_fetch_lengths(result);
+ totlen = 0;
+ for (i = 0; i < num_fields; i++) {
+ totlen += lengths[i];
+ snprintf(myrow.s[i], MAXCOLUMN, "%.*s", (int) lengths[i], row[i] ? row[i] : "NULL");
+ }
+#ifdef MDEBUG
+ printf("Lookup: %s %s %s\n", myrow.s[0], myrow.s[1], myrow.s[2]);
+#endif
+ if (dns_sdb_putrr(lookup, myrow.s[1], strtol(myrow.s[0], NULL, 10), myrow.s[2]) != ISC_R_SUCCESS) {
+ for (i = 0; i < ROWS; i++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+ printf("Lookup Failure\n");
+ return ISC_R_FAILURE;
+ } else putrr_success=1;
+ }
+#ifdef MDEBUG
+ printf ("Bailing out lookup\n");
+#endif
+ /* Ok. success. bail out. */
+ for (i = 0; i < ROWS; i++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+
+ /* Check if there is any *.foo.com available and return it in case that this is not a *.foo.com call */
+ if ((!putrr_success)&&(name[0]!='*')) {
+#ifdef MDEBUG
+printf ("Cannot find it. Trying to check * record\n");
+#endif
+ snprintf (seclook,150,"*.%s",zone);
+ return mysqldb_lookup (zone, seclook, dbdata, lookup);
+ }
+
+ /* else return SUCCESS */
+ return ISC_R_SUCCESS;
+}
+
+static isc_result_t
+mysqldb_allnodes(const char *zone, void *dbdata, dns_sdballnodes_t * allnodes)
+{
+ char *querystring = NULL;
+ struct mydbinfo *dbi = (struct mydbinfo *) dbdata;
+ MYSQL_RES *result;
+ struct mysqlrow myrow;
+ MYSQL_ROW row;
+ int num_fields;
+ int i, totlen, j;
+#ifdef MDEBUG
+ printf("All Nodes\n");
+#endif
+ querystring = (char *) malloc(200);
+ if (!querystring)
+ return ISC_R_NOMEMORY;
+ snprintf(querystring, 200, "SELECT TTL,NAME,RDTYPE,RDATA FROM %s where name like('%%%.150s')", dbi->table, zone);
+ mysql_ping(dbi->conn);
+ if (mysql_query(dbi->conn, querystring)) {
+ printf("Query Error\n");
+ free(querystring);
+ return ISC_R_FAILURE;
+ }
+ free(querystring);
+ result = mysql_store_result(dbi->conn);
+
+ num_fields = mysql_num_fields(result);
+ if (num_fields > ROWS) {
+ printf("Incorrect database format\n");
+ mysql_free_result(result);
+ return ISC_R_FAILURE;
+ }
+ /* allocate to fetch */
+ for (i = 0; i < ROWS; i++)
+ if (!(myrow.s[i] = (char *) malloc(MAXCOLUMN))) {
+ for (j = 0; j < i; j++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+ return ISC_R_NOMEMORY;
+ }
+ /* Ok. we found no reason why to not let fetch */
+ while ((row = mysql_fetch_row(result))) {
+ unsigned long *lengths;
+ lengths = mysql_fetch_lengths(result);
+ totlen = 0;
+ for (i = 0; i < num_fields; i++) {
+ totlen += lengths[i];
+ snprintf(myrow.s[i], MAXCOLUMN, "%.*s", (int) lengths[i], row[i] ? row[i] : "NULL");
+ }
+#ifdef MDEBUG
+ printf("All Nodes: %s %s %s %s\n", myrow.s[0], myrow.s[1], myrow.s[2], myrow.s[3]);
+#endif
+ if (dns_sdb_putnamedrr(allnodes, myrow.s[1], myrow.s[2], strtol(myrow.s[0], NULL, 10), myrow.s[3]) != ISC_R_SUCCESS) {
+ for (i = 0; i < ROWS; i++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+ return ISC_R_FAILURE;
+ }
+ }
+
+ /* Ok. success. bail out. */
+ mysql_free_result(result);
+ for (i = 0; i < ROWS; i++)
+ free(myrow.s[i]);
+ return ISC_R_SUCCESS;
+}
+
+
+
+/*
+ * Open database argv[i]=database,table,hostname,user,passwd
+ */
+
+static isc_result_t
+mysqldb_create(const char *zone, int argc, char **argv, void *driverdata, void **dbdata)
+{
+ struct mydbinfo *dbi;
+ #ifdef ONEDATABASE
+ static MYSQL *dbconstat;
+ #endif
+
+ /* Argument count checking */
+ if (argc < 5)
+ return ISC_R_FAILURE;
+
+ /* dbi init */
+
+ dbi = (struct mydbinfo *) isc_mem_get(ns_g_mctx, sizeof(struct mydbinfo));
+ if (!dbi)
+ return ISC_R_NOMEMORY;
+ dbi->database = NULL;
+ dbi->table = NULL;
+ dbi->host = NULL;
+ dbi->user = NULL;
+ dbi->passwd = NULL;
+
+ dbi->database = isc_mem_strdup(ns_g_mctx, argv[0]);
+ dbi->table = isc_mem_strdup(ns_g_mctx, argv[1]);
+ dbi->host = isc_mem_strdup(ns_g_mctx, argv[2]);
+ dbi->user = isc_mem_strdup(ns_g_mctx, argv[3]);
+ dbi->passwd = isc_mem_strdup(ns_g_mctx, argv[4]);
+
+ if ((!dbi->database) || (!dbi->table) || (!dbi->host) || (!dbi->user) || (!dbi->passwd)) {
+ printf("Cannot strdup\n");
+ if (dbi->conn)
+ mysql_close(dbi->conn);
+ if (dbi->database)
+ isc_mem_free(ns_g_mctx, dbi->database);
+ if (dbi->table)
+ isc_mem_free(ns_g_mctx, dbi->table);
+ if (dbi->host)
+ isc_mem_free(ns_g_mctx, dbi->host);
+ if (dbi->user)
+ isc_mem_free(ns_g_mctx, dbi->user);
+ if (dbi->passwd)
+ isc_mem_free(ns_g_mctx, dbi->passwd);
+ isc_mem_put(ns_g_mctx, dbi, sizeof(struct mydbinfo));
+ return ISC_R_NOMEMORY;
+ }
+ /* connect to database */
+ #ifdef ONEDATABASE
+ if (!((dbconstat) && (!mysql_ping(dbconstat))))
+ #endif
+ if (!mysql_dbcon(dbi)) {
+ printf("Cannot connect to database\n");
+ return ISC_R_FAILURE;
+ }
+ #ifdef ONEDATABASE
+ if (dbconstat) dbi->conn = dbconstat; else dbconstat = dbi->conn;
+ #endif
+ *dbdata = dbi;
+ return ISC_R_SUCCESS;
+}
+
+static void
+mysqldb_destroy(const char *zone, void *driverdata, void **dbdata)
+{
+ struct mydbinfo *dbi;
+
+ dbi = (struct mydbinfo *) (*dbdata);
+ if (!dbi)
+ return;
+ if (dbi->conn)
+ mysql_close(dbi->conn);
+ if (dbi->database)
+ isc_mem_free(ns_g_mctx, dbi->database);
+ if (dbi->table)
+ isc_mem_free(ns_g_mctx, dbi->table);
+ if (dbi->host)
+ isc_mem_free(ns_g_mctx, dbi->host);
+ if (dbi->user)
+ isc_mem_free(ns_g_mctx, dbi->user);
+ if (dbi->passwd)
+ isc_mem_free(ns_g_mctx, dbi->passwd);
+ isc_mem_put(ns_g_mctx, dbi, sizeof(struct mydbinfo));
+#ifdef MDEBUG
+ printf("Destroyed\n");
+#endif
+}
+
+
+/* SDB methods */
+
+static dns_sdbmethods_t mysqldb_methods = {
+ mysqldb_lookup,
+ NULL, /* authority */
+ mysqldb_allnodes,
+ mysqldb_create,
+ mysqldb_destroy
+};
+
+
+
+isc_result_t
+mysqldb_init()
+{
+ unsigned int flags = 0;
+ return dns_sdb_register("mysql", &mysqldb_methods, NULL, flags, ns_g_mctx, &mysqldb);
+}
+
+void
+mysqldb_clear()
+{
+ if (mysqldb)
+ dns_sdb_unregister(&mysqldb);
+}

View File

@@ -0,0 +1,402 @@
diff -uraN bind-9.2.5-orig/bin/named/include/mysqldb.h bind-9.2.5-mysql/bin/named/include/mysqldb.h
--- bind-9.2.5-orig/bin/named/include/mysqldb.h 1970-01-01 03:00:00.000000000 +0300
+++ bind-9.2.5-mysql/bin/named/include/mysqldb.h 2005-03-25 21:35:47.000000000 +0300
@@ -0,0 +1,7 @@
+
+#include <isc/types.h>
+
+isc_result_t mysqldb_init(void);
+
+void mysqldb_clear(void);
+
diff -uraN bind-9.2.5-orig/bin/named/main.c bind-9.2.5-mysql/bin/named/main.c
--- bind-9.2.5-orig/bin/named/main.c 2004-10-25 04:50:53.000000000 +0400
+++ bind-9.2.5-mysql/bin/named/main.c 2005-03-25 21:35:47.000000000 +0300
@@ -68,6 +68,7 @@
* Include header files for database drivers here.
*/
/* #include "xxdb.h" */
+#include "mysqldb.h"
static isc_boolean_t want_stats = ISC_FALSE;
static char program_name[ISC_DIR_NAMEMAX] = "named";
@@ -565,6 +566,7 @@
* Add calls to register sdb drivers here.
*/
/* xxdb_init(); */
+ mysqldb_init ();
ns_server_create(ns_g_mctx, &ns_g_server);
}
@@ -579,6 +581,7 @@
* Add calls to unregister sdb drivers here.
*/
/* xxdb_clear(); */
+ mysqldb_clear ();
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "exiting");
diff -uraN bind-9.2.5-orig/bin/named/Makefile.in bind-9.2.5-mysql/bin/named/Makefile.in
--- bind-9.2.5-orig/bin/named/Makefile.in 2004-09-07 01:42:06.000000000 +0400
+++ bind-9.2.5-mysql/bin/named/Makefile.in 2005-03-25 21:35:47.000000000 +0300
@@ -26,10 +26,10 @@
#
# Add database drivers here.
#
-DBDRIVER_OBJS =
-DBDRIVER_SRCS =
-DBDRIVER_INCLUDES =
-DBDRIVER_LIBS =
+DBDRIVER_OBJS = mysqldb.@O@
+DBDRIVER_SRCS = mysqldb.c
+DBDRIVER_INCLUDES = -I/usr/local/include
+DBDRIVER_LIBS = -L/usr/local/lib/mysql -lmysqlclient
CINCLUDES = -I${srcdir}/include -I${srcdir}/unix/include \
${LWRES_INCLUDES} ${DNS_INCLUDES} \
diff -uraN bind-9.2.5-orig/bin/named/mysqldb.c bind-9.2.5-mysql/bin/named/mysqldb.c
--- bind-9.2.5-orig/bin/named/mysqldb.c 1970-01-01 03:00:00.000000000 +0300
+++ bind-9.2.5-mysql/bin/named/mysqldb.c 2005-03-25 21:35:47.000000000 +0300
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2002 Mihai Chelaru ( kefren@netbastards.org )
+ *
+ * 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 I DISCLAIM ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL I BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+ * FROM LOSS 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.
+ */
+
+
+#include <config.h>
+#include <stdio.h>
+#include <malloc.h>
+#include <mysql/mysql.h>
+#include <isc/mem.h>
+#include <dns/sdb.h>
+#include <dns/result.h>
+#include <named/globals.h>
+
+#include <mysqldb.h>
+
+#define ROWS 20
+#define MAXCOLUMN 200
+
+/*
+#define ONEDATABASE
+#define MDEBUG
+*/
+struct mysqlrow {
+ char *s[ROWS];
+};
+
+static dns_sdbimplementation_t *mysqldb = NULL;
+
+struct mydbinfo {
+ MYSQL *conn;
+ char *database;
+ char *table;
+ char *host;
+ char *user;
+ char *passwd;
+};
+
+/* My internal functions */
+
+int mysql_dbcon(struct mydbinfo *);
+
+int
+mysql_dbcon(struct mydbinfo * dbi)
+{
+#ifdef MDEBUG
+ printf("Connecting\n");
+#endif
+ dbi->conn=mysql_init(NULL);
+ if (dbi->conn == NULL) return 0;
+ if (!mysql_real_connect(dbi->conn, dbi->host, dbi->user, dbi->passwd, dbi->database, 3306, NULL, 0))
+ return 0;
+#ifdef MDEBUG
+ printf("Connected\n");
+#endif
+ return 1;
+}
+
+/* External functions */
+
+static isc_result_t
+mysqldb_lookup(const char *zone, const char *name, void *dbdata, dns_sdblookup_t * lookup)
+{
+ char *querystring = NULL, seclook[150];
+ struct mydbinfo *dbi = (struct mydbinfo *) dbdata;
+ MYSQL_RES *result;
+ struct mysqlrow myrow;
+ int i, j, totlen;
+ MYSQL_ROW row;
+ int num_fields, putrr_success=0;
+#ifdef MDEBUG
+ printf("Lookup in %.200s for %.200s ", zone, name);
+#endif
+ querystring = (char *) malloc(200);
+ if (!querystring)
+ return ISC_R_NOMEMORY;
+ snprintf(querystring, 200, "SELECT TTL,RDTYPE,RDATA FROM %s where name='%.150s'", dbi->table, name);
+#ifdef MDEBUG
+ printf("Query = %s\n", querystring);
+#endif
+ mysql_ping(dbi->conn);
+ if (mysql_query(dbi->conn, querystring)) {
+ printf("Query Error in lookup\n");
+ free(querystring);
+ return ISC_R_FAILURE;
+ }
+ free(querystring);
+ result = mysql_store_result(dbi->conn);
+
+ num_fields = mysql_num_fields(result);
+ if (num_fields > ROWS) {
+ printf("Incorrect database format\n");
+ mysql_free_result(result);
+ return ISC_R_FAILURE;
+ }
+ /* allocate to fetch */
+ for (i = 0; i < ROWS; i++)
+ if (!(myrow.s[i] = (char *) malloc(MAXCOLUMN))) {
+ for (j = 0; j < i; j++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+ return ISC_R_NOMEMORY;
+ }
+ /* Ok. we found no reason why to not let fetch */
+ while ((row = mysql_fetch_row(result))) {
+ unsigned long *lengths;
+ lengths = mysql_fetch_lengths(result);
+ totlen = 0;
+ for (i = 0; i < num_fields; i++) {
+ totlen += lengths[i];
+ snprintf(myrow.s[i], MAXCOLUMN, "%.*s", (int) lengths[i], row[i] ? row[i] : "NULL");
+ }
+#ifdef MDEBUG
+ printf("Lookup: %s %s %s\n", myrow.s[0], myrow.s[1], myrow.s[2]);
+#endif
+ if (dns_sdb_putrr(lookup, myrow.s[1], strtol(myrow.s[0], NULL, 10), myrow.s[2]) != ISC_R_SUCCESS) {
+ for (i = 0; i < ROWS; i++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+ printf("Lookup Failure\n");
+ return ISC_R_FAILURE;
+ } else putrr_success=1;
+ }
+#ifdef MDEBUG
+ printf ("Bailing out lookup\n");
+#endif
+ /* Ok. success. bail out. */
+ for (i = 0; i < ROWS; i++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+
+ /* Check if there is any *.foo.com available and return it in case that this is not a *.foo.com call */
+ if ((!putrr_success)&&(name[0]!='*')) {
+#ifdef MDEBUG
+printf ("Cannot find it. Trying to check * record\n");
+#endif
+ snprintf (seclook,150,"*.%s",zone);
+ return mysqldb_lookup (zone, seclook, dbdata, lookup);
+ }
+
+ /* else return SUCCESS */
+ return ISC_R_SUCCESS;
+}
+
+static isc_result_t
+mysqldb_allnodes(const char *zone, void *dbdata, dns_sdballnodes_t * allnodes)
+{
+ char *querystring = NULL;
+ struct mydbinfo *dbi = (struct mydbinfo *) dbdata;
+ MYSQL_RES *result;
+ struct mysqlrow myrow;
+ MYSQL_ROW row;
+ int num_fields;
+ int i, totlen, j;
+#ifdef MDEBUG
+ printf("All Nodes\n");
+#endif
+ querystring = (char *) malloc(200);
+ if (!querystring)
+ return ISC_R_NOMEMORY;
+ snprintf(querystring, 200, "SELECT TTL,NAME,RDTYPE,RDATA FROM %s where name like('%%%.150s')", dbi->table, zone);
+ mysql_ping(dbi->conn);
+ if (mysql_query(dbi->conn, querystring)) {
+ printf("Query Error\n");
+ free(querystring);
+ return ISC_R_FAILURE;
+ }
+ free(querystring);
+ result = mysql_store_result(dbi->conn);
+
+ num_fields = mysql_num_fields(result);
+ if (num_fields > ROWS) {
+ printf("Incorrect database format\n");
+ mysql_free_result(result);
+ return ISC_R_FAILURE;
+ }
+ /* allocate to fetch */
+ for (i = 0; i < ROWS; i++)
+ if (!(myrow.s[i] = (char *) malloc(MAXCOLUMN))) {
+ for (j = 0; j < i; j++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+ return ISC_R_NOMEMORY;
+ }
+ /* Ok. we found no reason why to not let fetch */
+ while ((row = mysql_fetch_row(result))) {
+ unsigned long *lengths;
+ lengths = mysql_fetch_lengths(result);
+ totlen = 0;
+ for (i = 0; i < num_fields; i++) {
+ totlen += lengths[i];
+ snprintf(myrow.s[i], MAXCOLUMN, "%.*s", (int) lengths[i], row[i] ? row[i] : "NULL");
+ }
+#ifdef MDEBUG
+ printf("All Nodes: %s %s %s %s\n", myrow.s[0], myrow.s[1], myrow.s[2], myrow.s[3]);
+#endif
+ if (dns_sdb_putnamedrr(allnodes, myrow.s[1], myrow.s[2], strtol(myrow.s[0], NULL, 10), myrow.s[3]) != ISC_R_SUCCESS) {
+ for (i = 0; i < ROWS; i++)
+ free(myrow.s[i]);
+ mysql_free_result(result);
+ return ISC_R_FAILURE;
+ }
+ }
+
+ /* Ok. success. bail out. */
+ mysql_free_result(result);
+ for (i = 0; i < ROWS; i++)
+ free(myrow.s[i]);
+ return ISC_R_SUCCESS;
+}
+
+
+
+/*
+ * Open database argv[i]=database,table,hostname,user,passwd
+ */
+
+static isc_result_t
+mysqldb_create(const char *zone, int argc, char **argv, void *driverdata, void **dbdata)
+{
+ struct mydbinfo *dbi;
+ #ifdef ONEDATABASE
+ static MYSQL *dbconstat;
+ #endif
+
+ /* Argument count checking */
+ if (argc < 5)
+ return ISC_R_FAILURE;
+
+ /* dbi init */
+
+ dbi = (struct mydbinfo *) isc_mem_get(ns_g_mctx, sizeof(struct mydbinfo));
+ if (!dbi)
+ return ISC_R_NOMEMORY;
+ dbi->database = NULL;
+ dbi->table = NULL;
+ dbi->host = NULL;
+ dbi->user = NULL;
+ dbi->passwd = NULL;
+
+ dbi->database = isc_mem_strdup(ns_g_mctx, argv[0]);
+ dbi->table = isc_mem_strdup(ns_g_mctx, argv[1]);
+ dbi->host = isc_mem_strdup(ns_g_mctx, argv[2]);
+ dbi->user = isc_mem_strdup(ns_g_mctx, argv[3]);
+ dbi->passwd = isc_mem_strdup(ns_g_mctx, argv[4]);
+
+ if ((!dbi->database) || (!dbi->table) || (!dbi->host) || (!dbi->user) || (!dbi->passwd)) {
+ printf("Cannot strdup\n");
+ if (dbi->conn)
+ mysql_close(dbi->conn);
+ if (dbi->database)
+ isc_mem_free(ns_g_mctx, dbi->database);
+ if (dbi->table)
+ isc_mem_free(ns_g_mctx, dbi->table);
+ if (dbi->host)
+ isc_mem_free(ns_g_mctx, dbi->host);
+ if (dbi->user)
+ isc_mem_free(ns_g_mctx, dbi->user);
+ if (dbi->passwd)
+ isc_mem_free(ns_g_mctx, dbi->passwd);
+ isc_mem_put(ns_g_mctx, dbi, sizeof(struct mydbinfo));
+ return ISC_R_NOMEMORY;
+ }
+ /* connect to database */
+ #ifdef ONEDATABASE
+ if (!((dbconstat) && (!mysql_ping(dbconstat))))
+ #endif
+ if (!mysql_dbcon(dbi)) {
+ printf("Cannot connect to database\n");
+ return ISC_R_FAILURE;
+ }
+ #ifdef ONEDATABASE
+ if (dbconstat) dbi->conn = dbconstat; else dbconstat = dbi->conn;
+ #endif
+ *dbdata = dbi;
+ return ISC_R_SUCCESS;
+}
+
+static void
+mysqldb_destroy(const char *zone, void *driverdata, void **dbdata)
+{
+ struct mydbinfo *dbi;
+
+ dbi = (struct mydbinfo *) (*dbdata);
+ if (!dbi)
+ return;
+ if (dbi->conn)
+ mysql_close(dbi->conn);
+ if (dbi->database)
+ isc_mem_free(ns_g_mctx, dbi->database);
+ if (dbi->table)
+ isc_mem_free(ns_g_mctx, dbi->table);
+ if (dbi->host)
+ isc_mem_free(ns_g_mctx, dbi->host);
+ if (dbi->user)
+ isc_mem_free(ns_g_mctx, dbi->user);
+ if (dbi->passwd)
+ isc_mem_free(ns_g_mctx, dbi->passwd);
+ isc_mem_put(ns_g_mctx, dbi, sizeof(struct mydbinfo));
+#ifdef MDEBUG
+ printf("Destroyed\n");
+#endif
+}
+
+
+/* SDB methods */
+
+static dns_sdbmethods_t mysqldb_methods = {
+ mysqldb_lookup,
+ NULL, /* authority */
+ mysqldb_allnodes,
+ mysqldb_create,
+ mysqldb_destroy
+};
+
+
+
+isc_result_t
+mysqldb_init()
+{
+ unsigned int flags = 0;
+ return dns_sdb_register("mysql", &mysqldb_methods, NULL, flags, ns_g_mctx, &mysqldb);
+}
+
+void
+mysqldb_clear()
+{
+ if (mysqldb)
+ dns_sdb_unregister(&mysqldb);
+}

View File

@@ -0,0 +1,20 @@
--- configure.in 2006-07-09 22:00:54.000000000 +0000
+++ configure.in 2006-07-09 22:01:05.000000000 +0000
@@ -686,17 +686,7 @@
fi
done
- if test -z "`${CC} contrib/sdb/test//test.c -lodbc -o contrib/sdb/test/test.ok 2>&1`"; then
DLZ_ODBC_LIB="-lodbc"
- elif test -z "`${CC} contrib/sdb/test//test.c -liodbc -o contrib/sdb/test/test.ok 2>&1`"; then
- DLZ_ODBC_LIB="-liodbc"
- else
- DLZ_ODBC_LIB=""
- use_dlz_odbc="no"
- AC_MSG_RESULT("no ODBC libraries found")
- fi
- rm -f contrib/sdb/test/test.ok
-
if test "$use_dlz_odbc" = "yes"
then

View File

@@ -0,0 +1,20 @@
--- configure.in 2006-07-09 22:00:54.000000000 +0000
+++ configure.in 2006-07-09 22:01:05.000000000 +0000
@@ -686,17 +686,7 @@
fi
done
- if test -z "`${CC} contrib/sdb/test//test.c -lodbc -o contrib/sdb/test/test.ok 2>&1`"; then
DLZ_ODBC_LIB="-lodbc"
- elif test -z "`${CC} contrib/sdb/test//test.c -liodbc -o contrib/sdb/test/test.ok 2>&1`"; then
- DLZ_ODBC_LIB="-liodbc"
- else
- DLZ_ODBC_LIB=""
- use_dlz_odbc="no"
- AC_MSG_RESULT("no ODBC libraries found")
- fi
- rm -f contrib/sdb/test/test.ok
-
if test "$use_dlz_odbc" = "yes"
then

View File

@@ -0,0 +1,47 @@
diff -urN bind9-9.3.2-P1.backup/bin/named/Makefile.in bind9-9.3.2-P1/bin/named/Makefile.in
--- bind9-9.3.2-P1.backup/bin/named/Makefile.in 2004-09-06 23:47:25.000000000 +0200
+++ bind9-9.3.2-P1/bin/named/Makefile.in 2006-10-06 13:09:13.000000000 +0200
@@ -26,10 +26,10 @@
#
# Add database drivers here.
#
-DBDRIVER_OBJS =
+DBDRIVER_OBJS = ldapdb.@O@
DBDRIVER_SRCS =
-DBDRIVER_INCLUDES =
-DBDRIVER_LIBS =
+DBDRIVER_INCLUDES = -I/usr/include
+DBDRIVER_LIBS = -L/usr/lib -lldap -llber -lresolv
CINCLUDES = -I${srcdir}/include -I${srcdir}/unix/include \
${LWRES_INCLUDES} ${DNS_INCLUDES} ${BIND9_INCLUDES} \
diff -urN bind9-9.3.2-P1.backup/bin/named/main.c bind9-9.3.2-P1/bin/named/main.c
--- bind9-9.3.2-P1.backup/bin/named/main.c 2005-04-29 03:04:47.000000000 +0200
+++ bind9-9.3.2-P1/bin/named/main.c 2006-10-06 13:09:13.000000000 +0200
@@ -69,7 +69,7 @@
/*
* Include header files for database drivers here.
*/
-/* #include "xxdb.h" */
+#include "ldapdb.h"
static isc_boolean_t want_stats = ISC_FALSE;
static char program_name[ISC_DIR_NAMEMAX] = "named";
@@ -669,7 +669,7 @@
/*
* Add calls to register sdb drivers here.
*/
- /* xxdb_init(); */
+ ldapdb_init();
ns_server_create(ns_g_mctx, &ns_g_server);
}
@@ -685,7 +685,7 @@
/*
* Add calls to unregister sdb drivers here.
*/
- /* xxdb_clear(); */
+ ldapdb_clear();
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,
ISC_LOG_NOTICE, "exiting");

View File

@@ -0,0 +1,20 @@
--- configure.in 2006-07-09 22:00:54.000000000 +0000
+++ configure.in 2006-07-09 22:01:05.000000000 +0000
@@ -686,17 +686,7 @@
fi
done
- if test -z "`${CC} contrib/sdb/test//test.c -lodbc -o contrib/sdb/test/test.ok 2>&1`"; then
DLZ_ODBC_LIB="-lodbc"
- elif test -z "`${CC} contrib/sdb/test//test.c -liodbc -o contrib/sdb/test/test.ok 2>&1`"; then
- DLZ_ODBC_LIB="-liodbc"
- else
- DLZ_ODBC_LIB=""
- use_dlz_odbc="no"
- AC_MSG_RESULT("no ODBC libraries found")
- fi
- rm -f contrib/sdb/test/test.ok
-
if test "$use_dlz_odbc" = "yes"
then

View File

@@ -0,0 +1,11 @@
--- contrib/dlz/drivers/dlz_bdbhpt_driver.c 2007-03-02 12:02:12.000000000 +0300
+++ contrib/dlz/drivers/dlz_bdbhpt_driver.c 2007-03-02 12:02:18.000000000 +0300
@@ -442,7 +442,7 @@
xfr_cursor->c_close(xfr_cursor);
if (dns_cursor != NULL)
- dns_cursor->c_close(xfr_cursor);
+ dns_cursor->c_close(dns_cursor);
return result;
}

View File

@@ -0,0 +1,11 @@
--- bin/named/dlz_bdbhpt_driver.c Thu May 4 13:13:20 2006
+++ bin/named/dlz_bdbhpt_driver.c Thu May 4 13:27:05 2006
@@ -462,7 +462,7 @@
xfr_cursor->c_close(xfr_cursor);
if(dns_cursor != NULL)
- dns_cursor->c_close(xfr_cursor);
+ dns_cursor->c_close(dns_cursor);
return result;
}

View File

@@ -0,0 +1,12 @@
--- bin/dlzbdb/Makefile.in 2006-03-25 22:11:15.840755988 +0000
+++ bin/dlzbdb/Makefile.in 2006-03-25 22:33:43.873082259 +0000
@@ -26,6 +26,9 @@
DLZINCLUDES = @DLZ_BDB_INC@
CINCLUDES = -I${srcdir}/include -I${srcdir}/unix/include \
+ -I${top_srcdir}/lib/isc/include \
+ -I${top_srcdir}/lib/isc/unix/include \
+ -I${top_srcdir}/lib/isc/@ISC_THREAD_DIR@/include \
${ISC_INCLUDES} ${DLZINCLUDES}
CDEFINES = @USE_DLZ_BDB@

View File

@@ -0,0 +1,59 @@
--- bind-9.5.0a6.orig/contrib/dlz/drivers/dlz_mysql_driver.c 2007-02-06 06:44:26.000000000 +0100
+++ bind-9.5.0a6/contrib/dlz/drivers/dlz_mysql_driver.c 2007-09-04 23:57:57.000000000 +0200
@@ -92,6 +92,25 @@
*/
/*%
+ * Factorize the mysql_ping for adding a log error message
+ */
+static isc_result_t
+mysqldrv_ping(dbinstance_t *dbi) {
+ int pres = 0;
+
+ pres = mysql_ping(dbi->dbconn);
+ if ( pres != 0 ) {
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
+ DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1),
+ "\nMySQL Ping Error : %s (%i)\n",
+ mysql_error(dbi->dbconn),
+ mysql_errno(dbi->dbconn));
+ return (ISC_R_FAILURE);
+ }
+ return (ISC_R_SUCCESS);
+}
+
+/*%
* Allocates memory for a new string, and then constructs the new
* string by "escaping" the input string. The new string is
* safe to be used in queries. This is necessary because we cannot
@@ -225,6 +244,8 @@
}
+ mysqldrv_ping(dbi);
+
/*
* was a zone string passed? If so, make it safe for use in
* queries.
@@ -324,7 +345,7 @@
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; mysqldrv_ping(dbi) != 0 && j < 4; j++)
;
}
@@ -923,6 +944,12 @@
pass = getParameterValue(argv[1], "pass=");
socket = getParameterValue(argv[1], "socket=");
+ if(mysql_options((MYSQL *) dbi->dbconn, MYSQL_OPT_RECONNECT, "1")) {
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
+ DNS_LOGMODULE_DLZ, ISC_LOG_ERROR,
+ "Could not set database reconnect option");
+ }
+
for (j=0; dbc == NULL && j < 4; j++)
dbc = mysql_real_connect((MYSQL *) dbi->dbconn, host,
user, pass, dbname, port, socket,

View File

@@ -0,0 +1,9 @@
$TTL 1W
@ IN SOA ns.localhost. root.localhost. (
2002081601 ; Serial
28800 ; Refresh
14400 ; Retry
604800 ; Expire - 1 week
86400 ) ; Minimum
IN NS ns
localhost. IN A 127.0.0.1

View File

@@ -0,0 +1,9 @@
$TTL 1W
@ IN SOA ns.localhost. root.localhost. (
2002081601 ; Serial
28800 ; Refresh
14400 ; Retry
604800 ; Expire - 1 week
86400 ) ; Minimum
IN NS 127.0.0.1
localhost. IN A 127.0.0.1

View File

@@ -0,0 +1,11 @@
$TTL 1W
@ IN SOA ns.localhost. root.localhost. (
2002081601 ; Serial
28800 ; Refresh
14400 ; Retry
604800 ; Expire - 1 week
86400 ) ; Minimum
@ IN NS ns
ns IN A 127.0.0.1
ns IN AAAA ::1

View File

@@ -0,0 +1,85 @@
; This file holds the information on root name servers needed to
; initialize cache of Internet domain name servers
; (e.g. reference this file in the "cache . <file>"
; configuration file of BIND domain name servers).
;
; This file is made available by InterNIC
; under anonymous FTP as
; file /domain/named.root
; on server FTP.INTERNIC.NET
; -OR- RS.INTERNIC.NET
;
; last update: Feb 04, 2008
; related version of root zone: 2008020400
;
; formerly NS.INTERNIC.NET
;
. 3600000 IN NS A.ROOT-SERVERS.NET.
A.ROOT-SERVERS.NET. 3600000 A 198.41.0.4
A.ROOT-SERVERS.NET. 3600000 AAAA 2001:503:BA3E::2:30
;
; formerly NS1.ISI.EDU
;
. 3600000 NS B.ROOT-SERVERS.NET.
B.ROOT-SERVERS.NET. 3600000 A 192.228.79.201
;
; formerly C.PSI.NET
;
. 3600000 NS C.ROOT-SERVERS.NET.
C.ROOT-SERVERS.NET. 3600000 A 192.33.4.12
;
; formerly TERP.UMD.EDU
;
. 3600000 NS D.ROOT-SERVERS.NET.
D.ROOT-SERVERS.NET. 3600000 A 128.8.10.90
;
; formerly NS.NASA.GOV
;
. 3600000 NS E.ROOT-SERVERS.NET.
E.ROOT-SERVERS.NET. 3600000 A 192.203.230.10
;
; formerly NS.ISC.ORG
;
. 3600000 NS F.ROOT-SERVERS.NET.
F.ROOT-SERVERS.NET. 3600000 A 192.5.5.241
F.ROOT-SERVERS.NET. 3600000 AAAA 2001:500:2f::f
;
; formerly NS.NIC.DDN.MIL
;
. 3600000 NS G.ROOT-SERVERS.NET.
G.ROOT-SERVERS.NET. 3600000 A 192.112.36.4
;
; formerly AOS.ARL.ARMY.MIL
;
. 3600000 NS H.ROOT-SERVERS.NET.
H.ROOT-SERVERS.NET. 3600000 A 128.63.2.53
H.ROOT-SERVERS.NET. 3600000 AAAA 2001:500:1::803f:235
;
; formerly NIC.NORDU.NET
;
. 3600000 NS I.ROOT-SERVERS.NET.
I.ROOT-SERVERS.NET. 3600000 A 192.36.148.17
;
; operated by VeriSign, Inc.
;
. 3600000 NS J.ROOT-SERVERS.NET.
J.ROOT-SERVERS.NET. 3600000 A 192.58.128.30
J.ROOT-SERVERS.NET. 3600000 AAAA 2001:503:C27::2:30
;
; operated by RIPE NCC
;
. 3600000 NS K.ROOT-SERVERS.NET.
K.ROOT-SERVERS.NET. 3600000 A 193.0.14.129
K.ROOT-SERVERS.NET. 3600000 AAAA 2001:7fd::1
;
; operated by ICANN
;
. 3600000 NS L.ROOT-SERVERS.NET.
L.ROOT-SERVERS.NET. 3600000 A 199.7.83.42
;
; operated by WIDE
;
. 3600000 NS M.ROOT-SERVERS.NET.
M.ROOT-SERVERS.NET. 3600000 A 202.12.27.33
M.ROOT-SERVERS.NET. 3600000 AAAA 2001:dc3::35
; End of File

View File

@@ -0,0 +1,42 @@
options {
directory "/var/bind";
// uncomment the following lines to turn on DNS forwarding,
// and change the forwarding ip address(es) :
//forward first;
//forwarders {
// 123.123.123.123;
// 123.123.123.123;
//};
listen-on-v6 { none; };
listen-on { 127.0.0.1; };
// to allow only specific hosts to use the DNS server:
//allow-query {
// 127.0.0.1;
//};
// if you have problems and are behind a firewall:
//query-source address * port 53;
pid-file "/var/run/named/named.pid";
};
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "pri/localhost.zone";
allow-update { none; };
notify no;
};
zone "127.in-addr.arpa" IN {
type master;
file "pri/127.zone";
allow-update { none; };
notify no;
};

View File

@@ -0,0 +1,53 @@
options {
directory "/var/bind";
// uncomment the following lines to turn on DNS forwarding,
// and change the forwarding ip address(es) :
//forward first;
//forwarders {
// 123.123.123.123;
// 123.123.123.123;
//};
listen-on-v6 { none; };
listen-on { 127.0.0.1; };
// to allow only specific hosts to use the DNS server:
//allow-query {
// 127.0.0.1;
//};
// if you have problems and are behind a firewall:
//query-source address * port 53;
pid-file "/var/run/named/named.pid";
};
// Briefly, a zone which has been declared delegation-only will be effectively
// limited to containing NS RRs for subdomains, but no actual data beyond its
// own apex (for example, its SOA RR and apex NS RRset). This can be used to
// filter out "wildcard" or "synthesized" data from NAT boxes or from
// authoritative name servers whose undelegated (in-zone) data is of no
// interest.
// See http://www.isc.org/products/BIND/delegation-only.html for more info
//zone "COM" { type delegation-only; };
//zone "NET" { type delegation-only; };
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "pri/localhost.zone";
allow-update { none; };
notify no;
};
zone "127.in-addr.arpa" IN {
type master;
file "pri/127.zone";
allow-update { none; };
notify no;
};

View File

@@ -0,0 +1,13 @@
# Set various named options here.
#
OPTIONS=""
# Set this to the number of processors you have.
#
CPU="1"
# If you wish to run bind in a chroot, run:
# emerge --config =<bind-version>
# and un-comment the following line.
# You can specify a different chroot directory but MAKE SURE it's empty.
# CHROOT="/chroot/dns"

View File

@@ -0,0 +1,16 @@
# Set various named options here.
#
OPTIONS=""
# Set this to the number of processors you have.
#
CPU="1"
# If you wish to run bind in a chroot, run:
# emerge --config =<bind-version>
# and un-comment the following line.
# You can specify a different chroot directory but MAKE SURE it's empty.
# CHROOT="/chroot/dns"
# Default pid file location
PIDFILE="${CHROOT}/var/run/named/named.pid"

View File

@@ -0,0 +1,20 @@
# Set various named options here.
#
OPTIONS=""
# Set this to the number of processors you have.
#
CPU="1"
# If you wish to run bind in a chroot, run:
# emerge --config =<bind-version>
# and un-comment the following line.
# You can specify a different chroot directory but MAKE SURE it's empty.
# CHROOT="/chroot/dns"
# Default pid file location
PIDFILE="${CHROOT}/var/run/named/named.pid"
# Scheduling priority: 19 is the lowest and -20 is the highest.
#
NAMED_NICELEVEL="0"

72
net-dns/bind/files/named.init Executable file
View File

@@ -0,0 +1,72 @@
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.init,v 1.1 2005/06/23 17:37:44 voxus Exp $
opts="start stop reload restart"
depend() {
need net
use logger
provide dns
}
checkconfig() {
if [ ! -f ${CHROOT}/etc/bind/named.conf ] ; then
eerror "No ${CHROOT}/etc/bind/named.conf file exists!"
fi
# In case someone doesn't have $CPU set from /etc/conf.d/named
if [ ! ${CPU} ] ; then
CPU="1"
fi
# As with the named.conf test, above, there's no need
# for chroot and non-chroot cases here
PIDFILE=$(grep "pid-file" ${CHROOT}/etc/bind/named.conf | \
egrep -v ".*[#,//].*pid-file" | \
head -n 1 | \
sed -ne 's:.*pid-file \"\(.*\)\";:\1:p')
[ -n "$PIDFILE" ] || PIDFILE=/var/run/named.pid
PIDFILE="${CHROOT}$PIDFILE"
KEY="${CHROOT}/etc/bind/rndc.key"
}
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--exec /usr/sbin/named \
-- -u named -n ${CPU} ${OPTIONS} ${CHROOT:+-t $CHROOT}
eend $?
}
stop() {
ebegin "Stopping ${CHROOT:+chrooted }named"
checkconfig || return 2
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec /usr/sbin/named -- stop
eend $?
}
reload() {
checkconfig || return 3
if [ ! -f $PIDFILE ] ; then
/etc/init.d/named start &>/dev/null
exit
fi
if [ -f $KEY ] ; then
ebegin "Reloading named.conf and zone files"
rndc -k $KEY reload &>/dev/null
eend $?
else /etc/init.d/named restart &>/dev/null
fi
}
restart() {
svc_stop
svc_start
}

View File

@@ -0,0 +1,66 @@
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.init-r2,v 1.1 2005/09/30 22:33:25 voxus Exp $
opts="start stop reload restart"
depend() {
need net
use logger
provide dns
}
checkconfig() {
if [ ! -f ${CHROOT}/etc/bind/named.conf ] ; then
eerror "No ${CHROOT}/etc/bind/named.conf file exists!"
fi
# In case someone doesn't have $CPU set from /etc/conf.d/named
if [ ! ${CPU} ] ; then
CPU="1"
fi
# as suggested in bug #107724
PIDFILE=$(\
egrep -v \
"^([[:cntrl:] ]+(#|//|/\*)|(#|//|/\*))" \
${CHROOT}/etc/bind/named.conf \
| egrep -o -m1 "pid\-file +\".+\" *;" \
| cut -d\" -f2
)
KEY="${CHROOT}/etc/bind/rndc.key"
}
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--exec /usr/sbin/named \
-- -u named -n ${CPU} ${OPTIONS} ${CHROOT:+-t $CHROOT}
eend $?
}
stop() {
ebegin "Stopping ${CHROOT:+chrooted }named"
checkconfig || return 2
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec /usr/sbin/named -- stop
eend $?
}
reload() {
checkconfig || return 3
if [ ! -f $PIDFILE ] ; then
/etc/init.d/named start &>/dev/null
exit
fi
if [ -f $KEY ] ; then
ebegin "Reloading named.conf and zone files"
rndc -k $KEY reload &>/dev/null
eend $?
else /etc/init.d/named restart &>/dev/null
fi
}

View File

@@ -0,0 +1,66 @@
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.init-r3,v 1.1 2005/11/09 09:25:53 voxus Exp $
opts="start stop reload restart"
depend() {
need net
use logger
provide dns
}
checkconfig() {
if [ ! -f ${CHROOT}/etc/bind/named.conf ] ; then
eerror "No ${CHROOT}/etc/bind/named.conf file exists!"
fi
# In case someone doesn't have $CPU set from /etc/conf.d/named
if [ ! ${CPU} ] ; then
CPU="1"
fi
# as suggested in bug #107724
[ -n "${PIDFILE}" ] || PIDFILE=${CHROOT}$(\
egrep -v \
"^([[:cntrl:] ]+(#|//|/\*)|(#|//|/\*))" \
${CHROOT}/etc/bind/named.conf \
| egrep -o -m1 "pid\-file +\".+\" *;" \
| cut -d\" -f2
)
KEY="${CHROOT}/etc/bind/rndc.key"
}
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--exec /usr/sbin/named \
-- -u named -n ${CPU} ${OPTIONS} ${CHROOT:+-t $CHROOT}
eend $?
}
stop() {
ebegin "Stopping ${CHROOT:+chrooted }named"
checkconfig || return 2
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec /usr/sbin/named -- stop
eend $?
}
reload() {
checkconfig || return 3
if [ ! -f $PIDFILE ] ; then
/etc/init.d/named start &>/dev/null
exit
fi
if [ -f $KEY ] ; then
ebegin "Reloading named.conf and zone files"
rndc -k $KEY reload &>/dev/null
eend $?
else /etc/init.d/named restart &>/dev/null
fi
}

View File

@@ -0,0 +1,70 @@
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.init-r4,v 1.2 2007/05/12 23:19:40 uberlord Exp $
opts="start stop reload restart"
depend() {
need net
use logger
provide dns
}
checkconfig() {
if [ ! -f ${CHROOT}/etc/bind/named.conf ] ; then
eerror "No ${CHROOT}/etc/bind/named.conf file exists!"
fi
# In case someone doesn't have $CPU set from /etc/conf.d/named
if [ ! ${CPU} ] ; then
CPU="1"
fi
# as suggested in bug #107724
[ -n "${PIDFILE}" ] || PIDFILE=${CHROOT}$(\
egrep -v \
"^([[:cntrl:] ]+(#|//|/\*)|(#|//|/\*))" \
${CHROOT}/etc/bind/named.conf \
| egrep -o -m1 "pid\-file +\".+\" *;" \
| cut -d\" -f2
)
KEY="${CHROOT}/etc/bind/rndc.key"
}
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--exec /usr/sbin/named \
-- -u named -n ${CPU} ${OPTIONS} ${CHROOT:+-t} ${CHROOT}
eend $?
}
stop() {
ebegin "Stopping ${CHROOT:+chrooted }named"
checkconfig || return 2
if [ -f $KEY ] ; then
rndc -k $KEY stop &>/dev/null
else
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec /usr/sbin/named -- stop
fi
eend $?
}
reload() {
checkconfig || return 3
if [ ! -f $PIDFILE ] ; then
/etc/init.d/named start &>/dev/null
exit
fi
if [ -f $KEY ] ; then
ebegin "Reloading named.conf and zone files"
rndc -k $KEY reload &>/dev/null
eend $?
else /etc/init.d/named restart &>/dev/null
fi
}

View File

@@ -0,0 +1,71 @@
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.init-r5,v 1.1 2007/06/02 22:34:48 voxus Exp $
opts="start stop reload restart"
depend() {
need net
use logger
provide dns
}
checkconfig() {
if [ ! -f ${CHROOT}/etc/bind/named.conf ] ; then
eerror "No ${CHROOT}/etc/bind/named.conf file exists!"
fi
# In case someone doesn't have $CPU set from /etc/conf.d/named
if [ ! ${CPU} ] ; then
CPU="1"
fi
# as suggested in bug #107724
[ -n "${PIDFILE}" ] || PIDFILE=${CHROOT}$(\
egrep -v \
"^([[:cntrl:] ]+(#|//|/\*)|(#|//|/\*))" \
${CHROOT}/etc/bind/named.conf \
| egrep -o -m1 "pid\-file +\".+\" *;" \
| cut -d\" -f2
)
KEY="${CHROOT}/etc/bind/rndc.key"
}
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--nicelevel ${NAMED_NICELEVEL:-0} \
--exec /usr/sbin/named \
-- -u named -n ${CPU} ${OPTIONS} ${CHROOT:+-t} ${CHROOT}
eend $?
}
stop() {
ebegin "Stopping ${CHROOT:+chrooted }named"
checkconfig || return 2
if [ -f $KEY ] ; then
rndc -k $KEY stop &>/dev/null
else
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec /usr/sbin/named -- stop
fi
eend $?
}
reload() {
checkconfig || return 3
if [ ! -f $PIDFILE ] ; then
/etc/init.d/named start &>/dev/null
exit
fi
if [ -f $KEY ] ; then
ebegin "Reloading named.conf and zone files"
rndc -k $KEY reload &>/dev/null
eend $?
else /etc/init.d/named restart &>/dev/null
fi
}

72
net-dns/bind/files/named.rc Executable file
View File

@@ -0,0 +1,72 @@
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.rc,v 1.1 2005/08/03 16:54:38 voxus Exp $
opts="start stop reload restart"
depend() {
need net
use logger
provide dns
}
checkconfig() {
if [ ! -f ${CHROOT}/etc/bind/named.conf ] ; then
eerror "No ${CHROOT}/etc/bind/named.conf file exists!"
fi
# In case someone doesn't have $CPU set from /etc/conf.d/named
if [ ! ${CPU} ] ; then
CPU="1"
fi
# As with the named.conf test, above, there's no need
# for chroot and non-chroot cases here
PIDFILE=$(grep "pid-file" ${CHROOT}/etc/bind/named.conf | \
egrep -v ".*[#,//].*pid-file" | \
head -n 1 | \
sed -ne 's:.*pid-file\(.*\)\"\(.*\)\";:\2:p')
[ -n "$PIDFILE" ] || PIDFILE=/var/run/named.pid
PIDFILE="${CHROOT}$PIDFILE"
KEY="${CHROOT}/etc/bind/rndc.key"
}
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--exec /usr/sbin/named \
-- -u named -n ${CPU} ${OPTIONS} ${CHROOT:+-t $CHROOT}
eend $?
}
stop() {
ebegin "Stopping ${CHROOT:+chrooted }named"
checkconfig || return 2
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec /usr/sbin/named -- stop
eend $?
}
reload() {
checkconfig || return 3
if [ ! -f $PIDFILE ] ; then
/etc/init.d/named start &>/dev/null
exit
fi
if [ -f $KEY ] ; then
ebegin "Reloading named.conf and zone files"
rndc -k $KEY reload &>/dev/null
eend $?
else /etc/init.d/named restart &>/dev/null
fi
}
restart() {
svc_stop
svc_start
}

66
net-dns/bind/files/named.rc6 Executable file
View File

@@ -0,0 +1,66 @@
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.rc6,v 1.15 2004/07/14 23:18:19 agriffis Exp $
opts="start stop reload restart"
depend() {
need net
use logger
provide dns
}
checkconfig() {
if [ ! -f ${CHROOT}/etc/bind/named.conf ] ; then
eerror "No ${CHROOT}/etc/bind/named.conf file exists!"
fi
# In case someone doesn't have $CPU set from /etc/conf.d/named
if [ ! $CPU ] ; then
CPU=1
fi
if [ $CHROOT -a -d $CHROOT ] ; then
PIDFILE="${CHROOT}/var/run/named/named.pid"
KEY="${CHROOT}/etc/bind/rndc.key"
else
PIDFILE="/var/run/named/named.pid"
KEY="/etc/bind/rndc.key"
fi
}
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
start-stop-daemon --start --quiet --exec /usr/sbin/named -- -u named -n $CPU $OPTIONS ${CHROOT:+-t $CHROOT}
eend $?
}
stop() {
ebegin "Stopping ${CHROOT:+chrooted }named"
checkconfig || return 2
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
--exec /usr/sbin/named -- stop
eend $?
}
reload() {
checkconfig || return 3
if [ ! -f $PIDFILE ] ; then
/etc/init.d/named start &>/dev/null
exit
fi
if [ -f $KEY ] ; then
ebegin "Reloading named.conf and zone files"
rndc -k $KEY reload &>/dev/null
eend $?
else /etc/init.d/named restart &>/dev/null
fi
}
restart() {
svc_stop
svc_start
}

View File

@@ -0,0 +1,13 @@
--- files/named.rc6 2004-07-15 03:36:02.000000000 +0400
+++ named 2005-03-25 20:19:16.000000000 +0300
@@ -33,7 +33,9 @@
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
- start-stop-daemon --start --quiet --exec /usr/sbin/named -- -u named -n $CPU $OPTIONS ${CHROOT:+-t $CHROOT}
+ start-stop-daemon --start --quiet --exec /usr/sbin/named \
+ --pid ${CHROOT}/var/run/named/named.pid \
+ -- -u named -n $CPU $OPTIONS ${CHROOT:+-t $CHROOT}
eend $?
}

View File

@@ -0,0 +1,42 @@
--- named.orig 2005-04-17 16:14:08.000000000 +0400
+++ named.rc6 2005-04-17 16:18:00.000000000 +0400
@@ -17,23 +17,29 @@
fi
# In case someone doesn't have $CPU set from /etc/conf.d/named
- if [ ! $CPU ] ; then
- CPU=1
+ if [ ! ${CPU} ] ; then
+ CPU="1"
fi
- if [ $CHROOT -a -d $CHROOT ] ; then
- PIDFILE="${CHROOT}/var/run/named/named.pid"
- KEY="${CHROOT}/etc/bind/rndc.key"
- else
- PIDFILE="/var/run/named/named.pid"
- KEY="/etc/bind/rndc.key"
- fi
+ # As with the named.conf test, above, there's no need
+ # for chroot and non-chroot cases here
+ PIDFILE=$(grep "pid-file" ${CHROOT}/etc/bind/named.conf | \
+ egrep -v ".*[#,//].*pid-file" | \
+ head -n 1 | \
+ sed -ne 's:.*pid-file \"\(.*\)\";:\1:p')
+ [ -n "$PIDFILE" ] || PIDFILE=/var/run/named.pid
+
+ PIDFILE="${CHROOT}$PIDFILE"
+
+ KEY="${CHROOT}/etc/bind/rndc.key"
}
start() {
ebegin "Starting ${CHROOT:+chrooted }named"
checkconfig || return 1
- start-stop-daemon --start --quiet --exec /usr/sbin/named -- -u named -n $CPU $OPTIONS ${CHROOT:+-t $CHROOT}
+ start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
+ --exec /usr/sbin/named \
+ -- -u named -n ${CPU} ${OPTIONS} ${CHROOT:+-t $CHROOT}
eend $?
}