PluginStatus check(const std::string &client,
                    const std::string &user,
                    const std::string &privilege,
                    PolicyResult &result,
                    AgentType &requiredAgent,
                    PluginData &pluginData) noexcept
 {
     try {
         if (!m_cache.get(Key(client, user, privilege), result)) {
             pluginData = Translator::Plugin::requestToData(client, user, privilege);
             requiredAgent = AgentType(SupportedTypes::Agent::AgentType);
             return PluginStatus::ANSWER_NOTREADY;
         }
         if (result.policyType() == SupportedTypes::Client::ALLOW_PER_LIFE)
             result = PolicyResult(PredefinedPolicyType::ALLOW);
         else
             result = PolicyResult(PredefinedPolicyType::DENY);
         return PluginStatus::ANSWER_READY;
     } catch (const Translator::TranslateErrorException &e) {
         LOGE("Error translating request to data : " << e.what());
     } catch (const std::exception &e) {
         LOGE("Failed with std exception: " << e.what());
     } catch (...) {
         LOGE("Failed with unknown exception: ");
     }
     return PluginStatus::ERROR;
 }
示例#2
0
文件: AuditLog.cpp 项目: pohly/cynara
void AuditLog::log(const PolicyKey &policyKey, const PolicyResult &policyResult) {
    if (m_logLevel == AL_NONE)
        return;

    PolicyType policyType = policyResult.policyType();
    namespace PPT = PredefinedPolicyType;

    if (m_logLevel == AL_ALL || (m_logLevel == AL_DENY && policyType == PPT::DENY) ||
        (m_logLevel == AL_ALLOW && policyType == PPT::ALLOW) ||
        (m_logLevel == AL_OTHER && policyType != PPT::ALLOW && policyType != PPT::DENY)) {
            sd_journal_send("MESSAGE=%s;%s;%s => %s", policyKey.client().toString().c_str(),
                            policyKey.user().toString().c_str(),
                            policyKey.privilege().toString().c_str(),
                            policyResultToString(policyResult), "PRIORITY=%i", LOG_INFO,
                            "CYNARA_LOG_TYPE=AUDIT", NULL);
    }
}
示例#3
0
int OfflineLogic::insertOrUpdateBucket(const PolicyBucketId &bucket,
                                       const PolicyResult &policyResult) {
    try {
        acquireDatabase();
        acquirePlugins();
        checkSinglePolicyType(policyResult.policyType(), true, true);
        m_storage->addOrUpdateBucket(bucket, policyResult);
        onPoliciesChanged();
    } catch (const DefaultBucketSetNoneException &) {
        return CYNARA_API_OPERATION_NOT_ALLOWED;
    } catch (const InvalidBucketIdException &ex) {
        return CYNARA_API_OPERATION_NOT_ALLOWED;
    } catch (const DatabaseException &) {
        return CYNARA_API_OPERATION_FAILED;
    } catch (const DatabaseCorruptedException &) {
        return CYNARA_API_DATABASE_CORRUPTED;
    } catch (const UnknownPolicyTypeException &ex) {
        return CYNARA_API_INVALID_PARAM;
    }

    return CYNARA_API_SUCCESS;
}