00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_AUTH_H
00021 #define SBUILD_AUTH_H
00022
00023 #include <sbuild/sbuild-auth-conv.h>
00024 #include <sbuild/sbuild-custom-error.h>
00025 #include <sbuild/sbuild-environment.h>
00026 #include <sbuild/sbuild-types.h>
00027 #include <sbuild/sbuild-tr1types.h>
00028
00029 #include <string>
00030
00031 #include <sys/types.h>
00032 #include <sys/wait.h>
00033 #include <grp.h>
00034 #include <pwd.h>
00035 #include <unistd.h>
00036
00037 #include <security/pam_appl.h>
00038
00039 namespace sbuild
00040 {
00041
00073 class auth
00074 {
00075 public:
00077 enum status
00078 {
00079 STATUS_NONE,
00080 STATUS_USER,
00081 STATUS_FAIL
00082 };
00083
00085 enum verbosity
00086 {
00087 VERBOSITY_QUIET,
00088 VERBOSITY_NORMAL,
00089 VERBOSITY_VERBOSE
00090 };
00091
00093 enum error_code
00094 {
00095 HOSTNAME,
00096 USER,
00097 GROUP,
00098 AUTHENTICATION,
00099 AUTHORISATION,
00100 PAM_DOUBLE_INIT,
00101 PAM
00102 };
00103
00105 typedef custom_error<error_code> error;
00106
00108 typedef std::tr1::shared_ptr<auth_conv> conv_ptr;
00109
00118 auth (std::string const& service_name);
00119
00123 virtual ~auth ();
00124
00130 std::string const&
00131 get_service () const;
00132
00140 uid_t
00141 get_uid () const;
00142
00150 gid_t
00151 get_gid () const;
00152
00159 std::string const&
00160 get_user () const;
00161
00172 void
00173 set_user (std::string const& user);
00174
00182 string_list const&
00183 get_command () const;
00184
00191 void
00192 set_command (string_list const& command);
00193
00200 std::string const&
00201 get_home () const;
00202
00209 std::string const&
00210 get_wd () const;
00211
00218 void
00219 set_wd (std::string const& wd);
00220
00229 std::string const&
00230 get_shell () const;
00231
00237 environment const&
00238 get_environment () const;
00239
00246 void
00247 set_environment (char **environment);
00248
00254 void
00255 set_environment (environment const& environment);
00256
00263 environment
00264 get_pam_environment () const;
00265
00272 uid_t
00273 get_ruid () const;
00274
00281 gid_t
00282 get_rgid () const;
00283
00290 std::string const&
00291 get_ruser () const;
00292
00299 std::string const&
00300 get_rgroup () const;
00301
00307 verbosity
00308 get_verbosity () const;
00309
00315 void
00316 set_verbosity (verbosity verbosity);
00317
00323 conv_ptr&
00324 get_conv ();
00325
00331 void
00332 set_conv (conv_ptr& conv);
00333
00340 void
00341 run ();
00342
00349 void
00350 start ();
00351
00358 void
00359 stop ();
00360
00370 void
00371 authenticate ();
00372
00383 void
00384 setupenv ();
00385
00391 void
00392 account ();
00393
00399 void
00400 cred_establish ();
00401
00407 void
00408 cred_delete ();
00409
00415 void
00416 open_session ();
00417
00423 void
00424 close_session ();
00425
00426 protected:
00431 virtual status
00432 get_auth_status () const;
00433
00438 virtual void
00439 run_impl () = 0;
00440
00441 public:
00451 status
00452 change_auth (status oldauth,
00453 status newauth) const
00454 {
00455
00456 if (newauth > oldauth)
00457 return newauth;
00458 else
00459 return oldauth;
00460 }
00461
00462 protected:
00464 pam_handle_t *pam;
00465
00472 const char *
00473 pam_strerror (int pam_error);
00474
00475 private:
00477 const std::string service;
00479 uid_t uid;
00481 gid_t gid;
00483 std::string user;
00485 string_list command;
00487 std::string home;
00489 std::string wd;
00491 std::string shell;
00493 environment user_environment;
00495 uid_t ruid;
00497 gid_t rgid;
00499 std::string ruser;
00501 std::string rgroup;
00503 conv_ptr conv;
00505 verbosity message_verbosity;
00506 };
00507
00508 }
00509
00510 #endif
00511
00512
00513
00514
00515
00516