Fix ZT_SSO_SUPPORTED flag behavior. Allow disabling for embedded targets.

This commit is contained in:
Joseph Henry 2022-03-31 21:45:38 -07:00
parent d67f59f5b5
commit 6f4a69703b
No known key found for this signature in database
GPG Key ID: C45B33FF5EBC9344
3 changed files with 43 additions and 30 deletions

View File

@ -1,12 +1,12 @@
# Automagically pick CLANG or RH/CentOS newer GCC if present
# This is only done if we have not overridden these with an environment or CLI variable
ifeq ($(origin CC),default)
CC:=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
CC:=$(shell if [ -e /opt/rh/devtoolset-8/root/usr/bin/gcc ]; then echo /opt/rh/devtoolset-8/root/usr/bin/gcc; else echo $(CC); fi)
CC:=$(shell if [ -e /usr/bin/clang ]; then echo clang; else echo gcc; fi)
CC:=$(shell if [ -e /opt/rh/devtoolset-8/root/usr/bin/gcc ]; then echo /opt/rh/devtoolset-8/root/usr/bin/gcc; else echo $(CC); fi)
endif
ifeq ($(origin CXX),default)
CXX:=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
CXX:=$(shell if [ -e /opt/rh/devtoolset-8/root/usr/bin/g++ ]; then echo /opt/rh/devtoolset-8/root/usr/bin/g++; else echo $(CXX); fi)
CXX:=$(shell if [ -e /usr/bin/clang++ ]; then echo clang++; else echo g++; fi)
CXX:=$(shell if [ -e /opt/rh/devtoolset-8/root/usr/bin/g++ ]; then echo /opt/rh/devtoolset-8/root/usr/bin/g++; else echo $(CXX); fi)
endif
INCLUDES?=-Izeroidc/target
@ -75,16 +75,19 @@ else
endif
ifeq ($(ZT_QNAP), 1)
override DEFS+=-D__QNAP__
override DEFS+=-D__QNAP__
ZT_EMBEDDED=1
endif
ifeq ($(ZT_UBIQUITI), 1)
override DEFS+=-D__UBIQUITI__
override DEFS+=-D__UBIQUITI__
ZT_EMBEDDED=1
endif
ifeq ($(ZT_SYNOLOGY), 1)
override CFLAGS+=-fPIC
override CXXFLAGS+=-fPIC
override DEFS+=-D__SYNOLOGY__
ZT_EMBEDDED=1
endif
ifeq ($(ZT_DISABLE_COMPRESSION), 1)
@ -213,9 +216,9 @@ ifeq ($(CC_MACH),armv7hl)
ZT_USE_ARM32_NEON_ASM_CRYPTO=1
endif
ifeq ($(CC_MACH),armv7ve)
ZT_ARCHITECTURE=3
override DEFS+=-DZT_NO_TYPE_PUNNING
ZT_USE_ARM32_NEON_ASM_CRYPTO=1
ZT_ARCHITECTURE=3
override DEFS+=-DZT_NO_TYPE_PUNNING
ZT_USE_ARM32_NEON_ASM_CRYPTO=1
endif
ifeq ($(CC_MACH),arm64)
ZT_ARCHITECTURE=4
@ -268,10 +271,13 @@ ifeq ($(ZT_IA32),1)
endif
ifeq ($(ZT_SSO_SUPPORTED), 1)
ifeq ($(ZT_DEBUG),1)
LDLIBS+=zeroidc/target/debug/libzeroidc.a -ldl -lssl -lcrypto
else
LDLIBS+=zeroidc/target/release/libzeroidc.a -ldl -lssl -lcrypto
ifeq ($(ZT_EMBEDDED),)
override DEFS+=-DZT_SSO_SUPPORTED=1
ifeq ($(ZT_DEBUG),1)
LDLIBS+=zeroidc/target/debug/libzeroidc.a -ldl -lssl -lcrypto
else
LDLIBS+=zeroidc/target/release/libzeroidc.a -ldl -lssl -lcrypto
endif
endif
endif
@ -384,9 +390,11 @@ debug: FORCE
make ZT_DEBUG=1 selftest
ifeq ($(ZT_SSO_SUPPORTED), 1)
ifeq ($(ZT_EMBEDDED),)
zeroidc: FORCE
# export PATH=/root/.cargo/bin:$$PATH; cd zeroidc && cargo build -j1 $(RUSTFLAGS)
export PATH=/root/.cargo/bin:$$PATH; cd zeroidc && cargo build $(RUSTFLAGS)
endif
else
zeroidc:
endif

