}
}
-CynaraAdmin::TypeToDescriptionMap CynaraAdmin::TypeToDescription;
-CynaraAdmin::DescriptionToTypeMap CynaraAdmin::DescriptionToType;
+CynaraAdmin::TypeToDescriptionMap CynaraAdmin::s_typeToDescription;
+CynaraAdmin::DescriptionToTypeMap CynaraAdmin::s_descriptionToType;
CynaraAdmin::CynaraAdmin()
: m_policyDescriptionsInitialized(false)
{
checkCynaraError(
- cynara_admin_initialize(&m_CynaraAdmin),
+ cynara_admin_initialize(&m_cynaraAdmin),
"Cannot connect to Cynara administrative interface.");
}
CynaraAdmin::~CynaraAdmin()
{
- cynara_admin_finish(m_CynaraAdmin);
+ cynara_admin_finish(m_cynaraAdmin);
}
void CynaraAdmin::SetPolicies(const std::vector<CynaraAdminPolicy> &policies)
pp_policies[policies.size()] = nullptr;
checkCynaraError(
- cynara_admin_set_policies(m_CynaraAdmin, pp_policies.data()),
+ cynara_admin_set_policies(m_cynaraAdmin, pp_policies.data()),
"Error while updating Cynara policy.");
}
struct cynara_admin_policy ** pp_policies = nullptr;
checkCynaraError(
- cynara_admin_list_policies(m_CynaraAdmin, bucket.c_str(), label.c_str(),
+ cynara_admin_list_policies(m_cynaraAdmin, bucket.c_str(), label.c_str(),
user.c_str(), privilege.c_str(), &pp_policies),
"Error while getting list of policies for bucket: " + bucket);
const std::string &user, const std::string &privilege)
{
checkCynaraError(
- cynara_admin_erase(m_CynaraAdmin, bucketName.c_str(), static_cast<int>(recursive),
+ cynara_admin_erase(m_cynaraAdmin, bucketName.c_str(), static_cast<int>(recursive),
client.c_str(), user.c_str(), privilege.c_str()),
"Error while emptying bucket: " + bucketName + ", filter (C, U, P): " +
client + ", " + user + ", " + privilege);
// fetch
checkCynaraError(
- cynara_admin_list_policies_descriptions(m_CynaraAdmin, &descriptions),
+ cynara_admin_list_policies_descriptions(m_cynaraAdmin, &descriptions),
"Error while getting list of policies descriptions from Cynara.");
if (descriptions[0] == nullptr) {
// reset the state
m_policyDescriptionsInitialized = false;
- DescriptionToType.clear();
- TypeToDescription.clear();
+ s_descriptionToType.clear();
+ s_typeToDescription.clear();
// extract strings
for (int i = 0; descriptions[i] != nullptr; i++) {
std::string descriptionName(descriptions[i]->name);
- DescriptionToType[descriptionName] = descriptions[i]->result;
- TypeToDescription[descriptions[i]->result] = std::move(descriptionName);
+ s_descriptionToType[descriptionName] = descriptions[i]->result;
+ s_typeToDescription[descriptions[i]->result] = std::move(descriptionName);
free(descriptions[i]->name);
free(descriptions[i]);
{
FetchCynaraPolicyDescriptions(false);
- for (const auto &it : TypeToDescription)
+ for (const auto &it : s_typeToDescription)
policiesDescriptions.push_back(it.second);
}
{
FetchCynaraPolicyDescriptions(forceRefresh);
- return TypeToDescription.at(policyType);
+ return s_typeToDescription.at(policyType);
}
int CynaraAdmin::convertToPolicyType(const std::string &policy, bool forceRefresh)
{
FetchCynaraPolicyDescriptions(forceRefresh);
- return DescriptionToType.at(policy);
+ return s_descriptionToType.at(policy);
}
void CynaraAdmin::Check(const std::string &label, const std::string &user, const std::string &privilege,
char *resultExtraCstr = nullptr;
checkCynaraError(
- cynara_admin_check(m_CynaraAdmin, bucket.c_str(), recursive, label.c_str(),
+ cynara_admin_check(m_cynaraAdmin, bucket.c_str(), recursive, label.c_str(),
user.c_str(), privilege.c_str(), &result, &resultExtraCstr),
"Error while asking cynara admin API for permission for app label: " + label + ", user: "
+ user + " privilege: " + privilege + " bucket: " + bucket);
return result;
}
-Cynara::Cynara() : eventFd(eventfd(0, 0)), cynaraFd(eventFd), cynaraFdEvents(0), terminate(false)
+Cynara::Cynara() : m_eventFd(eventfd(0, 0)), m_cynaraFd(m_eventFd), m_cynaraFdEvents(0), m_terminate(false)
{
- if (eventFd == -1) {
+ if (m_eventFd == -1) {
LogError("Error while creating eventfd: " << GetErrnoString(errno));
ThrowMsg(CynaraException::UnknownError, "Error while creating eventfd");
}
checkCynaraError(cynara_async_configuration_set_cache_size(p_conf, CACHE_SIZE),
"Cannot set cynara async configuration cache size");
checkCynaraError(
- cynara_async_initialize(&cynara, p_conf, &Cynara::statusCallback, this),
+ cynara_async_initialize(&m_cynara, p_conf, &Cynara::statusCallback, this),
"Cannot connect to Cynara policy interface.");
- thread = std::thread(&Cynara::run, this);
+ m_thread = std::thread(&Cynara::run, this);
}
Cynara::~Cynara()
{
LogDebug("Sending terminate event to Cynara thread");
- terminate = true;
+ m_terminate = true;
threadNotifyPut();
- thread.join();
+ m_thread.join();
// Critical section
- std::lock_guard<std::mutex> guard(mutex);
- cynara_async_finish(cynara);
+ std::lock_guard<std::mutex> guard(m_mutex);
+ cynara_async_finish(m_cynara);
}
void Cynara::threadNotifyPut()
{
- int ret = eventfd_write(eventFd, 1);
+ int ret = eventfd_write(m_eventFd, 1);
if (ret == -1)
LogError("Unexpected error while writing to eventfd: " << GetErrnoString(errno));
}
void Cynara::threadNotifyGet()
{
eventfd_t value;
- int ret = eventfd_read(eventFd, &value);
+ int ret = eventfd_read(m_eventFd, &value);
if (ret == -1)
LogError("Unexpected error while reading from eventfd: " << GetErrnoString(errno));
}
"Status = " << status << ", oldFd = " << oldFd << ", newFd = " << newFd);
if (newFd == -1) {
- cynaraFdEvents = 0;
+ m_cynaraFdEvents = 0;
} else {
-
- cynaraFd = newFd;
+ m_cynaraFd = newFd;
switch (status) {
case CYNARA_STATUS_FOR_READ:
- cynaraFdEvents = POLLIN;
+ m_cynaraFdEvents = POLLIN;
break;
-
case CYNARA_STATUS_FOR_RW:
- cynaraFdEvents = POLLIN | POLLOUT;
+ m_cynaraFdEvents = POLLIN | POLLOUT;
break;
}
}
LogInfo("Cynara thread started");
while (true) {
std::atomic_thread_fence(std::memory_order_acquire);
- struct pollfd pollFds[2] = {{eventFd, POLLIN, 0}, {cynaraFd, cynaraFdEvents, 0}};
+ struct pollfd pollFds[2] = {{m_eventFd, POLLIN, 0}, {m_cynaraFd, m_cynaraFdEvents, 0}};
int ret = poll(pollFds, 2, -1);
if (ret == -1) {
// Check eventfd for termination signal
if (pollFds[0].revents) {
threadNotifyGet();
- if (terminate) {
+ if (m_terminate) {
LogInfo("Cynara thread terminated");
return;
}
if (pollFds[1].revents) {
try {
// Critical section
- std::lock_guard<std::mutex> guard(mutex);
+ std::lock_guard<std::mutex> guard(m_mutex);
- checkCynaraError(cynara_async_process(cynara),
+ checkCynaraError(cynara_async_process(m_cynara),
"Unexpected error returned by cynara_async_process");
} catch (const CynaraException::Base &e) {
LogError("Error while processing Cynara events: " << e.DumpToString());
// Critical section
{
- std::lock_guard<std::mutex> guard(mutex);
+ std::lock_guard<std::mutex> guard(m_mutex);
- int ret = cynara_async_check_cache(cynara,
+ int ret = cynara_async_check_cache(m_cynara,
label.c_str(), session.c_str(), user.c_str(), privilege.c_str());
if (ret != CYNARA_API_CACHE_MISS)
cynara_check_id check_id;
checkCynaraError(
- cynara_async_create_request(cynara,
+ cynara_async_create_request(m_cynara,
label.c_str(), session.c_str(), user.c_str(), privilege.c_str(),
&check_id, &Cynara::responseCallback, &promise),
"Cannot check permission with Cynara.");