VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/HostDnsService.h@ 86506

Last change on this file since 86506 was 85271, checked in by vboxsync, 4 years ago

Main/HostDnsServiceDarwin.cpp,++: Wrong index types (must use CFIndex). Left a number of TODOs behind. bugref:9790

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/* $Id: HostDnsService.h 85271 2020-07-12 12:36:21Z vboxsync $ */
2/** @file
3 * Host DNS listener.
4 */
5
6/*
7 * Copyright (C) 2005-2020 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
32typedef std::list<com::Utf8Str> Utf8StrList;
33typedef Utf8StrList::iterator Utf8StrListIterator;
34
35class HostDnsMonitorProxy;
36typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
37
38class HostDnsInformation
39{
40public:
41 static const uint32_t IGNORE_SERVER_ORDER = RT_BIT_32(0);
42 static const uint32_t IGNORE_SUFFIXES = RT_BIT_32(1);
43
44public:
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 */
57class HostDnsServiceBase
58{
59 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsServiceBase);
60
61public:
62
63 static HostDnsServiceBase *createHostDnsMonitor(void);
64
65public:
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
74protected:
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
83public:
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
92private:
93
94 static DECLCALLBACK(int) threadMonitorProc(RTTHREAD, void *);
95
96protected:
97
98 mutable RTCLockMtx m_LockMtx;
99
100public: /** @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 */
109class HostDnsMonitorProxy
110{
111public:
112
113 HostDnsMonitorProxy();
114 virtual ~HostDnsMonitorProxy();
115
116public:
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
126private:
127
128 void pollGlobalExtraData(void);
129 bool updateInfo(const HostDnsInformation &info);
130
131private:
132
133 mutable RTCLockMtx m_LockMtx;
134
135 struct Data;
136 Data *m;
137};
138
139# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
140class HostDnsServiceDarwin : public HostDnsServiceBase
141{
142public:
143
144 HostDnsServiceDarwin();
145 virtual ~HostDnsServiceDarwin();
146
147public:
148
149 HRESULT init(HostDnsMonitorProxy *pProxy);
150 void uninit(void);
151
152protected:
153
154 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
155 int monitorThreadProc(void);
156
157private:
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)
166class HostDnsServiceWin : public HostDnsServiceBase
167{
168public:
169 HostDnsServiceWin();
170 virtual ~HostDnsServiceWin();
171
172public:
173
174 HRESULT init(HostDnsMonitorProxy *pProxy);
175 void uninit(void);
176
177protected:
178
179 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
180 int monitorThreadProc(void);
181
182private:
183
184 HRESULT updateInfo(void);
185
186private:
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)
194class HostDnsServiceResolvConf: public HostDnsServiceBase
195{
196public:
197
198 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsServiceBase(fThreaded), m(NULL) {}
199 virtual ~HostDnsServiceResolvConf();
200
201public:
202
203 HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName);
204 void uninit(void);
205
206 const std::string& getResolvConf(void) const;
207
208protected:
209
210 HRESULT readResolvConf(void);
211
212protected:
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 */
221class HostDnsServiceSolaris : public HostDnsServiceResolvConf
222{
223public:
224
225 HostDnsServiceSolaris() {}
226 virtual ~HostDnsServiceSolaris() {}
227
228public:
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)
237class HostDnsServiceLinux : public HostDnsServiceResolvConf
238{
239public:
240
241 HostDnsServiceLinux() : HostDnsServiceResolvConf(true) {}
242 virtual ~HostDnsServiceLinux();
243
244public:
245
246 HRESULT init(HostDnsMonitorProxy *pProxy);
247
248protected:
249
250 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
251 int monitorThreadProc(void);
252};
253
254# endif
255# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
256class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
257{
258public:
259
260 HostDnsServiceFreebsd(){}
261 virtual ~HostDnsServiceFreebsd() {}
262
263public:
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)
273class HostDnsServiceOs2 : public HostDnsServiceResolvConf
274{
275public:
276
277 HostDnsServiceOs2() {}
278 virtual ~HostDnsServiceOs2() {}
279
280public:
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 */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use