Skip to content

Commit

Permalink
postgis plugin: avoid printing the password if connection fails - ame…
Browse files Browse the repository at this point in the history
…nds 19deb86
  • Loading branch information
Dane Springmeyer committed Nov 28, 2012
1 parent c95b8ff commit 9afaf09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
11 changes: 8 additions & 3 deletions plugins/input/postgis/connection.hpp
Expand Up @@ -44,16 +44,21 @@ extern "C" {
class Connection
{
public:
Connection(std::string const& connection_str)
Connection(std::string const& connection_str,boost::optional<std::string> const& password)
: cursorId(0),
closed_(false)
{
conn_ = PQconnectdb(connection_str.c_str());
std::string connect_with_pass = connection_str;
if (password && !password->empty())
{
connect_with_pass += " password=" + *password;
}
conn_ = PQconnectdb(connect_with_pass.c_str());
if (PQstatus(conn_) != CONNECTION_OK)
{
std::string err_msg = "Postgis Plugin: ";
err_msg += status();
err_msg += "\nConnection string:'";
err_msg += "\nConnection string: '";
err_msg += connection_str;
err_msg += "'\n";
throw mapnik::datasource_exception(err_msg);
Expand Down
20 changes: 13 additions & 7 deletions plugins/input/postgis/connection_manager.hpp
Expand Up @@ -66,7 +66,7 @@ class ConnectionCreator

T* operator()() const
{
return new T(connection_string());
return new T(connection_string_safe(),pass_);
}

inline std::string id() const
Expand All @@ -75,14 +75,20 @@ class ConnectionCreator
}

inline std::string connection_string() const
{
std::string connect_str = connection_string_safe();
if (pass_ && !pass_->empty()) connect_str += " password=" + *pass_;
return connect_str;
}

inline std::string connection_string_safe() const
{
std::string connect_str;
if (host_ && (*host_).size()) connect_str += "host=" + *host_;
if (port_ && (*port_).size()) connect_str += " port=" + *port_;
if (dbname_ && (*dbname_).size()) connect_str += " dbname=" + *dbname_;
if (user_ && (*user_).size()) connect_str += " user=" + *user_;
if (pass_ && (*pass_).size()) connect_str += " password=" + *pass_;
if (connect_timeout_ && (*connect_timeout_).size())
if (host_ && !host_->empty()) connect_str += "host=" + *host_;
if (port_ && !port_->empty()) connect_str += " port=" + *port_;
if (dbname_ && !dbname_->empty()) connect_str += " dbname=" + *dbname_;
if (user_ && !user_->empty()) connect_str += " user=" + *user_;
if (connect_timeout_ && !connect_timeout_->empty())
connect_str +=" connect_timeout=" + *connect_timeout_;
return connect_str;
}
Expand Down

0 comments on commit 9afaf09

Please sign in to comment.