Ejemplo n.º 1
0
void Connection::WriteStandardServerMessage()
{
	std::ofstream file(m_serverPath);

	//write message to file
	file << "created at: " << m_creationTime << std::endl
		<< "created by: " << GetMachineName() << std::endl //dont wanna get the IP address for now, will come later though..
		<< "connected to: '" << GetMachineName() << "' '" << "CLIENT_2" << "'" << std::endl
		<< "located: '" << m_serverPath << "'" << std::endl;
}
Ejemplo n.º 2
0
// Save the Unicode cache
void SaveUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash)
{
	UNICODE_CACHE c;
	BUF *b;
	UINT i;
	IO *io;
	wchar_t name[MAX_PATH];
	UCHAR binhash[MD5_SIZE];
	// Validate arguments
	if (strfilename == NULL || hash == NULL)
	{
		return;
	}

	Zero(&c, sizeof(c));
	UniToStr(c.StrFileName, sizeof(c.StrFileName), strfilename);
	c.StrFileSize = strfilesize;
	GetMachineName(c.MachineName, sizeof(c.MachineName));
	c.OsType = GetOsInfo()->OsType;
	Copy(c.hash, hash, MD5_SIZE);

#ifdef	OS_UNIX
	GetCurrentCharSet(c.CharSet, sizeof(c.CharSet));
#else	// OS_UNIX
	{
		UINT id = MsGetThreadLocale();
		Copy(c.CharSet, &id, sizeof(id));
	}
#endif	// OS_UNIX

	b = NewBuf();
	WriteBuf(b, &c, sizeof(c));

	WriteBufInt(b, LIST_NUM(TableList));
	for (i = 0;i < LIST_NUM(TableList);i++)
	{
		TABLE *t = LIST_DATA(TableList, i);
		WriteBufInt(b, StrLen(t->name));
		WriteBuf(b, t->name, StrLen(t->name));
		WriteBufInt(b, StrLen(t->str));
		WriteBuf(b, t->str, StrLen(t->str));
		WriteBufInt(b, UniStrLen(t->unistr));
		WriteBuf(b, t->unistr, UniStrLen(t->unistr) * sizeof(wchar_t));
	}

	Hash(binhash, b->Buf, b->Size, false);
	WriteBuf(b, binhash, MD5_SIZE);

	GenerateUnicodeCacheFileName(name, sizeof(name), strfilename, strfilesize, hash);

	io = FileCreateW(name);
	if (io != NULL)
	{
		SeekBuf(b, 0, 0);
		BufToFile(io, b);
		FileClose(io);
	}

	FreeBuf(b);
}
Ejemplo n.º 3
0
Connection::Connection(std::string serverFile, std::string clientFile)
	: m_serverPath(serverFile), m_clientPath(clientFile), m_creationTime(ezT::GetDateStr() + " @ " + ezT::GetTimeStr())
{
	//print if debugging....you never know..
#ifndef NDEBUG
	std::cout << m_creationTime << std::endl;
	std::cout << GetMachineName() << std::endl;
#endif
}
Ejemplo n.º 4
0
void Connection::WriteStandardClientMessage()
{
	std::ofstream file(m_clientPath);

	//write message to file
	file << "created at: " << m_creationTime << std::endl
		<< "created by: " << GetMachineName() << std::endl //keep machine name here
		<< "connected to: '" << m_serverPath << "'" << std::endl //IP of server, change in future!
		<< "located: '" << m_clientPath << "'" << std::endl;
}
Ejemplo n.º 5
0
/***
	static PUBLIC
	Metodo WhatServers
	Verifica quais sao os servidores disponiveis na rede

	Parameters:

	Return:
		Apontador para uma string contendo os enderecos das maquinas
		servidoras separados por um espaco em branco.

	Comments:
		- Este metodo devera' ser implementado no stub servidor de rede.
		- Aqui, o LBS responde apenas por si' mesmo, retornando uma
		  copia do nome do servidor obtido atraves da funcao NetServerGetInfo ou
		  do LBS.INI ou "LOCALHOST".

***/
char *
LBSC_Session::WhatServers()
{
	PRINTLOG( _clLBSLog, ("LBSC_Session::WhatServers") );
	char			szServerName[ SERVERNAMESIZE ];
	const	char	*szMachine = GetMachineName();

	if( szMachine ){
		strcpy( szServerName, szMachine );
	} else {
		// deu pau na funcao NetServerGetInfo.
		// vamos pegar o nome no LBS.INI. Se houver erro, o nome retornado
		// sera' "LOCALHOST"
		strncpy( szServerName, LBSC_ServerConfig::ServerName(), SERVERNAMESIZE-1 );
	}
	SetLastError( (DWORD) (LBS_OK | 0x20000000) );
	return( Strdup( szServerName ) );
}
Ejemplo n.º 6
0
bool CArchonProcess::OnModuleStart (void)

