00001 /* Copyright © 2005-2006 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 "sbuild-config.h" 00024 00025 #include <string> 00026 #include <vector> 00027 00028 #ifdef HAVE_TR1_MEMORY 00029 #include <tr1/memory> 00030 #elif HAVE_BOOST_SHARED_PTR_HPP 00031 #include <boost/shared_ptr.hpp> 00032 namespace std { namespace tr1 { using boost::shared_ptr; } } 00033 #else 00034 #error A shared_ptr implementation is not available 00035 #endif 00036 00037 #include <sys/types.h> 00038 #include <sys/wait.h> 00039 #include <grp.h> 00040 #include <pwd.h> 00041 #include <unistd.h> 00042 00043 #include <security/pam_appl.h> 00044 00045 #include "sbuild-auth-conv.h" 00046 #include "sbuild-environment.h" 00047 #include "sbuild-error.h" 00048 #include "sbuild-types.h" 00049 00050 namespace sbuild 00051 { 00052 00085 class auth 00086 { 00087 public: 00089 enum status 00090 { 00091 STATUS_NONE, 00092 STATUS_USER, 00093 STATUS_FAIL 00094 }; 00095 00097 enum verbosity 00098 { 00099 VERBOSITY_QUIET, 00100 VERBOSITY_NORMAL, 00101 VERBOSITY_VERBOSE 00102 }; 00103 00105 typedef runtime_error_custom<auth> 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 00211 std::string const& 00212 get_shell () const; 00213 00219 environment const& 00220 get_environment () const; 00221 00228 void 00229 set_environment (char **environment); 00230 00236 void 00237 set_environment (environment const& environment); 00238 00245 environment 00246 get_pam_environment () const; 00247 00254 uid_t 00255 get_ruid () const; 00256 00263 std::string const& 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 environment user_environment; 00442 uid_t ruid; 00444 std::string ruser; 00446 conv_ptr conv; 00448 verbosity message_verbosity; 00449 }; 00450 00451 } 00452 00453 #endif /* SBUILD_AUTH_H */ 00454 00455 /* 00456 * Local Variables: 00457 * mode:C++ 00458 * End: 00459 */