1 | /* $Id: HostDnsService.h 78941 2019-06-03 19:05:16Z 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 | virtual ~HostDnsServiceBase();
|
---|
71 |
|
---|
72 | protected:
|
---|
73 |
|
---|
74 | explicit HostDnsServiceBase(bool fThreaded = false);
|
---|
75 |
|
---|
76 | void setInfo(const HostDnsInformation &);
|
---|
77 |
|
---|
78 | /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
|
---|
79 | void onMonitorThreadInitDone();
|
---|
80 |
|
---|
81 | public:
|
---|
82 |
|
---|
83 | virtual int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs)
|
---|
84 | {
|
---|
85 | RT_NOREF(uTimeoutMs); AssertFailed(); return VERR_NOT_IMPLEMENTED;
|
---|
86 | }
|
---|
87 |
|
---|
88 | virtual int monitorThreadProc(void) { AssertFailed(); return VERR_NOT_IMPLEMENTED; }
|
---|
89 |
|
---|
90 | private:
|
---|
91 |
|
---|
92 | static DECLCALLBACK(int) threadMonitorProc(RTTHREAD, void *);
|
---|
93 |
|
---|
94 | protected:
|
---|
95 |
|
---|
96 | mutable RTCLockMtx m_LockMtx;
|
---|
97 |
|
---|
98 | public: /** @todo r=andy Why is this public? */
|
---|
99 |
|
---|
100 | struct Data;
|
---|
101 | Data *m;
|
---|
102 | };
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
|
---|
106 | */
|
---|
107 | class HostDnsMonitorProxy
|
---|
108 | {
|
---|
109 | public:
|
---|
110 |
|
---|
111 | HostDnsMonitorProxy();
|
---|
112 | virtual ~HostDnsMonitorProxy();
|
---|
113 |
|
---|
114 | public:
|
---|
115 |
|
---|
116 | HRESULT init(VirtualBox *virtualbox);
|
---|
117 | void uninit(void);
|
---|
118 | void notify(const HostDnsInformation &info);
|
---|
119 |
|
---|
120 | HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
|
---|
121 | HRESULT GetDomainName(com::Utf8Str *pDomainName);
|
---|
122 | HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
|
---|
123 |
|
---|
124 | private:
|
---|
125 |
|
---|
126 | void pollGlobalExtraData(void);
|
---|
127 | bool updateInfo(const HostDnsInformation &info);
|
---|
128 |
|
---|
129 | private:
|
---|
130 |
|
---|
131 | mutable RTCLockMtx m_LockMtx;
|
---|
132 |
|
---|
133 | struct Data;
|
---|
134 | Data *m;
|
---|
135 | };
|
---|
136 |
|
---|
137 | # if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
|
---|
138 | class HostDnsServiceDarwin : public HostDnsServiceBase
|
---|
139 | {
|
---|
140 | public:
|
---|
141 |
|
---|
142 | HostDnsServiceDarwin();
|
---|
143 | virtual ~HostDnsServiceDarwin();
|
---|
144 |
|
---|
145 | public:
|
---|
146 |
|
---|
147 | HRESULT init(HostDnsMonitorProxy *pProxy);
|
---|
148 | void uninit(void);
|
---|
149 |
|
---|
150 | protected:
|
---|
151 |
|
---|
152 | int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
|
---|
153 | int monitorThreadProc(void);
|
---|
154 |
|
---|
155 | private:
|
---|
156 |
|
---|
157 | int updateInfo(void);
|
---|
158 | static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
|
---|
159 | struct Data;
|
---|
160 | Data *m;
|
---|
161 | };
|
---|
162 | # endif
|
---|
163 | # if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
|
---|
164 | class HostDnsServiceWin : public HostDnsServiceBase
|
---|
165 | {
|
---|
166 | public:
|
---|
167 | HostDnsServiceWin();
|
---|
168 | virtual ~HostDnsServiceWin();
|
---|
169 |
|
---|
170 | public:
|
---|
171 |
|
---|
172 | HRESULT init(HostDnsMonitorProxy *pProxy);
|
---|
173 | void uninit(void);
|
---|
174 |
|
---|
175 | protected:
|
---|
176 |
|
---|
177 | int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
|
---|
178 | int monitorThreadProc(void);
|
---|
179 |
|
---|
180 | private:
|
---|
181 |
|
---|
182 | HRESULT updateInfo(void);
|
---|
183 |
|
---|
184 | private:
|
---|
185 |
|
---|
186 | struct Data;
|
---|
187 | Data *m;
|
---|
188 | };
|
---|
189 | # endif
|
---|
190 | # if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \
|
---|
191 | || defined(DOXYGEN_RUNNING)
|
---|
192 | class HostDnsServiceResolvConf: public HostDnsServiceBase
|
---|
193 | {
|
---|
194 | public:
|
---|
195 |
|
---|
196 | explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsServiceBase(fThreaded), m(NULL) {}
|
---|
197 | virtual ~HostDnsServiceResolvConf();
|
---|
198 |
|
---|
199 | public:
|
---|
200 |
|
---|
201 | HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName);
|
---|
202 | void uninit(void);
|
---|
203 |
|
---|
204 | const std::string& getResolvConf(void) const;
|
---|
205 |
|
---|
206 | protected:
|
---|
207 |
|
---|
208 | HRESULT readResolvConf(void);
|
---|
209 |
|
---|
210 | protected:
|
---|
211 |
|
---|
212 | struct Data;
|
---|
213 | Data *m;
|
---|
214 | };
|
---|
215 | # if defined(RT_OS_SOLARIS) || defined(DOXYGEN_RUNNING)
|
---|
216 | /**
|
---|
217 | * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
|
---|
218 | */
|
---|
219 | class HostDnsServiceSolaris : public HostDnsServiceResolvConf
|
---|
220 | {
|
---|
221 | public:
|
---|
222 |
|
---|
223 | HostDnsServiceSolaris() {}
|
---|
224 | virtual ~HostDnsServiceSolaris() {}
|
---|
225 |
|
---|
226 | public:
|
---|
227 |
|
---|
228 | virtual HRESULT init(HostDnsMonitorProxy *pProxy) {
|
---|
229 | return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
|
---|
230 | }
|
---|
231 | };
|
---|
232 |
|
---|
233 | # endif
|
---|
234 | # if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
|
---|
235 | class HostDnsServiceLinux : public HostDnsServiceResolvConf
|
---|
236 | {
|
---|
237 | public:
|
---|
238 |
|
---|
239 | HostDnsServiceLinux() : HostDnsServiceResolvConf(true) {}
|
---|
240 | virtual ~HostDnsServiceLinux();
|
---|
241 |
|
---|
242 | public:
|
---|
243 |
|
---|
244 | HRESULT init(HostDnsMonitorProxy *pProxy);
|
---|
245 |
|
---|
246 | protected:
|
---|
247 |
|
---|
248 | int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
|
---|
249 | int monitorThreadProc(void);
|
---|
250 | };
|
---|
251 |
|
---|
252 | # endif
|
---|
253 | # if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
|
---|
254 | class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
|
---|
255 | {
|
---|
256 | public:
|
---|
257 |
|
---|
258 | HostDnsServiceFreebsd(){}
|
---|
259 | virtual ~HostDnsServiceFreebsd() {}
|
---|
260 |
|
---|
261 | public:
|
---|
262 |
|
---|
263 | virtual HRESULT init(HostDnsMonitorProxy *pProxy)
|
---|
264 | {
|
---|
265 | return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
|
---|
266 | }
|
---|
267 | };
|
---|
268 |
|
---|
269 | # endif
|
---|
270 | # if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
|
---|
271 | class HostDnsServiceOs2 : public HostDnsServiceResolvConf
|
---|
272 | {
|
---|
273 | public:
|
---|
274 |
|
---|
275 | HostDnsServiceOs2() {}
|
---|
276 | virtual ~HostDnsServiceOs2() {}
|
---|
277 |
|
---|
278 | public:
|
---|
279 |
|
---|
280 | /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
|
---|
281 | virtual HRESULT init(HostDnsMonitorProxy *pProxy)
|
---|
282 | {
|
---|
283 | return HostDnsServiceResolvConf::init(pProxy, "\\MPTN\\ETC\\RESOLV2");
|
---|
284 | }
|
---|
285 | };
|
---|
286 |
|
---|
287 | # endif
|
---|
288 | # endif
|
---|
289 |
|
---|
290 | #endif /* !MAIN_INCLUDED_SRC_src_server_HostDnsService_h */
|
---|