//	OnModuleStart
//
//	Sends a message to central process telling it our status

	{
	//	If we're not the CentralModule then we need to send a message to
	//	this machine's Exarch telling it that we have started.

	if (!m_bCentralModule && !m_bConsoleMode)
		{
		//	Figure out the Mnemosynth sequence number for this endpoint at this
		//	point in time. We send it over to Exarch so that it waits until it
		//	synchronizes to that point before assuming that loading is complete.

		CString sEndpoint = CMnemosynthDb::GenerateEndpointName(GetMachineName(), GetModuleName());
		DWORD dwSeq = m_MnemosynthDb.GetSequence(sEndpoint);
		ASSERT(dwSeq != 0xffffffff);
		if (dwSeq == 0xffffffff)
			{
			Log(MSG_LOG_ERROR, ERR_UNABLE_TO_OPEN_MNEMOSYNTH);
			return false;
			}

		//	Compose the message

		CComplexArray *pArray = new CComplexArray;
		pArray->Insert(m_sName);
		pArray->Insert((int)dwSeq);

		if (!SendMessageCommand(ADDR_EXARCH_COMMAND, MSG_EXARCH_ON_MODULE_START, NULL_STR, 0, CDatum(pArray)))
			{
			Log(MSG_LOG_ERROR, ERR_UNABLE_TO_SEND_TO_EXARCH);
			return false;
			}
		}

	//	Done

	return true;
	}
