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 
00210     std::string const&
00211     get_shell () const;
00212 
00218     environment const&
00219     get_environment () const;
00220 
00227     void
00228     set_environment (char **environment);
00229 
00235     void
00236     set_environment (environment const& environment);
00237 
00244     environment
00245     get_pam_environment () const;
00246 
00253     uid_t
00254     get_ruid () const;
00255 
00262     std::string const&
00263     get_ruser () const;
00264 
00270     verbosity
00271     get_verbosity () const;
00272 
00278     void
00279     set_verbosity (verbosity verbosity);
00280 
00286     conv_ptr&
00287     get_conv ();
00288 
00294     void
00295     set_conv (conv_ptr& conv);
00296 
00303     void
00304     run ();
00305 
00312     void
00313     start ();
00314 
00321     void
00322     stop ();
00323 
00333     void
00334     authenticate ();
00335 
00348     void
00349     setupenv ();
00350 
00356     void
00357     account ();
00358 
00364     void
00365     cred_establish ();
00366 
00372     void
00373     cred_delete ();
00374 
00380     void
00381     open_session ();
00382 
00388     void
00389     close_session ();
00390 
00391 protected:
00396     virtual status
00397     get_auth_status () const;
00398 
00403     virtual void
00404     run_impl () = 0;
00405 
00406   public:
00416     status
00417     change_auth (status oldauth,
00418                  status newauth) const
00419     {
00420       /* Ensure auth level always escalates. */
00421       if (newauth > oldauth)
00422         return newauth;
00423       else
00424         return oldauth;
00425     }
00426 
00427   protected:
00429     pam_handle_t      *pam;
00430 
00437     const char *
00438     pam_strerror (int pam_error);
00439 
00440   private:
00442     const std::string  service;
00444     uid_t              uid;
00446     gid_t              gid;
00448     std::string        user;
00450     string_list        command;
00452     std::string        home;
00454     std::string        shell;
00456     environment        user_environment;
00458     uid_t              ruid;
00460     std::string        ruser;
00462     conv_ptr           conv;
00464     verbosity          message_verbosity;
00465   };
00466 
00467 }
00468 
00469 #endif /* SBUILD_AUTH_H */
00470 
00471 /*
00472  * Local Variables:
00473  * mode:C++
00474  * End:
00475  */

Generated on Thu Aug 3 12:20:16 2006 for schroot by  doxygen 1.4.7