void SqlConnection::DataCommand::BindInteger(
    SqlConnection::ArgumentIndex position,
    const Optional<int> &value)
{
    if (value.IsNull())
        BindNull(position);
    else
        BindInteger(position, *value);
}
Пример #2
0
void PrivilegeDb::GetUserApps(uid_t uid, std::vector<std::string> &apps)
{
   try_catch<void>([&] {
        auto command = getStatement(StmtType::EGetUserApps);
        command->BindInteger(1, static_cast<unsigned int>(uid));
        apps.clear();
        while (command->Step()) {
            std::string app = command->GetColumnString(0);
            LogDebug("User " << uid << " has app " << app << " installed");
            apps.push_back(app);
        };
    });
}
Пример #3
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);
    });
}
Пример #4
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);
        };
    });
}
Пример #5
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);
    });
}
Пример #6
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);
        }
    });
}
Пример #7
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));
    });
}