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