lxcpp: Switch on serialization from libConfig
[platform/core/security/vasum.git] / libs / lxcpp / attach / attach-config.hpp
1 /*
2  *  Copyright (C) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License version 2.1 as published by the Free Software Foundation.
7  *
8  *  This library is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  *  Lesser General Public License for more details.
12  *
13  *  You should have received a copy of the GNU Lesser General Public
14  *  License along with this library; if not, write to the Free Software
15  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17
18 /**
19  * @file
20  * @author  Jan Olszak (j.olszak@samsung.com)
21  * @brief   Internal structure sent between Attach command and AttachHelper
22  */
23
24 #ifndef LXCPP_ATTACH_ATTACH_CONFIG_HPP
25 #define LXCPP_ATTACH_ATTACH_CONFIG_HPP
26
27 #include "lxcpp/namespace.hpp"
28
29 #include <config/config.hpp>
30 #include <config/fields.hpp>
31
32 #include <sys/types.h>
33
34 #include <string>
35 #include <vector>
36
37 namespace lxcpp {
38
39 struct AttachConfig {
40
41     /// Arguments passed by user, argv[0] is the binary's path in container
42     std::vector<std::string> argv;
43
44     /// PID of the container's init process
45     pid_t initPid;
46
47     /// Namespaces to which we'll attach
48     std::vector<Namespace> namespaces;
49
50     /// User ID to set
51     uid_t uid;
52
53     /// Group ID to set
54     gid_t gid;
55
56     /// PTS that will become the control terminal for the attached process
57     int ttyFD;
58
59     /// Supplementary groups to set
60     std::vector<gid_t> supplementaryGids;
61
62     /// Mask of capabilities that will be available
63     int capsToKeep;
64
65     /// Work directory for the attached process
66     std::string workDirInContainer;
67
68     /// Environment variables that will be kept
69     std::vector<std::string> envToKeep;
70
71     /// Environment variables that will be set/updated for the attached process
72     std::vector<std::pair<std::string, std::string>> envToSet;
73
74     AttachConfig() = default;
75
76     AttachConfig(const std::vector<std::string>& argv,
77                  const pid_t initPid,
78                  const std::vector<Namespace>& namespaces,
79                  const uid_t uid,
80                  const gid_t gid,
81                  const std::vector<gid_t>& supplementaryGids,
82                  const int capsToKeep,
83                  const std::string& workDirInContainer,
84                  const std::vector<std::string>& envToKeep,
85                  const std::vector<std::pair<std::string, std::string>>& envToSet)
86         : argv(argv),
87           initPid(initPid),
88           namespaces(namespaces),
89           uid(uid),
90           gid(gid),
91           ttyFD(-1),
92           supplementaryGids(supplementaryGids),
93           capsToKeep(capsToKeep),
94           workDirInContainer(workDirInContainer),
95           envToKeep(envToKeep),
96           envToSet(envToSet)
97     {}
98
99     CONFIG_REGISTER
100     (
101         //TODO: Uncomment and fix cstring serialization
102         argv,
103         initPid,
104         namespaces,
105         uid,
106         gid,
107         ttyFD,
108         supplementaryGids,
109         capsToKeep,
110         workDirInContainer,
111         envToKeep,
112         envToSet
113     )
114 };
115
116 } // namespace lxcpp
117
118 #endif // LXCPP_ATTACH_ATTACH_CONFIG_HPP