~ubuntu-branches/ubuntu/intrepid/schroot/intrepid

« back to all changes in this revision

Viewing changes to dchroot-dsa/dchroot-dsa-session.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2006-07-08 18:33:28 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060708183328-rlo4mpldmyoda55q
Tags: 0.99.2-2ubuntu1
* remerge ubuntu changes:
  + debian/control: libpam-dev (>> 0.79-3ubuntu6)

Show diffs side-by-side

added added

removed removed

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