mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 05:55:28 +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:
@@ -306,6 +306,7 @@ AC_OUTPUT([src/bin/cfgmgr/b10-cfgmgr.py
|
||||
src/bin/msgq/msgq.py
|
||||
src/bin/msgq/msgq_test
|
||||
src/bin/msgq/run_msgq.sh
|
||||
src/bin/auth/auth.pre
|
||||
src/bin/auth/spec_config.h
|
||||
src/lib/config/tests/data_def_unittests_config.h
|
||||
src/lib/python/isc/config/tests/config_test
|
||||
|
@@ -9,10 +9,10 @@ endif
|
||||
|
||||
pkglibexecdir = $(libexecdir)/@PACKAGE@
|
||||
|
||||
CLEANFILES = *.gcno *.gcda
|
||||
CLEANFILES = *.gcno *.gcda auth.pre auth.spec
|
||||
|
||||
man_MANS = b10-auth.8
|
||||
EXTRA_DIST = $(man_MANS) b10-auth.xml
|
||||
EXTRA_DIST = $(man_MANS) b10-auth.xml auth.spec
|
||||
|
||||
if ENABLE_MAN
|
||||
|
||||
@@ -21,6 +21,9 @@ b10-auth.8: b10-auth.xml
|
||||
|
||||
endif
|
||||
|
||||
auth.spec: auth.pre
|
||||
$(SED) -e "s|@@LOCALSTATEDIR@@|$(localstatedir)|" auth.pre >$@
|
||||
|
||||
pkglibexec_PROGRAMS = b10-auth
|
||||
b10_auth_SOURCES = auth_srv.cc auth_srv.h
|
||||
b10_auth_SOURCES += common.h
|
||||
|
@@ -4,7 +4,8 @@
|
||||
"config_data": [
|
||||
{ "item_name": "database_file",
|
||||
"item_type": "string",
|
||||
"item_optional": True
|
||||
"item_optional": True,
|
||||
"item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3"
|
||||
}
|
||||
],
|
||||
"commands": [
|
@@ -65,11 +65,12 @@ public:
|
||||
isc::data::ElementPtr setDbFile(const isc::data::ElementPtr config);
|
||||
|
||||
std::string db_file_;
|
||||
isc::auth::MetaDataSrc data_sources_;
|
||||
ModuleCCSession* cs_;
|
||||
MetaDataSrc data_sources_;
|
||||
/// We keep a pointer to the currently running sqlite datasource
|
||||
/// so that we can specifically remove that one should the database
|
||||
/// file change
|
||||
isc::auth::ConstDataSrcPtr cur_datasrc_;
|
||||
ConstDataSrcPtr cur_datasrc_;
|
||||
|
||||
bool verbose_mode_;
|
||||
|
||||
@@ -77,17 +78,18 @@ public:
|
||||
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,
|
||||
// effectively being an empty (sqlite) data source. once ccsession is up
|
||||
// the datasource will be set by the configuration setting
|
||||
// (or the default one if none is set)
|
||||
|
||||
// add static data source
|
||||
data_sources_.addDataSrc(ConstDataSrcPtr(new StaticDataSrc));
|
||||
}
|
||||
|
||||
AuthSrv::AuthSrv() : impl_(new AuthSrvImpl) {}
|
||||
AuthSrv::AuthSrv() : impl_(new AuthSrvImpl) {
|
||||
}
|
||||
|
||||
AuthSrv::~AuthSrv() {
|
||||
delete impl_;
|
||||
@@ -154,6 +156,16 @@ AuthSrv::getVerbose() const {
|
||||
return (impl_->verbose_mode_);
|
||||
}
|
||||
|
||||
void
|
||||
AuthSrv::setConfigSession(ModuleCCSession* cs) {
|
||||
impl_->cs_ = cs;
|
||||
}
|
||||
|
||||
ModuleCCSession*
|
||||
AuthSrv::configSession() const {
|
||||
return (impl_->cs_);
|
||||
}
|
||||
|
||||
bool
|
||||
AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
|
||||
MessageRenderer& response_renderer,
|
||||
@@ -251,23 +263,34 @@ AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
|
||||
|
||||
ElementPtr
|
||||
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();
|
||||
if (verbose_mode_) {
|
||||
cerr << "[AuthSrv] Data source database file: " << db_file_ << endl;
|
||||
}
|
||||
final = config;
|
||||
} 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
|
||||
// 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
|
||||
// exception guarantee: We first need to perform all operations that can
|
||||
// fail, while acquiring resources in the RAII manner. We then perform
|
||||
// delete and swap operations which should not fail.
|
||||
DataSrcPtr datasrc_ptr(DataSrcPtr(new Sqlite3DataSrc));
|
||||
datasrc_ptr->init(config);
|
||||
ElementPtr answer = isc::config::createAnswer();
|
||||
datasrc_ptr->init(final);
|
||||
data_sources_.addDataSrc(datasrc_ptr);
|
||||
|
||||
// The following code should be exception free.
|
||||
@@ -276,26 +299,17 @@ AuthSrvImpl::setDbFile(const isc::data::ElementPtr config) {
|
||||
}
|
||||
cur_datasrc_ = datasrc_ptr;
|
||||
|
||||
return answer;
|
||||
return (answer);
|
||||
}
|
||||
|
||||
ElementPtr
|
||||
AuthSrv::updateConfig(isc::data::ElementPtr new_config) {
|
||||
try {
|
||||
// the ModuleCCSession has already checked if we have
|
||||
// the correct ElementPtr type as specified in our .spec file
|
||||
ElementPtr answer = isc::config::createAnswer();
|
||||
if (new_config != NULL) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
} catch (const isc::Exception& error) {
|
||||
if (impl_->verbose_mode_) {
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include <string>
|
||||
|
||||
#include <cc/data.h>
|
||||
#include <config/ccsession.h>
|
||||
|
||||
namespace isc {
|
||||
namespace dns {
|
||||
@@ -55,6 +56,8 @@ public:
|
||||
bool getVerbose() const;
|
||||
void serve(std::string zone_name);
|
||||
isc::data::ElementPtr updateConfig(isc::data::ElementPtr config);
|
||||
isc::config::ModuleCCSession* configSession() const;
|
||||
void setConfigSession(isc::config::ModuleCCSession* cs);
|
||||
private:
|
||||
AuthSrvImpl* impl_;
|
||||
};
|
||||
|
@@ -332,14 +332,11 @@ struct ServerSet {
|
||||
|
||||
void
|
||||
run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
|
||||
const string& specfile)
|
||||
AuthSrv* srv)
|
||||
{
|
||||
ServerSet servers;
|
||||
short portnum = atoi(port);
|
||||
|
||||
ModuleCCSession cs(specfile, io_service_, my_config_handler,
|
||||
my_command_handler);
|
||||
|
||||
if (use_ipv4) {
|
||||
servers.udp4_server = new UDPServer(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
|
||||
run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
|
||||
const string& specfile)
|
||||
AuthSrv* srv)
|
||||
{
|
||||
SocketSet socket_set;
|
||||
fd_set fds_base;
|
||||
@@ -579,11 +576,13 @@ run_server(const char* port, const bool use_ipv4, const bool use_ipv6,
|
||||
}
|
||||
++nfds;
|
||||
|
||||
ModuleCCSession cs(specfile, my_config_handler, my_command_handler);
|
||||
|
||||
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);
|
||||
OutputBuffer resonse_buffer(0);
|
||||
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);
|
||||
}
|
||||
if (FD_ISSET(ss, &fds)) {
|
||||
cs.checkCommand();
|
||||
srv->configSession()->checkCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -668,9 +667,6 @@ main(int argc, char* argv[]) {
|
||||
usage();
|
||||
}
|
||||
|
||||
auth_server = new AuthSrv;
|
||||
auth_server->setVerbose(verbose_mode);
|
||||
|
||||
// initialize command channel
|
||||
int ret = 0;
|
||||
try {
|
||||
@@ -682,7 +678,20 @@ main(int argc, char* argv[]) {
|
||||
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) {
|
||||
cerr << ex.what() << endl;
|
||||
ret = 1;
|
||||
|
@@ -54,10 +54,6 @@ struct Sqlite3Parameters {
|
||||
};
|
||||
|
||||
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[] = {
|
||||
"CREATE TABLE schema_version (version INTEGER NOT NULL)",
|
||||
"INSERT INTO schema_version VALUES (1)",
|
||||
@@ -567,7 +563,7 @@ Sqlite3DataSrc::init(const isc::data::ElementPtr config) {
|
||||
if (config && config->contains("database_file")) {
|
||||
open(config->get("database_file")->stringValue());
|
||||
} else {
|
||||
open(DEFAULT_DB_FILE);
|
||||
isc_throw(DataSourceError, "No sqlite3 database file specified");
|
||||
}
|
||||
return (SUCCESS);
|
||||
}
|
||||
|
Reference in New Issue
Block a user