remove initial attempt at dns config via scutil

This commit is contained in:
Grant Limberg 2020-08-05 14:42:09 -07:00
parent 302ac8fefe
commit d6e3164ea1
No known key found for this signature in database
GPG Key ID: 2BA62CCABBB4095A
2 changed files with 0 additions and 62 deletions

View File

@ -458,65 +458,6 @@ void MacEthernetTap::setDns(const char *domain, const std::vector<InetAddress> &
{
MacDNSHelper::doTheThing();
MacDNSHelper::setDNS(this->_nwid, domain, servers);
// _removeDnsConfig(domain, servers);
// _addDnsConfig(domain, servers);
}
void MacEthernetTap::_removeDnsConfig(const char *domain, const std::vector<InetAddress> &servers)
{
std::string tmpfile = std::tmpnam(nullptr);
std::FILE *remf = std::fopen(tmpfile.c_str(), "w");
char buf[4096] = {0};
sprintf(buf, "remove State:/Network/Service/%.16llx/DNS\n", _nwid);
std::fputs(buf, remf);
std::fflush(remf);
std::fclose(remf);
fprintf(stderr, "wrote tmpfile %s\n", tmpfile.c_str());
long cpid = (long)vfork();
if (cpid == 0) {
char cmd[1024] = {0};
sprintf(cmd, "/usr/sbin/scutil < %s", tmpfile.c_str());
::execl("/bin/sh", "-c", cmd);
} else if (cpid > 0) {
int exitcode = -1;
::waitpid(cpid, &exitcode,0);
if (exitcode) {
throw std::runtime_error("scutil dns config remove error");
}
}
}
void MacEthernetTap::_addDnsConfig(const char *domain, const std::vector<InetAddress> &servers)
{
std::string tmpfile = std::tmpnam(nullptr);
std::FILE *addf = std::fopen(tmpfile.c_str(), "w");
char buf[4096] = {0};
sprintf(buf, "d.init\n");
sprintf(buf, "d.add ServerAddresses *");
for (auto it = servers.begin(); it != servers.end(); ++it) {
char ipbuf[128] = {0};
sprintf(buf, " %s", it->toIpString(buf));
}
sprintf(buf, "\n");
sprintf(buf, "d.add SupplementalMatchDomains * %s\n", domain);
sprintf(buf, "set State:/Network/Service/%.16llx/DNS", _nwid);
std::fputs(buf, addf);
std::fflush(addf);
std::fclose(addf);
fprintf(stderr, "wrote add tmpfile %s\n", tmpfile.c_str());
long cpid = (long)vfork();
if (cpid == 0) {
char cmd[1024];
sprintf(cmd, "'/usr/bin/scutil < %s'", tmpfile.c_str());
fprintf(stderr, "%s\n", cmd);
::execl("/bin/sh", "-c", cmd);
} else if (cpid > 0) {
int exitcode = -1;
::waitpid(cpid, &exitcode, 0);
if (exitcode) {
throw std::runtime_error("scutil dns config add error");
}
}
}
} // namespace ZeroTier

View File

@ -62,9 +62,6 @@ public:
throw();
private:
void _removeDnsConfig(const char *domain, const std::vector<InetAddress> &servers);
void _addDnsConfig(const char *domain, const std::vector<InetAddress> &servers);
void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
void *_arg;
uint64_t _nwid;