2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-03 15:35:17 +00:00

Make b10-auth use a default database path from auth.spec rather than

/tmp/zone.sqlite3.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1536 e5f2f494-b856-4b98-b285-d166d9295462
This commit is contained in:
Evan Hunt
2010-03-18 20:17:56 +00:00
parent 7a289d3379
commit ceb8ef9564
7 changed files with 74 additions and 47 deletions

View File

@@ -306,6 +306,7 @@ AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py
src/bin/msgq/msgq.py src/bin/msgq/msgq.py
src/bin/msgq/msgq_test src/bin/msgq/msgq_test
src/bin/msgq/run_msgq.sh src/bin/msgq/run_msgq.sh
src/bin/auth/auth.pre
src/bin/auth/spec_config.h src/bin/auth/spec_config.h
src/lib/config/tests/data_def_unittests_config.h src/lib/config/tests/data_def_unittests_config.h
src/lib/python/isc/config/tests/config_test src/lib/python/isc/config/tests/config_test

View File

@@ -9,10 +9,10 @@ endif
pkglibexecdir = $(libexecdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@
CLEANFILES = *.gcno *.gcda CLEANFILES = *.gcno *.gcda auth.pre auth.spec
man_MANS = b10-auth.8 man_MANS = b10-auth.8
EXTRA_DIST = $(man_MANS) b10-auth.xml EXTRA_DIST = $(man_MANS) b10-auth.xml auth.spec
if ENABLE_MAN if ENABLE_MAN
@@ -21,6 +21,9 @@ b10-auth.8: b10-auth.xml
endif endif
auth.spec: auth.pre
$(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" auth.pre >$@
pkglibexec_PROGRAMS = b10-auth pkglibexec_PROGRAMS = b10-auth
b10_auth_SOURCES = auth_srv.cc auth_srv.h b10_auth_SOURCES = auth_srv.cc auth_srv.h
b10_auth_SOURCES += common.h b10_auth_SOURCES += common.h

View File

@@ -4,7 +4,8 @@
"config_data": [ "config_data": [
{ "item_name": "database_file", { "item_name": "database_file",
"item_type": "string", "item_type": "string",
"item_optional": True "item_optional": True,
"item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3"
} }
], ],
"commands": [ "commands": [

View File

@@ -65,11 +65,12 @@ public:
isc::data::ElementPtr setDbFile(const isc::data::ElementPtr config); isc::data::ElementPtr setDbFile(const isc::data::ElementPtr config);
std::string db_file_; std::string db_file_;
isc::auth::MetaDataSrc data_sources_; ModuleCCSession* cs_;
MetaDataSrc data_sources_;
/// We keep a pointer to the currently running sqlite datasource /// We keep a pointer to the currently running sqlite datasource
/// so that we can specifically remove that one should the database /// so that we can specifically remove that one should the database
/// file change /// file change
isc::auth::ConstDataSrcPtr cur_datasrc_; ConstDataSrcPtr cur_datasrc_;
bool verbose_mode_; bool verbose_mode_;
@@ -77,17 +78,18 @@ public:
static const uint16_t DEFAULT_LOCAL_UDPSIZE = 4096; static const uint16_t DEFAULT_LOCAL_UDPSIZE = 4096;
}; };
AuthSrvImpl::AuthSrvImpl() : verbose_mode_(false) { AuthSrvImpl::AuthSrvImpl() : cs_(NULL), verbose_mode_(false)
{
// cur_datasrc_ is automatically initialized by the default constructor, // cur_datasrc_ is automatically initialized by the default constructor,
// effectively being an empty (sqlite) data source. once ccsession is up // effectively being an empty (sqlite) data source. once ccsession is up
// the datasource will be set by the configuration setting // the datasource will be set by the configuration setting
// (or the default one if none is set)
// add static data source // add static data source
data_sources_.addDataSrc(ConstDataSrcPtr(new StaticDataSrc)); data_sources_.addDataSrc(ConstDataSrcPtr(new StaticDataSrc));
} }
AuthSrv::AuthSrv() : impl_(new AuthSrvImpl) {} AuthSrv::AuthSrv() : impl_(new AuthSrvImpl) {
}
AuthSrv::~AuthSrv() { AuthSrv::~AuthSrv() {
delete impl_; delete impl_;
@@ -154,6 +156,16 @@ AuthSrv::getVerbose() const {
return (impl_->verbose_mode_); return (impl_->verbose_mode_);
} }
void
AuthSrv::setConfigSession(ModuleCCSession* cs) {
impl_->cs_ = cs;
}
ModuleCCSession*
AuthSrv::configSession() const {
return (impl_->cs_);
}
bool bool
AuthSrv::processMessage(InputBuffer& request_buffer, Message& message, AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
MessageRenderer& response_renderer, MessageRenderer& response_renderer,
@@ -251,23 +263,34 @@ AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
ElementPtr ElementPtr
AuthSrvImpl::setDbFile(const isc::data::ElementPtr config) { AuthSrvImpl::setDbFile(const isc::data::ElementPtr config) {
if (config) { ElementPtr answer = isc::config::createAnswer();
ElementPtr final;
if (config && config->contains("database_file")) {
db_file_ = config->get("database_file")->stringValue(); db_file_ = config->get("database_file")->stringValue();
if (verbose_mode_) { final = config;
cerr << "[AuthSrv] Data source database file: " << db_file_ << endl; } else if (cs_ != NULL) {
} bool is_default;
string item("database_file");
ElementPtr value = cs_->getValue(is_default, item);
db_file_ = value->stringValue();
final = Element::createFromString("{}");
final->set(item, value);
} else {
return (answer);
}
if (verbose_mode_) {
cerr << "[AuthSrv] Data source database file: " << db_file_ << endl;
} }
// create SQL data source // create SQL data source
// config may be empty here; in that case it will load the default
// database file
// Note: the following step is tricky to be exception-safe and to ensure // Note: the following step is tricky to be exception-safe and to ensure
// exception guarantee: We first need to perform all operations that can // exception guarantee: We first need to perform all operations that can
// fail, while acquiring resources in the RAII manner. We then perform // fail, while acquiring resources in the RAII manner. We then perform
// delete and swap operations which should not fail. // delete and swap operations which should not fail.
DataSrcPtr datasrc_ptr(DataSrcPtr(new Sqlite3DataSrc)); DataSrcPtr datasrc_ptr(DataSrcPtr(new Sqlite3DataSrc));
datasrc_ptr->init(config); datasrc_ptr->init(final);
ElementPtr answer = isc::config::createAnswer();
data_sources_.addDataSrc(datasrc_ptr); data_sources_.addDataSrc(datasrc_ptr);
// The following code should be exception free. // The following code should be exception free.
@@ -276,26 +299,17 @@ AuthSrvImpl::setDbFile(const isc::data::ElementPtr config) {
} }
cur_datasrc_ = datasrc_ptr; cur_datasrc_ = datasrc_ptr;
return answer; return (answer);
} }
ElementPtr ElementPtr
AuthSrv::updateConfig(isc::data::ElementPtr new_config) { AuthSrv::updateConfig(isc::data::ElementPtr new_config) {
try { try {
// the ModuleCCSession has already checked if we have
// the correct ElementPtr type as specified in our .spec file
ElementPtr answer = isc::config::createAnswer(); ElementPtr answer = isc::config::createAnswer();
if (new_config != NULL) { answer = impl_->setDbFile(new_config);
// the ModuleCCSession has already checked if we have
// the correct ElementPtr type as specified in our .spec file
if (new_config->contains("database_file")) {
answer = impl_->setDbFile(new_config);
}
}
// if we have no sqlite3 data source, use the default
if (impl_->cur_datasrc_ == NULL) {
impl_->setDbFile(ElementPtr());
}
return answer; return answer;
} catch (const isc::Exception& error) { } catch (const isc::Exception& error) {
if (impl_->verbose_mode_) { if (impl_->verbose_mode_) {

View File

@@ -20,6 +20,7 @@
#include <string> #include <string>
#include <cc/data.h> #include <cc/data.h>
#include <config/ccsession.h>
namespace isc { namespace isc {
namespace dns { namespace dns {
@@ -55,6 +56,8 @@ public:
bool getVerbose() const; bool getVerbose() const;
void serve(std::string zone_name); void serve(std::string zone_name);
isc::data::ElementPtr updateConfig(isc::data::ElementPtr config); isc::data::ElementPtr updateConfig(isc::data::ElementPtr config);
isc::config::ModuleCCSession* configSession() const;
void setConfigSession(isc::config::ModuleCCSession* cs);
private: private:
AuthSrvImpl* impl_; AuthSrvImpl* impl_;
}; };

View File

@@ -332,14 +332,11 @@ struct ServerSet {
void void
run_server(const char* port, const bool use_ipv4, const bool use_ipv6, run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
const string& specfile) AuthSrv* srv)
{ {
ServerSet servers; ServerSet servers;
short portnum = atoi(port); short portnum = atoi(port);
ModuleCCSession cs(specfile, io_service_, my_config_handler,
my_command_handler);
if (use_ipv4) { if (use_ipv4) {
servers.udp4_server = new UDPServer(io_service_, AF_INET, portnum); servers.udp4_server = new UDPServer(io_service_, AF_INET, portnum);
servers.tcp4_server = new TCPServer(io_service_, AF_INET, portnum); servers.tcp4_server = new TCPServer(io_service_, AF_INET, portnum);
@@ -554,7 +551,7 @@ processMessageTCP(const int fd, Message& dns_message,
void void
run_server(const char* port, const bool use_ipv4, const bool use_ipv6, run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
const string& specfile) AuthSrv* srv)
{ {
SocketSet socket_set; SocketSet socket_set;
fd_set fds_base; fd_set fds_base;
@@ -579,11 +576,13 @@ run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
} }
++nfds; ++nfds;
ModuleCCSession cs(specfile, my_config_handler, my_command_handler);
cout << "Server started." << endl; cout << "Server started." << endl;
int ss = cs.getSocket(); if (srv->configSession() == NULL) {
isc_throw(FatalError, "Config session not initalized");
}
int ss = srv->configSession()->getSocket();
Message dns_message(Message::PARSE); Message dns_message(Message::PARSE);
OutputBuffer resonse_buffer(0); OutputBuffer resonse_buffer(0);
MessageRenderer response_renderer(resonse_buffer); MessageRenderer response_renderer(resonse_buffer);
@@ -615,7 +614,7 @@ run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
processMessageTCP(socket_set.tps6, dns_message, response_renderer); processMessageTCP(socket_set.tps6, dns_message, response_renderer);
} }
if (FD_ISSET(ss, &fds)) { if (FD_ISSET(ss, &fds)) {
cs.checkCommand(); srv->configSession()->checkCommand();
} }
} }
} }
@@ -668,9 +667,6 @@ main(int argc, char* argv[]) {
usage(); usage();
} }
auth_server = new AuthSrv;
auth_server->setVerbose(verbose_mode);
// initialize command channel // initialize command channel
int ret = 0; int ret = 0;
try { try {
@@ -682,7 +678,20 @@ main(int argc, char* argv[]) {
specfile = string(AUTH_SPECFILE_LOCATION); specfile = string(AUTH_SPECFILE_LOCATION);
} }
run_server(port, use_ipv4, use_ipv6, specfile); auth_server = new AuthSrv;
auth_server->setVerbose(verbose_mode);
#ifdef HAVE_BOOSTLIB
ModuleCCSession cs(specfile, io_service_, my_config_handler,
my_command_handler);
#else
ModuleCCSession cs(specfile, my_config_handler, my_command_handler);
#endif
auth_server->setConfigSession(&cs);
auth_server->updateConfig(ElementPtr());
run_server(port, use_ipv4, use_ipv6, auth_server);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
cerr << ex.what() << endl; cerr << ex.what() << endl;
ret = 1; ret = 1;

View File

@@ -54,10 +54,6 @@ struct Sqlite3Parameters {
}; };
namespace { namespace {
// Note: this cannot be std::string to avoid
// "static initialization order fiasco".
const char* DEFAULT_DB_FILE = "/tmp/zone.sqlite3";
const char* const SCHEMA_LIST[] = { const char* const SCHEMA_LIST[] = {
"CREATE TABLE schema_version (version INTEGER NOT NULL)", "CREATE TABLE schema_version (version INTEGER NOT NULL)",
"INSERT INTO schema_version VALUES (1)", "INSERT INTO schema_version VALUES (1)",
@@ -567,7 +563,7 @@ Sqlite3DataSrc::init(const isc::data::ElementPtr config) {
if (config && config->contains("database_file")) { if (config && config->contains("database_file")) {
open(config->get("database_file")->stringValue()); open(config->get("database_file")->stringValue());
} else { } else {
open(DEFAULT_DB_FILE); isc_throw(DataSourceError, "No sqlite3 database file specified");
} }
return (SUCCESS); return (SUCCESS);
} }