VirtualBox

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

Last change on this file since 78242 was 78030, checked in by vboxsync, 6 years ago

Main/HostDnsServiceDarwin: Preliminary fix to make VBoxSVC start on MacOS again; more work needed in that area, code still is too convoluted.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: HostDnsService.h 78030 2019-04-05 19:08:10Z 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
31typedef std::list<com::Utf8Str> Utf8StrList;
32typedef Utf8StrList::iterator Utf8StrListIterator;
33
34class HostDnsMonitorProxy;
35typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
36
37class 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 */
55class HostDnsServiceBase
56{
57 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsServiceBase);
58
59public:
60
61 static HostDnsServiceBase *createHostDnsMonitor(void);
62
63public:
64
65 /* @note: method will wait till client call
66 HostDnsService::monitorThreadInitializationDone() */
67 virtual HRESULT init(HostDnsMonitorProxy *pProxy);
68 virtual void uninit(void);
69
70protected:
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
80public:
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
89private:
90
91 static DECLCALLBACK(int) threadMonitorProc(RTTHREAD, void *);
92
93protected:
94
95 mutable RTCLockMtx m_LockMtx;
96
97public: /** @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 */
106class HostDnsMonitorProxy
107{
108public:
109
110 HostDnsMonitorProxy();
111 virtual ~HostDnsMonitorProxy();
112
113public:
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
123private:
124
125 void pollGlobalExtraData(void);
126 bool updateInfo(const HostDnsInformation &info);
127
128private:
129
130 mutable RTCLockMtx m_LockMtx;
131
132 struct Data;
133 Data *m;
134};
135
136# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
137class HostDnsServiceDarwin : public HostDnsServiceBase
138{
139public:
140
141 HostDnsServiceDarwin();
142 virtual ~HostDnsServiceDarwin();
143
144public:
145
146 HRESULT init(HostDnsMonitorProxy *pProxy);
147 void uninit(void);
148
149protected:
150
151 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
152 int monitorThreadProc(void);
153
154private:
155
156 int updateInfo(void);
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)
163class HostDnsServiceWin : public HostDnsServiceBase
164{
165public:
166 HostDnsServiceWin();
167 virtual ~HostDnsServiceWin();
168
169public:
170
171 HRESULT init(HostDnsMonitorProxy *pProxy);
172 void uninit(void);
173
174protected:
175
176 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
177 int monitorThreadProc(void);
178
179private:
180
181 HRESULT updateInfo(void);
182
183private:
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)
191class HostDnsServiceResolvConf: public HostDnsServiceBase
192{
193public:
194
195 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsServiceBase(fThreaded), m(NULL) {}
196 virtual ~HostDnsServiceResolvConf();
197
198public:
199
200 HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName);
201 void uninit(void);
202
203 const std::string& getResolvConf(void) const;
204
205protected:
206
207 HRESULT readResolvConf(void);
208
209protected:
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 */
218class HostDnsServiceSolaris : public HostDnsServiceResolvConf
219{
220public:
221
222 HostDnsServiceSolaris() {}
223 virtual ~HostDnsServiceSolaris() {}
224
225public:
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)
234class HostDnsServiceLinux : public HostDnsServiceResolvConf
235{
236public:
237
238 HostDnsServiceLinux() : HostDnsServiceResolvConf(true) {}
239 virtual ~HostDnsServiceLinux();
240
241public:
242
243 HRESULT init(HostDnsMonitorProxy *pProxy);
244
245protected:
246
247 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
248 int monitorThreadProc(void);
249};
250
251# endif
252# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
253class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
254{
255public:
256
257 HostDnsServiceFreebsd(){}
258 virtual ~HostDnsServiceFreebsd() {}
259
260public:
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)
270class HostDnsServiceOs2 : public HostDnsServiceResolvConf
271{
272public:
273
274 HostDnsServiceOs2() {}
275 virtual ~HostDnsServiceOs2() {}
276
277public:
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 */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette