From 3f64a9869e55ca9e65ca7c4d5c0b0791332e1cb4 Mon Sep 17 00:00:00 2001 From: Lucien XU Date: Wed, 29 Jun 2016 21:39:05 +0200 Subject: [PATCH] Add support for multiple privileges file Fixes MER#1607 --- src/launcherlib/booster.cpp | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/launcherlib/booster.cpp b/src/launcherlib/booster.cpp index e521084..9342996 100644 --- a/src/launcherlib/booster.cpp +++ b/src/launcherlib/booster.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -327,7 +328,7 @@ void Booster::renameProcess(int parentArgc, char** parentArgv, } } -static bool isPrivileged(AppData *appData) +static bool isPrivileged(AppData *appData, const char *path) { /* Returns true if privileged, false if not privileged. @@ -342,9 +343,7 @@ static bool isPrivileged(AppData *appData) Comment lines start with # and are ignored. */ - const char *BOOSTER_APP_PRIVILEGES_LIST = "/usr/share/mapplauncherd/privileges"; - - std::ifstream infile(BOOSTER_APP_PRIVILEGES_LIST); + std::ifstream infile(path); if (infile) { std::string line; while (std::getline(infile, line)) { @@ -370,6 +369,38 @@ static bool isPrivileged(AppData *appData) return false; } +static bool isPrivileged(AppData *appData) +{ + /* + Return true if privileged, false if not privileged. + + This function checks the standard paths to find privileges definition file. + First it will check + /usr/share/mapplauncherd/privileges + And then, any file in + /usr/share/mapplauncherd/privileges.d/ + */ + static const char *BOOSTER_APP_PRIVILEGES_LIST = "/usr/share/mapplauncherd/privileges"; + static const char *BOOSTER_APP_PRIVILEGES_DIR = "/usr/share/mapplauncherd/privileges.d"; + if (isPrivileged(appData, BOOSTER_APP_PRIVILEGES_LIST)) + return true; + + DIR *privilegesDir = opendir(BOOSTER_APP_PRIVILEGES_DIR); + if (!privilegesDir) + return false; + + bool privileged = false; + dirent *dir = NULL; + while ((dir = readdir(privilegesDir)) && !privileged) { + std::string privilegesFile (BOOSTER_APP_PRIVILEGES_DIR); + privilegesFile += "/"; + privilegesFile += dir->d_name; + privileged = isPrivileged(appData, privilegesFile.c_str()); + } + closedir(privilegesDir); + return privileged; +} + void Booster::setEnvironmentBeforeLaunch() { // Possibly restore process priority