VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 7 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* $Id: HostDnsService.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * Host DNS listener.
4 */
5
6/*
7 * Copyright (C) 2005-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_SRC_src_server_HostDnsService_h
29#define MAIN_INCLUDED_SRC_src_server_HostDnsService_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33#include "VirtualBoxBase.h"
34
35#include <iprt/err.h> /* VERR_IGNORED */
36#include <iprt/cpp/lock.h>
37
38#include <list>
39#include <iprt/sanitized/string>
40#include <vector>
41
42typedef std::list<com::Utf8Str> Utf8StrList;
43typedef Utf8StrList::iterator Utf8StrListIterator;
44
45class HostDnsMonitorProxy;
46typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
47
48class HostDnsInformation
49{
50public:
51 static const uint32_t IGNORE_SERVER_ORDER = RT_BIT_32(0);
52 static const uint32_t IGNORE_SUFFIXES = RT_BIT_32(1);
53
54public:
55 /** @todo r=bird: Why on earth are we using std::string and not Utf8Str? */
56 std::vector<std::string> servers;
57 std::string domain;
58 std::vector<std::string> searchList;
59 bool equals(const HostDnsInformation &, uint32_t fLaxComparison = 0) const;
60};
61
62/**
63 * Base class for host DNS service implementations.
64 * This class supposed to be a real DNS monitor object as a singleton,
65 * so it lifecycle starts and ends together with VBoxSVC.
66 */
67class HostDnsServiceBase
68{
69 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(HostDnsServiceBase);
70
71public:
72
73 static HostDnsServiceBase *createHostDnsMonitor(void);
74
75public:
76
77 /* @note: method will wait till client call
78 HostDnsService::monitorThreadInitializationDone() */
79 virtual HRESULT init(HostDnsMonitorProxy *pProxy);
80 virtual void uninit(void);
81
82 virtual ~HostDnsServiceBase();
83
84protected:
85
86 explicit HostDnsServiceBase(bool fThreaded = false);
87
88 void setInfo(const HostDnsInformation &);
89
90 /* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
91 void onMonitorThreadInitDone();
92
93public:
94
95 virtual int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs)
96 {
97 RT_NOREF(uTimeoutMs); AssertFailed(); return VERR_NOT_IMPLEMENTED;
98 }
99
100 virtual int monitorThreadProc(void) { AssertFailed(); return VERR_NOT_IMPLEMENTED; }
101
102private:
103
104 static DECLCALLBACK(int) threadMonitorProc(RTTHREAD, void *);
105
106protected:
107
108 mutable RTCLockMtx m_LockMtx;
109
110public: /** @todo r=andy Why is this public? */
111
112 struct Data;
113 Data *m;
114};
115
116/**
117 * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
118 */
119class HostDnsMonitorProxy
120{
121public:
122
123 HostDnsMonitorProxy();
124 virtual ~HostDnsMonitorProxy();
125
126public:
127
128 HRESULT init(VirtualBox *virtualbox);
129 void uninit(void);
130 void notify(const HostDnsInformation &info);
131
132 HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
133 HRESULT GetDomainName(com::Utf8Str *pDomainName);
134 HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
135
136private:
137
138 void pollGlobalExtraData(void);
139 bool updateInfo(const HostDnsInformation &info);
140
141private:
142
143 mutable RTCLockMtx m_LockMtx;
144
145 struct Data;
146 Data *m;
147};
148
149# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
150class HostDnsServiceDarwin : public HostDnsServiceBase
151{
152public:
153
154 HostDnsServiceDarwin();
155 virtual ~HostDnsServiceDarwin();
156
157public:
158
159 HRESULT init(HostDnsMonitorProxy *pProxy);
160 void uninit(void);
161
162protected:
163
164 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
165 int monitorThreadProc(void);
166
167private:
168
169 int updateInfo(void);
170 static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
171 struct Data;
172 Data *m;
173};
174# endif
175# if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
176class HostDnsServiceWin : public HostDnsServiceBase
177{
178public:
179 HostDnsServiceWin();
180 virtual ~HostDnsServiceWin();
181
182public:
183
184 HRESULT init(HostDnsMonitorProxy *pProxy);
185 void uninit(void);
186
187protected:
188
189 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
190 int monitorThreadProc(void);
191
192private:
193
194 HRESULT updateInfo(void);
195
196private:
197
198 struct Data;
199 Data *m;
200};
201# endif
202# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \
203 || defined(DOXYGEN_RUNNING)
204class HostDnsServiceResolvConf: public HostDnsServiceBase
205{
206public:
207
208 explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsServiceBase(fThreaded), m(NULL) {}
209 virtual ~HostDnsServiceResolvConf();
210
211public:
212
213 HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName);
214 void uninit(void);
215
216 const std::string& getResolvConf(void) const;
217
218protected:
219
220 HRESULT readResolvConf(void);
221
222protected:
223
224 struct Data;
225 Data *m;
226};
227# if defined(RT_OS_SOLARIS) || defined(DOXYGEN_RUNNING)
228/**
229 * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
230 */
231class HostDnsServiceSolaris : public HostDnsServiceResolvConf
232{
233public:
234
235 HostDnsServiceSolaris() {}
236 virtual ~HostDnsServiceSolaris() {}
237
238public:
239
240 virtual HRESULT init(HostDnsMonitorProxy *pProxy) {
241 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
242 }
243};
244
245# endif
246# if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
247class HostDnsServiceLinux : public HostDnsServiceResolvConf
248{
249public:
250
251 HostDnsServiceLinux() : HostDnsServiceResolvConf(true), m_fdShutdown(-1) {}
252 virtual ~HostDnsServiceLinux();
253
254public:
255
256 HRESULT init(HostDnsMonitorProxy *pProxy);
257
258protected:
259
260 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs);
261 int monitorThreadProc(void);
262
263 /** Socket end to write shutdown notification to, so the monitor thread will
264 * wake up and terminate. */
265 int m_fdShutdown;
266};
267
268# endif
269# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
270class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
271{
272public:
273
274 HostDnsServiceFreebsd(){}
275 virtual ~HostDnsServiceFreebsd() {}
276
277public:
278
279 virtual HRESULT init(HostDnsMonitorProxy *pProxy)
280 {
281 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");
282 }
283};
284
285# endif
286# if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
287class HostDnsServiceOs2 : public HostDnsServiceResolvConf
288{
289public:
290
291 HostDnsServiceOs2() {}
292 virtual ~HostDnsServiceOs2() {}
293
294public:
295
296 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
297 virtual HRESULT init(HostDnsMonitorProxy *pProxy)
298 {
299 return HostDnsServiceResolvConf::init(pProxy, "\\MPTN\\ETC\\RESOLV2");
300 }
301};
302
303# endif
304# endif
305
306#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