summaryrefslogtreecommitdiff
path: root/bin/csbuild
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2007-04-01 21:45:32 +0000
committerRoger Leigh <rleigh@debian.org>2007-04-01 21:45:32 +0000
commit58187d2accabcaeba61a36eb7d5243e752856ac4 (patch)
tree968b0d380782e3eebf8b3f11560e7051a16fe312 /bin/csbuild
parent04462fcccc7a5537a6a7c7f9407b48a2ac1167de (diff)
downloadschroot-58187d2accabcaeba61a36eb7d5243e752856ac4.tar.gz
* Move schroot, dchroot, dchroot and csbuild to a new
subdirectory, bin. * bin/*/Makefile.am (LOCAL_CXXFLAGS): Add -I$(top_srcdir)/bin. * bin/Makefile.am: New file. (SUBDIRS): schroot dchroot dchroot-dsa csbuild * configure.ac: Use new file locations. * doc/schroot.dox.in: Use new source locations. Disable call graph.
Diffstat (limited to 'bin/csbuild')
-rw-r--r--bin/csbuild/Makefile.am61
-rw-r--r--bin/csbuild/csbuild-main-base.cc148
-rw-r--r--bin/csbuild/csbuild-main-base.h78
-rw-r--r--bin/csbuild/csbuild-main.cc64
-rw-r--r--bin/csbuild/csbuild-main.h57
-rw-r--r--bin/csbuild/csbuild-options.cc105
-rw-r--r--bin/csbuild/csbuild-options.h58
-rw-r--r--bin/csbuild/csbuild-session-base.cc87
-rw-r--r--bin/csbuild/csbuild-session-base.h94
-rw-r--r--bin/csbuild/csbuild.1.in317
-rw-r--r--bin/csbuild/csbuild.cc45
11 files changed, 1114 insertions, 0 deletions
diff --git a/bin/csbuild/Makefile.am b/bin/csbuild/Makefile.am
new file mode 100644
index 00000000..2c4a9e62
--- /dev/null
+++ b/bin/csbuild/Makefile.am
@@ -0,0 +1,61 @@
+# schroot Makefile template
+#
+#
+# Copyright © 2004-2006 Roger Leigh <rleigh@debian.org>
+#
+# schroot is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# schroot is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#####################################################################
+
+include $(top_srcdir)/scripts/global.mk
+
+LOCAL_CXXFLAGS = $(SCHROOT_CFLAGS) -I$(top_srcdir)/bin
+
+DEFS = -DLOCALEDIR=\"$(localedir)\" -D_GNU_SOURCE
+
+if BUILD_CSBUILD
+noinst_LTLIBRARIES = libcsbuild.la
+csbuild = csbuild
+endif
+
+bin_PROGRAMS = $(csbuild)
+
+libcsbuild_la_SOURCES = \
+ csbuild-main-base.h \
+ csbuild-main-base.cc \
+ csbuild-session-base.h \
+ csbuild-session-base.cc
+libcsbuild_la_LIBADD = $(top_builddir)/bin/schroot/libschroot.la
+
+csbuild_SOURCES = \
+ csbuild-options.h \
+ csbuild-options.cc \
+ csbuild-main.h \
+ csbuild-main.cc \
+ csbuild.cc
+csbuild_LDADD = libcsbuild.la
+
+if BUILD_CSBUILD
+csbuild_mans = csbuild.1
+endif
+
+man_MANS = $(csbuild_mans)
+
+install-exec-hook:
+# Install setuid root.
+ if [ -f "$(DESTDIR)$(bindir)/csbuild" ]; then \
+ chmod 4755 "$(DESTDIR)$(bindir)/csbuild"; \
+ fi
diff --git a/bin/csbuild/csbuild-main-base.cc b/bin/csbuild/csbuild-main-base.cc
new file mode 100644
index 00000000..01243d09
--- /dev/null
+++ b/bin/csbuild/csbuild-main-base.cc
@@ -0,0 +1,148 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include "csbuild-main.h"
+
+#include <cstdlib>
+#include <iostream>
+#include <locale>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include <boost/format.hpp>
+
+#include <syslog.h>
+
+using std::endl;
+using boost::format;
+using sbuild::_;
+using schroot::options_base;
+using namespace csbuild;
+
+main_base::main_base (std::string const& program_name,
+ std::string const& program_usage,
+ schroot::options_base::ptr& options):
+ schroot::main_base(program_name, program_usage, options),
+ use_csbuild_conf(false)
+{
+}
+
+main_base::~main_base ()
+{
+}
+
+void
+main_base::action_config ()
+{
+ std::cout << "# "
+ // TRANSLATORS: %1% = program name
+ // TRANSLATORS: %2% = program version
+ // TRANSLATORS: %3% = current date
+ << format(_("schroot configuration generated by %1% %2% on %3%"))
+ % this->program_name % VERSION % sbuild::date(time(0))
+ << endl;
+ if (this->use_csbuild_conf)
+ {
+ // Help text at head of new config.
+ std::cout << "# " << endl
+ << "# "
+ // TODO: Quote "users" and "groups".
+ // TRANSLATORS: Do not translate "users" and "groups";
+ // these are keywords used in the configuration file.
+ << _("To allow users access to the chroots, use the users or groups keys.") << endl;
+ std::cout << "# "
+ // TODO: Quote "root-users" and "root-groups".
+ // TRANSLATORS: Do not translate "root-users" and
+ // "root-groups"; these are keywords used in the
+ // configuration file.
+ << _("To allow password-less root access, use the root-users or root-groups keys.") << endl;
+ std::cout << "# "
+ // TRANSLATORS: %1% = file
+ << format(_("Remove '%1%' to use the new configuration."))
+ % CSBUILD_CONF
+ << endl;
+ }
+ std::cout << endl;
+ this->config->print_chroot_config(this->chroots, std::cout);
+}
+
+void
+main_base::action_list ()
+{
+ this->config->print_chroot_list_simple(std::cout);
+}
+
+void
+main_base::compat_check ()
+{
+ if (this->options->verbose)
+ {
+ sbuild::log_warning()
+ // TRANSLATORS: %1% = program name
+ << format(_("Running schroot in %1% compatibility mode"))
+ % this->program_name
+ << endl;
+ sbuild::log_info()
+ // TRANSLATORS: "full capabilities" in this context means "all
+ // features"
+ << _("Run \"schroot\" for full capabilities")
+ << endl;
+ }
+}
+
+void
+main_base::check_csbuild_conf ()
+{
+ this->use_csbuild_conf = false;
+ struct stat statbuf;
+ if (stat(CSBUILD_CONF, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
+ {
+ this->use_csbuild_conf = true;
+
+ if (this->options->verbose)
+ {
+ sbuild::log_warning()
+ // TRANSLATORS: %1% = program name
+ // TRANSLATORS: %2% = configuration file
+ << format(_("Using %1% configuration file: '%2%'"))
+ % this->program_name % CSBUILD_CONF
+ << endl;
+ sbuild::log_info()
+ << format(_("Run \"%1%\""))
+ % "csbuild --config >> " SCHROOT_CONF
+ << endl;
+ sbuild::log_info()
+ << _("to migrate to a schroot configuration.")
+ << endl;
+ sbuild::log_info()
+ << format(_("Edit '%1%' to add appropriate user and/or group access."))
+ % SCHROOT_CONF
+ << endl;
+ sbuild::log_info()
+ << format(_("Remove '%1%' to use the new configuration."))
+ % CSBUILD_CONF
+ << endl;
+ }
+ }
+}
diff --git a/bin/csbuild/csbuild-main-base.h b/bin/csbuild/csbuild-main-base.h
new file mode 100644
index 00000000..d6a73322
--- /dev/null
+++ b/bin/csbuild/csbuild-main-base.h
@@ -0,0 +1,78 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#ifndef CSBUILD_MAIN_BASE_H
+#define CSBUILD_MAIN_BASE_H
+
+#include <schroot/schroot-main-base.h>
+
+namespace csbuild
+{
+
+ /**
+ * Frontend base class for csbuild. This class contains frontend
+ * functionality common to csbuild and csbuild-dsa.
+ */
+ class main_base : public schroot::main_base
+ {
+ public:
+ /**
+ * The constructor.
+ *
+ * @param program_name the program name.
+ * @param program_usage the program usage message.
+ * @param options the command-line options to use.
+ */
+ main_base (std::string const& program_name,
+ std::string const& program_usage,
+ schroot::options_base::ptr& options);
+
+ /// The destructor.
+ virtual ~main_base ();
+
+ protected:
+ /**
+ * Check csbuild.conf exists. If it exists, and using verbose
+ * messages, print a warning about upgrading to schroot.conf.
+ */
+ void
+ check_csbuild_conf();
+
+ virtual void
+ compat_check ();
+
+ virtual void
+ action_config ();
+
+ virtual void
+ action_list ();
+
+ /// Use csbuild.conf as the configuration file.
+ bool use_csbuild_conf;
+ };
+
+}
+
+#endif /* CSBUILD_MAIN_BASE_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */
diff --git a/bin/csbuild/csbuild-main.cc b/bin/csbuild/csbuild-main.cc
new file mode 100644
index 00000000..259f3ce2
--- /dev/null
+++ b/bin/csbuild/csbuild-main.cc
@@ -0,0 +1,64 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include "csbuild-main.h"
+
+#include <cstdlib>
+#include <iostream>
+#include <locale>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <termios.h>
+#include <unistd.h>
+
+#include <boost/format.hpp>
+
+using std::endl;
+using sbuild::_;
+using boost::format;
+using schroot::options_base;
+using namespace csbuild;
+
+main::main (schroot::options_base::ptr& options):
+ main_base("csbuild",
+ // TRANSLATORS: '...' is an ellipsis e.g. U+2026, and '-'
+ // is an em-dash.
+ _("[OPTION...] [COMMAND] - run command or shell in a chroot"),
+ options)
+{
+}
+
+main::~main ()
+{
+}
+
+void
+main::create_session(sbuild::session::operation sess_op)
+{
+ sbuild::log_debug(sbuild::DEBUG_INFO) << "Creating schroot session" << endl;
+
+ this->session = sbuild::session::ptr
+ (new sbuild::session("schroot", this->config, sess_op, this->chroots));
+
+ if (!this->options->user.empty())
+ this->session->set_user(this->options->user);
+}
diff --git a/bin/csbuild/csbuild-main.h b/bin/csbuild/csbuild-main.h
new file mode 100644
index 00000000..5fbd5d21
--- /dev/null
+++ b/bin/csbuild/csbuild-main.h
@@ -0,0 +1,57 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#ifndef CSBUILD_MAIN_H
+#define CSBUILD_MAIN_H
+
+#include <csbuild/csbuild-main-base.h>
+
+namespace csbuild
+{
+
+ /**
+ * Frontend for csbuild. This class is used to "run" csbuild.
+ */
+ class main : public csbuild::main_base
+ {
+ public:
+ /**
+ * The constructor.
+ *
+ * @param options the command-line options to use.
+ */
+ main (schroot::options_base::ptr& options);
+
+ /// The destructor.
+ virtual ~main ();
+
+ protected:
+ virtual void
+ create_session (sbuild::session::operation sess_op);
+ };
+
+}
+
+#endif /* CSBUILD_MAIN_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */
diff --git a/bin/csbuild/csbuild-options.cc b/bin/csbuild/csbuild-options.cc
new file mode 100644
index 00000000..0ef5e287
--- /dev/null
+++ b/bin/csbuild/csbuild-options.cc
@@ -0,0 +1,105 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include "csbuild-options.h"
+
+#include <cstdlib>
+#include <iostream>
+
+#include <boost/format.hpp>
+#include <boost/program_options.hpp>
+
+using std::endl;
+using sbuild::_;
+using boost::format;
+namespace opt = boost::program_options;
+using namespace csbuild;
+
+options::options ():
+ schroot::options_base()
+{
+}
+
+options::~options ()
+{
+}
+
+void
+options::add_options ()
+{
+ schroot::options_base::add_options();
+
+ general.add_options()
+ ("path,p", opt::value<std::string>(&this->chroot_path),
+ _("Print path to selected chroot"));
+
+ chroot.add_options()
+ ("all,a",
+ _("Select all chroots"));
+
+ chrootenv.add_options()
+ ("directory", opt::value<std::string>(&this->directory),
+ _("Directory to use"))
+ ("preserve-environment,d",
+ _("Preserve user environment"));
+}
+
+void
+options::check_options ()
+{
+ schroot::options_base::check_options();
+
+ if (vm.count("path"))
+ set_action(ACTION_LOCATION);
+
+ if (vm.count("all"))
+ {
+ this->all = false;
+ this->all_chroots = true;
+ this->all_sessions = false;
+ }
+
+ if (vm.count("preserve-environment"))
+ this->preserve = true;
+
+ if (this->quiet && this->verbose)
+ {
+ sbuild::log_warning()
+ << _("--quiet and --verbose may not be used at the same time")
+ << endl;
+ sbuild::log_info() << _("Using verbose output") << endl;
+ }
+
+ if (!this->chroots.empty() && all_used())
+ {
+ sbuild::log_warning()
+ << _("--chroot and --all may not be used at the same time")
+ << endl;
+ sbuild::log_info() << _("Using --chroots only") << endl;
+ this->all = this->all_chroots = this->all_sessions = false;
+ }
+
+ if (this->all == true)
+ {
+ this->all_chroots = true;
+ this->all_sessions = true;
+ }
+}
diff --git a/bin/csbuild/csbuild-options.h b/bin/csbuild/csbuild-options.h
new file mode 100644
index 00000000..18b648c7
--- /dev/null
+++ b/bin/csbuild/csbuild-options.h
@@ -0,0 +1,58 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#ifndef CSBUILD_OPTIONS_H
+#define CSBUILD_OPTIONS_H
+
+#include <schroot/schroot-options-base.h>
+
+namespace csbuild
+{
+
+ /**
+ * csbuild command-line options.
+ * @todo Replace with schroot::options_base.
+ */
+ class options : public schroot::options_base
+ {
+ public:
+ /// The constructor.
+ options ();
+
+ /// The destructor.
+ virtual ~options ();
+
+ protected:
+ virtual void
+ add_options ();
+
+ virtual void
+ check_options ();
+ };
+
+}
+
+#endif /* CSBUILD_OPTIONS_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */
+
diff --git a/bin/csbuild/csbuild-session-base.cc b/bin/csbuild/csbuild-session-base.cc
new file mode 100644
index 00000000..041b4a10
--- /dev/null
+++ b/bin/csbuild/csbuild-session-base.cc
@@ -0,0 +1,87 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include "csbuild-session-base.h"
+
+#include <cassert>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <memory>
+
+#include <unistd.h>
+
+#include <syslog.h>
+
+#include <boost/format.hpp>
+
+#include <uuid/uuid.h>
+
+using std::cout;
+using std::endl;
+using sbuild::_;
+using boost::format;
+using namespace csbuild;
+
+session_base::session_base (std::string const& service,
+ config_ptr& config,
+ operation operation,
+ sbuild::string_list const& chroots,
+ bool compat):
+ sbuild::session(service, config, operation, chroots),
+ compat(compat)
+{
+}
+
+session_base::~session_base ()
+{
+}
+
+bool
+session_base::get_compat () const
+{
+ return this->compat;
+}
+
+void
+session_base::set_compat (bool state)
+{
+ this->compat = state;
+}
+
+void
+session_base::run_impl ()
+{
+ if (get_ruid() != get_uid())
+ throw error(get_ruser(), get_user(), USER_SWITCH,
+ _("csbuild session restriction"));
+
+ sbuild::session::run_impl();
+}
+
+sbuild::string_list
+session_base::get_command_directories () const
+{
+ // csbuild does not treat logins differently from commands with
+ // respect to the cwd inside the chroot.
+ return get_login_directories();
+}
diff --git a/bin/csbuild/csbuild-session-base.h b/bin/csbuild/csbuild-session-base.h
new file mode 100644
index 00000000..50202df8
--- /dev/null
+++ b/bin/csbuild/csbuild-session-base.h
@@ -0,0 +1,94 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#ifndef CSBUILD_SESSION_BASE_H
+#define CSBUILD_SESSION_BASE_H
+
+#include <sbuild/sbuild-session.h>
+
+namespace csbuild
+{
+
+ /**
+ * Basic session handler for csbuild sessions.
+ *
+ * This class provides common session functionality for csbuild and
+ * csbuild-dsa, such as providing a schroot compatibility mode. It
+ * also prevents user switching when running sessions, which is
+ * forbidden.
+ */
+ class session_base : public sbuild::session
+ {
+ public:
+ /**
+ * The constructor.
+ *
+ * @param service the PAM service name.
+ * @param config a shared_ptr to the chroot configuration.
+ * @param operation the session operation to perform.
+ * @param chroots the chroots to act upon.
+ * @param compat true to enable full csbuild compatibility, or
+ * false to enable schroot compatiblity (permissions checks).
+ */
+ session_base (std::string const& service,
+ config_ptr& config,
+ operation operation,
+ sbuild::string_list const& chroots,
+ bool compat);
+
+ /// The destructor.
+ virtual ~session_base ();
+
+ /**
+ * Get the csbuild compatibility state.
+ *
+ * @returns the state.
+ */
+ bool
+ get_compat () const;
+
+ /**
+ * Set the csbuild compatibility state.
+ *
+ * @param state the csbuild compatibility state.
+ */
+ void
+ set_compat (bool state);
+
+ protected:
+ virtual void
+ run_impl ();
+
+ virtual sbuild::string_list
+ get_command_directories () const;
+
+ private:
+ /// csbuild compatibility enabled?
+ bool compat;
+ };
+
+}
+
+#endif /* CSBUILD_SESSION_BASE_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */
diff --git a/bin/csbuild/csbuild.1.in b/bin/csbuild/csbuild.1.in
new file mode 100644
index 00000000..6a36ed92
--- /dev/null
+++ b/bin/csbuild/csbuild.1.in
@@ -0,0 +1,317 @@
+.\" Copyright © 2005-2007 Roger Leigh <rleigh@debian.org>
+.\"
+.\" schroot is free software; you can redistribute it and/or modify it
+.\" under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation; either version 2 of the License, or
+.\" (at your option) any later version.
+.\"
+.\" schroot is distributed in the hope that it will be useful, but
+.\" WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+.\" General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" along with this program; if not, write to the Free Software
+.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+.\" MA 02111-1307 USA
+.TH CSBUILD 1 "@RELEASE_DATE@" "Version @VERSION@" "Debian sbuild"
+.SH NAME
+csbuild \[em] build debian packages from source
+.SH SYNOPSIS
+.B csbuild
+.RB [ \-h \[or] \-\-help " \[or] " \-V \[or] \-\-version
+.RB " \[or] " \-l \[or] \-\-list " \[or] " \-i \[or] \-\-info
+.RB " \[or] " \-\-config " \[or] " \-\-location ]
+.RB [ "\-\-directory=\fIdirectory\fP" ]
+.RB [ \-d \[or] \-\-preserve\-environment ]
+.RB [ \-q \[or] \-\-quiet " \[or] " \-v \[or] \-\-verbose ]
+.RB [ "\-c \fIchroot\fP" \[or] "\-\-chroot=\fIchroot\fP"
+.RB " \[or] " \-\-all ]
+.RB [ COMMAND " [ " ARG1 " [ " ARG2 " [ " ARGn ]]]]
+.SH DESCRIPTION
+\fBcsbuild\fP allows the user to run a command or a login shell in a chroot
+environment. If no command is specified, a login shell will be started in the
+user's home directory inside the chroot.
+.PP
+The command is one or more arguments which will be run in the user's default
+shell using its \fI\-c\fP option. As a result, shell code may be embedded
+in this argument. If multiple command options are used, they are concatenated
+together, separated by spaces. Users should be aware of the shell quoting
+issues this presents, and should use \fBschroot\fP if necessary, which does not
+have any quoting issues.
+.PP
+The directory the command or login shell is run in depends upon the context.
+See \fI\-\-directory\fP option below for a complete description.
+.PP
+This version of csbuild is a compatibility wrapper around the
+.BR schroot (1)
+program. It is provided for backward compatibility with the csbuild
+command-line options, but schroot is recommended for future use. See the
+section \[lq]\fIMigration\fP\[rq] below for help migrating an existing csbuild
+configuration to schroot. See the section \[lq]\fIIncompatibilities\fP\[rq]
+below for known incompatibilities with older versions of csbuild.
+.PP
+If no chroot is specified, the chroot name or alias \[oq]default\[cq] will be
+used as a fallback. If using the configuration in \fI@CSBUILD_CONF@\fP, the
+first chroot in the file is the default.
+.SH OPTIONS
+\fBcsbuild\fP accepts the following options:
+.SS Basic options
+.TP
+.BR \-h ", " \-\-help
+Show help summary.
+.TP
+.BR \-a ", " \-\-all
+Select all chroots.
+.TP
+.BR \-c ", " \-\-chroot=\fIchroot\fP
+Specify a chroot to use. This option may be used multiple times to specify
+more than one chroot, in which case its effect is similar to \fI\-\-all\fP.
+.TP
+.BR \-l ", " \-\-list
+List all available chroots.
+.TP
+.BR \-i ", " \-\-info
+Print detailed information about the specified chroots. Note that earlier
+versions of csbuild did not include this option.
+.TP
+.BR \-p ", " \-\-path
+Print location (path) of the specified chroots.
+.TP
+.BR \-\-config
+Print configuration of the specified chroots. This is useful for testing that
+the configuration in use is the same as the configuration file. Any comments
+in the original file will be missing. Note that earlier versions of csbuild
+did not include this option.
+.TP
+.BR \-d ", " \-\-directory=\fIdirectory\fP
+Change to \fIdirectory\fP inside the chroot before running the command or login
+shell. If \fIdirectory\fP is not available, csbuild will exit with an error
+status.
+.IP
+The default behaviour is as follows (all directory paths are inside the
+chroot). Unless the \fI\-\-preserve\-environment\fP option is used to preserve
+the environment, the login shell or command will run in the user's home
+directory, or \fI/\fP if the home directory is not available. When the
+\fI\-\-preserve\-environment\fP option is used, it will attempt to use the
+current working directory, again falling back to \fI/\fP if it is not
+accessible. If none of the directories are available, csbuild will exit with
+an error status.
+.TP
+.BR \-d ", " \-\-preserve\-environment
+Preserve the user's environment inside the chroot environment. The default is
+to use a clean environment; this option copies the entire user environment and
+sets it in the session.
+.TP
+.BR \-q ", " \-\-quiet
+Print only essential messages.
+.TP
+.BR \-v ", " \-\-verbose
+Print all messages. Note that earlier versions of csbuild did not include this
+option.
+.TP
+.BR \-V ", " \-\-version
+Print version information.
+.PP
+Note that earlier versions of csbuild did not provide long options.
+.SH CONFIGURATION
+The csbuild configuration file, \fI@CSBUILD_CONF@\fP, used by earlier versions
+of csbuild, has the following format:
+.IP \[bu]
+\[oq]#\[cq] starts a comment line.
+.IP \[bu]
+Blank lines are ignored.
+.IP \[bu]
+Chroot definitions are a single line containing an \f[CBI]identifier\fP,
+\f[CBI]path\fP, and an optional \f[CBI]personality\fP separated by whitespace.
+.IP \[bu]
+The first chroot is also the default chroot.
+.PP
+An example file:
+.PP
+.RS
+\f[CR]# Example comment\fP
+.br
+\f[CR]\fP
+.br
+\f[CR]sarge /srv/chroot/sarge\fP
+.br
+\f[CR]sid /srv/chroot/sid linux32\fP
+.br
+.RE
+.PP
+This file defines a chroot called \[oq]sarge\[cq], located at
+\fI/srv/chroot/sarge\fP, and a second chroot called \[oq]sid\[cq], located at
+\fI/srv/chroot/sid\fP. The second chroot uses the \[oq]linux32\[cq]
+personality, which allows a 32-bit chroot to be used on a 64-bit system.
+\[oq]sarge\[cq] is the default chroot, because it was listed first, which means
+if the \fI\-c\fP option is omitted this chroot will be used.
+.SH INCOMPATIBILITIES
+.SS Debian csbuild prior to version 0.99.0
+.IP \[bu]
+Log messages are worded and formatted differently.
+.IP \[bu]
+The parsing of \fI@CSBUILD_CONF@\fP uses a smaller list of allowed whitespace
+characters (space and tab), which may cause a parse error during tokenising if
+the file contains odd characters as separators, such as carriage returns,
+vertical tabs and form feeds.
+.IP \[bu]
+.BR su (1)
+is no longer used to run commands in the chroot; this is done by csbuild
+internally. This change may cause subtle differences. If you find an
+incompatibility, please report it so it may be corrected.
+.IP \[bu]
+csbuild provides a restricted subset of the functionality implemented by
+\fBschroot\fP, but is still schroot underneath. Thus csbuild is still subject
+to schroot security checking, including PAM authentication and authorisation,
+and session management, for example, and hence may behave slightly differently
+to older csbuild versions in some circumstances.
+.SS DSA csbuild
+Machines run by the Debian System Administrators for the Debian Project have a
+\fBcsbuild-dsa\fP package which provides an alternate csbuild implementation.
+.IP \[bu]
+All the above incompatibilities apply.
+.IP \[bu]
+This version of csbuild has incompatible command-line options, and while some
+of those options are supported or have equivalent options by a different name,
+the \fI\-c\fP option is not required to specify a chroot, and this version of
+csbuild cannot implement this behaviour in a backward-compatible manner
+(because if \fI\-c\fP is omitted, the default chroot is used). DSA csbuild
+uses the first non-option as the chroot to use, only allowing one chroot to be
+used at once.
+.IP \[bu]
+This version of csbuild has an incompatible format for \fIcsbuild.conf\fP.
+While the first two fields are the same, the remaining fields are an optional
+\f[CBI]users\fP, a list of users permitted to access the chroot, instead of the
+\f[CI]personality\fP field allowed by this version. If access restrictions are
+needed, please use \fI@SCHROOT_CONF@\fP and add the allowed users there, as
+shown in \[lq]\fIMigration\fP\[rq] below.
+.SH MIGRATION
+To migrate an existing \fBcsbuild\fP configuration to \fBschroot\fP, perform
+the following steps:
+.IP 1
+Dump the csbuild configuration in schroot keyfile format to
+\fI@SCHROOT_CONF@\fP.
+.PP
+.RS
+\f[CR]# \f[CB]csbuild --config >> @SCHROOT_CONF@
+.br
+.RE
+.PP
+.IP 2
+Edit \fI@SCHROOT_CONF@\fP to add access to the users and/or groups which are to
+be allowed to access the chroots, and make any other desired changes to the
+configuration. See
+.BR schroot.conf (5).
+.IP 3
+Remove \fI@CSBUILD_CONF@\fP, so that csbuild will subsequently use
+\fI@SCHROOT_CONF@\fP for its configuration.
+.SH EXAMPLES
+\f[CR]$ \f[CB]csbuild \-l\fP\fP
+.br
+\f[CR]Available chroots: sarge [default], sid\fP
+.br
+\f[CR]\fP
+.br
+\f[CR]$ \f[CB]csbuild \-p sid\fP\fP
+.br
+\f[CR]/srv/chroot/sid\fP
+.br
+\f[CR]\fP
+.br
+\f[CR]$ \f[CB]csbuild \-q \-c sid \-\- uname \-smr\fP\fP
+.br
+\f[CR]Linux 2.6.16.17 ppc\fP
+.br
+\f[CR]$ \f[CB]csbuild \-q \-c sid \-\- "uname \-smr"\fP\fP
+.br
+\f[CR]Linux 2.6.16.17 ppc\fP
+.br
+\f[CR]\fP
+.br
+\f[CR]$ \f[CB]csbuild -q -c sid "ls -1 / | tac | head -n 4"\fP\fP
+.br
+\f[CR]var\fP
+.br
+\f[CR]usr\fP
+.br
+\f[CR]tmp\fP
+.br
+\f[CR]sys\fP
+.br
+\f[CR]\fP
+.br
+\f[CR]$ \f[CB]csbuild \-c sid\fP\fP
+.br
+\f[CR]I: [sid chroot] Running login shell: \[lq]/bin/bash\[rq]\fP
+.br
+\f[CR]$ \fP
+.br
+.LP
+Use \fI\-\-\fP to allow options beginning with \[oq]\-\[cq] or \[oq]\-\-\[cq]
+in the command to run in the chroot. This prevents them being interpreted as
+options for csbuild itself. Note that the top line was echoed to standard
+error, and the remaining lines to standard output. This is intentional, so
+that program output from commands run in the chroot may be piped and redirected
+as required; the data will be the same as if the command was run directly on
+the host system.
+.SH TROUBLESHOOTING
+If something is not working, and it's not clear from the error messages what is
+wrong, try using the \fB\-\-debug=\fP\fIlevel\fP option to turn on debugging
+messages. This gives a great deal more information. Valid debug levels are
+\[oq]none\[cq], and \[oq]notice\[cq], \[oq]info\[cq], \[oq]warning\[cq] and
+\[oq]critical\[cq] in order of increasing severity. The lower the severity
+level, the more output.
+.PP
+If you are still having trouble, the developers may be contacted on the mailing
+list:
+.br
+\f[CR]Debian\ buildd-tools\ Developers
+.br
+<buildd-tools-devel@lists.alioth.debian.org>\fP
+.SH BUGS
+On the \fBmips\fP and \fBmipsel\fP architectures, Linux kernels up to and
+including at least version 2.6.17 have broken
+.BR personality (2)
+support, which results in a failure to set the personality. This will be seen
+as an \[lq]Operation not permitted\[rq] (EPERM) error. To work around this
+problem, set \f[CI]personality\fP to \[oq]undefined\[cq], or upgrade to a more
+recent kernel.
+.SH FILES
+.TP
+\f[BI]@CSBUILD_CONF@\fP
+The system-wide \fBcsbuild\fP chroot definition file. This file must be owned
+by the root user, and not be writable by other. If present, this file will be
+used in preference to \fI@SCHROOT_CONF@\fP.
+.TP
+\f[BI]@SCHROOT_CONF@\fP
+The system-wide \fBschroot\fP definition file. This file must be owned by the
+root user, and not be writable by other. It is recommended that this file be
+used in preference to \fI@CSBUILD_CONF@\fP, because the chroots can be used
+interchangeably with schroot, and the user and group security policies provided
+by schroot are also enforced.
+.SH AUTHORS
+Roger Leigh.
+.PP
+This implementation of csbuild uses the same command-line options as the
+original \fBsbuild\fP by David Kimdon \f[CR]<dwhedon@debian.org>\fP, but is an
+independent implementation.
+.SH COPYRIGHT
+Copyright \(co 2005\-2007 Roger Leigh \f[CR]<rleigh@debian.org>\fP
+.PP
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2 of the License, or (at your option)
+any later version.
+.SH SEE ALSO
+.BR schroot (1),
+.BR sbuild (1),
+.BR chroot (2),
+.BR schroot-setup (5),
+.BR schroot.conf (5).
+.\"#
+.\"# The following sets edit modes for GNU EMACS
+.\"# Local Variables:
+.\"# mode:nroff
+.\"# fill-column:79
+.\"# End:
diff --git a/bin/csbuild/csbuild.cc b/bin/csbuild/csbuild.cc
new file mode 100644
index 00000000..a024be3f
--- /dev/null
+++ b/bin/csbuild/csbuild.cc
@@ -0,0 +1,45 @@
+/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org>
+ *
+ * schroot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include "csbuild-main.h"
+#include "csbuild-options.h"
+
+#include <schroot/schroot-base-run.h>
+
+using std::endl;
+using boost::format;
+using namespace csbuild;
+
+/**
+ * Main routine.
+ *
+ * @param argc the number of arguments
+ * @param argv argument vector
+ *
+ * @returns 0 on success, 1 on failure or the exit status of the
+ * chroot command.
+ */
+int
+main (int argc,
+ char *argv[])
+{
+ return schroot_base::run<csbuild::options, csbuild::main>(argc, argv);
+}