sbuild  1.7.1
auth.h
1 /* Copyright © 2005-2013 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/config.h>
23 #include <sbuild/custom-error.h>
24 #include <sbuild/environment.h>
25 #include <sbuild/types.h>
26 #include <sbuild/util.h>
27 
28 #include <string>
29 #include <memory>
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 {
42  namespace auth
43  {
44 
74  class auth
75  {
76  public:
78  enum status
79  {
83  };
84 
87  {
89  USER,
94  PAM,
96  };
97 
100 
102  typedef std::shared_ptr<auth> ptr;
103 
104  protected:
113  auth (const std::string& service_name);
114 
115  public:
119  virtual ~auth ();
120 
126  std::string const&
127  get_service () const;
128 
136  uid_t
137  get_uid () const;
138 
146  gid_t
147  get_gid () const;
148 
155  std::string const&
156  get_user () const;
157 
168  void
169  set_user (uid_t uid);
170 
181  void
182  set_user (const std::string& user);
183 
184  protected:
195  void
196  set_user (const passwd& pwent);
197 
198  public:
206  string_list const&
207  get_command () const;
208 
215  void
217 
224  std::string const&
225  get_home () const;
226 
233  std::string const&
234  get_wd () const;
235 
242  void
243  set_wd (const std::string& wd);
244 
253  std::string const&
254  get_shell () const;
255 
261  environment const&
262  get_user_environment () const;
263 
270  void
272 
278  void
280 
288  get_minimal_environment () const;
289 
298  get_complete_environment () const;
299 
306  virtual environment
307  get_auth_environment () const = 0;
308 
315  uid_t
316  get_ruid () const;
317 
324  gid_t
325  get_rgid () const;
326 
333  std::string const&
334  get_ruser () const;
335 
346  void
347  set_ruser (uid_t ruid);
348 
359  void
360  set_ruser (const std::string& ruser);
361 
362  protected:
373  void
374  set_ruser (const passwd& rpwent);
375  public:
376 
383  std::string const&
384  get_rgroup () const;
385 
392  virtual void
393  start ();
394 
401  virtual void
402  stop ();
403 
416  virtual void
417  authenticate (status auth_status);
418 
429  virtual void
430  setupenv ();
431 
437  virtual void
438  account ();
439 
445  virtual void
446  cred_establish ();
447 
453  virtual void
454  cred_delete ();
455 
461  virtual void
462  open_session ();
463 
469  virtual void
470  close_session ();
471 
481  static status
482  change_auth (status oldauth,
483  status newauth)
484  {
485  /* Ensure auth level always escalates. */
486  if (newauth > oldauth)
487  return newauth;
488  else
489  return oldauth;
490  }
491 
496  virtual bool
497  is_initialised () const = 0;
498 
499  protected:
501  const std::string service;
503  uid_t uid;
505  gid_t gid;
507  std::string user;
511  std::string home;
513  std::string wd;
515  std::string shell;
519  uid_t ruid;
521  gid_t rgid;
523  std::string ruser;
525  std::string rgroup;
526  };
527 
528  }
529 }
530 
531 #endif /* SBUILD_AUTH_H */
532 
533 /*
534  * Local Variables:
535  * mode:C++
536  * End:
537  */