static void TestUserNameAndId(void) { // Test user id. uid_t uid; gid_t gid; LE_ASSERT(user_GetIDs(USER_NAME, &uid, &gid) == LE_OK); LE_ASSERT(uid == Uid); LE_ASSERT(gid == Gid); // Test the GetUid() function. LE_ASSERT(user_GetUid(USER_NAME, &uid) == LE_OK); LE_ASSERT(uid == Uid); // Test the GetGid() function. LE_ASSERT(user_GetGid(USER_NAME, &gid) == LE_OK); LE_ASSERT(gid == Gid); // Test user name. char buf[100]; LE_ASSERT(user_GetName(Uid, buf, sizeof(buf)) == LE_OK); LE_ASSERT(strcmp(buf, USER_NAME) == 0); // Test group name. LE_ASSERT(user_GetGroupName(Gid, buf, sizeof(buf)) == LE_OK); LE_ASSERT(strcmp(buf, USER_NAME) == 0); // Test app name. LE_ASSERT(user_GetAppName(Uid, buf, sizeof(buf)) == LE_NOT_FOUND); LE_ASSERT(user_GetAppName(AppUid, buf, sizeof(buf)) == LE_OK); LE_ASSERT(strcmp(buf, APP_NAME) == 0); }
//-------------------------------------------------------------------------------------------------- static void WatchdogHandleExpiry ( le_timer_Ref_t timerRef ///< [IN] The reference to the expired timer ) { char appName[LIMIT_MAX_APP_NAME_BYTES]; pid_t procId = (intptr_t)le_timer_GetContextPtr(timerRef); WatchdogObj_t* expiredDog = LookupClientWatchdogPtrById(procId); if (expiredDog != NULL) { uid_t appId = expiredDog->appId; if (LE_OK == user_GetAppName(appId, appName, sizeof(appName) )) { LE_CRIT("app %s, proc %d timed out", appName, procId); } else { LE_CRIT("app %d, proc %d timed out", appId, procId); } DeleteWatchdog(procId); le_sup_wdog_WatchdogTimedOut(appId, procId); } else { LE_CRIT("Processing watchdog timeout for proc %d but watchdog already freed.", procId); } }
static void TestUserDeletion(void) { LE_ASSERT(user_Delete(USER_NAME) == LE_OK); LE_ASSERT(user_Delete(APP_USER_NAME) == LE_OK); LE_ASSERT(user_GetIDs(USER_NAME, NULL, NULL) == LE_NOT_FOUND); char buf[100]; LE_ASSERT(user_GetName(Uid, buf, sizeof(buf)) == LE_NOT_FOUND); LE_ASSERT(user_GetAppName(AppUid, buf, sizeof(buf)) == LE_NOT_FOUND); }
//-------------------------------------------------------------------------------------------------- static tu_UserRef_t GetUser ( uid_t userId, ///< [IN] The user id to look up. bool* wasCreated ///< [OUT] Was the user info created for this request? Pass NULL if you don't ///< need this. ) //-------------------------------------------------------------------------------------------------- { // If the connected user has the same uid we're running under, treat the user as if they're // root. if (userId == geteuid()) { userId = 0; } if (wasCreated) { *wasCreated = false; } // Now try to look up this user in our hash table. If not found, create it now. tu_UserRef_t userRef = le_hashmap_Get(UserCollectionRef, &userId); if (userRef == NULL) { // At this point, grab the user's app name, which will succeed if it is an app, otherwise we get // the standard user name. char userName[LIMIT_MAX_USER_NAME_BYTES] = ""; if (user_GetAppName(userId, userName, sizeof(userName)) != LE_OK) { LE_ASSERT(user_GetName(userId, userName, sizeof(userName)) == LE_OK); } userRef = CreateUserInfo(userId, userName, userName); if (wasCreated) { *wasCreated = true; } } return userRef; }
//-------------------------------------------------------------------------------------------------- static le_clk_Time_t GetConfigKickTimeoutInterval ( pid_t procId, ///< The process id of the client uid_t appId ///< The user id of the application ) { char appName[LIMIT_MAX_APP_NAME_BYTES] = ""; char procName[LIMIT_MAX_PROCESS_NAME_BYTES] = ""; char configPath[LIMIT_MAX_PATH_BYTES] = ""; const int defaultTimeout = TIMEOUT_DEFAULT; int proc_milliseconds = CFG_TIMEOUT_USE_DEFAULT; int app_milliseconds = CFG_TIMEOUT_USE_DEFAULT; if (LE_OK == user_GetAppName(appId, appName, sizeof(appName) )) { // Check if there is a config for the process name first else check under the app name // It's a real app. Let's look up the config! LE_DEBUG("Getting configured watchdog timeout for app %s", appName); if (le_path_Concat("/", configPath, sizeof(configPath), "apps", appName, "watchdogTimeout", NULL) == LE_OK) { app_milliseconds = le_cfg_QuickGetInt(configPath, CFG_TIMEOUT_USE_DEFAULT); } if (LE_OK == GetProcessNameFromPid( procId, procName, sizeof(procName))) { // get the config configPath[0]='\0'; LE_DEBUG("Getting configured watchdog timeout for process %s", procName); if(le_path_Concat("/", configPath, sizeof(configPath), "apps", appName, "procs", procName, "watchdogTimeout", NULL) == LE_OK) { proc_milliseconds = le_cfg_QuickGetInt(configPath, CFG_TIMEOUT_USE_DEFAULT); } } // find a valid value starting at proc level and working up if (proc_milliseconds == CFG_TIMEOUT_USE_DEFAULT) { if (app_milliseconds == CFG_TIMEOUT_USE_DEFAULT) { proc_milliseconds = defaultTimeout; LE_WARN("No watchdog timeout configured for %s - using default %d ms", appName, proc_milliseconds); } else { proc_milliseconds = app_milliseconds; LE_INFO("No watchdog timeout configured for process %s - using app timeout %d ms", procName, proc_milliseconds); } } else { LE_DEBUG("Watchdog timeout configured for %s - timeout %d ms", procName, proc_milliseconds); } } else { // We have no idea what process is calling us, but we can set a default timeout // and play along. // TODO: Find a way to get the configured watchdog timeout duration for unsandboxed // apps, which run as root. proc_milliseconds = defaultTimeout; LE_WARN("Unknown app with uid %u requested watchdog - using default timeout %d ms", appId, proc_milliseconds); } return MakeTimerInterval(proc_milliseconds); }