sbuild  1.6.4
sbuild-auth.h
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 #ifndef SBUILD_AUTH_H
20 #define SBUILD_AUTH_H
21 
22 #include <sbuild/sbuild-config.h>
23 #include <sbuild/sbuild-custom-error.h>
24 #include <sbuild/sbuild-environment.h>
25 #include <sbuild/sbuild-types.h>
26 #include <sbuild/sbuild-util.h>
27 #include <sbuild/sbuild-tr1types.h>
28 
29 #include <string>
30 
31 #include <sys/types.h>
32 #include <sys/wait.h>
33 #include <grp.h>
34 #include <pwd.h>
35 #include <unistd.h>
36 
37 namespace sbuild
38 {
39 
69  class auth
70  {
71  public:
73  enum status
74  {
78  };
79 
82  {
84  USER,
89  PAM,
91  };
92 
95 
97  typedef std::shared_ptr<auth> ptr;
98 
99  protected:
108  auth (std::string const& service_name);
109 
110  public:
114  virtual ~auth ();
115 
121  std::string const&
122  get_service () const;
123 
131  uid_t
132  get_uid () const;
133 
141  gid_t
142  get_gid () const;
143 
150  std::string const&
151  get_user () const;
152 
163  void
164  set_user (uid_t uid);
165 
176  void
177  set_user (std::string const& user);
178 
179  protected:
190  void
191  set_user (passwd const& pwent);
192 
193  public:
201  string_list const&
202  get_command () const;
203 
210  void
212 
219  std::string const&
220  get_home () const;
221 
228  std::string const&
229  get_wd () const;
230 
237  void
238  set_wd (std::string const& wd);
239 
248  std::string const&
249  get_shell () const;
250 
256  environment const&
257  get_user_environment () const;
258 
265  void
267 
273  void
275 
283  get_minimal_environment () const;
284 
293  get_complete_environment () const;
294 
301  virtual environment
302  get_auth_environment () const = 0;
303 
310  uid_t
311  get_ruid () const;
312 
319  gid_t
320  get_rgid () const;
321 
328  std::string const&
329  get_ruser () const;
330 
341  void
342  set_ruser (uid_t ruid);
343 
354  void
355  set_ruser (std::string const& ruser);
356 
357  protected:
368  void
369  set_ruser (passwd const& rpwent);
370  public:
371 
378  std::string const&
379  get_rgroup () const;
380 
387  virtual void
388  start ();
389 
396  virtual void
397  stop ();
398 
411  virtual void
412  authenticate (status auth_status);
413 
424  virtual void
425  setupenv ();
426 
432  virtual void
433  account ();
434 
440  virtual void
441  cred_establish ();
442 
448  virtual void
449  cred_delete ();
450 
456  virtual void
457  open_session ();
458 
464  virtual void
465  close_session ();
466 
476  static status
477  change_auth (status oldauth,
478  status newauth)
479  {
480  /* Ensure auth level always escalates. */
481  if (newauth > oldauth)
482  return newauth;
483  else
484  return oldauth;
485  }
486 
491  virtual bool
492  is_initialised () const = 0;
493 
494  protected:
496  const std::string service;
498  uid_t uid;
500  gid_t gid;
502  std::string user;
506  std::string home;
508  std::string wd;
510  std::string shell;
514  uid_t ruid;
516  gid_t rgid;
518  std::string ruser;
520  std::string rgroup;
521  };
522 
523 }
524 
525 #endif /* SBUILD_AUTH_H */
526 
527 /*
528  * Local Variables:
529  * mode:C++
530  * End:
531  */