1 | /* $Id: HostDnsService.h 49718 2013-11-29 10:51:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Host DNS listener.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2005-2012 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 ___H_DNSHOSTSERVICE
|
---|
19 | #define ___H_DNSHOSTSERVICE
|
---|
20 | #include "VirtualBoxBase.h"
|
---|
21 |
|
---|
22 | #include <iprt/cdefs.h>
|
---|
23 | #include <iprt/critsect.h>
|
---|
24 | #include <iprt/types.h>
|
---|
25 |
|
---|
26 | #include <list>
|
---|
27 | #include <vector>
|
---|
28 |
|
---|
29 | typedef std::list<com::Utf8Str> Utf8StrList;
|
---|
30 | typedef Utf8StrList::iterator Utf8StrListIterator;
|
---|
31 |
|
---|
32 | class HostDnsMonitorProxy;
|
---|
33 | typedef const HostDnsMonitorProxy *PCHostDnsMonitorProxy;
|
---|
34 |
|
---|
35 | class Lockee
|
---|
36 | {
|
---|
37 | public:
|
---|
38 | Lockee();
|
---|
39 | virtual ~Lockee();
|
---|
40 | const RTCRITSECT* lock() const;
|
---|
41 |
|
---|
42 | private:
|
---|
43 | RTCRITSECT mLock;
|
---|
44 | };
|
---|
45 |
|
---|
46 | class ALock
|
---|
47 | {
|
---|
48 | public:
|
---|
49 | ALock(const Lockee *l);
|
---|
50 | ~ALock();
|
---|
51 |
|
---|
52 | private:
|
---|
53 | const Lockee *lockee;
|
---|
54 | };
|
---|
55 |
|
---|
56 | class HostDnsInformation
|
---|
57 | {
|
---|
58 | public:
|
---|
59 | std::vector<std::string> servers;
|
---|
60 | std::string domain;
|
---|
61 | std::vector<std::string> searchList;
|
---|
62 | };
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * This class supposed to be a real DNS monitor object it should be singleton,
|
---|
66 | * it lifecycle starts and ends together with VBoxSVC.
|
---|
67 | */
|
---|
68 | class HostDnsMonitor : public Lockee
|
---|
69 | {
|
---|
70 | public:
|
---|
71 | static const HostDnsMonitor *getHostDnsMonitor();
|
---|
72 | static void shutdown();
|
---|
73 |
|
---|
74 | void addMonitorProxy(PCHostDnsMonitorProxy) const;
|
---|
75 | void releaseMonitorProxy(PCHostDnsMonitorProxy) const;
|
---|
76 | const HostDnsInformation &getInfo() const;
|
---|
77 | virtual HRESULT init();
|
---|
78 |
|
---|
79 | protected:
|
---|
80 | void notifyAll() const;
|
---|
81 | void setInfo(const HostDnsInformation &);
|
---|
82 | HostDnsMonitor();
|
---|
83 | virtual ~HostDnsMonitor();
|
---|
84 |
|
---|
85 | private:
|
---|
86 | HostDnsMonitor(const HostDnsMonitor &);
|
---|
87 | HostDnsMonitor& operator= (const HostDnsMonitor &);
|
---|
88 |
|
---|
89 | public:
|
---|
90 | struct Data;
|
---|
91 | Data *m;
|
---|
92 | };
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * This class supposed to be a proxy for events on changing Host Name Resolving configurations.
|
---|
96 | */
|
---|
97 | class HostDnsMonitorProxy : public Lockee
|
---|
98 | {
|
---|
99 | public:
|
---|
100 | HostDnsMonitorProxy();
|
---|
101 | ~HostDnsMonitorProxy();
|
---|
102 | void init(const HostDnsMonitor *aMonitor, const VirtualBox *aParent);
|
---|
103 | void notify() const;
|
---|
104 |
|
---|
105 | HRESULT GetNameServers(ComSafeArrayOut(BSTR, aNameServers));
|
---|
106 | HRESULT GetDomainName(BSTR *aDomainName);
|
---|
107 | HRESULT GetSearchStrings(ComSafeArrayOut(BSTR, aSearchStrings));
|
---|
108 |
|
---|
109 | bool operator==(PCHostDnsMonitorProxy&);
|
---|
110 |
|
---|
111 | private:
|
---|
112 | void updateInfo();
|
---|
113 |
|
---|
114 | private:
|
---|
115 | struct Data;
|
---|
116 | Data *m;
|
---|
117 | };
|
---|
118 |
|
---|
119 | # ifdef RT_OS_DARWIN
|
---|
120 | class HostDnsServiceDarwin : public HostDnsMonitor
|
---|
121 | {
|
---|
122 | public:
|
---|
123 | HostDnsServiceDarwin();
|
---|
124 | ~HostDnsServiceDarwin();
|
---|
125 | HRESULT init();
|
---|
126 |
|
---|
127 | private:
|
---|
128 | HRESULT updateInfo();
|
---|
129 | static void hostDnsServiceStoreCallback(void *store, void *arrayRef, void *info);
|
---|
130 | };
|
---|
131 | # endif
|
---|
132 | # ifdef RT_OS_WINDOWS
|
---|
133 | class HostDnsServiceWin : public HostDnsMonitor
|
---|
134 | {
|
---|
135 | public:
|
---|
136 | HostDnsServiceWin();
|
---|
137 | ~HostDnsServiceWin();
|
---|
138 | HRESULT init();
|
---|
139 |
|
---|
140 | private:
|
---|
141 | void strList2List(std::vector<std::string>& lst, char *strLst);
|
---|
142 | HRESULT updateInfo();
|
---|
143 | };
|
---|
144 | # endif
|
---|
145 | # if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
|
---|
146 | class HostDnsServiceResolvConf: public HostDnsMonitor
|
---|
147 | {
|
---|
148 | public:
|
---|
149 | HostDnsServiceResolvConf() : m(NULL) {}
|
---|
150 | virtual ~HostDnsServiceResolvConf();
|
---|
151 | virtual HRESULT init(const char *aResolvConfFileName);
|
---|
152 | const std::string& resolvConf();
|
---|
153 |
|
---|
154 | protected:
|
---|
155 | HRESULT readResolvConf();
|
---|
156 |
|
---|
157 | protected:
|
---|
158 | struct Data;
|
---|
159 | Data *m;
|
---|
160 | };
|
---|
161 | # if defined(RT_OS_SOLARIS)
|
---|
162 | /**
|
---|
163 | * XXX: https://blogs.oracle.com/praks/entry/file_events_notification
|
---|
164 | */
|
---|
165 | class HostDnsServiceSolaris : public HostDnsServiceResolvConf
|
---|
166 | {
|
---|
167 | public:
|
---|
168 | HostDnsServiceSolaris(){}
|
---|
169 | ~HostDnsServiceSolaris(){}
|
---|
170 | HRESULT init(){ return HostDnsServiceResolvConf::init("/etc/resolv.conf");}
|
---|
171 | };
|
---|
172 |
|
---|
173 | # elif defined(RT_OS_LINUX)
|
---|
174 | class HostDnsServiceLinux : public HostDnsServiceResolvConf
|
---|
175 | {
|
---|
176 | public:
|
---|
177 | HostDnsServiceLinux(){}
|
---|
178 | ~HostDnsServiceLinux();
|
---|
179 | HRESULT init() {return init("/etc/resolv.conf");}
|
---|
180 | HRESULT init(const char *aResolvConfFileName);
|
---|
181 |
|
---|
182 | static int hostMonitoringRoutine(RTTHREAD ThreadSelf, void *pvUser);
|
---|
183 | };
|
---|
184 |
|
---|
185 | # elif defined(RT_OS_FREEBSD)
|
---|
186 | class HostDnsServiceFreebsd: public HostDnsServiceResolvConf
|
---|
187 | {
|
---|
188 | public:
|
---|
189 | HostDnsServiceFreebsd(){}
|
---|
190 | ~HostDnsServiceFreebsd(){}
|
---|
191 | HRESULT init(){ return HostDnsServiceResolvConf::init("/etc/resolv.conf");}
|
---|
192 | };
|
---|
193 |
|
---|
194 | # elif defined(RT_OS_OS2)
|
---|
195 | class HostDnsServiceOs2 : public HostDnsServiceResolvConf
|
---|
196 | {
|
---|
197 | public:
|
---|
198 | HostDnsServiceOs2(){}
|
---|
199 | ~HostDnsServiceOs2(){}
|
---|
200 | /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */
|
---|
201 | HRESULT init(){ return init("\\MPTN\\ETC\\RESOLV2");}
|
---|
202 | };
|
---|
203 |
|
---|
204 | # endif
|
---|
205 | # endif
|
---|
206 |
|
---|
207 | #endif /* !___H_DNSHOSTSERVICE */
|
---|