39 # define __attribute__(x)
46 #include "boost/scoped_array.hpp"
52 #include <sys/types.h>
59 namespace dafBase = lsst::daf::base;
60 namespace dafPersist = lsst::daf::persistence;
61 namespace pexPolicy = lsst::pex::policy;
65 static std::pair<std::string, std::string>
66 search(std::string
const& host, std::string
const& port) {
67 if (authPolicy == 0) {
70 long maxbuf = sysconf(_SC_GETPW_R_SIZE_MAX);
71 boost::scoped_array<char> buffer(
new char[maxbuf]);
72 int ret = getpwuid_r(geteuid(), &pwd, buffer.get(), maxbuf, &pw);
73 if (ret != 0 || pw->pw_dir == 0) {
75 "Could not get home directory");
77 std::string dir = std::string(pw->pw_dir) +
"/.lsst";
78 std::string filename = dir +
"/db-auth.paf";
80 ret = stat(dir.c_str(), &st);
81 if (ret != 0 || (st.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
83 dir +
" directory is missing or accessible by others");
85 ret = stat(filename.c_str(), &st);
86 if (ret != 0 || (st.st_mode & (S_IRWXG | S_IRWXO)) != 0) {
88 filename +
" is missing or accessible by others");
95 int portNum = atoi(port.c_str());
97 authPolicy->getPolicyArray(
"database.authInfo");
98 for (pexPolicy::Policy::PolicyPtrArray::const_iterator i =
99 authArray.begin(); i != authArray.end(); ++i) {
100 if ((*i)->getString(
"host") == host &&
101 (*i)->getInt(
"port") == portNum) {
102 std::string username = (*i)->getString(
"user");
103 std::string password = (*i)->getString(
"password");
104 if (username.empty()) {
106 "Empty username for host/port: " + host +
":" + port);
108 return std::pair<std::string, std::string>(username, password);
112 "No credentials found for host/port: " + host +
":" + port);
113 return std::pair<std::string, std::string>(
"",
"");
131 std::string
const& port) {
133 std::pair<std::string, std::string> result = search(host, port);
148 std::string
const& port) {
149 std::pair<std::string, std::string> result = search(host, port);
150 return result.first +
":" + result.second;
159 std::string
const& port) {
160 std::pair<std::string, std::string> result = search(host, port);
170 std::string
const& port) {
171 std::pair<std::string, std::string> result = search(host, port);
172 return result.second;
Interface for DbAuth class.
std::vector< Ptr > PolicyPtrArray
static bool available(std::string const &host, std::string const &port)
Include files required for standard LSST Exception handling.
a container for holding hierarchical configuration data in memory.
boost::shared_ptr< Policy > Ptr
static void setPolicy(lsst::pex::policy::Policy::Ptr policy)
static std::string authString(std::string const &host, std::string const &port)
#define LSST_EXCEPT(type,...)
static std::string username(std::string const &host, std::string const &port)
static std::string password(std::string const &host, std::string const &port)