From d6e3164ea10a98a6d65eaac1ef7f1faf142fde37 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 5 Aug 2020 14:42:09 -0700 Subject: [PATCH] remove initial attempt at dns config via scutil --- osdep/MacEthernetTap.cpp | 59 ---------------------------------------- osdep/MacEthernetTap.hpp | 3 -- 2 files changed, 62 deletions(-) diff --git a/osdep/MacEthernetTap.cpp b/osdep/MacEthernetTap.cpp index a48de6758..fb49bad61 100644 --- a/osdep/MacEthernetTap.cpp +++ b/osdep/MacEthernetTap.cpp @@ -458,65 +458,6 @@ void MacEthernetTap::setDns(const char *domain, const std::vector & { MacDNSHelper::doTheThing(); MacDNSHelper::setDNS(this->_nwid, domain, servers); - // _removeDnsConfig(domain, servers); - // _addDnsConfig(domain, servers); -} - -void MacEthernetTap::_removeDnsConfig(const char *domain, const std::vector &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 &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 diff --git a/osdep/MacEthernetTap.hpp b/osdep/MacEthernetTap.hpp index 9ffbdee56..7945bb408 100644 --- a/osdep/MacEthernetTap.hpp +++ b/osdep/MacEthernetTap.hpp @@ -62,9 +62,6 @@ public: throw(); private: - void _removeDnsConfig(const char *domain, const std::vector &servers); - void _addDnsConfig(const char *domain, const std::vector &servers); - void (*_handler)(void *,void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int); void *_arg; uint64_t _nwid;