18 static const char*
b64str =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
38 int irand = ::rand() % (::strlen(
b64str));
44 struct passwd* userp = ::getpwuid(::getuid());
46 char* uName = userp->pw_name;
51 if (loginName.empty()) {
65 if (
item.size() > 3) {
66 paramName =
item.substr(0, 2);
67 paramValue =
item.substr(2);
68 params.insert(std::make_pair(paramName, paramValue));
81 for (
size_t i = 0;
i < keySize;
i++) {
89 ::srand(m_iteration + 2);
100 s <<
NAMEPREFIX <<
"<principal_name>" << std::endl;
101 s <<
OWNERPREFIX <<
"<owner_name, optional>" << std::endl;
102 s <<
KEYPREFIX <<
"<key, leave empty if generated>" << std::endl;
105 <<
"<user0_name>;" <<
PASSWORDPREFIX <<
"<password0>;" << std::endl;
107 <<
"<user1_name>;" <<
PASSWORDPREFIX <<
"<password1>;" << std::endl;
109 <<
"<user2_name>;" <<
PASSWORDPREFIX <<
"<password2>;" << std::endl;
114 if (keyFileName.empty()) {
118 m_fileName = keyFileName;
122 m_principalName.clear();
123 m_principalKey.clear();
128 std::ifstream
keyFile(m_fileName.c_str(),
std::ios::in | std::ios::binary | std::ios::ate);
130 size_t fsize =
keyFile.tellg();
131 unsigned char* buff = (
unsigned char*)
malloc(fsize);
132 keyFile.seekg(0, std::ios::beg);
133 keyFile.read(reinterpret_cast<char*>(buff), fsize);
146 if (
line.size() > 3) {
148 m_version =
line.substr(2);
150 m_principalName =
line.substr(2);
152 m_principalKey =
line.substr(2);
154 m_owner =
line.substr(2);
156 std::stringstream serviceStr(
line.substr(2));
157 std::vector<std::string> sdata;
158 while (serviceStr.good()) {
162 std::map<std::string, ServiceCredentials>::iterator iS =
164 iS->second.connectionString = sdata[1];
165 iS->second.userName = sdata[2];
166 iS->second.password = sdata[3];
172 if (m_principalName.empty() || m_principalKey.empty()) {
176 if (!m_owner.empty()) {
178 if (m_owner != currentUser) {
179 m_principalName.clear();
180 m_principalKey.clear();
183 std::string msg =
"Provided key is invalid for user=" + currentUser;
188 std::string msg =
"Required Key File \"" + m_fileName +
"\" is missing or unreadable.";
202 m_principalName.clear();
203 m_principalKey.clear();
208 std::map<std::string, std::string>
params;
213 if (
line.size() > 3) {
215 m_version =
line.substr(2);
217 m_principalName =
line.substr(2);
219 m_principalKey =
line.substr(2);
221 m_owner =
line.substr(2);
229 m_services.insert(std::make_pair(
serviceName, creds));
235 if (m_principalKey.empty() && generatedKeySize) {
237 m_principalKey =
gen.make(generatedKeySize);
252 for (std::map<std::string, ServiceCredentials>::const_iterator iS = m_services.begin(); iS != m_services.end();
262 std::ofstream
outFile(m_fileName.c_str(), std::ios::binary);
266 if (!m_version.empty()) {
269 if (!m_principalName.empty()) {
272 if (!m_principalKey.empty()) {
275 if (!m_owner.empty()) {
278 for (std::map<std::string, ServiceCredentials>::const_iterator iD = m_services.begin(); iD != m_services.end();
289 outFile.write(reinterpret_cast<char*>(
out), outSize);
293 msg +=
"Provided Key File \"" + m_fileName +
"\n is invalid.";
307 std::map<std::string, ServiceCredentials>::iterator iK = m_services.find(
serviceName);
308 if (iK == m_services.end()) {
static const std::string KEYPREFIX("K=")
size_t init(const std::string &keyFileName, const std::string &password, bool readMode=true)
ret
prodAgent to be discontinued
void addService(const std::string &serviceName, const std::string &connectionString, const std::string &userName, const std::string &password)
void parseLineForNamedParams(const std::string &line, std::map< std::string, std::string > ¶ms)
S make(const edm::ParameterSet &cfg)
std::string getLoginName()
static const std::string USERPREFIX("U=")
static const std::string serviceName
void throwException(const std::string &message, const std::string &methodName)
static const std::string VERSIONPREFIX("V=")
static const std::string SERVICEPREFIX("S=")
std::string connectionString
size_t createFromInputFile(const std::string &inputFileName, size_t generatedKeySize=0)
static const char * b64str
static const std::string KEY_HEADER("Cond_Authentication_Key")
constexpr char LineSeparator
static const std::string DEFAULT_SERVICE("Cond_Default_Service")
void free(void *ptr) noexcept
static std::string templateFile()
size_t encrypt(const std::string &input, unsigned char *&output)
def gen(fragment, howMuch)
Event to runs.
void addDefaultService(const std::string &connectionString)
constexpr char ItemSeparator
static const std::string PASSWORDPREFIX("P=")
void * malloc(size_t size) noexcept
static const std::string OWNERPREFIX("O=")
std::string makeWithRandomSize(size_t maxSize)
std::string make(size_t keySize)
static const std::string CONNECTIONPREFIX("C=")
std::string decrypt(const unsigned char *input, size_t inputSize)
static const std::string NAMEPREFIX("N=")
static const std::string keyFile("/nfshome0/hcalsw/.ReadOMDSKey")
void list(std::ostream &out)
def addService(process, multirun=False)