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-dsa-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_dsa;
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 dchroot::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
00063
00064
00065
00066
00067 if (get_compat() == true)
00068 {
00069 sbuild::string_list const& users = chroot->get_users();
00070 sbuild::string_list const& groups = chroot->get_groups();
00071
00072 if (this->get_ruid() == this->get_uid() &&
00073 users.empty() && groups.empty())
00074 status = change_auth(status, auth::STATUS_NONE);
00075 else
00076 status = change_auth(status,
00077 sbuild::session::get_chroot_auth_status(status,
00078 chroot));
00079 }
00080 else
00081 {
00082 status = change_auth(status,
00083 sbuild::session::get_chroot_auth_status(status,
00084 chroot));
00085 }
00086
00087 return status;
00088 }
00089
00090 sbuild::string_list
00091 session::get_login_directories () const
00092 {
00093 sbuild::string_list ret;
00094
00095 std::string const& wd(get_wd());
00096 if (!wd.empty())
00097 {
00098
00099 ret.push_back(wd);
00100 }
00101 else
00102 {
00103 ret.push_back(get_home());
00104
00105
00106 if (std::find(ret.begin(), ret.end(), "/") == ret.end())
00107 ret.push_back("/");
00108 }
00109
00110 return ret;
00111 }
00112
00113 void
00114 session::get_user_command (sbuild::chroot::ptr& session_chroot,
00115 std::string& file,
00116 sbuild::string_list& command) const
00117 {
00118 std::string programstring = command[0];
00119 file = programstring;
00120
00121 if (!sbuild::is_absname(file))
00122 throw error(file, COMMAND_ABS);
00123
00124 std::string commandstring = sbuild::string_list_to_string(command, " ");
00125 sbuild::log_debug(sbuild::DEBUG_NOTICE)
00126 << format("Running command: %1%") % commandstring << endl;
00127 if (get_uid() == 0 || get_ruid() != get_uid())
00128 syslog(LOG_USER|LOG_NOTICE, "[%s chroot] (%s->%s) Running command: \"%s\"",
00129 session_chroot->get_name().c_str(), get_ruser().c_str(), get_user().c_str(), commandstring.c_str());
00130
00131 if (get_verbosity() != auth::VERBOSITY_QUIET)
00132 {
00133 std::string format_string;
00134
00135
00136 format_string = (_("[%1% chroot] Running command: \"%2%\""));
00137
00138 format fmt(format_string);
00139 fmt % session_chroot->get_name()
00140 % programstring;
00141 sbuild::log_info() << fmt << endl;
00142 }
00143 }