diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2012-12-28 14:27:17 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2012-12-28 14:27:17 +0000 |
commit | f1000598cfdd80dc4dc0eb9bb1a0e3e142137856 (patch) | |
tree | 807d47b213577381d36dd0bc608a4ab7b9c9426c /protocols/Skype/src/skype_subclassing.cpp | |
parent | 564aadb3ff4757c2d5af86dc00f606e96b2c7ae4 (diff) |
- code refactoring
- added account registration
- temporary disabled chatrooms
git-svn-id: http://svn.miranda-ng.org/main/trunk@2869 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Skype/src/skype_subclassing.cpp')
-rw-r--r-- | protocols/Skype/src/skype_subclassing.cpp | 258 |
1 files changed, 258 insertions, 0 deletions
diff --git a/protocols/Skype/src/skype_subclassing.cpp b/protocols/Skype/src/skype_subclassing.cpp index 6289bc1f98..32a8c95b2c 100644 --- a/protocols/Skype/src/skype_subclassing.cpp +++ b/protocols/Skype/src/skype_subclassing.cpp @@ -1,5 +1,16 @@ #include "skype_subclassing.h"
+#include <win2k.h>
+#include <ShellAPI.h>
+#include <shlwapi.h>
+#include <tlhelp32.h>
+#include "base64/base64.h"
+#include "..\..\..\skypekit\key.h"
+extern "C"
+{
+#include "aes\aes.h"
+}
+
// CSkype
CSkype::CSkype(int num_threads) : Skype(num_threads)
@@ -63,6 +74,217 @@ void CSkype::SetOnMessageCallback(OnMessaged callback, CSkypeProto* proto) this->onMessagedCallback = callback;
}
+BOOL CSkype::IsRunAsAdmin()
+{
+ BOOL fIsRunAsAdmin = FALSE;
+ DWORD dwError = ERROR_SUCCESS;
+ PSID pAdministratorsGroup = NULL;
+
+ // Allocate and initialize a SID of the administrators group.
+ SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
+ if ( !AllocateAndInitializeSid(
+ &NtAuthority,
+ 2,
+ SECURITY_BUILTIN_DOMAIN_RID,
+ DOMAIN_ALIAS_RID_ADMINS,
+ 0, 0, 0, 0, 0, 0,
+ &pAdministratorsGroup))
+ {
+ dwError = GetLastError();
+ goto Cleanup;
+ }
+
+ // Determine whether the SID of administrators group is enabled in
+ // the primary access token of the process.
+ if ( !CheckTokenMembership(NULL, pAdministratorsGroup, &fIsRunAsAdmin))
+ {
+ dwError = GetLastError();
+ goto Cleanup;
+ }
+
+Cleanup:
+ // Centralized cleanup for all allocated resources.
+ if (pAdministratorsGroup)
+ {
+ FreeSid(pAdministratorsGroup);
+ pAdministratorsGroup = NULL;
+ }
+
+ // Throw the error if something failed in the function.
+ if (ERROR_SUCCESS != dwError)
+ {
+ throw dwError;
+ }
+
+ return fIsRunAsAdmin;
+}
+
+char *CSkype::LoadKeyPair(HINSTANCE hInstance)
+{
+ HRSRC hRes = FindResource(hInstance, MAKEINTRESOURCE(/*IDR_KEY*/107), L"BIN");
+ if (hRes)
+ {
+ HGLOBAL hResource = LoadResource(hInstance, hRes);
+ if (hResource)
+ {
+ aes_context ctx;
+ unsigned char key[128];
+
+ int basedecoded = Base64::Decode(MY_KEY, (char *)key, MAX_PATH);
+ ::aes_set_key(&ctx, key, 128);
+
+ int dwResSize = ::SizeofResource(hInstance, hRes);
+ char *pData = (char *)::GlobalLock(hResource);
+ basedecoded = dwResSize;
+ ::GlobalUnlock(hResource);
+
+ unsigned char *bufD = (unsigned char*)::malloc(basedecoded + 1);
+ unsigned char *tmpD = (unsigned char*)::malloc(basedecoded + 1);
+ basedecoded = Base64::Decode(pData, (char *)tmpD, basedecoded);
+
+ for (int i = 0; i < basedecoded; i += 16)
+ aes_decrypt(&ctx, tmpD+i, bufD+i);
+
+ ::free(tmpD);
+ bufD[basedecoded] = 0; //cert should be null terminated
+ return (char *)bufD;
+ }
+ return NULL;
+ }
+ return NULL;
+}
+
+int CSkype::StartSkypeRuntime(HINSTANCE hInstance, const wchar_t *profileName, int &port, const wchar_t *dbPath)
+{
+ STARTUPINFO cif;
+ PROCESS_INFORMATION pi;
+ wchar_t param[128];
+
+ ::ZeroMemory(&cif, sizeof(STARTUPINFO));
+ cif.cb = sizeof(STARTUPINFO);
+ cif.dwFlags = STARTF_USESHOWWINDOW;
+ cif.wShowWindow = SW_HIDE;
+
+ //HRSRC hRes;
+ //HGLOBAL hResource;
+ wchar_t fileName[MAX_PATH];
+
+ HRSRC hRes = ::FindResource(hInstance, MAKEINTRESOURCE(/*IDR_RUNTIME*/102), L"BIN");
+ if (hRes)
+ {
+ HGLOBAL hResource = ::LoadResource(hInstance, hRes);
+ if (hResource)
+ {
+ HANDLE hFile;
+ char *pData = (char *)LockResource(hResource);
+ DWORD dwSize = SizeofResource(hInstance, hRes), written = 0;
+ ::GetModuleFileName(hInstance, fileName, MAX_PATH);
+
+ wchar_t *skypeKitPath = ::wcsrchr(fileName, '\\');
+ if (skypeKitPath != NULL)
+ *skypeKitPath = 0;
+ ::swprintf(fileName, SIZEOF(fileName), L"%s\\%s", fileName, L"SkypeKit.exe");
+ if ( !::PathFileExists(fileName))
+ {
+ if ((hFile = ::CreateFile(
+ fileName,
+ GENERIC_WRITE,
+ 0,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ 0)) != INVALID_HANDLE_VALUE)
+ {
+ ::WriteFile(hFile, (void *)pData, dwSize, &written, NULL);
+ ::CloseHandle(hFile);
+ }
+ else
+ {
+ // Check the current process's "run as administrator" status.
+ // Elevate the process if it is not run as administrator.
+ if (!CSkype::IsRunAsAdmin())
+ {
+ wchar_t path[MAX_PATH], cmdLine[100];
+ ::GetModuleFileName(NULL, path, ARRAYSIZE(path));
+ ::swprintf(
+ cmdLine,
+ SIZEOF(cmdLine),
+ L" /restart:%d /profile=%s",
+ ::GetCurrentProcessId(),
+ profileName);
+
+ // Launch itself as administrator.
+ SHELLEXECUTEINFO sei = { sizeof(sei) };
+ sei.lpVerb = L"runas";
+ sei.lpFile = path;
+ sei.lpParameters = cmdLine;
+ //sei.hwnd = hDlg;
+ sei.nShow = SW_NORMAL;
+
+ if ( !::ShellExecuteEx(&sei))
+ {
+ DWORD dwError = ::GetLastError();
+ if (dwError == ERROR_CANCELLED)
+ {
+ // The user refused to allow privileges elevation.
+ // Do nothing ...
+ }
+ }
+ //else
+ //{
+ // //DestroyWindow(hDlg); // Quit itself
+ // ::CallService("CloseAction", 0, 0);
+ //}
+ }
+ return 0;
+ }
+ }
+ }
+ }
+
+ PROCESSENTRY32 entry;
+ entry.dwSize = sizeof(PROCESSENTRY32);
+
+ HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
+ if (::Process32First(snapshot, &entry) == TRUE) {
+ while (::Process32Next(snapshot, &entry) == TRUE) {
+ if (::wcsicmp(entry.szExeFile, L"SkypeKit.exe") == 0) {
+ HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
+ port += rand() % 1000;
+ ::CloseHandle(hProcess);
+ break;
+ }
+ }
+ }
+ ::CloseHandle(snapshot);
+
+ ::swprintf(param, SIZEOF(param), L"-p -P %d -f %s", port, dbPath);
+ int startingrt = ::CreateProcess(
+ fileName, param,
+ NULL, NULL, FALSE,
+ CREATE_NEW_CONSOLE,
+ NULL, NULL, &cif, &pi);
+
+ return startingrt;
+}
+
+CSkype *CSkype::GetInstance(HINSTANCE hInstance, const wchar_t *profileName, const wchar_t *dbPath)
+{
+ int port = 8963;
+ if (!CSkype::StartSkypeRuntime(hInstance, profileName, port, dbPath)) return NULL;
+
+ char *keyPair = CSkype::LoadKeyPair(hInstance);
+
+ CSkype *skype = new CSkype();
+ skype->init(keyPair, "127.0.0.1", port);
+ skype->start();
+
+ free(keyPair);
+
+ //this->skype->SetOnMessageCallback((CSkype::OnMessaged)&CSkypeProto::OnMessage, this);
+ return skype;
+}
+
// CAccount
CAccount::CAccount(unsigned int oid, SERootObject* root) : Account(oid, root)
@@ -161,6 +383,36 @@ void CContactSearch::SetOnContactFindedCallback(OnContactFinded callback) CParticipant::CParticipant(unsigned int oid, SERootObject* root) : Participant(oid, root) { }
+SEString CParticipant::GetRankName(CParticipant::RANK rank)
+{
+ char *result = NULL;
+ switch (rank)
+ {
+ case CParticipant::CREATOR:
+ result = "Creator";
+ break;
+ case CParticipant::ADMIN:
+ result = "Admin";
+ break;
+ case CParticipant::SPEAKER:
+ result = "Speaker";
+ break;
+ case CParticipant::WRITER:
+ result = "Writer";
+ break;
+ case CParticipant::SPECTATOR:
+ result = "Spectator";
+ break;
+ case CParticipant::RETIRED:
+ result = "Retried";
+ break;
+ case CParticipant::OUTLAW:
+ result = "Outlaw";
+ break;
+ }
+ return result;
+}
+
// CContact
CContact::CContact(unsigned int oid, SERootObject* root) : Contact(oid, root)
@@ -175,6 +427,12 @@ void CContact::SetOnContactChangedCallback(OnContactChanged callback, CSkypeProt this->callback = callback;
}
+//bool CContact::SentAuthRequest(SEString message)
+//{
+// this->SetBuddyStatus(Contact::AUTHORIZED_BY_ME);
+// this->SendAuthRequest(message);
+//}
+
void CContact::OnChange(int prop)
{
if (this->proto)
|