sbuild-auth.h

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 error_code
00081       {
00082         HOSTNAME,        
00083         USER,            
00084         GROUP,           
00085         AUTHENTICATION,  
00086         AUTHORISATION,   
00087         PAM_DOUBLE_INIT, 
00088         PAM,             
00089         PAM_END          
00090       };
00091 
00093     typedef custom_error<error_code> error;
00094 
00096     typedef std::tr1::shared_ptr<auth> ptr;
00097 
00098   protected:
00107     auth (std::string const& service_name);
00108 
00109   public:
00113     virtual ~auth ();
00114 
00120     std::string const&
00121     get_service () const;
00122 
00130     uid_t
00131     get_uid () const;
00132 
00140     gid_t
00141     get_gid () const;
00142 
00149     std::string const&
00150     get_user () const;
00151 
00162     void
00163     set_user (std::string const& user);
00164 
00172     string_list const&
00173     get_command () const;
00174 
00181     void
00182     set_command (string_list const& command);
00183 
00190     std::string const&
00191     get_home () const;
00192 
00199     std::string const&
00200     get_wd () const;
00201 
00208     void
00209     set_wd (std::string const& wd);
00210 
00219     std::string const&
00220     get_shell () const;
00221 
00227     environment const&
00228     get_user_environment () const;
00229 
00236     void
00237     set_user_environment (char **environment);
00238 
00244     void
00245     set_user_environment (environment const& environment);
00246 
00253     environment
00254     get_minimal_environment () const;
00255 
00263     environment
00264     get_complete_environment () const;
00265 
00272     virtual environment
00273     get_auth_environment () const = 0;
00274 
00281     uid_t
00282     get_ruid () const;
00283 
00290     gid_t
00291     get_rgid () const;
00292 
00299     std::string const&
00300     get_ruser () const;
00301 
00308     std::string const&
00309     get_rgroup () const;
00310 
00317     virtual void
00318     start ();
00319 
00326     virtual void
00327     stop ();
00328 
00341     virtual void
00342     authenticate (status auth_status);
00343 
00354     virtual void
00355     setupenv ();
00356 
00362     virtual void
00363     account ();
00364 
00370     virtual void
00371     cred_establish ();
00372 
00378     virtual void
00379     cred_delete ();
00380 
00386     virtual void
00387     open_session ();
00388 
00394     virtual void
00395     close_session ();
00396 
00406     static status
00407     change_auth (status oldauth,
00408                  status newauth)
00409     {
00410       /* Ensure auth level always escalates. */
00411       if (newauth > oldauth)
00412         return newauth;
00413       else
00414         return oldauth;
00415     }
00416 
00421     virtual bool
00422     is_initialised () const = 0;
00423 
00424   protected:
00426     const std::string  service;
00428     uid_t              uid;
00430     gid_t              gid;
00432     std::string        user;
00434     string_list        command;
00436     std::string        home;
00438     std::string        wd;
00440     std::string        shell;
00442     environment        user_environment;
00444     uid_t              ruid;
00446     gid_t              rgid;
00448     std::string        ruser;
00450     std::string        rgroup;
00451   };
00452 
00453 }
00454 
00455 #endif /* SBUILD_AUTH_H */
00456 
00457 /*
00458  * Local Variables:
00459  * mode:C++
00460  * End:
00461  */

Generated on Tue Jan 18 21:48:56 2011 for sbuild by  doxygen 1.5.6