1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
/* $Id$ */
/** @file
* Host DNS listener.
*/
/*
* Copyright (C) 2005-2017 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ___H_DNSHOSTSERVICE
#define ___H_DNSHOSTSERVICE
#include "VirtualBoxBase.h"
#include <iprt/cdefs.h>
#include <iprt/types.h>
#include <iprt/cpp/lock.h>
#include <list>
#include <vector>
typedef std::list<com::Utf8Str> Utf8StrList;
typedef Utf8StrList::iterator Utf8StrListIterator;
class HostDnsMonitorProxy;
typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
class HostDnsInformation
{
public:
static const uint32_t IGNORE_SERVER_ORDER = RT_BIT_32(0);
static const uint32_t IGNORE_SUFFIXES = RT_BIT_32(1);
public:
std::vector<std::string> servers;
std::string domain;
std::vector<std::string> searchList;
bool equals(const HostDnsInformation &, uint32_t fLaxComparison = 0) const;
};
/**
* This class supposed to be a real DNS monitor object it should be singleton,
* it lifecycle starts and ends together with VBoxSVC.
*/
class HostDnsMonitor
{
public:
static const HostDnsMonitor *getHostDnsMonitor(VirtualBox *virtualbox);
static void shutdown();
void addMonitorProxy(PCHostDnsMonitorProxy) const;
void releaseMonitorProxy(PCHostDnsMonitorProxy) const;
const HostDnsInformation &getInfo() const;
/* @note: method will wait till client call
HostDnsService::monitorThreadInitializationDone() */
virtual HRESULT init(VirtualBox *virtualbox);
protected:
explicit HostDnsMonitor(bool fThreaded = false);
virtual ~HostDnsMonitor();
void setInfo(const HostDnsInformation &);
/* this function used only if HostDnsMonitor::HostDnsMonitor(true) */
void monitorThreadInitializationDone();
virtual void monitorThreadShutdown() = 0;
virtual int monitorWorker() = 0;
private:
HostDnsMonitor(const HostDnsMonitor &);
HostDnsMonitor& operator= (const HostDnsMonitor &);
static DECLCALLBACK(int) threadMonitoringRoutine(RTTHREAD, void *);
void pollGlobalExtraData();
protected:
mutable RTCLockMtx m_LockMtx;
public:
struct Data;
Data *m;
};
/**
* This class supposed to be a proxy for events on changing Host Name Resolving configurations.
*/
class HostDnsMonitorProxy
{
public:
HostDnsMonitorProxy();
~HostDnsMonitorProxy();
void init(const HostDnsMonitor *aMonitor, VirtualBox *virtualbox);
void notify() const;
HRESULT GetNameServers(std::vector<com::Utf8Str> &aNameServers);
HRESULT GetDomainName(com::Utf8Str *pDomainName);
HRESULT GetSearchStrings(std::vector<com::Utf8Str> &aSearchStrings);
bool operator==(PCHostDnsMonitorProxy&);
private:
void updateInfo();
private:
mutable RTCLockMtx m_LockMtx;
private:
struct Data;
Data *m;
};
# if defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
class HostDnsServiceDarwin : public HostDnsMonitor
{
public:
HostDnsServiceDarwin();
~HostDnsServiceDarwin();
virtual HRESULT init(VirtualBox *virtualbox);
protected:
virtual void monitorThreadShutdown();
virtual int monitorWorker();
private:
HRESULT updateInfo();
static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
struct Data;
Data *m;
};
# endif
# if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
class HostDnsServiceWin : public HostDnsMonitor
{
public:
HostDnsServiceWin();
~HostDnsServiceWin();
virtual HRESULT init(VirtualBox *virtualbox);
protected:
virtual void monitorThreadShutdown();
virtual int monitorWorker();
private:
HRESULT updateInfo();
private:
struct Data;
Data *m;
};
# endif
# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) \
|| defined(DOXYGEN_RUNNING)
class HostDnsServiceResolvConf: public HostDnsMonitor
{
public:
explicit HostDnsServiceResolvConf(bool fThreaded = false) : HostDnsMonitor(fThreaded), m(NULL) {}
virtual ~HostDnsServiceResolvConf();
virtual HRESULT init(VirtualBox *virtualbox, const char *aResolvConfFileName);
const std::string& resolvConf() const;
protected:
HRESULT readResolvConf();
/* While not all hosts supports Hosts DNS change notifiaction
* default implementation offers return VERR_IGNORE.
*/
virtual void monitorThreadShutdown() {}
virtual int monitorWorker() {return VERR_IGNORED;}
protected:
struct Data;
Data *m;
};
# if defined(RT_OS_SOLARIS) || defined(DOXYGEN_RUNNING)
/**
* XXX: https://blogs.oracle.com/praks/entry/file_events_notification
*/
class HostDnsServiceSolaris : public HostDnsServiceResolvConf
{
public:
HostDnsServiceSolaris(){}
~HostDnsServiceSolaris(){}
virtual HRESULT init(VirtualBox *virtualbox) {
return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
}
};
# endif
# if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
class HostDnsServiceLinux : public HostDnsServiceResolvConf
{
public:
HostDnsServiceLinux():HostDnsServiceResolvConf(true){}
virtual ~HostDnsServiceLinux();
virtual HRESULT init(VirtualBox *virtualbox) {
return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
}
protected:
virtual void monitorThreadShutdown();
virtual int monitorWorker();
};
# endif
# if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
{
public:
HostDnsServiceFreebsd(){}
~HostDnsServiceFreebsd(){}
virtual HRESULT init(VirtualBox *virtualbox) {
return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
}
};
# endif
# if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
class HostDnsServiceOs2 : public HostDnsServiceResolvConf
{
public:
HostDnsServiceOs2(){}
~HostDnsServiceOs2(){}
/* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
virtual HRESULT init(VirtualBox *virtualbox) {
return HostDnsServiceResolvConf::init(virtualbox, "\\MPTN\\ETC\\RESOLV2");
}
};
# endif
# endif
#endif /* !___H_DNSHOSTSERVICE */
|