sbuild
1.4.26
|
00001 /* Copyright © 2005-2007 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 3 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, see 00015 * <http://www.gnu.org/licenses/>. 00016 * 00017 *********************************************************************/ 00018 00019 #ifndef SBUILD_AUTH_H 00020 #define SBUILD_AUTH_H 00021 00022 #include <sbuild/sbuild-config.h> 00023 #include <sbuild/sbuild-custom-error.h> 00024 #include <sbuild/sbuild-environment.h> 00025 #include <sbuild/sbuild-types.h> 00026 #include <sbuild/sbuild-util.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 namespace sbuild 00038 { 00039 00069 class auth 00070 { 00071 public: 00073 enum status 00074 { 00075 STATUS_NONE, 00076 STATUS_USER, 00077 STATUS_FAIL 00078 }; 00079 00081 enum error_code 00082 { 00083 HOSTNAME, 00084 USER, 00085 GROUP, 00086 AUTHENTICATION, 00087 AUTHORISATION, 00088 PAM_DOUBLE_INIT, 00089 PAM, 00090 PAM_END 00091 }; 00092 00094 typedef custom_error<error_code> error; 00095 00097 typedef std::tr1::shared_ptr<auth> ptr; 00098 00099 protected: 00108 auth (std::string const& service_name); 00109 00110 public: 00114 virtual ~auth (); 00115 00121 std::string const& 00122 get_service () const; 00123 00131 uid_t 00132 get_uid () const; 00133 00141 gid_t 00142 get_gid () const; 00143 00150 std::string const& 00151 get_user () const; 00152 00163 void 00164 set_user (uid_t uid); 00165 00176 void 00177 set_user (std::string const& user); 00178 00179 protected: 00190 void 00191 set_user (passwd const& pwent); 00192 00193 public: 00201 string_list const& 00202 get_command () const; 00203 00210 void 00211 set_command (string_list const& command); 00212 00219 std::string const& 00220 get_home () const; 00221 00228 std::string const& 00229 get_wd () const; 00230 00237 void 00238 set_wd (std::string const& wd); 00239 00248 std::string const& 00249 get_shell () const; 00250 00256 environment const& 00257 get_user_environment () const; 00258 00265 void 00266 set_user_environment (char **environment); 00267 00273 void 00274 set_user_environment (environment const& environment); 00275 00282 environment 00283 get_minimal_environment () const; 00284 00292 environment 00293 get_complete_environment () const; 00294 00301 virtual environment 00302 get_auth_environment () const = 0; 00303 00310 uid_t 00311 get_ruid () const; 00312 00319 gid_t 00320 get_rgid () const; 00321 00328 std::string const& 00329 get_ruser () const; 00330 00341 void 00342 set_ruser (uid_t ruid); 00343 00354 void 00355 set_ruser (std::string const& ruser); 00356 00357 protected: 00368 void 00369 set_ruser (passwd const& rpwent); 00370 public: 00371 00378 std::string const& 00379 get_rgroup () const; 00380 00387 virtual void 00388 start (); 00389 00396 virtual void 00397 stop (); 00398 00411 virtual void 00412 authenticate (status auth_status); 00413 00424 virtual void 00425 setupenv (); 00426 00432 virtual void 00433 account (); 00434 00440 virtual void 00441 cred_establish (); 00442 00448 virtual void 00449 cred_delete (); 00450 00456 virtual void 00457 open_session (); 00458 00464 virtual void 00465 close_session (); 00466 00476 static status 00477 change_auth (status oldauth, 00478 status newauth) 00479 { 00480 /* Ensure auth level always escalates. */ 00481 if (newauth > oldauth) 00482 return newauth; 00483 else 00484 return oldauth; 00485 } 00486 00491 virtual bool 00492 is_initialised () const = 0; 00493 00494 protected: 00496 const std::string service; 00498 uid_t uid; 00500 gid_t gid; 00502 std::string user; 00504 string_list command; 00506 std::string home; 00508 std::string wd; 00510 std::string shell; 00512 environment user_environment; 00514 uid_t ruid; 00516 gid_t rgid; 00518 std::string ruser; 00520 std::string rgroup; 00521 }; 00522 00523 } 00524 00525 #endif /* SBUILD_AUTH_H */ 00526 00527 /* 00528 * Local Variables: 00529 * mode:C++ 00530 * End: 00531 */