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