sbuild-auth.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef SBUILD_AUTH_H
00020 #define SBUILD_AUTH_H
00021
00022 #include <sbuild/sbuild-auth-conv.h>
00023 #include <sbuild/sbuild-custom-error.h>
00024 #include <sbuild/sbuild-environment.h>
00025 #include <sbuild/sbuild-types.h>
00026 #include <sbuild/sbuild-tr1types.h>
00027
00028 #include <string>
00029
00030 #include <sys/types.h>
00031 #include <sys/wait.h>
00032 #include <grp.h>
00033 #include <pwd.h>
00034 #include <unistd.h>
00035
00036 #include <security/pam_appl.h>
00037
00038 namespace sbuild
00039 {
00040
00072 class auth
00073 {
00074 public:
00076 enum status
00077 {
00078 STATUS_NONE,
00079 STATUS_USER,
00080 STATUS_FAIL
00081 };
00082
00084 enum verbosity
00085 {
00086 VERBOSITY_QUIET,
00087 VERBOSITY_NORMAL,
00088 VERBOSITY_VERBOSE
00089 };
00090
00092 enum error_code
00093 {
00094 HOSTNAME,
00095 USER,
00096 GROUP,
00097 AUTHENTICATION,
00098 AUTHORISATION,
00099 PAM_DOUBLE_INIT,
00100 PAM
00101 };
00102
00104 typedef custom_error<error_code> error;
00105
00107 typedef std::tr1::shared_ptr<auth_conv> conv_ptr;
00108
00117 auth (std::string const& service_name);
00118
00122 virtual ~auth ();
00123
00129 std::string const&
00130 get_service () const;
00131
00139 uid_t
00140 get_uid () const;
00141
00149 gid_t
00150 get_gid () const;
00151
00158 std::string const&
00159 get_user () const;
00160
00171 void
00172 set_user (std::string const& user);
00173
00181 string_list const&
00182 get_command () const;
00183
00190 void
00191 set_command (string_list const& command);
00192
00199 std::string const&
00200 get_home () const;
00201
00208 std::string const&
00209 get_wd () const;
00210
00217 void
00218 set_wd (std::string const& wd);
00219
00228 std::string const&
00229 get_shell () const;
00230
00236 environment const&
00237 get_environment () const;
00238
00245 void
00246 set_environment (char **environment);
00247
00253 void
00254 set_environment (environment const& environment);
00255
00262 environment
00263 get_pam_environment () const;
00264
00271 uid_t
00272 get_ruid () const;
00273
00280 gid_t
00281 get_rgid () const;
00282
00289 std::string const&
00290 get_ruser () const;
00291
00298 std::string const&
00299 get_rgroup () const;
00300
00306 verbosity
00307 get_verbosity () const;
00308
00314 void
00315 set_verbosity (verbosity verbosity);
00316
00322 conv_ptr&
00323 get_conv ();
00324
00330 void
00331 set_conv (conv_ptr& conv);
00332
00339 void
00340 run ();
00341
00348 void
00349 start ();
00350
00357 void
00358 stop ();
00359
00369 void
00370 authenticate ();
00371
00382 void
00383 setupenv ();
00384
00390 void
00391 account ();
00392
00398 void
00399 cred_establish ();
00400
00406 void
00407 cred_delete ();
00408
00414 void
00415 open_session ();
00416
00422 void
00423 close_session ();
00424
00425 protected:
00430 virtual status
00431 get_auth_status () const;
00432
00437 virtual void
00438 run_impl () = 0;
00439
00440 public:
00450 status
00451 change_auth (status oldauth,
00452 status newauth) const
00453 {
00454
00455 if (newauth > oldauth)
00456 return newauth;
00457 else
00458 return oldauth;
00459 }
00460
00461 protected:
00463 pam_handle_t *pam;
00464
00471 const char *
00472 pam_strerror (int pam_error);
00473
00474 private:
00476 const std::string service;
00478 uid_t uid;
00480 gid_t gid;
00482 std::string user;
00484 string_list command;
00486 std::string home;
00488 std::string wd;
00490 std::string shell;
00492 environment user_environment;
00494 uid_t ruid;
00496 gid_t rgid;
00498 std::string ruser;
00500 std::string rgroup;
00502 conv_ptr conv;
00504 verbosity message_verbosity;
00505 };
00506
00507 }
00508
00509 #endif
00510
00511
00512
00513
00514
00515