VirtualBox

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

Last change on this file since 79812 was 78941, checked in by vboxsync, 6 years ago

Main/HostDnsService: Fixed a memory leak; was not deleting the monitor implementation instance on uninit.

  • 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 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
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
70 virtual ~HostDnsServiceBase();
71
72protected:
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
81public:
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
90private:
91
92 static DECLCALLBACK(int) threadMonitorProc(RTTHREAD, void *);
93
94protected:
95
96 mutable RTCLockMtx m_LockMtx;
97
98public: /** @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 */
107class HostDnsMonitorProxy
108{
109public:
110
111 HostDnsMonitorProxy();
112 virtual ~HostDnsMonitorProxy();
113
114public:
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
124private:
125
126 void pollGlobalExtraData(void);
127 bool updateInfo(const HostDnsInformation &info);
128
129private:
130
131 mutable RTCLockMtx m_LockMtx;
132
133 struct Data;
134 Data *m;
135};
136
137# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
138class HostDnsServiceDarwin : public HostDnsServiceBase
139{
140public:
141
142 HostDnsServiceDarwin();
143 virtual ~HostDnsServiceDarwin();
144
145public:
146
147 HRESULT init(HostDnsMonitorProxy *pProxy);
148 void uninit(void);
149
150protected:
151
152 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
153 int monitorThreadProc(void);
154
155private:
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)
164class HostDnsServiceWin : public HostDnsServiceBase
165{
166public:
167 HostDnsServiceWin();
168 virtual ~HostDnsServiceWin();
169
170public:
171
172 HRESULT init(HostDnsMonitorProxy *pProxy);
173 void uninit(void);
174
175protected:
176
177 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
178 int monitorThreadProc(void);
179
180private:
181
182 HRESULT updateInfo(void);
183
184private:
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)
192class HostDnsServiceResolvConf: public HostDnsServiceBase
193{
194public:
195
196 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsServiceBase(fThreaded), m(NULL) {}
197 virtual ~HostDnsServiceResolvConf();
198
199public:
200
201 HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName);
202 void uninit(void);
203
204 const std::string& getResolvConf(void) const;
205
206protected:
207
208 HRESULT readResolvConf(void);
209
210protected:
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 */
219class HostDnsServiceSolaris : public HostDnsServiceResolvConf
220{
221public:
222
223 HostDnsServiceSolaris() {}
224 virtual ~HostDnsServiceSolaris() {}
225
226public:
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)
235class HostDnsServiceLinux : public HostDnsServiceResolvConf
236{
237public:
238
239 HostDnsServiceLinux() : HostDnsServiceResolvConf(true) {}
240 virtual ~HostDnsServiceLinux();
241
242public:
243
244 HRESULT init(HostDnsMonitorProxy *pProxy);
245
246protected:
247
248 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
249 int monitorThreadProc(void);
250};
251
252# endif
253# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
254class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
255{
256public:
257
258 HostDnsServiceFreebsd(){}
259 virtual ~HostDnsServiceFreebsd() {}
260
261public:
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)
271class HostDnsServiceOs2 : public HostDnsServiceResolvConf
272{
273public:
274
275 HostDnsServiceOs2() {}
276 virtual ~HostDnsServiceOs2() {}
277
278public:
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 */
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