/[winpt]/trunk/Src/wptKeysigDlg.cpp
ViewVC logotype

Contents of /trunk/Src/wptKeysigDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations)
Wed Oct 26 11:20:09 2005 UTC (19 years, 4 months ago) by twoaday
File size: 12639 byte(s)
2005-10-25  Timo Schulz  <twoaday@g10code.com>
                                                                                
        * wptGPGUtil.cpp (create_process): Hide window.
        * wptKeyPropsDlg.cpp (get_photo_tmpname): New.
        * wptClipSignEncDlg.cpp (clip_signenc_dlg_proc): Remove
        static var 'enable'.
        * wptKeygenDlg.cpp (keygen_dlg_proc): Likewise.
        (gpg_genkey_params): Make sure all primary keys are capable
        for signing and certification.
        * wptKeySigDlg.cpp (is_sig): If no item is selected, return 0.
        * wptGPG.cpp (gnupg_access_keyring): Check return value for
        NULL. Noted by Ralf.
        (get_gnupg_prog): Simplified.
        (check_homedir): Fixed. Return 0 when the dir is successfully created.
        * wptKeyManagerDlg.cpp (km_file_import): Use the hourglass to
        indicate a pending GPG process.
        * wptFileManager.cpp (op_begin, op_end): New. Indicate an start
        and and of an operation. For now just the cursor changes.
        (fm_parse_command_line): Remove debug output. Thanks to Ralf again.
        * WinPT.cpp (WinMain): Check if there is already an instance and
        set a variable early as possible.
        (load_gettext): If a previous instance was found, do not output
        any errors. Kudos to Ralf.


