ARC SDK
User.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_USER_H__
4 #define __ARC_USER_H__
5 
6 #include <string>
7 #include <arc/Thread.h>
8 
9 struct passwd;
10 
11 namespace Arc {
12 
14 
16  class User {
17  private:
18  // local name, home directory, uid and gid of this user
19  std::string name;
20  std::string home;
21  int uid;
22  int gid;
23  bool valid;
24  bool set(const struct passwd*);
25 
26  public:
28  User();
30 
31  User(const std::string& name, const std::string& group="");
33 
34  User(int uid, int gid=-1);
36  operator bool() const {
37  return valid;
38  }
40  bool operator !() const {
41  return !valid;
42  }
44  const std::string& Name(void) const {
45  return name;
46  }
48  const std::string& Home(void) const {
49  return home;
50  }
52  int get_uid(void) const {
53  return (int)uid;
54  }
56  int get_gid(void) const {
57  return (int)gid;
58  }
60  bool operator==(const std::string& n) {
61  return (n == name);
62  }
64 
65  int check_file_access(const std::string& path, int flags) const;
67 
73  bool SwitchUser() const;
74  }; // class User
75 
77 
95  class UserSwitch {
96  private:
97  static SimpleCondition suid_lock;
98  static int suid_count;
99  static int suid_uid_orig;
100  static int suid_gid_orig;
101  bool valid;
102  public:
104  UserSwitch(int uid,int gid);
106  ~UserSwitch(void);
108  operator bool(void) { return valid; };
111  void resetPostFork(void);
112  }; // class UserSwitch
113 
114 
115 } // namespace Arc
116 
117 #endif
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
Simple triggered condition.
Definition: Thread.h:150
void resetPostFork(void)
bool operator==(const std::string &n)
Returns true if this User&#39;s name is the same as n.
Definition: User.h:60
UserSwitch(int uid, int gid)
Switch uid and gid.
const std::string & Name(void) const
Returns the name of this user.
Definition: User.h:44
bool SwitchUser() const
Change the owner of the current process.
int check_file_access(const std::string &path, int flags) const
Check if this User has the rights specified by flags on the given path.
int get_gid(void) const
Returns the user&#39;s gid.
Definition: User.h:56
bool operator!() const
Returns true is this is not a valid user.
Definition: User.h:40
~UserSwitch(void)
Switch back to old uid and gid and release lock on this class.
User()
Construct user from current process owner.
Class for temporary switching of user id.
Definition: User.h:95
const std::string & Home(void) const
Returns the path to the user&#39;s home directory.
Definition: User.h:48
Platform independent representation of system user.
Definition: User.h:16
int get_uid(void) const
Returns the user&#39;s uid.
Definition: User.h:52