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-chroot-file.h"
00023 #include "sbuild-format-detail.h"
00024 #include "sbuild-lock.h"
00025
00026 #include <cerrno>
00027 #include <cstring>
00028
00029 #include <sys/types.h>
00030 #include <sys/stat.h>
00031 #include <sys/sysmacros.h>
00032 #include <unistd.h>
00033
00034 #include <boost/format.hpp>
00035
00036 using boost::format;
00037 using namespace sbuild;
00038
00039 chroot_file::chroot_file ():
00040 chroot(),
00041 chroot_source(),
00042 file(),
00043 repack(false)
00044 {
00045 set_run_setup_scripts(true);
00046 set_run_exec_scripts(true);
00047 }
00048
00049 chroot_file::~chroot_file ()
00050 {
00051 }
00052
00053 sbuild::chroot::ptr
00054 chroot_file::clone () const
00055 {
00056 return ptr(new chroot_file(*this));
00057 }
00058
00059 sbuild::chroot::ptr
00060 chroot_file::clone_source () const
00061 {
00062 chroot_file *clone_file = new chroot_file(*this);
00063 ptr clone(clone_file);
00064
00065 chroot_source::clone_source_setup(clone);
00066 clone_file->repack = true;
00067
00068 return clone;
00069 }
00070
00071 std::string const&
00072 chroot_file::get_file () const
00073 {
00074 return this->file;
00075 }
00076
00077 void
00078 chroot_file::set_file (std::string const& file)
00079 {
00080 if (!is_absname(file))
00081 throw error(file, FILE_ABS);
00082
00083 this->file = file;
00084 }
00085
00086 bool
00087 chroot_file::get_file_repack () const
00088 {
00089 return this->repack;
00090 }
00091
00092 void
00093 chroot_file::set_file_repack (bool repack)
00094 {
00095 this->repack = repack;
00096 }
00097
00098 std::string const&
00099 chroot_file::get_chroot_type () const
00100 {
00101 static const std::string type("file");
00102
00103 return type;
00104 }
00105
00106 void
00107 chroot_file::setup_env (environment& env)
00108 {
00109 chroot::setup_env(env);
00110 chroot_source::setup_env(env);
00111
00112 env.add("CHROOT_FILE", get_file());
00113 env.add("CHROOT_FILE_REPACK", this->repack);
00114 }
00115
00116 void
00117 chroot_file::setup_lock (chroot::setup_type type,
00118 bool lock,
00119 int status)
00120 {
00121
00122 if (type == SETUP_START && lock == true)
00123 {
00124 struct stat statbuf;
00125 if (stat(this->file.c_str(), &statbuf) < 0)
00126 throw error(this->file, FILE_STAT, strerror(errno));
00127
00128
00129 if (statbuf.st_uid != 0)
00130 throw error(this->file, FILE_OWNER);
00131 if (statbuf.st_mode & S_IWOTH)
00132 throw error(this->file, FILE_PERMS);
00133 if (!S_ISREG(statbuf.st_mode))
00134 throw error(this->file, FILE_NOTREG);
00135 }
00136
00137
00138
00139 if ((type == SETUP_START && lock == true) ||
00140 (type == SETUP_STOP && lock == false && status == 0))
00141 {
00142
00143 bool start = (type == SETUP_START);
00144 setup_session_info(start);
00145 }
00146 }
00147
00148 sbuild::chroot::session_flags
00149 chroot_file::get_session_flags () const
00150 {
00151 return SESSION_CREATE;
00152 }
00153
00154 void
00155 chroot_file::get_details (format_detail& detail) const
00156 {
00157 chroot::get_details(detail);
00158 chroot_source::get_details(detail);
00159
00160 if (!this->file.empty())
00161 detail
00162 .add(_("File"), get_file())
00163 .add(_("File Repack"), this->repack);
00164 }
00165
00166 void
00167 chroot_file::get_keyfile (keyfile& keyfile) const
00168 {
00169 chroot::get_keyfile(keyfile);
00170 chroot_source::get_keyfile(keyfile);
00171
00172 keyfile::set_object_value(*this, &chroot_file::get_file,
00173 keyfile, get_name(), "file");
00174
00175 if (get_active())
00176 keyfile::set_object_value(*this, &chroot_file::get_file_repack,
00177 keyfile, get_name(), "file-repack");
00178 }
00179
00180 void
00181 chroot_file::set_keyfile (keyfile const& keyfile)
00182 {
00183 chroot::set_keyfile(keyfile);
00184 chroot_source::set_keyfile(keyfile);
00185
00186 keyfile::get_object_value(*this, &chroot_file::set_file,
00187 keyfile, get_name(), "file",
00188 keyfile::PRIORITY_REQUIRED);
00189
00190 keyfile::get_object_value(*this, &chroot_file::set_file_repack,
00191 keyfile, get_name(), "file-repack",
00192 get_active() ?
00193 keyfile::PRIORITY_REQUIRED :
00194 keyfile::PRIORITY_DISALLOWED);
00195 }