18 static const char*
b64str =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
43 struct passwd* userp = ::getpwuid(::getuid());
45 char* uName = userp->pw_name;
50 if (loginName.empty()) {
64 if (
item.size() > 3) {
65 paramName =
item.substr(0, 2);
66 paramValue =
item.substr(2);
67 params.insert(std::make_pair(paramName, paramValue));
80 for (
size_t i = 0;
i < keySize;
i++) {
88 ::srand(m_iteration + 2);
99 s <<
OWNERPREFIX <<
"<owner_name, optional>" << std::endl;
100 s <<
KEYPREFIX <<
"<key, leave empty if generated>" << std::endl;
103 <<
"<user0_name>;" <<
PASSWORDPREFIX <<
"<password0>;" << std::endl;
105 <<
"<user1_name>;" <<
PASSWORDPREFIX <<
"<password1>;" << std::endl;
107 <<
"<user2_name>;" <<
PASSWORDPREFIX <<
"<password2>;" << std::endl;
112 if (keyFileName.empty()) {
116 m_fileName = keyFileName;
119 m_principalName.clear();
120 m_principalKey.clear();
125 std::ifstream
keyFile(m_fileName.c_str(),
std::ios::in | std::ios::binary | std::ios::ate);
127 size_t fsize =
keyFile.tellg();
128 unsigned char* buff = (
unsigned char*)malloc(fsize);
129 keyFile.seekg(0, std::ios::beg);
130 keyFile.read(reinterpret_cast<char*>(buff), fsize);
143 if (
line.size() > 3) {
145 m_principalName =
line.substr(2);
147 m_principalKey =
line.substr(2);
149 m_owner =
line.substr(2);
151 std::stringstream serviceStr(
line.substr(2));
152 std::vector<std::string> sdata;
153 while (serviceStr.good()) {
157 std::map<std::string, ServiceCredentials>::iterator iS =
159 iS->second.connectionString = sdata[1];
160 iS->second.userName = sdata[2];
161 iS->second.password = sdata[3];
167 if (m_principalName.empty() || m_principalKey.empty()) {
171 if (!m_owner.empty()) {
173 if (m_owner != currentUser) {
174 m_principalName.clear();
175 m_principalKey.clear();
178 std::string msg =
"Provided key is invalid for user=" + currentUser;
183 std::string msg =
"Required Key File \"" + m_fileName +
"\" is missing or unreadable.";
196 m_principalName.clear();
197 m_principalKey.clear();
202 std::map<std::string, std::string>
params;
207 if (
line.size() > 3) {
209 m_principalName =
line.substr(2);
211 m_principalKey =
line.substr(2);
213 m_owner =
line.substr(2);
221 m_services.insert(std::make_pair(
serviceName, creds));
227 if (m_principalKey.empty() && generatedKeySize) {
229 m_principalKey =
gen.make(generatedKeySize);
243 for (std::map<std::string, ServiceCredentials>::const_iterator iS = m_services.begin(); iS != m_services.end();
253 std::ofstream
outFile(m_fileName.c_str(), std::ios::binary);
257 if (!m_principalName.empty()) {
260 if (!m_principalKey.empty()) {
263 if (!m_owner.empty()) {
266 for (std::map<std::string, ServiceCredentials>::const_iterator iD = m_services.begin(); iD != m_services.end();
277 outFile.write(reinterpret_cast<char*>(
out), outSize);
281 msg +=
"Provided Key File \"" + m_fileName +
"\n is invalid.";
295 std::map<std::string, ServiceCredentials>::iterator iK = m_services.find(
serviceName);
296 if (iK == m_services.end()) {