diff options
Diffstat (limited to 'utilities.cpp')
-rwxr-xr-x | utilities.cpp | 400 |
1 files changed, 152 insertions, 248 deletions
diff --git a/utilities.cpp b/utilities.cpp index b42d8e7..736e5cf 100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -377,27 +377,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;
@@ -419,42 +415,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;
@@ -478,43 +461,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);
}
}
@@ -553,7 +528,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('\\'));
@@ -563,58 +541,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;
@@ -694,9 +656,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]);
@@ -710,9 +671,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]);
@@ -729,23 +689,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)
{
@@ -875,24 +818,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;
{
@@ -925,49 +865,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;
@@ -981,7 +910,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())
{
@@ -1084,8 +1013,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);
@@ -1096,48 +1025,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 ?
@@ -1294,24 +1211,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)
@@ -1381,7 +1289,7 @@ int SendBroadcast( HANDLE hContact, int type, int result, HANDLE hProcess, LPARA 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 );
}
@@ -1681,26 +1589,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;
@@ -1919,44 +1816,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);
mir_free(ptmp);
- _tcscat(tmp2, _T("\\"));
- _tcscat(tmp2, _T("temporary_exported.asc"));
- DeleteFile(tmp2);
- wfstream f(tmp2, std::ios::out);
+ 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)
@@ -1965,7 +1853,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;
@@ -2033,7 +1921,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;
}
}
@@ -2042,7 +1930,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;
@@ -2053,32 +1941,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)
@@ -2321,16 +2198,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);
@@ -2376,3 +2252,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 |