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