1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/* Copyright © 2005-2007 Roger Leigh <rleigh@debian.org>
*
* schroot is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* schroot is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
*********************************************************************/
#include <config.h>
#include "dchroot-session.h"
#include <cassert>
#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <memory>
#include <unistd.h>
#include <syslog.h>
#include <boost/format.hpp>
using std::cout;
using std::endl;
using sbuild::_;
using boost::format;
using namespace dchroot;
session::session (std::string const& service,
config_ptr& config,
operation operation,
sbuild::string_list const& chroots,
bool compat):
session_base(service, config, operation, chroots, compat)
{
}
session::~session ()
{
}
sbuild::auth::status
session::get_chroot_auth_status (sbuild::auth::status status,
sbuild::chroot::ptr const& chroot) const
{
if (get_compat() == true)
status = change_auth(status, auth::STATUS_NONE);
else
status = change_auth(status,
sbuild::session::get_chroot_auth_status(status,
chroot));
return status;
}
sbuild::string_list
session::get_login_directories () const
{
sbuild::string_list ret;
std::string const& wd(get_wd());
if (!wd.empty())
{
// Set specified working directory.
ret.push_back(wd);
}
else
{
// Set current working directory only if preserving environment.
// Only change to home if not preserving the environment.
if (!get_environment().empty())
ret.push_back(this->sbuild::session::cwd);
else
ret.push_back(get_home());
// Final fallback to root.
if (std::find(ret.begin(), ret.end(), "/") == ret.end())
ret.push_back("/");
}
return ret;
}
void
session::get_user_command (sbuild::chroot::ptr& session_chroot,
std::string& file,
sbuild::string_list& command) const
{
std::string programstring = sbuild::string_list_to_string(command, " ");
command.clear();
command.push_back(get_shell());
command.push_back("-c");
command.push_back(programstring);
file = command[0];
sbuild::log_debug(sbuild::DEBUG_NOTICE) << "file=" << file << endl;
std::string commandstring = sbuild::string_list_to_string(command, " ");
sbuild::log_debug(sbuild::DEBUG_NOTICE)
<< format("Running command: %1%") % commandstring << endl;
if (get_uid() == 0 || get_ruid() != get_uid())
syslog(LOG_USER|LOG_NOTICE, "[%s chroot] (%s->%s) Running command: \"%s\"",
session_chroot->get_name().c_str(), get_ruser().c_str(), get_user().c_str(), commandstring.c_str());
if (get_verbosity() != auth::VERBOSITY_QUIET)
{
std::string format_string;
// TRANSLATORS: %1% = chroot name
// TRANSLATORS: %2% = command
format_string = (_("[%1% chroot] Running command: \"%2%\""));
format fmt(format_string);
fmt % session_chroot->get_name()
% programstring;
sbuild::log_info() << fmt << endl;
}
}
|