diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-08 23:57:56 +0200 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2013-02-08 23:57:56 +0200 |
commit | 418736c65c97cdc6ca4910e1e8650e474cb12849 (patch) | |
tree | c5d85988440500689a3106490abbeb1b888bcf95 /src/utilities.cpp | |
parent | 5ea554f9494093cf070559f47e777df13b6bc423 (diff) |
merged with miranda_ng main repo
"boosted" process management
evnt_to_db/history>actual_sending logic to avoid srmm problem
Diffstat (limited to 'src/utilities.cpp')
-rwxr-xr-x | src/utilities.cpp | 402 |
1 files changed, 153 insertions, 249 deletions
diff --git a/src/utilities.cpp b/src/utilities.cpp index d725b5b..8a7e0b3 100755 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -374,27 +374,23 @@ int onProtoAck(WPARAM w, LPARAM l) if(file_msg_state < 1)
return 0;
HistoryLog(ack->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<wstring> 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<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->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<<std::string(time_str()+": info: passwords not found in database or memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->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<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(!gpg_launcher(params, boost::posix_time::minutes(15)))
return 0; - } while(out.find("public key decryption failed: bad passphrase") != string::npos)
{ extern bool _terminate;
@@ -475,43 +458,35 @@ int onProtoAck(WPARAM w, LPARAM l) new_key_hcnt_mutex.lock();
new_key_hcnt = ack->hContact;
ShowLoadKeyPasswordWindow();
- wstring cmd2 = cmd;
+ std::vector<wstring> cmd2 = cmd;
if(password)
{
if(bDebugLog)
debuglog<<std::string(time_str()+": info: found password in memory, trying to decrypt message from "+toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)ack->hContact, GCDNF_TCHAR)));
- wstring tmp = _T("--passphrase \"");
- tmp += password;
- tmp += _T("\" ");
- cmd2.insert(0, tmp);
+ std::vector<wstring> 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<<std::string(time_str()+": GPG execution timed out, aborted");
- //DeleteFile(filename);
+ //boost::filesystem::remove(filename);
return 0;
}
if(result == pxNotFound)
{
- //DeleteFile(filename);
+ //boost::filesystem::remove(filename);
return 0;
}
} if(result == pxSuccess)
- DeleteFile(filename);
+ boost::filesystem::remove(filename);
mir_free(filename);
}
} @@ -550,7 +525,10 @@ std::wstring encrypt_file(HANDLE hContact, TCHAR *filename) DWORD code; pxResult result; HANDLE hcnt = metaIsProtoMetaContacts(hContact)?metaGetMostOnline(hContact):hContact; - wstring cmd = _T("--batch --yes -r "); + std::vector<wstring> 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<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(!gpg_launcher(params, boost::posix_time::minutes(3)))
return 0; - } if(out.find("There is no assurance this key belongs to the named user") != string::npos) { out.clear(); if(MessageBox(0, TranslateT("We trying to encrypt with untrusted key, do you want to trust this key permanently ?"), TranslateT("Warning"), MB_YESNO) == IDYES)
{ DBWriteContactSettingByte(hcnt, szGPGModuleName, "bAlwaysTrust", 1); - cmd.insert(0, _T("--trust-model always ")); - 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<<std::string(time_str()+": GPG execution timed out, aborted");
+ std::vector<std::wstring> 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<<toUTF8(str).c_str(); f.close(); - if(_waccess(path_out.c_str(), 0) == -1) + if(!boost::filesystem::exists(path_out))
{ - if(errno == ENOENT) - { - if(bDebugLog)
- debuglog<<std::string(time_str()+": info: Failed to write prescense in file");
- return FALSE; - } + if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: Failed to write prescense in file");
+ return FALSE;
} { extern TCHAR *password; string out; DWORD code; - wstring cmd; + std::vector<wstring> 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<<std::string(time_str()+": info: found password in memory, trying to encrypt message from self with password");
- cmd += _T("--passphrase \""); - cmd += password; - cmd += _T("\" "); + cmd.push_back(L"--passphrase");
+ cmd.push_back(password);
} else if (bDebugLog)
debuglog<<std::string(time_str()+": info: passwords not found in database or memory, trying to encrypt message from self with out password");
mir_free(pass); mir_free(inkeyid); } - cmd += _T("--local-user "); + cmd.push_back(L"--local-user");
path_c = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T("")); - cmd += path_c; - cmd += _T(" --default-key "); - cmd += path_c; + cmd.push_back(path_c);
+ cmd.push_back(L"--default-key");
+ cmd.push_back(path_c);
mir_free(path_c); - cmd += _T(" --batch --yes -a -b -s \"");
- cmd += path_out; - cmd += _T("\" "); - gpg_execution_params params; + cmd.push_back(L"--batch");
+ cmd.push_back(L"--yes");
+ cmd.push_back(L"-abs");
+ cmd.push_back(path_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))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog)
- debuglog<<std::string(time_str()+"GPG execution timed out, aborted");
- } - DeleteFile(path_out.c_str()); + gpg_launcher(params, boost::posix_time::seconds(15)); // TODO: handle errors
+ boost::filesystem::remove(path_out);
path_out += _T(".asc"); f.open(path_out.c_str(), std::ios::in | std::ios::ate | std::ios::binary); wstring data; @@ -978,7 +907,7 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU data.append(tmp); delete [] tmp; f.close(); - DeleteFile(path_out.c_str()); + boost::filesystem::remove(path_out);
} if(data.empty()) { @@ -1081,8 +1010,8 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi status_file_out += status_file;
status_file_out += L".status";
// sign_file_mutex.lock(); - DeleteFile(path_out.c_str()); - DeleteFile(status_file_out.c_str());
+ boost::filesystem::remove(path_out);
+ boost::filesystem::remove(status_file_out);
wfstream f(path_out.c_str(), std::ios::out); while(!f.is_open()) f.open(path_out.c_str(), std::ios::out); @@ -1093,48 +1022,36 @@ static JABBER_HANDLER_FUNC PrescenseHandler(IJabberInterface *ji, HXML node, voi f.open(status_file_out.c_str(), std::ios::out);
f<<toUTF8(status_str).c_str();
f.close();
- if(_waccess(path_out.c_str(), 0) == -1) + if(!boost::filesystem::exists(path_out))
{ - if(errno == ENOENT) - { // sign_file_mutex.unlock(); - if(bDebugLog)
- debuglog<<std::string(time_str()+": info: Failed to write sign in file");
- return FALSE; - } + if(bDebugLog)
+ debuglog<<std::string(time_str()+": info: Failed to write sign in file");
+ return FALSE;
} { //gpg string out; DWORD code; - wstring cmd = L" --verify -a \"";
- cmd += path_out; - cmd += L"\"";
- cmd += L" \"";
- cmd += status_file_out;
- cmd += L"\"";
- gpg_execution_params params; + std::vector<wstring> 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<<std::string(time_str()+": GPG execution timed out, aborted");
return FALSE; } if(result == pxNotFound) { return FALSE; } - DeleteFile(path_out.c_str()); - DeleteFile(status_file_out.c_str());
+ boost::filesystem::remove(path_out);
+ boost::filesystem::remove(status_file_out);
if(out.find("key ID ") != string::npos) { //need to get hcontact here, i can get jid from hxml, and get handle from jid, maybe exists better way ? @@ -1291,24 +1208,15 @@ bool isGPGValid() DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp); string out; DWORD code; - wstring cmd = _T("--version"); - gpg_execution_params params; + std::vector<wstring> 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<<std::string(time_str()+": GPG execution timed out, aborted");
- } + gpg_launcher(params);
gpg_valid = false; string::size_type p1 = out.find("(GnuPG) "); if(p1 == string::npos) @@ -1374,11 +1282,11 @@ int SendBroadcast( HANDLE hContact, int type, int result, HANDLE hProcess, LPARA ACKDATA ack; memset(&ack,0,sizeof(ack)); ack.cbSize = sizeof( ACKDATA ); - ack.szModule = szGPGModuleName;// GetContactProto(hContact);
+ ack.szModule = GetContactProto(hContact);//szGPGModuleName;
ack.hContact = hContact; ack.type = type; ack.result = result; - ack.hProcess = hProcess; + ack.hProcess = (HANDLE)777;//hProcess;
ack.lParam = lParam; return CallService( MS_PROTO_BROADCASTACK, 0, ( LPARAM )&ack ); } @@ -1679,26 +1587,15 @@ void ExportGpGKeysFunc(int type) string out;
DWORD code;
pxResult result;
- gpg_execution_params params;
- wstring cmd = _T("--batch --export-secret-keys -a");
- params.cmd = &cmd;
- params.useless = "";
+ std::vector<wstring> 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<<std::string(time_str()+": GPG execution timed out, aborted");
- //break;
- }
- else if(result == pxNotFound)
- ;//break;
- else
+ gpg_launcher(params); //TODO: handle errors
{
file<<out;
file<<std::endl;
@@ -1917,44 +1814,35 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) } if(found) { - wstring cmd; - TCHAR tmp2[MAX_PATH] = {0}; + wstring path;
+ std::vector<std::wstring> 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<<toUTF16(key).c_str(); f.close(); - cmd += _T(" --batch "); - cmd += _T(" --import \""); - cmd += tmp2; - cmd += _T("\""); + cmd.push_back(L"--batch");
+ cmd.push_back(L"--import");
+ cmd.push_back(path);
} - 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))) - { - gpg_thread.~thread(); - TerminateProcess(params.hProcess, 1); - params.hProcess = NULL; - if(bDebugLog)
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(!gpg_launcher(params))
break; - } if(result == pxNotFound) break; if(result == pxSuccess) @@ -1963,7 +1851,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) if(output.find("already in secret keyring") != string::npos) { MessageBox(0, TranslateT("Key already in scret key ring."), TranslateT("Info"), MB_OK);
- DeleteFile(tmp2); + boost::filesystem::remove(path);
break; } char *tmp2; @@ -2031,7 +1919,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) DBWriteContactSettingByte(hContact, szGPGModuleName, "GPGEncryption", 1); DBWriteContactSettingTString(hContact, szGPGModuleName, "GPGPubKey", toUTF16(key).c_str()); } - DeleteFile(tmp2); + boost::filesystem::remove(path);
break; } } @@ -2040,7 +1928,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) }
if(strstr(line, "-----END PGP PRIVATE KEY BLOCK-----"))
{
- wstring cmd;
+ std::vector<wstring> 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<<toUTF16(key).c_str();
f.close();
- cmd += _T(" --batch ");
- cmd += _T(" --import \"");
- cmd += tmp2;
- cmd += _T("\"");
+ cmd.push_back(L"--batch");
+ cmd.push_back(L"--import");
+ cmd.push_back(tmp2);
}
- 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)))
- {
- gpg_thread.~thread();
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
- if(bDebugLog)
- debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
+ if(!gpg_launcher(params))
break;
- }
if(result == pxNotFound)
break;
if(result == pxSuccess)
@@ -2319,16 +2196,15 @@ static INT_PTR CALLBACK DlgProcChangePasswd(HWND hwndDlg, UINT msg, WPARAM wPara cmd.push_back(L"passwd");
gpg_execution_params_pass params(cmd, old_pass, new_pass);
pxResult result;
- params.useless = "";
params.out = &output;
params.code = &exitcode;
params.result = &result;
boost::thread gpg_thread(boost::bind(&pxEexcute_passwd_change_thread, ¶ms));
- if(!gpg_thread.timed_join(boost::posix_time::seconds(100)))
+ if(!gpg_thread.timed_join(boost::posix_time::minutes(10)))
{
gpg_thread.~thread();
- TerminateProcess(params.hProcess, 1);
- params.hProcess = NULL;
+ if(params.child)
+ boost::process::terminate(*(params.child));
if(bDebugLog)
debuglog<<std::string(time_str()+": GPG execution timed out, aborted");
DestroyWindow(hwndDlg);
@@ -2374,3 +2250,31 @@ void ShowChangePasswdDlg() hwndPaaswdDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CHANGE_PASSWD), NULL, DlgProcChangePasswd);
SetForegroundWindow(hwndPaaswdDlg);
}
+ +
+void clean_temp_dir()
+{
+ using namespace boost::filesystem; + char *mir_path = new char [MAX_PATH]; + CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path); + wstring path = toUTF16(mir_path); + SetCurrentDirectoryA(mir_path); + delete [] mir_path; + TCHAR *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ path += tmp;
+ mir_free(tmp);
+ path += L"\\tmp";
+ if(exists(path) && is_directory(path))
+ {
+ boost::filesystem::path p(path);
+ for(directory_iterator i = directory_iterator(p), end = directory_iterator(); i != end; ++i)
+ {
+ if(boost::filesystem::is_regular_file(i->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 |