39 # define __attribute__(x) 52 #include <sys/types.h> 67 if (authPolicy == 0) {
70 long maxbuf = sysconf(_SC_GETPW_R_SIZE_MAX);
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");
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) {
103 std::string password = (*i)->getString(
"password");
104 if (username.
empty()) {
106 "Empty username for host/port: " + host +
":" + port);
112 "No credentials found for host/port: " + host +
":" + port);
128 authPolicy =
nullptr;
157 return result.first +
":" + result.second;
179 return result.second;
Interface for DbAuth class.
A PersistentCitizenScope object causes all Citizen objects created during its lifetime to be marked a...
static bool available(std::string const &host, std::string const &port)
Determine whether an authenticator string is available for database access.
a container for holding hierarchical configuration data in memory.
std::vector< Ptr > PolicyPtrArray
static void setPolicy(lsst::pex::policy::Policy::Ptr policy)
Set the authenticator Policy.
static void resetPolicy()
Set the authenticator Policy back to null.
std::shared_ptr< Policy > Ptr
static std::string authString(std::string const &host, std::string const &port)
Get the authenticator string for a database.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
static std::string username(std::string const &host, std::string const &port)
Get the username to use to authenticate to a database.
static std::string password(std::string const &host, std::string const &port)
Get the password to use to authenticate to a database.
Reports errors that are due to events beyond the control of the program.