|
22 | 22 | #endif
|
23 | 23 |
|
24 | 24 | #include "IPCPrivate.hpp"
|
25 |
| -#include "Common/Thread.hpp" |
26 | 25 |
|
27 | 26 | #include "Devices.pb.h"
|
28 | 27 | #include "Policy.pb.h"
|
|
32 | 31 | #include "usbguard/Typedefs.hpp"
|
33 | 32 | #include "usbguard/IPCServer.hpp"
|
34 | 33 |
|
35 |
| -#include <map> |
36 |
| -#include <mutex> |
37 |
| -#include <future> |
38 |
| - |
39 |
| -#include <qb/qbipcs.h> |
40 |
| -#include <qb/qbloop.h> |
41 |
| - |
42 | 34 | namespace usbguard
|
43 | 35 | {
|
44 | 36 | class IPCServerPrivate
|
45 | 37 | {
|
46 |
| - using MessageHandler = IPC::MessageHandler<IPCServerPrivate>; |
47 |
| - |
48 | 38 | public:
|
49 |
| - IPCServerPrivate(IPCServer& p_instance); |
50 |
| - ~IPCServerPrivate(); |
| 39 | + virtual ~IPCServerPrivate() = default; |
51 | 40 |
|
52 |
| - void start(); |
53 |
| - void stop(); |
| 41 | + virtual void start() = 0; |
| 42 | + virtual void stop() = 0; |
54 | 43 |
|
55 |
| - void DevicePresenceChanged(uint32_t id, |
| 44 | + virtual void DevicePresenceChanged(uint32_t id, |
56 | 45 | DeviceManager::EventType event,
|
57 | 46 | Rule::Target target,
|
58 |
| - const std::string& device_rule); |
| 47 | + const std::string& device_rule) = 0; |
59 | 48 |
|
60 |
| - void DevicePolicyChanged(uint32_t id, |
| 49 | + virtual void DevicePolicyChanged(uint32_t id, |
61 | 50 | Rule::Target target_old,
|
62 | 51 | Rule::Target target_new,
|
63 | 52 | const std::string& device_rule,
|
64 |
| - uint32_t rule_id); |
| 53 | + uint32_t rule_id) = 0; |
65 | 54 |
|
66 |
| - void PropertyParameterChanged(const std::string& name, |
| 55 | + virtual void PropertyParameterChanged(const std::string& name, |
67 | 56 | const std::string& value_old,
|
68 |
| - const std::string& value_new); |
| 57 | + const std::string& value_new) = 0; |
69 | 58 |
|
70 |
| - void ExceptionMessage(const std::string& context, |
| 59 | + virtual void ExceptionMessage(const std::string& context, |
71 | 60 | const std::string& object,
|
72 | 61 | const std::string& reason,
|
73 |
| - uint64_t request_id = 0); |
74 |
| - |
75 |
| - void addAllowedUID(uid_t uid, const IPCServer::AccessControl& ac); |
76 |
| - void addAllowedGID(gid_t gid, const IPCServer::AccessControl& ac); |
77 |
| - void addAllowedUsername(const std::string& username, const IPCServer::AccessControl& ac); |
78 |
| - void addAllowedGroupname(const std::string& groupname, const IPCServer::AccessControl& ac); |
79 |
| - |
80 |
| - private: |
81 |
| - struct ClientContext { |
82 |
| - IPCServer::AccessControl access_control; |
83 |
| - std::mutex mutex; |
84 |
| - }; |
85 |
| - |
86 |
| - void initIPC(); |
87 |
| - void finiIPC(); |
88 |
| - |
89 |
| - void thread(); |
90 |
| - void wakeup(); |
91 |
| - void destruct(); |
92 |
| - |
93 |
| - static int32_t qbPollWakeupFn(int32_t fd, int32_t revents, void* data); |
94 |
| - static int32_t qbIPCConnectionAcceptFn(qb_ipcs_connection_t*, uid_t, gid_t); |
95 |
| - static void qbIPCConnectionCreatedFn(qb_ipcs_connection_t*); |
96 |
| - static void qbIPCConnectionDestroyedFn(qb_ipcs_connection_t*); |
97 |
| - static int32_t qbIPCConnectionClosedFn(qb_ipcs_connection_t*); |
98 |
| - static int32_t qbIPCMessageProcessFn(qb_ipcs_connection_t*, void*, size_t); |
99 |
| - |
100 |
| - static int32_t qbIPCJobAdd(enum qb_loop_priority p, void* data, qb_loop_job_dispatch_fn fn); |
101 |
| - static int32_t qbIPCDispatchAdd(enum qb_loop_priority p, int32_t fd, int32_t evts, void* data, qb_ipcs_dispatch_fn_t fn); |
102 |
| - static int32_t qbIPCDispatchMod(enum qb_loop_priority p, int32_t fd, int32_t evts, void* data, qb_ipcs_dispatch_fn_t fn); |
103 |
| - static int32_t qbIPCDispatchDel(int32_t fd); |
104 |
| - static int32_t qbIPCConnectionClientPID(qb_ipcs_connection_t* connection); |
105 |
| - |
106 |
| - bool hasACLEntries() const; |
107 |
| - bool qbIPCConnectionAllowed(uid_t uid, gid_t gid, IPCServer::AccessControl* const ac_ptr) const; |
108 |
| - bool authenticateIPCConnectionDAC(uid_t uid, gid_t gid, IPCServer::AccessControl* const ac_ptr = nullptr) const; |
109 |
| - |
110 |
| - bool matchACLByUID(uid_t uid, IPCServer::AccessControl* const ac_ptr) const; |
111 |
| - bool matchACLByGID(gid_t gid, IPCServer::AccessControl* const ac_ptr) const; |
112 |
| - bool matchACLByName(uid_t uid, gid_t gid, IPCServer::AccessControl* const ac_ptr) const; |
113 |
| - |
114 |
| - static std::string getNameFromUID(uid_t uid); |
115 |
| - static std::string getNameFromGID(gid_t gid); |
116 |
| - static std::vector<std::string> getGroupMemberNames(gid_t gid); |
117 |
| - static std::vector<std::string> getGroupMemberNames(const std::string& groupname); |
118 |
| - |
119 |
| - static void qbIPCSendMessage(qb_ipcs_connection_t* qb_conn, const IPC::MessagePointer& message); |
120 |
| - static IPCServer::AccessControl::Section messageTypeNameToAccessControlSection(const std::string& name); |
121 |
| - void qbIPCBroadcastData(const struct iovec* iov, size_t iov_len, IPCServer::AccessControl::Section section); |
122 |
| - void qbIPCBroadcastMessage(const IPC::MessagePointer& message); |
123 |
| - void qbIPCBroadcastMessage(const IPC::MessageType* message); |
124 |
| - |
125 |
| - IPC::MessagePointer handleIPCPayload(const uint32_t payload_type, const std::string& payload, |
126 |
| - const IPCServer::AccessControl* const access_control); |
127 |
| - |
128 |
| - template<class T> |
129 |
| - void registerHandler(MessageHandler::HandlerType method, IPCServer::AccessControl::Section section, |
130 |
| - IPCServer::AccessControl::Privilege privilege) |
131 |
| - { |
132 |
| - const uint32_t type_number = IPC::messageTypeNameToNumber(T::default_instance().GetTypeName()); |
133 |
| - _handlers.emplace(type_number, MessageHandler::create<T>(*this, method, section, privilege)); |
134 |
| - } |
135 |
| - |
136 |
| - void handleAppendRule(IPC::MessagePointer& request, IPC::MessagePointer& response); |
137 |
| - void handleRemoveRule(IPC::MessagePointer& request, IPC::MessagePointer& response); |
138 |
| - void handleListRules(IPC::MessagePointer& request, IPC::MessagePointer& response); |
139 |
| - |
140 |
| - void handleApplyDevicePolicy(IPC::MessagePointer& request, IPC::MessagePointer& response); |
141 |
| - void handleListDevices(IPC::MessagePointer& request, IPC::MessagePointer& response); |
142 |
| - |
143 |
| - void handleSetParameter(IPC::MessagePointer& request, IPC::MessagePointer& response); |
144 |
| - void handleGetParameter(IPC::MessagePointer& request, IPC::MessagePointer& response); |
145 |
| - |
146 |
| - IPCServer& _p_instance; |
147 |
| - |
148 |
| - qb_loop_t* _qb_loop; |
149 |
| - qb_ipcs_service_t* _qb_service; |
150 |
| - int _wakeup_fd; |
151 |
| - |
152 |
| - std::unordered_map<uid_t, IPCServer::AccessControl> _allowed_uids; |
153 |
| - std::unordered_map<gid_t, IPCServer::AccessControl> _allowed_gids; |
154 |
| - std::unordered_map<std::string, IPCServer::AccessControl> _allowed_usernames; |
155 |
| - std::unordered_map<std::string, IPCServer::AccessControl> _allowed_groupnames; |
156 |
| - |
157 |
| - Thread<IPCServerPrivate> _thread; |
| 62 | + uint64_t request_id = 0) = 0; |
158 | 63 |
|
159 |
| - std::unordered_map<uint32_t, MessageHandler> _handlers; |
| 64 | + virtual void addAllowedUID(uid_t uid, const IPCServer::AccessControl& ac) = 0; |
| 65 | + virtual void addAllowedGID(gid_t gid, const IPCServer::AccessControl& ac) = 0; |
| 66 | + virtual void addAllowedUsername(const std::string& username, const IPCServer::AccessControl& ac) = 0; |
| 67 | + virtual void addAllowedGroupname(const std::string& groupname, const IPCServer::AccessControl& ac) = 0; |
160 | 68 | };
|
161 | 69 | } /* namespace usbguard */
|
162 | 70 |
|
|
0 commit comments