View File

@ -50,16 +50,17 @@
#define __UNIX_LIKE__
#endif
#include <endian.h>
#if (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64) || defined(__aarch64__))
#define OIDC_SUPPORTED 1
#else
#define OIDC_SUPPORTED 0
#ifdef ZT_SSO_SUPPORTED
#define ZT_SSO_ENABLED 1
#endif
#endif
#endif
#ifdef __APPLE__
#define OIDC_SUPPORTED 1
#ifdef ZT_SSO_SUPPORTED
#define ZT_SSO_ENABLED 1
#endif
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
#include <TargetConditionals.h>
@ -73,7 +74,9 @@
#endif
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
#define OIDC_SUPPORTED 0
#ifdef ZT_SSO_SUPPORTED
#define ZT_SSO_ENABLED 0
#endif
#ifndef __UNIX_LIKE__
#define __UNIX_LIKE__
#endif
@ -89,7 +92,9 @@
#endif
#if defined(_WIN32) || defined(_WIN64)
#define OIDC_SUPPORTED 1
#ifdef ZT_SSO_SUPPORTED
#define ZT_SSO_ENABLED 1
#endif
#ifndef __WINDOWS__
#define __WINDOWS__
#endif

View File

@ -53,7 +53,7 @@
#include "OneService.hpp"
#include "SoftwareUpdater.hpp"
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
#include <zeroidc.h>
#endif
@ -195,7 +195,7 @@ public:
NetworkState()
: _webPort(9993)
, _tap((EthernetTap *)0)
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
, _idc(nullptr)
#endif
{
@ -212,7 +212,7 @@ public:
this->_managedRoutes.clear();
this->_tap.reset();
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
if (_idc) {
zeroidc::zeroidc_stop(_idc);
zeroidc::zeroidc_delete(_idc);
@ -296,7 +296,7 @@ public:
if (_config.ssoEnabled && _config.ssoVersion == 1) {
// fprintf(stderr, "ssoEnabled for %s\n", nwid);
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
if (_idc == nullptr)
{
assert(_config.issuerURL != nullptr);
@ -353,7 +353,7 @@ public:
}
const char* getAuthURL() {
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
if (_idc != nullptr) {
return zeroidc::zeroidc_get_auth_url(_idc);
}
@ -363,7 +363,7 @@ public:
}
const char* doTokenExchange(const char *code) {
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
if (_idc == nullptr) {
fprintf(stderr, "ainfo or idc null\n");
return "";
@ -386,7 +386,7 @@ public:
}
uint64_t getExpiryTime() {
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
if (_idc == nullptr) {
fprintf(stderr, "idc is null\n");
return 0;
@ -404,7 +404,7 @@ private:
std::vector<InetAddress> _managedIps;
std::map< InetAddress, SharedPtr<ManagedRoute> > _managedRoutes;
OneService::NetworkSettings _settings;
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
zeroidc::ZeroIDC *_idc;
#endif
};
@ -1705,7 +1705,7 @@ public:
scode = _controller->handleControlPlaneHttpGET(std::vector<std::string>(ps.begin()+1,ps.end()),urlArgs,headers,body,responseBody,responseContentType);
} else scode = 404;
}
#if OIDC_SUPPORTED
#if ZT_SSO_ENABLED
} else if (ps[0] == "sso") {
char resBuf[4096] = {0};
const char *error = zeroidc::zeroidc_get_url_param_value("error", path.c_str());
@ -2308,11 +2308,11 @@ public:
fprintf(stderr,"ERROR: unable to add ip address %s" ZT_EOL_S, ip->toString(ipbuf));
}
}
#endif
#ifdef __APPLE__
if (!MacDNSHelper::addIps(n.config().nwid, n.config().mac, n.tap()->deviceName().c_str(), newManagedIps))
fprintf(stderr, "ERROR: unable to add v6 addresses to system configuration" ZT_EOL_S);
#endif
#endif
n.setManagedIps(newManagedIps);
}