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); } }); }
void Routine::releaseStatement(thread_db* tdbb) { if (getStatement()) { getStatement()->release(tdbb); setStatement(NULL); } setInputFormat(NULL); setOutputFormat(NULL); flags &= ~FLAG_SCANNED; }
bool PrivilegeDb::PkgIdExists(const std::string &pkgId) { return try_catch<bool>([&] { auto command = getStatement(StmtType::EPkgIdExists); command->BindString(1, pkgId); return command->Step(); }); }
std::string Pragma::toStr(const clang::SourceManager& sm) const { std::ostringstream ss; ss << "(" << utils::location(getStartLocation(), sm) << ", " << utils::location(getEndLocation(), sm) << "),\n\t"; ss << (isStatement() ? "Stmt -> " : "Decl -> ") << "("; if(isStatement() && getStatement()) { ss << utils::location(getStatement()->getLocStart(), sm) << ", " << utils::location(getStatement()->getLocEnd(), sm); } else if(isDecl() && getDecl()) ss << utils::location(getDecl()->getLocStart(), sm) << ", " << utils::location(getDecl()->getLocEnd(), sm); ss << ")"; return ss.str(); }
void PrivilegeDb::GetGroups(std::vector<std::string> &groups) { try_catch<void>([&] { auto command = getStatement(StmtType::EGetGroups); while (command->Step()) { std::string groupName = command->GetColumnString(0); LogDebug("Group " << groupName); groups.push_back(groupName); }; }); }
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); }; }); }
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); }; }); }
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); }); }
tree * getWhile(token **tokenPtr,char *buffer) { assert((*tokenPtr)!=NULL); if ((*tokenPtr)->type!=WHILE) return NULL; tree * result=newTree(); result->action=(*tokenPtr); if ((*tokenPtr)!=NULL) (*tokenPtr)=nextToken((*tokenPtr),buffer,false); result->left=getExpression(tokenPtr,buffer); if ((*tokenPtr)==NULL) { printf("Syntax error... expected expression + statement after while\n"); exit(1); } result->right=getStatement(tokenPtr,buffer); return result; }
void PrivilegeDb::GetPkgPrivileges(const std::string &pkgId, uid_t uid, std::vector<std::string> ¤tPrivileges) { 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); }; }); }
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); }; }); }
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); }); }
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; }); }
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 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); } }); }
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); } }); }
tree * getExpList(token **tokenPtr,char *buffer) { assert((*tokenPtr)!=NULL); tree * exp=getStatement(tokenPtr,buffer); if ((*tokenPtr)==NULL) return exp; // Single expression only if ((*tokenPtr)->type==RCURLY) return exp; // Expression lists closed by rcurly if ((*tokenPtr)->type==EOS) { tree* result=newTree(); result->left=exp; result->action=(*tokenPtr); (*tokenPtr)=nextToken((*tokenPtr),buffer,false); if (((*tokenPtr)==NULL) || (*tokenPtr)->type==LCURLY) { // Semicolon at end of buffer ignored result->left=NULL; freeTree(result); return exp; } result->right=getExpList(tokenPtr,buffer); return result; } printf("Syntax error: unexpected tokens after expression list\n"); exit(1); }
// Decrement the routine's use count. void Routine::release(thread_db* tdbb) { // Actually, it's possible for routines to have intermixed dependencies, so // this routine can be called for the routine which is being freed itself. // Hence we should just silently ignore such a situation. if (!useCount) return; if (intUseCount > 0) intUseCount--; --useCount; #ifdef DEBUG_PROCS { string buffer; buffer.printf( "Called from CMP_decrement():\n\t Decrementing use count of %s\n", getName().toString().c_str()); JRD_print_procedure_info(tdbb, buffer.c_str()); } #endif // Call recursively if and only if the use count is zero AND the routine // in the cache is different than this routine. // The routine will be different than in the cache only if it is a // floating copy, i.e. an old copy or a deleted routine. if (useCount == 0 && !checkCache(tdbb)) { if (getStatement()) releaseStatement(tdbb); flags &= ~Routine::FLAG_BEING_ALTERED; remove(tdbb); } }
// Parse routine BLR. void Routine::parseBlr(thread_db* tdbb, CompilerScratch* csb, bid* blob_id) { Jrd::Attachment* attachment = tdbb->getAttachment(); UCharBuffer tmp; if (blob_id) { blb* blob = blb::open(tdbb, attachment->getSysTransaction(), blob_id); ULONG length = blob->blb_length + 10; UCHAR* temp = tmp.getBuffer(length); length = blob->BLB_get_data(tdbb, temp, length); tmp.resize(length); } parseMessages(tdbb, csb, BlrReader(tmp.begin(), (unsigned) tmp.getCount())); JrdStatement* statement = getStatement(); PAR_blr(tdbb, NULL, tmp.begin(), (ULONG) tmp.getCount(), NULL, &csb, &statement, false, 0); setStatement(statement); if (!blob_id) setImplemented(false); }
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 PreparedStatementManager::deleteStatement(std::string name) { delete getStatement(name); _data_map.erase(name); }