[prev in list] [next in list] [prev in thread] [next in thread]
List: helix-server-cvs
Subject: [Server-cvs] license/slicensepln server_license.cpp, 1.20.4.5, 1.20.4.6
From: yijil () helixcommunity ! org
Date: 2013-12-19 6:06:43
[Download RAW message or body]
Update of /cvsroot/server/license/slicensepln
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv19047
Modified Files:
Tag: SERVER_15_1_0
server_license.cpp
Log Message:
Committed to: HEAD, SERVER_15_1_0_RN
Reviewed by: Richard
Synopsis
========
Update in ServerLicense
Branches: HEAD, SERVER_15_1_0_RN
Reviewer: Anyone
Description
===========
Change method to fetch local address in ServerLicense and add back "AWS PASSTHRU" \
check
Using another method to fetch local address
Files Affected
==============
server/license/slicensepln/server_license.cpp
Test perform
==============
Integration Tests:
None
Leak Tests: None
Performance Tests: N/A
Platforms Tested: win-x86_64-vc10
QA Hints
========
None.
Index: server_license.cpp
===================================================================
RCS file: /cvsroot/server/license/slicensepln/server_license.cpp,v
retrieving revision 1.20.4.5
retrieving revision 1.20.4.6
diff -u -d -r1.20.4.5 -r1.20.4.6
--- server_license.cpp 17 Dec 2013 06:11:48 -0000 1.20.4.5
+++ server_license.cpp 19 Dec 2013 06:06:39 -0000 1.20.4.6
@@ -68,6 +68,13 @@
#include <arpa/inet.h>
#endif
+#ifdef _LINUX
+#include <sys/types.h>
+#include <ifaddrs.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
+
#ifdef _WIN32
#include "reg.h"
#endif
@@ -146,18 +153,10 @@
char* pFilename = NULL;
//Get local address
- char hostname[1024];
- gethostname(hostname,sizeof(hostname));
- struct hostent *h;
- h = hx_gethostbyname(hostname);
- if (h)
+ if (HXR_OK != FetchLocalIPAddress())
{
- for (INT32 i = 0; h->h_addr_list[i] != NULL; i++)
- {
- char* pAddr = inet_ntoa(*(struct in_addr*)h->h_addr_list[i]);
- char* pSaveAddr = new_string(pAddr);
- m_pAddrArray->Add(pSaveAddr);
- }
+ LICENSE_ERRMSG("Can`t fetch local IP address.\n");
+ return HXR_FAIL;
}
//KT: We need to do something about implementing SetReadOnly
@@ -415,17 +414,39 @@
{
if (strcmp((const char*)pBuffer->GetBuffer(), "AWSKey") == 0)
{
- hResult = ValidateAWS(AWSMetaData_ProductCode, pServRegKey);
+ HXBOOL bPass = FALSE;
+ IHXBuffer* pBufDistribution = NULL;
+ sprintf(pRegKey, "%s.License.Definition.Distribution", \
pServRegKey); + hResult = m_pRegistry->GetStrByName(pRegKey, \
pBufDistribution); + if (hResult == HXR_OK && pBufDistribution && \
strstr((const char*)pBufDistribution->GetBuffer(), "AWS PASSTHRU")) + \
{ + bPass = TRUE;
+ }
+ HX_RELEASE(pBufDistribution);
+
+ if (!bPass)
+ {
+ hResult = ValidateAWS(AWSMetaData_ProductCode, pServRegKey);
+ }
+ else
+ {
+ hResult = ValidateAWS(AWSMetaData_InstanceID, pServRegKey);
+ }
}
else if (strcmp((const char*)pBuffer->GetBuffer(), "CPNKey") == 0)
{
hResult = ValidateComputNext(pServRegKey, TRUE);
+ if (HXR_OK != hResult)
+ {
+ LICENSE_ERRMSG("ComputeNext license could not run on \
non-ComputeNext platform.\n"); + }
}
else if (strcmp((const char*)pBuffer->GetBuffer(), "NormalKey") == \
0) {
if (HXR_OK == ValidateAWS(AWSMetaData_InstanceID, pServRegKey) \
|| HXR_OK == ValidateComputNext(pServRegKey, FALSE))
{
+ LICENSE_ERRMSG("Common license could not run on ComputeNext \
or AWS platform.\n"); hResult = HXR_FAIL;
}
}
@@ -437,6 +458,7 @@
else if (HXR_OK == ValidateAWS(AWSMetaData_InstanceID, pServRegKey) ||
HXR_OK == ValidateComputNext(pServRegKey, FALSE))
{
+ LICENSE_ERRMSG("Common license could not run on ComputeNext or AWS \
platform.\n"); hResult = HXR_FAIL;
}
else
@@ -979,6 +1001,81 @@
}
HX_RESULT
+ServerLicense::FetchLocalIPAddress()
+{
+#if defined(_LINUX)
+ struct ifaddrs* ifa = NULL, *oifa;
+ if (getifaddrs(&ifa) < 0)
+ {
+ return HXR_FAIL;
+ }
+ oifa = ifa;
+ while (ifa != NULL)
+ {
+ if (ifa->ifa_addr != NULL && (ifa->ifa_addr->sa_family == AF_INET || \
ifa->ifa_addr->sa_family == AF_INET6)) + {
+ struct sockaddr_in* saddr = (struct sockaddr_in*)ifa->ifa_addr;
+
+ char* pAddr = inet_ntoa(saddr->sin_addr);
+ if (strcmp(pAddr, "0.0.0.0") != 0 &&
+ strcmp(pAddr, "127.0.0.1") != 0)
+ {
+ char* pSaveAddr = new_string(pAddr);
+ m_pAddrArray->Add(pSaveAddr);
+ }
+ }
+ ifa = ifa->ifa_next;
+ }
+ freeifaddrs(oifa);
+#else
+ int wsError;
+ SOCKET s;
+ DWORD bytesReturned;
+ char* pAddr = NULL;
+ SOCKADDR_IN* pAddrInet;
+ INTERFACE_INFO localAddr[1024];
+ int numLocalAddr = 0;
+
+ if((s = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 0, 0)) == \
INVALID_SOCKET) + {
+ return HXR_FAIL;
+ }
+
+ // Enumerate all IP interfaces
+ wsError = WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0, &localAddr,
+ sizeof(localAddr), &bytesReturned, NULL, NULL);
+ if (wsError == SOCKET_ERROR)
+ {
+ closesocket(s);
+ return HXR_FAIL;
+ }
+
+ closesocket(s);
+
+ numLocalAddr = (bytesReturned/sizeof(INTERFACE_INFO));
+ for (int i = 0; i < numLocalAddr; i++)
+ {
+ pAddrInet = (SOCKADDR_IN*)&localAddr[i].iiAddress;
+ pAddr = inet_ntoa(pAddrInet->sin_addr);
+ if (strcmp(pAddr, "0.0.0.0") != 0 &&
+ strcmp(pAddr, "127.0.0.1") != 0)
+ {
+ char* pSaveAddr = new_string(pAddr);
+ m_pAddrArray->Add(pSaveAddr);
+ }
+ }
+#endif
+ if (m_pAddrArray->GetSize() > 0)
+ {
+ return HXR_OK;
+ }
+ else
+ {
+ return HXR_FAIL;
+ }
+}
+
+HX_RESULT
ServerLicense::ValidateAWS(AWSMetaDataType eType, const char* pMainRegKey)
{
HX_RESULT hResult = HXR_FAIL;
@@ -994,9 +1091,9 @@
char pRegKey[256] = {0};
sprintf(pRegKey, "%s.License.Definition.AWSProductCode", pMainRegKey);
hResult = m_pRegistry->GetStrByName(pRegKey, pCode);
- if (strcmp((const char*)pBuffer->GetBuffer(), (const \
char*)pCode->GetBuffer()) != 0) + if (strcmp((const \
char*)pBuffer->GetBuffer(), (const char*)pCode->GetBuffer()) == 0) {
- hResult == HXR_FAIL;
+ hResult == HXR_OK;
}
HX_RELEASE(pCode);
LICENSE_ERRMSG("AWS AMI must have a product code and match with the \
license.\n"); @@ -1018,10 +1115,6 @@
HX_RESULT hResult = HXR_FAIL;
if (m_pAddrArray->GetSize() <= 0)
{
- if (bCPN)
- {
- LICENSE_ERRMSG("Can`t fetch local address for ComputeNext \
authentication.\n");
- }
return hResult;
}
#if !defined(_LINUX) || !defined(_WINDOWS)
@@ -1168,7 +1261,7 @@
if ((nRetSize = recv(fd, pRecvBuffer, DEFAULT_TCP_READ_SIZE - 1, 0)) <= 0)
{
- LICENSE_ERRMSG("could not receive ComputeNext licensing check.\n");
+ LICENSE_ERRMSG("could not receive ComputeNext license check.\n");
goto out_error;
}
pRecvBuffer[nRetSize] = 0;
@@ -1212,7 +1305,7 @@
{
if (!bCPN)
{
- LICENSE_ERRMSG("ComputeNext licensing could not run on \
non-ComputeNext platform.\n"); + LICENSE_ERRMSG("Non ComputeNext \
license could not run on ComputeNext platform.\n"); }
break;
}
_______________________________________________
Server-cvs mailing list
Server-cvs@helixcommunity.org
http://lists.helixcommunity.org/mailman/listinfo/server-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic