mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-20 17:52:46 +00:00
Rename Utils::snprintf due to it being a #define on one platform.
This commit is contained in:
parent
02d18af57d
commit
355cce3938
243
attic/DBM.cpp
243
attic/DBM.cpp
@ -1,243 +0,0 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial closed-source software that incorporates or links
|
||||
* directly against ZeroTier software without disclosing the source code
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
#include "DBM.hpp"
|
||||
|
||||
#include "../version.h"
|
||||
|
||||
#include "../node/Salsa20.hpp"
|
||||
#include "../node/Poly1305.hpp"
|
||||
#include "../node/SHA512.hpp"
|
||||
|
||||
#include "../osdep/OSUtils.hpp"
|
||||
|
||||
#define ZT_STORED_OBJECT_TYPE__CLUSTER_NODE_STATUS (ZT_STORED_OBJECT__MAX_TYPE_ID + 1)
|
||||
#define ZT_STORED_OBJECT_TYPE__CLUSTER_DEFINITION (ZT_STORED_OBJECT__MAX_TYPE_ID + 2)
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
// We generate the cluster ID from our address and version info since this is
|
||||
// not at all designed to allow interoperation between versions (or endians)
|
||||
// in the same cluster.
|
||||
static inline uint64_t _mkClusterId(const Address &myAddress)
|
||||
{
|
||||
uint64_t x = ZEROTIER_ONE_VERSION_MAJOR;
|
||||
x <<= 8;
|
||||
x += ZEROTIER_ONE_VERSION_MINOR;
|
||||
x <<= 8;
|
||||
x += ZEROTIER_ONE_VERSION_REVISION;
|
||||
x <<= 40;
|
||||
x ^= myAddress.toInt();
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
++x;
|
||||
#endif;
|
||||
return x;
|
||||
}
|
||||
|
||||
void DBM::onUpdate(uint64_t from,const _MapKey &k,const _MapValue &v,uint64_t rev)
|
||||
{
|
||||
char p[4096];
|
||||
char tmp[ZT_DBM_MAX_VALUE_SIZE];
|
||||
if (_persistentPath((ZT_StoredObjectType)k.type,k.key,p,sizeof(p))) {
|
||||
// Reduce unnecessary disk writes
|
||||
FILE *f = fopen(p,"r");
|
||||
if (f) {
|
||||
long n = (long)fread(tmp,1,sizeof(tmp),f);
|
||||
fclose(f);
|
||||
if ((n == (long)v.len)&&(!memcmp(v.data,tmp,n)))
|
||||
return;
|
||||
}
|
||||
|
||||
// Write to disk if file has changed or was not already present
|
||||
f = fopen(p,"w");
|
||||
if (f) {
|
||||
if (fwrite(data,len,1,f) != 1)
|
||||
fprintf(stderr,"WARNING: error writing to %s (I/O error)" ZT_EOL_S,p);
|
||||
fclose(f);
|
||||
if (type == ZT_STORED_OBJECT_IDENTITY_SECRET)
|
||||
OSUtils::lockDownFile(p,false);
|
||||
} else {
|
||||
fprintf(stderr,"WARNING: error writing to %s (cannot open)" ZT_EOL_S,p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DBM::onDelete(uint64_t from,const _MapKey &k)
|
||||
{
|
||||
char p[4096];
|
||||
if (_persistentPath((ZT_StoredObjectType)k.type,k.key,p,sizeof(p)))
|
||||
OSUtils::rm(p);
|
||||
}
|
||||
|
||||
DBM::_vsdm_cryptor::_vsdm_cryptor(const Identity &secretIdentity)
|
||||
{
|
||||
uint8_t s512[64];
|
||||
SHA512::hash(h512,secretIdentity.privateKeyPair().priv.data,ZT_C25519_PRIVATE_KEY_LEN);
|
||||
memcpy(_key,s512,sizeof(_key));
|
||||
}
|
||||
|
||||
void DBM::_vsdm_cryptor::encrypt(void *d,unsigned long l)
|
||||
{
|
||||
if (l >= 24) { // sanity check
|
||||
uint8_t key[32];
|
||||
uint8_t authKey[32];
|
||||
uint8_t auth[16];
|
||||
|
||||
uint8_t *const iv = reinterpret_cast<uint8_t *>(d) + (l - 16);
|
||||
Utils::getSecureRandom(iv,16);
|
||||
memcpy(key,_key,32);
|
||||
for(unsigned long i=0;i<8;++i)
|
||||
_key[i] ^= iv[i];
|
||||
|
||||
Salsa20 s20(key,iv + 8);
|
||||
memset(authKey,0,32);
|
||||
s20.crypt12(authKey,authKey,32);
|
||||
s20.crypt12(d,d,l - 24);
|
||||
|
||||
Poly1305::compute(auth,d,l - 24,authKey);
|
||||
memcpy(reinterpret_cast<uint8_t *>(d) + (l - 24),auth,8);
|
||||
}
|
||||
}
|
||||
|
||||
bool DBM::_vsdm_cryptor::decrypt(void *d,unsigned long l)
|
||||
{
|
||||
if (l >= 24) { // sanity check
|
||||
uint8_t key[32];
|
||||
uint8_t authKey[32];
|
||||
uint8_t auth[16];
|
||||
|
||||
uint8_t *const iv = reinterpret_cast<uint8_t *>(d) + (l - 16);
|
||||
memcpy(key,_key,32);
|
||||
for(unsigned long i=0;i<8;++i)
|
||||
_key[i] ^= iv[i];
|
||||
|
||||
Salsa20 s20(key,iv + 8);
|
||||
memset(authKey,0,32);
|
||||
s20.crypt12(authKey,authKey,32);
|
||||
|
||||
Poly1305::compute(auth,d,l - 24,authKey);
|
||||
if (!Utils::secureEq(reinterpret_cast<uint8_t *>(d) + (l - 24),auth,8))
|
||||
return false;
|
||||
|
||||
s20.crypt12(d,d,l - 24);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DBM::DBM(const Identity &secretIdentity,uint64_t clusterMemberId,const std::string &basePath,Node *node) :
|
||||
_basePath(basePath),
|
||||
_node(node),
|
||||
_startTime(OSUtils::now()),
|
||||
_m(_mkClusterId(secretIdentity.address()),clusterMemberId,false,_vsdm_cryptor(secretIdentity),_vsdm_watcher(this))
|
||||
{
|
||||
}
|
||||
|
||||
DBM::~DBM()
|
||||
{
|
||||
}
|
||||
|
||||
void DBM::put(const ZT_StoredObjectType type,const uint64_t key,const void *data,unsigned int len)
|
||||
{
|
||||
char p[4096];
|
||||
if (_m.put(_MapKey(key,(uint16_t)type),Value(OSUtils::now(),(uint16_t)len,data))) {
|
||||
if (_persistentPath(type,key,p,sizeof(p))) {
|
||||
FILE *f = fopen(p,"w");
|
||||
if (f) {
|
||||
if (fwrite(data,len,1,f) != 1)
|
||||
fprintf(stderr,"WARNING: error writing to %s (I/O error)" ZT_EOL_S,p);
|
||||
fclose(f);
|
||||
if (type == ZT_STORED_OBJECT_IDENTITY_SECRET)
|
||||
OSUtils::lockDownFile(p,false);
|
||||
} else {
|
||||
fprintf(stderr,"WARNING: error writing to %s (cannot open)" ZT_EOL_S,p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DBM::get(const ZT_StoredObjectType type,const uint64_t key,Value &value)
|
||||
{
|
||||
char p[4096];
|
||||
if (_m.get(_MapKey(key,(uint16_t)type),value))
|
||||
return true;
|
||||
if (_persistentPath(type,key,p,sizeof(p))) {
|
||||
FILE *f = fopen(p,"r");
|
||||
if (f) {
|
||||
long n = (long)fread(value.data,1,sizeof(value.data),f);
|
||||
value.len = (n > 0) ? (uint16_t)n : (uint16_t)0;
|
||||
fclose(f);
|
||||
value.ts = OSUtils::getLastModified(p);
|
||||
_m.put(_MapKey(key,(uint16_t)type),value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DBM::del(const ZT_StoredObjectType type,const uint64_t key)
|
||||
{
|
||||
char p[4096];
|
||||
_m.del(_MapKey(key,(uint16_t)type));
|
||||
if (_persistentPath(type,key,p,sizeof(p)))
|
||||
OSUtils::rm(p);
|
||||
}
|
||||
|
||||
void DBM::clean()
|
||||
{
|
||||
}
|
||||
|
||||
bool DBM::_persistentPath(const ZT_StoredObjectType type,const uint64_t key,char *p,unsigned int maxlen)
|
||||
{
|
||||
switch(type) {
|
||||
case ZT_STORED_OBJECT_IDENTITY_PUBLIC:
|
||||
Utils::snprintf(p,maxlen,"%s" ZT_PATH_SEPARATOR_S "identity.public",_basePath.c_str());
|
||||
return true;
|
||||
case ZT_STORED_OBJECT_IDENTITY_SECRET:
|
||||
Utils::snprintf(p,maxlen,"%s" ZT_PATH_SEPARATOR_S "identity.secret",_basePath.c_str());
|
||||
return true;
|
||||
case ZT_STORED_OBJECT_IDENTITY:
|
||||
Utils::snprintf(p,maxlen,"%s" ZT_PATH_SEPARATOR_S "iddb.d" ZT_PATH_SEPARATOR_S "%.10llx",_basePath.c_str(),key);
|
||||
return true;
|
||||
case ZT_STORED_OBJECT_NETWORK_CONFIG:
|
||||
Utils::snprintf(p,maxlen,"%s" ZT_PATH_SEPARATOR_S "networks.d" ZT_PATH_SEPARATOR_S "%.16llx.conf",_basePath.c_str(),key);
|
||||
return true;
|
||||
case ZT_STORED_OBJECT_PLANET:
|
||||
Utils::snprintf(p,maxlen,"%s" ZT_PATH_SEPARATOR_S "planet",_basePath.c_str());
|
||||
return true;
|
||||
case ZT_STORED_OBJECT_MOON:
|
||||
Utils::snprintf(p,maxlen,"%s" ZT_PATH_SEPARATOR_S "moons.d" ZT_PATH_SEPARATOR_S "%.16llx.moon",_basePath.c_str(),key);
|
||||
return true;
|
||||
case (ZT_StoredObjectType)ZT_STORED_OBJECT_TYPE__CLUSTER_DEFINITION:
|
||||
Utils::snprintf(p,maxlen,"%s" ZT_PATH_SEPARATOR_S "cluster",_basePath.c_str());
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
168
attic/DBM.hpp
168
attic/DBM.hpp
@ -1,168 +0,0 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2017 ZeroTier, Inc. https://www.zerotier.com/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* You can be released from the requirements of the license by purchasing
|
||||
* a commercial license. Buying such a license is mandatory as soon as you
|
||||
* develop commercial closed-source software that incorporates or links
|
||||
* directly against ZeroTier software without disclosing the source code
|
||||
* of your own application.
|
||||
*/
|
||||
|
||||
#ifndef ZT_DBM_HPP___
|
||||
#define ZT_DBM_HPP___
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "../node/Constants.hpp"
|
||||
#include "../node/Mutex.hpp"
|
||||
#include "../node/Utils.hpp"
|
||||
#include "../node/Identity.hpp"
|
||||
#include "../node/Peer.hpp"
|
||||
|
||||
#include "../ext/vsdm/vsdm.hpp"
|
||||
|
||||
// The Peer is the largest structure we persist here
|
||||
#define ZT_DBM_MAX_VALUE_SIZE sizeof(Peer)
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
class Node;
|
||||
class DBM;
|
||||
|
||||
class DBM
|
||||
{
|
||||
public:
|
||||
ZT_PACKED_STRUCT(struct Value
|
||||
{
|
||||
Value(const uint64_t t,const uint16_t l,const void *d) :
|
||||
ts(t),
|
||||
l(l)
|
||||
{
|
||||
memcpy(data,d,l);
|
||||
}
|
||||
uint64_t ts;
|
||||
uint16_t len;
|
||||
uint8_t data[ZT_DBM_MAX_VALUE_SIZE];
|
||||
});
|
||||
|
||||
private:
|
||||
ZT_PACKED_STRUCT(struct _MapKey
|
||||
{
|
||||
_MapKey() : obj(0),type(0) {}
|
||||
_MapKey(const uint16_t t,const uint64_t o) : obj(o),type(t) {}
|
||||
uint64_t obj;
|
||||
uint16_t type;
|
||||
inline bool operator==(const _MapKey &k) const { return ((obj == k.obj)&&(type == k.type)); }
|
||||
});
|
||||
struct _MapHasher
|
||||
{
|
||||
inline std::size_t operator()(const _MapKey &k) const { return (std::size_t)((k.obj ^ (k.obj >> 32)) + (uint64_t)k.type); }
|
||||
};
|
||||
|
||||
void onUpdate(uint64_t from,const _MapKey &k,const Value &v,uint64_t rev);
|
||||
void onDelete(uint64_t from,const _MapKey &k);
|
||||
|
||||
class _vsdm_watcher
|
||||
{
|
||||
public:
|
||||
_vsdm_watcher(DBM *p) : _parent(p) {}
|
||||
inline void add(uint64_t from,const _MapKey &k,const Value &v,uint64_t rev) { _parent->onUpdate(from,k,v,rev); }
|
||||
inline void update(uint64_t from,const _MapKey &k,const Value &v,uint64_t rev) { _parent->onUpdate(from,k,v,rev); }
|
||||
inline void del(uint64_t from,const _MapKey &k) { _parent->onDelete(from,k); }
|
||||
private:
|
||||
DBM *_parent;
|
||||
};
|
||||
class _vsdm_serializer
|
||||
{
|
||||
public:
|
||||
static inline unsigned long objectSize(const _MapKey &k) { return 10; }
|
||||
static inline unsigned long objectSize(const Value &v) { return (10 + v.len); }
|
||||
static inline const char *objectData(const _MapKey &k) { return reinterpret_cast<const char *>(&k); }
|
||||
static inline const char *objectData(const Value &v) { return reinterpret_cast<const char *>(&v); }
|
||||
static inline bool objectDeserialize(const char *d,unsigned long l,_MapKey &k)
|
||||
{
|
||||
if (l == 10) {
|
||||
memcpy(&k,d,10);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static inline bool objectDeserialize(const char *d,unsigned long l,Value &v)
|
||||
{
|
||||
if ((l >= 10)&&(l <= (10 + ZT_DBM_MAX_VALUE_SIZE))) {
|
||||
memcpy(&v,d,l);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
class _vsdm_cryptor
|
||||
{
|
||||
public:
|
||||
_vsdm_cryptor(const Identity &secretIdentity);
|
||||
static inline unsigned long overhead() { return 24; }
|
||||
void encrypt(void *d,unsigned long l);
|
||||
bool decrypt(void *d,unsigned long l);
|
||||
uint8_t _key[32];
|
||||
};
|
||||
|
||||
typedef vsdm< _MapKey,Value,16384,_vsdm_watcher,_vsdm_serializer,_vsdm_cryptor,_MapHasher > _Map;
|
||||
|
||||
friend class _Map;
|
||||
|
||||
public:
|
||||
ZT_PACKED_STRUCT(struct ClusterPeerStatus
|
||||
{
|
||||
uint64_t startTime;
|
||||
uint64_t currentTime;
|
||||
uint64_t clusterPeersConnected;
|
||||
uint64_t ztPeersConnected;
|
||||
uint16_t platform;
|
||||
uint16_t arch;
|
||||
});
|
||||
|
||||
DBM(const Identity &secretIdentity,uint64_t clusterMemberId,const std::string &basePath,Node *node);
|
||||
|
||||
~DBM();
|
||||
|
||||
void put(const ZT_StoredObjectType type,const uint64_t key,const void *data,unsigned int len);
|
||||
|
||||
bool get(const ZT_StoredObjectType type,const uint64_t key,Value &value);
|
||||
|
||||
void del(const ZT_StoredObjectType type,const uint64_t key);
|
||||
|
||||
void clean();
|
||||
|
||||
private:
|
||||
bool DBM::_persistentPath(const ZT_StoredObjectType type,const uint64_t key,char *p,unsigned int maxlen);
|
||||
|
||||
const std::string _basePath;
|
||||
Node *const _node;
|
||||
uint64_t _startTime;
|
||||
_Map _m;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif
|
@ -122,12 +122,12 @@ static json _renderRule(ZT_VirtualNetworkRule &rule)
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_MAC_SOURCE:
|
||||
r["type"] = "MATCH_MAC_SOURCE";
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(unsigned int)rule.v.mac[0],(unsigned int)rule.v.mac[1],(unsigned int)rule.v.mac[2],(unsigned int)rule.v.mac[3],(unsigned int)rule.v.mac[4],(unsigned int)rule.v.mac[5]);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(unsigned int)rule.v.mac[0],(unsigned int)rule.v.mac[1],(unsigned int)rule.v.mac[2],(unsigned int)rule.v.mac[3],(unsigned int)rule.v.mac[4],(unsigned int)rule.v.mac[5]);
|
||||
r["mac"] = tmp;
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_MAC_DEST:
|
||||
r["type"] = "MATCH_MAC_DEST";
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(unsigned int)rule.v.mac[0],(unsigned int)rule.v.mac[1],(unsigned int)rule.v.mac[2],(unsigned int)rule.v.mac[3],(unsigned int)rule.v.mac[4],(unsigned int)rule.v.mac[5]);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(unsigned int)rule.v.mac[0],(unsigned int)rule.v.mac[1],(unsigned int)rule.v.mac[2],(unsigned int)rule.v.mac[3],(unsigned int)rule.v.mac[4],(unsigned int)rule.v.mac[5]);
|
||||
r["mac"] = tmp;
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_IPV4_SOURCE:
|
||||
@ -179,7 +179,7 @@ static json _renderRule(ZT_VirtualNetworkRule &rule)
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_CHARACTERISTICS:
|
||||
r["type"] = "MATCH_CHARACTERISTICS";
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.16llx",rule.v.characteristics);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.16llx",rule.v.characteristics);
|
||||
r["mask"] = tmp;
|
||||
break;
|
||||
case ZT_NETWORK_RULE_MATCH_FRAME_SIZE_RANGE:
|
||||
@ -514,7 +514,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
|
||||
_db.eachMember(nwid,[&responseBody](uint64_t networkId,uint64_t nodeId,const json &member) {
|
||||
if ((member.is_object())&&(member.size() > 0)) {
|
||||
char tmp[128];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s%.10llx\":%llu",(responseBody.length() > 1) ? ",\"" : "\"",(unsigned long long)nodeId,(unsigned long long)OSUtils::jsonInt(member["revision"],0));
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s%.10llx\":%llu",(responseBody.length() > 1) ? ",\"" : "\"",(unsigned long long)nodeId,(unsigned long long)OSUtils::jsonInt(member["revision"],0));
|
||||
responseBody.append(tmp);
|
||||
}
|
||||
});
|
||||
@ -548,7 +548,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
|
||||
for(std::vector<uint64_t>::const_iterator i(networkIds.begin());i!=networkIds.end();++i) {
|
||||
if (responseBody.length() > 1)
|
||||
responseBody.push_back(',');
|
||||
Utils::snprintf(tmp,sizeof(tmp),"\"%.16llx\"",(unsigned long long)*i);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"\"%.16llx\"",(unsigned long long)*i);
|
||||
responseBody.append(tmp);
|
||||
}
|
||||
responseBody.push_back(']');
|
||||
@ -562,7 +562,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
|
||||
// Controller status
|
||||
|
||||
char tmp[4096];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"{\n\t\"controller\": true,\n\t\"apiVersion\": %d,\n\t\"clock\": %llu\n}\n",ZT_NETCONF_CONTROLLER_API_VERSION,(unsigned long long)OSUtils::now());
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"{\n\t\"controller\": true,\n\t\"apiVersion\": %d,\n\t\"clock\": %llu\n}\n",ZT_NETCONF_CONTROLLER_API_VERSION,(unsigned long long)OSUtils::now());
|
||||
responseBody = tmp;
|
||||
responseContentType = "application/json";
|
||||
return 200;
|
||||
@ -603,14 +603,14 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
||||
if ((path.size() >= 2)&&(path[1].length() == 16)) {
|
||||
uint64_t nwid = Utils::hexStrToU64(path[1].c_str());
|
||||
char nwids[24];
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",(unsigned long long)nwid);
|
||||
Utils::ztsnprintf(nwids,sizeof(nwids),"%.16llx",(unsigned long long)nwid);
|
||||
|
||||
if (path.size() >= 3) {
|
||||
|
||||
if ((path.size() == 4)&&(path[2] == "member")&&(path[3].length() == 10)) {
|
||||
uint64_t address = Utils::hexStrToU64(path[3].c_str());
|
||||
char addrs[24];
|
||||
Utils::snprintf(addrs,sizeof(addrs),"%.10llx",(unsigned long long)address);
|
||||
Utils::ztsnprintf(addrs,sizeof(addrs),"%.10llx",(unsigned long long)address);
|
||||
|
||||
json member;
|
||||
_db.getNetworkMember(nwid,address,member);
|
||||
@ -748,7 +748,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
||||
if (!nwid)
|
||||
return 503;
|
||||
}
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",(unsigned long long)nwid);
|
||||
Utils::ztsnprintf(nwids,sizeof(nwids),"%.16llx",(unsigned long long)nwid);
|
||||
|
||||
json network;
|
||||
_db.getNetwork(nwid,network);
|
||||
@ -995,7 +995,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
||||
_queue.post(qe);
|
||||
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"{\"clock\":%llu,\"ping\":%s}",(unsigned long long)now,OSUtils::jsonDump(b).c_str());
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"{\"clock\":%llu,\"ping\":%s}",(unsigned long long)now,OSUtils::jsonDump(b).c_str());
|
||||
responseBody = tmp;
|
||||
responseContentType = "application/json";
|
||||
|
||||
@ -1083,7 +1083,7 @@ void EmbeddedNetworkController::threadMain()
|
||||
auto ms = this->_memberStatus.find(_MemberStatusKey(networkId,nodeId));
|
||||
if (ms != _memberStatus.end())
|
||||
lrt = ms->second.lastRequestTime;
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s\"%.16llx-%.10llx\":%llu",
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s\"%.16llx-%.10llx\":%llu",
|
||||
(first) ? "" : ",",
|
||||
(unsigned long long)networkId,
|
||||
(unsigned long long)nodeId,
|
||||
@ -1093,7 +1093,7 @@ void EmbeddedNetworkController::threadMain()
|
||||
});
|
||||
}
|
||||
char tmp2[256];
|
||||
Utils::snprintf(tmp2,sizeof(tmp2),"},\"clock\":%llu,\"startTime\":%llu}",(unsigned long long)now,(unsigned long long)_startTime);
|
||||
Utils::ztsnprintf(tmp2,sizeof(tmp2),"},\"clock\":%llu,\"startTime\":%llu}",(unsigned long long)now,(unsigned long long)_startTime);
|
||||
pong.append(tmp2);
|
||||
_db.writeRaw("pong",pong);
|
||||
}
|
||||
@ -1126,7 +1126,7 @@ void EmbeddedNetworkController::_request(
|
||||
ms.lastRequestTime = now;
|
||||
}
|
||||
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
Utils::ztsnprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
if (!_db.getNetworkAndMember(nwid,identity.address().toInt(),network,member,ns)) {
|
||||
_sender->ncSendError(nwid,requestPacketId,identity.address(),NetworkController::NC_ERROR_OBJECT_NOT_FOUND);
|
||||
return;
|
||||
|
@ -94,7 +94,7 @@ bool JSONDB::writeRaw(const std::string &n,const std::string &obj)
|
||||
std::string body;
|
||||
std::map<std::string,std::string> reqHeaders;
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%lu",(unsigned long)obj.length());
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%lu",(unsigned long)obj.length());
|
||||
reqHeaders["Content-Length"] = tmp;
|
||||
reqHeaders["Content-Type"] = "application/json";
|
||||
const unsigned int sc = Http::PUT(0,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),(_basePath+"/"+n).c_str(),reqHeaders,obj.data(),(unsigned long)obj.length(),headers,body);
|
||||
@ -164,7 +164,7 @@ bool JSONDB::getNetworkMember(const uint64_t networkId,const uint64_t nodeId,nlo
|
||||
void JSONDB::saveNetwork(const uint64_t networkId,const nlohmann::json &networkConfig)
|
||||
{
|
||||
char n[64];
|
||||
Utils::snprintf(n,sizeof(n),"network/%.16llx",(unsigned long long)networkId);
|
||||
Utils::ztsnprintf(n,sizeof(n),"network/%.16llx",(unsigned long long)networkId);
|
||||
writeRaw(n,OSUtils::jsonDump(networkConfig));
|
||||
{
|
||||
Mutex::Lock _l(_networks_m);
|
||||
@ -176,7 +176,7 @@ void JSONDB::saveNetwork(const uint64_t networkId,const nlohmann::json &networkC
|
||||
void JSONDB::saveNetworkMember(const uint64_t networkId,const uint64_t nodeId,const nlohmann::json &memberConfig)
|
||||
{
|
||||
char n[256];
|
||||
Utils::snprintf(n,sizeof(n),"network/%.16llx/member/%.10llx",(unsigned long long)networkId,(unsigned long long)nodeId);
|
||||
Utils::ztsnprintf(n,sizeof(n),"network/%.16llx/member/%.10llx",(unsigned long long)networkId,(unsigned long long)nodeId);
|
||||
writeRaw(n,OSUtils::jsonDump(memberConfig));
|
||||
{
|
||||
Mutex::Lock _l(_networks_m);
|
||||
@ -202,7 +202,7 @@ nlohmann::json JSONDB::eraseNetwork(const uint64_t networkId)
|
||||
}
|
||||
|
||||
char n[256];
|
||||
Utils::snprintf(n,sizeof(n),"network/%.16llx",(unsigned long long)networkId);
|
||||
Utils::ztsnprintf(n,sizeof(n),"network/%.16llx",(unsigned long long)networkId);
|
||||
|
||||
if (_httpAddr) {
|
||||
// Deletion is currently done by Central in harnessed mode
|
||||
@ -229,7 +229,7 @@ nlohmann::json JSONDB::eraseNetwork(const uint64_t networkId)
|
||||
nlohmann::json JSONDB::eraseNetworkMember(const uint64_t networkId,const uint64_t nodeId,bool recomputeSummaryInfo)
|
||||
{
|
||||
char n[256];
|
||||
Utils::snprintf(n,sizeof(n),"network/%.16llx/member/%.10llx",(unsigned long long)networkId,(unsigned long long)nodeId);
|
||||
Utils::ztsnprintf(n,sizeof(n),"network/%.16llx/member/%.10llx",(unsigned long long)networkId,(unsigned long long)nodeId);
|
||||
|
||||
if (_httpAddr) {
|
||||
// Deletion is currently done by the caller in Central harnessed mode
|
||||
|
@ -144,7 +144,7 @@ public:
|
||||
inline std::string toString() const
|
||||
{
|
||||
char buf[16];
|
||||
Utils::snprintf(buf,sizeof(buf),"%.10llx",(unsigned long long)_a);
|
||||
Utils::ztsnprintf(buf,sizeof(buf),"%.10llx",(unsigned long long)_a);
|
||||
return std::string(buf);
|
||||
};
|
||||
|
||||
@ -154,7 +154,7 @@ public:
|
||||
*/
|
||||
inline void toString(char *buf,unsigned int len) const
|
||||
{
|
||||
Utils::snprintf(buf,len,"%.10llx",(unsigned long long)_a);
|
||||
Utils::ztsnprintf(buf,len,"%.10llx",(unsigned long long)_a);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -391,7 +391,7 @@ public:
|
||||
inline bool add(const char *key,uint64_t value)
|
||||
{
|
||||
char tmp[32];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%llx",(unsigned long long)value);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%llx",(unsigned long long)value);
|
||||
return this->add(key,tmp,-1);
|
||||
}
|
||||
|
||||
@ -401,7 +401,7 @@ public:
|
||||
inline bool add(const char *key,const Address &a)
|
||||
{
|
||||
char tmp[32];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.10llx",(unsigned long long)a.toInt());
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.10llx",(unsigned long long)a.toInt());
|
||||
return this->add(key,tmp,-1);
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ std::string InetAddress::toString() const
|
||||
char buf[128];
|
||||
switch(ss_family) {
|
||||
case AF_INET:
|
||||
Utils::snprintf(buf,sizeof(buf),"%d.%d.%d.%d/%d",
|
||||
Utils::ztsnprintf(buf,sizeof(buf),"%d.%d.%d.%d/%d",
|
||||
(int)(reinterpret_cast<const unsigned char *>(&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr)))[0],
|
||||
(int)(reinterpret_cast<const unsigned char *>(&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr)))[1],
|
||||
(int)(reinterpret_cast<const unsigned char *>(&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr)))[2],
|
||||
@ -161,7 +161,7 @@ std::string InetAddress::toString() const
|
||||
);
|
||||
return std::string(buf);
|
||||
case AF_INET6:
|
||||
Utils::snprintf(buf,sizeof(buf),"%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x/%d",
|
||||
Utils::ztsnprintf(buf,sizeof(buf),"%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x/%d",
|
||||
(int)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr[0]),
|
||||
(int)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr[1]),
|
||||
(int)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr[2]),
|
||||
@ -190,7 +190,7 @@ std::string InetAddress::toIpString() const
|
||||
char buf[128];
|
||||
switch(ss_family) {
|
||||
case AF_INET:
|
||||
Utils::snprintf(buf,sizeof(buf),"%d.%d.%d.%d",
|
||||
Utils::ztsnprintf(buf,sizeof(buf),"%d.%d.%d.%d",
|
||||
(int)(reinterpret_cast<const unsigned char *>(&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr)))[0],
|
||||
(int)(reinterpret_cast<const unsigned char *>(&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr)))[1],
|
||||
(int)(reinterpret_cast<const unsigned char *>(&(reinterpret_cast<const struct sockaddr_in *>(this)->sin_addr.s_addr)))[2],
|
||||
@ -198,7 +198,7 @@ std::string InetAddress::toIpString() const
|
||||
);
|
||||
return std::string(buf);
|
||||
case AF_INET6:
|
||||
Utils::snprintf(buf,sizeof(buf),"%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x",
|
||||
Utils::ztsnprintf(buf,sizeof(buf),"%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x",
|
||||
(int)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr[0]),
|
||||
(int)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr[1]),
|
||||
(int)(reinterpret_cast<const struct sockaddr_in6 *>(this)->sin6_addr.s6_addr[2]),
|
||||
|
@ -178,7 +178,7 @@ public:
|
||||
*/
|
||||
inline void toString(char *buf,unsigned int len) const
|
||||
{
|
||||
Utils::snprintf(buf,len,"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)(*this)[0],(int)(*this)[1],(int)(*this)[2],(int)(*this)[3],(int)(*this)[4],(int)(*this)[5]);
|
||||
Utils::ztsnprintf(buf,len,"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)(*this)[0],(int)(*this)[1],(int)(*this)[2],(int)(*this)[3],(int)(*this)[4],(int)(*this)[5]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,7 @@ public:
|
||||
inline std::string toString() const
|
||||
{
|
||||
char buf[64];
|
||||
Utils::snprintf(buf,sizeof(buf),"%.2x%.2x%.2x%.2x%.2x%.2x/%.8lx",(unsigned int)_mac[0],(unsigned int)_mac[1],(unsigned int)_mac[2],(unsigned int)_mac[3],(unsigned int)_mac[4],(unsigned int)_mac[5],(unsigned long)_adi);
|
||||
Utils::ztsnprintf(buf,sizeof(buf),"%.2x%.2x%.2x%.2x%.2x%.2x/%.8lx",(unsigned int)_mac[0],(unsigned int)_mac[1],(unsigned int)_mac[2],(unsigned int)_mac[3],(unsigned int)_mac[4],(unsigned int)_mac[5],(unsigned long)_adi);
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ namespace ZeroTier {
|
||||
namespace {
|
||||
|
||||
#ifdef ZT_RULES_ENGINE_DEBUGGING
|
||||
#define FILTER_TRACE(f,...) { Utils::snprintf(dpbuf,sizeof(dpbuf),f,##__VA_ARGS__); dlog.push_back(std::string(dpbuf)); }
|
||||
#define FILTER_TRACE(f,...) { Utils::ztsnprintf(dpbuf,sizeof(dpbuf),f,##__VA_ARGS__); dlog.push_back(std::string(dpbuf)); }
|
||||
static const char *_rtn(const ZT_VirtualNetworkRuleType rt)
|
||||
{
|
||||
switch(rt) {
|
||||
@ -1261,7 +1261,7 @@ void Network::requestConfiguration(void *tPtr)
|
||||
nconf->rules[13].t = (uint8_t)ZT_NETWORK_RULE_ACTION_DROP;
|
||||
|
||||
nconf->type = ZT_NETWORK_TYPE_PUBLIC;
|
||||
Utils::snprintf(nconf->name,sizeof(nconf->name),"adhoc-%.04x-%.04x",(int)startPortRange,(int)endPortRange);
|
||||
Utils::ztsnprintf(nconf->name,sizeof(nconf->name),"adhoc-%.04x-%.04x",(int)startPortRange,(int)endPortRange);
|
||||
|
||||
this->setConfiguration(tPtr,*nconf,false);
|
||||
delete nconf;
|
||||
|
@ -94,7 +94,7 @@ bool NetworkConfig::toDictionary(Dictionary<ZT_NETWORKCONFIG_DICT_CAPACITY> &d,b
|
||||
if (ets.length() > 0)
|
||||
ets.push_back(',');
|
||||
char tmp2[16];
|
||||
Utils::snprintf(tmp2,sizeof(tmp2),"%x",et);
|
||||
Utils::ztsnprintf(tmp2,sizeof(tmp2),"%x",et);
|
||||
ets.append(tmp2);
|
||||
}
|
||||
et = 0;
|
||||
|
@ -742,7 +742,7 @@ void Node::postTrace(const char *module,unsigned int line,const char *fmt,...)
|
||||
va_end(ap);
|
||||
tmp2[sizeof(tmp2)-1] = (char)0;
|
||||
|
||||
Utils::snprintf(tmp1,sizeof(tmp1),"[%s] %s:%u %s",nowstr,module,line,tmp2);
|
||||
Utils::ztsnprintf(tmp1,sizeof(tmp1),"[%s] %s:%u %s",nowstr,module,line,tmp2);
|
||||
postEvent((void *)0,ZT_EVENT_TRACE,tmp1);
|
||||
}
|
||||
#endif // ZT_TRACE
|
||||
|
@ -244,8 +244,7 @@ bool Utils::scopy(char *dest,unsigned int len,const char *src)
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int Utils::snprintf(char *buf,unsigned int len,const char *fmt,...)
|
||||
throw(std::length_error)
|
||||
unsigned int Utils::ztsnprintf(char *buf,unsigned int len,const char *fmt,...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
@ -256,7 +255,7 @@ unsigned int Utils::snprintf(char *buf,unsigned int len,const char *fmt,...)
|
||||
if ((n >= (int)len)||(n < 0)) {
|
||||
if (len)
|
||||
buf[len - 1] = (char)0;
|
||||
throw std::length_error("buf[] overflow in Utils::snprintf");
|
||||
throw std::length_error("buf[] overflow");
|
||||
}
|
||||
|
||||
return (unsigned int)n;
|
||||
|
@ -244,8 +244,7 @@ public:
|
||||
* @param ... Format arguments
|
||||
* @throws std::length_error buf[] too short (buf[] will still be left null-terminated)
|
||||
*/
|
||||
static unsigned int snprintf(char *buf,unsigned int len,const char *fmt,...)
|
||||
throw(std::length_error);
|
||||
static unsigned int ztsnprintf(char *buf,unsigned int len,const char *fmt,...);
|
||||
|
||||
/**
|
||||
* Count the number of bits set in an integer
|
||||
|
20
one.cpp
20
one.cpp
@ -260,9 +260,9 @@ static int cli(int argc,char **argv)
|
||||
if (hd) {
|
||||
char p[4096];
|
||||
#ifdef __APPLE__
|
||||
Utils::snprintf(p,sizeof(p),"%s/Library/Application Support/ZeroTier/One/authtoken.secret",hd);
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s/Library/Application Support/ZeroTier/One/authtoken.secret",hd);
|
||||
#else
|
||||
Utils::snprintf(p,sizeof(p),"%s/.zeroTierOneAuthToken",hd);
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s/.zeroTierOneAuthToken",hd);
|
||||
#endif
|
||||
OSUtils::readFile(p,authToken);
|
||||
}
|
||||
@ -278,7 +278,7 @@ static int cli(int argc,char **argv)
|
||||
InetAddress addr;
|
||||
{
|
||||
char addrtmp[256];
|
||||
Utils::snprintf(addrtmp,sizeof(addrtmp),"%s/%u",ip.c_str(),port);
|
||||
Utils::ztsnprintf(addrtmp,sizeof(addrtmp),"%s/%u",ip.c_str(),port);
|
||||
addr = InetAddress(addrtmp);
|
||||
}
|
||||
|
||||
@ -366,7 +366,7 @@ static int cli(int argc,char **argv)
|
||||
std::string addr = path["address"];
|
||||
const uint64_t now = OSUtils::now();
|
||||
const double lq = (path.count("linkQuality")) ? (double)path["linkQuality"] : -1.0;
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s;%llu;%llu;%1.2f",addr.c_str(),now - (uint64_t)path["lastSend"],now - (uint64_t)path["lastReceive"],lq);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s;%llu;%llu;%1.2f",addr.c_str(),now - (uint64_t)path["lastSend"],now - (uint64_t)path["lastReceive"],lq);
|
||||
bestPath = tmp;
|
||||
break;
|
||||
}
|
||||
@ -378,7 +378,7 @@ static int cli(int argc,char **argv)
|
||||
int64_t vmin = p["versionMinor"];
|
||||
int64_t vrev = p["versionRev"];
|
||||
if (vmaj >= 0) {
|
||||
Utils::snprintf(ver,sizeof(ver),"%lld.%lld.%lld",vmaj,vmin,vrev);
|
||||
Utils::ztsnprintf(ver,sizeof(ver),"%lld.%lld.%lld",vmaj,vmin,vrev);
|
||||
} else {
|
||||
ver[0] = '-';
|
||||
ver[1] = (char)0;
|
||||
@ -527,9 +527,9 @@ static int cli(int argc,char **argv)
|
||||
const uint64_t seed = Utils::hexStrToU64(arg2.c_str());
|
||||
if ((worldId)&&(seed)) {
|
||||
char jsons[1024];
|
||||
Utils::snprintf(jsons,sizeof(jsons),"{\"seed\":\"%s\"}",arg2.c_str());
|
||||
Utils::ztsnprintf(jsons,sizeof(jsons),"{\"seed\":\"%s\"}",arg2.c_str());
|
||||
char cl[128];
|
||||
Utils::snprintf(cl,sizeof(cl),"%u",(unsigned int)strlen(jsons));
|
||||
Utils::ztsnprintf(cl,sizeof(cl),"%u",(unsigned int)strlen(jsons));
|
||||
requestHeaders["Content-Type"] = "application/json";
|
||||
requestHeaders["Content-Length"] = cl;
|
||||
unsigned int scode = Http::POST(
|
||||
@ -579,11 +579,11 @@ static int cli(int argc,char **argv)
|
||||
if (eqidx != std::string::npos) {
|
||||
if ((arg2.substr(0,eqidx) == "allowManaged")||(arg2.substr(0,eqidx) == "allowGlobal")||(arg2.substr(0,eqidx) == "allowDefault")) {
|
||||
char jsons[1024];
|
||||
Utils::snprintf(jsons,sizeof(jsons),"{\"%s\":%s}",
|
||||
Utils::ztsnprintf(jsons,sizeof(jsons),"{\"%s\":%s}",
|
||||
arg2.substr(0,eqidx).c_str(),
|
||||
(((arg2.substr(eqidx,2) == "=t")||(arg2.substr(eqidx,2) == "=1")) ? "true" : "false"));
|
||||
char cl[128];
|
||||
Utils::snprintf(cl,sizeof(cl),"%u",(unsigned int)strlen(jsons));
|
||||
Utils::ztsnprintf(cl,sizeof(cl),"%u",(unsigned int)strlen(jsons));
|
||||
requestHeaders["Content-Type"] = "application/json";
|
||||
requestHeaders["Content-Length"] = cl;
|
||||
unsigned int scode = Http::POST(
|
||||
@ -864,7 +864,7 @@ static int idtool(int argc,char **argv)
|
||||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> wbuf;
|
||||
w.serialize(wbuf);
|
||||
char fn[128];
|
||||
Utils::snprintf(fn,sizeof(fn),"%.16llx.moon",w.id());
|
||||
Utils::ztsnprintf(fn,sizeof(fn),"%.16llx.moon",w.id());
|
||||
OSUtils::writeFile(fn,wbuf.data(),wbuf.size());
|
||||
printf("wrote %s (signed world with timestamp %llu)" ZT_EOL_S,fn,(unsigned long long)now);
|
||||
}
|
||||
|
@ -114,8 +114,8 @@ BSDEthernetTap::BSDEthernetTap(
|
||||
|
||||
std::vector<std::string> devFiles(OSUtils::listDirectory("/dev"));
|
||||
for(int i=9993;i<(9993+128);++i) {
|
||||
Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||
Utils::ztsnprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||
Utils::ztsnprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||
if (std::find(devFiles.begin(),devFiles.end(),std::string(tmpdevname)) == devFiles.end()) {
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
@ -152,8 +152,8 @@ BSDEthernetTap::BSDEthernetTap(
|
||||
/* Other BSDs like OpenBSD only have a limited number of tap devices that cannot be renamed */
|
||||
|
||||
for(int i=0;i<64;++i) {
|
||||
Utils::snprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||
Utils::ztsnprintf(tmpdevname,sizeof(tmpdevname),"tap%d",i);
|
||||
Utils::ztsnprintf(devpath,sizeof(devpath),"/dev/%s",tmpdevname);
|
||||
_fd = ::open(devpath,O_RDWR);
|
||||
if (_fd > 0) {
|
||||
_dev = tmpdevname;
|
||||
@ -171,9 +171,9 @@ BSDEthernetTap::BSDEthernetTap(
|
||||
}
|
||||
|
||||
// Configure MAC address and MTU, bring interface up
|
||||
Utils::snprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
Utils::ztsnprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::ztsnprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::ztsnprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"lladdr",ethaddr,"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
||||
@ -385,7 +385,7 @@ void BSDEthernetTap::setMtu(unsigned int mtu)
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%u",mtu);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%u",mtu);
|
||||
execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"mtu",tmp,(const char *)0);
|
||||
_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
|
@ -244,10 +244,10 @@ unsigned int Http::_do(
|
||||
|
||||
try {
|
||||
char tmp[1024];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s %s HTTP/1.1\r\n",method,path);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s %s HTTP/1.1\r\n",method,path);
|
||||
handler.writeBuf.append(tmp);
|
||||
for(std::map<std::string,std::string>::const_iterator h(requestHeaders.begin());h!=requestHeaders.end();++h) {
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s: %s\r\n",h->first.c_str(),h->second.c_str());
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s: %s\r\n",h->first.c_str(),h->second.c_str());
|
||||
handler.writeBuf.append(tmp);
|
||||
}
|
||||
handler.writeBuf.append("\r\n");
|
||||
|
@ -97,7 +97,7 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||
char procpath[128],nwids[32];
|
||||
struct stat sbuf;
|
||||
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
Utils::ztsnprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
|
||||
Mutex::Lock _l(__tapCreateLock); // create only one tap at a time, globally
|
||||
|
||||
@ -134,7 +134,7 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||
std::map<std::string,std::string>::const_iterator gdmEntry = globalDeviceMap.find(nwids);
|
||||
if (gdmEntry != globalDeviceMap.end()) {
|
||||
Utils::scopy(ifr.ifr_name,sizeof(ifr.ifr_name),gdmEntry->second.c_str());
|
||||
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
Utils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
recalledDevice = (stat(procpath,&sbuf) != 0);
|
||||
}
|
||||
|
||||
@ -142,8 +142,8 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||
#ifdef __SYNOLOGY__
|
||||
int devno = 50;
|
||||
do {
|
||||
Utils::snprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"eth%d",devno++);
|
||||
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
Utils::ztsnprintf(ifr.ifr_name,sizeof(ifr.ifr_name),"eth%d",devno++);
|
||||
Utils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
} while (stat(procpath,&sbuf) == 0); // try zt#++ until we find one that does not exist
|
||||
#else
|
||||
char devno = 0;
|
||||
@ -158,7 +158,7 @@ LinuxEthernetTap::LinuxEthernetTap(
|
||||
_base32_5_to_8(reinterpret_cast<const uint8_t *>(tmp2) + 5,tmp3 + 10);
|
||||
tmp3[15] = (char)0;
|
||||
memcpy(ifr.ifr_name,tmp3,16);
|
||||
Utils::snprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
Utils::ztsnprintf(procpath,sizeof(procpath),"/proc/sys/net/ipv4/conf/%s",ifr.ifr_name);
|
||||
} while (stat(procpath,&sbuf) == 0);
|
||||
#endif
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
|
||||
if (date.QuadPart > 0) {
|
||||
date.QuadPart -= adjust.QuadPart;
|
||||
if ((uint64_t)((date.QuadPart / 10000000) * 1000) < olderThan) {
|
||||
Utils::snprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName);
|
||||
Utils::ztsnprintf(tmp, sizeof(tmp), "%s\\%s", path, ffd.cFileName);
|
||||
if (DeleteFileA(tmp))
|
||||
++cleaned;
|
||||
}
|
||||
@ -157,7 +157,7 @@ long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
|
||||
break;
|
||||
if (dptr) {
|
||||
if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))&&(dptr->d_type == DT_REG)) {
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%s/%s",path,dptr->d_name);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%s/%s",path,dptr->d_name);
|
||||
if (stat(tmp,&st) == 0) {
|
||||
uint64_t mt = (uint64_t)(st.st_mtime);
|
||||
if ((mt > 0)&&((mt * 1000) < olderThan)) {
|
||||
@ -446,7 +446,7 @@ std::string OSUtils::jsonString(const nlohmann::json &jv,const char *dfl)
|
||||
return jv;
|
||||
} else if (jv.is_number()) {
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%llu",(uint64_t)jv);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%llu",(uint64_t)jv);
|
||||
return tmp;
|
||||
} else if (jv.is_boolean()) {
|
||||
return ((bool)jv ? std::string("1") : std::string("0"));
|
||||
|
@ -336,7 +336,7 @@ OSXEthernetTap::OSXEthernetTap(
|
||||
char devpath[64],ethaddr[64],mtustr[32],metstr[32],nwids[32];
|
||||
struct stat stattmp;
|
||||
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
Utils::ztsnprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
|
||||
Mutex::Lock _gl(globalTapCreateLock);
|
||||
|
||||
@ -391,13 +391,13 @@ OSXEthernetTap::OSXEthernetTap(
|
||||
// Open the first unused tap device if we didn't recall a previous one.
|
||||
if (!recalledDevice) {
|
||||
for(int i=0;i<64;++i) {
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/zt%d",i);
|
||||
Utils::ztsnprintf(devpath,sizeof(devpath),"/dev/zt%d",i);
|
||||
if (stat(devpath,&stattmp))
|
||||
throw std::runtime_error("no more TAP devices available");
|
||||
_fd = ::open(devpath,O_RDWR);
|
||||
if (_fd > 0) {
|
||||
char foo[16];
|
||||
Utils::snprintf(foo,sizeof(foo),"zt%d",i);
|
||||
Utils::ztsnprintf(foo,sizeof(foo),"zt%d",i);
|
||||
_dev = foo;
|
||||
break;
|
||||
}
|
||||
@ -413,9 +413,9 @@ OSXEthernetTap::OSXEthernetTap(
|
||||
}
|
||||
|
||||
// Configure MAC address and MTU, bring interface up
|
||||
Utils::snprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
Utils::ztsnprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::ztsnprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::ztsnprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"lladdr",ethaddr,"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
||||
@ -636,7 +636,7 @@ void OSXEthernetTap::setMtu(unsigned int mtu)
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%u",mtu);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%u",mtu);
|
||||
execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"mtu",tmp,(const char *)0);
|
||||
_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
|
@ -205,7 +205,7 @@ public:
|
||||
memset(externalip,0,sizeof(externalip));
|
||||
memset(&urls,0,sizeof(urls));
|
||||
memset(&data,0,sizeof(data));
|
||||
Utils::snprintf(inport,sizeof(inport),"%d",localPort);
|
||||
Utils::ztsnprintf(inport,sizeof(inport),"%d",localPort);
|
||||
|
||||
if ((UPNP_GetValidIGD(devlist,&urls,&data,lanaddr,sizeof(lanaddr)))&&(lanaddr[0])) {
|
||||
#ifdef ZT_PORTMAPPER_TRACE
|
||||
@ -220,7 +220,7 @@ public:
|
||||
int tryPort = (int)localPort + tries;
|
||||
if (tryPort >= 65535)
|
||||
tryPort = (tryPort - 65535) + 1025;
|
||||
Utils::snprintf(outport,sizeof(outport),"%u",tryPort);
|
||||
Utils::ztsnprintf(outport,sizeof(outport),"%u",tryPort);
|
||||
|
||||
// First check and see if this port is already mapped to the
|
||||
// same unique name. If so, keep this mapping and don't try
|
||||
|
@ -484,7 +484,7 @@ WindowsEthernetTap::WindowsEthernetTap(
|
||||
char tag[24];
|
||||
|
||||
// We "tag" registry entries with the network ID to identify persistent devices
|
||||
Utils::snprintf(tag,sizeof(tag),"%.16llx",(unsigned long long)nwid);
|
||||
Utils::ztsnprintf(tag,sizeof(tag),"%.16llx",(unsigned long long)nwid);
|
||||
|
||||
Mutex::Lock _l(_systemTapInitLock);
|
||||
|
||||
@ -601,10 +601,10 @@ WindowsEthernetTap::WindowsEthernetTap(
|
||||
|
||||
if (_netCfgInstanceId.length() > 0) {
|
||||
char tmps[64];
|
||||
unsigned int tmpsl = Utils::snprintf(tmps,sizeof(tmps),"%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",(unsigned int)mac[0],(unsigned int)mac[1],(unsigned int)mac[2],(unsigned int)mac[3],(unsigned int)mac[4],(unsigned int)mac[5]) + 1;
|
||||
unsigned int tmpsl = Utils::ztsnprintf(tmps,sizeof(tmps),"%.2X-%.2X-%.2X-%.2X-%.2X-%.2X",(unsigned int)mac[0],(unsigned int)mac[1],(unsigned int)mac[2],(unsigned int)mac[3],(unsigned int)mac[4],(unsigned int)mac[5]) + 1;
|
||||
RegSetKeyValueA(nwAdapters,_mySubkeyName.c_str(),"NetworkAddress",REG_SZ,tmps,tmpsl);
|
||||
RegSetKeyValueA(nwAdapters,_mySubkeyName.c_str(),"MAC",REG_SZ,tmps,tmpsl);
|
||||
tmpsl = Utils::snprintf(tmps, sizeof(tmps), "%d", mtu);
|
||||
tmpsl = Utils::ztsnprintf(tmps, sizeof(tmps), "%d", mtu);
|
||||
RegSetKeyValueA(nwAdapters,_mySubkeyName.c_str(),"MTU",REG_SZ,tmps,tmpsl);
|
||||
|
||||
DWORD tmp = 0;
|
||||
@ -879,7 +879,7 @@ void WindowsEthernetTap::setMtu(unsigned int mtu)
|
||||
HKEY nwAdapters;
|
||||
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ | KEY_WRITE, &nwAdapters) == ERROR_SUCCESS) {
|
||||
char tmps[64];
|
||||
unsigned int tmpsl = Utils::snprintf(tmps, sizeof(tmps), "%d", mtu);
|
||||
unsigned int tmpsl = Utils::ztsnprintf(tmps, sizeof(tmps), "%d", mtu);
|
||||
RegSetKeyValueA(nwAdapters, _mySubkeyName.c_str(), "MTU", REG_SZ, tmps, tmpsl);
|
||||
RegCloseKey(nwAdapters);
|
||||
}
|
||||
@ -902,7 +902,7 @@ void WindowsEthernetTap::threadMain()
|
||||
HANDLE wait4[3];
|
||||
OVERLAPPED tapOvlRead,tapOvlWrite;
|
||||
|
||||
Utils::snprintf(tapPath,sizeof(tapPath),"\\\\.\\Global\\%s.tap",_netCfgInstanceId.c_str());
|
||||
Utils::ztsnprintf(tapPath,sizeof(tapPath),"\\\\.\\Global\\%s.tap",_netCfgInstanceId.c_str());
|
||||
|
||||
try {
|
||||
while (_run) {
|
||||
|
@ -831,7 +831,7 @@ static int testOther()
|
||||
memset(key, 0, sizeof(key));
|
||||
memset(value, 0, sizeof(value));
|
||||
for(unsigned int q=0;q<32;++q) {
|
||||
Utils::snprintf(key[q],16,"%.8lx",(unsigned long)(rand() % 1000) + (q * 1000));
|
||||
Utils::ztsnprintf(key[q],16,"%.8lx",(unsigned long)(rand() % 1000) + (q * 1000));
|
||||
int r = rand() % 128;
|
||||
for(int x=0;x<r;++x)
|
||||
value[q][x] = ("0123456789\0\t\r\n= ")[rand() % 16];
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
return;
|
||||
|
||||
char myAddressStr[64];
|
||||
Utils::snprintf(myAddressStr,sizeof(myAddressStr),"%.10llx",myAddress);
|
||||
Utils::ztsnprintf(myAddressStr,sizeof(myAddressStr),"%.10llx",myAddress);
|
||||
|
||||
std::vector<std::string> lines(OSUtils::split(cf.c_str(),"\r\n","",""));
|
||||
for(std::vector<std::string>::iterator l(lines.begin());l!=lines.end();++l) {
|
||||
|
@ -210,10 +210,10 @@ static void _networkToJson(nlohmann::json &nj,const ZT_VirtualNetworkConfig *nc,
|
||||
case ZT_NETWORK_TYPE_PUBLIC: ntype = "PUBLIC"; break;
|
||||
}
|
||||
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.16llx",nc->nwid);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.16llx",nc->nwid);
|
||||
nj["id"] = tmp;
|
||||
nj["nwid"] = tmp;
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(unsigned int)((nc->mac >> 40) & 0xff),(unsigned int)((nc->mac >> 32) & 0xff),(unsigned int)((nc->mac >> 24) & 0xff),(unsigned int)((nc->mac >> 16) & 0xff),(unsigned int)((nc->mac >> 8) & 0xff),(unsigned int)(nc->mac & 0xff));
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(unsigned int)((nc->mac >> 40) & 0xff),(unsigned int)((nc->mac >> 32) & 0xff),(unsigned int)((nc->mac >> 24) & 0xff),(unsigned int)((nc->mac >> 16) & 0xff),(unsigned int)((nc->mac >> 8) & 0xff),(unsigned int)(nc->mac & 0xff));
|
||||
nj["mac"] = tmp;
|
||||
nj["name"] = nc->name;
|
||||
nj["status"] = nstatus;
|
||||
@ -260,12 +260,12 @@ static void _peerToJson(nlohmann::json &pj,const ZT_Peer *peer)
|
||||
case ZT_PEER_ROLE_PLANET: prole = "PLANET"; break;
|
||||
}
|
||||
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.10llx",peer->address);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.10llx",peer->address);
|
||||
pj["address"] = tmp;
|
||||
pj["versionMajor"] = peer->versionMajor;
|
||||
pj["versionMinor"] = peer->versionMinor;
|
||||
pj["versionRev"] = peer->versionRev;
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%d.%d.%d",peer->versionMajor,peer->versionMinor,peer->versionRev);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%d.%d.%d",peer->versionMajor,peer->versionMinor,peer->versionRev);
|
||||
pj["version"] = tmp;
|
||||
pj["latency"] = peer->latency;
|
||||
pj["role"] = prole;
|
||||
@ -289,7 +289,7 @@ static void _peerToJson(nlohmann::json &pj,const ZT_Peer *peer)
|
||||
static void _moonToJson(nlohmann::json &mj,const World &world)
|
||||
{
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.16llx",world.id());
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.16llx",world.id());
|
||||
mj["id"] = tmp;
|
||||
mj["timestamp"] = world.timestamp();
|
||||
mj["signature"] = Utils::hex(world.signature().data,(unsigned int)world.signature().size());
|
||||
@ -687,7 +687,7 @@ public:
|
||||
|
||||
// Save primary port to a file so CLIs and GUIs can learn it easily
|
||||
char portstr[64];
|
||||
Utils::snprintf(portstr,sizeof(portstr),"%u",_ports[0]);
|
||||
Utils::ztsnprintf(portstr,sizeof(portstr),"%u",_ports[0]);
|
||||
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S "zerotier-one.port").c_str(),std::string(portstr));
|
||||
|
||||
// Attempt to bind to a secondary port chosen from our ZeroTier address.
|
||||
@ -725,7 +725,7 @@ public:
|
||||
}
|
||||
if (_ports[2]) {
|
||||
char uniqueName[64];
|
||||
Utils::snprintf(uniqueName,sizeof(uniqueName),"ZeroTier/%.10llx@%u",_node->address(),_ports[2]);
|
||||
Utils::ztsnprintf(uniqueName,sizeof(uniqueName),"ZeroTier/%.10llx@%u",_node->address(),_ports[2]);
|
||||
_portMapper = new PortMapper(_ports[2],uniqueName);
|
||||
}
|
||||
}
|
||||
@ -1069,7 +1069,7 @@ public:
|
||||
n->second.settings = settings;
|
||||
|
||||
char nlcpath[4096];
|
||||
Utils::snprintf(nlcpath,sizeof(nlcpath),"%s" ZT_PATH_SEPARATOR_S "%.16llx.local.conf",_networksPath.c_str(),nwid);
|
||||
Utils::ztsnprintf(nlcpath,sizeof(nlcpath),"%s" ZT_PATH_SEPARATOR_S "%.16llx.local.conf",_networksPath.c_str(),nwid);
|
||||
FILE *out = fopen(nlcpath,"w");
|
||||
if (out) {
|
||||
fprintf(out,"allowManaged=%d\n",(int)n->second.settings.allowManaged);
|
||||
@ -1188,7 +1188,7 @@ public:
|
||||
ZT_NodeStatus status;
|
||||
_node->status(&status);
|
||||
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.10llx",status.address);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.10llx",status.address);
|
||||
res["address"] = tmp;
|
||||
res["publicIdentity"] = status.publicIdentity;
|
||||
res["online"] = (bool)(status.online != 0);
|
||||
@ -1197,7 +1197,7 @@ public:
|
||||
res["versionMinor"] = ZEROTIER_ONE_VERSION_MINOR;
|
||||
res["versionRev"] = ZEROTIER_ONE_VERSION_REVISION;
|
||||
res["versionBuild"] = ZEROTIER_ONE_VERSION_BUILD;
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%d.%d.%d",ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%d.%d.%d",ZEROTIER_ONE_VERSION_MAJOR,ZEROTIER_ONE_VERSION_MINOR,ZEROTIER_ONE_VERSION_REVISION);
|
||||
res["version"] = tmp;
|
||||
res["clock"] = OSUtils::now();
|
||||
|
||||
@ -1373,7 +1373,7 @@ public:
|
||||
|
||||
if ((scode != 200)&&(seed != 0)) {
|
||||
char tmp[64];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"%.16llx",id);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"%.16llx",id);
|
||||
res["id"] = tmp;
|
||||
res["roots"] = json::array();
|
||||
res["timestamp"] = 0;
|
||||
@ -1617,7 +1617,7 @@ public:
|
||||
std::string h = controllerDbHttpHost;
|
||||
_controllerDbPath.append(h);
|
||||
char dbp[128];
|
||||
Utils::snprintf(dbp,sizeof(dbp),"%d",(int)controllerDbHttpPort);
|
||||
Utils::ztsnprintf(dbp,sizeof(dbp),"%d",(int)controllerDbHttpPort);
|
||||
_controllerDbPath.push_back(':');
|
||||
_controllerDbPath.append(dbp);
|
||||
if (controllerDbHttpPath.is_string()) {
|
||||
@ -1711,7 +1711,7 @@ public:
|
||||
if (syncRoutes) {
|
||||
char tapdev[64];
|
||||
#ifdef __WINDOWS__
|
||||
Utils::snprintf(tapdev,sizeof(tapdev),"%.16llx",(unsigned long long)n.tap->luid().Value);
|
||||
Utils::ztsnprintf(tapdev,sizeof(tapdev),"%.16llx",(unsigned long long)n.tap->luid().Value);
|
||||
#else
|
||||
Utils::scopy(tapdev,sizeof(tapdev),n.tap->deviceName().c_str());
|
||||
#endif
|
||||
@ -1933,24 +1933,24 @@ public:
|
||||
bool secure = false;
|
||||
switch(type) {
|
||||
case ZT_STATE_OBJECT_IDENTITY_PUBLIC:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.public",_homePath.c_str());
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.public",_homePath.c_str());
|
||||
break;
|
||||
case ZT_STATE_OBJECT_IDENTITY_SECRET:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.secret",_homePath.c_str());
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.secret",_homePath.c_str());
|
||||
secure = true;
|
||||
break;
|
||||
case ZT_STATE_OBJECT_PEER_IDENTITY:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "iddb.d/%.10llx",_homePath.c_str(),(unsigned long long)id);
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "iddb.d/%.10llx",_homePath.c_str(),(unsigned long long)id);
|
||||
break;
|
||||
case ZT_STATE_OBJECT_NETWORK_CONFIG:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "networks.d/%.16llx.conf",_homePath.c_str(),(unsigned long long)id);
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "networks.d/%.16llx.conf",_homePath.c_str(),(unsigned long long)id);
|
||||
secure = true;
|
||||
break;
|
||||
case ZT_STATE_OBJECT_PLANET:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "planet",_homePath.c_str());
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "planet",_homePath.c_str());
|
||||
break;
|
||||
case ZT_STATE_OBJECT_MOON:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "moons.d/%.16llx.moon",_homePath.c_str(),(unsigned long long)id);
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "moons.d/%.16llx.moon",_homePath.c_str(),(unsigned long long)id);
|
||||
break;
|
||||
default:
|
||||
p[0] = (char)0;
|
||||
@ -2022,7 +2022,7 @@ public:
|
||||
&_nextBackgroundTaskDeadline);
|
||||
if (ZT_ResultCode_isFatal(rc)) {
|
||||
char tmp[256];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"fatal error code from processWirePacket: %d",(int)rc);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"fatal error code from processWirePacket: %d",(int)rc);
|
||||
Mutex::Lock _l(_termReason_m);
|
||||
_termReason = ONE_UNRECOVERABLE_ERROR;
|
||||
_fatalErrorMessage = tmp;
|
||||
@ -2235,7 +2235,7 @@ public:
|
||||
&_nextBackgroundTaskDeadline);
|
||||
if (ZT_ResultCode_isFatal(rc)) {
|
||||
char tmp[256];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"fatal error code from processWirePacket: %d",(int)rc);
|
||||
Utils::ztsnprintf(tmp,sizeof(tmp),"fatal error code from processWirePacket: %d",(int)rc);
|
||||
Mutex::Lock _l(_termReason_m);
|
||||
_termReason = ONE_UNRECOVERABLE_ERROR;
|
||||
_fatalErrorMessage = tmp;
|
||||
@ -2402,7 +2402,7 @@ public:
|
||||
if (!n.tap) {
|
||||
try {
|
||||
char friendlyName[128];
|
||||
Utils::snprintf(friendlyName,sizeof(friendlyName),"ZeroTier One [%.16llx]",nwid);
|
||||
Utils::ztsnprintf(friendlyName,sizeof(friendlyName),"ZeroTier One [%.16llx]",nwid);
|
||||
|
||||
n.tap = new EthernetTap(
|
||||
_homePath.c_str(),
|
||||
@ -2416,7 +2416,7 @@ public:
|
||||
*nuptr = (void *)&n;
|
||||
|
||||
char nlcpath[256];
|
||||
Utils::snprintf(nlcpath,sizeof(nlcpath),"%s" ZT_PATH_SEPARATOR_S "networks.d" ZT_PATH_SEPARATOR_S "%.16llx.local.conf",_homePath.c_str(),nwid);
|
||||
Utils::ztsnprintf(nlcpath,sizeof(nlcpath),"%s" ZT_PATH_SEPARATOR_S "networks.d" ZT_PATH_SEPARATOR_S "%.16llx.local.conf",_homePath.c_str(),nwid);
|
||||
std::string nlcbuf;
|
||||
if (OSUtils::readFile(nlcpath,nlcbuf)) {
|
||||
Dictionary<4096> nc;
|
||||
@ -2502,7 +2502,7 @@ public:
|
||||
#endif
|
||||
if (op == ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_DESTROY) {
|
||||
char nlcpath[256];
|
||||
Utils::snprintf(nlcpath,sizeof(nlcpath),"%s" ZT_PATH_SEPARATOR_S "networks.d" ZT_PATH_SEPARATOR_S "%.16llx.local.conf",_homePath.c_str(),nwid);
|
||||
Utils::ztsnprintf(nlcpath,sizeof(nlcpath),"%s" ZT_PATH_SEPARATOR_S "networks.d" ZT_PATH_SEPARATOR_S "%.16llx.local.conf",_homePath.c_str(),nwid);
|
||||
OSUtils::rm(nlcpath);
|
||||
}
|
||||
} else {
|
||||
@ -2554,22 +2554,22 @@ public:
|
||||
char p[4096];
|
||||
switch(type) {
|
||||
case ZT_STATE_OBJECT_IDENTITY_PUBLIC:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.public",_homePath.c_str());
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.public",_homePath.c_str());
|
||||
break;
|
||||
case ZT_STATE_OBJECT_IDENTITY_SECRET:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.secret",_homePath.c_str());
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "identity.secret",_homePath.c_str());
|
||||
break;
|
||||
case ZT_STATE_OBJECT_PEER_IDENTITY:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "iddb.d/%.10llx",_homePath.c_str(),(unsigned long long)id);
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "iddb.d/%.10llx",_homePath.c_str(),(unsigned long long)id);
|
||||
break;
|
||||
case ZT_STATE_OBJECT_NETWORK_CONFIG:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "networks.d/%.16llx.conf",_homePath.c_str(),(unsigned long long)id);
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "networks.d/%.16llx.conf",_homePath.c_str(),(unsigned long long)id);
|
||||
break;
|
||||
case ZT_STATE_OBJECT_PLANET:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "planet",_homePath.c_str());
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "planet",_homePath.c_str());
|
||||
break;
|
||||
case ZT_STATE_OBJECT_MOON:
|
||||
Utils::snprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "moons.d/%.16llx.moon",_homePath.c_str(),(unsigned long long)id);
|
||||
Utils::ztsnprintf(p,sizeof(p),"%s" ZT_PATH_SEPARATOR_S "moons.d/%.16llx.moon",_homePath.c_str(),(unsigned long long)id);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
@ -2765,7 +2765,7 @@ public:
|
||||
default: scodestr = "Error"; break;
|
||||
}
|
||||
|
||||
Utils::snprintf(tmpn,sizeof(tmpn),"HTTP/1.1 %.3u %s\r\nCache-Control: no-cache\r\nPragma: no-cache\r\nContent-Type: %s\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
|
||||
Utils::ztsnprintf(tmpn,sizeof(tmpn),"HTTP/1.1 %.3u %s\r\nCache-Control: no-cache\r\nPragma: no-cache\r\nContent-Type: %s\r\nContent-Length: %lu\r\nConnection: close\r\n\r\n",
|
||||
scode,
|
||||
scodestr,
|
||||
contentType.c_str(),
|
||||
|
@ -284,7 +284,7 @@ bool SoftwareUpdater::check(const uint64_t now)
|
||||
if ((now - _lastCheckTime) >= ZT_SOFTWARE_UPDATE_CHECK_PERIOD) {
|
||||
_lastCheckTime = now;
|
||||
char tmp[512];
|
||||
const unsigned int len = Utils::snprintf(tmp,sizeof(tmp),
|
||||
const unsigned int len = Utils::ztsnprintf(tmp,sizeof(tmp),
|
||||
"%c{\"" ZT_SOFTWARE_UPDATE_JSON_VERSION_MAJOR "\":%d,"
|
||||
"\"" ZT_SOFTWARE_UPDATE_JSON_VERSION_MINOR "\":%d,"
|
||||
"\"" ZT_SOFTWARE_UPDATE_JSON_VERSION_REVISION "\":%d,"
|
||||
|
Loading…
x
Reference in New Issue
Block a user