1 /* wptKeysigDlg.cpp - Key signature listing
2 * Copyright (C) 2001-2005 Timo Schulz
3 *
4 * This file is part of WinPT.
5 *
6 * WinPT is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * WinPT is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with WinPT; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 */
20
21 #include <windows.h>
22 #include <commctrl.h>
23 #include <time.h>
24
25 #include "../resource.h"
26 #include "wptGPG.h"
27 #include "wptCommonCtl.h"
28 #include "wptContext.h" /* for passphrase_s */
29 #include "wptDlgs.h"
30 #include "wptW32API.h"
31 #include "wptNLS.h"
32 #include "wptKeyList.h"
33 #include "wptKeyserver.h"
34 #include "wptUTF8.h"
35 #include "wptTypes.h"
36 #include "wptVersion.h"
37 #include "wptErrors.h"
38 #include "wptKeyEdit.h"
39
40 static subclass_s siglist_proc;
41
42
43 static int
44 is_sig (listview_ctrl_t lv, int pos)
45 {
46 char tmpbuf[256];
47
48 if (pos == -1)
49 pos = listview_get_curr_pos (lv);
50 if (pos == -1)
51 return 0;
52 listview_get_item_text (lv, pos, 0, tmpbuf, 200);
53 if (*tmpbuf == ' ')
54 return -1;
55 return 0;
56 }
57
58
59 /* Delete the selected signature from list view @lv. The
60 key is given in @key. */
61 static int
62 do_delsig (HWND dlg, listview_ctrl_t lv, winpt_key_t key)
63 {
64 int pos, npos, id;
65 int signo=0, uidno=0;
66 GpgKeyEdit *ke;
67 gpgme_error_t err;
68
69 npos = pos = listview_get_curr_pos (lv);
70 if (!is_sig (lv, -1))
71 return -1;
72 while (pos > 0 && is_sig (lv, pos)) {
73 signo++;
74 pos--;
75 }
76 pos = npos;
77 while (npos > 0) {
78 if (!is_sig (lv, npos))
79 uidno++;
80 npos--;
81 }
82 uidno++;
83
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"
87 " \"%s\""), key->uid);
88 if (id == IDNO)
89 return 0;
90
91 ke = new GpgKeyEdit (key->keyid);
92 if (!ke)
93 BUG (NULL);
94 err = ke->delUseridSignature (uidno, signo);
95 if (err)
96 msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR);
97 else
98 listview_del_item (lv, pos);
99 delete ke;
100 key->update = 1; /*update*/
101 return err? -1 : 0;
102 }
103
104
105 /* Dialog box procedure to display the signature properties. */
106 static BOOL CALLBACK
107 sigprops_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
108 {
109 static listview_ctrl_t lv;
110 char tmpbuf[256];
111 int n;
112 struct {
113 unsigned int exportable:1;
114 unsigned int expired:1;
115 unsigned int nrev:1;
116 unsigned int rev:1;
117 const char * alg;
118 int _class;
119 } ctx;
120 const char *fmt_templ = _("%s %s signature");
121
122 switch (msg) {
123 case WM_SYSCOMMAND:
124 if (LOWORD (wparam) == SC_CLOSE)
125 EndDialog (dlg, TRUE);
126 return FALSE;
127
128 case WM_INITDIALOG:
129 lv = (listview_ctrl_t)lparam;
130 if (!lv)
131 dlg_fatal_error (dlg, "could not get dialog param");
132 memset (&ctx, 0, sizeof ctx);
133 n = listview_get_curr_pos (lv);
134 listview_get_item_text (lv, n, 2, tmpbuf, DIM (tmpbuf)-1);
135 if (!strstr (tmpbuf, "L"))
136 ctx.exportable = 1;
137 ctx._class = atoi (tmpbuf);
138 if (ctx._class == 0)
139 ctx._class = 10;
140 else if (ctx._class < 10)
141 ctx._class += 10;
142 listview_get_item_text (lv, n, 6, tmpbuf, DIM (tmpbuf)-1);
143 if (strstr (tmpbuf, "DSA"))
144 ctx.alg = "DSA";
145 else if (strstr (tmpbuf, "RSA"))
146 ctx.alg = "RSA";
147 else
148 ctx.alg = "ELG";
149 _snprintf (tmpbuf, DIM (tmpbuf)-1, fmt_templ,
150 ctx.exportable? _("Exportable") : _("Non-exportable"), ctx.alg);
151 SetDlgItemText (dlg, IDC_SIGPROPS_INFO, tmpbuf);
152 listview_get_item_text (lv, n, 4, tmpbuf, DIM (tmpbuf)-1);
153 SetDlgItemText (dlg, IDC_SIGPROPS_KEYID, tmpbuf);
154 SetDlgItemInt (dlg, IDC_SIGPROPS_CLASS, ctx._class, FALSE);
155 if (ctx.exportable)
156 CheckDlgButton (dlg, IDC_SIGPROPS_EXP, BST_CHECKED);
157 listview_get_item_text (lv, n, 0, tmpbuf, DIM (tmpbuf)-1);
158 SetDlgItemText (dlg, IDC_SIGPROPS_ISSUER, tmpbuf+1);
159 tmpbuf[0] = 0;
160 listview_get_item_text (lv, n, 5, tmpbuf, DIM (tmpbuf)-1);
161 if (strlen (tmpbuf) == 0) {
162 ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPSTR), SW_HIDE);
163 ShowWindow (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE), SW_HIDE);
164 }
165 else {
166 SYSTEMTIME st;
167 struct tm * tm;
168 time_t t = time (NULL);
169
170 memset (&st, 0, sizeof st);
171 st.wYear = atoi (tmpbuf);
172 st.wMonth = atoi (tmpbuf+5);
173 st.wDay = atoi (tmpbuf+8);
174 DateTime_SetSystemtime (GetDlgItem (dlg, IDC_SIGPROPS_EXPDATE),
175 GDT_VALID, &st);
176
177 tm = localtime (&t);
178 tm->tm_mon++;
179 tm->tm_year += 1900;
180 if (tm->tm_year > st.wYear)
181 ctx.expired = 1;
182 else if (tm->tm_mon > st.wMonth)
183 ctx.expired = 1;
184 if (ctx.expired)
185 CheckDlgButton (dlg, IDC_SIGPROPS_EXPIRED, BST_CHECKED);
186 }
187 SetDlgItemText (dlg, IDC_SIGPROPS_EXP, _("Exportable"));
188 SetDlgItemText (dlg, IDC_SIGPROPS_NREV, _("Non-revocably"));
189 SetDlgItemText (dlg, IDC_SIGPROPS_REV, _("Revoked"));
190 SetDlgItemText (dlg, IDC_SIGPROPS_EXPIRED, _("Expired"));
191 SetWindowText (dlg, _("Signature Properties"));
192 SetForegroundWindow (dlg);
193 center_window (dlg, NULL);
194 return TRUE;
195
196 case WM_COMMAND:
197 switch (LOWORD (wparam)) {
198 case IDOK:
199 EndDialog (dlg, TRUE);
200 break;
201 }
202 }
203
204 return FALSE;
205 }
206
207
208 static BOOL CALLBACK
209 subclass_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
210 {
211 listview_ctrl_t lv;
212 winpt_key_t key;
213
214 switch (msg) {
215 case WM_KEYUP:
216 int virt_key = (int)wparam;
217 key = (winpt_key_t)siglist_proc.opaque;
218 lv = key->callback.ctl;
219 if (virt_key == VK_SPACE) {
220 if (is_sig (lv, -1))
221 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
222 sigprops_dlg_proc, (LPARAM)lv);
223 }
224 else if (virt_key == VK_DELETE)
225 do_delsig (dlg, lv, key);
226 break;
227 }
228 return CallWindowProc (siglist_proc.old, dlg, msg, wparam, lparam);
229 }
230
231
232 /* Return 1 if the list view @lv contains non-available keys. */
233 static int
234 check_for_missing_keys (listview_ctrl_t lv)
235 {
236 int i, n;
237 char id[128];
238
239 n = listview_count_items( lv, 0 );
240 for( i = 0; i < n; i++ ) {
241 listview_get_item_text( lv, i, 1, id, sizeof (id) - 1 );
242 if( !strncmp( id, "NOKEY", 5 ) )
243 return 1;
244 }
245
246 return 0;
247 }
248
249
250 /* Receive all missing keys marked in the list @lv. */
251 static int
252 recv_missing_keys (HWND dlg, listview_ctrl_t lv)
253 {
254 int i, n, rc;
255 char id[128], keyid[18+1];
256
257 n = listview_count_items (lv, 0);
258 for( i = 0; i < n; i++ ) {
259 listview_get_item_text( lv, i, 1, id, sizeof id - 1 );
260 if( !strncmp( id, "NOKEY", 5 ) ) {
261 listview_get_item_text( lv, i, 4, keyid, sizeof keyid -1 );
262 rc = hkp_recv_key( dlg, default_keyserver, default_keyserver_port, keyid, 0, 0 );
263 if( rc )
264 break;
265 }
266 }
267
268 return rc;
269 }
270
271
272 /* Create a mini popup with available choices. */
273 static void
274 do_create_popup (HWND dlg)
275 {
276 HMENU hm, sm;
277 POINT p;
278
279 GetCursorPos (&p);
280 hm = LoadMenu (glob_hinst, MAKEINTRESOURCE (IDR_WINPT_KEYSIG_CTX));
281 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);
287
288 DestroyMenu (hm);
289 DestroyMenu (sm);
290 }
291
292
293 /* Load the key property dialog with the selected key from @lv. */
294 static void
295 do_load_keyprops (HWND dlg, listview_ctrl_t lv)
296 {
297 winpt_key_s k;
298 gpgme_key_t key;
299 char keyid[32] = {0};
300 char status[64] = {0}, creation[64] = {0};
301 int n = listview_get_curr_pos (lv);
302
303 listview_get_item_text (lv, n, 1, status, DIM (status)-1);
304 listview_get_item_text (lv, n, 3, creation, DIM (creation)-1);
305 listview_get_item_text (lv, n, 4, keyid, DIM (keyid)-1);
306 if (!strcmp (status, "NOKEY")) {
307 msg_box (dlg, _("Key not found in keyring, please get it from the keyserver first."),
308 _("Key Manager"), MB_INFO);
309 return;
310 }
311
312 if ((strlen (keyid) < 3 ||get_pubkey (keyid, &key))) {
313 if (strlen (creation) > 0)
314 msg_box (dlg, _("Key not found in keyring."), _("Key Manager"), MB_INFO);
315 return;
316 }
317 memset (&k, 0, sizeof k);
318 k.keyid = keyid;
319 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYPROPS, dlg,
320 keyprops_dlg_proc, (LPARAM)&k);
321 }
322
323
324 /* Dialog box procedure to list signatures. */
325 BOOL CALLBACK
326 keysig_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
327 {
328 static listview_ctrl_t lv = NULL;
329 static struct winpt_key_s *k;
330 char inf[384], keyid[18+1];
331 int idx = 0, id, rc;
332 HWND sl;
333
334 switch( msg ) {
335 case WM_INITDIALOG:
336 k = (winpt_key_t) lparam;
337 if (!k)
338 BUG (0);
339 if (k->uid)
340 _snprintf (inf, DIM (inf)-1, _("Signature List for \"%s\""), k->uid);
341 SetWindowText (dlg, inf);
342 #ifndef LANG_DE
343 SetDlgItemText (dlg, IDC_KEYSIG_RECVKEY, _("&Receive Key"));
344 SetDlgItemText (dlg, IDC_KEYSIG_SIGPROPS, _("&Properties"));
345 #endif
346 lv = siglist_load (GetDlgItem (dlg, IDC_KEYSIG_LIST), k->keyid);
347 if (!check_for_missing_keys (lv))
348 EnableWindow (GetDlgItem( dlg, IDC_KEYSIG_RECVKEY ), FALSE);
349 k->callback.ctl = lv;
350 sl = GetDlgItem (dlg, IDC_KEYSIG_LIST);
351 siglist_proc.dlg = dlg;
352 siglist_proc.opaque = k;
353 siglist_proc.current = (WNDPROC)subclass_dlg_proc;
354 siglist_proc.old = (WNDPROC)GetWindowLong (sl, GWL_WNDPROC);
355 if (siglist_proc.old) {
356 if (!SetWindowLong (sl, GWL_WNDPROC, (LONG)siglist_proc.current)) {
357 msg_box (dlg, _("Could not set keylist window procedure."),
358 _("Key Manager"), MB_ERR);
359 BUG (0);
360 }
361 }
362 SetForegroundWindow (dlg);
363 center_window (dlg, NULL);
364 return TRUE;
365
366 case WM_DESTROY:
367 if ( lv ) {
368 siglist_delete( lv );
369 lv = NULL;
370 }
371 return FALSE;
372
373 case WM_SYSCOMMAND:
374 if (LOWORD (wparam) == SC_CLOSE) {
375 if (k->update)
376 keycache_update (0, k->keyid);
377 EndDialog (dlg, TRUE);
378 }
379 return FALSE;
380
381 case WM_NOTIFY:
382 NMHDR * notify;
383
384 notify = (NMHDR *)lparam;
385 if( notify && notify->code == NM_DBLCLK
386 && notify->idFrom == IDC_KEYSIG_LIST )
387 do_load_keyprops (dlg, lv);
388 if (notify && notify->code == NM_RCLICK &&
389 notify->idFrom == IDC_KEYSIG_LIST)
390 do_create_popup (dlg);
391 break;
392
393 case WM_COMMAND:
394 switch ( LOWORD( wparam ) ) {
395
396 case ID_SIGCTX_KEYPROPS:
397 do_load_keyprops (dlg, lv);
398 break;
399
400 case ID_SIGCTX_PROPS:
401 if (is_sig (lv, -1))
402 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
403 sigprops_dlg_proc, (LPARAM)lv);
404 break;
405
406 case IDC_KEYSIG_RECVKEY:
407 idx = listview_get_curr_pos (lv);
408 if (idx == -1) {
409 id = msg_box( dlg, _("Really receive all missing keys?"),
410 _("Key Manager"), MB_YESNO|MB_INFO );
411 if (id == IDYES) {
412 rc = recv_missing_keys (dlg, lv);
413 if( !rc )
414 keycache_set_reload (1);
415 return TRUE;
416 }
417 return TRUE;
418 }
419 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);
424 if (!rc)
425 keycache_set_reload (1);
426 return TRUE;
427
428 case IDC_KEYSIG_SIGPROPS:
429 if (is_sig (lv, -1))
430 DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SIGPROPS, dlg,
431 sigprops_dlg_proc, (LPARAM)lv);
432 return TRUE;
433
434 case IDOK:
435 if (k->update)
436 keycache_update (0, k->keyid);
437 EndDialog (dlg, TRUE);
438 return TRUE;
439 }
440 break;
441 }
442 return FALSE;
443 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26