From 418736c65c97cdc6ca4910e1e8650e474cb12849 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Fri, 8 Feb 2013 23:57:56 +0200 Subject: merged with miranda_ng main repo "boosted" process management evnt_to_db/history>actual_sending logic to avoid srmm problem --- src/gpg_wrapper.cpp | 225 +++++++++++--------------- src/gpg_wrapper.h | 30 ++-- src/init.cpp | 4 +- src/main.cpp | 442 +++++++++++++++++----------------------------------- src/main.h | 2 +- src/messages.cpp | 391 ++++++++++++++++++++++++++-------------------- src/options.cpp | 107 ++++--------- src/utilities.cpp | 402 ++++++++++++++++++----------------------------- src/utilities.h | 1 + 9 files changed, 671 insertions(+), 933 deletions(-) (limited to 'src') diff --git a/src/gpg_wrapper.cpp b/src/gpg_wrapper.cpp index adce958..5f9df7d 100755 --- a/src/gpg_wrapper.cpp +++ b/src/gpg_wrapper.cpp @@ -15,186 +15,148 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" - //thx gpg module from Harald Treder, Zakhar V. Bardymov -//boost::mutex gpg_mutex; - -pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess, PROCESS_INFORMATION *pr) +pxResult pxExecute(std::vector &aargv, string *aoutput, LPDWORD aexitcode, pxResult *result, boost::process::child *_child) { -// gpg_mutex.lock(); if(!gpg_valid) return pxNotConfigured; extern logtofile debuglog; - BOOL success; - STARTUPINFO sinfo = {0}; - SECURITY_ATTRIBUTES sattrs = {0}; - SECURITY_DESCRIPTOR sdesc = {0}; - PROCESS_INFORMATION pri = {0}; - HANDLE newstdin, newstdout, readstdout, writestdin; - char *inputpos; - unsigned long transfered; - int size; - - wstring commandline; - - sattrs.nLength=sizeof(SECURITY_ATTRIBUTES); - sattrs.bInheritHandle=TRUE; - InitializeSecurityDescriptor(&sdesc,SECURITY_DESCRIPTOR_REVISION); - SetSecurityDescriptorDacl(&sdesc,TRUE,NULL,FALSE); - sattrs.lpSecurityDescriptor=&sdesc; - - success=CreatePipe(&newstdin,&writestdin,&sattrs,0); - if (!success) - { - *result = pxCreatePipeFailed; - return pxCreatePipeFailed; - } - - success=CreatePipe(&readstdout,&newstdout,&sattrs,0); - if (!success) - { - CloseHandle(newstdin); - CloseHandle(writestdin); - *result = pxCreatePipeFailed; - return pxCreatePipeFailed; - } - - GetStartupInfo(&sinfo); - sinfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; - sinfo.wShowWindow=SW_HIDE; - sinfo.hStdOutput=newstdout; - sinfo.hStdError=newstdout; - sinfo.hStdInput=newstdin; - - char *mir_path = new char [MAX_PATH]; - CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); - SetCurrentDirectoryA(mir_path); - delete [] mir_path; + TCHAR *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); { - if(_waccess(bin_path, 0) == -1) + if(!boost::filesystem::exists(bin_path)) { - if(errno == ENOENT) - { - mir_free(bin_path); - if(bDebugLog) - debuglog< argv; + std::vector env; + env.push_back(L"LANGUAGE=en@quot"); + env.push_back(L"LC_ALL=English"); + argv.push_back(bin_path); + argv.push_back(L"--homedir"); + TCHAR *home_dir = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); + argv.push_back(home_dir); + mir_free(home_dir); + argv.push_back(L"--display-charset"); + argv.push_back(L"utf-8"); + argv.push_back(L"-z9"); + argv.insert(argv.end(), aargv.begin(), aargv.end()); + + if(bDebugLog) { - CloseHandle(newstdin); - CloseHandle(writestdin); - CloseHandle(newstdout); - CloseHandle(readstdout); - if(bDebugLog) - debuglog< is(source); + try{ + std::string s; + while(std::getline(is, s)) + { + aoutput->append(s); + aoutput->append("\n"); + } + } + catch(const std::exception &e) + { + if(bDebugLog) + debuglog<cmd, params->useless, params->out, params->code, params->result, params->hProcess, params->proc); + bool ret = true; + boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, params)); + if(!gpg_thread->timed_join(t)) + { + ret = false; + delete gpg_thread; + if(params.child) + boost::process::terminate(*(params.child)); + if(bDebugLog) + debuglog< &aargv, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess, PROCESS_INFORMATION *pr, string &old_pass, string &new_pass) +pxResult pxExecute_passwd_change(std::vector &aargv, string *aoutput, LPDWORD aexitcode, pxResult *result, boost::process::child *_child, string &old_pass, string &new_pass) { -// gpg_mutex.lock(); if(!gpg_valid) return pxNotConfigured; extern logtofile debuglog; TCHAR *bin_path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T("")); { - if(_waccess(bin_path, 0) == -1) + if(!boost::filesystem::exists(bin_path)) { - if(errno == ENOENT) - { - mir_free(bin_path); - if(bDebugLog) - debuglog< &aargv, char *ainput, argv.insert(argv.end(), aargv.begin(), aargv.end()); // pipe pout = create_pipe(); - pipe pin = create_pipe(); +// pipe pin = create_pipe(); // file_descriptor_sink sout(pout.sink, close_handle); - file_descriptor_source sin(pin.source, close_handle); +// file_descriptor_source sin(pin.source, close_handle); char *mir_path = new char [MAX_PATH]; CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); //execute(set_args(argv), bind_stdout(sout), bind_stdin(sin), show_window(SW_HIDE), hide_console(), inherit_env(), set_env(env), start_in_dir(toUTF16(mir_path))); - child c = execute(set_args(argv), bind_stdin(sin), inherit_env(), set_env(env), start_in_dir(toUTF16(mir_path))); - //child c = execute(run_exe("c:\\windows\\system32\\cmd.exe"), bind_stdin(sin), inherit_env(), set_env(env), start_in_dir(toUTF16(mir_path))); + child c = execute(set_args(argv), /*bind_stdin(sin), */inherit_env(), set_env(env), start_in_dir(toUTF16(mir_path))); + _child = &c; delete [] mir_path; @@ -247,7 +209,8 @@ pxResult pxExecute_passwd_change(std::vector &aargv, char *ainput, // out< &aargv, char *ainput, void pxEexcute_passwd_change_thread(void *param) { gpg_execution_params_pass *params = (gpg_execution_params_pass*)param; - pxResult result = pxExecute_passwd_change(params->args, params->useless, params->out, params->code, params->result, params->hProcess, params->proc, params->old_pass, params->new_pass); + pxResult result = pxExecute_passwd_change(params->args, params->out, params->code, params->result, params->child, params->old_pass, params->new_pass); } diff --git a/src/gpg_wrapper.h b/src/gpg_wrapper.h index 44b2f4f..9ff0957 100755 --- a/src/gpg_wrapper.h +++ b/src/gpg_wrapper.h @@ -32,36 +32,44 @@ typedef enum { } pxResult; -pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess, PROCESS_INFORMATION *pr); -pxResult pxExecute_passwd_change(std::vector &aargv, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess, PROCESS_INFORMATION *pr, string &old_pass, string &new_pass); +pxResult pxExecute(std::vector &aargv, string *aoutput, LPDWORD aexitcode, pxResult *result); +pxResult pxExecute_passwd_change(std::vector &aargv, string *aoutput, LPDWORD aexitcode, pxResult *result, string &old_pass, string &new_pass); struct gpg_execution_params { - wstring *cmd; - char *useless; + std::vector &aargv; +// char *useless; string *out; LPDWORD code; pxResult *result; - HANDLE hProcess; - PROCESS_INFORMATION *proc; + boost::process::child *child; +// HANDLE hProcess; +// PROCESS_INFORMATION *proc; + gpg_execution_params(std::vector &a): aargv(a) + { + child = nullptr; + } }; struct gpg_execution_params_pass { std::vector &args; string &old_pass, &new_pass; - char *useless; string *out; LPDWORD code; pxResult *result; - HANDLE hProcess; - PROCESS_INFORMATION *proc; + boost::process::child *child; +// HANDLE hProcess; +// PROCESS_INFORMATION *proc; gpg_execution_params_pass(std::vector &a, std::string &o, std::string &n): args(a), old_pass(o), new_pass(n) - {} + { + child = nullptr; + } }; -void pxEexcute_thread(void *param); +void pxEexcute_thread(gpg_execution_params ¶ms); +bool gpg_launcher(gpg_execution_params ¶ms, boost::posix_time::time_duration t = boost::posix_time::seconds(10)); void pxEexcute_passwd_change_thread(void *param); #endif \ No newline at end of file diff --git a/src/init.cpp b/src/init.cpp index aab8935..06097ed 100755 --- a/src/init.cpp +++ b/src/init.cpp @@ -191,6 +191,7 @@ static int OnModulesLoaded(WPARAM wParam,LPARAM lParam) CreateProtoServiceFunction(szGPGModuleName, PSS_FILE, (MIRANDASERVICE)onSendFile); CreateProtoServiceFunction(szGPGModuleName, PSS_FILE"W", (MIRANDASERVICE)onSendFile); + clean_temp_dir(); return 0; } @@ -263,7 +264,7 @@ extern "C" int __declspec(dllexport) Unload(void) { for(list::iterator p = transfers.begin(); p != transfers.end(); p++) if(!(*p).empty()) - DeleteFile((*p).c_str()); + boost::filesystem::remove((*p)); } mir_free(inopentag); mir_free(inclosetag); @@ -271,5 +272,6 @@ extern "C" int __declspec(dllexport) Unload(void) mir_free(outclosetag); if(password) mir_free(password); + clean_temp_dir(); return 0; } diff --git a/src/main.cpp b/src/main.cpp index 2578995..a38ff2d 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,21 +101,15 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR pxResult result; wstring::size_type p = 0, p2 = 0, stop = 0; { - gpg_execution_params params; - wstring cmd = _T("--batch --list-secret-keys"); - params.cmd = &cmd; - params.useless = ""; + std::vector cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--list-secret-keys"); + gpg_execution_params params(cmd); params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(fp); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--list-secret-keys"); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--fingerprint"); + cmd.push_back(fp); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog<timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"--gen-key"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; @@ -613,20 +584,14 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE_KEY), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_LIST), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_GENERATE_RANDOM), 0); - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) + if(!gpg_launcher(params, boost::posix_time::minutes(10))) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(fp); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export-secret-keys"); + cmd.push_back(fp); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - gpg_thread.~thread(); - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - gpg_thread.~thread(); - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"--gen-key"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) + if(!gpg_launcher(params, boost::posix_time::minutes(10))) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"--gen-key"); + cmd.push_back(path); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; @@ -1660,20 +1562,12 @@ static INT_PTR CALLBACK DlgProcKeyGenDialog(HWND hwndDlg, UINT msg, WPARAM wPara EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_EMAIL), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_COMMENT), 0); EnableWindow(GetDlgItem(hwndDlg, IDC_KEY_EXPIRE_DATE), 0); - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::minutes(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--list-secret-keys"); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--list-keys"); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(id); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--keyserver"); TCHAR *server= new TCHAR [128]; GetDlgItemText(hwndDlg, IDC_KEYSERVER, server, 128); - cmd += server; + cmd.push_back(server); delete [] server; - cmd += _T("\" --recv-keys "); + cmd.push_back(L"--recv-keys"); // char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID_Prescense", ""); // TCHAR *tmp2 = mir_a2t(tmp); // mir_free(tmp); - cmd += toUTF16(hcontact_data[hContact].key_in_prescense); + cmd.push_back(toUTF16(hcontact_data[hContact].key_in_prescense)); // mir_free(tmp2); - gpg_execution_params params; + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--list-secret-keys"); + gpg_execution_params params(cmd); params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; TCHAR tmp2[MAX_PATH] = {0}; TCHAR *ptmp; string output; @@ -2513,7 +2366,7 @@ void ImportKey() mir_free(ptmp); _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); wfstream f(tmp2, std::ios::out); if(metaIsProtoMetaContacts(hContact)) ptmp = UniGetContactSettingUtf(metaGetMostOnline(hContact), szGPGModuleName, "GPGPubKey", _T("")); @@ -2523,28 +2376,17 @@ void ImportKey() mir_free(ptmp); f< msgs_to_send, msgs_to_pass; + list msgs_to_send;// msgs_to_pass; string key_in_prescense; }; diff --git a/src/messages.cpp b/src/messages.cpp index d3525d2..262aa2a 100755 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -86,7 +86,7 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, wstring decfile = toUTF16(get_random(10)); path.append(_T("\\tmp\\")); path.append(encfile); - DeleteFile(path.c_str()); + boost::filesystem::remove(path); fstream f(path.c_str(), std::ios::out); while(!f.is_open()) f.open(path.c_str(), std::ios::out); @@ -97,8 +97,8 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, extern TCHAR *password; string out; DWORD code; - wstring cmd; - cmd += _T("--batch "); + std::vector cmd; + cmd.push_back(L"--batch"); { char *inkeyid = UniGetContactSettingUtf(metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact, szGPGModuleName, "InKeyID", ""); TCHAR *pass = NULL; @@ -119,17 +119,15 @@ void RecvMsgSvc_func(HANDLE hContact, std::wstring str, char *msg, DWORD flags, } if(pass && pass[0]) { - cmd += _T("--passphrase \""); - cmd += pass; - cmd += _T("\" "); + cmd.push_back(L"--passphrase"); + cmd.push_back(pass); } else if(password && password[0]) { if(bDebugLog) debuglog<timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd2 = cmd; if(password) { if(bDebugLog) debuglog< tmp; + tmp.push_back(L"--passphrase"); + tmp.push_back(password); + cmd2.insert(cmd2.begin(), tmp.begin(), tmp.end()); } out.clear(); - gpg_execution_params params; + gpg_execution_params params(cmd2); pxResult result; - params.cmd = &cmd2; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - gpg_thread = gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog<timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog<hContact, szGPGModuleName, "GPGPubKey", str.substr(s1,s2-s1).c_str()); { //gpg execute block - wstring cmd; + std::vector cmd; TCHAR tmp2[MAX_PATH] = {0}; TCHAR *ptmp; string output; @@ -439,7 +409,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) _tcscat(tmp2, _T(".asc")); mir_free(tmp3); //_tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); wfstream f(tmp2, std::ios::out); while(!f.is_open()) f.open(tmp2, std::ios::out); @@ -448,29 +418,18 @@ int RecvMsgSvc(WPARAM w, LPARAM l) mir_free(ptmp); f< cmd; extern bool bJabberAPI, bIsMiranda09; char *tmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "KeyID", ""); if(!tmp[0]) { mir_free(tmp); HistoryLog(hContact, db_event("Failed to encrypt message with GPG (not found key for encryption in db)", 0,0, DBEF_SENT)); - hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG (not found key for encryption in db)"); - mir_free(msg); +// hcontact_data[hContact].msgs_to_pass.push_back("Failed to encrypt message with GPG (not found key for encryption in db)"); + //mir_free(msg); CallContactService(hContact, PSS_MESSAGE, (WPARAM)flags, (LPARAM)msg); return; } if(!bJabberAPI || !bIsMiranda09) //force jabber to handle encrypted message by itself - cmd += _T("--comment \"\" --no-version "); + { + cmd.push_back(L"--comment"); + cmd.push_back(L"\"\""); + cmd.push_back(L"--no-version"); + } if(DBGetContactSettingByte(hContact, szGPGModuleName, "bAlwaysTrust", 0)) - cmd += _T("--trust-model always "); - cmd += _T("--batch --yes -e -a -t -r "); + { + cmd.push_back(L"--trust-model"); + cmd.push_back(L"always"); + } + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"-eatr"); TCHAR *tmp2 = mir_a2t(tmp); mir_free(tmp); - cmd += tmp2; + cmd.push_back(tmp2); mir_free(tmp2); - cmd += _T(" \""); tmp2 = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - path.append(tmp2); - cmd += tmp2; + path = tmp2; + cmd.push_back(std::wstring(tmp2) + L"\\tmp\\" + file); mir_free(tmp2); - cmd += _T("\\tmp\\"); - cmd += file; - path.append(_T("\\tmp\\")); + path += L"\\tmp\\"; path += file; - cmd += _T("\""); { fstream f(path.c_str(), std::ios::out); while(!f.is_open()) @@ -712,28 +674,20 @@ void SendMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) f.write(tmp.c_str(), tmp.size()); f.close(); } - gpg_execution_params params; + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< tmp; + tmp.push_back(L"--trust-model"); + tmp.push_back(L"always"); + cmd.insert(cmd.begin(), tmp.begin(), tmp.end()); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog<hContact, GCDNF_TCHAR))); return CallService(MS_PROTO_CHAINSEND, w, l); } - if(!isContactHaveKey(ccs->hContact)) + /*if(!isContactHaveKey(ccs->hContact)) { if(bDebugLog) debuglog<hContact, GCDNF_TCHAR))); @@ -954,7 +904,7 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } - } + } */ else if(bDebugLog) debuglog<hContact, GCDNF_TCHAR))); if(bDebugLog && metaIsProtoMetaContacts(ccs->hContact)) @@ -966,7 +916,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) mir_free(msg); return CallService(MS_PROTO_CHAINSEND, w, l); } - boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); + mir_free(msg); + //boost::thread *thr = new boost::thread(boost::bind(SendMsgSvc_func, ccs->hContact, msg, (DWORD)ccs->wParam)); return returnNoError(ccs->hContact); } @@ -995,28 +946,136 @@ int HookSendMsg(WPARAM w, LPARAM l) return 1; } } - if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering + if(metaIsProtoMetaContacts(hContact)) + return 0; + + if(!isContactHaveKey(hContact)) { - if(!hcontact_data[hContact].msgs_to_pass.empty()) + if(bDebugLog) + debuglog<pBlob, "-----PGP KEY REQUEST-----") && !strstr((char*)dbei->pBlob, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid) { - event_processing_mutex.lock(); - std::list::iterator end = hcontact_data[hContact].msgs_to_pass.end(); - for(std::list::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i) + if(bDebugLog) + debuglog<pBlob)) + if(bDebugLog) + debuglog<pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+", message is in allowed list"); - event_processing_mutex.unlock(); - return 0; + debuglog<flags & DBEF_UTF) == DBEF_UTF)?PREF_UTF:0, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); + //TODO: wait for message + return 0; + } + } + } + else + { + TCHAR *jid = UniGetContactSettingUtf(hContact, proto, "jid", _T("")); + if(jid[0]) + { + if(bDebugLog) + debuglog< Accounts; + list::iterator end = Accounts.end(); + for(list::iterator p = Accounts.begin(); p != end; p++) + { + TCHAR *caps = (*p)->getJabberInterface()->Net()->GetResourceFeatures(jid); + if(caps) + { + wstring str; + for(int i=0;;i++) + { + str.push_back(caps[i]); + if(caps[i] == '\0') + if(caps[i+1] == '\0') + break; + } + mir_free(caps); + if(str.find(_T("GPG_Key_Auto_Exchange:0")) != string::npos) + { + if(bDebugLog) + debuglog<flags & DBEF_UTF) == DBEF_UTF)?PREF_UTF:0, (LPARAM)"-----PGP KEY REQUEST-----"); + hcontact_data[hContact].msgs_to_send.push_back((char*)dbei->pBlob); + boost::thread *thr = new boost::thread(boost::bind(send_encrypted_msgs_thread, hContact)); + mir_free((char*)dbei->pBlob); + //TODO: wait for message + return 0; + } + } + } } } - event_processing_mutex.unlock(); } - if(metaIsProtoMetaContacts(hContact) && !isContactSecured(metaGetMostOnline(hContact))) + else + { return 0; - return 1; + } + } + if(isContactSecured(hContact) && (dbei->flags & DBEF_SENT)) //aggressive outgoing events filtering + { + DWORD flags; + if((dbei->flags & DBEF_UTF) == DBEF_UTF) + flags |= PREF_UTF; + SendMsgSvc_func(hContact, (char*)dbei->pBlob, flags); + //TODO: handle errors somehow ... + if(bAppendTags) + { + string str_event = (char*)dbei->pBlob; + mir_free(dbei->pBlob); + str_event.insert(0, toUTF8(outopentag)); + str_event.append(toUTF8(outclosetag)); + dbei->pBlob = (PBYTE)mir_strdup(str_event.c_str()); + dbei->cbBlob = str_event.length() + 1; + } + + return 0; +/* bool stop = false; + int count = 0; */ +/* while(!stop) + { + if(count >= 300) + stop = true; + if(!hcontact_data[hContact].msgs_to_pass.empty()) + { + event_processing_mutex.lock(); + std::list::iterator end = hcontact_data[hContact].msgs_to_pass.end(); + for(std::list::iterator i = hcontact_data[hContact].msgs_to_pass.begin(); i != end; ++i) + { + if(!strcmp((*i).c_str(), (char*)dbei->pBlob)) + { + hcontact_data[hContact].msgs_to_pass.erase(i); + if(bDebugLog) + debuglog<pBlob+"\" passed event filter, contact "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR))+", message is in allowed list"); + event_processing_mutex.unlock(); + return 0; + } + } + event_processing_mutex.unlock(); + } + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + count++; + } */ + //return 1; } if(!isContactSecured(hContact)) { diff --git a/src/options.cpp b/src/options.cpp index ab54404..9028232 100755 --- a/src/options.cpp +++ b/src/options.cpp @@ -258,28 +258,22 @@ static INT_PTR CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP if(!keep) if(MessageBox(0, TranslateT("This key not used by any contact, do you want to remove it from public keyring ?"), TranslateT("Key info"), MB_YESNO) == IDYES) { - wstring cmd; + std::vector cmd; string output; DWORD exitcode; - cmd += _T(" --batch --yes --delete-key "); + cmd.push_back(L"--batch"); + cmd.push_back(L"--yes"); + cmd.push_back(L"--delete-key"); ptmp = mir_a2t(tmp); - cmd += ptmp; + cmd.push_back(ptmp); mir_free(ptmp); - gpg_execution_params params; + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &output; params.code = &exitcode; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) + if(!gpg_launcher(params)) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - } + gpg_launcher(params); DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp_path); mir_free(tmp_path); string::size_type p1 = out.find("(GnuPG) "); @@ -844,26 +831,16 @@ static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam { string out; DWORD code; - wstring cmd = _T(" --export -a "); -// TCHAR *tmp3 = mir_a2t(tmp); - cmd += toUTF16(hcontact_data[hcnt].key_in_prescense); -// mir_free(tmp3); - gpg_execution_params params; + std::vector cmd; + cmd.push_back(L"--export"); + cmd.push_back(L"-a"); + cmd.push_back(toUTF16(hcontact_data[hcnt].key_in_prescense)); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; TCHAR tmp2[MAX_PATH] = {0}; TCHAR *ptmp; string output; @@ -985,7 +962,7 @@ static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam mir_free(ptmp); _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); wfstream f(tmp2, std::ios::out); ptmp = UniGetContactSettingUtf(hcnt, szGPGModuleName, "GPGPubKey", _T("")); wstring str = ptmp; @@ -997,28 +974,17 @@ static INT_PTR CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam } f< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-a"); + cmd.push_back(L"--export"); + cmd.push_back(fp); mir_free(fp); - gpg_execution_params params; + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog<hContact, db_event("Recieved encrypted file, trying to decrypt", 0,0, 0)); - if(_waccess(f->tszCurrentFile, 0) == -1) - { - if(errno == ENOENT) - return 0; - } + if(!boost::filesystem::exists(f->tszCurrentFile)) + return 0; string out; DWORD code; pxResult result; - wstring cmd = _T(" -o "); + std::vector cmd; + cmd.push_back(L"-o"); wstring file = filename; wstring::size_type p1 = file.rfind(_T(".gpg")); file.erase(p1, _tcslen(_T(".gpg"))); - if(_waccess(file.c_str(), 0) != -1) + if(boost::filesystem::exists(file)) { if(MessageBox(0, TranslateT("Target file exists, do you want to replace it ?"), TranslateT("Warning"), MB_YESNO) == IDNO) return 0; } - DeleteFile(file.c_str()); - file.insert(0, _T("\"")); - file.insert(file.length(), _T("\" ")); - cmd += file; + cmd.push_back(file); + boost::filesystem::remove(file); extern TCHAR *password; { // password TCHAR *pass = NULL; @@ -416,42 +412,29 @@ int onProtoAck(WPARAM w, LPARAM l) } if(_tcslen(pass) > 0) { - cmd += _T("--passphrase \""); - cmd += pass; - cmd += _T("\" "); + cmd.push_back(L"--passphrase"); + cmd.push_back(pass); } else if(password) { if(bDebugLog) debuglog<hContact, GCDNF_TCHAR))+" with password"); - cmd += _T("--passphrase \""); - cmd += password; - cmd += _T("\" "); + cmd.push_back(L"--passphrase"); + cmd.push_back(password); } else if (bDebugLog) debuglog<hContact, GCDNF_TCHAR))+" with out password"); mir_free(pass); mir_free(keyid); } - cmd += _T(" -d \""); - cmd += filename; - cmd += _T("\""); - gpg_execution_params params; - params.cmd = &cmd; - params.useless = ""; + cmd.push_back(L"-d"); + cmd.push_back(filename); + gpg_execution_params params(cmd); params.out = &out; params.code = &code; params.result = &result; - boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::minutes(15))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog<hContact; ShowLoadKeyPasswordWindow(); - wstring cmd2 = cmd; + std::vector cmd2 = cmd; if(password) { if(bDebugLog) debuglog<hContact, GCDNF_TCHAR))); - wstring tmp = _T("--passphrase \""); - tmp += password; - tmp += _T("\" "); - cmd2.insert(0, tmp); + std::vector tmp; + tmp.push_back(L"--passphrase"); + tmp.push_back(password); + cmd2.insert(cmd2.begin(), tmp.begin(), tmp.end()); } out.clear(); - gpg_execution_params params; + gpg_execution_params params(cmd2); //pxResult result; - params.cmd = &cmd2; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - gpg_thread = gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(15))) + if(!gpg_launcher(params, boost::posix_time::seconds(15))) { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"--tes"); + cmd.push_back(L"-r"); char *keyid = UniGetContactSettingUtf(hcnt, szGPGModuleName, "KeyID", ""); TCHAR *szKeyid = mir_a2t(keyid); TCHAR *name = _tcsrchr(filename,_T('\\')); @@ -560,58 +538,42 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) name++; TCHAR *file_out = new TCHAR [_tcslen(filename)+4]; mir_sntprintf(file_out, _tcslen(name)+7, _T("%s.gpg"), name); - cmd += szKeyid; + cmd.push_back(szKeyid); if(DBGetContactSettingByte(hcnt, szGPGModuleName, "bAlwaysTrust", 0)) - cmd += _T(" --trust-model always "); + { + cmd.push_back(L"--trust-model"); + cmd.push_back(L"always"); + } mir_free(szKeyid); mir_free(keyid); - cmd += _T(" -o \""); + cmd.push_back(L"-o"); TCHAR *temp = _tgetenv(_T("TEMP")); - cmd += temp; - cmd += _T("\\"); - cmd += file_out; + cmd.push_back(wstring(temp) + L"\\" + file_out); wstring path_out = temp; path_out += _T("\\"); path_out += file_out; - DeleteFile(path_out.c_str()); - cmd += _T("\" "); - cmd += _T(" -e \""); - cmd += filename; - cmd += _T("\" "); - gpg_execution_params params; - params.cmd = &cmd; - params.useless = ""; + boost::filesystem::remove(path_out); + cmd.push_back(L"-e"); + cmd.push_back(filename); + gpg_execution_params params(cmd); params.out = &out; params.code = &code; params.result = &result; delete [] file_out; - boost::thread *gpg_thread = new boost::thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread->timed_join(boost::posix_time::seconds(180))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog<timed_join(boost::posix_time::seconds(180))) - { - delete gpg_thread; - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< tmp; + tmp.push_back(L"--trust-model"); + tmp.push_back(L"always"); + cmd.insert(cmd.begin(), tmp.begin(), tmp.end()); + if(!gpg_launcher(params, boost::posix_time::minutes(3))) return 0; - } } else return 0; @@ -691,9 +653,8 @@ int onSendFile(WPARAM w, LPARAM l) TCHAR **file=(TCHAR **)ccs->lParam; for(i = 0; file[i]; i++) { - if(_waccess(file[i], 0) == -1) - if(errno == ENOENT) - return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) + if(!boost::filesystem::exists(file[i])) + return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) if (_tcsstr(file[i],_T(".gpg"))) continue; std::wstring path_out = encrypt_file(ccs->hContact, file[i]); @@ -707,9 +668,8 @@ int onSendFile(WPARAM w, LPARAM l) char **file = (char**) ccs->lParam; for(i = 0; file[i]; i++) { - if(_access(file[i], 0) == -1) - if(errno == ENOENT) - return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) + if(!boost::filesystem::exists(file[i])) + return 0; //we do not want to send file unencrypted (sometimes ack have wrong info) if (strstr(file[i],".gpg")) continue; TCHAR *tmp = mir_utf8decodeT(file[i]); @@ -726,23 +686,6 @@ int onSendFile(WPARAM w, LPARAM l) return CallService(MS_PROTO_CHAINSEND, w, l); } -void storeOutput(HANDLE ahandle, string *output) -{ - BOOL success; - char *readbuffer = NULL; - unsigned long transfered, available; - - do { - PeekNamedPipe(ahandle,NULL,0,NULL,&available,NULL); - if (!available) - continue; - readbuffer = (char*)mir_alloc(available); - success=ReadFile(ahandle,readbuffer,available,&transfered,NULL); - if (success && transfered) - output->append(readbuffer, available); - mir_free(readbuffer); - } while (available>0); -} void HistoryLog(HANDLE hContact, db_event evt) { @@ -872,24 +815,21 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU mir_free(path_c); path_out += _T("\\tmp\\"); path_out += file; - DeleteFile(path_out.c_str()); + boost::filesystem::remove(path_out); wfstream f(path_out.c_str(), std::ios::out); f< cmd; { char *inkeyid; { @@ -922,49 +862,38 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU } if(pass[0]) { - cmd += _T("--passphrase \""); - cmd += pass; - cmd += _T("\" "); + cmd.push_back(L"--passphrase"); + cmd.push_back(pass); } else if(password) { if(bDebugLog) debuglog< cmd; + cmd.push_back(L"--verify"); + cmd.push_back(L"-a"); + cmd.push_back(path_out); + cmd.push_back(status_file_out); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(15))) + if(!gpg_launcher(params, boost::posix_time::seconds(15))) { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--version"); + gpg_execution_params params(cmd); pxResult result; - params.cmd = &cmd; - params.useless = ""; params.out = &out; params.code = &code; params.result = &result; gpg_valid = true; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; + cmd.push_back(L"--batch"); + cmd.push_back(L"-export-secret-keys"); + cmd.push_back(L"-a"); + gpg_execution_params params(cmd); params.out = &out; params.code = &code; params.result = &result; - boost::thread gpg_thread(boost::bind(&pxEexcute_thread, ¶ms)); - if(!gpg_thread.timed_join(boost::posix_time::seconds(10))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog) - debuglog< cmd; TCHAR *ptmp; string output; DWORD exitcode; { HANDLE hcnt = hContact; ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T("")); - _tcscpy(tmp2, ptmp); + path = ptmp; mir_free(ptmp); - _tcscat(tmp2, _T("\\")); - _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); - wfstream f(tmp2, std::ios::out); + mir_free(ptmp); + wstring rand = toUTF16(get_random(10)); + path += L"\\"; + path += rand; + boost::filesystem::remove(path); + wfstream f(path, std::ios::out); f< cmd; TCHAR tmp2[MAX_PATH] = {0}; TCHAR *ptmp; string output; @@ -2051,32 +1939,21 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) mir_free(ptmp); _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); - DeleteFile(tmp2); + boost::filesystem::remove(tmp2); wfstream f(tmp2, std::ios::out); f<path())) + { + if((i->path().filename().generic_string().length() == 10 && (i->path().filename().generic_string().find(".") == std::string::npos)) || + i->path().extension() == ".sig" || i->path().extension() == ".asc" || i->path().extension() == ".status") + boost::filesystem::remove(i->path()); + } + } + } +} \ No newline at end of file diff --git a/src/utilities.h b/src/utilities.h index 508a241..eaa7ef7 100755 --- a/src/utilities.h +++ b/src/utilities.h @@ -105,5 +105,6 @@ void fix_line_term(std::wstring &s); void strip_line_term(std::wstring &s); void strip_line_term(std::string &s); void strip_tags(std::wstring &s); +void clean_temp_dir(); #endif -- cgit v1.2.3