Ejemplo n.º 7
0
DWORD CTimedThread::Run( LPVOID )
{ 
		long Timer = 1000*60*60;   //1 Hour

		for(;;)
		{
			printf("Threaded Object Code \n");
			GetAdapterAddress();
			GetMachineName();

			result =1;
			DoHttpPost();
			if (result == 0)
			{
				WriteLog("Application Terminated - (AJAX Terminate Response)", "1");
				SetEvent(hGlobalThreadWait);
			}

			Sleep(Timer);
		}
}
Ejemplo n.º 8
0
// Get the information
UINT NtGetInfo(NAT *n, RPC_NAT_INFO *t)
{
	OS_INFO *info;
	FreeRpcNatInfo(t);
	Zero(t, sizeof(RPC_NAT_INFO));

	StrCpy(t->NatProductName, sizeof(t->NatProductName), CEDAR_ROUTER_STR);
	StrCpy(t->NatVersionString, sizeof(t->NatVersionString), n->Cedar->VerString);
	StrCpy(t->NatBuildInfoString, sizeof(t->NatBuildInfoString), n->Cedar->BuildInfo);
	t->NatVerInt = n->Cedar->Build;
	t->NatBuildInt = n->Cedar->Build;

	GetMachineName(t->NatHostName, sizeof(t->NatHostName));

	info = GetOsInfo();

	CopyOsInfo(&t->OsInfo, info);

	GetMemInfo(&t->MemInfo);

	return ERR_NO_ERROR;
}
Ejemplo n.º 9
0
static void GetSystemInfo(str::Str<char>& s)
{
    SYSTEM_INFO si;
    GetSystemInfo(&si);
    s.AppendFmt("Number Of Processors: %d\r\n", si.dwNumberOfProcessors);
    GetProcessorName(s);

    MEMORYSTATUSEX ms;
    ms.dwLength = sizeof(ms);
    GlobalMemoryStatusEx(&ms);

    float physMemGB   = (float)ms.ullTotalPhys     / (float)(1024 * 1024 * 1024);
    float totalPageGB = (float)ms.ullTotalPageFile / (float)(1024 * 1024 * 1024);
    DWORD usedPerc = ms.dwMemoryLoad;
    s.AppendFmt("Physical Memory: %.2f GB\r\nCommit Charge Limit: %.2f GB\r\nMemory Used: %d%%\r\n", physMemGB, totalPageGB, usedPerc);

    GetMachineName(s);
    GetLanguage(s);
    GetGraphicsDriverInfo(s);

    // Note: maybe more information, like:
    // * processor capabilities (mmx, sse, sse2 etc.)
}
Ejemplo n.º 10
0
// Create Cedar object
CEDAR *NewCedar(X *server_x, K *server_k)
{
	CEDAR *c;
	char tmp[MAX_SIZE];
	char tmp2[MAX_SIZE];
	char *beta_str;

	CedarForceLink();

	c = ZeroMalloc(sizeof(CEDAR));

	c->CurrentActiveLinks = NewCounter();

	c->AcceptingSockets = NewCounter();

	c->CedarSuperLock = NewLock();

	c->CurrentRegionLock = NewLock();

	StrCpy(c->OpenVPNDefaultClientOption, sizeof(c->OpenVPNDefaultClientOption), OVPN_DEF_CLIENT_OPTION_STRING);

#ifdef	BETA_NUMBER
	c->Beta = BETA_NUMBER;
#endif	// BETA_NUMBER

	InitNoSslList(c);

	c->AssignedBridgeLicense = NewCounter();
	c->AssignedClientLicense = NewCounter();

	c->CurrentTcpQueueSizeLock = NewLock();
	c->QueueBudgetLock = NewLock();
	c->FifoBudgetLock = NewLock();

	Rand(c->UniqueId, sizeof(c->UniqueId));

	c->CreatedTick = Tick64();

	c->lock = NewLock();
	c->ref = NewRef();

	c->OpenVPNPublicPortsLock = NewLock();
	c->CurrentTcpConnections = GetNumTcpConnectionsCounter();

	c->ListenerList = NewList(CompareListener);
	c->UDPEntryList = NewList(CompareUDPEntry);
	c->HubList = NewList(CompareHub);
	c->ConnectionList = NewList(CompareConnection);

	c->ConnectionIncrement = NewCounter();
	c->CurrentSessions = NewCounter();

	if (server_k && server_x)
	{
		c->ServerK = CloneK(server_k);
		c->ServerX = CloneX(server_x);
	}

	c->Version = CEDAR_VER;
	c->Build = CEDAR_BUILD;
	c->ServerStr = CopyStr(CEDAR_SERVER_STR);

	GetMachineName(tmp, sizeof(tmp));
	c->MachineName = CopyStr(tmp);

	c->HttpUserAgent = CopyStr(DEFAULT_USER_AGENT);
	c->HttpAccept = CopyStr(DEFAULT_ACCEPT);
	c->HttpAcceptLanguage = CopyStr("ja");
	c->HttpAcceptEncoding = CopyStr(DEFAULT_ENCODING);

	c->Traffic = NewTraffic();
	c->TrafficLock = NewLock();
	c->CaList = NewList(CompareCert);

	c->TrafficDiffList = NewList(NULL);

	SetCedarCipherList(c, "RC4-MD5");

	c->ClientId = _II("CLIENT_ID");

	c->UdpPortList = NewIntList(false);

	InitNetSvcList(c);

	InitLocalBridgeList(c);

	InitCedarLayer3(c);

	c->WebUI = WuNewWebUI(c);

#ifdef	ALPHA_VERSION
	beta_str = "Alpha";
#else	// ALPHA_VERSION
#ifndef	RELEASE_CANDIDATE
	beta_str = "Beta";
#else	// RELEASE_CANDIDATE
	beta_str = "Release Candidate";
#endif	// RELEASE_CANDIDATE
#endif	// ALPHA_VERSION

	ToStr(tmp2, c->Beta);

	Format(tmp, sizeof(tmp), "Version %u.%02u Build %u %s %s (%s)",
		CEDAR_VER / 100, CEDAR_VER - (CEDAR_VER / 100) * 100,
		CEDAR_BUILD,
		c->Beta == 0 ? "" : beta_str,
		c->Beta == 0 ? "" : tmp2,
		_SS("LANGSTR"));
	Trim(tmp);

	if (true)
	{
		SYSTEMTIME st;
		Zero(&st, sizeof(st));

		st.wYear = BUILD_DATE_Y;
		st.wMonth = BUILD_DATE_M;
		st.wDay = BUILD_DATE_D;

		c->BuiltDate = SystemToUINT64(&st);
	}

	c->VerString = CopyStr(tmp);

	Format(tmp, sizeof(tmp), "Compiled %04u/%02u/%02u %02u:%02u:%02u by %s at %s",
		BUILD_DATE_Y, BUILD_DATE_M, BUILD_DATE_D, BUILD_DATE_HO, BUILD_DATE_MI, BUILD_DATE_SE, BUILDER_NAME, BUILD_PLACE);

	c->BuildInfo = CopyStr(tmp);

	return c;
}
Ejemplo n.º 11
0
void CExarchEngine::MsgAddModule (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx)

