[Box Backup-commit] COMMIT r3057 - in box/invisnet/vs2010/0.11: infrastructure/msvc/2010 infrastructure/msvc/2010/install/custom infrastructure/msvc/2010/install/setup lib/win32/_sys

subversion at boxbackup.org subversion at boxbackup.org
Thu Jan 19 19:00:05 GMT 2012


Author: invisnet
Date: 2012-01-19 19:00:04 +0000 (Thu, 19 Jan 2012)
New Revision: 3057

Added:
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/Custom.cpp
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/Custom.def
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/FetchServerCert.cpp
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/GenerateCSR.cpp
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/GenerateKeyFile.cpp
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/resource.h
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/stdafx.cpp
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/stdafx.h
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/targetver.h
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/setup/bblogo.bmp
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/setup/bbsplash.bmp
   box/invisnet/vs2010/0.11/lib/win32/_sys/socket.h
   box/invisnet/vs2010/0.11/lib/win32/_sys/syslog.cpp
   box/invisnet/vs2010/0.11/lib/win32/_sys/syslog.h
Modified:
   box/invisnet/vs2010/0.11/infrastructure/msvc/2010/boxbackup.sln
Log:
Add missing files

Modified: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/boxbackup.sln
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/boxbackup.sln	2012-01-19 18:28:55 UTC (rev 3056)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/boxbackup.sln	2012-01-19 19:00:04 UTC (rev 3057)
@@ -21,10 +21,16 @@
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "crypt", "crypt", "{F6273D56-81D4-4D75-BD47-0EAFDE030BCD}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpcre", "pcre\libpcre\libpcre.vcxproj", "{2615F432-7C7A-4B34-BC9A-D0E58ED8E90F}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pcretest", "pcre\pcretest\pcretest.vcxproj", "{03734708-A8DD-4F61-A1CE-FDCB32079E9A}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libzlib", "zlib\libzlib\libzlib.vcxproj", "{80E019FF-948A-44C1-B422-2D9E540F9FF1}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "zlib\example\example.vcxproj", "{B3B4FE6B-5065-46C4-8664-847F51CC7B7C}"
 EndProject
@@ -35,14 +41,26 @@
 	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bbackupd", "boxbackup\bbackupd\bbackupd.vcxproj", "{1E2BCEE2-BE5B-4366-BAD5-4DD50D494FD7}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "build", "build\build.vcxproj", "{DCDD2786-23D3-44DB-9509-864DC01DB661}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bbackupquery", "boxbackup\bbackupquery\bbackupquery.vcxproj", "{719D334E-6432-4005-9AEB-5763C23BE75B}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bbackupctl", "boxbackup\bbackupctl\bbackupctl.vcxproj", "{682F676C-50F5-45AF-85FA-C23E344583FC}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "setup", "install\setup\setup.wixproj", "{A5D16DCE-9EDA-4DA8-B388-7DC203B6B074}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "custom", "install\custom\custom.vcxproj", "{B43EFCBE-06E0-46C4-9502-1D06B713EB57}"
 	ProjectSection(ProjectDependencies) = postProject
@@ -53,8 +71,14 @@
 	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libeay", "openssl\libeay\libeay.vcxproj", "{FAEDAF88-9894-4F02-B936-B30674DE9192}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libssl", "openssl\libssl\libssl.vcxproj", "{469ACDA3-2237-414C-BABF-D30FFFF2FE6A}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rsa_test", "openssl\rsa_test\rsa_test.vcxproj", "{A67946D1-E644-45E1-931B-DA46177F5263}"
 EndProject
