1 | /* $Id: HostDnsService.h 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Host DNS listener.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2005-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef MAIN_INCLUDED_SRC_src_server_HostDnsService_h
|
---|
19 | #define MAIN_INCLUDED_SRC_src_server_HostDnsService_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 | #include "VirtualBoxBase.h"
|
---|
24 |
|
---|
25 | #include <iprt/err.h> /* VERR_IGNORED */
|
---|
26 | #include <iprt/cpp/lock.h>
|
---|
27 |
|
---|
28 | #include <list>
|
---|
29 | #include <iprt/sanitized/string>
|
---|
30 | #include <vector>
|
---|
31 |
|
---|
32 | typedef std::list<com::Utf8Str> Utf8StrList;
|
---|
33 | typedef Utf8StrList::iterator Utf8StrListIterator;
|
---|
34 |
|
---|
35 | class HostDnsMonitorProxy;
|
---|
36 | typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
|
---|
37 |
|
---|
38 | class HostDnsInformation
|
---|
39 | {
|
---|
40 | public:
|
---|
41 | static const uint32_t IGNORE_SERVER_ORDER = RT_BIT_32(0);
|
---|
42 | static const uint32_t IGNORE_SUFFIXES = RT_BIT_32(1);
|
---|
43 |
|
---|
44 | public:
|
---|
45 | /** @todo r=bird: Why on earth are we using std::string and not Utf8Str? */
|
---|
46 | std::vector<std::string> servers;
|
---|
47 | std::string domain;
|
---|
48 | std::vector<std::string> searchList;
|
---|
49 | bool equals(const HostDnsInformation &, uint32_t fLaxComparison = 0) const;
|
---|
50 | };
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Base class for host DNS service implementations.
|
---|
54 | * This class supposed to be a real DNS monitor object as a singleton,
|
---|
55 | * so it lifecycle starts and ends together with VBoxSVC.
|
---|
56 | */
|
---|
57 | class HostDnsServiceBase
|
---|
58 | {
|
---|
59 | DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsServiceBase);
|
---|
60 |
|
---|
61 | public:
|
---|
62 |
|
---|
63 | static HostDnsServiceBase *createHostDnsMonitor(void);
|
---|
64 |
|
---|
65 | public:
|
---|
66 |
|
---|
67 | /* @note: method will wait till client call
|
---|
68 | HostDnsService::monitorThreadInitializationDone() */
|
---|
69 | virtual HRESULT init(HostDnsMonitorProxy *pProxy);
|
---|
70 | virtual void uninit(void);
|
---|
71 |
|
---|
72 | virtual ~HostDnsServiceBase();
|
---|
73 |
|
---|
74 | protected:
|
---|
75 |
|
---|
76 | explicit HostDnsServiceBase(bool fThreaded = false);
|
---|
77 |
|
---|
78 | void setInfo(const HostDnsInformation &);
|
---|
79 |
|
---|
80 | /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
|
---|
81 | void onMonitorThreadInitDone();
|
---|
82 |
|
---|
83 | public:
|
---|
84 |
|
---|
85 | virtual int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs)
|
---|
86 | {
|
---|
87 | RT_NOREF(uTimeoutMs); AssertFailed(); return VERR_NOT_IMPLEMENTED;
|
---|
88 | }
|
---|
89 |
|
---|
90 | virtual int monitorThreadProc(void) { AssertFailed(); return VERR_NOT_IMPLEMENTED; }
|
---|
91 |
|
---|
92 | private:
|
---|
93 |
|
---|
94 | static DECLCALLBACK(int) threadMonitorProc(RTTHREAD, void *);
|
---|
95 |
|
---|
96 | protected:
|
---|
97 |
|
---|
98 | mutable RTCLockMtx m_LockMtx;
|
---|
99 |
|
---|
100 | public: /** @todo r=andy Why is this public? */
|
---|
101 |
|
---|
102 | struct Data;
|
---|
103 | Data *m;
|
---|
104 | };
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
|
---|
108 | */
|
---|
109 | class HostDnsMonitorProxy
|
---|
110 | {
|
---|
111 | public:
|
---|
112 |
|
---|
113 | HostDnsMonitorProxy();
|
---|
114 | virtual ~HostDnsMonitorProxy();
|
---|
115 |
|
---|
116 | public:
|
---|
117 |
|
---|
118 | HRESULT init(VirtualBox *virtualbox);
|
---|
119 | void uninit(void);
|
---|
120 | void notify(const HostDnsInformation &info);
|
---|
121 |
|
---|
122 | HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
|
---|
123 | HRESULT GetDomainName(com::Utf8Str *pDomainName);
|
---|
124 | HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
|
---|
125 |
|
---|
126 | private:
|
---|
127 |
|
---|
128 | void pollGlobalExtraData(void);
|
---|
129 | bool updateInfo(const HostDnsInformation &info);
|
---|
130 |
|
---|
131 | private:
|
---|
132 |
|
---|
133 | mutable RTCLockMtx m_LockMtx;
|
---|
134 |
|
---|
135 | struct Data;
|
---|
136 | Data *m;
|
---|
137 | };
|
---|
138 |
|
---|
139 | # if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
|
---|
140 | class HostDnsServiceDarwin : public HostDnsServiceBase
|
---|
141 | {
|
---|
142 | public:
|
---|
143 |
|
---|
144 | HostDnsServiceDarwin();
|
---|
145 | virtual ~HostDnsServiceDarwin();
|
---|
146 |
|
---|
147 | public:
|
---|
148 |
|
---|
149 | HRESULT init(HostDnsMonitorProxy *pProxy);
|
---|
150 | void uninit(void);
|
---|
151 |
|
---|
152 | protected:
|
---|
153 |
|
---|
154 | int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
|
---|
155 | int monitorThreadProc(void);
|
---|
156 |
|
---|
157 | private:
|
---|
158 |
|
---|
159 | int updateInfo(void);
|
---|
160 | static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
|
---|
161 | struct Data;
|
---|
162 | Data *m;
|
---|
163 | };
|
---|
164 | # endif
|
---|
165 | # if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
|
---|
166 | class HostDnsServiceWin : public HostDnsServiceBase
|
---|
167 | {
|
---|
168 | public:
|
---|
169 | HostDnsServiceWin();
|
---|
170 | virtual ~HostDnsServiceWin();
|
---|
171 |
|
---|
172 | public:
|
---|
173 |
|
---|
174 | HRESULT init(HostDnsMonitorProxy *pProxy);
|
---|
175 | void uninit(void);
|
---|
176 |
|
---|
177 | protected:
|
---|
178 |
|
---|
179 | int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
|
---|
180 | int monitorThreadProc(void);
|
---|
181 |
|
---|
182 | private:
|
---|
183 |
|
---|
184 | HRESULT updateInfo(void);
|
---|
185 |
|
---|
186 | private:
|
---|
187 |
|
---|
188 | struct Data;
|
---|
189 | Data *m;
|
---|
190 | };
|
---|
191 | # endif
|
---|
192 | # if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \
|
---|
193 | || defined(DOXYGEN_RUNNING)
|
---|
194 | class HostDnsServiceResolvConf: public HostDnsServiceBase
|
---|
195 | {
|
---|
196 | public:
|
---|
197 |
|
---|
198 | explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsServiceBase(fThreaded), m(NULL) {}
|
---|
199 | virtual ~HostDnsServiceResolvConf();
|
---|
200 |
|
---|
201 | public:
|
---|
202 |
|
---|
203 | HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName);
|
---|
204 | void uninit(void);
|
---|
205 |
|
---|
206 | const std::string& getResolvConf(void) const;
|
---|
207 |
|
---|
208 | protected:
|
---|
209 |
|
---|
210 | HRESULT readResolvConf(void);
|
---|
211 |
|
---|
212 | protected:
|
---|
213 |
|
---|
214 | struct Data;
|
---|
215 | Data *m;
|
---|
216 | };
|
---|
217 | # if defined(RT_OS_SOLARIS) || defined(DOXYGEN_RUNNING)
|
---|
218 | /**
|
---|
219 | * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
|
---|
220 | */
|
---|
221 | class HostDnsServiceSolaris : public HostDnsServiceResolvConf
|
---|
222 | {
|
---|
223 | public:
|
---|
224 |
|
---|
225 | HostDnsServiceSolaris() {}
|
---|
226 | virtual ~HostDnsServiceSolaris() {}
|
---|
227 |
|
---|
228 | public:
|
---|
229 |
|
---|
230 | virtual HRESULT init(HostDnsMonitorProxy *pProxy) {
|
---|
231 | return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
|
---|
232 | }
|
---|
233 | };
|
---|
234 |
|
---|
235 | # endif
|
---|
236 | # if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
|
---|
237 | class HostDnsServiceLinux : public HostDnsServiceResolvConf
|
---|
238 | {
|
---|
239 | public:
|
---|
240 |
|
---|
241 | HostDnsServiceLinux() : HostDnsServiceResolvConf(true) {}
|
---|
242 | virtual ~HostDnsServiceLinux();
|
---|
243 |
|
---|
244 | public:
|
---|
245 |
|
---|
246 | HRESULT init(HostDnsMonitorProxy *pProxy);
|
---|
247 |
|
---|
248 | protected:
|
---|
249 |
|
---|
250 | int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
|
---|
251 | int monitorThreadProc(void);
|
---|
252 | };
|
---|
253 |
|
---|
254 | # endif
|
---|
255 | # if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
|
---|
256 | class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
|
---|
257 | {
|
---|
258 | public:
|
---|
259 |
|
---|
260 | HostDnsServiceFreebsd(){}
|
---|
261 | virtual ~HostDnsServiceFreebsd() {}
|
---|
262 |
|
---|
263 | public:
|
---|
264 |
|
---|
265 | virtual HRESULT init(HostDnsMonitorProxy *pProxy)
|
---|
266 | {
|
---|
267 | return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
|
---|
268 | }
|
---|
269 | };
|
---|
270 |
|
---|
271 | # endif
|
---|
272 | # if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
|
---|
273 | class HostDnsServiceOs2 : public HostDnsServiceResolvConf
|
---|
274 | {
|
---|
275 | public:
|
---|
276 |
|
---|
277 | HostDnsServiceOs2() {}
|
---|
278 | virtual ~HostDnsServiceOs2() {}
|
---|
279 |
|
---|
280 | public:
|
---|
281 |
|
---|
282 | /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
|
---|
283 | virtual HRESULT init(HostDnsMonitorProxy *pProxy)
|
---|
284 | {
|
---|
285 | return HostDnsServiceResolvConf::init(pProxy, "\\MPTN\\ETC\\RESOLV2");
|
---|
286 | }
|
---|
287 | };
|
---|
288 |
|
---|
289 | # endif
|
---|
290 | # endif
|
---|
291 |
|
---|
292 | #endif /* !MAIN_INCLUDED_SRC_src_server_HostDnsService_h */
|
---|