Exemplo n.º 1
0
void PrivilegeDb::GetPrivilegesMappings(const std::string &version_from,
                                        const std::string &version_to,
                                        const std::vector<std::string> &privileges,
                                        std::vector<std::string> &mappings)
{
    try_catch<void>([&] {
        auto deleteCmd = getStatement(StmtType::EDeletePrivilegesToMap);
        deleteCmd->Step();

        auto insertCmd = getStatement(StmtType::EInsertPrivilegeToMap);
        for (auto &privilege : privileges) {
            if (privilege.empty())
                continue;
            insertCmd->BindString(1, privilege);
            insertCmd->Step();
            insertCmd->Reset();
        }

        insertCmd->BindNull(1);
        insertCmd->Step();

        auto queryCmd = getStatement(StmtType::EGetPrivilegesMappings);
        queryCmd->BindString(1, version_from);
        queryCmd->BindString(2, version_to);

        mappings.clear();
        while (queryCmd->Step()) {
            std::string mapping = queryCmd->GetColumnString(0);
            LogDebug("Privilege set  in version " << version_from
                     <<" has mapping " << mapping << " in version " << version_to);
             mappings.push_back(mapping);
        }
    });
}
Exemplo n.º 2
0
bool PrivilegeDb::PkgIdExists(const std::string &pkgId)
{
    return try_catch<bool>([&] {
        auto command = getStatement(StmtType::EPkgIdExists);
        command->BindString(1, pkgId);
        return command->Step();
    });
}
Exemplo n.º 3
0
void PrivilegeDb::GetDefaultMapping(const std::string &version_from,
                                    const std::string &version_to,
                                    std::vector<std::string> &mappings)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetDefaultMappings);
        command->BindString(1, version_from);
        command->BindString(2, version_to);

        mappings.clear();
        while (command->Step()) {
            std::string mapping = command->GetColumnString(0);
            LogDebug("Default Privilege from version " << version_from
                    <<" to version " << version_to << " is " << mapping);
            mappings.push_back(mapping);
        }
    });
}
Exemplo n.º 4
0
void PrivilegeDb::UpdateAppPrivileges(const std::string &appId, uid_t uid,
        const std::vector<std::string> &privileges)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EAddAppPrivileges);
        command->BindString(1, appId);
        command->BindInteger(2, static_cast<unsigned int>(uid));

        RemoveAppPrivileges(appId, uid);

        for (const auto &privilege : privileges) {
            command->BindString(3, privilege);
            command->Step();
            command->Reset();
            LogDebug("Added privilege: " << privilege << " to appId: " << appId);
        }
    });
}
void SqlConnection::DataCommand::BindString(
    SqlConnection::ArgumentIndex position,
    const Optional<String> &value)
{
    if (!!value)
        BindString(position, ToUTF8String(*value).c_str());
    else
        BindNull(position);
}
Exemplo n.º 6
0
void PrivilegeDb::GetPrivilegeMappings(const std::string &version_from,
                                       const std::string &version_to,
                                       const std::string &privilege,
                                       std::vector<std::string> &mappings)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetPrivilegeMappings);
        command->BindString(1, version_from);
        command->BindString(2, version_to);
        command->BindString(3, privilege);

        mappings.clear();
        while (command->Step()) {
            std::string mapping = command->GetColumnString(0);
            LogDebug("Privilege " << privilege << " in version " << version_from
                    <<" has mapping " << mapping << " in version " << version_to);
            mappings.push_back(mapping);
        }
    });
}
Exemplo n.º 7
0
void adbusI_logbind(const char* header, const adbus_Bind* b)
{
    if (!adbusI_log_enabled())
        return;
    d_String str;
    ZERO(&str);
    BindString(&str, b);
    adbusI_addheader(&str, "%-10s ", header);
    adbusI_klog(&str);
    ds_free(&str);
}
Exemplo n.º 8
0
void PrivilegeDb::GetPrivilegeGroups(const std::string &privilege,
        std::vector<std::string> &groups)
{
   try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetPrivilegeGroups);
        command->BindString(1, privilege);

        while (command->Step()) {
            std::string groupName = command->GetColumnString(0);
            LogDebug("Privilege " << privilege << " gives access to group: " << groupName);
            groups.push_back(groupName);
        };
    });
}
Exemplo n.º 9
0
void PrivilegeDb::RemoveAppPrivileges(const std::string &appId, uid_t uid)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::ERemoveAppPrivileges);
        command->BindString(1, appId);
        command->BindInteger(2, static_cast<unsigned int>(uid));
        if (command->Step()) {
            LogDebug("Unexpected SQLITE_ROW answer to query: " <<
                    Queries.at(StmtType::ERemoveAppPrivileges));
        }

        LogDebug("Removed all privileges for appId: " << appId);
    });
}
Exemplo n.º 10
0
void PrivilegeDb::GetPkgPrivileges(const std::string &pkgId, uid_t uid,
        std::vector<std::string> &currentPrivileges)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetPkgPrivileges);
        command->BindString(1, pkgId);
        command->BindInteger(2, static_cast<unsigned int>(uid));

        while (command->Step()) {
            std::string privilege = command->GetColumnString(0);
            LogDebug("Got privilege: " << privilege);
            currentPrivileges.push_back(privilege);
        };
    });
}
Exemplo n.º 11
0
void PrivilegeDb::GetAppIdsForPkgId(const std::string &pkgId,
        std::vector<std::string> &appIds)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetAppsInPkg);

        command->BindString(1, pkgId);
        appIds.clear();

        while (command->Step()) {
            std::string appId = command->GetColumnString (0);
            LogDebug ("Got appid: " << appId << " for pkgId " << pkgId);
            appIds.push_back(appId);
        };
    });
}
Exemplo n.º 12
0
void PrivilegeDb::AddApplication(const std::string &appId,
        const std::string &pkgId, uid_t uid)
{
    try_catch<void>([&] {
        auto command = getStatement(StmtType::EAddApplication);
        command->BindString(1, appId);
        command->BindString(2, pkgId);
        command->BindInteger(3, static_cast<unsigned int>(uid));

        if (command->Step()) {
            LogDebug("Unexpected SQLITE_ROW answer to query: " <<
                    Queries.at(StmtType::EAddApplication));
        };

        LogDebug("Added appId: " << appId << ", pkgId: " << pkgId);
    });
}
Exemplo n.º 13
0
bool PrivilegeDb::GetAppPkgId(const std::string &appId, std::string &pkgId)
{
    return try_catch<bool>([&] {
        auto command = getStatement(StmtType::EGetPkgId);
        command->BindString(1, appId);

        if (!command->Step()) {
            // No application with such appId
            return false;
        }

        // application package found in the database, get it
        pkgId = command->GetColumnString(0);

        return true;
    });
}
Exemplo n.º 14
0
void PrivilegeDb::RemoveApplication(const std::string &appId, uid_t uid,
        bool &pkgIdIsNoMore)
{
    try_catch<void>([&] {
        std::string pkgId;
        if (!GetAppPkgId(appId, pkgId)) {
            pkgIdIsNoMore = false;
            return;
        }

        auto command = getStatement(StmtType::ERemoveApplication);
        command->BindString(1, appId);
        command->BindInteger(2, static_cast<unsigned int>(uid));

        if (command->Step()) {
            LogDebug("Unexpected SQLITE_ROW answer to query: " <<
                    Queries.at(StmtType::ERemoveApplication));
        };

        LogDebug("Removed appId: " << appId);

        pkgIdIsNoMore = !(this->PkgIdExists(pkgId));
    });
}
void SqlConnection::DataCommand::BindString(
    SqlConnection::ArgumentIndex position,
    const String &value)
{
    BindString(position, ToUTF8String(value).c_str());
}