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

Contents of /trunk/Src/wptKeyserverDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 218 - (show annotations)
Wed May 24 07:53:24 2006 UTC (18 years, 9 months ago) by twoaday
File size: 21580 byte(s)
2006-05-23  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptKeyEditDlgs.cpp (do_add_new_userid): Fix re-introduced
        problem.
        (keyedit_main_dlg_proc): Popup menu for the user ID list
        with common commands.
        * wptKeyserverDlg.cpp (keyserver_dlg_proc): Automatically
        disable search for ldap servers.
        Use subkeys.pgp.net by default when no server was selected.
                                                                                


1 /* wptKeyserverDlg.cpp - Keyserver dialog
2 * Copyright (C) 2000-2006 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 #include <commctrl.h>
27 #include <malloc.h>
28
29 #include "resource.h"
30 #include "wptKeyserver.h"
31 #include "wptErrors.h"
32 #include "wptTypes.h"
33 #include "wptCommonCtl.h"
34 #include "wptNLS.h"
35 #include "wptW32API.h"
36 #include "wptVersion.h"
37 #include "wptGPG.h"
38 #include "wptGPGME.h"
39 #include "wptContext.h" /* for passphrase_s */
40 #include "wptKeyManager.h"
41 #include "wptDlgs.h"
42 #include "wptUTF8.h"
43
44
45 char* get_reg_entry_keyserver (const char *);
46 int set_reg_entry_keyserver (const char *, const char *);
47
48 enum { KS_COL_NAME = 0, KS_COL_PORT };
49
50 /* Callback context to modify (add, edit) keyserver items. */
51 struct keyserver_rec_s {
52 char name[200]; /* hostname */
53 int proto; /* protocol */
54 int port; /* used port */
55 bool mode; /* true = edit */
56 bool cancel;
57 };
58 typedef struct keyserver_rec_s *keyserver_rec_t;
59
60 /* Print out keyserver error and a possible Winsock error. */
61 static void
62 hkp_err_box (HWND dlg, const char *host, WORD port, int rc)
63 {
64 const char *err = kserver_strerror ();
65 const char *ws_err = wsock_strerror ();
66
67 if (ws_err && strlen (ws_err) > 0)
68 log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", host, port, ws_err);
69 else
70 log_box (_("Keyserver"), MB_ERR, "%s:%d: %s\n%s",
71 host, port, winpt_strerror (rc), err? err : "");
72 }
73
74
75 /* Send the extracted key with keyid @pattern to the
76 keyserver @kserver (port @port).
77 Return value: 0 on success. */
78 int
79 hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern)
80 {
81 GPGME *gpg;
82 gpgme_error_t ec;
83 char *rawkey = NULL;
84 char msg[384];
85
86 gpg = new GPGME ();
87 gpg->setArmor (true);
88 ec = gpg->exportToBuffer (pattern, &rawkey);
89 if (ec) {
90 msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR);
91 goto leave;
92 }
93 op_begin ();
94 ec = kserver_sendkey (kserver, port, rawkey, strlen (rawkey));
95 op_end ();
96 if (ec) {
97 hkp_err_box (dlg, kserver, port, ec);
98 goto leave;
99 }
100
101 _snprintf (msg, sizeof (msg) -1, _("Key '%s' successfully sent"), pattern);
102 status_box (dlg, msg, _("GnuPG status"));
103
104 leave:
105 delete gpg;
106 free_if_alloc (rawkey);
107 return ec? -1 : 0;
108 }
109
110
111
112 /* Show all received keys from the keyserver. */
113 static void
114 show_imported_keys (gpgme_import_result_t res)
115 {
116 gpgme_import_status_t t;
117 gpgme_key_t key;
118 gpgme_data_t msg;
119 gpgme_ctx_t ctx;
120 gpgme_error_t err;
121 const char *s;
122 char *p, *uid;
123 size_t n=0;
124
125 if (!res)
126 return;
127
128 err = gpgme_data_new (&msg);
129 if (err)
130 BUG (NULL);
131 err = gpgme_new (&ctx);
132 if (err)
133 BUG (NULL);
134 if (res->considered > 1) {
135 s = _("WARNING: multiple keys matched request.\n\n");
136 gpgme_data_write (msg, s, strlen (s));
137 }
138
139 if (res->unchanged == res->considered)
140 s = _("Key(s) successfully received but nothing was changed.");
141 else
142 s = _("Key(s) sucessfully received and imported.");
143 gpgme_data_write (msg, s, strlen (s));
144 gpgme_data_write (msg, "\n\n", 2);
145
146 for (t=res->imports; t; t = t->next) {
147 if (!gpgme_get_key (ctx, t->fpr, &key, 0)) {
148 s = uid = utf8_to_native (key->uids->uid);
149 gpgme_data_write (msg, s, strlen (s));
150 gpgme_data_write (msg, "\n", 1);
151 gpgme_key_release (key);
152 free (uid);
153 }
154 }
155 gpgme_data_write (msg, "\0", 1);
156 p = gpgme_data_release_and_get_mem (msg, &n);
157 if (p != NULL) {
158 msg_box (NULL, p, _("Imported Keys"), MB_INFO);
159 gpgme_free (p);
160 }
161 gpgme_release (ctx);
162 }
163
164
165 /* Receive a key from the keyserver @kserver (port @port)
166 with the pattern @pattern.
167 Return value: 0 on success. */
168 static int
169 keyserver_recv_key (HWND dlg, const char *kserver, WORD port,
170 const char *pattern, int proto, int flags,
171 char **r_fpr)
172 {
173 gpgme_ctx_t ctx;
174 gpgme_data_t keydata;
175 gpgme_import_result_t import_res = NULL;
176 gpgme_error_t err;
177 char *rawkey = NULL;
178 int keylen = 0;
179 int rc;
180
181 if (proto == KSPROTO_LDAP) {
182 rc = ldap_recvkey (kserver, pattern, &rawkey, &keylen);
183 if (rc) {
184 msg_box (dlg, _("LDAP key import failed.\n"
185 "Please make sure you have an online connection"
186 " and gpgkeys_ldap.exe is installed"),
187 _("Keyserver"), MB_ERR);
188 free_if_alloc (rawkey);
189 return rc;
190 }
191 }
192 else if (proto == KSPROTO_FINGER) {
193 rc = finger_recvkey (kserver, pattern, &rawkey, &keylen);
194 if (rc) {
195 log_box (_("Keyserver"), MB_ERR,
196 _("Finger key import failed: %s\n"), winpt_strerror (rc));
197 free_if_alloc (rawkey);
198 return rc;
199 }
200 }
201 else if ((rc = kserver_recvkey (kserver, port,
202 kserver_check_keyid (pattern),
203 &rawkey, &keylen))) {
204 hkp_err_box (dlg, kserver, port, rc);
205 free_if_alloc (rawkey);
206 return rc;
207 }
208
209 if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) {
210 msg_box (dlg, _("This is not a valid OpenPGP key."),
211 _("Keyserver"), MB_ERR);
212 goto leave;
213 }
214 if (gpgme_new (&ctx))
215 BUG (NULL);
216 gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1);
217 err = gpgme_op_import (ctx, keydata);
218 if (err) {
219 msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR);
220 goto leave;
221 }
222 import_res = gpgme_op_import_result (ctx);
223 if (import_res && r_fpr)
224 *r_fpr = m_strdup (import_res->imports->fpr);
225
226 /* if we use the refresh mode, a lot of keys will be fetched and thus only
227 a summarize at the end is presented and not for each key. */
228 if (!(flags & KM_KS_REFRESH)) {
229 show_imported_keys (import_res);
230 if (import_res && import_res->unchanged == import_res->considered) {
231 rc = WPTERR_GENERAL; /* no keys updated. */
232 goto leave;
233 }
234 }
235
236 leave:
237 free_if_alloc (rawkey);
238 gpgme_release (ctx);
239 gpgme_data_release (keydata);
240
241 return rc;
242 }
243
244
245 /* Alias for keyserver_recv_key but without the ability to return
246 the fingerprint of the key. */
247 int
248 hkp_recv_key (HWND dlg, const char *kserver, WORD port,
249 const char *pattern, int proto, int flags)
250 {
251 return keyserver_recv_key (dlg, kserver, port, pattern,
252 proto, flags, NULL);
253 }
254
255 int
256 hkp_recv_key2 (HWND dlg, const char *kserver, WORD port,
257 const char *pattern, int proto, char **r_fpr)
258 {
259 return keyserver_recv_key (dlg, kserver, port, pattern, proto, 0,
260 r_fpr);
261 }
262
263
264 #define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F'))
265
266 static int
267 check_pattern (const char *pattern)
268 {
269 int rc = WPTERR_GENERAL;
270
271 /* do not allow white spaces. */
272 if (strchr (pattern, ' '))
273 return rc;
274
275 if (strstr (pattern, "0x"))
276 pattern += 2;
277
278 if (((my_iskeychar (pattern[0])) && (strlen (pattern) == 8)) ||
279 (my_iskeychar (pattern[0])) && (strlen (pattern) == 16))
280 rc = 0; /* assume long or short key ID. */
281 else if (strchr (pattern, '@') && strlen (pattern) >= 3)
282 rc = 0; /* assume email address. */
283
284 return rc;
285 }
286
287
288 /* Return human readable name for the proxy protocol. */
289 static const char*
290 name_from_proto (int proto)
291 {
292 const char *s;
293
294 switch (proto) {
295 case PROXY_PROTO_NONE: s = ""; break;
296 case PROXY_PROTO_HTTP: s = "HTTP"; break;
297 case PROXY_PROTO_SOCKS5: s = "SOCKS5"; break;
298 default: s= "HTTP"; break;
299 }
300 return s;
301 }
302
303
304 static int inline
305 kserver_get_pos (listview_ctrl_t lv)
306 {
307 if (listview_count_items (lv, 0) == 1)
308 return 0;
309 return listview_get_curr_pos (lv);
310 }
311
312
313 static WORD inline
314 kserver_get_port (listview_ctrl_t lv)
315 {
316 char buf[16];
317
318 listview_get_item_text (lv, kserver_get_pos (lv), KS_COL_PORT, buf, 15);
319 return (WORD)strtoul (buf, NULL, 10);
320 }
321
322
323 static void
324 set_default_ks (listview_ctrl_t lv)
325 {
326 char *p, buf[200];
327 int i;
328
329 p = get_reg_entry_keyserver ("Default");
330 if (!p)
331 return;
332 for (i=0; i < listview_count_items (lv, 0); i++) {
333 listview_get_item_text (lv, i, KS_COL_NAME, buf, sizeof (buf)-1);
334 if (!strcmp (buf, p)) {
335 listview_select_one (lv, i);
336 break;
337 }
338 }
339 free_if_alloc (p);
340 }
341
342
343 /* Save the selected keyserver from @lv as the default server. */
344 static int
345 save_default_ks (listview_ctrl_t lv)
346 {
347 char buf[192], port[32];
348 int idx, i;
349
350 idx = listview_get_curr_pos (lv);
351 if (idx == -1) {
352 msg_box (NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR);
353 return -1;
354 }
355 listview_get_item_text (lv, idx, KS_COL_NAME, buf, sizeof (buf)-1);
356 if (strncmp (buf, "http", 4) && strncmp (buf, "hkp", 3)) {
357 msg_box (NULL, _("Only HTTP keyserver can be used."),
358 _("Keyserver"), MB_ERR);
359 return -1;
360 }
361 set_reg_entry_keyserver ("Default", buf);
362 i = kserver_get_port (lv);
363 sprintf (port, "%d", i);
364 set_reg_entry_keyserver ("Default_Port", port);
365 keyserver_set_default (buf, (WORD)i);
366 return 0;
367 }
368
369
370 int
371 keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd)
372 {
373 struct listview_column_s keyserver[] = {
374 {0, 180, (char *)_("DNS Name")},
375 {1, 55, (char *)_("Port")},
376 {0, 0, NULL}
377 };
378 HICON ico[1];
379 listview_ctrl_t lv;
380 char buf[32];
381 int j;
382
383 ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_COMPUTER);
384 listview_new (&lv, hwnd);
385 for (j=0; keyserver[j].fieldname; j++)
386 listview_add_column (lv, &keyserver[j]);
387 listview_set_image_list (lv, 16, 16, ico, 1);
388 for (j = 0; j<MAX_KEYSERVERS; j++) {
389 if (!server[j].used)
390 continue;
391 listview_add_item_image (lv, " ", 0);
392 listview_add_sub_item (lv, 0, KS_COL_NAME, server[j].name);
393 sprintf (buf, "%d", server[j].port);
394 listview_add_sub_item (lv, 0, KS_COL_PORT, buf);
395 }
396 if (listview_count_items (lv, 0) == 0) {
397 listview_add_item (lv, "");
398 listview_add_sub_item (lv, 0, KS_COL_NAME, DEF_HKP_KEYSERVER);
399 }
400 listview_set_ext_style (lv);
401 *r_lv = lv;
402 return 0;
403 }
404
405
406 static void
407 keyserver_remove (listview_ctrl_t lv)
408 {
409 char name[100];
410 int pos = listview_get_curr_pos (lv);
411 int i;
412
413 listview_get_item_text (lv, pos, KS_COL_NAME, name, sizeof (name)-1);
414 for (i=0; i < MAX_KEYSERVERS; i++) {
415 if (server[i].name && strcmp (server[i].name, name) == 0)
416 server[i].used = 0;
417 }
418 listview_del_item (lv, pos);
419 }
420
421
422 static void
423 keyserver_edit (listview_ctrl_t lv, keyserver_rec_t ctx)
424 {
425 char buf[16];
426 bool fnd = false;
427 int i;
428
429 for (i=0; i < MAX_KEYSERVERS; i++) {
430 if (server[i].name && strcmp (server[i].name, ctx->name) == 0) {
431 fnd = true;
432 break;
433 }
434 }
435 if (!fnd)
436 return;
437 server[i].port = ctx->port;
438
439 i = listview_get_curr_pos (lv);
440 sprintf (buf, "%d", ctx->port);
441 listview_add_sub_item (lv, i, KS_COL_NAME, ctx->name);
442 listview_add_sub_item (lv, i, KS_COL_PORT, buf);
443 }
444
445 static void
446 keyserver_add (listview_ctrl_t lv, keyserver_rec_t ctx)
447 {
448 char buf[16];
449 bool fnd = false;
450 int i;
451
452 for (i=0; i < MAX_KEYSERVERS; i++) {
453 if (server[i].used == 0) {
454 fnd = true;
455 break;
456 }
457 }
458 if (!fnd) {
459 msg_box (NULL, _("No space for new keyserver entry"),
460 _("Keyserver"), MB_ERR);
461 return;
462 }
463 free_if_alloc (server[i].name);
464 server[i].name = m_strdup (ctx->name);
465 server[i].port = ctx->port;
466 server[i].proto = ctx->proto;
467 server[i].used = 1;
468
469 sprintf (buf, "%d", ctx->port);
470 listview_add_item (lv, " ");
471 listview_add_sub_item (lv, 0, KS_COL_NAME, ctx->name);
472 listview_add_sub_item (lv, 0, KS_COL_PORT, buf);
473 }
474
475
476 static void
477 fill_keyserv_types (HWND dlg)
478 {
479 HWND h = GetDlgItem (dlg, IDC_KSERVADD_TYPES);
480 combox_add_string (h, _("HKP Keyserver"));
481 combox_add_string (h, _("LDAP Keyserver"));
482 combox_add_string (h, _("Finger Keyserver"));
483 SendMessage (h, CB_SETCURSEL, 0, 0);
484 }
485
486
487 /* Dialog box procedure for modify keyservers. */
488 BOOL CALLBACK
489 keyserver_modify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
490 {
491 static keyserver_rec_t ctx;
492 char tmp[128];
493
494 switch (msg) {
495 case WM_INITDIALOG:
496 fill_keyserv_types (dlg);
497 ctx = (keyserver_rec_t)lparam;
498 if (ctx->mode) {
499 SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_SETCURSEL, ctx->proto, 0);
500 SetDlgItemText (dlg, IDC_KSERVADD_HOST, ctx->name);
501 SetDlgItemInt (dlg, IDC_KSERVADD_PORT, ctx->port, FALSE);
502 EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_HOST), FALSE);
503 EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_TYPES), FALSE);
504 }
505 else
506 SetDlgItemInt (dlg, IDC_KSERVADD_PORT, 11371, FALSE);
507 SetWindowText (dlg, _("Edit Keyserver"));
508 SetDlgItemText (dlg, IDOK, _("&Add"));
509 SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
510 SetDlgItemText (dlg, IDC_KSERVADD_TYPEINF, _("Type:"));
511 SetDlgItemText (dlg, IDC_KSERVADD_PORTINF, _("Port:"));
512 SetDlgItemText (dlg, IDC_KSERVADD_HOSTINF, _("Host name:"));
513 SetForegroundWindow (dlg);
514 break;
515
516 case WM_COMMAND:
517 switch (LOWORD (wparam)) {
518 case IDOK:
519 if (!GetDlgItemText (dlg, IDC_KSERVADD_HOST, tmp, sizeof (tmp)-1)) {
520 msg_box (dlg, _("Please enter a host name"), _("Keyserver"), MB_ERR);
521 return FALSE;
522 }
523 ctx->port = GetDlgItemInt (dlg, IDC_KSERVADD_PORT, NULL, FALSE);
524 if (ctx->port > 65535) {
525 msg_box (dlg, _("Invalid port, valid numbers are < 65535"), _("Keyserver"), MB_ERR);
526 return FALSE;
527 }
528 ctx->proto = SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_GETCURSEL, 0, 0);
529 ctx->cancel = false;
530 ctx->name[0] = '\0';
531 if (!strstr (tmp, "://")) {
532 switch (ctx->proto) {
533 case KSPROTO_HTTP: strcpy (ctx->name, "http://"); break;
534 case KSPROTO_LDAP: strcpy (ctx->name, "ldap://"); break;
535 case KSPROTO_FINGER:strcpy (ctx->name, "finger://"); break;
536 }
537 }
538 strcat (ctx->name, tmp);
539 ctx->cancel = false;
540 EndDialog (dlg, TRUE);
541 break;
542
543 case IDCANCEL:
544 ctx->cancel = true;
545 EndDialog (dlg, FALSE);
546 break;
547 }
548 break;
549 }
550
551 return FALSE;
552 }
553
554 /* Dialog box procedure to access keyservers. */
555 BOOL CALLBACK
556 keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
557 {
558 static listview_ctrl_t lv = NULL;
559 static int lv_idx = 0;
560 keyserver_ctx ksc;
561 struct keyserver_rec_s edit;
562 char kserver[128], pattern[128];
563 char proto[16], *fpr = NULL;
564 int rc, proto_nr = 0;
565
566 switch (msg) {
567 case WM_INITDIALOG:
568 SetWindowText (dlg, _("Keyserver Access"));
569 SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive"));
570 SetDlgItemText (dlg, IDC_KEYSERVER_SEND,
571 _("Send key (default is receiving)"));
572 SetDlgItemText (dlg, IDC_KEYSERVER_INFO,
573 _("Please enter the key ID or email address you search for"));
574 SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search"));
575 SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange proxy"));
576 SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default"));
577 SetDlgItemText (dlg, IDCANCEL, _("&Close"));
578
579 keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST));
580 set_default_ks (lv);
581 center_window (dlg, NULL);
582 SetForegroundWindow (dlg);
583 return TRUE;
584
585 case WM_NOTIFY:
586 NMHDR *notify;
587 notify = (NMHDR *)lparam;
588 if (!notify)
589 break;
590 if (notify->code == NM_CLICK
591 && notify->idFrom == IDC_KEYSERVER_LIST)
592 lv_idx = listview_get_curr_pos (lv);
593 else if (notify->code == NM_RCLICK &&
594 notify->idFrom == IDC_KEYSERVER_LIST) {
595 POINT p;
596 GetCursorPos (&p);
597 HMENU hm, pop;
598 hm = LoadMenu (glob_hinst, (LPCTSTR)IDR_WINPT_KEYSERVER_CTX);
599 pop = GetSubMenu (hm, 0);
600 set_menu_text (pop, ID_KSERVCTX_ADD, _("&Add"));
601 set_menu_text (pop, ID_KSERVCTX_DEL, _("&Remove"));
602 set_menu_text (pop, ID_KSERVCTX_EDIT, _("&Edit"));
603 TrackPopupMenu (pop, 0, p.x, p.y, 0, dlg, NULL);
604 DestroyMenu (hm);
605 DestroyMenu (pop);
606 }
607 else if (notify->code == LVN_ITEMCHANGED &&
608 ((LPNMLISTVIEW)lparam)->uNewState) {
609 listview_get_item_text (lv, listview_get_curr_pos (lv),
610 KS_COL_NAME, kserver, sizeof (kserver)-1);
611 if (!strnicmp (kserver, "ldap://", 7))
612 EnableWindow (GetDlgItem (dlg, IDC_KEYSERVER_INDEX), FALSE);
613 else
614 EnableWindow (GetDlgItem (dlg, IDC_KEYSERVER_INDEX), TRUE);
615 }
616 return TRUE;
617
618 case WM_DESTROY:
619 if (lv) {
620 listview_release (lv);
621 lv = NULL;
622 }
623 lv_idx = 0;
624 return FALSE;
625
626 case WM_SYSCOMMAND:
627 if (LOWORD (wparam) == SC_CLOSE)
628 EndDialog (dlg, TRUE);
629 return FALSE;
630
631 case WM_COMMAND:
632 switch (LOWORD (wparam)) {
633 case IDC_KEYSERVER_PROXSETT:
634 dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY,
635 dlg, keyserver_proxy_dlg_proc, 0,
636 _("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY);
637 return TRUE;
638
639 case IDC_KEYSERVER_INDEX:
640 if (!lv_idx)
641 lv_idx = kserver_get_pos (lv);
642
643 if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) {
644 msg_box (dlg, _("Please enter the search pattern."),
645 _("Keyserver"), MB_INFO);
646 return FALSE;
647 }
648
649 if (lv_idx != -1) {
650 listview_get_item_text (lv, lv_idx, KS_COL_NAME,
651 kserver, sizeof (kserver)-1);
652 ksc.name = kserver;
653 ksc.port = kserver_get_port (lv);
654 }
655 else {
656 ksc.name = DEF_HKP_KEYSERVER;
657 ksc.port = HKP_PORT;
658 }
659 ksc.pattern = pattern;
660 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg,
661 hkpsearch_dlg_proc, (LPARAM) &ksc);
662 return TRUE;
663
664 case IDC_KEYSERVER_RECV:
665 memset (&kserver, 0, sizeof (kserver));
666 if (!lv_idx) {
667 lv_idx = kserver_get_pos (lv);
668 if (lv_idx == -1) {
669 msg_box (dlg, _("Please select one of the keyservers."),
670 _("Keyserver"), MB_INFO);
671 return FALSE;
672 }
673 }
674 listview_get_item_text (lv, lv_idx, KS_COL_NAME,
675 proto, sizeof (proto)-1);
676 proto_nr = KSPROTO_HTTP;
677 if (!strncmp (proto, "ldap", 4))
678 proto_nr = KSPROTO_LDAP;
679 else if (!strncmp (proto, "finger", 6))
680 proto_nr = KSPROTO_FINGER;
681 listview_get_item_text (lv, lv_idx, KS_COL_NAME,
682 kserver, sizeof (kserver)-1);
683 if (!GetDlgItemText(dlg, IDC_KEYSERVER_SEARCH,
684 pattern, sizeof (pattern)-1)) {
685 msg_box (dlg, _("Please enter the search pattern."),
686 _("Keyserver"), MB_INFO);
687 return FALSE;
688 }
689 if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) {
690 msg_box (dlg, _("Only keyids are allowed."),
691 _("Keyserver"), MB_INFO);
692 return FALSE;
693 }
694 else if (proto_nr == KSPROTO_FINGER) {
695 if (strchr (pattern, '@') || strchr (pattern, ' ')) {
696 msg_box (dlg, _("Only enter the name of the user."),
697 _("Keyserver"), MB_INFO);
698 return FALSE;
699 }
700 }
701 else if (check_pattern (pattern)) {
702 msg_box (dlg, _("Only email addresses or keyids are allowed."),
703 _("Keyserver"), MB_INFO);
704 return FALSE;
705 }
706 rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv),
707 pattern, proto_nr, 0,
708 &fpr);
709 if (!rc && fpr != NULL) {
710 keycache_update (0, fpr);
711 free_if_alloc (fpr);
712 }
713 return TRUE;
714
715 case IDC_KEYSERVER_DEFAULT:
716 save_default_ks (lv);
717 break;
718
719 case ID_KSERVCTX_ADD:
720 memset (&edit, 0, sizeof (edit));
721 edit.mode = false;
722 dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg,
723 keyserver_modify_dlg_proc,
724 (LPARAM)&edit, _("Edit Keyserver"), 0);
725 if (!edit.cancel)
726 keyserver_add (lv, &edit);
727 return TRUE;
728
729 case ID_KSERVCTX_EDIT:
730 memset (&edit, 0, sizeof (edit));
731 edit.mode = true;
732 listview_get_item_text (lv, lv_idx, KS_COL_NAME,
733 edit.name, sizeof (edit.name)-1);
734 listview_get_item_text (lv, lv_idx, KS_COL_PORT, pattern, 32);
735 edit.port = atoi (pattern);
736 if (!strncmp (edit.name, "hkp", 3) || !strncmp (edit.name, "http", 4))
737 edit.proto = KSPROTO_HTTP;
738 else if (!strncmp (edit.name, "ldap", 4))
739 edit.proto = KSPROTO_LDAP;
740 else
741 edit.proto = KSPROTO_FINGER;
742 dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg,
743 keyserver_modify_dlg_proc,
744 (LPARAM)&edit, _("Edit Keyserver"), 0);
745 if (!edit.cancel)
746 keyserver_edit (lv, &edit);
747 break;
748
749 case ID_KSERVCTX_DEL:
750 keyserver_remove (lv);
751 return TRUE;
752
753 case IDCANCEL:
754 EndDialog (dlg, FALSE);
755 return FALSE;
756 }
757 break;
758 }
759
760 return FALSE;
761 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26