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