namespace {
-const uid_t kUserRoot = 0;
-const uid_t kGlobalUser = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+const uid_t kRootUserUid = 0;
+const uid_t kAppfwUserUid = 301;
+const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
const char kPkgInstallManifestPath[] = "/usr/bin/pkg-install-manifest";
const char kBackendDirectoryPath[] = "/etc/package-manager/backend/";
bf::path backend_path(kBackendDirectoryPath);
backend_path /= type;
ci::Subprocess backend(backend_path.string());
- backend.set_uid(uid);
- if (preload)
+ if (preload) {
+ if (uid != kRootUserUid) {
+ std::cerr << "Preload request for non-root user" << std::endl;
+ return -1;
+ }
backend.Run("-y", pkgid.c_str(), "--preload");
- else
- backend.Run("-y", pkgid.c_str());
+ } else {
+ backend.set_uid(kAppfwUserUid);
+ std::string str_uid = std::to_string(uid);
+ backend.Run("-y", pkgid.c_str(), "-u", str_uid.c_str());
+ }
return backend.Wait();
}
bool IsGlobal(uid_t uid) {
- return uid == kUserRoot || uid == kGlobalUser;
+ return uid == kRootUserUid || uid == kGlobalUserUid;
}
void InitdbLoadDirectory(uid_t uid, const bf::path& directory, bool preload) {
} // namespace
int main(int argc, char *argv[]) {
- if (getuid() != kUserRoot) {
+ if (getuid() != kRootUserUid) {
std::cerr << "This binary should be run as root user" << std::endl;
return -1;
}
uid_t uid;
try {
options.add_options()
- ("uid,u", bpo::value<int>()->default_value(kUserRoot), "user id")
+ ("uid,u", bpo::value<int>()->default_value(kRootUserUid), "user id")
("help,h", "display this help message");
bpo::store(bpo::parse_command_line(argc, argv, options), opt_map);
if (opt_map.count("help")) {