2015-12-29 19:34:53 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_CAPABILITIES
|
|
|
|
#define INCLUDED_CAPABILITIES
|
|
|
|
|
|
|
|
#include <sys/capability.h>
|
|
|
|
|
2016-03-02 00:47:13 -06:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2015-12-29 19:34:53 -06:00
|
|
|
#include "Util.hpp"
|
|
|
|
|
|
|
|
static
|
2016-02-29 06:25:12 -06:00
|
|
|
void dropCapability(cap_value_t capability)
|
2015-12-29 19:34:53 -06:00
|
|
|
{
|
|
|
|
cap_t caps;
|
|
|
|
cap_value_t cap_list[] = { capability };
|
|
|
|
|
|
|
|
caps = cap_get_proc();
|
|
|
|
if (caps == nullptr)
|
|
|
|
{
|
|
|
|
Log::error("Error: cap_get_proc() failed.");
|
2016-03-02 00:47:13 -06:00
|
|
|
std::exit(1);
|
2015-12-29 19:34:53 -06:00
|
|
|
}
|
|
|
|
|
2016-02-29 04:12:18 -06:00
|
|
|
char *capText = cap_to_text(caps, nullptr);
|
|
|
|
Log::info("Capabilities first: " + std::string(capText));
|
|
|
|
cap_free(capText);
|
|
|
|
|
2015-12-29 19:34:53 -06:00
|
|
|
if (cap_set_flag(caps, CAP_EFFECTIVE, sizeof(cap_list)/sizeof(cap_list[0]), cap_list, CAP_CLEAR) == -1 ||
|
|
|
|
cap_set_flag(caps, CAP_PERMITTED, sizeof(cap_list)/sizeof(cap_list[0]), cap_list, CAP_CLEAR) == -1)
|
|
|
|
{
|
|
|
|
Log::error("Error: cap_set_flag() failed.");
|
2016-03-02 00:47:13 -06:00
|
|
|
std::exit(1);
|
2015-12-29 19:34:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cap_set_proc(caps) == -1)
|
|
|
|
{
|
|
|
|
Log::error("Error: cap_set_proc() failed.");
|
2016-03-02 00:47:13 -06:00
|
|
|
std::exit(1);
|
2015-12-29 19:34:53 -06:00
|
|
|
}
|
|
|
|
|
2016-02-29 04:12:18 -06:00
|
|
|
capText = cap_to_text(caps, nullptr);
|
2015-12-29 19:34:53 -06:00
|
|
|
Log::info("Capabilities now: " + std::string(capText));
|
|
|
|
cap_free(capText);
|
|
|
|
|
|
|
|
cap_free(caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|