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 
00366     void
00367     setupenv ();
00368 
00374     void
00375     account ();
00376 
00382     void
00383     cred_establish ();
00384 
00390     void
00391     cred_delete ();
00392 
00398     void
00399     open_session ();
00400 
00406     void
00407     close_session ();
00408 
00409 protected:
00414     virtual status
00415     get_auth_status () const;
00416 
00421     virtual void
00422     run_impl () = 0;
00423 
00424   public:
00434     status
00435     change_auth (status oldauth,
00436                  status newauth) const
00437     {
00438       /* Ensure auth level always escalates. */
00439       if (newauth > oldauth)
00440         return newauth;
00441       else
00442         return oldauth;
00443     }
00444 
00445   protected:
00447     pam_handle_t      *pam;
00448 
00455     const char *
00456     pam_strerror (int pam_error);
00457 
00458   private:
00460     const std::string  service;
00462     uid_t              uid;
00464     gid_t              gid;
00466     std::string        user;
00468     string_list        command;
00470     std::string        home;
00472     std::string        wd;
00474     std::string        shell;
00476     environment        user_environment;
00478     uid_t              ruid;
00480     std::string        ruser;
00482     conv_ptr           conv;
00484     verbosity          message_verbosity;
00485   };
00486 
00487 }
00488 
00489 #endif /* SBUILD_AUTH_H */
00490 
00491 /*
00492  * Local Variables:
00493  * mode:C++
00494  * End:
00495  */

Generated on Mon Sep 11 23:12:43 2006 for schroot by  doxygen 1.4.7