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 "dchroot-session.h"
00023
00024 #include <cassert>
00025 #include <cerrno>
00026 #include <cstdlib>
00027 #include <cstring>
00028 #include <iostream>
00029 #include <memory>
00030
00031 #include <unistd.h>
00032
00033 #include <syslog.h>
00034
00035 #include <boost/format.hpp>
00036
00037 #include <uuid/uuid.h>
00038
00039 using std::cout;
00040 using std::endl;
00041 using sbuild::_;
00042 using boost::format;
00043 using namespace dchroot;
00044
00045 session::session (std::string const& service,
00046 config_ptr& config,
00047 operation operation,
00048 sbuild::string_list const& chroots,
00049 bool compat):
00050 session_base(service, config, operation, chroots, compat)
00051 {
00052 }
00053
00054 session::~session ()
00055 {
00056 }
00057
00058 sbuild::auth::status
00059 session::get_chroot_auth_status (sbuild::auth::status status,
00060 sbuild::chroot::ptr const& chroot) const
00061 {
00062 if (get_compat() == true)
00063 status = change_auth(status, auth::STATUS_NONE);
00064 else
00065 status = change_auth(status,
00066 sbuild::session::get_chroot_auth_status(status,
00067 chroot));
00068
00069 return status;
00070 }
00071
00072 sbuild::string_list
00073 session::get_login_directories () const
00074 {
00075 sbuild::string_list ret;
00076
00077 std::string const& wd(get_wd());
00078 if (!wd.empty())
00079 {
00080
00081 ret.push_back(wd);
00082 }
00083 else
00084 {
00085
00086
00087 if (!get_environment().empty())
00088 ret.push_back(this->sbuild::session::cwd);
00089 else
00090 ret.push_back(get_home());
00091
00092
00093 if (std::find(ret.begin(), ret.end(), "/") == ret.end())
00094 ret.push_back("/");
00095 }
00096
00097 return ret;
00098 }
00099
00100 void
00101 session::get_user_command (sbuild::chroot::ptr& session_chroot,
00102 std::string& file,
00103 sbuild::string_list& command) const
00104 {
00105 std::string programstring = sbuild::string_list_to_string(command, " ");
00106
00107 command.clear();
00108 command.push_back(get_shell());
00109 command.push_back("-c");
00110 command.push_back(programstring);
00111
00112 file = command[0];
00113
00114 sbuild::log_debug(sbuild::DEBUG_NOTICE) << "file=" << file << endl;
00115
00116 std::string commandstring = sbuild::string_list_to_string(command, " ");
00117 sbuild::log_debug(sbuild::DEBUG_NOTICE)
00118 << format("Running command: %1%") % commandstring << endl;
00119 if (get_uid() == 0 || get_ruid() != get_uid())
00120 syslog(LOG_USER|LOG_NOTICE, "[%s chroot] (%s->%s) Running command: \"%s\"",
00121 session_chroot->get_name().c_str(), get_ruser().c_str(), get_user().c_str(), commandstring.c_str());
00122
00123 if (get_verbosity() != auth::VERBOSITY_QUIET)
00124 {
00125 std::string format_string;
00126
00127
00128 format_string = (_("[%1% chroot] Running command: \"%2%\""));
00129
00130 format fmt(format_string);
00131 fmt % session_chroot->get_name()
00132 % programstring;
00133 sbuild::log_info() << fmt << endl;
00134 }
00135 }