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 |
|
22 |
#ifdef HAVE_CONFIG_H |
23 |
#include <config.h> |
24 |
#endif |
25 |
|
26 |
#include <windows.h> |
27 |
#include <windows.h> |
28 |
|
29 |
#include "resource.h" |
30 |
#include "wptCrypto.h" |
31 |
#include "wptGPG.h" |
32 |
#include "wptCommonCtl.h" |
33 |
#include "wptKeylist.h" |
34 |
#include "wptNLS.h" |
35 |
#include "wptErrors.h" |
36 |
#include "wptTypes.h" |
37 |
#include "wptContext.h" /* for passphrase_s */ |
38 |
#include "wptDlgs.h" |
39 |
#include "wptW32API.h" |
40 |
#include "wptVersion.h" |
41 |
#include "wptImport.h" |
42 |
|
43 |
|
44 |
/* Import the PGP key data from the clipboard. |
45 |
Return value: 0 on success. */ |
46 |
gpgme_error_t |
47 |
gpgme_op_clip_import (gpgme_ctx_t ctx) |
48 |
{ |
49 |
gpgme_error_t err = 0; |
50 |
gpgme_data_t keydata = NULL; |
51 |
|
52 |
err = gpg_data_new_from_clipboard (&keydata, 0); |
53 |
if (!err) |
54 |
err = gpgme_op_import (ctx, keydata); |
55 |
|
56 |
gpgme_data_release (keydata); |
57 |
return err; |
58 |
} |
59 |
|
60 |
|
61 |
/* Load the import statistics dialog with the results from @res. */ |
62 |
void |
63 |
print_import_status (gpgme_import_result_t res) |
64 |
{ |
65 |
int rc = 0; |
66 |
|
67 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT_STAT, glob_hwnd, |
68 |
import_status_dlg_proc, (LPARAM)res, |
69 |
_("Key Import Statistics"), IDS_WINPT_IMPORT_STAT); |
70 |
if (res->imported || res->secret_imported) |
71 |
keycache_set_reload (1); /* XXX: update flag */ |
72 |
} |
73 |
|
74 |
|
75 |
/* Dialog procedure for importing key clipboard data. */ |
76 |
BOOL CALLBACK |
77 |
clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
78 |
{ |
79 |
static listview_ctrl_t lv = NULL; |
80 |
static int is_revcert; |
81 |
static int has_seckeys; |
82 |
int rc = 0, id = 0; |
83 |
gpgme_error_t err; |
84 |
gpgme_ctx_t ctx; |
85 |
gpgme_import_result_t res; |
86 |
gpgme_key_t *selkeys = NULL; |
87 |
|
88 |
switch( msg ) { |
89 |
case WM_INITDIALOG: |
90 |
SetWindowText (dlg, _("Key Import")); |
91 |
SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import")); |
92 |
|
93 |
rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST)); |
94 |
if (rc) |
95 |
BUG (NULL); |
96 |
SetForegroundWindow (dlg); |
97 |
center_window (dlg, NULL); |
98 |
rc = implist_load (lv, NULL, &is_revcert, &has_seckeys); |
99 |
return TRUE; |
100 |
|
101 |
case WM_DESTROY: |
102 |
if( lv ) { |
103 |
implist_delete(lv); |
104 |
lv = NULL; |
105 |
} |
106 |
return FALSE; |
107 |
|
108 |
case WM_SYSCOMMAND: |
109 |
if( LOWORD (wparam) == SC_CLOSE ) |
110 |
EndDialog( dlg, TRUE ); |
111 |
return FALSE; |
112 |
|
113 |
case WM_COMMAND: |
114 |
switch( LOWORD( wparam ) ) { |
115 |
case IDCANCEL: |
116 |
EndDialog (dlg, TRUE); |
117 |
return TRUE; |
118 |
|
119 |
case IDC_IMPORT_DOIT: |
120 |
if (has_seckeys > 0) { |
121 |
msg_box (dlg, _("Some of the imported keys are secret keys.\n\n" |
122 |
"The ownertrust values of these keys must be\n" |
123 |
"set manually via the Key Properties dialog."), |
124 |
_("Import"), MB_INFO); |
125 |
} |
126 |
SetForegroundWindow (dlg); |
127 |
center_window (dlg, NULL); |
128 |
|
129 |
/* XXX: support interactive and only import some keys. */ |
130 |
/* |
131 |
int n; |
132 |
char keyid[32]; |
133 |
n = listview_count_items (lv, 0); |
134 |
if( n > 1 && listview_count_items( lv, 1 ) > 0 ) { |
135 |
selkeys = calloc (n+1, sizeof (gpgme_key_t)); |
136 |
if (!selkeys) |
137 |
BUG (NULL); |
138 |
for (id = 0; id < n; id++) { |
139 |
if (listview_get_item_state (lv, id)) { |
140 |
listview_get_item_text (lv, id, 2, keyid, DIM (keyid)-1); |
141 |
// XXX: set the keyid?? |
142 |
// ( selkeys, keyid+2 ); |
143 |
} |
144 |
} |
145 |
} |
146 |
*/ |
147 |
|
148 |
err = gpgme_new (&ctx); |
149 |
if (err) |
150 |
BUG (NULL); |
151 |
err = gpgme_op_clip_import (ctx); |
152 |
if (err) { |
153 |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
154 |
gpgme_release (ctx); |
155 |
return FALSE; |
156 |
} |
157 |
res = gpgme_op_import_result (ctx); |
158 |
print_import_status (res); |
159 |
if (res->no_user_id > 0) { |
160 |
msg_box (dlg, _("Key without a self signature was dectected!\n" |
161 |
"(This key is NOT usable for encryption, etc)\n" |
162 |
"\n" |
163 |
"Cannot import these key(s)."), _("Import"), MB_INFO); |
164 |
} |
165 |
gpgme_release (ctx); |
166 |
EndDialog (dlg, TRUE); |
167 |
return TRUE; |
168 |
} |
169 |
break; |
170 |
} |
171 |
|
172 |
return FALSE; |
173 |
} |