35 |
#include "wptTypes.h" |
#include "wptTypes.h" |
36 |
#include "wptVersion.h" |
#include "wptVersion.h" |
37 |
#include "wptErrors.h" |
#include "wptErrors.h" |
38 |
|
#include "wptKeyEdit.h" |
39 |
|
|
40 |
static subclass_s siglist_proc; |
static subclass_s siglist_proc; |
41 |
|
|
42 |
|
|
43 |
static int inline |
static int |
44 |
is_sig (listview_ctrl_t lv, int pos) |
is_sig (listview_ctrl_t lv, int pos) |
45 |
{ |
{ |
46 |
char tmpbuf[256]; |
char tmpbuf[256]; |
47 |
|
|
48 |
if (pos == -1) |
if (pos == -1) |
49 |
pos = listview_get_curr_pos (lv); |
pos = listview_get_curr_pos (lv); |
50 |
|
if (pos == -1) |
51 |
|
return 0; |
52 |
listview_get_item_text (lv, pos, 0, tmpbuf, 200); |
listview_get_item_text (lv, pos, 0, tmpbuf, 200); |
53 |
if (*tmpbuf == ' ') |
if (*tmpbuf == ' ') |
54 |
return -1; |
return -1; |
56 |
} |
} |
57 |
|
|
58 |
|
|
59 |
|
/* Delete the selected signature from list view @lv. The |
60 |
|
key is given in @key. */ |
61 |
static int |
static int |
62 |
do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key) |
do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key) |
63 |
{ |
{ |
64 |
int pos, npos, id; |
int pos, npos, id; |
65 |
int signo=0, uidno=0; |
int signo=0, uidno=0; |
66 |
gpgme_ctx_t ctx; |
GpgKeyEdit *ke; |
67 |
gpgme_editkey_t ek; |
gpgme_error_t err; |
|
gpgme_error_t rc; |
|
68 |
|
|
69 |
npos = pos = listview_get_curr_pos (lv); |
npos = pos = listview_get_curr_pos (lv); |
70 |
if (!is_sig (lv, -1)) |
if (!is_sig (lv, -1)) |
71 |
return -1; |
return -1; |
72 |
while (pos > 0 && is_sig (lv, pos)) |
while (pos > 0 && is_sig (lv, pos)) { |
|
{ |
|
73 |
signo++; |
signo++; |
74 |
pos--; |
pos--; |
75 |
} |
} |
76 |
pos = npos; |
pos = npos; |
77 |
while (npos > 0) |
while (npos > 0) { |
|
{ |
|
78 |
if (!is_sig (lv, npos)) |
if (!is_sig (lv, npos)) |
79 |
uidno++; |
uidno++; |
80 |
npos--; |
npos--; |
81 |
} |
} |
82 |
uidno++; |
uidno++; |
83 |
id = log_box(_("Key Manager"), MB_YESNO, |
|
84 |
|
/* XXX: do not allow to delete the self signature */ |
85 |
|
id = log_box (_("Key Manager"), MB_YESNO, |
86 |
_("Are you really sure you want to delete this signature from\n" |
_("Are you really sure you want to delete this signature from\n" |
87 |
" \"%s\""), key->uid); |
" \"%s\""), key->uid); |
88 |
if (id == IDNO) |
if (id == IDNO) |
89 |
return 0; |
return 0; |
90 |
rc = gpgme_new (&ctx); |
|
91 |
if (rc) |
ke = new GpgKeyEdit (key->keyid); |
92 |
BUG (0); |
if (!ke) |
93 |
rc = gpgme_editkey_new (&ek); |
BUG (NULL); |
94 |
if (rc) |
err = ke->delUseridSignature (uidno, signo); |
95 |
BUG (0); |
if (err) |
96 |
gpgme_editkey_delsig_set (ek, uidno, signo); |
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR); |
|
gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_DELSIG); |
|
|
rc = gpgme_op_editkey (ctx, key->keyid); |
|
|
if (rc) |
|
|
msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR); |
|
97 |
else |
else |
98 |
listview_del_item (lv, pos); |
listview_del_item (lv, pos); |
99 |
gpgme_release (ctx); |
delete ke; |
100 |
gpgme_editkey_release (ek); |
key->update = 1; /*update*/ |
101 |
return 0; |
return err? -1 : 0; |
102 |
} |
} |
103 |
|
|
104 |
|
|
105 |
|
/* Dialog box procedure to display the signature properties. */ |
106 |
static BOOL CALLBACK |
static BOOL CALLBACK |
107 |
sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
108 |
{ |
{ |
117 |
const char * alg; |
const char * alg; |
118 |
int _class; |
int _class; |
119 |
} ctx; |
} ctx; |
120 |
const char * fmt_templ = "%s %s signature"; |
const char *fmt_templ = _("%s %s signature"); |
121 |
|
|
122 |
switch (msg) |
switch (msg) { |
|
{ |
|
123 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
124 |
if (LOWORD (wparam) == SC_CLOSE) |
if (LOWORD (wparam) == SC_CLOSE) |
125 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
146 |
ctx.alg = "RSA"; |
ctx.alg = "RSA"; |
147 |
else |
else |
148 |
ctx.alg = "ELG"; |
ctx.alg = "ELG"; |
149 |
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ, |
_snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ, |
150 |
ctx.exportable? "Exportable" : "Non-exportable", ctx.alg); |
ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg); |
151 |
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf); |
SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf); |
152 |
listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1); |
listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1); |
153 |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf); |
SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf); |
188 |
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably")); |
189 |
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked")); |
190 |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired")); |
191 |
|
SetWindowText (dlg, _("Signature Properties")); |
192 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
193 |
center_window (dlg); |
center_window (dlg, NULL); |
194 |
return TRUE; |
return TRUE; |
195 |
|
|
196 |
case WM_COMMAND: |
case WM_COMMAND: |
211 |
listview_ctrl_t lv; |
listview_ctrl_t lv; |
212 |
winpt_key_t key; |
winpt_key_t key; |
213 |
|
|
214 |
switch (msg) |
switch (msg) { |
|
{ |
|
215 |
case WM_KEYUP: |
case WM_KEYUP: |
216 |
int virt_key = (int)wparam; |
int virt_key = (int)wparam; |
217 |
key = (winpt_key_t)siglist_proc.opaque; |
key = (winpt_key_t)siglist_proc.opaque; |
218 |
lv = key->callback.ctl; |
lv = key->callback.ctl; |
219 |
if (virt_key == VK_SPACE) |
if (virt_key == VK_SPACE) { |
|
{ |
|
220 |
if (is_sig (lv, -1)) |
if (is_sig (lv, -1)) |
221 |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg, |
222 |
sigprops_dlg_proc, (LPARAM)lv); |
sigprops_dlg_proc, (LPARAM)lv); |
229 |
} |
} |
230 |
|
|
231 |
|
|
232 |
|
/* Return 1 if the list view @lv contains non-available keys. */ |
233 |
static int |
static int |
234 |
check_for_missing_keys (listview_ctrl_t lv) |
check_for_missing_keys (listview_ctrl_t lv) |
235 |
{ |
{ |
238 |
|
|
239 |
n = listview_count_items( lv, 0 ); |
n = listview_count_items( lv, 0 ); |
240 |
for( i = 0; i < n; i++ ) { |
for( i = 0; i < n; i++ ) { |
241 |
listview_get_item_text( lv, i, 1, id, sizeof id - 1 ); |
listview_get_item_text( lv, i, 1, id, sizeof (id) - 1 ); |
242 |
if( !strncmp( id, "NOKEY", 5 ) ) |
if( !strncmp( id, "NOKEY", 5 ) ) |
243 |
return 1; |
return 1; |
244 |
} |
} |
245 |
|
|
246 |
return 0; |
return 0; |
247 |
} /* check_for_missing_keys */ |
} |
248 |
|
|
249 |
|
|
250 |
|
/* Receive all missing keys marked in the list @lv. */ |
251 |
static int |
static int |
252 |
recv_missing_keys (HWND dlg, listview_ctrl_t lv) |
recv_missing_keys (HWND dlg, listview_ctrl_t lv) |
253 |
{ |
{ |
266 |
} |
} |
267 |
|
|
268 |
return rc; |
return rc; |
269 |
} /* recv_missing_keys */ |
} |
270 |
|
|
271 |
|
|
272 |
|
/* Create a mini popup with available choices. */ |
273 |
static void |
static void |
274 |
do_create_popup (HWND dlg) |
do_create_popup (HWND dlg) |
275 |
{ |
{ |
280 |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX)); |
hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX)); |
281 |
sm = GetSubMenu (hm, 0); |
sm = GetSubMenu (hm, 0); |
282 |
|
|
283 |
|
set_menu_text (sm, ID_SIGCTX_PROPS, _("Signature &Properties")); |
284 |
|
set_menu_text (sm, ID_SIGCTX_KEYPROPS, _("Signing &Key Properties")); |
285 |
|
|
286 |
TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
TrackPopupMenu (sm, TPM_RIGHTALIGN, p.x, p.y, 0, dlg, NULL); |
287 |
|
|
288 |
DestroyMenu (hm); |
DestroyMenu (hm); |
290 |
} |
} |
291 |
|
|
292 |
|
|
293 |
|
/* Load the key property dialog with the selected key from @lv. */ |
294 |
static void |
static void |
295 |
do_load_keyprops (HWND dlg, listview_ctrl_t lv) |
do_load_keyprops (HWND dlg, listview_ctrl_t lv) |
296 |
{ |
{ |
321 |
} |
} |
322 |
|
|
323 |
|
|
324 |
|
/* Dialog box procedure to list signatures. */ |
325 |
BOOL CALLBACK |
BOOL CALLBACK |
326 |
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
327 |
{ |
{ |
328 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
329 |
struct winpt_key_s *k; |
static struct winpt_key_s *k; |
330 |
char inf[384], keyid[18+1]; |
char inf[384], keyid[18+1]; |
331 |
int idx = 0, id, rc; |
int idx = 0, id, rc; |
332 |
HWND sl; |
HWND sl; |
336 |
k = (winpt_key_t) lparam; |
k = (winpt_key_t) lparam; |
337 |
if (!k) |
if (!k) |
338 |
BUG (0); |
BUG (0); |
339 |
if( k->uid ) |
if (k->uid) |
340 |
_snprintf( inf, sizeof inf - 1, _("Signature List for \"%s\""), k->uid ); |
_snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid); |
341 |
SetWindowText( dlg, inf ); |
SetWindowText (dlg, inf); |
342 |
#ifndef LANG_DE |
#ifndef LANG_DE |
343 |
SetDlgItemText( dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key") ); |
SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key")); |
344 |
SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties")); |
SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties")); |
345 |
#endif |
#endif |
346 |
lv = siglist_load( GetDlgItem( dlg, IDC_KEYSIG_LIST ), k->keyid ); |
lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid); |
347 |
if( !check_for_missing_keys( lv ) ) |
if (!check_for_missing_keys (lv)) |
348 |
EnableWindow( GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE ); |
EnableWindow (GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE); |
349 |
k->callback.ctl = lv; |
k->callback.ctl = lv; |
350 |
sl = GetDlgItem (dlg, IDC_KEYSIG_LIST); |
sl = GetDlgItem (dlg, IDC_KEYSIG_LIST); |
351 |
siglist_proc.dlg = dlg; |
siglist_proc.dlg = dlg; |
352 |
siglist_proc.opaque = k; |
siglist_proc.opaque = k; |
353 |
siglist_proc.current = (WNDPROC)subclass_dlg_proc; |
siglist_proc.current = (WNDPROC)subclass_dlg_proc; |
354 |
siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC); |
siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC); |
355 |
if (siglist_proc.old) |
if (siglist_proc.old) { |
356 |
{ |
if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) { |
357 |
if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) |
msg_box (dlg, _("Could not set keylist window procedure."), |
358 |
{ |
_("Key Manager"), MB_ERR); |
|
msg_box (dlg, _("Could not set keylist window procedure."), _("Key Manager"), MB_ERR); |
|
359 |
BUG (0); |
BUG (0); |
360 |
} |
} |
361 |
} |
} |
362 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
363 |
center_window (dlg); |
center_window (dlg, NULL); |
364 |
return TRUE; |
return TRUE; |
365 |
|
|
366 |
case WM_DESTROY: |
case WM_DESTROY: |
371 |
return FALSE; |
return FALSE; |
372 |
|
|
373 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
374 |
if( LOWORD ( wparam ) == SC_CLOSE ) |
if (LOWORD (wparam) == SC_CLOSE) { |
375 |
EndDialog( dlg, TRUE ); |
if (k->update) |
376 |
|
keycache_update (0, k->keyid); |
377 |
|
EndDialog (dlg, TRUE); |
378 |
|
} |
379 |
return FALSE; |
return FALSE; |
380 |
|
|
381 |
case WM_NOTIFY: |
case WM_NOTIFY: |
404 |
break; |
break; |
405 |
|
|
406 |
case IDC_KEYSIG_RECVKEY: |
case IDC_KEYSIG_RECVKEY: |
407 |
idx = listview_get_curr_pos( lv ); |
idx = listview_get_curr_pos (lv); |
408 |
if( idx == -1 ) { |
if (idx == -1) { |
409 |
id = msg_box( dlg, _("Really receive all missing keys?"), |
id = msg_box( dlg, _("Really receive all missing keys?"), |
410 |
_("Key Manager"), MB_YESNO|MB_INFO ); |
_("Key Manager"), MB_YESNO|MB_INFO ); |
411 |
if( id == IDYES ) { |
if (id == IDYES) { |
412 |
rc = recv_missing_keys( dlg, lv ); |
rc = recv_missing_keys (dlg, lv); |
413 |
if( !rc ) |
if( !rc ) |
414 |
keycache_set_reload( 1 ); |
keycache_set_reload (1); |
415 |
return TRUE; |
return TRUE; |
416 |
} |
} |
417 |
return FALSE; |
return TRUE; |
418 |
} |
} |
419 |
listview_get_item_text (lv, idx, 4, keyid, sizeof keyid - 1); |
listview_get_item_text (lv, idx, 1, inf, DIM (inf)-1); |
420 |
|
if (strcmp (inf, "NOKEY")) |
421 |
|
return FALSE; |
422 |
|
listview_get_item_text (lv, idx, 4, keyid, DIM (keyid)-1); |
423 |
rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0); |
rc = hkp_recv_key (dlg, default_keyserver, default_keyserver_port, keyid, 0, 0); |
424 |
if (!rc) |
if (!rc) |
425 |
keycache_set_reload (1); |
keycache_set_reload (1); |
432 |
return TRUE; |
return TRUE; |
433 |
|
|
434 |
case IDOK: |
case IDOK: |
435 |
|
if (k->update) |
436 |
|
keycache_update (0, k->keyid); |
437 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
438 |
return TRUE; |
return TRUE; |
439 |
} |
} |
440 |
break; |
break; |
441 |
} |
} |
442 |
return FALSE; |
return FALSE; |
443 |
} /* keysig_dlg_proc */ |
} |