00001 /* Copyright © 2005 Roger Leigh <rleigh@debian.org> 00002 * 00003 * schroot is free software; you can redistribute it and/or modify it 00004 * under the terms of the GNU General Public License as published by 00005 * the Free Software Foundation; either version 2 of the License, or 00006 * (at your option) any later version. 00007 * 00008 * schroot is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00016 * MA 02111-1307 USA 00017 * 00018 *********************************************************************/ 00019 00020 #ifndef SBUILD_AUTH_H 00021 #define SBUILD_AUTH_H 00022 00023 #include <string> 00024 #include <vector> 00025 #include <tr1/memory> 00026 00027 #include <sys/types.h> 00028 #include <sys/wait.h> 00029 #include <grp.h> 00030 #include <pwd.h> 00031 #include <unistd.h> 00032 00033 #include <security/pam_appl.h> 00034 00035 #include "sbuild-auth-conv.h" 00036 #include "sbuild-error.h" 00037 #include "sbuild-types.h" 00038 00039 namespace sbuild 00040 { 00041 00074 class Auth 00075 { 00076 public: 00078 enum Status 00079 { 00080 STATUS_NONE, 00081 STATUS_USER, 00082 STATUS_FAIL 00083 }; 00084 00086 enum Verbosity 00087 { 00088 VERBOSITY_QUIET, 00089 VERBOSITY_NORMAL, 00090 VERBOSITY_VERBOSE 00091 }; 00092 00094 typedef runtime_error_custom<Auth> error; 00095 00097 typedef std::tr1::shared_ptr<AuthConv> conv_ptr; 00098 00107 Auth(const std::string& service_name); 00108 00114 virtual ~Auth(); 00115 00121 const std::string& 00122 get_service () const; 00123 00131 uid_t 00132 get_uid () const; 00133 00141 gid_t 00142 get_gid () const; 00143 00150 const std::string& 00151 get_user () const; 00152 00170 void 00171 set_user (const std::string& user); 00172 00180 const string_list& 00181 get_command () const; 00182 00189 void 00190 set_command (const string_list& command); 00191 00198 const std::string& 00199 get_home () const; 00200 00209 const std::string& 00210 get_shell () const; 00211 00219 const env_list& 00220 get_environment () const; 00221 00228 void 00229 set_environment (char **environment); 00230 00236 void 00237 set_environment (const env_list& environment); 00238 00245 env_list 00246 get_pam_environment () const; 00247 00254 uid_t 00255 get_ruid () const; 00256 00263 const std::string& 00264 get_ruser () const; 00265 00271 Verbosity 00272 get_verbosity () const; 00273 00279 void 00280 set_verbosity (Verbosity verbosity); 00281 00287 conv_ptr& 00288 get_conv (); 00289 00295 void 00296 set_conv (conv_ptr& conv); 00297 00304 void 00305 run (); 00306 00313 void 00314 start (); 00315 00322 void 00323 stop (); 00324 00331 void 00332 authenticate (); 00333 00341 void 00342 setupenv (); 00343 00349 void 00350 account (); 00351 00357 void 00358 cred_establish (); 00359 00365 void 00366 cred_delete (); 00367 00373 void 00374 open_session (); 00375 00381 void 00382 close_session (); 00383 00384 protected: 00389 virtual Status 00390 get_auth_status () const; 00391 00396 virtual void 00397 run_impl () = 0; 00398 00399 public: 00409 Status 00410 change_auth (Status oldauth, 00411 Status newauth) const 00412 { 00413 /* Ensure auth level always escalates. */ 00414 if (newauth > oldauth) 00415 return newauth; 00416 else 00417 return oldauth; 00418 } 00419 00420 protected: 00422 pam_handle_t *pam; 00423 00424 private: 00426 const std::string service; 00428 uid_t uid; 00430 gid_t gid; 00432 std::string user; 00434 string_list command; 00436 std::string home; 00438 std::string shell; 00440 env_list environment; 00442 uid_t ruid; 00444 std::string ruser; 00446 conv_ptr conv; 00448 Verbosity verbosity; 00449 }; 00450 00451 } 00452 00453 #endif /* SBUILD_AUTH_H */ 00454 00455 /* 00456 * Local Variables: 00457 * mode:C++ 00458 * End: 00459 */