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 
00074   class auth
00075   {
00076   public:
00078     enum status
00079       {
00080         STATUS_NONE, 
00081         STATUS_USER, 
00082         STATUS_FAIL  
00083       };
00084 
00086     enum verbosity
00087       {
00088         VERBOSITY_QUIET,  
00089         VERBOSITY_NORMAL, 
00090         VERBOSITY_VERBOSE 
00091       };
00092 
00094     enum error_code
00095       {
00096         HOSTNAME,        
00097         USER,            
00098         AUTHENTICATION,  
00099         AUTHORISATION,   
00100         PAM_DOUBLE_INIT, 
00101         PAM              
00102       };
00103 
00105     typedef custom_error<error_code> error;
00106 
00108     typedef std::tr1::shared_ptr<auth_conv> conv_ptr;
00109 
00118     auth (std::string const& service_name);
00119 
00123     virtual ~auth ();
00124 
00130     std::string const&
00131     get_service () const;
00132 
00140     uid_t
00141     get_uid () const;
00142 
00150     gid_t
00151     get_gid () const;
00152 
00159     std::string const&
00160     get_user () const;
00161 
00172     void
00173     set_user (std::string const& user);
00174 
00182     string_list const&
00183     get_command () const;
00184 
00191     void
00192     set_command (string_list const& command);
00193 
00200     std::string const&
00201     get_home () const;
00202 
00211     std::string const&
00212     get_shell () const;
00213 
00219     environment const&
00220     get_environment () const;
00221 
00228     void
00229     set_environment (char **environment);
00230 
00236     void
00237     set_environment (environment const& environment);
00238 
00245     environment
00246     get_pam_environment () const;
00247 
00254     uid_t
00255     get_ruid () const;
00256 
00263     std::string const&
00264     get_ruser () const;
00265 
00271     verbosity
00272     get_verbosity () const;
00273 
00279     void
00280     set_verbosity (verbosity verbosity);
00281 
00287     conv_ptr&
00288     get_conv ();
00289 
00295     void
00296     set_conv (conv_ptr& conv);
00297 
00304     void
00305     run ();
00306 
00313     void
00314     start ();
00315 
00322     void
00323     stop ();
00324 
00331     void
00332     authenticate ();
00333 
00341     void
00342     setupenv ();
00343 
00349     void
00350     account ();
00351 
00357     void
00358     cred_establish ();
00359 
00365     void
00366     cred_delete ();
00367 
00373     void
00374     open_session ();
00375 
00381     void
00382     close_session ();
00383 
00384 protected:
00389     virtual status
00390     get_auth_status () const;
00391 
00396     virtual void
00397     run_impl () = 0;
00398 
00399   public:
00409     status
00410     change_auth (status oldauth,
00411                  status newauth) const
00412     {
00413       /* Ensure auth level always escalates. */
00414       if (newauth > oldauth)
00415         return newauth;
00416       else
00417         return oldauth;
00418     }
00419 
00420   protected:
00422     pam_handle_t      *pam;
00423 
00430     const char *
00431     pam_strerror (int pam_error);
00432 
00433   private:
00435     const std::string  service;
00437     uid_t              uid;
00439     gid_t              gid;
00441     std::string        user;
00443     string_list        command;
00445     std::string        home;
00447     std::string        shell;
00449     environment        user_environment;
00451     uid_t              ruid;
00453     std::string        ruser;
00455     conv_ptr           conv;
00457     verbosity          message_verbosity;
00458   };
00459 
00460 }
00461 
00462 #endif /* SBUILD_AUTH_H */
00463 
00464 /*
00465  * Local Variables:
00466  * mode:C++
00467  * End:
00468  */

Generated on Thu Jul 6 19:21:41 2006 for schroot by  doxygen 1.4.7