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