summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-05-18 22:28:05 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-05-18 22:28:05 +0300
commit365d949d8ec2712fbdec479e73e78cbbe80b3399 (patch)
tree8b3fdf275d6ec5cc92d0ecedbe57cf9cc9617be7
parent570935ac486f2e1f5d36ecd07216e1474603c8ce (diff)
fixed (#33 Settings)
-rwxr-xr-xglobals.h2
-rwxr-xr-xgpg_wrapper.cpp2
-rwxr-xr-xinit.cpp2
-rwxr-xr-xmain.cpp54
-rwxr-xr-xmessages.cpp6
-rwxr-xr-xutilities.cpp70
-rwxr-xr-xutilities.h3
7 files changed, 109 insertions, 30 deletions
diff --git a/globals.h b/globals.h
index 334e535..e62ab24 100755
--- a/globals.h
+++ b/globals.h
@@ -16,7 +16,7 @@
#ifndef GLOBALS_H
#define GLOBALS_H
-extern bool bAppendTags, gpg_configured;
+extern bool bAppendTags, gpg_valid, gpg_keyexist;
extern TCHAR *inopentag, *inclosetag, *outopentag, *outclosetag;
extern logtofile debuglog;
#endif
diff --git a/gpg_wrapper.cpp b/gpg_wrapper.cpp
index a36926e..410a0d5 100755
--- a/gpg_wrapper.cpp
+++ b/gpg_wrapper.cpp
@@ -24,7 +24,7 @@
pxResult pxExecute(wstring *acommandline, char *ainput, string *aoutput, LPDWORD aexitcode, pxResult *result, HANDLE hProcess, PROCESS_INFORMATION *pr)
{
// gpg_mutex.lock();
- if(!gpg_configured)
+ if(!gpg_valid)
return pxNotConfigured;
extern logtofile debuglog;
BOOL success;
diff --git a/init.cpp b/init.cpp
index 97bc30c..0d2fb4b 100755
--- a/init.cpp
+++ b/init.cpp
@@ -33,7 +33,7 @@ UTF8_INTERFACE utfi = {0};
RECT key_from_keyserver_rect = {0}, firstrun_rect = {0}, new_key_rect = {0}, key_gen_rect = {0}, load_key_rect = {0}, import_key_rect = {0}, key_password_rect = {0}, load_existing_key_rect = {0};
XML_API xi = {0};
logtofile debuglog;
-bool gpg_configured = false;
+bool gpg_valid = false, gpg_keyexist = false;
std::map<HANDLE, contact_data> hcontact_data;
diff --git a/main.cpp b/main.cpp
index abd6982..36a037f 100755
--- a/main.cpp
+++ b/main.cpp
@@ -226,7 +226,8 @@ static BOOL CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM
delete [] name;
}
bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange");
- gpg_configured = isGPGConfigured();
+ gpg_valid = isGPGValid();
+ gpg_keyexist = isGPGKeyExist();
DestroyWindow(hwndDlg);
break;
case IDC_OTHER:
@@ -570,9 +571,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
if(_waccess(tmp, 0) == -1)
{
if(errno == ENOENT)
- {
MessageBox(0, TranslateT("wrong gpg binary location found in system.\nplease choose another location"), TranslateT("Warning"), MB_OK);
- }
}
}
}
@@ -594,7 +593,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
params.out = &out;
params.code = &code;
params.result = &result;
- gpg_configured = true;
+ gpg_valid = true;
boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
{
@@ -603,7 +602,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
}
- gpg_configured = false;
+ gpg_valid = false;
DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath");
string::size_type p1 = out.find("(GnuPG) ");
if(p1 != string::npos)
@@ -714,7 +713,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
params.out = &out;
params.code = &code;
params.result = &result;
- gpg_configured = true;
+ gpg_valid = true;
boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
{
@@ -723,7 +722,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
gpg_thread.~thread();
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
}
- gpg_configured = false;
+ gpg_valid = false;
DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath");
string::size_type p1 = out.find("(GnuPG) ");
if(p1 != string::npos)
@@ -760,7 +759,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
}
mir_free(path);
}
- gpg_configured = true;
+ gpg_valid = true;
DBWriteContactSettingByte(NULL, szGPGModuleName, "FirstRun", 0);
DestroyWindow(hwndDlg);
ShowFirstRunDialog();
@@ -803,7 +802,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
params.out = &out;
params.code = &code;
params.result = &result;
- gpg_configured = true;
+ gpg_valid = true;
boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
{
@@ -812,7 +811,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
gpg_thread.~thread();
debuglog<<time_str()<<": GPG execution timed out, aborted\n";
}
- gpg_configured = false;
+ gpg_valid = false;
DBDeleteContactSetting(NULL, szGPGModuleName, "szGpgBinPath");
string::size_type p1 = out.find("(GnuPG) ");
if(p1 != string::npos)
@@ -895,7 +894,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
params.out = &out;
params.code = &code;
params.result = &result;
- gpg_configured = true;
+ gpg_valid = true;
boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread.timed_join(boost::posix_time::minutes(10)))
{
@@ -903,10 +902,10 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
debuglog<<time_str()<<": GPG execution timed out, aborted";
- gpg_configured = false;
+ gpg_valid = false;
break;
}
- gpg_configured = false;
+ gpg_valid = false;
if(result == pxNotFound)
break;
DeleteFile(path.c_str());
@@ -929,7 +928,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
params.out = &out;
params.code = &code;
params.result = &result;
- gpg_configured = true;
+ gpg_valid = true;
boost::thread gpg_thread(boost::bind(&pxEexcute_thread, &params));
if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
{
@@ -937,10 +936,10 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
TerminateProcess(params.hProcess, 1);
params.hProcess = NULL;
debuglog<<time_str()<<"GPG execution timed out, aborted\n";
- gpg_configured = false;
+ gpg_valid = false;
break;
}
- gpg_configured = false;
+ gpg_valid = false;
if(result == pxNotFound)
break;
string::size_type s = 0;
@@ -955,7 +954,7 @@ static BOOL CALLBACK DlgProcGpgBinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP
}
}
bAutoExchange = CheckStateStoreDB(hwndDlg, IDC_AUTO_EXCHANGE, "bAutoExchange");
- gpg_configured = true;
+ gpg_valid = true;
DBWriteContactSettingByte(NULL, szGPGModuleName, "FirstRun", 0);
DestroyWindow(hwndDlg);
break;
@@ -1787,9 +1786,10 @@ void FirstRun()
void InitCheck()
{
{//parse gpg output
- gpg_configured = isGPGConfigured();
- if(!gpg_configured)
+ gpg_valid = isGPGValid();
+ if(!gpg_valid)
return;
+ gpg_keyexist = isGPGKeyExist();
string out;
DWORD code;
pxResult result;
@@ -1821,13 +1821,23 @@ void InitCheck()
_wmkdir(tmp_dir.c_str());
string question = Translate("Your secret key whith id: ");
char *keyid = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", "");
- question += keyid;
- mir_free(keyid);
- question += Translate(" deleted from gpg secret keyring\nDo you want to set another key ?");
+ char *key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", "");
void ShowFirstRunDialog();
+ if(!keyid[0] || !key[0])
+ {
+ question = Translate("You have not set public key for gpg, it's recommended to do it.\nDo you want to do it now ?");
+ if(MessageBoxA(0, question.c_str(), Translate("Own public key warning"), MB_YESNO) == IDYES)
+ ShowFirstRunDialog();
+ }
if(out.find(keyid) == string::npos)
+ {
+ question += keyid;
+ question += Translate(" deleted from gpg secret keyring\nDo you want to set another key ?");
if(MessageBoxA(0, question.c_str(), Translate("Own secret key warning"), MB_YESNO) == IDYES)
ShowFirstRunDialog();
+ }
+ mir_free(keyid);
+ mir_free(key);
}
{
TCHAR *path = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
diff --git a/messages.cpp b/messages.cpp
index fc52aea..74d0c44 100755
--- a/messages.cpp
+++ b/messages.cpp
@@ -545,7 +545,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
HistoryLog(ccs->hContact, db_event(msg, 0, 0, dbflags));
return 0;
}
- if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && isGPGConfigured())
+ if(bAutoExchange && strstr(msg, "-----PGP KEY REQUEST-----") && gpg_valid && gpg_keyexist)
{
char *tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", "");
if(tmp[0])
@@ -557,7 +557,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l)
DBWriteContactSettingByte(ccs->hContact, szGPGModuleName, "GPGEncryption", 1);
}
mir_free(tmp);
- if(!isContactHaveKey(ccs->hContact) && bAutoExchange && isGPGConfigured())
+ if(!isContactHaveKey(ccs->hContact) && bAutoExchange && gpg_valid && gpg_keyexist)
{
LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0);
DWORD uin = DBGetContactSettingDword(ccs->hContact, proto, "UIN", 0);
@@ -802,7 +802,7 @@ int SendMsgSvc(WPARAM w, LPARAM l)
return CallService(MS_PROTO_CHAINSEND, w, l);
if(!isContactHaveKey(ccs->hContact))
{
- if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && isGPGConfigured())
+ if(bAutoExchange && !strstr(msg, "-----PGP KEY REQUEST-----") && !strstr(msg, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && gpg_valid)
{
void send_encrypted_msgs_thread(HANDLE hContact);
LPSTR proto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)ccs->hContact, 0);
diff --git a/utilities.cpp b/utilities.cpp
index f6a0290..0648c37 100755
--- a/utilities.cpp
+++ b/utilities.cpp
@@ -1033,7 +1033,7 @@ bool isContactHaveKey(HANDLE hContact)
return false;
}
-bool isGPGConfigured()
+bool isGPGKeyExist()
{
TCHAR *id = UniGetContactSettingUtf(NULL, szGPGModuleName, "KeyID", _T(""));
char *key = UniGetContactSettingUtf(NULL, szGPGModuleName, "GPGPubKey", "");
@@ -1047,6 +1047,74 @@ bool isGPGConfigured()
mir_free(key);
return false;
}
+bool isGPGValid()
+{
+ TCHAR *tmp;
+ bool gpg_exists = false, is_valid = true;
+ tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szGpgBinPath", _T(""));
+ if(_waccess(tmp, 0) != -1)
+ gpg_exists = true;
+ else
+ {
+ mir_free(tmp);
+ TCHAR *path = new TCHAR [MAX_PATH];
+ char *mir_path = new char [MAX_PATH];
+ CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM)"\\", (LPARAM)mir_path);
+ SetCurrentDirectoryA(mir_path);
+ tmp = mir_a2t(mir_path);
+ mir_free(mir_path);
+ mir_realloc(path, (_tcslen(path)+128)*sizeof(TCHAR));
+ TCHAR *gpg_path = new TCHAR [MAX_PATH];
+ _tcscpy(gpg_path, tmp);
+ _tcscat(gpg_path, _T("\\GnuPG\\gpg.exe"));
+ mir_free(tmp);
+ if(_waccess(gpg_path, 0) != -1)
+ {
+ gpg_exists = true;
+ _tcscpy(path, _T("GnuPG\\gpg.exe"));
+ }
+ mir_free(gpg_path);
+ tmp = mir_wstrdup(path);
+ delete [] path;
+ }
+ DWORD len = MAX_PATH;
+ if(gpg_exists)
+ {
+ DBWriteContactSettingTString(NULL, szGPGModuleName, "szGpgBinPath", tmp);
+ string out;
+ DWORD code;
+ wstring cmd = _T("--version");
+ gpg_execution_params params;
+ 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, &params));
+ if(!gpg_thread.timed_join(boost::posix_time::seconds(10)))
+ {
+ gpg_thread.~thread();
+ TerminateProcess(params.hProcess, 1);
+ params.hProcess = NULL;
+ debuglog<<time_str()<<": GPG execution timed out, aborted\n";
+ }
+ gpg_valid = false;
+ string::size_type p1 = out.find("(GnuPG) ");
+ if(p1 == string::npos)
+ is_valid = false;
+ }
+ mir_free(tmp);
+ if(!gpg_exists)
+ {
+ wstring path_ = _wgetenv(_T("APPDATA"));
+ path_ += _T("\\GnuPG");
+ tmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", (TCHAR*)path_.c_str());
+ }
+ mir_free(tmp);
+ return is_valid;
+}
#define NEWTSTR_MALLOC(A) (A==NULL)?NULL:strcpy((char*)mir_alloc(sizeof(char)*(strlen(A)+1)),A)
diff --git a/utilities.h b/utilities.h
index 3d9d693..f27dfca 100755
--- a/utilities.h
+++ b/utilities.h
@@ -27,7 +27,8 @@ void storeOutput(HANDLE ahandle, string *output);
int ComboBoxAddStringUtf(HWND hCombo, const TCHAR *szString, DWORD data);
bool isContactSecured(HANDLE hContact);
bool isContactHaveKey(HANDLE hContact);
-bool isGPGConfigured();
+bool isGPGKeyExist();
+bool isGPGValid();
const bool StriStr(const char *str, const char *substr);
string toUTF8(wstring str);
wstring toUTF16(string str);