summaryrefslogtreecommitdiff
path: root/enterprise.cpp
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2024-06-12 21:59:50 -0400
committerAlexander Taylor <alex@vector35.com>2024-06-26 09:47:42 -0400
commit015bb4fa79d01a1e2d4887cba96d150c7e1dd3bb (patch)
tree8333733fca03ec373b63d7390096db986e0b8a3f /enterprise.cpp
parent17435e0df2dccb8f09ec26e54de017ee05ade8ee (diff)
[Enterprise] Clean up initialization flow
Diffstat (limited to 'enterprise.cpp')
-rw-r--r--enterprise.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/enterprise.cpp b/enterprise.cpp
index 837bab59..abbaac8b 100644
--- a/enterprise.cpp
+++ b/enterprise.cpp
@@ -23,6 +23,19 @@
using namespace BinaryNinja::Enterprise;
+
+bool BinaryNinja::Enterprise::IsInitialized()
+{
+ return BNIsEnterpriseServerInitialized();
+}
+
+
+bool BinaryNinja::Enterprise::Initialize()
+{
+ return BNInitializeEnterpriseServer();
+}
+
+
bool BinaryNinja::Enterprise::AuthenticateWithCredentials(const std::string& username, const std::string& password, bool remember)
{
return BNAuthenticateEnterpriseServerWithCredentials(username.c_str(), password.c_str(), remember);
@@ -99,6 +112,8 @@ bool BinaryNinja::Enterprise::IsAuthenticated()
std::string BinaryNinja::Enterprise::GetUsername()
{
char* value = BNGetEnterpriseServerUsername();
+ if (!value)
+ return "";
std::string result = value;
BNFreeString(value);
return result;
@@ -108,6 +123,8 @@ std::string BinaryNinja::Enterprise::GetUsername()
std::string BinaryNinja::Enterprise::GetToken()
{
char* value = BNGetEnterpriseServerToken();
+ if (!value)
+ return "";
std::string result = value;
BNFreeString(value);
return result;
@@ -117,6 +134,8 @@ std::string BinaryNinja::Enterprise::GetToken()
std::string BinaryNinja::Enterprise::GetServerName()
{
char* value = BNGetEnterpriseServerName();
+ if (!value)
+ return "";
std::string result = value;
BNFreeString(value);
return result;
@@ -126,6 +145,8 @@ std::string BinaryNinja::Enterprise::GetServerName()
std::string BinaryNinja::Enterprise::GetServerUrl()
{
char* value = BNGetEnterpriseServerUrl();
+ if (!value)
+ return "";
std::string result = value;
BNFreeString(value);
return result;
@@ -135,6 +156,8 @@ std::string BinaryNinja::Enterprise::GetServerUrl()
std::string BinaryNinja::Enterprise::GetServerId()
{
char* value = BNGetEnterpriseServerId();
+ if (!value)
+ return "";
std::string result = value;
BNFreeString(value);
return result;
@@ -150,6 +173,8 @@ uint64_t BinaryNinja::Enterprise::GetServerVersion()
std::string BinaryNinja::Enterprise::GetServerBuildId()
{
char* value = BNGetEnterpriseServerBuildId();
+ if (!value)
+ return "";
std::string result = value;
BNFreeString(value);
return result;
@@ -188,7 +213,6 @@ bool BinaryNinja::Enterprise::IsLicenseStillActivated()
std::string BinaryNinja::Enterprise::GetLastError()
{
- return BNGetEnterpriseServerLastError();
char* str = BNGetEnterpriseServerLastError();
std::string value = str;
BNFreeString(str);
@@ -208,7 +232,7 @@ void BinaryNinja::Enterprise::UnregisterNotification(BNEnterpriseServerCallbacks
}
-BinaryNinja::Enterprise::LicenseCheckout::LicenseCheckout(int64_t duration)
+BinaryNinja::Enterprise::LicenseCheckout::LicenseCheckout(int64_t duration): m_acquiredLicense(false)
{
// This is a port of python's binaryninja.enterprise.LicenseCheckout
@@ -216,6 +240,28 @@ BinaryNinja::Enterprise::LicenseCheckout::LicenseCheckout(int64_t duration)
if (BNIsUIEnabled())
return;
+ if (!IsInitialized())
+ {
+ if (!Initialize())
+ {
+ // Named/computer licenses don't need this flow at all
+ if (!IsFloatingLicense())
+ {
+ return;
+ }
+
+ // Floating licenses though, this is an error. Probably the error
+ // for needing to set enterprise.server.url in settings.json
+ throw EnterpriseException(
+ "Could not initialize Binary Ninja Enterprise: " + GetLastError()
+ );
+ }
+ }
+
+ if (!IsFloatingLicense())
+ {
+ return;
+ }
if (!IsConnected())
{
Connect();