2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 22:45:18 +00:00

Merge branch 'trac4216'

This commit is contained in:
Thomas Markwalder
2015-12-15 08:32:30 -05:00
3 changed files with 29 additions and 20 deletions

View File

@@ -532,6 +532,16 @@ and hardware address.
A debug message issued when the server is about to obtain schema version A debug message issued when the server is about to obtain schema version
information from the MySQL database. information from the MySQL database.
% DHCPSRV_MYSQL_HOST_DB opening MySQL hosts database: %1
This informational message is logged when a DHCP server (either V4 or
V6) is about to open a MySQL hosts database. The parameters of the
connection including database name and username needed to access it
(but not the password if any) are logged.
% DHCPSRV_MYSQL_HOST_DB_GET_VERSION obtaining schema version information for the MySQL hosts database
A debug message issued when the server is about to obtain schema version
information from the MySQL hosts database.
% DHCPSRV_MYSQL_ROLLBACK rolling back MySQL database % DHCPSRV_MYSQL_ROLLBACK rolling back MySQL database
The code has issued a rollback call. All outstanding transaction will The code has issued a rollback call. All outstanding transaction will
be rolled back and not committed to the database. be rolled back and not committed to the database.
@@ -658,6 +668,12 @@ and hardware address.
A debug message issued when the server is about to obtain schema version A debug message issued when the server is about to obtain schema version
information from the PostgreSQL database. information from the PostgreSQL database.
% DHCPSRV_PGSQL_HOST_DB opening PostgreSQL hosts database: %1
This informational message is logged when a DHCP server (either V4 or
V6) is about to open a PostgreSQL hosts database. The parameters of the
connection including database name and username needed to access it
(but not the password if any) are logged.
% DHCPSRV_PGSQL_ROLLBACK rolling back PostgreSQL database % DHCPSRV_PGSQL_ROLLBACK rolling back PostgreSQL database
The code has issued a rollback call. All outstanding transaction will The code has issued a rollback call. All outstanding transaction will
be rolled back and not committed to the database. be rolled back and not committed to the database.

View File

@@ -47,45 +47,38 @@ HostDataSourceFactory::getHostDataSourcePtr() {
void void
HostDataSourceFactory::create(const std::string& dbaccess) { HostDataSourceFactory::create(const std::string& dbaccess) {
const std::string type = "type";
// Parse the access string and create a redacted string for logging. // Parse the access string and create a redacted string for logging.
DatabaseConnection::ParameterMap parameters = DatabaseConnection::ParameterMap parameters =
DatabaseConnection::parse(dbaccess); DatabaseConnection::parse(dbaccess);
std::string redacted =
DatabaseConnection::redactedAccessString(parameters);
// Is "type" present? // Get the databaase type and open the corresponding database
if (parameters.find(type) == parameters.end()) { DatabaseConnection::ParameterMap::iterator it = parameters.find("type");
LOG_ERROR(dhcpsrv_logger, DHCPSRV_NOTYPE_DB).arg(dbaccess); if (it == parameters.end()) {
isc_throw(InvalidParameter, "Database configuration parameters do not " isc_throw(InvalidParameter, "Host database configuration does not "
"contain the 'type' keyword"); "contain the 'type' keyword");
} }
std::string db_type = it->second;
// Yes, check what it is.
#ifdef HAVE_MYSQL #ifdef HAVE_MYSQL
if (parameters[type] == string("mysql")) { if (db_type == "mysql") {
LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_DB).arg(redacted); LOG_INFO(dhcpsrv_logger, DHCPSRV_MYSQL_HOST_DB)
.arg(DatabaseConnection::redactedAccessString(parameters));
getHostDataSourcePtr().reset(new MySqlHostDataSource(parameters)); getHostDataSourcePtr().reset(new MySqlHostDataSource(parameters));
return; return;
} }
#endif #endif
#ifdef HAVE_PGSQL #ifdef HAVE_PGSQL
if (parameters[type] == string("postgresql")) { if (db_type == "postgresql") {
LOG_INFO(dhcpsrv_logger, DHCPSRV_PGSQL_DB).arg(redacted); isc_throw(NotImplemented, "Sorry, PostgreSQL backend for host reservations "
isc_throw(NotImplemented, "Sorry, Postgres backend for host reservations "
"is not implemented yet."); "is not implemented yet.");
// Set pgsql data source here, when it will be implemented.
return;
} }
#endif #endif
// Get here on no match. // Get here on no match.
LOG_ERROR(dhcpsrv_logger, DHCPSRV_UNKNOWN_DB).arg(parameters[type]); isc_throw(InvalidType, "Hosts database access parameter 'type': " <<
isc_throw(InvalidType, "Database access parameter 'type' does " db_type << " is invalid");
"not specify a supported database backend");
} }
void void

View File

@@ -976,7 +976,7 @@ std::pair<uint32_t, uint32_t> MySqlHostDataSource::getVersion() const {
const StatementIndex stindex = GET_VERSION; const StatementIndex stindex = GET_VERSION;
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_MYSQL_GET_VERSION); DHCPSRV_MYSQL_HOST_DB_GET_VERSION);
uint32_t major; // Major version number uint32_t major; // Major version number
uint32_t minor; // Minor version number uint32_t minor; // Minor version number