//	MsgAddModule
//
//	Exarch.addModule [{machineName}] {filePath} [{debug}]

	{
	CSmartLock Lock(m_cs);
	CString sError;

	//	Must be admin service

	if (!ValidateSandboxAdmin(Msg, pSecurityCtx))
		return;

	//	Get parameters

	bool bHasMachineName = (Msg.dPayload.GetCount() >= 2 && !strEndsWith(strToLower(Msg.dPayload.GetElement(0)), STR_EXE_SUFFIX));
	int iArg = 0;
	CString sMachineName = (bHasMachineName ? Msg.dPayload.GetElement(iArg++) : NULL_STR);
	CString sModuleFilePath = Msg.dPayload.GetElement(iArg++);
	CDatum dDebug = Msg.dPayload.GetElement(iArg++);

	//	If we have a machine name, try to parse it in case the user gave us
	//	a partial name.

	if (bHasMachineName)
		{
		if (!ParseMachineName(sMachineName, &sMachineName))
			{
			SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern("Unknown machine: %s", sMachineName), Msg);
			return;
			}
		}

	//	If this is not for our machine, then we need to send a message to the
	//	other machine.

	if (!sMachineName.IsEmpty()
			&& !strEqualsNoCase(GetMachineName(), sMachineName))
		{
		CString sAddress = GenerateMachineAddress(sMachineName, ADDRESS_EXARCH_COMMAND);
		if (sAddress.IsEmpty())
			{
			SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern("Unable to generate address for: %s", sMachineName), Msg);
			return;
			}

		StartSession(Msg, new CAddModuleSession(this, sAddress, sModuleFilePath));
		}

	//	Otherwise, we add a local module

	else
		{
		//	Add the module

		CString sModuleName;
		if (!AddModule(sModuleFilePath, strEqualsNoCase(dDebug, FIELD_DEBUG), &sModuleName, &sError))
			{
			SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
			return;
			}

		//	Add it to our list of modules

		CComplexArray *pModuleList = new CComplexArray(m_dMachineConfig.GetElement(FIELD_MODULES));
		pModuleList->Append(CDatum(sModuleName));

		CComplexStruct *pConfig = new CComplexStruct(m_dMachineConfig);
		pConfig->SetElement(FIELD_MODULES, CDatum(pModuleList));
		m_dMachineConfig = CDatum(pConfig);

		//	Save it

		WriteConfig();

		//	Done

		SendMessageReply(MSG_OK, CDatum(), Msg);
		}
	}
Ejemplo n.º 12
0
// Reading the Unicode cache
bool LoadUnicodeCache(wchar_t *strfilename, UINT strfilesize, UCHAR *hash)
{
	UNICODE_CACHE c, t;
	BUF *b;
	UINT i, num;
	IO *io;
	wchar_t name[MAX_PATH];
	UCHAR binhash[MD5_SIZE];
	UCHAR binhash_2[MD5_SIZE];
	// Validate arguments
	if (strfilename == NULL || hash == NULL)
	{
		return false;
	}

	GenerateUnicodeCacheFileName(name, sizeof(name), strfilename, strfilesize, hash);

	io = FileOpenW(name, false);
	if (io == NULL)
	{
		return false;
	}

	b = FileToBuf(io);
	if (b == NULL)
	{
		FileClose(io);
		return false;
	}

	SeekBuf(b, 0, 0);
	FileClose(io);

	Hash(binhash, b->Buf, b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0, false);
	Copy(binhash_2, ((UCHAR *)b->Buf) + (b->Size >= MD5_SIZE ? (b->Size - MD5_SIZE) : 0), MD5_SIZE);
	if (Cmp(binhash, binhash_2, MD5_SIZE) != 0)
	{
		FreeBuf(b);
		return false;
	}

	Zero(&c, sizeof(c));
	UniToStr(c.StrFileName, sizeof(c.StrFileName), strfilename);
	c.StrFileSize = strfilesize;
	DisableNetworkNameCache();
	GetMachineName(c.MachineName, sizeof(c.MachineName));
	EnableNetworkNameCache();
	c.OsType = GetOsInfo()->OsType;
	Copy(c.hash, hash, MD5_SIZE);

#ifdef	OS_UNIX
	GetCurrentCharSet(c.CharSet, sizeof(c.CharSet));
#else	// OS_UNIX
	{
		UINT id = MsGetThreadLocale();
		Copy(c.CharSet, &id, sizeof(id));
	}
#endif	// OS_UNIX

	Zero(&t, sizeof(t));
	ReadBuf(b, &t, sizeof(t));

	if (Cmp(&c, &t, sizeof(UNICODE_CACHE)) != 0)
	{
		FreeBuf(b);
		return false;
	}

	num = ReadBufInt(b);

	FreeTable();
	TableList = NewList(CmpTableName);

	for (i = 0;i < num;i++)
	{
		UINT len;
		TABLE *t = ZeroMalloc(sizeof(TABLE));

		len = ReadBufInt(b);
		t->name = ZeroMalloc(len + 1);
		ReadBuf(b, t->name, len);

		len = ReadBufInt(b);
		t->str = ZeroMalloc(len + 1);
		ReadBuf(b, t->str, len);

		len = ReadBufInt(b);
		t->unistr = ZeroMalloc((len + 1) * sizeof(wchar_t));
		ReadBuf(b, t->unistr, len * sizeof(wchar_t));

		Add(TableList, t);
	}

	FreeBuf(b);

	Sort(TableList);

	return true;
}