From fc6dba079795d9e0c7a053b5539d157c615c68d6 Mon Sep 17 00:00:00 2001 From: Diego Schulz Date: Thu, 2 Aug 2018 17:13:55 -0400 Subject: Add functionality to erase members from networks using file backend in controller microservice Signed-off-by: Diego Schulz --- controller/EmbeddedNetworkController.cpp | 1 + controller/FileDB.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index ef52f6e0..f4d1c958 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -1042,6 +1042,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE( json network,member; _db->get(nwid,network,address,member); + _db->eraseMember(nwid, address); { std::lock_guard l(_memberStatus_l); diff --git a/controller/FileDB.cpp b/controller/FileDB.cpp index a7b59cbf..d4bc16ad 100644 --- a/controller/FileDB.cpp +++ b/controller/FileDB.cpp @@ -134,12 +134,24 @@ void FileDB::eraseNetwork(const uint64_t networkId) get(networkId,network); char p[16384]; OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "%.16llx.json",_networksPath.c_str(),networkId); - OSUtils::rm(p); + + if (OSUtils::fileExists(p,false)){ + OSUtils::rm(p); + } _networkChanged(network,nullJson,true); } void FileDB::eraseMember(const uint64_t networkId,const uint64_t memberId) { + nlohmann::json network,member,nullJson; + get(networkId,network); + get(memberId,member); + char p[16384]; + OSUtils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "%.16llx" ZT_PATH_SEPARATOR_S "member" ZT_PATH_SEPARATOR_S "%.10llx.json",_networksPath.c_str(),networkId,memberId); + if (OSUtils::fileExists(p,false)){ + OSUtils::rm(p); + } + _memberChanged(member,nullJson,true); } void FileDB::nodeIsOnline(const uint64_t networkId,const uint64_t memberId,const InetAddress &physicalAddress) -- cgit v1.2.3 From 8e260bae116f01839899d319e5efb0e6867b99a0 Mon Sep 17 00:00:00 2001 From: Vincent Milum Jr Date: Fri, 14 Sep 2018 22:42:58 -0700 Subject: Correcting conversion to/from IP address / string 1) Use existing standard libraries to convert to/from IPv4/IPv6 strings and binary representation. 2) Move null terminator assignment InetAddress::toIpString to top of function, this way if ANY errors occurs that don't write content to the buffer, we're not passing a potentially dangerous buffer around. --- node/InetAddress.cpp | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp index 36b4e434..bc1974c7 100644 --- a/node/InetAddress.cpp +++ b/node/InetAddress.cpp @@ -139,33 +139,15 @@ char *InetAddress::toString(char buf[64]) const char *InetAddress::toIpString(char buf[64]) const { + memset(buf,0,64); switch(ss_family) { case AF_INET: { - const uint8_t *a = reinterpret_cast(&(reinterpret_cast(this)->sin_addr.s_addr)); - char *p = buf; - for(int i=0;;++i) { - Utils::decimal((unsigned long)a[i],p); - if (i != 3) { - while (*p) ++p; - *(p++) = '.'; - } else break; - } - } break; + inet_ntop(AF_INET, &reinterpret_cast(this)->sin_addr.s_addr, buf, INET_ADDRSTRLEN); + } break; case AF_INET6: { - uint16_t a[8]; - ZT_FAST_MEMCPY(a,reinterpret_cast(this)->sin6_addr.s6_addr,16); - char *p = buf; - for(int i=0;i<8;++i) { - Utils::hex(Utils::ntoh(a[i]),p); - p[4] = (i == 7) ? (char)0 : ':'; - p += 5; - } + inet_ntop(AF_INET6, reinterpret_cast(this)->sin6_addr.s6_addr, buf, INET6_ADDRSTRLEN); } break; - - default: - buf[0] = (char)0; - break; } return buf; } @@ -191,28 +173,17 @@ bool InetAddress::fromString(const char *ipSlashPort) } if (strchr(buf,':')) { - uint16_t a[8]; - unsigned int b = 0; - char *saveptr = (char *)0; - for(char *s=Utils::stok(buf,":",&saveptr);((s)&&(b<8));s=Utils::stok((char *)0,":",&saveptr)) - a[b++] = Utils::hton((uint16_t)(Utils::hexStrToUInt(s) & 0xffff)); - struct sockaddr_in6 *const in6 = reinterpret_cast(this); + inet_pton(AF_INET6, buf, &in6->sin6_addr.s6_addr); in6->sin6_family = AF_INET6; - ZT_FAST_MEMCPY(in6->sin6_addr.s6_addr,a,16); in6->sin6_port = Utils::hton((uint16_t)port); + return true; } else if (strchr(buf,'.')) { - uint8_t a[4]; - unsigned int b = 0; - char *saveptr = (char *)0; - for(char *s=Utils::stok(buf,".",&saveptr);((s)&&(b<4));s=Utils::stok((char *)0,".",&saveptr)) - a[b++] = (uint8_t)(Utils::strToUInt(s) & 0xff); - struct sockaddr_in *const in = reinterpret_cast(this); + inet_pton(AF_INET, buf, &in->sin_addr.s_addr); in->sin_family = AF_INET; - ZT_FAST_MEMCPY(&(in->sin_addr.s_addr),a,4); in->sin_port = Utils::hton((uint16_t)port); return true; -- cgit v1.2.3 From 79b47b055a5ba08e94a6024a183217394416e583 Mon Sep 17 00:00:00 2001 From: Vincent Milum Jr Date: Sat, 15 Sep 2018 12:13:06 -0700 Subject: Only null terminate the first character --- node/InetAddress.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/InetAddress.cpp b/node/InetAddress.cpp index bc1974c7..2b9158f2 100644 --- a/node/InetAddress.cpp +++ b/node/InetAddress.cpp @@ -139,7 +139,7 @@ char *InetAddress::toString(char buf[64]) const char *InetAddress::toIpString(char buf[64]) const { - memset(buf,0,64); + buf[0] = (char)0; switch(ss_family) { case AF_INET: { inet_ntop(AF_INET, &reinterpret_cast(this)->sin_addr.s_addr, buf, INET_ADDRSTRLEN); -- cgit v1.2.3 From 88d879987d72e5ba6a700f1cbe0329d88e420a41 Mon Sep 17 00:00:00 2001 From: Tommy Yang Date: Sun, 23 Sep 2018 16:53:30 -0700 Subject: Remove symlinks from the actual location Binary symlinks are in `/usr/local/bin` instead of `/usr/bin` since commit 0cf4ddd --- ext/installfiles/mac/uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/installfiles/mac/uninstall.sh b/ext/installfiles/mac/uninstall.sh index 9bf5d6fc..52c09b63 100755 --- a/ext/installfiles/mac/uninstall.sh +++ b/ext/installfiles/mac/uninstall.sh @@ -27,7 +27,7 @@ kextunload '/Library/Application Support/ZeroTier/One/tap.kext' >>/dev/null 2>&1 echo "Removing ZeroTier One files..." rm -rf '/Applications/ZeroTier One.app' -rm -f '/usr/bin/zerotier-one' '/usr/bin/zerotier-idtool' '/usr/bin/zerotier-cli' '/Library/LaunchDaemons/com.zerotier.one.plist' +rm -f '/usr/local/bin/zerotier-one' '/usr/local/bin/zerotier-idtool' '/usr/local/bin/zerotier-cli' '/Library/LaunchDaemons/com.zerotier.one.plist' cd '/Library/Application Support/ZeroTier/One' if [ "`pwd`" = '/Library/Application Support/ZeroTier/One' ]; then -- cgit v1.2.3