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 
8 struct passwd;
9 
10 namespace Arc {
11 
13 
15  class User {
16  private:
17  // local name, home directory, uid and gid of this user
18  std::string name;
19  std::string home;
20  int uid;
21  int gid;
22  bool valid;
23  bool set(const struct passwd*);
24 
25  public:
27  User();
29 
30  User(const std::string& name, const std::string& group="");
32 
33  User(int uid, int gid=-1);
35  operator bool() const {
36  return valid;
37  }
39  bool operator !() const {
40  return !valid;
41  }
43  const std::string& Name(void) const {
44  return name;
45  }
47  const std::string& Home(void) const {
48  return home;
49  }
51  int get_uid(void) const {
52  return (int)uid;
53  }
55  int get_gid(void) const {
56  return (int)gid;
57  }
59  bool operator==(const std::string& n) {
60  return (n == name);
61  }
63 
64  int check_file_access(const std::string& path, int flags) const;
66 
72  bool SwitchUser() const;
73  }; // class User
74 
76 
94  class UserSwitch {
95  private:
96  int old_uid;
97  int old_gid;
98  bool valid;
99  public:
101  UserSwitch(int uid,int gid);
103  ~UserSwitch(void);
105  operator bool(void) { return valid; };
106  }; // class UserSwitch
107 
108 
109 } // namespace Arc
110 
111 #endif