1 |
/* wptClipImportDlg.cpp - WinPT key import dialog |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
5 |
* This file is part of WinPT. |
6 |
* |
7 |
* WinPT is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* WinPT is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
*/ |
21 |
#ifdef HAVE_CONFIG_H |
22 |
#include <config.h> |
23 |
#endif |
24 |
|
25 |
#include <windows.h> |
26 |
|
27 |
#include "resource.h" |
28 |
#include "wptCrypto.h" |
29 |
#include "wptGPG.h" |
30 |
#include "wptCommonCtl.h" |
31 |
#include "wptKeylist.h" |
32 |
#include "wptNLS.h" |
33 |
#include "wptErrors.h" |
34 |
#include "wptTypes.h" |
35 |
#include "wptContext.h" /* for passphrase_s */ |
36 |
#include "wptDlgs.h" |
37 |
#include "wptW32API.h" |
38 |
#include "wptVersion.h" |
39 |
#include "wptImport.h" |
40 |
#include "wptKeyManager.h" |
41 |
|
42 |
|
43 |
/* Import the PGP key data from the clipboard. |
44 |
Return value: 0 on success. */ |
45 |
gpgme_error_t |
46 |
gpgme_op_clip_import (gpgme_ctx_t ctx) |
47 |
{ |
48 |
gpgme_error_t err = 0; |
49 |
gpgme_data_t keydata = NULL; |
50 |
|
51 |
err = gpg_data_new_from_clipboard (&keydata, 0); |
52 |
if (!err) |
53 |
err = gpgme_op_import (ctx, keydata); |
54 |
|
55 |
gpgme_data_release (keydata); |
56 |
return err; |
57 |
} |
58 |
|
59 |
|
60 |
/* Load the import statistics dialog with the results from @res. */ |
61 |
int |
62 |
print_import_status (gpgme_import_result_t res) |
63 |
{ |
64 |
gpgme_import_status_t st; |
65 |
const char *keyid; |
66 |
int new_keys = res->considered - res->unchanged; |
67 |
|
68 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT_STAT, glob_hwnd, |
69 |
import_status_dlg_proc, (LPARAM)res, |
70 |
_("Key Import Statistics"), IDS_WINPT_IMPORT_STAT); |
71 |
if (new_keys > 0 && new_keys < KM_PRELOAD_KEYS) { |
72 |
for (st=res->imports; st; st=st->next) { |
73 |
if (st->status == 0) /* nothing changed */ |
74 |
continue; |
75 |
keyid = st->fpr; |
76 |
keyid += (strlen (st->fpr) == 32)? 24 : 32; |
77 |
keycache_update (0, keyid); |
78 |
} |
79 |
} |
80 |
return !(res->unchanged == res->considered); |
81 |
} |
82 |
|
83 |
|
84 |
/* Dialog procedure for importing key clipboard data. */ |
85 |
BOOL CALLBACK |
86 |
clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
87 |
{ |
88 |
static listview_ctrl_t lv = NULL; |
89 |
static int is_revcert; |
90 |
static int has_seckeys; |
91 |
int rc = 0, upd = 0; |
92 |
gpgme_error_t err; |
93 |
gpgme_ctx_t ctx; |
94 |
gpgme_import_result_t res; |
95 |
|
96 |
switch (msg) { |
97 |
case WM_INITDIALOG: |
98 |
SetWindowText (dlg, _("Key Import")); |
99 |
SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import")); |
100 |
|
101 |
rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST)); |
102 |
if (rc) |
103 |
BUG (NULL); |
104 |
SetForegroundWindow (dlg); |
105 |
center_window (dlg, NULL); |
106 |
rc = implist_load (lv, NULL, &is_revcert, &has_seckeys); |
107 |
return TRUE; |
108 |
|
109 |
case WM_DESTROY: |
110 |
if( lv ) { |
111 |
implist_delete(lv); |
112 |
lv = NULL; |
113 |
} |
114 |
return FALSE; |
115 |
|
116 |
case WM_SYSCOMMAND: |
117 |
if (LOWORD (wparam) == SC_CLOSE) |
118 |
EndDialog (dlg, FALSE); |
119 |
return FALSE; |
120 |
|
121 |
case WM_COMMAND: |
122 |
switch (LOWORD(wparam)) { |
123 |
case IDCANCEL: |
124 |
EndDialog (dlg, FALSE); |
125 |
return TRUE; |
126 |
|
127 |
case IDC_IMPORT_DOIT: |
128 |
if (has_seckeys > 0) { |
129 |
msg_box (dlg, _("Some of the imported keys are secret keys.\n\n" |
130 |
"The ownertrust values of these keys must be\n" |
131 |
"set manually via the Key Properties dialog."), |
132 |
_("Import"), MB_INFO); |
133 |
} |
134 |
SetForegroundWindow (dlg); |
135 |
center_window (dlg, NULL); |
136 |
|
137 |
err = gpgme_new (&ctx); |
138 |
if (err) |
139 |
BUG (NULL); |
140 |
err = gpgme_op_clip_import (ctx); |
141 |
if (err) { |
142 |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
143 |
gpgme_release (ctx); |
144 |
return FALSE; |
145 |
} |
146 |
res = gpgme_op_import_result (ctx); |
147 |
print_import_status (res); |
148 |
upd = res->considered - res->unchanged; |
149 |
if (res->no_user_id > 0) { |
150 |
msg_box (dlg, _("Key without a self signature was dectected!\n" |
151 |
"(This key is NOT usable for encryption, etc)\n" |
152 |
"\n" |
153 |
"Cannot import these key(s)."), _("Import"), MB_INFO); |
154 |
} |
155 |
gpgme_release (ctx); |
156 |
EndDialog (dlg, upd); |
157 |
return TRUE; |
158 |
} |
159 |
break; |
160 |
} |
161 |
|
162 |
return FALSE; |
163 |
} |