service: add full path for service binary (#4316)

This commit is contained in:
Nick Anderson 2018-05-01 20:47:22 -07:00 committed by GitHub
parent f5abb45919
commit 6eb695bf9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 7 deletions

View File

@ -37,6 +37,8 @@
#include "osquery/main/main.h"
#include "osquery/sql/sqlite_util.h"
namespace fs = boost::filesystem;
namespace osquery {
SHELL_FLAG(int32,
@ -150,7 +152,8 @@ int startOsquery(int argc, char* argv[], std::function<void()> shutdown) {
// Options for installing or uninstalling the osqueryd as a service
if (FLAGS_install) {
if (!installService(argv[0])) {
auto binPath = fs::system_complete(fs::path(argv[0]));
if (!installService(binPath.string())) {
LOG(ERROR) << "Unable to install the osqueryd service";
}
return 1;

View File

@ -26,7 +26,7 @@ namespace osquery {
* This disconnect of install flows is a limitation. The POSIX install flows
* should be refactored into install/uninstall service methods.
*/
Status installService(const char* const path);
Status installService(const std::string& path);
/// See installService.
Status uninstallService();

View File

@ -16,7 +16,7 @@
namespace osquery {
Status installService(const char* const /*path*/) {
Status installService(const std::string& /*path*/) {
LOG(INFO) << "The --install service flag only applies to Windows platforms";
return Status(1);
}

View File

@ -207,7 +207,7 @@ class ServiceArgumentParser {
};
/// Install osqueryd as a service given the path to the binary
Status installService(const char* const binPath) {
Status installService(const std::string& binPath) {
SC_HANDLE schSCManager = OpenSCManager(
nullptr, nullptr, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE);
@ -225,9 +225,8 @@ Status installService(const char* const binPath) {
}
HANDLE flagsFilePtr = nullptr;
std::string binPathWithFlagFile = std::string(binPath) + " --flagfile=";
std::string flagsFile =
FLAGS_flagfile.empty() ? kDefaultFlagsFile : FLAGS_flagfile;
auto binPathWithFlagFile = binPath + " --flagfile=";
auto flagsFile = FLAGS_flagfile.empty() ? kDefaultFlagsFile : FLAGS_flagfile;
binPathWithFlagFile += flagsFile;
flagsFilePtr = CreateFile(flagsFile.c_str(),
GENERIC_READ,