@@ -117,10 +141,16 @@
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "run openssl tests", "openssl\run\run.vcxproj", "{995B6A5A-9A87-4CD1-A785-FE62E63251EE}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bbstored", "boxbackup\bbstored\bbstored.vcxproj", "{2F13350C-C902-47B8-8584-8FA2F6C05917}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bbackupclient", "boxbackup\bbackupclient\bbackupclient.vcxproj", "{DCEF045D-507C-4137-B11A-C76C4B94DFBA}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bbutil", "boxbackup\bbutil\bbutil.vcxproj", "{D84AC0C6-6E7D-44AA-A37A-BBC1A599BAB3}"
+	ProjectSection(ProjectDependencies) = postProject
+		{DCDD2786-23D3-44DB-9509-864DC01DB661} = {DCDD2786-23D3-44DB-9509-864DC01DB661}
+	EndProjectSection
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/Custom.cpp
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/Custom.cpp	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/Custom.cpp	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,61 @@
+#include "stdafx.h"
+
+
+// DllMain - Initialize and cleanup WiX custom action utils.
+extern "C" BOOL WINAPI DllMain(
+	__in HINSTANCE hInst,
+	__in ULONG ulReason,
+	__in LPVOID
+	)
+{
+	switch(ulReason)
+	{
+	case DLL_PROCESS_ATTACH:
+		WcaGlobalInitialize(hInst);
+		break;
+
+	case DLL_PROCESS_DETACH:
+		WcaGlobalFinalize();
+		break;
+	}
+
+	return TRUE;
+}
+
+
+HCRYPTPROV GetCryptContext(void)
+{
+	HCRYPTPROV		hCryptProv		= NULL;
+
+	// Force creation of a new container
+	CryptAcquireContext(&hCryptProv,"BoxBackup",NULL,0,CRYPT_DELETEKEYSET);
+	CryptAcquireContext(&hCryptProv,"BoxBackup",NULL,PROV_RSA_FULL,CRYPT_MACHINE_KEYSET|CRYPT_NEWKEYSET);
+
+	return hCryptProv;
+}
+
+
+char* GetCustomActionData(MSIHANDLE hInstall)
+{
+	DWORD	lenValueBuf = 0;
+	char* valueBuf = NULL;
+	UINT uiStat =  MsiGetProperty(hInstall, "CustomActionData", "", &lenValueBuf);
+	//cchValueBuf now contains the size of the property's string, without null termination
+	if (ERROR_MORE_DATA == uiStat)
+	{
+		++lenValueBuf; // add 1 for null termination
+		valueBuf = new char[lenValueBuf];
+		if (valueBuf)
+		{
+			uiStat = MsiGetProperty(hInstall, "CustomActionData", valueBuf, &lenValueBuf);
+		}
+	}
+	if (ERROR_SUCCESS != uiStat && valueBuf != NULL)
+	{
+		delete[] valueBuf;
+		valueBuf = NULL;
+		SetLastError(uiStat);
+	}
+
+	return valueBuf;
+}

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/Custom.def
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/Custom.def	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/Custom.def	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,6 @@
+LIBRARY "custom"
+
+EXPORTS
+
+GenerateCSR
+GenerateKeyFile

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/FetchServerCert.cpp
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/FetchServerCert.cpp	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/FetchServerCert.cpp	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,20 @@
+#include "stdafx.h"
+
+
+UINT __stdcall FetchServerCert(MSIHANDLE hInstall)
+{
+	HRESULT hr;
+
+	if(FAILED(hr = WcaInitialize(hInstall, "FetchServerCert")))
+	{
+		WcaLogError(hr, "Failed to initialize");
+	}
+	else
+	{
+		char *HostName = GetCustomActionData(hInstall);
+
+
+	}
+
+}
+

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/GenerateCSR.cpp
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/GenerateCSR.cpp	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/GenerateCSR.cpp	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,309 @@
+#include "stdafx.h"
+
+
+static BOOL CheckPrivateKey(HCRYPTPROV hCryptProv)
+{
+	HCRYPTKEY	hKey	= NULL;
+	BOOL			rv		= FALSE;
+
+	WcaLog(LOGMSG_STANDARD, "Checking keys");
+	if (CryptGenKey(hCryptProv,AT_KEYEXCHANGE,0x08000000|CRYPT_EXPORTABLE,&hKey))
+	{
+		rv = CryptDestroyKey(hKey);
+	}
+	WcaLog(LOGMSG_STANDARD, "Checked keys");
+
+	return rv;
+}
+
+
+UINT __stdcall GenerateCSR(MSIHANDLE hInstall)
+{
+	HRESULT hr;
+	UINT er = ERROR_INSTALL_FAILURE;
+	DWORD gle;
+	char	ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
+	DWORD lenComputerName = sizeof(ComputerName);
+
+	if(FAILED(hr = WcaInitialize(hInstall, "GenerateCSR")))
+	{
+		WcaLogError(hr, "Failed to initialize");
+	}
+	else
+	{
+		DWORD gle;
+		HKEY hKey;
+
+		if(ERROR_SUCCESS == (gle = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Box Backup",0,KEY_QUERY_VALUE,&hKey)))
+		{
+			DWORD	data;
+			DWORD cb = sizeof(DWORD);
+
+			gle = RegQueryValueEx(hKey,"GeneratedCsrOk",NULL,NULL,(BYTE*)&data,&cb);
+
+			RegCloseKey(hKey);
+
+			if(ERROR_SUCCESS == gle && data)
+			{
+				return WcaFinalize(ERROR_SUCCESS);
+			}
+		}
+	}
+
+	if(FALSE == GetComputerName(ComputerName,&lenComputerName))
+	{
+		hr = HRESULT_FROM_WIN32(GetLastError());
+		WcaLogError(hr, "Look out the window - I think the world just ended!");
+	}
+	else
+	{
+		DWORD lenInstallLocation = 0,
+				lenAccountNumber = 0,
+				lenEmailAddress = 0;
+		char	*InstallLocation,
+				*AccountNumber,
+				*EmailAddress,
+				*next = NULL;
+
+		InstallLocation = GetCustomActionData(hInstall);
+
+		lenInstallLocation = (DWORD)strlen(InstallLocation = strtok_s(InstallLocation,"\n",&next));
+		lenAccountNumber = (DWORD)strlen(AccountNumber = strtok_s(NULL,"\n",&next));
+		lenEmailAddress = (DWORD)strlen(EmailAddress = strtok_s(NULL,"\n",&next));
+
+
+		if(SUCCEEDED(hr))
+		{
+			HCRYPTPROV hCryptProv;
+
+			WcaLog(LOGMSG_STANDARD, "Initialized.");
+			WcaLog(LOGMSG_STANDARD, InstallLocation);
+			WcaLog(LOGMSG_STANDARD, AccountNumber);
+			WcaLog(LOGMSG_STANDARD, EmailAddress);
+		
+			// Get the crypt context - can't do anything without it
+			if(NULL == (hCryptProv = GetCryptContext()))
+			{
+				hr = HRESULT_FROM_WIN32(GetLastError());
+				WcaLogError(hr, "Failed to aquire crypt context");
+			}
+			// Make sure we've got a key that's valid for signing
+			else if(FALSE == CheckPrivateKey(hCryptProv))
+			{
+				hr = HRESULT_FROM_WIN32(GetLastError());
+				WcaLogError(hr, "Failed to get private key");
+			}
+			else
+			{
+				CERT_RDN_ATTR	rgNameAttr[]	= {   { szOID_ORGANIZATION_NAME,				CERT_RDN_PRINTABLE_STRING, 0, NULL  },
+																{ szOID_COMMON_NAME,						CERT_RDN_PRINTABLE_STRING, 0, NULL  },
+																{ szOID_RSA_emailAddr,					CERT_RDN_IA5_STRING, 		0, NULL  },
+																{ szOID_ORGANIZATIONAL_UNIT_NAME,   CERT_RDN_PRINTABLE_STRING, 0, NULL  }	};
+				CERT_RDN			rgRDN[]			= { 4, rgNameAttr };
+				CERT_NAME_INFO	Name				= { 1, rgRDN };
+				LPSTR				pbCSR				= NULL;
+				char				CommonName[128];
+				DWORD				lenCommonName;
+
+				lenCommonName = sprintf_s(CommonName,"BACKUP-%s",AccountNumber);
+				rgNameAttr[0].Value.cbData	= 3;
+				rgNameAttr[0].Value.pbData	= (BYTE*)"n/a";
+				rgNameAttr[1].Value.cbData	= lenCommonName;
+				rgNameAttr[1].Value.pbData = (BYTE*)CommonName;
+				rgNameAttr[2].Value.cbData	= lenEmailAddress;
+				rgNameAttr[2].Value.pbData = (BYTE*)EmailAddress;
+				rgNameAttr[3].Value.cbData	= lenComputerName;
+				rgNameAttr[3].Value.pbData	= (BYTE*)ComputerName;
+
+				WcaLog(LOGMSG_STANDARD, "Encoding CSR");
+
+				DWORD	cbNameEncoded = 0;
+
+				if(FALSE == CryptEncodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, X509_NAME, &Name, NULL, &cbNameEncoded))
+				{
+					hr = HRESULT_FROM_WIN32(GetLastError());
+					WcaLogError(hr, "Failed to get buffer size to encode object");
+				}
+				else
+				{
+					BYTE *pbNameEncoded = new BYTE[cbNameEncoded];
+
+					if(FALSE == CryptEncodeObject(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, X509_NAME, &Name, pbNameEncoded, &cbNameEncoded))
+					{
+						hr = HRESULT_FROM_WIN32(GetLastError());
+						WcaLogError(hr, "Failed to encode object");
+					}
+					else
+					{
+						DWORD cbPublicKeyInfo = 0;
+
+						WcaLog(LOGMSG_STANDARD, "Exporting public key");
+
+						if(FALSE == CryptExportPublicKeyInfo(hCryptProv, AT_KEYEXCHANGE, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, NULL, &cbPublicKeyInfo))
+						{
+							hr = HRESULT_FROM_WIN32(GetLastError());
+							WcaLogError(hr, "Failed to get buffer length for public key");
+						}
+						else
+						{
+							char	*PublicKeyBuffer	= new char[cbPublicKeyInfo];
+							CERT_PUBLIC_KEY_INFO*	pbPublicKeyInfo	= (CERT_PUBLIC_KEY_INFO*) PublicKeyBuffer;
+
+							if(FALSE == CryptExportPublicKeyInfo(hCryptProv, AT_KEYEXCHANGE, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, pbPublicKeyInfo, &cbPublicKeyInfo))
+							{
+								hr = HRESULT_FROM_WIN32(GetLastError());
+								WcaLogError(hr, "Failed to export public key");
+							}
+							else
+							{
+								CRYPT_ALGORITHM_IDENTIFIER			SigAlg;
+								SigAlg.pszObjId						= szOID_RSA_SHA1RSA;
+								SigAlg.Parameters.cbData			= 0;
+
+								CERT_REQUEST_INFO						CertReqInfo;
+								CertReqInfo.dwVersion				= CERT_REQUEST_V1;
+								CertReqInfo.Subject.cbData			= cbNameEncoded;
+								CertReqInfo.Subject.pbData			= pbNameEncoded;
+								CertReqInfo.SubjectPublicKeyInfo	= *pbPublicKeyInfo;
+								CertReqInfo.cAttribute				= 0;
+								CertReqInfo.rgAttribute				= NULL;
+
+
+								DWORD cbSignedEncodedCertReqSize = 0;
+
+								WcaLog(LOGMSG_STANDARD, "Signing certificate");
+
+								if(FALSE == CryptSignAndEncodeCertificate(
+									hCryptProv,
+									AT_KEYEXCHANGE,
+									X509_ASN_ENCODING,
+									X509_CERT_REQUEST_TO_BE_SIGNED,
+									&CertReqInfo,
+									&SigAlg,
+									NULL,
+									NULL,
+									&cbSignedEncodedCertReqSize))
+								{
+									hr = HRESULT_FROM_WIN32(GetLastError());
+									WcaLogError(hr, "Failed to get buffer size for csr");
+								}
+								else
+								{
+									BYTE* pbSignedEncodedCertReq = new BYTE[cbSignedEncodedCertReqSize];
+
+									if(FALSE == CryptSignAndEncodeCertificate(
+										hCryptProv,
+										AT_KEYEXCHANGE,
+										X509_ASN_ENCODING,
+										X509_CERT_REQUEST_TO_BE_SIGNED,
+										&CertReqInfo,
+										&SigAlg,
+										NULL,
+										pbSignedEncodedCertReq,
+										&cbSignedEncodedCertReqSize))
+									{
+										hr = HRESULT_FROM_WIN32(hr);
+										WcaLogError(hr, "Failed to sign and encode certificate");
+									}
+									else
+									{
+										DWORD cbCSR = 0;
+
+										WcaLog(LOGMSG_STANDARD, "Binary to string");
+
+										if(FALSE == CryptBinaryToString(pbSignedEncodedCertReq, cbSignedEncodedCertReqSize, CRYPT_STRING_BASE64REQUESTHEADER, NULL, &cbCSR))
+										{
+											hr = HRESULT_FROM_WIN32(GetLastError());
+											WcaLogError(hr, "Failed to get buffer size for csr string");
+										}
+										else
+										{
+											char *pbCSR = new char[cbCSR];
+
+											if(FALSE == CryptBinaryToString(pbSignedEncodedCertReq, cbSignedEncodedCertReqSize, CRYPT_STRING_BASE64REQUESTHEADER, pbCSR, &cbCSR))
+											{
+												hr = HRESULT_FROM_WIN32(GetLastError());
+												WcaLogError(hr, "Failed to get csr as string");
+											}
+											else
+											{
+												HANDLE hFile;
+												char filename[MAX_PATH+1];
+
+												// Woo! We've got everything
+
+												sprintf_s(filename,sizeof(filename),"%s%s-csr.pem",InstallLocation,AccountNumber);
+												if(INVALID_HANDLE_VALUE == (hFile = CreateFile(filename,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL))
+													&& ERROR_FILE_EXISTS != (gle = GetLastError()))
+												{
+													hr = HRESULT_FROM_WIN32(gle);
+													WcaLogError(hr, "Can't create CSR file");
+												}
+												else
+												{
+													DWORD nWritten;
+
+													if (FALSE == WriteFile(hFile,pbCSR,cbCSR,&nWritten,NULL)
+														|| cbCSR != nWritten)
+													{
+														hr = HRESULT_FROM_WIN32(GetLastError());
+														WcaLogError(hr, "Failed to write CSR");
+													}
+													else
+													{
+														DWORD gle;
+														HKEY hKey;
+
+														if(ERROR_SUCCESS != (gle = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Box Backup",0,KEY_SET_VALUE,&hKey)))
+														{
+															hr = HRESULT_FROM_WIN32(gle);
+															WcaLogError(hr, "Failed to open registry key");
+														}
+														else
+														{
+															DWORD data = 1;
+
+															if(ERROR_SUCCESS != (gle = RegSetValueEx(hKey,"GeneratedCsrOk",0,REG_DWORD,(BYTE*)&data,sizeof(DWORD))))
+															{
+																hr = HRESULT_FROM_WIN32(gle);
+																WcaLogError(hr, "Failed to set registry value");
+															}
+
+															RegCloseKey(hKey);
+														}
+													}
+
+													CloseHandle(hFile);
+												}
+
+
+												if(SUCCEEDED(hr))
+												{
+													er = ERROR_SUCCESS;
+												}
+											}
+
+											delete[] pbCSR;
+										}
+									}
+
+									delete[] pbSignedEncodedCertReq;
+								}
+							}
+
+							delete[] PublicKeyBuffer;
+						}
+					}
+
+					delete[] pbNameEncoded;
+				}
+			}
+
+			CryptReleaseContext(hCryptProv,0);
+		}
+
+		delete[] InstallLocation;
+	}
+
+	return WcaFinalize(er);
+}

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/GenerateKeyFile.cpp
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/GenerateKeyFile.cpp	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/GenerateKeyFile.cpp	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,67 @@
+#include "stdafx.h"
+
+
+UINT __stdcall GenerateKeyFile(MSIHANDLE hInstall)
+{
+	HRESULT hr;
+
+	if(FAILED(hr = WcaInitialize(hInstall, "GenerateKeyFile")))
+	{
+		WcaLogError(hr, "Failed to initialize");
+	}
+	else
+	{
+		DWORD err;
+		HKEY hKey;
+
+		if(ERROR_SUCCESS != (err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Box Backup", 0, KEY_QUERY_VALUE|KEY_SET_VALUE, &hKey)))
+		{
+			hr = HRESULT_FROM_WIN32(err);
+			WcaLogError(hr, "Failed to open registry key");
+		}
+		else
+		{
+			// Make sure we don't stomp on an existing key
+			if(ERROR_SUCCESS == (err = RegQueryValueEx(hKey, "FileEncKeys", NULL, NULL, NULL, NULL)))
+			{
+				hr = HRESULT_FROM_WIN32(err);
+			}
+			else
+			{
+				HCRYPTPROV hCryptProv;
+
+				if(!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
+				{
+					hr = HRESULT_FROM_WIN32(GetLastError());
+					WcaLogError(hr, "Failed to aquire crypt context");
+				}
+				else
+				{
+					BYTE RandomData[BACKUPCRYPTOKEYS_FILE_SIZE];
+
+					if(!CryptGenRandom(hCryptProv, BACKUPCRYPTOKEYS_FILE_SIZE, RandomData))
+					{
+						hr = HRESULT_FROM_WIN32(GetLastError());
+						WcaLogError(hr, "Can't get random data");
+					}
+					else
+					{
+						if(ERROR_SUCCESS != (err = RegSetValueEx(hKey, "FileEncKeys", 0, REG_BINARY, RandomData, BACKUPCRYPTOKEYS_FILE_SIZE)))
+						{
+							hr = HRESULT_FROM_WIN32(err);
+							WcaLogError(hr, "Failed to set registry value");
+						}
+
+						SecureZeroMemory(RandomData, BACKUPCRYPTOKEYS_FILE_SIZE);
+					}
+
+					CryptReleaseContext(hCryptProv, 0);
+				}
+			}
+
+			RegCloseKey(hKey);
+		}
+	}
+
+	return WcaFinalize( (SUCCEEDED(hr)) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE );
+}

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/resource.h
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/resource.h	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/resource.h	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,14 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by custom.rc
+
+// Next default values for new objects
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE        101
+#define _APS_NEXT_COMMAND_VALUE         40001
+#define _APS_NEXT_CONTROL_VALUE         1001
+#define _APS_NEXT_SYMED_VALUE           101
+#endif
+#endif

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/stdafx.cpp
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/stdafx.cpp	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/stdafx.cpp	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,8 @@
+// stdafx.cpp : source file that includes just the standard includes
+// custom.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/stdafx.h
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/stdafx.h	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/stdafx.h	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,28 @@
+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+#include "targetver.h"
+
+#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
+// Windows Header Files:
+#include <windows.h>
+#include <strsafe.h>
+#include <msiquery.h>
+
+// WiX Header Files:
+#include <wcautil.h>
+
+
+// TODO: reference additional headers your program requires here
+#include <string>
+
+
+#include "BackupClientCryptoKeys.h"
+
+
+extern HCRYPTPROV GetCryptContext(void);
+extern char* GetCustomActionData(MSIHANDLE hInstall);

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/targetver.h
===================================================================
--- box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/targetver.h	                        (rev 0)
+++ box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/custom/targetver.h	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,24 @@
+#pragma once
+
+// The following macros define the minimum required platform.  The minimum required platform
+// is the earliest version of Windows, Internet Explorer etc. that has the necessary features to run 
+// your application.  The macros work by enabling all features available on platform versions up to and 
+// including the version specified.
+
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef WINVER                  // Specifies that the minimum required platform is Windows XP/2003.
+#define WINVER 0x0600           // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows XP/2003.
+#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_IE               // Specifies that the minimum required platform is Internet Explorer 5.0.
+#define _WIN32_IE 0x0500        // Change this to the appropriate value to target other versions of IE.
+#endif
+
+#ifndef _WIN32_MSI              // Specifies that the minimum required MSI version is MSI 3.1
+#define _WIN32_MSI 310          // Change this to the appropriate value to target other versions of MSI.
+#endif

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/setup/bblogo.bmp
===================================================================
(Binary files differ)


Property changes on: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/setup/bblogo.bmp
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/setup/bbsplash.bmp
===================================================================
(Binary files differ)


Property changes on: box/invisnet/vs2010/0.11/infrastructure/msvc/2010/install/setup/bbsplash.bmp
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: box/invisnet/vs2010/0.11/lib/win32/_sys/socket.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/win32/_sys/socket.h	                        (rev 0)
+++ box/invisnet/vs2010/0.11/lib/win32/_sys/socket.h	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,12 @@
+#ifndef EMU_SYS_SOCKET_H
+#	define EMU_SYS_SOCKET_H
+
+#	ifdef WIN32
+#		pragma once
+
+#		define SHUT_RDWR SD_BOTH
+#		define SHUT_RD SD_RECEIVE
+#		define SHUT_WR SD_SEND
+#	endif
+
+#endif

Added: box/invisnet/vs2010/0.11/lib/win32/_sys/syslog.cpp
===================================================================
--- box/invisnet/vs2010/0.11/lib/win32/_sys/syslog.cpp	                        (rev 0)
+++ box/invisnet/vs2010/0.11/lib/win32/_sys/syslog.cpp	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,268 @@
+#include "Box.h"
+
+#include "messages.h"
+
+
+using namespace Win32;
+
+
+// copied from MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/eventlog/base/adding_a_source_to_the_registry.asp
+
+BOOL AddEventSource
+(
+	const char* pszSrcName, // event source name
+	DWORD  dwNum       // number of categories
+)
+{
+	// Work out the executable file name, to register ourselves
+	// as the event source
+
+	WCHAR cmd[MAX_PATH];
+	DWORD len = GetModuleFileNameW(NULL, cmd, MAX_PATH);
+
+	if (len == 0)
+	{
+		::syslog(LOG_ERR, "Failed to get the program file name: %s",
+			GetErrorMessage(GetLastError()).c_str());
+		return FALSE;
+	}
+
+	// Create the event source as a subkey of the log. 
+
+	std::string regkey("SYSTEM\\CurrentControlSet\\Services\\EventLog\\"
+		"Box Backup\\");
+	regkey += pszSrcName; 
+ 
+	HKEY hk;
+	DWORD dwDisp;
+
+	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, regkey.c_str(), 
+			 0, NULL, REG_OPTION_NON_VOLATILE,
+			 KEY_WRITE, NULL, &hk, &dwDisp)) 
+	{
+		::syslog(LOG_ERR, "Failed to create the registry key: %s",
+			GetErrorMessage(GetLastError()).c_str());
+		return FALSE;
+	}
+
+	// Set the name of the message file. 
+ 
+	if (RegSetValueExW(hk,                 // subkey handle 
+			   L"EventMessageFile", // value name 
+			   0,                  // must be zero 
+			   REG_EXPAND_SZ,      // value type 
+			   (LPBYTE)cmd,        // pointer to value data 
+			   len*sizeof(WCHAR))) // data size
+	{
+		::syslog(LOG_ERR, "Failed to set the event message file: %s",
+			GetErrorMessage(GetLastError()).c_str());
+		RegCloseKey(hk); 
+		return FALSE;
+	}
+ 
+	// Set the supported event types. 
+ 
+	DWORD dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | 
+		  EVENTLOG_INFORMATION_TYPE; 
+ 
+	if (RegSetValueEx(hk,               // subkey handle 
+			  "TypesSupported", // value name 
+			  0,                // must be zero 
+			  REG_DWORD,        // value type 
+			  (LPBYTE) &dwData, // pointer to value data 
+			  sizeof(DWORD)))   // length of value data 
+	{
+		::syslog(LOG_ERR, "Failed to set the supported types: %s",
+			GetErrorMessage(GetLastError()).c_str());
+		RegCloseKey(hk); 
+		return FALSE;
+	}
+ 
+	// Set the category message file and number of categories.
+
+	if (RegSetValueExW(hk,                    // subkey handle 
+			   L"CategoryMessageFile", // value name 
+			   0,                     // must be zero 
+			   REG_EXPAND_SZ,         // value type 
+			   (LPBYTE)cmd,           // pointer to value data 
+			   len*sizeof(WCHAR)))    // data size
+	{
+		::syslog(LOG_ERR, "Failed to set the category message file: "
+			"%s", GetErrorMessage(GetLastError()).c_str());
+		RegCloseKey(hk); 
+		return FALSE;
+	}
+ 
+	if (RegSetValueEx(hk,              // subkey handle 
+			  "CategoryCount", // value name 
+			  0,               // must be zero 
+			  REG_DWORD,       // value type 
+			  (LPBYTE) &dwNum, // pointer to value data 
+			  sizeof(DWORD)))  // length of value data 
+	{
+		::syslog(LOG_ERR, "Failed to set the category count: %s",
+			GetErrorMessage(GetLastError()).c_str());
+		RegCloseKey(hk); 
+		return FALSE;
+	}
+
+	RegCloseKey(hk); 
+	return TRUE;
+}
+
+
+static HANDLE gSyslogH = 0;
+static bool sHaveWarnedEventLogFull = false;
+
+void openlog(const char * daemonName, int, int)
+{
+	// register a default event source, so that we can
+	// log errors with the process of adding or registering our own.
+	gSyslogH = RegisterEventSource(
+		NULL,        // uses local computer
+		daemonName); // source name
+	if (gSyslogH == NULL)
+	{
+	}
+
+	BOOL success = AddEventSource(daemonName, 0);
+
+	if (!success)
+	{
+		::syslog(LOG_ERR, "Failed to add our own event source");
+		return;
+	}
+
+	HANDLE newSyslogH = RegisterEventSource(NULL, daemonName);
+	if (newSyslogH == NULL)
+	{
+		::syslog(LOG_ERR, "Failed to register our own event source: "
+			"%s", GetErrorMessage(GetLastError()).c_str());
+		return;
+	}
+
+	DeregisterEventSource(gSyslogH);
+	gSyslogH = newSyslogH;
+}
+
+void closelog(void)
+{
+	DeregisterEventSource(gSyslogH);
+}
+
+void syslog(int loglevel, const char *frmt, ...)
+{
+	WORD errinfo;
+	char buffer[1024];
+	std::string sixfour(frmt);
+
+	switch (loglevel)
+	{
+	case LOG_INFO:
+		errinfo = EVENTLOG_INFORMATION_TYPE;
+		break;
+	case LOG_ERR:
+		errinfo = EVENTLOG_ERROR_TYPE;
+		break;
+	case LOG_WARNING:
+	default:
+		errinfo = EVENTLOG_WARNING_TYPE;
+		break;
+	}
+
+	// taken from MSDN
+	int sixfourpos;
+	while ( (sixfourpos = (int)sixfour.find("%ll")) != -1 )
+	{
+		// maintain portability - change the 64 bit formater...
+		std::string temp = sixfour.substr(0,sixfourpos);
+		temp += "%I64";
+		temp += sixfour.substr(sixfourpos+3, sixfour.length());
+		sixfour = temp;
+	}
+
+	// printf("parsed string is:%s\r\n", sixfour.c_str());
+
+	va_list args;
+	va_start(args, frmt);
+
+	int len = vsnprintf(buffer, sizeof(buffer)-1, sixfour.c_str(), args);
+	if (len < 0)
+	{
+		printf("%s\r\n", buffer);
+		fflush(stdout);
+		return;
+	}
+
+	buffer[sizeof(buffer)-1] = 0;
+
+	va_end(args);
+
+	if (gSyslogH == 0)
+	{
+		printf("%s\r\n", buffer);
+		fflush(stdout);
+		return;
+	}
+
+	std::wstring wide = multi2wide(buffer);
+
+	DWORD result;
+
+/*	if (wide == NULL)
+	{
+		std::string buffer2 = buffer;
+		buffer2 += " (failed to convert string encoding)";
+		LPCSTR strings[] = { buffer2.c_str(), NULL };
+
+		result = ReportEventA(gSyslogH, // event log handle
+			errinfo,               // event type
+			0,                     // category zero
+			MSG_ERR,	       // event identifier -
+					       // we will call them all the same
+			NULL,                  // no user security identifier
+			1,                     // one substitution string
+			0,                     // no data
+			strings,               // pointer to string array
+			NULL);                 // pointer to data
+	}
+	else*/
+	{
+		LPCWSTR strings[] = { wide.c_str(), NULL };
+		result = ReportEventW(gSyslogH, // event log handle
+			errinfo,               // event type
+			0,                     // category zero
+			MSG_ERR,	       // event identifier -
+					       // we will call them all the same
+			NULL,                  // no user security identifier
+			1,                     // one substitution string
+			0,                     // no data
+			strings,               // pointer to string array
+			NULL);                 // pointer to data
+	}
+
+	if (result == 0)
+	{
+		DWORD err = GetLastError();
+		if (err == ERROR_LOG_FILE_FULL)
+		{
+			if (!sHaveWarnedEventLogFull)
+			{
+				printf("Unable to send message to Event Log "
+					"(Event Log is full):\r\n");
+				fflush(stdout);
+				sHaveWarnedEventLogFull = TRUE;
+			}
+		}
+		else
+		{
+			printf("Unable to send message to Event Log: %s:\r\n",
+				GetErrorMessage(err).c_str());
+			fflush(stdout);
+		}
+	}
+	else
+	{
+		sHaveWarnedEventLogFull = false;
+	}
+}

Added: box/invisnet/vs2010/0.11/lib/win32/_sys/syslog.h
===================================================================
--- box/invisnet/vs2010/0.11/lib/win32/_sys/syslog.h	                        (rev 0)
+++ box/invisnet/vs2010/0.11/lib/win32/_sys/syslog.h	2012-01-19 19:00:04 UTC (rev 3057)
@@ -0,0 +1,28 @@
+#ifndef EMU_SYS_SYSLOG_H
+#	define EMU_SYS_SYSLOG_H
+
+#	ifdef WIN32
+#		pragma once
+
+#		define LOG_DEBUG LOG_INFO
+#		define LOG_INFO 6
+#		define LOG_NOTICE LOG_INFO
+#		define LOG_WARNING 4
+#		define LOG_ERR 3
+#		define LOG_CRIT LOG_ERR
+#		define LOG_PID 0
+#		define LOG_LOCAL0 0
+#		define LOG_LOCAL1 0
+#		define LOG_LOCAL2 0
+#		define LOG_LOCAL3 0
+#		define LOG_LOCAL4 0
+#		define LOG_LOCAL5 0
+#		define LOG_LOCAL6 0
+#		define LOG_DAEMON 0
+
+		extern void openlog (const char * daemonName, int, int) throw();
+		extern void closelog(void) throw();
+		extern void syslog  (int loglevel, const char *fmt, ...) throw();
+#	endif
+
+#endif




More information about the Boxbackup-commit mailing list