Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
environment.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Michal Witanowski <m.witanowski@samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
25 #ifndef COMMON_UTILS_ENVIRONMENT_HPP
26 #define COMMON_UTILS_ENVIRONMENT_HPP
27 
28 #include <string>
29 #include <vector>
30 #include <functional>
31 #include <sys/types.h>
32 
33 
34 namespace utils {
35 
36 
40 bool setSuppGroups(const std::vector<std::string>& groups);
41 
45 bool dropRoot(uid_t uid, gid_t gid, const std::vector<unsigned int>& caps);
46 
52 bool launchAsRoot(const std::function<bool()>& func);
53 
57 bool joinToNs(int nsPid, int ns);
58 
62 int passNamespacedFd(int nsPid, int ns, const std::function<int()>& fdFactory);
63 
64 } // namespace utils
65 
66 
67 #endif // COMMON_UTILS_ENVIRONMENT_HPP
bool dropRoot(uid_t uid, gid_t gid, const std::vector< unsigned int > &caps)
Set effective and permitted capabilities on the current process and drop root privileges.
Definition: environment.cpp:195
bool setSuppGroups(const std::vector< std::string > &groups)
Set supplementary groups to the current process.
Definition: environment.cpp:171
int passNamespacedFd(int nsPid, int ns, const std::function< int()> &fdFactory)
Pass file descriptor from namespace of some process.
Definition: environment.cpp:347
bool launchAsRoot(const std::function< bool()> &func)
Launch func as root user.
Definition: environment.cpp:304
bool joinToNs(int nsPid, int ns)
Join to namespace.
Definition: environment.cpp:324