00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include <sbuild/sbuild-chroot-plain.h>
00023 #include <sbuild/sbuild-log.h>
00024 #include <sbuild/sbuild-parse-error.h>
00025
00026 #include "dchroot-dsa-chroot-config.h"
00027
00028 #include <cerrno>
00029 #include <cstdlib>
00030 #include <cstring>
00031 #include <iostream>
00032
00033 #include <boost/format.hpp>
00034
00035 using std::endl;
00036 using sbuild::keyfile;
00037 using boost::format;
00038 using namespace dchroot_dsa;
00039
00040 chroot_config::chroot_config ():
00041 sbuild::chroot_config()
00042 {
00043 }
00044
00045 chroot_config::chroot_config (std::string const& file,
00046 bool active):
00047 sbuild::chroot_config(file, active)
00048 {
00049 }
00050
00051 chroot_config::~chroot_config ()
00052 {
00053 }
00054
00055 void
00056 chroot_config::parse_data (std::istream& stream,
00057 bool active)
00058 {
00059 active = false;
00060
00061 size_t linecount = 0;
00062 std::string line;
00063 std::string chroot_name;
00064 std::string chroot_location;
00065
00066 sbuild::keyfile kconfig;
00067
00068 while (std::getline(stream, line))
00069 {
00070 linecount++;
00071
00072 if (line[0] == '#')
00073 {
00074
00075 }
00076 else if (line.length() == 0)
00077 {
00078
00079 }
00080 else
00081 {
00082 static const char *whitespace = " \t:;,";
00083
00084
00085 std::string::size_type cstart = line.find_first_not_of(whitespace);
00086 std::string::size_type cend = line.find_first_of(whitespace, cstart);
00087
00088
00089 std::string::size_type lstart = line.find_first_not_of(whitespace,
00090 cend);
00091 std::string::size_type lend = line.find_first_of(whitespace, lstart);
00092
00093 if (cstart == std::string::npos)
00094 throw keyfile::error(linecount, keyfile::INVALID_LINE, line);
00095
00096 std::string chroot_name = line.substr(cstart, cend - cstart);
00097
00098 std::string location;
00099 if (lstart != std::string::npos)
00100 location = line.substr(lstart, lend - lstart);
00101
00102
00103 sbuild::string_list users;
00104 if (lend != std::string::npos)
00105 users = sbuild::split_string(line.substr(lend), whitespace);
00106
00107
00108 if (kconfig.has_group(chroot_name))
00109 throw keyfile::error(linecount, keyfile::DUPLICATE_GROUP,
00110 chroot_name);
00111 else
00112 kconfig.set_group(chroot_name, "", linecount);
00113
00114 kconfig.set_value(chroot_name, "type", "plain", "", linecount);
00115
00116
00117 format fmt(_("%1% chroot (dchroot-dsa compatibility)"));
00118 fmt % chroot_name;
00119
00120 kconfig.set_value(chroot_name, "description", fmt, "", linecount);
00121
00122 if (lstart != std::string::npos)
00123 kconfig.set_value(chroot_name, "location", location, "", linecount);
00124
00125 kconfig.set_list_value(chroot_name, "users",
00126 users.begin(), users.end(),
00127 "", linecount);
00128 }
00129 }
00130
00131 load_keyfile(kconfig, active);
00132 }