sbuild-auth.h

Go to the documentation of this file.
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/sbuild-auth-conv.h>
00024 #include <sbuild/sbuild-custom-error.h>
00025 #include <sbuild/sbuild-environment.h>
00026 #include <sbuild/sbuild-types.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 #include <security/pam_appl.h>
00038 
00039 namespace sbuild
00040 {
00041 
00073   class auth
00074   {
00075   public:
00077     enum status
00078       {
00079         STATUS_NONE, 
00080         STATUS_USER, 
00081         STATUS_FAIL  
00082       };
00083 
00085     enum verbosity
00086       {
00087         VERBOSITY_QUIET,  
00088         VERBOSITY_NORMAL, 
00089         VERBOSITY_VERBOSE 
00090       };
00091 
00093     enum error_code
00094       {
00095         HOSTNAME,        
00096         USER,            
00097         AUTHENTICATION,  
00098         AUTHORISATION,   
00099         PAM_DOUBLE_INIT, 
00100         PAM              
00101       };
00102 
00104     typedef custom_error<error_code> error;
00105 
00107     typedef std::tr1::shared_ptr<auth_conv> conv_ptr;
00108 
00117     auth (std::string const& service_name);
00118 
00122     virtual ~auth ();
00123 
00129     std::string const&
00130     get_service () const;
00131 
00139     uid_t
00140     get_uid () const;
00141 
00149     gid_t
00150     get_gid () const;
00151 
00158     std::string const&
00159     get_user () const;
00160 
00171     void
00172     set_user (std::string const& user);
00173 
00181     string_list const&
00182     get_command () const;
00183 
00190     void
00191     set_command (string_list const& command);
00192 
00199     std::string const&
00200     get_home () const;
00201 
00208     std::string const&
00209     get_wd () const;
00210 
00217     void
00218     set_wd (std::string const& wd);
00219 
00228     std::string const&
00229     get_shell () const;
00230 
00236     environment const&
00237     get_environment () const;
00238 
00245     void
00246     set_environment (char **environment);
00247 
00253     void
00254     set_environment (environment const& environment);
00255 
00262     environment
00263     get_pam_environment () const;
00264 
00271     uid_t
00272     get_ruid () const;
00273 
00280     std::string const&
00281     get_ruser () const;
00282 
00288     verbosity
00289     get_verbosity () const;
00290 
00296     void
00297     set_verbosity (verbosity verbosity);
00298 
00304     conv_ptr&
00305     get_conv ();
00306 
00312     void
00313     set_conv (conv_ptr& conv);
00314 
00321     void
00322     run ();
00323 
00330     void
00331     start ();
00332 
00339     void
00340     stop ();
00341 
00351     void
00352     authenticate ();
00353 
00364     void
00365     setupenv ();
00366 
00372     void
00373     account ();
00374 
00380     void
00381     cred_establish ();
00382 
00388     void
00389     cred_delete ();
00390 
00396     void
00397     open_session ();
00398 
00404     void
00405     close_session ();
00406 
00407 protected:
00412     virtual status
00413     get_auth_status () const;
00414 
00419     virtual void
00420     run_impl () = 0;
00421 
00422   public:
00432     status
00433     change_auth (status oldauth,
00434                  status newauth) const
00435     {
00436       /* Ensure auth level always escalates. */
00437       if (newauth > oldauth)
00438         return newauth;
00439       else
00440         return oldauth;
00441     }
00442 
00443   protected:
00445     pam_handle_t      *pam;
00446 
00453     const char *
00454     pam_strerror (int pam_error);
00455 
00456   private:
00458     const std::string  service;
00460     uid_t              uid;
00462     gid_t              gid;
00464     std::string        user;
00466     string_list        command;
00468     std::string        home;
00470     std::string        wd;
00472     std::string        shell;
00474     environment        user_environment;
00476     uid_t              ruid;
00478     std::string        ruser;
00480     conv_ptr           conv;
00482     verbosity          message_verbosity;
00483   };
00484 
00485 }
00486 
00487 #endif /* SBUILD_AUTH_H */
00488 
00489 /*
00490  * Local Variables:
00491  * mode:C++
00492  * End:
00493  */

Generated on Fri Aug 25 17:36:50 2006 for schroot by  doxygen 1.4.7