*
* @param[in] uid user id
* @param[in] installationType type of installation (global or local)
+ * @param[in] labelsForUser set of labels permitted for given user
* @return resulting true on success
*/
-void updatePermissibleFile(uid_t uid, int installationType);
+void updatePermissibleFile(uid_t uid, int installationType,
+ const std::vector<std::string> &labelsForUser);
/**
* Read labels from a file into a vector
}
}
-void updatePermissibleFile(uid_t uid, int installationType)
+void updatePermissibleFile(uid_t uid, int installationType,
+ const std::vector<std::string> &labelsForUser)
{
std::string nameFile = getPerrmissibleFileLocation(uid, installationType);
std::ofstream fstream;
openAndLockNameFile(nameFile, fstream);
markPermissibleFileValid(getFd(fstream), nameFile, false);
- std::vector<std::string> appNames;
- PrivilegeDb::getInstance().GetUserApps(uid, appNames);
- for (auto &appName : appNames) {
- std::string pkgName;
- PrivilegeDb::getInstance().GetAppPkgName(appName, pkgName);
- bool isPkgHybrid = PrivilegeDb::getInstance().IsPackageHybrid(pkgName);
-
- fstream << SmackLabels::generateProcessLabel(appName, pkgName, isPkgHybrid) << '\n';
+ for (auto &label : labelsForUser) {
+ fstream << label << '\n';
if (fstream.bad()) {
LogError("Unable to write to file " << nameFile << ": " << GetErrnoString(errno));
ThrowMsg(PermissibleSetException::PermissibleSetException::FileWriteError,
}
}
+void ServiceImpl::updatePermissibleSet(uid_t uid, int type)
+{
+ std::vector<std::string> userPkgs;
+ PrivilegeDb::getInstance().GetUserPkgs(uid, userPkgs);
+ std::vector<std::string> labelsForUser;
+ for (const auto &pkg : userPkgs) {
+ std::vector<std::string> pkgLabels;
+ getPkgLabels(pkg, pkgLabels);
+ labelsForUser.insert(labelsForUser.end(), pkgLabels.begin(), pkgLabels.end());
+ }
+ PermissibleSet::updatePermissibleFile(uid, type, labelsForUser);
+}
+
int ServiceImpl::appInstall(const Credentials &creds, app_inst_req &&req)
{
std::vector<std::string> addedPermissions;
// WTF? Why this commit is here? Shouldn't it be at the end of this function?
PrivilegeDb::getInstance().CommitTransaction();
LogDebug("Application installation commited to database");
- PermissibleSet::updatePermissibleFile(req.uid, req.installationType);
+ updatePermissibleSet(req.uid, req.installationType);
} catch (const PrivilegeDb::Exception::IOError &e) {
LogError("Cannot access application database: " << e.DumpToString());
return SECURITY_MANAGER_ERROR_SERVER_ERROR;
std::vector<std::string>(), isPrivilegePrivacy);
PrivilegeDb::getInstance().CommitTransaction();
LogDebug("Application uninstallation commited to database");
- PermissibleSet::updatePermissibleFile(req.uid, req.installationType);
+ updatePermissibleSet(req.uid, req.installationType);
} catch (const PrivilegeDb::Exception::IOError &e) {
LogError("Cannot access application database: " << e.DumpToString());
return SECURITY_MANAGER_ERROR_SERVER_ERROR;