1 | /* Copyright © 2005-2009 Roger Leigh <rleigh@debian.org> |
---|
2 | * |
---|
3 | * schroot is free software: you can redistribute it and/or modify it |
---|
4 | * under the terms of the GNU General Public License as published by |
---|
5 | * the Free Software Foundation, either version 3 of the License, or |
---|
6 | * (at your option) any later version. |
---|
7 | * |
---|
8 | * schroot is distributed in the hope that it will be useful, but |
---|
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
11 | * General Public License for more details. |
---|
12 | * |
---|
13 | * You should have received a copy of the GNU General Public License |
---|
14 | * along with this program. If not, see |
---|
15 | * <http://www.gnu.org/licenses/>. |
---|
16 | * |
---|
17 | *********************************************************************/ |
---|
18 | |
---|
19 | #include <config.h> |
---|
20 | |
---|
21 | #include "sbuild-chroot.h" |
---|
22 | #include "sbuild-chroot-facet-source-clonable.h" |
---|
23 | #include "sbuild-chroot-facet-source.h" |
---|
24 | |
---|
25 | #include <cassert> |
---|
26 | |
---|
27 | using boost::format; |
---|
28 | using std::endl; |
---|
29 | using namespace sbuild; |
---|
30 | |
---|
31 | chroot_facet_source_clonable::chroot_facet_source_clonable (): |
---|
32 | chroot_facet(), |
---|
33 | source_users(), |
---|
34 | source_groups(), |
---|
35 | source_root_users(), |
---|
36 | source_root_groups() |
---|
37 | { |
---|
38 | } |
---|
39 | |
---|
40 | chroot_facet_source_clonable::~chroot_facet_source_clonable () |
---|
41 | { |
---|
42 | } |
---|
43 | |
---|
44 | chroot_facet_source_clonable::ptr |
---|
45 | chroot_facet_source_clonable::create () |
---|
46 | { |
---|
47 | return ptr(new chroot_facet_source_clonable()); |
---|
48 | } |
---|
49 | |
---|
50 | chroot_facet::ptr |
---|
51 | chroot_facet_source_clonable::clone () const |
---|
52 | { |
---|
53 | return ptr(new chroot_facet_source_clonable(*this)); |
---|
54 | } |
---|
55 | |
---|
56 | std::string const& |
---|
57 | chroot_facet_source_clonable::get_name () const |
---|
58 | { |
---|
59 | static const std::string name("source-clonable"); |
---|
60 | |
---|
61 | return name; |
---|
62 | } |
---|
63 | |
---|
64 | void |
---|
65 | chroot_facet_source_clonable::clone_source_setup (chroot::ptr& clone) const |
---|
66 | { |
---|
67 | clone->set_name(clone->get_name() + "-source"); |
---|
68 | clone->set_description |
---|
69 | (clone->get_description() + ' ' + _("(source chroot)")); |
---|
70 | clone->set_original(false); |
---|
71 | clone->set_users(this->get_source_users()); |
---|
72 | clone->set_groups(this->get_source_groups()); |
---|
73 | clone->set_root_users(this->get_source_root_users()); |
---|
74 | clone->set_root_groups(this->get_source_root_groups()); |
---|
75 | string_list const& aliases = clone->get_aliases(); |
---|
76 | string_list source_aliases; |
---|
77 | for (string_list::const_iterator alias = aliases.begin(); |
---|
78 | alias != aliases.end(); |
---|
79 | ++alias) |
---|
80 | source_aliases.push_back(*alias + "-source"); |
---|
81 | clone->set_aliases(source_aliases); |
---|
82 | |
---|
83 | clone->remove_facet<chroot_facet_source_clonable>(); |
---|
84 | clone->add_facet(chroot_facet_source::create()); |
---|
85 | } |
---|
86 | |
---|
87 | string_list const& |
---|
88 | chroot_facet_source_clonable::get_source_users () const |
---|
89 | { |
---|
90 | return this->source_users; |
---|
91 | } |
---|
92 | |
---|
93 | void |
---|
94 | chroot_facet_source_clonable::set_source_users (string_list const& source_users) |
---|
95 | { |
---|
96 | this->source_users = source_users; |
---|
97 | } |
---|
98 | |
---|
99 | string_list const& |
---|
100 | chroot_facet_source_clonable::get_source_groups () const |
---|
101 | { |
---|
102 | return this->source_groups; |
---|
103 | } |
---|
104 | |
---|
105 | void |
---|
106 | chroot_facet_source_clonable::set_source_groups (string_list const& source_groups) |
---|
107 | { |
---|
108 | this->source_groups = source_groups; |
---|
109 | } |
---|
110 | |
---|
111 | string_list const& |
---|
112 | chroot_facet_source_clonable::get_source_root_users () const |
---|
113 | { |
---|
114 | return this->source_root_users; |
---|
115 | } |
---|
116 | |
---|
117 | void |
---|
118 | chroot_facet_source_clonable::set_source_root_users (string_list const& users) |
---|
119 | { |
---|
120 | this->source_root_users = users; |
---|
121 | } |
---|
122 | |
---|
123 | string_list const& |
---|
124 | chroot_facet_source_clonable::get_source_root_groups () const |
---|
125 | { |
---|
126 | return this->source_root_groups; |
---|
127 | } |
---|
128 | |
---|
129 | void |
---|
130 | chroot_facet_source_clonable::set_source_root_groups (string_list const& groups) |
---|
131 | { |
---|
132 | this->source_root_groups = groups; |
---|
133 | } |
---|
134 | |
---|
135 | void |
---|
136 | chroot_facet_source_clonable::setup_env (chroot const& chroot, |
---|
137 | environment& env) const |
---|
138 | { |
---|
139 | } |
---|
140 | |
---|
141 | chroot::session_flags |
---|
142 | chroot_facet_source_clonable::get_session_flags (chroot const& chroot) const |
---|
143 | { |
---|
144 | // Cloning is only possible for non-source and inactive chroots. |
---|
145 | if (chroot.get_active()) |
---|
146 | return chroot::SESSION_NOFLAGS; |
---|
147 | else |
---|
148 | return chroot::SESSION_CLONE; |
---|
149 | } |
---|
150 | |
---|
151 | void |
---|
152 | chroot_facet_source_clonable::get_details (chroot const& chroot, |
---|
153 | format_detail& detail) const |
---|
154 | { |
---|
155 | detail |
---|
156 | .add(_("Source Users"), get_source_users()) |
---|
157 | .add(_("Source Groups"), get_source_groups()) |
---|
158 | .add(_("Source Root Users"), get_source_root_users()) |
---|
159 | .add(_("Source Root Groups"), get_source_root_groups()); |
---|
160 | } |
---|
161 | |
---|
162 | void |
---|
163 | chroot_facet_source_clonable::get_keyfile (chroot const& chroot, |
---|
164 | keyfile& keyfile) const |
---|
165 | { |
---|
166 | keyfile::set_object_list_value(*this, &chroot_facet_source_clonable::get_source_users, |
---|
167 | keyfile, chroot.get_keyfile_name(), |
---|
168 | "source-users"); |
---|
169 | |
---|
170 | keyfile::set_object_list_value(*this, &chroot_facet_source_clonable::get_source_groups, |
---|
171 | keyfile, chroot.get_keyfile_name(), |
---|
172 | "source-groups"); |
---|
173 | |
---|
174 | keyfile::set_object_list_value(*this, &chroot_facet_source_clonable::get_source_root_users, |
---|
175 | keyfile, chroot.get_keyfile_name(), |
---|
176 | "source-root-users"); |
---|
177 | |
---|
178 | keyfile::set_object_list_value(*this, &chroot_facet_source_clonable::get_source_root_groups, |
---|
179 | keyfile, chroot.get_keyfile_name(), |
---|
180 | "source-root-groups"); |
---|
181 | } |
---|
182 | |
---|
183 | void |
---|
184 | chroot_facet_source_clonable::set_keyfile (chroot& chroot, |
---|
185 | keyfile const& keyfile, |
---|
186 | string_list& used_keys) |
---|
187 | { |
---|
188 | keyfile::get_object_list_value(*this, &chroot_facet_source_clonable::set_source_users, |
---|
189 | keyfile, chroot.get_keyfile_name(), |
---|
190 | "source-users", |
---|
191 | keyfile::PRIORITY_OPTIONAL); |
---|
192 | used_keys.push_back("source_clonable-users"); |
---|
193 | |
---|
194 | keyfile::get_object_list_value(*this, &chroot_facet_source_clonable::set_source_groups, |
---|
195 | keyfile, chroot.get_keyfile_name(), |
---|
196 | "source-groups", |
---|
197 | keyfile::PRIORITY_OPTIONAL); |
---|
198 | used_keys.push_back("source-groups"); |
---|
199 | |
---|
200 | keyfile::get_object_list_value(*this, &chroot_facet_source_clonable::set_source_root_users, |
---|
201 | keyfile, chroot.get_keyfile_name(), |
---|
202 | "source-root-users", |
---|
203 | keyfile::PRIORITY_OPTIONAL); |
---|
204 | used_keys.push_back("source-root-users"); |
---|
205 | |
---|
206 | keyfile::get_object_list_value(*this, &chroot_facet_source_clonable::set_source_root_groups, |
---|
207 | keyfile, chroot.get_keyfile_name(), |
---|
208 | "source-root-groups", |
---|
209 | keyfile::PRIORITY_OPTIONAL); |
---|
210 | used_keys.push_back("source-root-groups"); |
---|
211 | } |
---|