Back to index

nordugrid-arc-nox  1.1.0~rc6
User.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef __ARC_USER_H__
00004 #define __ARC_USER_H__
00005 
00006 #include <string>
00007 
00008 struct passwd;
00009 
00010 namespace Arc {
00011 
00012   class User {
00013   private:
00014     /* local name, home directory, uid and gid of this user */
00015     std::string name;
00016     std::string home;
00017     int uid;
00018     int gid;
00019     void set(const struct passwd*);
00020 
00021   public:
00022     // get current user
00023     User();
00024     User(const std::string name);
00025     User(int uid);
00026     const std::string& Name(void) const {
00027       return name;
00028     }
00029     const std::string& Home(void) const {
00030       return home;
00031     }
00032     int get_uid(void) const {
00033       return (int)uid;
00034     }
00035     int get_gid(void) const {
00036       return (int)gid;
00037     }
00038     bool operator==(const std::string n) {
00039       return (n == name);
00040     }
00041     int check_file_access(const std::string& path, int flags);
00042     /* Run command as behalf of this user */
00043     bool RunAs(std::string cmd);
00044   }; // class User
00045 
00046   // For quick switching of user id.
00063   class UserSwitch {
00064   private:
00065     int old_uid;
00066     int old_gid;
00067     bool valid;
00068   public:
00069     UserSwitch(int uid,int gid);
00070     ~UserSwitch(void);
00071     operator bool(void) { return valid; };
00072   }; // class UserSwitch
00073 
00074 
00075 } // namespace Arc
00076 
00077 #endif