source: trunk/debathena/third/schroot/bin/schroot/schroot-main.cc @ 24167

Revision 24167, 2.8 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
Line 
1/* Copyright © 2005-2007  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 3 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, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 *********************************************************************/
18
19#include <config.h>
20
21#include <sbuild/sbuild-config.h>
22#ifdef SBUILD_FEATURE_PAM
23#include <sbuild/sbuild-auth-pam.h>
24#include <sbuild/sbuild-auth-pam-conv-tty.h>
25#endif
26
27#include "schroot-main.h"
28
29#include <cstdlib>
30#include <ctime>
31#include <iostream>
32#include <locale>
33
34#include <termios.h>
35#include <unistd.h>
36
37#include <boost/format.hpp>
38
39using std::endl;
40using boost::format;
41using sbuild::_;
42using namespace schroot;
43
44main::main (options_base::ptr& options):
45  main_base("schroot",
46            // TRANSLATORS: '...' is an ellipsis e.g. U+2026, and '-'
47            // is an em-dash.
48            _("[OPTION...] [COMMAND] - run command or shell in a chroot"),
49            options,
50            true)
51{
52}
53
54main::~main ()
55{
56}
57
58void
59main::action_config ()
60{
61  std::cout << "# "
62    // TRANSLATORS: %1% = program name
63    // TRANSLATORS: %2% = program version
64    // TRANSLATORS: %3% = current date
65            << format(_("schroot configuration generated by %1% %2% on %3%"))
66    % this->program_name % VERSION % sbuild::date(time(0))
67            << endl;
68  std::cout << endl;
69  this->config->print_chroot_config(this->chroots, std::cout);
70}
71
72void
73main::action_list ()
74{
75  this->config->print_chroot_list(std::cout);
76}
77
78void
79main::create_session(sbuild::session::operation sess_op)
80{
81  sbuild::log_debug(sbuild::DEBUG_INFO) << "Creating schroot session" << endl;
82
83  this->session = sbuild::session::ptr
84    (new sbuild::session("schroot", this->config, sess_op, this->chroots));
85
86#ifdef SBUILD_FEATURE_PAM
87  sbuild::auth::ptr auth = sbuild::auth_pam::create("schroot");
88
89  sbuild::auth_pam_conv_tty::auth_ptr auth_ptr =
90    std::tr1::dynamic_pointer_cast<sbuild::auth_pam>(auth);
91
92  sbuild::auth_pam_conv::ptr conv = sbuild::auth_pam_conv_tty::create(auth_ptr);
93
94  /* Set up authentication timeouts. */
95  time_t curtime = 0;
96  time(&curtime);
97  conv->set_warning_timeout(curtime + 15);
98  conv->set_fatal_timeout(curtime + 20);
99
100  this->session->set_auth(auth);
101#endif // SBUILD_FEATURE_PAM
102
103  if (!this->options->user.empty())
104    this->session->get_auth()->set_user(this->options->user);
105}
Note: See TracBrowser for help on using the repository browser.