1 // SecurityContext.h 2 3 #ifndef NET_FS_SECURITY_CONTEXT_H 4 #define NET_FS_SECURITY_CONTEXT_H 5 6 #include <Archivable.h> 7 #include <HashString.h> 8 #include <Locker.h> 9 #include <Node.h> 10 #include <Referenceable.h> 11 12 #include "Permissions.h" 13 #include "Vector.h" 14 15 class UserSecurityContext; 16 17 // User 18 class User : public BReferenceable, public BArchivable { 19 public: 20 User(); 21 User(BMessage* archive); 22 ~User(); 23 24 virtual status_t Archive(BMessage* archive, 25 bool deep = true) const; 26 static BArchivable* Instantiate(BMessage* archive); 27 28 29 status_t Init(const char* name, const char* password); 30 status_t InitCheck() const; 31 32 status_t Unarchive(const BMessage* archive); 33 34 const char* GetName() const; 35 const char* GetPassword() const; 36 37 private: 38 HashString fName; 39 HashString fPassword; 40 }; 41 42 // Share 43 class Share : public BReferenceable, public BArchivable { 44 public: 45 Share(); 46 Share(BMessage* archive); 47 ~Share(); 48 49 virtual status_t Archive(BMessage* archive, 50 bool deep = true) const; 51 static BArchivable* Instantiate(BMessage* archive); 52 53 status_t Init(const char* name, const node_ref& ref, 54 const char* path = NULL); 55 status_t Init(const char* name, const char* path); 56 status_t InitCheck() const; 57 58 status_t Unarchive(const BMessage* archive); 59 60 const char* GetName() const; 61 bool DoesExist() const; 62 const node_ref& GetNodeRef() const; 63 dev_t GetVolumeID() const; 64 ino_t GetNodeID() const; 65 const char* GetPath() const; 66 67 private: 68 HashString fName; 69 node_ref fNodeRef; 70 HashString fPath; 71 }; 72 73 // SecurityContext 74 class SecurityContext : public BArchivable, public BLocker { 75 public: 76 SecurityContext(); 77 SecurityContext(BMessage* archive); 78 ~SecurityContext(); 79 80 virtual status_t Archive(BMessage* archive, 81 bool deep = true) const; 82 static BArchivable* Instantiate(BMessage* archive); 83 84 status_t InitCheck() const; 85 86 status_t AddUser(const char* name, const char* password, 87 User** user = NULL); 88 status_t RemoveUser(const char* name, 89 User** user = NULL); 90 status_t RemoveUser(User* user); 91 User* FindUser(const char* name); 92 status_t AuthenticateUser(const char* name, 93 const char* password, User** user); 94 int32 CountUsers(); 95 status_t GetUsers(BMessage* users); 96 97 status_t AddShare(const char* name, const node_ref& ref, 98 Share** share = NULL); 99 status_t AddShare(const char* name, const char* path, 100 Share** share = NULL); 101 status_t RemoveShare(const char* name, 102 Share** share = NULL); 103 status_t RemoveShare(Share* share); 104 Share* FindShare(const char* name); 105 int32 CountShares(); 106 status_t GetShares(BMessage* shares); 107 108 status_t SetNodePermissions(const node_ref& ref, 109 User* user, Permissions permissions); 110 status_t SetNodePermissions(const char* path, 111 User* user, Permissions permissions); 112 void ClearNodePermissions(const node_ref& ref, 113 User* user = NULL); 114 void ClearNodePermissions(const char* path, 115 User* user = NULL); 116 Permissions GetNodePermissions(const node_ref& ref, 117 User* user); 118 Permissions GetNodePermissions(const char* path, 119 User* user); 120 121 status_t GetUserSecurityContext(User* user, 122 UserSecurityContext* userContext); 123 124 private: 125 status_t _AddNodePath(const char* path, 126 node_ref* ref = NULL); 127 status_t _AddNodePath(const node_ref& ref, 128 HashString* path = NULL); 129 status_t _EnterNodePath(const char* path, 130 const node_ref& ref); 131 bool _GetNodeForPath(const char* path, 132 node_ref* ref); 133 134 private: 135 struct UserMap; 136 struct ShareMap; 137 struct UserPath; 138 struct PermissionMap; 139 struct NodePathMap; 140 struct PathNodeMap; 141 142 UserMap* fUsers; 143 ShareMap* fShares; 144 PermissionMap* fPermissions; 145 NodePathMap* fNode2Path; 146 PathNodeMap* fPath2Node; 147 }; 148 149 #endif // NET_FS_SECURITY_CONTEXT_H 150