儲存庫 vbox 的更動 108012
- 時間撮記:
- 2025-2-1 上午02:19:11 (6 週 以前)
- svn:sync-xref-src-repo-rev:
- 167284
- 位置:
- trunk/src/VBox/Main/src-server
- 檔案:
-
- 修改 6 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Main/src-server/HostDnsService.cpp
r108010 r108012 42 42 #include <algorithm> 43 43 #include <set> 44 #include <iprt/sanitized/string>45 44 #include "HostDnsService.h" 46 45 47 46 48 47 49 static void dumpHostDnsStrVector(const std::string &prefix, const std::vector<std::string> &v)48 static void dumpHostDnsStrVector(const char *prefix, const std::vector<com::Utf8Str> &v) 50 49 { 51 50 int i = 1; 52 for (std::vector<std::string>::const_iterator it = v.begin(); 53 it != v.end(); 54 ++it, ++i) 55 LogRel((" %s %d: %s\n", prefix.c_str(), i, it->c_str())); 51 for (std::vector<com::Utf8Str>::const_iterator it = v.begin(); it != v.end(); ++it, ++i) 52 LogRel((" %s %d: %s\n", prefix, i, it->c_str())); 56 53 if (v.empty()) 57 LogRel((" no %s entries\n", prefix .c_str()));54 LogRel((" no %s entries\n", prefix)); 58 55 } 59 56 … … 62 59 dumpHostDnsStrVector("server", info.servers); 63 60 64 if ( !info.domain.empty())61 if (info.domain.isNotEmpty()) 65 62 LogRel((" domain: %s\n", info.domain.c_str())); 66 63 else … … 77 74 else 78 75 { 79 std::set< std::string> l(servers.begin(), servers.end());80 std::set< std::string> r(info.servers.begin(), info.servers.end());76 std::set<com::Utf8Str> l(servers.begin(), servers.end()); 77 std::set<com::Utf8Str> r(info.servers.begin(), info.servers.end()); 81 78 82 79 fSameServers = (l == r); … … 93 90 94 91 return fSameServers && fSameDomain && fSameSearchList; 95 }96 97 DECLINLINE(void) detachVectorOfStrings(const std::vector<std::string>& v, std::vector<com::Utf8Str> &aArray)98 {99 aArray.resize(v.size());100 size_t i = 0;101 for (std::vector<std::string>::const_iterator it = v.begin(); it != v.end(); ++it, ++i)102 aArray[i] = Utf8Str(it->c_str()); /** @todo r=bird: *it isn't necessarily UTF-8 clean!!103 * On darwin we do silly shit like using CFStringGetSystemEncoding()104 * that may be UTF-8 but doesn't need to be.105 *106 * Why on earth are we using std::string here anyway?107 */108 92 } 109 93 … … 384 368 dumpHostDnsStrVector("name server", m->info.servers); 385 369 386 detachVectorOfStrings(m->info.servers, aNameServers);370 aNameServers = m->info.servers; 387 371 388 372 return S_OK; … … 394 378 AssertReturn(m != NULL, E_FAIL); 395 379 396 LogRel(("HostDnsMonitorProxy::GetDomainName: %s\n", m->info.domain. empty() ? "no domain set" : m->info.domain.c_str()));380 LogRel(("HostDnsMonitorProxy::GetDomainName: %s\n", m->info.domain.isEmpty() ? "no domain set" : m->info.domain.c_str())); 397 381 *pDomainName = m->info.domain.c_str(); 398 382 … … 408 392 dumpHostDnsStrVector("search string", m->info.searchList); 409 393 410 detachVectorOfStrings(m->info.searchList, aSearchStrings);394 aSearchStrings = m->info.searchList; 411 395 412 396 return S_OK; -
trunk/src/VBox/Main/src-server/HostDnsService.h
r108010 r108012 37 37 38 38 #include <list> 39 #include <iprt/sanitized/string>40 39 #include <vector> 41 40 … … 53 52 54 53 public: 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; 54 std::vector<com::Utf8Str> servers; 55 com::Utf8Str domain; 56 std::vector<com::Utf8Str> searchList; 59 57 bool equals(const HostDnsInformation &, uint32_t fLaxComparison = 0) const; 60 58 }; … … 109 107 mutable RTCLockMtx m_LockMtx; 110 108 111 public: /** @todo r=andy Why is this public? */109 //public: /** @todo r=andy Why is this public? */ 112 110 113 111 struct Data; … … 160 158 public: 161 159 162 HRESULT init(HostDnsMonitorProxy *pProxy) ;163 void uninit(void) ;160 HRESULT init(HostDnsMonitorProxy *pProxy) RT_OVERRIDE; 161 void uninit(void) RT_OVERRIDE; 164 162 165 163 protected: … … 185 183 public: 186 184 187 HRESULT init(HostDnsMonitorProxy *pProxy) ;188 void uninit(void) ;185 HRESULT init(HostDnsMonitorProxy *pProxy) RT_OVERRIDE; 186 void uninit(void) RT_OVERRIDE; 189 187 190 188 protected: … … 215 213 216 214 HRESULT init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName); 217 void uninit(void) ;218 219 const std::string&getResolvConf(void) const;215 void uninit(void) RT_OVERRIDE; 216 217 const Utf8Str &getResolvConf(void) const; 220 218 221 219 protected: … … 238 236 HostDnsServiceSolaris() {} 239 237 virtual ~HostDnsServiceSolaris() {} 238 239 public: 240 241 virtual HRESULT init(HostDnsMonitorProxy *pProxy) RT_OVERRIDE 242 { 243 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf"); 244 } 245 }; 246 247 # endif 248 # if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING) 249 class HostDnsServiceLinux : public HostDnsServiceResolvConf 250 { 251 public: 252 253 HostDnsServiceLinux() : HostDnsServiceResolvConf(true), m_fdShutdown(-1) {} 254 virtual ~HostDnsServiceLinux(); 255 256 public: 257 258 HRESULT init(HostDnsMonitorProxy *pProxy) RT_OVERRIDE; 259 260 protected: 261 262 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs) RT_OVERRIDE; 263 int monitorThreadProc(void) RT_OVERRIDE; 264 265 /** Socket end to write shutdown notification to, so the monitor thread will 266 * wake up and terminate. */ 267 int m_fdShutdown; 268 }; 269 270 # endif 271 # if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING) 272 class HostDnsServiceFreebsd: public HostDnsServiceResolvConf 273 { 274 public: 275 276 HostDnsServiceFreebsd(){} 277 virtual ~HostDnsServiceFreebsd() {} 240 278 241 279 public: … … 248 286 249 287 # endif 250 # if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)251 class HostDnsServiceLinux : public HostDnsServiceResolvConf252 {253 public:254 255 HostDnsServiceLinux() : HostDnsServiceResolvConf(true), m_fdShutdown(-1) {}256 virtual ~HostDnsServiceLinux();257 258 public:259 260 HRESULT init(HostDnsMonitorProxy *pProxy);261 262 protected:263 264 int monitorThreadShutdown(RTMSINTERVAL uTimeoutMs) RT_OVERRIDE;265 int monitorThreadProc(void) RT_OVERRIDE;266 267 /** Socket end to write shutdown notification to, so the monitor thread will268 * wake up and terminate. */269 int m_fdShutdown;270 };271 272 # endif273 # if defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)274 class HostDnsServiceFreebsd: public HostDnsServiceResolvConf275 {276 public:277 278 HostDnsServiceFreebsd(){}279 virtual ~HostDnsServiceFreebsd() {}280 281 public:282 283 virtual HRESULT init(HostDnsMonitorProxy *pProxy)284 {285 return HostDnsServiceResolvConf::init(pProxy, "/etc/resolv.conf");286 }287 };288 289 # endif290 288 # if defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING) 291 289 class HostDnsServiceOs2 : public HostDnsServiceResolvConf … … 299 297 300 298 /* XXX: \\MPTN\\ETC should be taken from environment variable ETC */ 301 virtual HRESULT init(HostDnsMonitorProxy *pProxy) 299 virtual HRESULT init(HostDnsMonitorProxy *pProxy) RT_OVERRIDE 302 300 { 303 301 return HostDnsServiceResolvConf::init(pProxy, "\\MPTN\\ETC\\RESOLV2"); -
trunk/src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp
r106061 r108012 49 49 #include <VBox/log.h> 50 50 51 #include <iprt/sanitized/string>52 53 51 #include "HostDnsService.h" 54 52 #include "../../Devices/Network/slirp/resolv_conf_parser.h" … … 62 60 }; 63 61 64 std::stringresolvConfFilename;62 com::Utf8Str resolvConfFilename; 65 63 }; 66 64 … … 96 94 } 97 95 98 const std::string&HostDnsServiceResolvConf::getResolvConf(void) const96 const com::Utf8Str &HostDnsServiceResolvConf::getResolvConf(void) const 99 97 { 100 98 return m->resolvConfFilename; … … 104 102 { 105 103 struct rcp_state st; 106 107 104 st.rcps_flags = RCPSF_NO_STR2IPCONV; 108 105 int vrc = rcp_parse(&st, m->resolvConfFilename.c_str()); … … 114 111 { 115 112 AssertBreak(st.rcps_str_nameserver[i]); 113 RTStrPurgeEncoding(st.rcps_str_nameserver[i]); 116 114 info.servers.push_back(st.rcps_str_nameserver[i]); 117 115 } 118 116 119 117 if (st.rcps_domain) 118 { 119 RTStrPurgeEncoding(st.rcps_domain); 120 120 info.domain = st.rcps_domain; 121 } 121 122 122 123 for (unsigned i = 0; i != st.rcps_num_searchlist; ++i) 123 124 { 124 125 AssertBreak(st.rcps_searchlist[i]); 126 RTStrPurgeEncoding(st.rcps_searchlist[i]); 125 127 info.searchList.push_back(st.rcps_searchlist[i]); 126 128 } 129 127 130 setInfo(info); 128 129 131 return S_OK; 130 132 } -
trunk/src/VBox/Main/src-server/darwin/HostDnsServiceDarwin.cpp
r108010 r108012 38 38 #include <SystemConfiguration/SCDynamicStore.h> 39 39 40 #include <iprt/sanitized/string>41 40 #include <vector> 42 41 #include "../HostDnsService.h" … … 185 184 } 186 185 186 DECLINLINE(bool) queryCFStringAsUtf8Str(CFStringRef hRefSrc, com::Utf8Str &a_rDst, size_t cbMax) 187 { 188 a_rDst.reserve(_1K); 189 if (!CFStringGetCString(hRefSrc, a_rDst.mutableRaw(), (CFIndex)a_rDst.capacity(), kCFStringEncodingUTF8)) 190 { 191 a_rDst.reserve(cbMax); 192 if (!CFStringGetCString(hRefSrc, a_rDst.mutableRaw(), (CFIndex)a_rDst.capacity(), kCFStringEncodingUTF8)) 193 return false; 194 } 195 RTStrPurgeEncoding(a_rDst.mutableRaw()); /* paranoia */ 196 a_rDst.jolt(); 197 return true; 198 } 199 200 187 201 int HostDnsServiceDarwin::updateInfo(void) 188 202 { 189 203 CFPropertyListRef propertyRef = SCDynamicStoreCopyValue(m->m_store, kStateNetworkGlobalDNSKey); 190 /* *204 /* 191 205 * # scutil 192 206 * \> get State:/Network/Global/DNS … … 205 219 * } 206 220 */ 207 208 221 if (!propertyRef) 209 222 return VINF_SUCCESS; 223 CFDictionaryRef const propertyAsDictRef = static_cast<CFDictionaryRef>(propertyRef); 210 224 211 225 HostDnsInformation info; 212 CFStringRef domainNameRef = (CFStringRef)CFDictionaryGetValue(static_cast<CFDictionaryRef>(propertyRef), CFSTR("DomainName")); 226 com::Utf8Str strTmp; 227 228 CFStringRef const domainNameRef = (CFStringRef)CFDictionaryGetValue(propertyAsDictRef, CFSTR("DomainName")); 213 229 if (domainNameRef) 214 { 215 const char *pszDomainName = CFStringGetCStringPtr(domainNameRef, CFStringGetSystemEncoding()); 216 if (pszDomainName) 217 info.domain = pszDomainName; 218 } 219 220 CFArrayRef serverArrayRef = (CFArrayRef)CFDictionaryGetValue(static_cast<CFDictionaryRef>(propertyRef), 221 CFSTR("ServerAddresses")); 230 if (queryCFStringAsUtf8Str(domainNameRef, strTmp, _16K)) 231 info.domain = strTmp; 232 233 CFArrayRef const serverArrayRef = (CFArrayRef)CFDictionaryGetValue(propertyAsDictRef, CFSTR("ServerAddresses")); 222 234 if (serverArrayRef) 223 235 { … … 225 237 for (CFIndex i = 0; i < cItems; ++i) 226 238 { 227 CFStringRef serverAddressRef = (CFStringRef)CFArrayGetValueAtIndex(serverArrayRef, i); 228 if (!serverAddressRef) 229 continue; 230 231 /** @todo r=bird: This code is messed up as CFStringGetCStringPtr is documented 232 * to return NULL even if the string is valid. Furthermore, we must have 233 * UTF-8 - some joker might decide latin-1 is better here for all we know 234 * and we'll end up with evil invalid UTF-8 sequences. */ 235 const char *pszServerAddress = CFStringGetCStringPtr(serverAddressRef, CFStringGetSystemEncoding()); 236 if (!pszServerAddress) 237 continue; 238 239 /** @todo r=bird: Why on earth are we using std::string and not Utf8Str? */ 240 info.servers.push_back(std::string(pszServerAddress)); 239 CFStringRef const serverAddressRef = (CFStringRef)CFArrayGetValueAtIndex(serverArrayRef, i); 240 if (serverAddressRef) 241 if (queryCFStringAsUtf8Str(serverAddressRef, strTmp, _16K)) 242 info.servers.push_back(strTmp); 241 243 } 242 244 } 243 245 244 CFArrayRef searchArrayRef = (CFArrayRef)CFDictionaryGetValue(static_cast<CFDictionaryRef>(propertyRef), 245 CFSTR("SearchDomains")); 246 CFArrayRef const searchArrayRef = (CFArrayRef)CFDictionaryGetValue(propertyAsDictRef, CFSTR("SearchDomains")); 246 247 if (searchArrayRef) 247 248 { … … 250 251 { 251 252 CFStringRef searchStringRef = (CFStringRef)CFArrayGetValueAtIndex(searchArrayRef, i); 252 if (!searchStringRef) 253 continue; 254 255 /** @todo r=bird: This code is messed up as CFStringGetCStringPtr is documented 256 * to return NULL even if the string is valid. Furthermore, we must have 257 * UTF-8 - some joker might decide latin-1 is better here for all we know 258 * and we'll end up with evil invalid UTF-8 sequences. */ 259 const char *pszSearchString = CFStringGetCStringPtr(searchStringRef, CFStringGetSystemEncoding()); 260 if (!pszSearchString) 261 continue; 262 263 /** @todo r=bird: Why on earth are we using std::string and not Utf8Str? */ 264 info.searchList.push_back(std::string(pszSearchString)); 253 if (searchStringRef) 254 if (queryCFStringAsUtf8Str(searchStringRef, strTmp, _64K)) 255 info.searchList.push_back(strTmp); 265 256 } 266 257 } -
trunk/src/VBox/Main/src-server/linux/HostDnsServiceLinux.cpp
r106061 r108012 45 45 #include <string.h> 46 46 #include <unistd.h> 47 #include <stdlib.h> 47 48 48 49 #include <fcntl.h> -
trunk/src/VBox/Main/src-server/win/HostDnsServiceWin.cpp
r106061 r108012 48 48 49 49 #include <algorithm> 50 #include <iprt/sanitized/sstream>51 #include <iprt/sanitized/string>52 50 #include <vector> 53 51 … … 60 58 hEvent, 61 59 TRUE); 62 Assert MsgReturn(lrc == ERROR_SUCCESS,63 ("Failed to register event on the key. Please debug me!"),64 VERR_INTERNAL_ERROR);60 AssertLogRelMsgReturn(lrc == ERROR_SUCCESS, 61 ("Failed to register event on the key. Please debug me!"), 62 VERR_INTERNAL_ERROR); 65 63 66 64 return VINF_SUCCESS; 67 65 } 68 66 69 static void appendTokenizedStrings(std::vector< std::string> &vecStrings, const std::string&strToAppend, char chDelim = ' ')70 { 71 if (strToAppend. empty())67 static void appendTokenizedStrings(std::vector<com::Utf8Str> &vecStrings, const com::Utf8Str &strToAppend, char chDelim = ' ') 68 { 69 if (strToAppend.isEmpty()) 72 70 return; 73 71 74 std::istringstream stream(strToAppend); 75 std::string substr; 76 77 while (std::getline(stream, substr, chDelim)) 78 { 79 if (substr.empty()) 80 continue; 81 82 if (std::find(vecStrings.cbegin(), vecStrings.cend(), substr) != vecStrings.cend()) 83 continue; 84 85 vecStrings.push_back(substr); 72 RTCString const strDelim(1, chDelim); 73 auto const lstSubStrings = strToAppend.split(strDelim); 74 size_t const cSubStrings = lstSubStrings.size(); 75 for (size_t i = 0; i < cSubStrings; i++) 76 { 77 RTCString const &strCur = lstSubStrings[i]; 78 if (strCur.isNotEmpty()) 79 if (std::find(vecStrings.cbegin(), vecStrings.cend(), strCur) == vecStrings.cend()) 80 vecStrings.push_back(strCur); 86 81 } 87 82 } … … 97 92 #define DATA_TIMER 2 98 93 #define DATA_MAX_EVENT 3 99 HANDLE haDataEvent[DATA_MAX_EVENT];94 HANDLE ahDataEvents[DATA_MAX_EVENT]; 100 95 101 96 Data() … … 105 100 106 101 for (size_t i = 0; i < DATA_MAX_EVENT; ++i) 107 haDataEvent[i] = NULL;102 ahDataEvents[i] = NULL; 108 103 } 109 104 … … 111 106 { 112 107 if (hKeyTcpipParameters != NULL) 108 { 113 109 RegCloseKey(hKeyTcpipParameters); 110 hKeyTcpipParameters = NULL; 111 } 114 112 115 113 for (size_t i = 0; i < DATA_MAX_EVENT; ++i) 116 if (haDataEvent[i] != NULL) 117 CloseHandle(haDataEvent[i]); 114 if (ahDataEvents[i] != NULL) 115 { 116 CloseHandle(ahDataEvents[i]); 117 ahDataEvents[i] = NULL; 118 } 118 119 } 119 120 }; … … 137 138 return E_FAIL; 138 139 139 bool fRc = true;140 140 LONG lRc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 141 141 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 142 142 0, 143 KEY_READ |KEY_NOTIFY,143 KEY_READ | KEY_NOTIFY, 144 144 &m->hKeyTcpipParameters); 145 145 if (lRc != ERROR_SUCCESS) 146 146 { 147 147 LogRel(("HostDnsServiceWin: failed to open key Tcpip\\Parameters (error %d)\n", lRc)); 148 fRc = false;149 }150 else151 {152 for (size_t i = 0; i < DATA_MAX_EVENT; ++i)153 {154 HANDLE h;155 156 if (i == DATA_TIMER)157 h = CreateWaitableTimer(NULL, FALSE, NULL);158 else159 h = CreateEvent(NULL, TRUE, FALSE, NULL);160 161 if (h == NULL)162 {163 LogRel(("HostDnsServiceWin: failed to create event (error %d)\n", GetLastError()));164 fRc = false;165 break;166 }167 168 m->haDataEvent[i] = h;169 }170 }171 172 if (!fRc)173 148 return E_FAIL; 149 } 150 151 for (size_t i = 0; i < DATA_MAX_EVENT; ++i) 152 { 153 HANDLE h; 154 if (i == DATA_TIMER) 155 h = CreateWaitableTimer(NULL, FALSE, NULL); 156 else 157 h = CreateEvent(NULL, TRUE, FALSE, NULL); 158 if (h == NULL) 159 { 160 LogRel(("HostDnsServiceWin: failed to create %s (error %d)\n", 161 i == DATA_TIMER ? "waitable timer" : "event", GetLastError())); 162 return E_FAIL; 163 } 164 165 m->ahDataEvents[i] = h; 166 } 174 167 175 168 HRESULT hrc = HostDnsServiceBase::init(pProxy); … … 187 180 int HostDnsServiceWin::monitorThreadShutdown(RTMSINTERVAL uTimeoutMs) 188 181 { 189 RT_NOREF(uTimeoutMs); 190 191 AssertPtr(m); 192 SetEvent(m->haDataEvent[DATA_SHUTDOWN_EVENT]); 193 /** @todo r=andy Wait for thread? Check vrc here. Timeouts? */ 182 AssertPtrReturn(m, VINF_SUCCESS); 183 184 SetEvent(m->ahDataEvents[DATA_SHUTDOWN_EVENT]); 185 RT_NOREF(uTimeoutMs); /* (Caller waits for the thread) */ 194 186 195 187 return VINF_SUCCESS; … … 201 193 202 194 registerNotification(m->hKeyTcpipParameters, 203 m-> haDataEvent[DATA_DNS_UPDATE_EVENT]);195 m->ahDataEvents[DATA_DNS_UPDATE_EVENT]); 204 196 205 197 onMonitorThreadInitDone(); … … 207 199 for (;;) 208 200 { 209 DWORD dwReady; 210 211 dwReady = WaitForMultipleObjects(DATA_MAX_EVENT, m->haDataEvent, 212 FALSE, INFINITE); 213 201 DWORD dwReady = WaitForMultipleObjects(DATA_MAX_EVENT, m->ahDataEvents, FALSE, INFINITE); 214 202 if (dwReady == WAIT_OBJECT_0 + DATA_SHUTDOWN_EVENT) 215 203 break; … … 225 213 LARGE_INTEGER delay; /* in 100ns units */ 226 214 delay.QuadPart = -2 * 1000 * 1000 * 10LL; /* relative: 2s */ 227 228 BOOL ok = SetWaitableTimer(m->haDataEvent[DATA_TIMER], &delay, 229 0, NULL, NULL, FALSE); 230 if (ok) 231 { 215 if (SetWaitableTimer(m->ahDataEvents[DATA_TIMER], &delay, 0, NULL, NULL, FALSE)) 232 216 m->fTimerArmed = true; 233 }234 217 else 235 218 { … … 239 222 } 240 223 241 ResetEvent(m-> haDataEvent[DATA_DNS_UPDATE_EVENT]);224 ResetEvent(m->ahDataEvents[DATA_DNS_UPDATE_EVENT]); 242 225 registerNotification(m->hKeyTcpipParameters, 243 m-> haDataEvent[DATA_DNS_UPDATE_EVENT]);226 m->ahDataEvents[DATA_DNS_UPDATE_EVENT]); 244 227 } 245 228 else if (dwReady == WAIT_OBJECT_0 + DATA_TIMER) … … 267 250 HostDnsInformation info; 268 251 269 std::stringstrDomain;270 std::stringstrSearchList; /* NB: comma separated, no spaces */252 com::Utf8Str strDomain; 253 com::Utf8Str strSearchList; /* NB: comma separated, no spaces */ 271 254 272 255 /* … … 279 262 for (DWORD regIndex = 0; /**/; ++regIndex) 280 263 { 281 char keyName[256]; 282 DWORD cbKeyName = sizeof(keyName); 283 DWORD keyType = 0; 284 char keyData[1024]; 285 DWORD cbKeyData = sizeof(keyData); 286 287 /** @todo use unicode API. This isn't UTF-8 clean! */ 288 LSTATUS lrc = RegEnumValueA(m->hKeyTcpipParameters, regIndex, 289 keyName, &cbKeyName, 0, 290 &keyType, (LPBYTE)keyData, &cbKeyData); 264 WCHAR wszKeyName[256] = {0}; 265 DWORD cbKeyName = RT_ELEMENTS(wszKeyName); 266 DWORD keyType = 0; 267 WCHAR wszKeyData[1024]; 268 DWORD cbKeyData = sizeof(wszKeyData); 269 LSTATUS lrc = RegEnumValueW(m->hKeyTcpipParameters, regIndex, 270 wszKeyName, &cbKeyName, NULL /*pReserved*/, 271 &keyType, (LPBYTE)wszKeyData, &cbKeyData); 291 272 292 273 if (lrc == ERROR_NO_MORE_ITEMS) … … 305 286 continue; 306 287 307 if (cbKeyData > 0 && keyData[cbKeyData - 1] == '\0') 308 --cbKeyData; /* don't count trailing NUL if present */ 309 310 if (RTStrICmp("Domain", keyName) == 0) 311 { 312 strDomain.assign(keyData, cbKeyData); 288 size_t cwcKeyData = cbKeyData / sizeof(wszKeyData[0]); 289 if (cwcKeyData > 0 && wszKeyData[cwcKeyData - 1] == '\0') 290 --cwcKeyData; /* don't count trailing NUL if present */ 291 292 if (RTUtf16ICmpAscii(wszKeyName, "Domain") == 0) 293 { 294 strDomain.assign(wszKeyData, cwcKeyData); 313 295 LogRel2(("HostDnsServiceWin: Domain=\"%s\"\n", strDomain.c_str())); 314 296 } 315 else if (RTStrICmp("DhcpDomain", keyName) == 0) 316 { 317 std::string strDhcpDomain(keyData, cbKeyData); 297 else if (RTUtf16ICmpAscii(wszKeyName, "SearchList") == 0) 298 { 299 strSearchList.assign(wszKeyData, cwcKeyData); 300 LogRel2(("HostDnsServiceWin: SearchList=\"%s\"\n", strSearchList.c_str())); 301 } 302 else if (LogRelIs2Enabled() && RTUtf16ICmpAscii(wszKeyName, "DhcpDomain") == 0) 303 { 304 com::Utf8Str strDhcpDomain(wszKeyData, cwcKeyData); 318 305 LogRel2(("HostDnsServiceWin: DhcpDomain=\"%s\"\n", strDhcpDomain.c_str())); 319 306 } 320 else if (RTStrICmp("SearchList", keyName) == 0)321 {322 strSearchList.assign(keyData, cbKeyData);323 LogRel2(("HostDnsServiceWin: SearchList=\"%s\"\n", strSearchList.c_str()));324 }325 307 } 326 308 327 309 /* statically configured domain name */ 328 if ( !strDomain.empty())310 if (strDomain.isNotEmpty()) 329 311 { 330 312 info.domain = strDomain; … … 333 315 334 316 /* statically configured search list */ 335 if ( !strSearchList.empty())317 if (strSearchList.isNotEmpty()) 336 318 appendTokenizedStrings(info.searchList, strSearchList, ','); 337 319 … … 343 325 * right thing there. 344 326 */ 345 DNS_STATUS status;346 327 PIP4_ARRAY pIp4Array = NULL; 347 348 // NB: must be set on input it seems, despite docs' claim to the contrary. 349 DWORD cbBuffer = sizeof(&pIp4Array); 350 351 status = DnsQueryConfig(DnsConfigDnsServerList, 352 DNS_CONFIG_FLAG_ALLOC, NULL, NULL, 353 &pIp4Array, &cbBuffer); 354 328 DWORD cbBuffer = sizeof(&pIp4Array); // NB: must be set on input it seems, despite docs' claim to the contrary. 329 DNS_STATUS status = DnsQueryConfig(DnsConfigDnsServerList, DNS_CONFIG_FLAG_ALLOC, NULL, NULL, &pIp4Array, &cbBuffer); 355 330 if (status == NO_ERROR && pIp4Array != NULL) 356 331 { 357 332 for (DWORD i = 0; i < pIp4Array->AddrCount; ++i) 358 333 { 359 char szAddr Str[16] = "";360 RTStrPrintf(szAddr Str, sizeof(szAddrStr), "%RTnaipv4", pIp4Array->AddrArray[i]);361 362 LogRel2(("HostDnsServiceWin: server %d: %s\n", i+1, szAddr Str));363 info.servers.push_back(szAddr Str);334 char szAddr[16] = ""; 335 RTStrPrintf(szAddr, sizeof(szAddr), "%RTnaipv4", pIp4Array->AddrArray[i]); 336 337 LogRel2(("HostDnsServiceWin: server %d: %s\n", i+1, szAddr)); 338 info.servers.push_back(szAddr); 364 339 } 365 340 … … 368 343 369 344 370 /* *345 /* 371 346 * DnsQueryConfig(DnsConfigSearchList, ...) is not implemented. 372 347 * Call GetAdaptersAddresses() that orders the returned list 373 348 * appropriately and collect IP_ADAPTER_ADDRESSES::DnsSuffix. 374 349 */ 375 do { 376 PIP_ADAPTER_ADDRESSES pAddrBuf = NULL; 377 ULONG cbAddrBuf = 8 * 1024; 378 bool fReallocated = false; 379 ULONG err; 380 381 pAddrBuf = (PIP_ADAPTER_ADDRESSES) malloc(cbAddrBuf); 350 do /* not a loop */ 351 { 352 ULONG cbAddrBuf = _8K; 353 PIP_ADAPTER_ADDRESSES pAddrBuf = (PIP_ADAPTER_ADDRESSES)RTMemAllocZ(cbAddrBuf); 382 354 if (pAddrBuf == NULL) 383 355 { 384 LogRel2(("HostDnsServiceWin: failed to allocate %zu bytes" 385 " of GetAdaptersAddresses buffer\n", 386 (size_t)cbAddrBuf)); 356 LogRel2(("HostDnsServiceWin: failed to allocate %zu bytes of GetAdaptersAddresses buffer\n", (size_t)cbAddrBuf)); 387 357 break; 388 358 } 389 359 390 while (pAddrBuf != NULL) 391 { 392 ULONG cbAddrBufProvided = cbAddrBuf; 393 394 err = GetAdaptersAddresses(AF_UNSPEC, 395 GAA_FLAG_SKIP_ANYCAST 396 | GAA_FLAG_SKIP_MULTICAST, 397 NULL, 398 pAddrBuf, &cbAddrBuf); 360 for (unsigned iReallocLoops = 0; ; iReallocLoops++) 361 { 362 ULONG const cbAddrBufProvided = cbAddrBuf; /* for logging */ 363 364 ULONG err = GetAdaptersAddresses(AF_UNSPEC, 365 GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST, 366 NULL, 367 pAddrBuf, &cbAddrBuf); 399 368 if (err == NO_ERROR) 369 break; 370 if (err == ERROR_BUFFER_OVERFLOW) 400 371 { 401 break; 402 } 403 else if (err == ERROR_BUFFER_OVERFLOW) 404 { 405 LogRel2(("HostDnsServiceWin: provided GetAdaptersAddresses with %zu" 406 " but asked again for %zu bytes\n", 372 LogRel2(("HostDnsServiceWin: provided GetAdaptersAddresses with %zu but asked again for %zu bytes\n", 407 373 (size_t)cbAddrBufProvided, (size_t)cbAddrBuf)); 408 409 if (RT_UNLIKELY(fReallocated)) /* what? again?! */ 374 if (iReallocLoops < 16) 410 375 { 411 LogRel2(("HostDnsServiceWin: ... not going to realloc again\n")); 412 free(pAddrBuf); 413 pAddrBuf = NULL; 414 break; 376 /* Reallocate the buffer and try again. */ 377 void * const pvNew = RTMemRealloc(pAddrBuf, cbAddrBuf); 378 if (pvNew) 379 { 380 pAddrBuf = (PIP_ADAPTER_ADDRESSES)pvNew; 381 continue; 382 } 383 384 LogRel2(("HostDnsServiceWin: failed to reallocate %zu bytes\n", (size_t)cbAddrBuf)); 415 385 } 416 417 PIP_ADAPTER_ADDRESSES pNewBuf = (PIP_ADAPTER_ADDRESSES) realloc(pAddrBuf, cbAddrBuf); 418 if (pNewBuf == NULL) 419 { 420 LogRel2(("HostDnsServiceWin: failed to reallocate %zu bytes\n", (size_t)cbAddrBuf)); 421 free(pAddrBuf); 422 pAddrBuf = NULL; 423 break; 424 } 425 426 /* try again */ 427 pAddrBuf = pNewBuf; /* cbAddrBuf already updated */ 428 fReallocated = true; 386 else 387 LogRel2(("HostDnsServiceWin: iReallocLoops=%d - giving up!\n", iReallocLoops)); 429 388 } 430 389 else 390 LogRel2(("HostDnsServiceWin: GetAdaptersAddresses error %d\n", err)); 391 RTMemFree(pAddrBuf); 392 pAddrBuf = NULL; 393 break; 394 } 395 if (pAddrBuf) 396 { 397 for (PIP_ADAPTER_ADDRESSES pAdp = pAddrBuf; pAdp != NULL; pAdp = pAdp->Next) 431 398 { 432 LogRel2(("HostDnsServiceWin: GetAdaptersAddresses error %d\n", err)); 433 free(pAddrBuf); 434 pAddrBuf = NULL; 435 break; 399 LogRel2(("HostDnsServiceWin: %ls (status %u) ...\n", 400 pAdp->FriendlyName ? pAdp->FriendlyName : L"(null)", pAdp->OperStatus)); 401 402 if (pAdp->OperStatus != IfOperStatusUp) 403 continue; 404 405 if (pAdp->DnsSuffix == NULL || *pAdp->DnsSuffix == L'\0') 406 continue; 407 408 char *pszDnsSuffix = NULL; 409 int vrc = RTUtf16ToUtf8Ex(pAdp->DnsSuffix, RTSTR_MAX, &pszDnsSuffix, 0, /* allocate */ NULL); 410 if (RT_FAILURE(vrc)) 411 { 412 LogRel2(("HostDnsServiceWin: failed to convert DNS suffix \"%ls\": %Rrc\n", pAdp->DnsSuffix, vrc)); 413 continue; 414 } 415 416 AssertContinue(pszDnsSuffix != NULL); 417 AssertContinue(*pszDnsSuffix != '\0'); 418 LogRel2(("HostDnsServiceWin: ... suffix = \"%s\"\n", pszDnsSuffix)); 419 420 appendTokenizedStrings(info.searchList, pszDnsSuffix); 421 RTStrFree(pszDnsSuffix); 436 422 } 437 } 438 439 if (pAddrBuf == NULL) 440 break; 441 442 for (PIP_ADAPTER_ADDRESSES pAdp = pAddrBuf; pAdp != NULL; pAdp = pAdp->Next) 443 { 444 LogRel2(("HostDnsServiceWin: %ls (status %u) ...\n", 445 pAdp->FriendlyName ? pAdp->FriendlyName : L"(null)", pAdp->OperStatus)); 446 447 if (pAdp->OperStatus != IfOperStatusUp) 448 continue; 449 450 if (pAdp->DnsSuffix == NULL || *pAdp->DnsSuffix == L'\0') 451 continue; 452 453 char *pszDnsSuffix = NULL; 454 int vrc = RTUtf16ToUtf8Ex(pAdp->DnsSuffix, RTSTR_MAX, &pszDnsSuffix, 0, /* allocate */ NULL); 455 if (RT_FAILURE(vrc)) 456 { 457 LogRel2(("HostDnsServiceWin: failed to convert DNS suffix \"%ls\": %Rrc\n", pAdp->DnsSuffix, vrc)); 458 continue; 459 } 460 461 AssertContinue(pszDnsSuffix != NULL); 462 AssertContinue(*pszDnsSuffix != '\0'); 463 LogRel2(("HostDnsServiceWin: ... suffix = \"%s\"\n", pszDnsSuffix)); 464 465 appendTokenizedStrings(info.searchList, pszDnsSuffix); 466 RTStrFree(pszDnsSuffix); 467 } 468 469 free(pAddrBuf); 423 424 RTMemFree(pAddrBuf); 425 } 470 426 } while (0); 471 427 472 428 473 if (info.domain. empty() && !info.searchList.empty())429 if (info.domain.isEmpty() && !info.searchList.empty()) 474 430 info.domain = info.searchList[0]; 475 431 476 if (info.searchList.size() == 1) 432 if (info.searchList.size() == 1) /* ?? */ 477 433 info.searchList.clear(); 478 434
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器