[24167] | 1 | /* Copyright © 2005-2007 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/sbuild-chroot-plain.h> |
---|
| 22 | #include <sbuild/sbuild-log.h> |
---|
| 23 | #include <sbuild/sbuild-parse-error.h> |
---|
| 24 | |
---|
| 25 | #include "dchroot-dsa-chroot-config.h" |
---|
| 26 | |
---|
| 27 | #include <cerrno> |
---|
| 28 | #include <cstdlib> |
---|
| 29 | #include <cstring> |
---|
| 30 | #include <iostream> |
---|
| 31 | |
---|
| 32 | #include <boost/format.hpp> |
---|
| 33 | |
---|
| 34 | using std::endl; |
---|
| 35 | using sbuild::_; |
---|
| 36 | using sbuild::keyfile; |
---|
| 37 | using boost::format; |
---|
| 38 | using namespace dchroot_dsa; |
---|
| 39 | |
---|
| 40 | chroot_config::chroot_config (): |
---|
| 41 | sbuild::chroot_config() |
---|
| 42 | { |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | chroot_config::chroot_config (std::string const& file, |
---|
| 46 | bool active): |
---|
| 47 | sbuild::chroot_config(file, active) |
---|
| 48 | { |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | chroot_config::~chroot_config () |
---|
| 52 | { |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void |
---|
| 56 | chroot_config::parse_data (std::istream& stream, |
---|
| 57 | bool active) |
---|
| 58 | { |
---|
| 59 | active = false; // dchroot does not support sessions. |
---|
| 60 | |
---|
| 61 | size_t linecount = 0; |
---|
| 62 | std::string line; |
---|
| 63 | std::string chroot_name; |
---|
| 64 | std::string chroot_location; |
---|
| 65 | |
---|
| 66 | sbuild::keyfile kconfig; |
---|
| 67 | |
---|
| 68 | while (std::getline(stream, line)) |
---|
| 69 | { |
---|
| 70 | linecount++; |
---|
| 71 | |
---|
| 72 | if (line[0] == '#') |
---|
| 73 | { |
---|
| 74 | // Comment line; do nothing. |
---|
| 75 | } |
---|
| 76 | else if (line.length() == 0) |
---|
| 77 | { |
---|
| 78 | // Empty line; do nothing. |
---|
| 79 | } |
---|
| 80 | else // Item |
---|
| 81 | { |
---|
| 82 | static const char *whitespace = " \t:;,"; |
---|
| 83 | |
---|
| 84 | // Get chroot name |
---|
| 85 | std::string::size_type cstart = line.find_first_not_of(whitespace); |
---|
| 86 | std::string::size_type cend = line.find_first_of(whitespace, cstart); |
---|
| 87 | |
---|
| 88 | // Get chroot location |
---|
| 89 | std::string::size_type lstart = line.find_first_not_of(whitespace, |
---|
| 90 | cend); |
---|
| 91 | std::string::size_type lend = line.find_first_of(whitespace, lstart); |
---|
| 92 | |
---|
| 93 | if (cstart == std::string::npos) |
---|
| 94 | throw keyfile::error(linecount, keyfile::INVALID_LINE, line); |
---|
| 95 | |
---|
| 96 | std::string chroot_name = line.substr(cstart, cend - cstart); |
---|
| 97 | |
---|
| 98 | std::string location; |
---|
| 99 | if (lstart != std::string::npos) |
---|
| 100 | location = line.substr(lstart, lend - lstart); |
---|
| 101 | |
---|
| 102 | // DSA dchroot parses valid users. |
---|
| 103 | sbuild::string_list users; |
---|
| 104 | if (lend != std::string::npos) |
---|
| 105 | users = sbuild::split_string(line.substr(lend), whitespace); |
---|
| 106 | |
---|
| 107 | // Add details to keyfile. |
---|
| 108 | if (kconfig.has_group(chroot_name)) |
---|
| 109 | throw keyfile::error(linecount, keyfile::DUPLICATE_GROUP, |
---|
| 110 | chroot_name); |
---|
| 111 | else |
---|
| 112 | kconfig.set_group(chroot_name, "", linecount); |
---|
| 113 | |
---|
| 114 | kconfig.set_value(chroot_name, "type", "plain", "", linecount); |
---|
| 115 | |
---|
| 116 | // TRANSLATORS: %1% = chroot name |
---|
| 117 | format fmt(_("%1% chroot (dchroot-dsa compatibility)")); |
---|
| 118 | fmt % chroot_name; |
---|
| 119 | |
---|
| 120 | kconfig.set_value(chroot_name, "description", fmt, "", linecount); |
---|
| 121 | |
---|
| 122 | if (lstart != std::string::npos) |
---|
| 123 | kconfig.set_value(chroot_name, "location", location, "", linecount); |
---|
| 124 | |
---|
| 125 | kconfig.set_list_value(chroot_name, "users", |
---|
| 126 | users.begin(), users.end(), |
---|
| 127 | "", linecount); |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | load_keyfile(kconfig, active); |
---|
| 132 | } |
---|