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