diff options
author | Alexander Gluzsky <sss123next@list.ru> | 2013-01-24 19:26:22 +0000 |
---|---|---|
committer | Alexander Gluzsky <sss123next@list.ru> | 2013-01-24 19:26:22 +0000 |
commit | 270ca4cfb74b5bbcff9402264bc476b9c79028c1 (patch) | |
tree | 3d286336b8125d4f415aa42bcc1a327a4ab84057 | |
parent | 30144e31da8cae86a7d3ab070f34b9f9ef79c2e5 (diff) |
some memory allocation bugs fixed
enhanced key export/import
git-svn-id: http://svn.miranda-ng.org/main/trunk@3267 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rwxr-xr-x | plugins/New_GPG/res/new_gpg.rc | 30 | ||||
-rwxr-xr-x | plugins/New_GPG/src/init.cpp | 4 | ||||
-rwxr-xr-x | plugins/New_GPG/src/options.cpp | 18 | ||||
-rwxr-xr-x | plugins/New_GPG/src/resource.h | 9 | ||||
-rwxr-xr-x | plugins/New_GPG/src/utilities.cpp | 428 |
5 files changed, 345 insertions, 144 deletions
diff --git a/plugins/New_GPG/res/new_gpg.rc b/plugins/New_GPG/res/new_gpg.rc index b86a849cb3..e93473f664 100755 --- a/plugins/New_GPG/res/new_gpg.rc +++ b/plugins/New_GPG/res/new_gpg.rc @@ -1,6 +1,6 @@ // Microsoft Visual C++ generated resource script.
//
-#include "..\src\resource.h"
+#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
@@ -183,6 +183,20 @@ BEGIN CONTROL "Remember choice",IDC_REMEMBER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,22,157,10
END
+IDD_EXPORT_TYPE DIALOGEX 0, 0, 281, 90
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
+CAPTION "Choose which keys to export"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ GROUPBOX "Статический",IDC_STATIC,7,7,267,63
+ PUSHBUTTON "Ok",IDC_OK,7,71,50,14
+ PUSHBUTTON "Cancel",IDC_CANCEL,224,71,50,14
+ CONTROL "Export public keys (only set for contacts)",IDC_PUBLIC,
+ "Button",BS_AUTORADIOBUTTON,15,23,248,10
+ CONTROL "Export all private keys",IDC_PRIVATE,"Button",BS_AUTORADIOBUTTON,15,36,246,10
+ CONTROL "Export public and private keys",IDC_ALL,"Button",BS_AUTORADIOBUTTON,15,50,248,10
+END
+
/////////////////////////////////////////////////////////////////////////////
//
@@ -266,6 +280,15 @@ BEGIN TOPMARGIN, 7
BOTTOMMARGIN, 56
END
+
+ IDD_EXPORT_TYPE, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 274
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 85
+ HORZGUIDE, 70
+ END
END
#endif // APSTUDIO_INVOKED
@@ -385,12 +408,14 @@ BEGIN "Button",BS_AUTOCHECKBOX | WS_TABSTOP,3,76,233,10
END
-IDD_OPT_GPG_ADVANCED DIALOGEX 0, 0, 286, 32
+IDD_OPT_GPG_ADVANCED DIALOGEX 0, 0, 286, 50
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
CONTROL "Turn on presence signing (Jabber) (required by xep 0-27)",IDC_PRESCENSE_SUBSCRIPTION,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,9,268,10
+ PUSHBUTTON "Export keys",IDC_EXPORT,12,26,60,14
+ PUSHBUTTON "Import keys",IDC_IMPORT,82,26,68,14
END
@@ -417,6 +442,7 @@ BEGIN IDD_OPT_GPG_ADVANCED, DIALOG
BEGIN
VERTGUIDE, 12
+ BOTTOMMARGIN, 40
END
END
#endif // APSTUDIO_INVOKED
diff --git a/plugins/New_GPG/src/init.cpp b/plugins/New_GPG/src/init.cpp index 1caaa9c0e1..2abe389d1e 100755 --- a/plugins/New_GPG/src/init.cpp +++ b/plugins/New_GPG/src/init.cpp @@ -230,7 +230,7 @@ extern "C" int __declspec(dllexport) Load() mi.position=-0x7FFFFFFF;
mi.flags=CMIF_TCHAR;
mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
- mi.ptszName=LPGENT("Export GPG Public keys from all users");
+ mi.ptszName=LPGENT("Export GPG Public keys");
mi.pszService="/ExportGPGKeys";
hExportGpgKeys = Menu_AddMainMenuItem(&mi);
@@ -239,7 +239,7 @@ extern "C" int __declspec(dllexport) Load() mi.position=-0x7FFFFFFF;
mi.flags=CMIF_TCHAR;
mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
- mi.ptszName=LPGENT("Import GPG Public keys from all users");
+ mi.ptszName=LPGENT("Import GPG Public keys");
mi.pszService="/ImportGPGKeys";
hImportGpgKeys = Menu_AddMainMenuItem(&mi);
diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp index 6b26457864..feea41b67a 100755 --- a/plugins/New_GPG/src/options.cpp +++ b/plugins/New_GPG/src/options.cpp @@ -720,6 +720,24 @@ static INT_PTR CALLBACK DlgProcGpgAdvOpts(HWND hwndDlg, UINT msg, WPARAM wParam, case WM_COMMAND: { + switch (LOWORD(wParam)) + { + case IDC_EXPORT: + { + INT_PTR ExportGpGKeys(WPARAM w, LPARAM l); + ExportGpGKeys(NULL, NULL); + } + break; + case IDC_IMPORT: + { + INT_PTR ImportGpGKeys(WPARAM w, LPARAM l); + ImportGpGKeys(NULL, NULL); + } + break; + default: + break; + } + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } diff --git a/plugins/New_GPG/src/resource.h b/plugins/New_GPG/src/resource.h index 1135dbd3ea..7ffd83c47b 100755 --- a/plugins/New_GPG/src/resource.h +++ b/plugins/New_GPG/src/resource.h @@ -17,6 +17,7 @@ #define IDI_UNSECURED 113
#define IDD_OPT_GPG_ADVANCED 113
#define IDD_ENCRYPTED_FILE_MSG_BOX 114
+#define IDD_EXPORT_TYPE 115
#define IDC_SET_BIN_PATH 1016
#define IDC_SET_HOME_DIR 1017
#define IDC_BIN_PATH 1018
@@ -40,6 +41,8 @@ #define IDC_SELECT_EXISTING 1026
#define IDC_KEY_EMAIL 1026
#define IDC_IGNORE 1026
+#define IDC_OK 1026
+#define IDC_EXPORT 1026
#define IDC_DELETE_KEY_BUTTON 1027
#define IDC_IN_CLOSE_TAG 1027
#define IDC_KEY_REAL_NAME 1027
@@ -61,6 +64,7 @@ #define IDC_LOG_FILE_SET 1046
#define IDC_IMPORT 1046
#define IDC_DECRYPT 1046
+#define IDC_CANCEL 1046
#define IDC_SAVE_PASSWORD 1047
#define IDC_DEBUG_LOG 1048
#define IDC_JABBER_API 1049
@@ -88,6 +92,9 @@ #define IDC_KEY_ID 1071
#define IDC_COMBO1 1072
#define IDC_ACCOUNT 1072
+#define IDC_PUBLIC 1073
+#define IDC_PRIVATE 1074
+#define IDC_ALL 1075
// Next default values for new objects
//
@@ -95,7 +102,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 115
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1073
+#define _APS_NEXT_CONTROL_VALUE 1076
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/plugins/New_GPG/src/utilities.cpp b/plugins/New_GPG/src/utilities.cpp index 129b7cb9cc..6812fe8922 100755 --- a/plugins/New_GPG/src/utilities.cpp +++ b/plugins/New_GPG/src/utilities.cpp @@ -1407,15 +1407,14 @@ bool isTabsrmmUsed() return found;
}
-
-INT_PTR ExportGpGKeys(WPARAM w, LPARAM l)
+void ExportGpGKeysFunc(int type)
{
- TCHAR *p = GetFilePath(_T("Choose file to export public keys"), _T("*"), _T("Any file"), true);
+ TCHAR *p = GetFilePath(_T("Choose file to export keys"), _T("*"), _T("Any file"), true);
if(!p || !p[0])
{
delete [] p;
//TODO: handle error
- return 1;
+ return;
}
char *path = mir_t2a(p);
delete [] p;
@@ -1424,150 +1423,194 @@ INT_PTR ExportGpGKeys(WPARAM w, LPARAM l) mir_free(path);
int exported_keys = 0;
if(!file.is_open())
- return 1; //TODO: handle error
- for(HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ return; //TODO: handle error
+ if(!type || type == 2)
{
- char *k = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", "");
- if(!k[0])
+ for(HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
{
- mir_free(k);
- continue;
- }
- std::string key = k;
- mir_free(k);
-
- const char* proto = (const char*)GetContactProto(hContact);
- std::string id = "Comment: login ";
- const char * uid = (const char*)CallProtoService(proto, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0);
- DBVARIANT dbv = {0};
- DBCONTACTGETSETTING dbcgs = {0};
- dbcgs.pValue = &dbv;
- dbcgs.szModule = proto;
- dbcgs.szSetting = uid;
- CallService(MS_DB_CONTACT_GETSETTING, 0, (LPARAM)&dbcgs);
- switch(dbcgs.pValue->type)
- {
- case DBVT_DELETED:
- continue;
- break;
- case DBVT_BYTE:
- {
- char _id[64];
- mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal);
- id += _id;
- }
- break;
- case DBVT_WORD:
- {
- char _id[64];
- mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal);
- id += _id;
- }
- break;
- case DBVT_DWORD:
+ char *k = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", "");
+ if(!k[0])
{
- char _id[64];
- mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal);
- id += _id;
+ mir_free(k);
+ continue;
}
- break;
- case DBVT_ASCIIZ:
+ std::string key = k;
+ mir_free(k);
+
+ const char* proto = (const char*)GetContactProto(hContact);
+ std::string id = "Comment: login ";
+ const char * uid = (const char*)CallProtoService(proto, PS_GETCAPS, (WPARAM)PFLAG_UNIQUEIDSETTING, 0);
+ DBVARIANT dbv = {0};
+ DBCONTACTGETSETTING dbcgs = {0};
+ dbcgs.pValue = &dbv;
+ dbcgs.szModule = proto;
+ dbcgs.szSetting = uid;
+ CallService(MS_DB_CONTACT_GETSETTING, 0, (LPARAM)&dbcgs);
+ switch(dbcgs.pValue->type)
{
- id += dbcgs.pValue->pszVal;
+ case DBVT_DELETED:
+ continue;
+ break;
+ case DBVT_BYTE:
+ {
+ char _id[64];
+ mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal);
+ id += _id;
+ }
+ break;
+ case DBVT_WORD:
+ {
+ char _id[64];
+ mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal);
+ id += _id;
+ }
+ break;
+ case DBVT_DWORD:
+ {
+ char _id[64];
+ mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal);
+ id += _id;
+ }
+ break;
+ case DBVT_ASCIIZ:
+ {
+ id += dbcgs.pValue->pszVal;
+ CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
+ }
+ break;
+ case DBVT_UTF8:
+ {
+ char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal);
+ if(tmp[0])
+ id += tmp;
+ mir_free(tmp);
+ CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
+ }
+ break;
+ case DBVT_BLOB:
+ //TODO
CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
- }
- break;
- case DBVT_UTF8:
- {
- char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal);
- if(tmp[0])
- id += tmp;
- mir_free(tmp);
+ break;
+ case DBVT_WCHAR:
+ //TODO
CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
+ break;
}
- break;
- case DBVT_BLOB:
- //TODO
- CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
- break;
- case DBVT_WCHAR:
- //TODO
- CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
- break;
- }
- id += " contact_id ";
- ZeroMemory(&dbv, sizeof(dbv));
- ZeroMemory(&dbcgs, sizeof(dbcgs));
- dbcgs.pValue = &dbv;
- dbcgs.szModule = proto;
- dbcgs.szSetting = uid;
- CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs);
- switch(dbcgs.pValue->type)
- {
- case DBVT_DELETED:
- continue;
- break;
- case DBVT_BYTE:
- {
- char _id[64];
- mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal);
- id += _id;
- }
- break;
- case DBVT_WORD:
- {
- char _id[64];
- mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal);
- id += _id;
- }
- break;
- case DBVT_DWORD:
- {
- char _id[64];
- mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal);
- id += _id;
- }
- break;
- case DBVT_ASCIIZ:
+ id += " contact_id ";
+ ZeroMemory(&dbv, sizeof(dbv));
+ ZeroMemory(&dbcgs, sizeof(dbcgs));
+ dbcgs.pValue = &dbv;
+ dbcgs.szModule = proto;
+ dbcgs.szSetting = uid;
+ CallService(MS_DB_CONTACT_GETSETTING, (WPARAM)hContact, (LPARAM)&dbcgs);
+ switch(dbcgs.pValue->type)
{
- id += dbcgs.pValue->pszVal;
+ case DBVT_DELETED:
+ continue;
+ break;
+ case DBVT_BYTE:
+ {
+ char _id[64];
+ mir_snprintf(_id, 63, "%d", dbcgs.pValue->bVal);
+ id += _id;
+ }
+ break;
+ case DBVT_WORD:
+ {
+ char _id[64];
+ mir_snprintf(_id, 63, "%d", dbcgs.pValue->wVal);
+ id += _id;
+ }
+ break;
+ case DBVT_DWORD:
+ {
+ char _id[64];
+ mir_snprintf(_id, 63, "%d", dbcgs.pValue->dVal);
+ id += _id;
+ }
+ break;
+ case DBVT_ASCIIZ:
+ {
+ id += dbcgs.pValue->pszVal;
+ CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
+ }
+ break;
+ case DBVT_UTF8:
+ {
+ char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal);
+ if(tmp[0])
+ id += tmp;
+ mir_free(tmp);
+ CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
+ }
+ break;
+ case DBVT_BLOB:
+ //TODO
CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
- }
- break;
- case DBVT_UTF8:
- {
- char *tmp = mir_utf8decodeA(dbcgs.pValue->pszVal);
- if(tmp[0])
- id += tmp;
- mir_free(tmp);
+ break;
+ case DBVT_WCHAR:
+ //TODO
CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
+ break;
}
- break;
- case DBVT_BLOB:
- //TODO
- CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
- break;
- case DBVT_WCHAR:
- //TODO
- CallService(MS_DB_CONTACT_FREEVARIANT, 0, (LPARAM)&dbv);
- break;
+ std::string::size_type p1 = key.find("-----BEGIN PGP PUBLIC KEY BLOCK-----");
+ if(p1 == std::string::npos)
+ continue;
+ p1 += strlen("-----BEGIN PGP PUBLIC KEY BLOCK-----");
+ p1 ++;
+ id += '\n';
+ key.insert(p1, id);
+ file<<key;
+ file<<std::endl;
+ exported_keys++;
+ }
+ }
+ if(type == 1 || type == 2)
+ {
+ string out;
+ DWORD code;
+ pxResult result;
+ gpg_execution_params params;
+ wstring cmd = _T("--batch --export-secret-keys -a");
+ 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<<std::string(time_str()+": GPG execution timed out, aborted");
+ //break;
+ }
+ else if(result == pxNotFound)
+ ;//break;
+ else
+ {
+ file<<out;
+ file<<std::endl;
}
- std::string::size_type p1 = key.find("-----BEGIN PGP PUBLIC KEY BLOCK-----");
- if(p1 == std::string::npos)
- continue;
- p1 += strlen("-----BEGIN PGP PUBLIC KEY BLOCK-----");
- p1 ++;
- id += '\n';
- key.insert(p1, id);
- file<<key;
- file<<std::endl;
- exported_keys++;
}
if(file.is_open())
file.close();
char msg[512];
- mir_snprintf(msg, 511, "we have succesfully exported %d keys", exported_keys);
+ if(type == 2)
+ mir_snprintf(msg, 511, "%s %d %s %s %s", Translate("we have succesfully exported"), exported_keys, Translate("public keys"), Translate("and"), Translate("all private keys"));
+ else if(type == 1)
+ mir_snprintf(msg, 511, "%s %s", Translate("we have succesfully exported"), Translate("all private keys"));
+ else if(!type)
+ mir_snprintf(msg, 511, "%s %d %s",Translate("we have succesfully exported"), exported_keys, Translate("public keys"));
MessageBoxA(NULL, msg, Translate("Keys export result"), MB_OK);
+}
+
+INT_PTR ExportGpGKeys(WPARAM w, LPARAM l)
+{
+ void ShowExportKeysDlg();
+ ShowExportKeysDlg();
return 0;
}
@@ -1588,11 +1631,11 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) if(!file.is_open())
return 1; //TODO: handle error
PROTOACCOUNT **accs;
- int acc_count = 0, processed_keys = 0;
+ int acc_count = 0, processed_keys = 0, processed_private_keys = 0;
ProtoEnumAccounts(&acc_count, &accs);
char line[256];
file.getline(line, 255);
- if(!strstr(line, "-----BEGIN PGP PUBLIC KEY BLOCK-----"))
+ if(!strstr(line, "-----BEGIN PGP PUBLIC KEY BLOCK-----") && !strstr(line, "-----BEGIN PGP PRIVATE KEY BLOCK-----"))
return 1; //TODO: handle error
std::string key, login, contact_id;
key += line;
@@ -1603,7 +1646,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) key += line;
key += '\n';
if(strstr(line, "-----END PGP PUBLIC KEY BLOCK-----"))
- { //TODO: parse key
+ {
std::string::size_type p1 = 0, p2 = 0;
p1 = key.find("Comment: login ");
p1 += strlen("Comment: login ");
@@ -1817,7 +1860,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) char *tmp2;
string::size_type s = output.find("gpg: key ") + strlen("gpg: key ");
string::size_type s2 = output.find(":", s);
- tmp2 = new char [output.substr(s,s2-s).length()+1];
+ tmp2 = (char*)mir_alloc((output.substr(s,s2-s).length()+1) * sizeof(char));
strcpy(tmp2, output.substr(s,s2-s).c_str());
mir_utf8decode(tmp2, 0);
DBWriteContactSettingString(hContact, szGPGModuleName, "KeyID", tmp2);
@@ -1836,7 +1879,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) s2 = output.find("<", s);
if(s2 != string::npos)
{
- tmp2 = new char [output.substr(s,s2-s-1).length()+1];
+ tmp2 = (char*)mir_alloc((output.substr(s,s2-s-1).length()+1) * sizeof(char));
strcpy(tmp2, output.substr(s,s2-s-1).c_str());
mir_utf8decode(tmp2, 0);
if(hContact)
@@ -1851,7 +1894,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) s2++;
if(output[s] == ')')
{
- tmp2 = new char [output.substr(s2,s-s2).length()+1];
+ tmp2 = (char*)mir_alloc((output.substr(s2,s-s2).length()+1) * sizeof(char));
strcpy(tmp2, output.substr(s2,s-s2).c_str());
mir_utf8decode(tmp2, 0);
if(hContact)
@@ -1859,7 +1902,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) mir_free(tmp2);
s+=3;
s2 = output.find(">", s);
- tmp2 = new char [output.substr(s,s2-s).length()+1];
+ tmp2 = (char*)mir_alloc((output.substr(s,s2-s).length()+1) * sizeof(char));
strcpy(tmp2, output.substr(s,s2-s).c_str());
mir_utf8decode(tmp2, 0);
if(hContact)
@@ -1868,7 +1911,7 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) }
else
{
- tmp2 = new char [output.substr(s2,s-s2).length()+1];
+ tmp2 = (char*)mir_alloc((output.substr(s2,s-s2).length()+1) * sizeof(char));
strcpy(tmp2, output.substr(s2,s-s2).c_str());
mir_utf8decode(tmp2, 0);
if(hContact)
@@ -1886,11 +1929,59 @@ INT_PTR ImportGpGKeys(WPARAM w, LPARAM l) }
key.clear();
}
+ if(strstr(line, "-----END PGP PRIVATE KEY BLOCK-----"))
+ {
+ wstring cmd;
+ TCHAR tmp2[MAX_PATH] = {0};
+ TCHAR *ptmp;
+ string output;
+ DWORD exitcode;
+ {
+ ptmp = UniGetContactSettingUtf(NULL, szGPGModuleName, "szHomePath", _T(""));
+ _tcscpy(tmp2, ptmp);
+ mir_free(ptmp);
+ _tcscat(tmp2, _T("\\"));
+ _tcscat(tmp2, _T("temporary_exported.asc"));
+ DeleteFile(tmp2);
+ wfstream f(tmp2, std::ios::out);
+ f<<toUTF16(key).c_str();
+ f.close();
+ cmd += _T(" --batch ");
+ cmd += _T(" --import \"");
+ cmd += tmp2;
+ cmd += _T("\"");
+ }
+ gpg_execution_params params;
+ 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");
+ break;
+ }
+ if(result == pxNotFound)
+ break;
+ if(result == pxSuccess)
+ processed_private_keys++;
+ key.clear();
+ }
}
if(file.is_open())
file.close();
char msg[512];
- mir_snprintf(msg, 511, "we have succesfully processed %d keys", processed_keys);
+ if(processed_private_keys)
+ mir_snprintf(msg, 511, "we have succesfully processed %d public keys and some private keys", processed_keys);
+ else
+ mir_snprintf(msg, 511, "we have succesfully processed %d public keys", processed_keys);
MessageBoxA(NULL, msg, Translate("Keys import result"), MB_OK);
return 0;
}
@@ -1987,8 +2078,67 @@ static INT_PTR CALLBACK DlgProcEncryptedFileMsgBox(HWND hwndDlg, UINT msg, WPARA return FALSE;
}
+
void ShowEncryptedFileMsgBox()
{
extern HINSTANCE hInst;
DialogBox(hInst, MAKEINTRESOURCE(IDD_ENCRYPTED_FILE_MSG_BOX), NULL, DlgProcEncryptedFileMsgBox);
}
+
+
+static INT_PTR CALLBACK DlgProcExportKeys(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ {
+ TranslateDialogDefault(hwndDlg);
+ return TRUE;
+ }
+
+
+ case WM_COMMAND:
+ {
+ switch (LOWORD(wParam))
+ {
+ case IDC_OK:
+ if(IsDlgButtonChecked(hwndDlg, IDC_PUBLIC))
+ ExportGpGKeysFunc(0);
+ else if(IsDlgButtonChecked(hwndDlg, IDC_PRIVATE))
+ ExportGpGKeysFunc(1);
+ else if(IsDlgButtonChecked(hwndDlg, IDC_ALL))
+ ExportGpGKeysFunc(2);
+ DestroyWindow(hwndDlg);
+ break;
+
+ case IDC_CANCEL:
+ DestroyWindow(hwndDlg);
+ break;
+
+ default:
+ break;
+ }
+
+ break;
+ }
+
+ case WM_NOTIFY:
+ {
+ }
+ break;
+ case WM_CLOSE:
+ DestroyWindow(hwndDlg);
+ break;
+ case WM_DESTROY:
+ {
+ }
+ break;
+ }
+ return FALSE;
+}
+
+void ShowExportKeysDlg()
+{
+ extern HINSTANCE hInst;
+ DialogBox(hInst, MAKEINTRESOURCE(IDD_EXPORT_TYPE), NULL, DlgProcExportKeys);
+}
|