2017-12-19 00:04:06 +00:00
|
|
|
/**
|
2020-08-11 20:46:54 +00:00
|
|
|
* Copyright (c) 2014-present, The osquery authors
|
2016-05-11 21:16:32 +00:00
|
|
|
*
|
2020-08-11 20:46:54 +00:00
|
|
|
* This source code is licensed as defined by the LICENSE file found in the
|
|
|
|
* root directory of this source tree.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: (Apache-2.0 OR GPL-2.0-only)
|
2016-05-11 21:16:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2016-08-31 23:45:06 +00:00
|
|
|
#include <dlfcn.h>
|
2016-05-11 21:16:32 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <sys/resource.h>
|
2016-12-03 07:24:08 +00:00
|
|
|
#include <sys/syscall.h>
|
2016-05-11 21:16:32 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
2020-08-11 15:54:54 +00:00
|
|
|
#include <osquery/core/flags.h>
|
2018-09-21 18:54:31 +00:00
|
|
|
#include <osquery/process/process.h>
|
2016-05-11 21:16:32 +00:00
|
|
|
|
|
|
|
namespace osquery {
|
|
|
|
|
2017-01-13 02:09:46 +00:00
|
|
|
DECLARE_uint64(alarm_timeout);
|
|
|
|
|
2019-07-01 15:19:57 +00:00
|
|
|
uint32_t platformGetUid() {
|
2016-10-14 17:23:37 +00:00
|
|
|
return ::getuid();
|
2016-09-12 16:46:52 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:16:32 +00:00
|
|
|
bool isLauncherProcessDead(PlatformProcess& launcher) {
|
|
|
|
if (!launcher.isValid()) {
|
2017-01-26 01:48:33 +00:00
|
|
|
return true;
|
2016-05-11 21:16:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (::getppid() != launcher.nativeHandle());
|
|
|
|
}
|
|
|
|
|
2016-08-31 23:45:06 +00:00
|
|
|
ModuleHandle platformModuleOpen(const std::string& path) {
|
|
|
|
return ::dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* platformModuleGetSymbol(ModuleHandle module, const std::string& symbol) {
|
|
|
|
return ::dlsym(module, symbol.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string platformModuleGetError() {
|
|
|
|
return ::dlerror();
|
|
|
|
}
|
2016-05-11 21:16:32 +00:00
|
|
|
|
2016-08-31 23:45:06 +00:00
|
|
|
bool platformModuleClose(ModuleHandle module) {
|
|
|
|
return (::dlclose(module) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setToBackgroundPriority() {
|
|
|
|
setpriority(PRIO_PGRP, 0, 10);
|
|
|
|
}
|
2016-09-02 21:53:04 +00:00
|
|
|
|
|
|
|
// Helper function to determine if thread is running with admin privilege.
|
|
|
|
bool isUserAdmin() {
|
|
|
|
return getuid() == 0;
|
|
|
|
}
|
2016-10-14 17:23:37 +00:00
|
|
|
|
|
|
|
int platformGetPid() {
|
2017-09-10 17:58:38 +00:00
|
|
|
return static_cast<int>(getpid());
|
2016-10-14 17:23:37 +00:00
|
|
|
}
|
2016-12-03 07:24:08 +00:00
|
|
|
|
2019-07-01 15:19:57 +00:00
|
|
|
uint64_t platformGetTid() {
|
2017-05-31 00:08:20 +00:00
|
|
|
return std::hash<std::thread::id>()(std::this_thread::get_id());
|
2016-12-03 07:24:08 +00:00
|
|
|
}
|
2016-05-11 21:16:32 +00:00
|
|
|
}
|