VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/HostDnsServiceResolvConf.cpp@ 108012

Last change on this file since 108012 was 108012, checked in by vboxsync, 2 weeks ago

Main: Replaced std::string with com::Utf8Str in the HostDnsService code, santizing all the strings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: HostDnsServiceResolvConf.cpp 108012 2025-02-01 02:19:11Z vboxsync $ */
2/** @file
3 * Base class for Host DNS & Co services.
4 */
5
6/*
7 * Copyright (C) 2014-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/* -*- indent-tabs-mode: nil; -*- */
29#include <VBox/com/string.h>
30#include <VBox/com/ptr.h>
31
32
33#ifdef RT_OS_OS2
34# include <sys/socket.h>
35typedef int socklen_t;
36#endif
37
38#include <stdio.h>
39#include <sys/socket.h>
40#include <netinet/in.h>
41#include <arpa/inet.h>
42
43
44#include <iprt/assert.h>
45#include <iprt/errcore.h>
46#include <iprt/file.h>
47#include <iprt/critsect.h>
48
49#include <VBox/log.h>
50
51#include "HostDnsService.h"
52#include "../../Devices/Network/slirp/resolv_conf_parser.h"
53
54
55struct HostDnsServiceResolvConf::Data
56{
57 Data(const char *fileName)
58 : resolvConfFilename(fileName)
59 {
60 };
61
62 com::Utf8Str resolvConfFilename;
63};
64
65HostDnsServiceResolvConf::~HostDnsServiceResolvConf()
66{
67 if (m)
68 {
69 delete m;
70 m = NULL;
71 }
72}
73
74HRESULT HostDnsServiceResolvConf::init(HostDnsMonitorProxy *pProxy, const char *aResolvConfFileName)
75{
76 HRESULT hrc = HostDnsServiceBase::init(pProxy);
77 AssertComRCReturn(hrc, hrc);
78
79 m = new Data(aResolvConfFileName);
80 AssertPtrReturn(m, E_OUTOFMEMORY);
81
82 return readResolvConf();
83}
84
85void HostDnsServiceResolvConf::uninit(void)
86{
87 if (m)
88 {
89 delete m;
90 m = NULL;
91 }
92
93 HostDnsServiceBase::uninit();
94}
95
96const com::Utf8Str &HostDnsServiceResolvConf::getResolvConf(void) const
97{
98 return m->resolvConfFilename;
99}
100
101HRESULT HostDnsServiceResolvConf::readResolvConf(void)
102{
103 struct rcp_state st;
104 st.rcps_flags = RCPSF_NO_STR2IPCONV;
105 int vrc = rcp_parse(&st, m->resolvConfFilename.c_str());
106 if (vrc == -1)
107 return S_OK;
108
109 HostDnsInformation info;
110 for (unsigned i = 0; i != st.rcps_num_nameserver; ++i)
111 {
112 AssertBreak(st.rcps_str_nameserver[i]);
113 RTStrPurgeEncoding(st.rcps_str_nameserver[i]);
114 info.servers.push_back(st.rcps_str_nameserver[i]);
115 }
116
117 if (st.rcps_domain)
118 {
119 RTStrPurgeEncoding(st.rcps_domain);
120 info.domain = st.rcps_domain;
121 }
122
123 for (unsigned i = 0; i != st.rcps_num_searchlist; ++i)
124 {
125 AssertBreak(st.rcps_searchlist[i]);
126 RTStrPurgeEncoding(st.rcps_searchlist[i]);
127 info.searchList.push_back(st.rcps_searchlist[i]);
128 }
129
130 setInfo(info);
131 return S_OK;
132}
133
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