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 <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-environment.h" 00037 #include "sbuild-error.h" 00038 #include "sbuild-types.h" 00039 00040 namespace sbuild 00041 { 00042 00075 class auth 00076 { 00077 public: 00079 enum status 00080 { 00081 STATUS_NONE, 00082 STATUS_USER, 00083 STATUS_FAIL 00084 }; 00085 00087 enum verbosity 00088 { 00089 VERBOSITY_QUIET, 00090 VERBOSITY_NORMAL, 00091 VERBOSITY_VERBOSE 00092 }; 00093 00095 typedef runtime_error_custom<auth> error; 00096 00098 typedef std::tr1::shared_ptr<auth_conv> conv_ptr; 00099 00108 auth (std::string const& service_name); 00109 00113 virtual ~auth (); 00114 00120 std::string const& 00121 get_service () const; 00122 00130 uid_t 00131 get_uid () const; 00132 00140 gid_t 00141 get_gid () const; 00142 00149 std::string const& 00150 get_user () const; 00151 00162 void 00163 set_user (std::string const& user); 00164 00172 string_list const& 00173 get_command () const; 00174 00181 void 00182 set_command (string_list const& command); 00183 00190 std::string const& 00191 get_home () const; 00192 00201 std::string const& 00202 get_shell () const; 00203 00209 environment const& 00210 get_environment () const; 00211 00218 void 00219 set_environment (char **environment); 00220 00226 void 00227 set_environment (environment const& environment); 00228 00235 environment 00236 get_pam_environment () const; 00237 00244 uid_t 00245 get_ruid () const; 00246 00253 std::string const& 00254 get_ruser () const; 00255 00261 verbosity 00262 get_verbosity () const; 00263 00269 void 00270 set_verbosity (verbosity verbosity); 00271 00277 conv_ptr& 00278 get_conv (); 00279 00285 void 00286 set_conv (conv_ptr& conv); 00287 00294 void 00295 run (); 00296 00303 void 00304 start (); 00305 00312 void 00313 stop (); 00314 00321 void 00322 authenticate (); 00323 00331 void 00332 setupenv (); 00333 00339 void 00340 account (); 00341 00347 void 00348 cred_establish (); 00349 00355 void 00356 cred_delete (); 00357 00363 void 00364 open_session (); 00365 00371 void 00372 close_session (); 00373 00374 protected: 00379 virtual status 00380 get_auth_status () const; 00381 00386 virtual void 00387 run_impl () = 0; 00388 00389 public: 00399 status 00400 change_auth (status oldauth, 00401 status newauth) const 00402 { 00403 /* Ensure auth level always escalates. */ 00404 if (newauth > oldauth) 00405 return newauth; 00406 else 00407 return oldauth; 00408 } 00409 00410 protected: 00412 pam_handle_t *pam; 00413 00414 private: 00416 const std::string service; 00418 uid_t uid; 00420 gid_t gid; 00422 std::string user; 00424 string_list command; 00426 std::string home; 00428 std::string shell; 00430 environment user_environment; 00432 uid_t ruid; 00434 std::string ruser; 00436 conv_ptr conv; 00438 verbosity message_verbosity; 00439 }; 00440 00441 } 00442 00443 #endif /* SBUILD_AUTH_H */ 00444 00445 /* 00446 * Local Variables: 00447 * mode:C++ 00448 * End: 00449 */