sbuild-auth.h

Go to the documentation of this file.
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-tr1types.h>
00027 
00028 #include <string>
00029 
00030 #include <sys/types.h>
00031 #include <sys/wait.h>
00032 #include <grp.h>
00033 #include <pwd.h>
00034 #include <unistd.h>
00035 
00036 namespace sbuild
00037 {
00038 
00068   class auth
00069   {
00070   public:
00072     enum status
00073       {
00074         STATUS_NONE, 
00075         STATUS_USER, 
00076         STATUS_FAIL  
00077       };
00078 
00080     enum verbosity
00081       {
00082         VERBOSITY_QUIET,  
00083         VERBOSITY_NORMAL, 
00084         VERBOSITY_VERBOSE 
00085       };
00086 
00088     enum error_code
00089       {
00090         HOSTNAME,        
00091         USER,            
00092         GROUP,           
00093         AUTHENTICATION,  
00094         AUTHORISATION,   
00095         PAM_DOUBLE_INIT, 
00096         PAM              
00097       };
00098 
00100     typedef custom_error<error_code> error;
00101 
00103     typedef std::tr1::shared_ptr<auth> ptr;
00104 
00105   protected:
00114     auth (std::string const& service_name);
00115 
00116   public:
00120     virtual ~auth ();
00121 
00127     std::string const&
00128     get_service () const;
00129 
00137     uid_t
00138     get_uid () const;
00139 
00147     gid_t
00148     get_gid () const;
00149 
00156     std::string const&
00157     get_user () const;
00158 
00169     void
00170     set_user (std::string const& user);
00171 
00179     string_list const&
00180     get_command () const;
00181 
00188     void
00189     set_command (string_list const& command);
00190 
00197     std::string const&
00198     get_home () const;
00199 
00206     std::string const&
00207     get_wd () const;
00208 
00215     void
00216     set_wd (std::string const& wd);
00217 
00226     std::string const&
00227     get_shell () const;
00228 
00234     environment const&
00235     get_environment () const;
00236 
00243     void
00244     set_environment (char **environment);
00245 
00251     void
00252     set_environment (environment const& environment);
00253 
00261     environment
00262     get_minimal_environment () const;
00263 
00270     virtual environment
00271     get_auth_environment () const = 0;
00272 
00279     uid_t
00280     get_ruid () const;
00281 
00288     gid_t
00289     get_rgid () const;
00290 
00297     std::string const&
00298     get_ruser () const;
00299 
00306     std::string const&
00307     get_rgroup () const;
00308 
00314     verbosity
00315     get_verbosity () const;
00316 
00322     void
00323     set_verbosity (verbosity verbosity);
00324 
00331     virtual void
00332     start ();
00333 
00340     virtual void
00341     stop ();
00342 
00355     virtual void
00356     authenticate (status auth_status);
00357 
00368     virtual void
00369     setupenv ();
00370 
00376     virtual void
00377     account ();
00378 
00384     virtual void
00385     cred_establish ();
00386 
00392     virtual void
00393     cred_delete ();
00394 
00400     virtual void
00401     open_session ();
00402 
00408     virtual void
00409     close_session ();
00410 
00420     static status
00421     change_auth (status oldauth,
00422                  status newauth)
00423     {
00424       /* Ensure auth level always escalates. */
00425       if (newauth > oldauth)
00426         return newauth;
00427       else
00428         return oldauth;
00429     }
00430 
00435     virtual bool
00436     is_initialised () const = 0;
00437 
00438   protected:
00440     const std::string  service;
00442     uid_t              uid;
00444     gid_t              gid;
00446     std::string        user;
00448     string_list        command;
00450     std::string        home;
00452     std::string        wd;
00454     std::string        shell;
00456     environment        user_environment;
00458     uid_t              ruid;
00460     gid_t              rgid;
00462     std::string        ruser;
00464     std::string        rgroup;
00465 #ifndef SBUILD_FEATURE_PAM
00466 
00467     environment        auth_environment;
00468 #endif // !SBUILD_FEATURE_PAM
00469 
00470     verbosity          message_verbosity;
00471   };
00472 
00473 }
00474 
00475 #endif /* SBUILD_AUTH_H */
00476 
00477 /*
00478  * Local Variables:
00479  * mode:C++
00480  * End:
00481  */
Generated on Sat Apr 3 02:43:46 2010 for sbuild by  doxygen 1.6.3