1 |
/* wptKeyserverDlg.cpp - Keyserver dialog |
/* wptKeyserverDlg.cpp - Keyserver dialog |
2 |
* Copyright (C) 2000-2007 Timo Schulz |
* Copyright (C) 2000-2007, 2009 Timo Schulz |
3 |
* Copyright (C) 2005, 2006 g10 Code GmbH |
* Copyright (C) 2005, 2006 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
33 |
#include "wptGPGME.h" |
#include "wptGPGME.h" |
34 |
#include "wptKeyserver.h" |
#include "wptKeyserver.h" |
35 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptContext.h" /* for passphrase_s */ |
36 |
|
#include "wptKeylist.h" |
37 |
#include "wptKeyManager.h" |
#include "wptKeyManager.h" |
38 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
39 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
40 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
|
#include "wptKeylist.h" |
|
41 |
|
|
|
char* get_reg_entry_keyserver (const char *); |
|
|
int set_reg_entry_keyserver (const char *, const char *); |
|
42 |
|
|
43 |
/* Symbolic column IDs */ |
/* Symbolic column IDs */ |
44 |
enum { KS_COL_NAME = 0, KS_COL_PORT }; |
enum { KS_COL_NAME = 0, KS_COL_PORT }; |
45 |
|
|
|
/* Callback context to modify (add, edit) keyserver items. */ |
|
|
struct keyserver_rec_s { |
|
|
char name[200]; /* hostname */ |
|
|
int proto; /* protocol */ |
|
|
int port; /* used port */ |
|
|
bool mode; /* true = edit */ |
|
|
bool cancel; |
|
|
}; |
|
|
typedef struct keyserver_rec_s *keyserver_rec_t; |
|
|
|
|
46 |
|
|
47 |
/* Print out keyserver error and a possible Winsock error. */ |
/* Print out keyserver error and a possible Winsock error. */ |
48 |
static void |
static void |
85 |
} |
} |
86 |
|
|
87 |
_snprintf (msg, DIM (msg) -1, _("Key '%s' successfully sent"), pattern); |
_snprintf (msg, DIM (msg) -1, _("Key '%s' successfully sent"), pattern); |
88 |
status_box (dlg, msg, _("GnuPG status")); |
status_box (dlg, msg, _("GnuPG Status")); |
89 |
|
|
90 |
leave: |
leave: |
91 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
96 |
|
|
97 |
/* Show all received keys from the keyserver. */ |
/* Show all received keys from the keyserver. */ |
98 |
static void |
static void |
99 |
show_imported_keys (gpgme_import_result_t res) |
show_imported_keys (HWND dlg, gpgme_import_result_t res) |
100 |
{ |
{ |
101 |
gpgme_import_status_t t; |
gpgme_import_status_t t; |
102 |
gpgme_key_t key; |
gpgme_key_t key; |
141 |
gpgme_data_write (msg, "\0", 1); |
gpgme_data_write (msg, "\0", 1); |
142 |
p = gpgme_data_release_and_get_mem (msg, &n); |
p = gpgme_data_release_and_get_mem (msg, &n); |
143 |
if (p != NULL) { |
if (p != NULL) { |
144 |
msg_box (NULL, p, _("Imported Keys"), MB_INFO); |
msg_box (dlg, p, _("Imported Keys"), MB_INFO); |
145 |
gpgme_free (p); |
gpgme_free (p); |
146 |
} |
} |
147 |
gpgme_release (ctx); |
gpgme_release (ctx); |
163 |
size_t keylen = 0; |
size_t keylen = 0; |
164 |
int rc; |
int rc; |
165 |
|
|
166 |
if (proto == KSPROTO_LDAP) { |
if ((rc = kserver_recvkey (kserver, port, |
167 |
rc = ldap_recvkey (kserver, pattern, &rawkey, &keylen); |
kserver_check_keyid (pattern), |
168 |
if (rc) { |
&rawkey, &keylen))) { |
|
msg_box (dlg, _("LDAP key import failed.\n" |
|
|
"Please make sure you have an online connection" |
|
|
" and gpgkeys_ldap.exe is installed"), |
|
|
_("Keyserver"), MB_ERR); |
|
|
free_if_alloc (rawkey); |
|
|
return rc; |
|
|
} |
|
|
} |
|
|
else if (proto == KSPROTO_FINGER) { |
|
|
rc = finger_recvkey (kserver, pattern, &rawkey, &keylen); |
|
|
if (rc) { |
|
|
log_box (_("Keyserver"), MB_ERR, |
|
|
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
|
|
free_if_alloc (rawkey); |
|
|
return rc; |
|
|
} |
|
|
} |
|
|
else if ((rc = kserver_recvkey (kserver, port, |
|
|
kserver_check_keyid (pattern), |
|
|
&rawkey, &keylen))) { |
|
169 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, rc); |
170 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
171 |
return rc; |
return rc; |
188 |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
189 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
190 |
if (import_res && !(flags & KM_KS_REFRESH)) { |
if (import_res && !(flags & KM_KS_REFRESH)) { |
191 |
show_imported_keys (import_res); |
show_imported_keys (dlg, import_res); |
192 |
if (import_res->unchanged == import_res->considered) { |
if (import_res->unchanged == import_res->considered) { |
193 |
rc = WPTERR_GENERAL; /* no keys updated. */ |
rc = WPTERR_GENERAL; /* no keys updated. */ |
194 |
goto leave; |
goto leave; |
287 |
|
|
288 |
|
|
289 |
/* Return human readable name for the proxy protocol. */ |
/* Return human readable name for the proxy protocol. */ |
290 |
|
#if 0 |
291 |
static const char* |
static const char* |
292 |
name_from_proto (int proto) |
name_from_proto (int proto) |
293 |
{ |
{ |
301 |
} |
} |
302 |
return s; |
return s; |
303 |
} |
} |
304 |
|
#endif |
305 |
|
|
306 |
|
|
307 |
static int inline |
static int inline |
319 |
char buf[16]; |
char buf[16]; |
320 |
|
|
321 |
listview_get_item_text (lv, kserver_get_pos (lv), |
listview_get_item_text (lv, kserver_get_pos (lv), |
322 |
KS_COL_PORT, buf, sizeof (buf)-1); |
KS_COL_PORT, buf, DIM (buf)-1); |
323 |
return (WORD)strtoul (buf, NULL, 10); |
return (WORD)strtoul (buf, NULL, 10); |
324 |
} |
} |
325 |
|
|
326 |
|
|
|
static void |
|
|
set_default_ks (listview_ctrl_t lv) |
|
|
{ |
|
|
char *p, buf[128]; |
|
|
int i; |
|
|
|
|
|
p = get_reg_entry_keyserver ("Default"); |
|
|
if (!p) |
|
|
return; |
|
|
for (i=0; i < listview_count_items (lv, 0); i++) { |
|
|
listview_get_item_text (lv, i, KS_COL_NAME, buf, sizeof (buf)-1); |
|
|
if (!stricmp (buf, p)) { |
|
|
listview_select_one (lv, i); |
|
|
break; |
|
|
} |
|
|
} |
|
|
free_if_alloc (p); |
|
|
} |
|
|
|
|
|
|
|
|
/* Save the selected keyserver from @lv as the default server. */ |
|
|
static int |
|
|
save_default_ks (listview_ctrl_t lv) |
|
|
{ |
|
|
char buf[192], port[32]; |
|
|
int idx, i; |
|
|
|
|
|
idx = listview_get_curr_pos (lv); |
|
|
if (idx == -1) { |
|
|
msg_box (NULL, _("Please select one of the servers."), |
|
|
_("Keyserver"), MB_ERR); |
|
|
return -1; |
|
|
} |
|
|
listview_get_item_text (lv, idx, KS_COL_NAME, buf, sizeof (buf)-1); |
|
|
if (strnicmp (buf, "http", 4) && strnicmp (buf, "hkp", 3)) { |
|
|
msg_box (NULL, _("Only HKP keyserver can be used."), |
|
|
_("Keyserver"), MB_ERR); |
|
|
return -1; |
|
|
} |
|
|
set_reg_entry_keyserver ("Default", buf); |
|
|
i = kserver_get_port (lv); |
|
|
sprintf (port, "%d", i); |
|
|
set_reg_entry_keyserver ("Default_Port", port); |
|
|
keyserver_set_default (buf, (WORD)i); |
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
327 |
int |
int |
328 |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
329 |
{ |
{ |
350 |
sprintf (buf, "%d", server[j].port); |
sprintf (buf, "%d", server[j].port); |
351 |
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
352 |
} |
} |
|
if (listview_count_items (lv, 0) == 0) { |
|
|
listview_add_item (lv, ""); |
|
|
listview_add_sub_item (lv, 0, KS_COL_NAME, DEF_HKP_KEYSERVER); |
|
|
} |
|
353 |
listview_set_ext_style (lv); |
listview_set_ext_style (lv); |
354 |
*r_lv = lv; |
*r_lv = lv; |
355 |
return 0; |
return 0; |
356 |
} |
} |
357 |
|
|
358 |
|
|
359 |
static void |
#if 0 |
|
keyserver_remove (listview_ctrl_t lv) |
|
|
{ |
|
|
char name[100]; |
|
|
int pos = listview_get_curr_pos (lv); |
|
|
int i; |
|
|
|
|
|
listview_get_item_text (lv, pos, KS_COL_NAME, name, sizeof (name)-1); |
|
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
|
|
if (server[i].name && stricmp (server[i].name, name) == 0) |
|
|
server[i].used = 0; |
|
|
} |
|
|
listview_del_item (lv, pos); |
|
|
} |
|
|
|
|
|
|
|
|
static void |
|
|
keyserver_edit (listview_ctrl_t lv, keyserver_rec_t ctx) |
|
|
{ |
|
|
char buf[16]; |
|
|
bool fnd = false; |
|
|
int i; |
|
|
|
|
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
|
|
if (server[i].name && stricmp (server[i].name, ctx->name) == 0) { |
|
|
fnd = true; |
|
|
break; |
|
|
} |
|
|
} |
|
|
if (!fnd) |
|
|
return; |
|
|
server[i].port = ctx->port; |
|
|
|
|
|
i = listview_get_curr_pos (lv); |
|
|
sprintf (buf, "%d", ctx->port); |
|
|
listview_add_sub_item (lv, i, KS_COL_NAME, ctx->name); |
|
|
listview_add_sub_item (lv, i, KS_COL_PORT, buf); |
|
|
} |
|
|
|
|
|
static void |
|
|
keyserver_add (listview_ctrl_t lv, keyserver_rec_t ctx) |
|
|
{ |
|
|
char buf[16]; |
|
|
bool fnd = false; |
|
|
int i; |
|
|
|
|
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
|
|
if (server[i].used == 0) { |
|
|
fnd = true; |
|
|
break; |
|
|
} |
|
|
} |
|
|
if (!fnd) { |
|
|
msg_box (NULL, _("No space for new keyserver entry"), |
|
|
_("Keyserver"), MB_ERR); |
|
|
return; |
|
|
} |
|
|
free_if_alloc (server[i].name); |
|
|
server[i].name = m_strdup (ctx->name); |
|
|
server[i].port = ctx->port; |
|
|
server[i].proto = ctx->proto; |
|
|
server[i].used = 1; |
|
|
|
|
|
sprintf (buf, "%d", ctx->port); |
|
|
listview_add_item (lv, " "); |
|
|
listview_add_sub_item (lv, 0, KS_COL_NAME, ctx->name); |
|
|
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
|
|
} |
|
|
|
|
|
|
|
360 |
static void |
static void |
361 |
fill_keyserv_types (HWND dlg) |
fill_keyserv_types (HWND dlg) |
362 |
{ |
{ |
363 |
HWND h = GetDlgItem (dlg, IDC_KSERVADD_TYPES); |
HWND h = GetDlgItem (dlg, IDC_KSERVADD_TYPES); |
364 |
combox_add_string (h, _("HKP Keyserver")); |
combox_add_string (h, _("HKP Keyserver")); |
|
combox_add_string (h, _("LDAP Keyserver")); |
|
|
combox_add_string (h, _("Finger Keyserver")); |
|
365 |
SendMessage (h, CB_SETCURSEL, 0, 0); |
SendMessage (h, CB_SETCURSEL, 0, 0); |
366 |
} |
} |
367 |
|
#endif |
|
|
|
|
/* Dialog box procedure for modify keyservers. */ |
|
|
BOOL CALLBACK |
|
|
keyserver_modify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
|
|
{ |
|
|
static keyserver_rec_t ctx; |
|
|
char tmp[128]; |
|
|
|
|
|
switch (msg) { |
|
|
case WM_INITDIALOG: |
|
|
fill_keyserv_types (dlg); |
|
|
ctx = (keyserver_rec_t)lparam; |
|
|
if (ctx->mode) { |
|
|
SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_SETCURSEL, ctx->proto, 0); |
|
|
SetDlgItemText (dlg, IDC_KSERVADD_HOST, ctx->name); |
|
|
SetDlgItemInt (dlg, IDC_KSERVADD_PORT, ctx->port, FALSE); |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_HOST), FALSE); |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_TYPES), FALSE); |
|
|
} |
|
|
else |
|
|
SetDlgItemInt (dlg, IDC_KSERVADD_PORT, 11371, FALSE); |
|
|
SetWindowText (dlg, _("Edit Keyserver")); |
|
|
SetDlgItemText (dlg, IDOK, _("&Add")); |
|
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
|
|
SetDlgItemText (dlg, IDC_KSERVADD_TYPEINF, _("Type:")); |
|
|
SetDlgItemText (dlg, IDC_KSERVADD_PORTINF, _("Port:")); |
|
|
SetDlgItemText (dlg, IDC_KSERVADD_HOSTINF, _("Host name:")); |
|
|
SetForegroundWindow (dlg); |
|
|
break; |
|
|
|
|
|
case WM_COMMAND: |
|
|
switch (LOWORD (wparam)) { |
|
|
case IDOK: |
|
|
if (!GetDlgItemText (dlg, IDC_KSERVADD_HOST, tmp, sizeof (tmp)-1)) { |
|
|
msg_box (dlg, _("Please enter a host name"), _("Keyserver"), MB_ERR); |
|
|
return FALSE; |
|
|
} |
|
|
ctx->port = GetDlgItemInt (dlg, IDC_KSERVADD_PORT, NULL, FALSE); |
|
|
if (ctx->port > 65535) { |
|
|
msg_box (dlg, _("Invalid port, valid numbers are < 65535"), _("Keyserver"), MB_ERR); |
|
|
return FALSE; |
|
|
} |
|
|
ctx->proto = SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_GETCURSEL, 0, 0); |
|
|
ctx->cancel = false; |
|
|
ctx->name[0] = '\0'; |
|
|
if (!strstr (tmp, "://")) { |
|
|
switch (ctx->proto) { |
|
|
case KSPROTO_HTTP: strcpy (ctx->name, "http://"); break; |
|
|
case KSPROTO_LDAP: strcpy (ctx->name, "ldap://"); break; |
|
|
case KSPROTO_FINGER:strcpy (ctx->name, "finger://"); break; |
|
|
} |
|
|
} |
|
|
strcat (ctx->name, tmp); |
|
|
ctx->cancel = false; |
|
|
EndDialog (dlg, TRUE); |
|
|
break; |
|
|
|
|
|
case IDCANCEL: |
|
|
ctx->cancel = true; |
|
|
EndDialog (dlg, FALSE); |
|
|
break; |
|
|
} |
|
|
break; |
|
|
} |
|
|
|
|
|
return FALSE; |
|
|
} |
|
368 |
|
|
369 |
|
|
370 |
/* XXX: factor out the pattern code for generic use. */ |
/* XXX: factor out the pattern code for generic use. */ |
445 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
446 |
static int lv_idx = 0; |
static int lv_idx = 0; |
447 |
keyserver_ctx ksc; |
keyserver_ctx ksc; |
|
struct keyserver_rec_s edit; |
|
448 |
char kserver[128], pattern[128]; |
char kserver[128], pattern[128]; |
449 |
char proto[16], *fpr = NULL; |
char *fpr = NULL; |
450 |
int rc, proto_nr = 0; |
int rc, proto_nr = 0; |
451 |
|
|
452 |
switch (msg) { |
switch (msg) { |
464 |
|
|
465 |
load_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, "KSsearch"); |
load_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, "KSsearch"); |
466 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
|
set_default_ks (lv); |
|
467 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
468 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
469 |
return TRUE; |
return TRUE; |
476 |
if (notify->code == (UINT)NM_CLICK |
if (notify->code == (UINT)NM_CLICK |
477 |
&& notify->idFrom == (UINT)IDC_KEYSERVER_LIST) |
&& notify->idFrom == (UINT)IDC_KEYSERVER_LIST) |
478 |
lv_idx = listview_get_curr_pos (lv); |
lv_idx = listview_get_curr_pos (lv); |
479 |
else if (notify->code == (UINT)NM_RCLICK && |
break; |
|
notify->idFrom == (UINT)IDC_KEYSERVER_LIST) { |
|
|
POINT p; |
|
|
GetCursorPos (&p); |
|
|
HMENU hm, pop; |
|
|
hm = LoadMenu (glob_hinst, (LPCTSTR)IDR_WINPT_KEYSERVER_CTX); |
|
|
pop = GetSubMenu (hm, 0); |
|
|
set_menu_text (pop, ID_KSERVCTX_ADD, _("&Add")); |
|
|
set_menu_text (pop, ID_KSERVCTX_DEL, _("&Remove")); |
|
|
set_menu_text (pop, ID_KSERVCTX_EDIT, _("&Edit")); |
|
|
TrackPopupMenu (pop, 0, p.x, p.y, 0, dlg, NULL); |
|
|
DestroyMenu (hm); |
|
|
DestroyMenu (pop); |
|
|
} |
|
|
else if (notify->code == LVN_ITEMCHANGED && |
|
|
((LPNMLISTVIEW)lparam)->uNewState) { |
|
|
listview_get_item_text (lv, listview_get_curr_pos (lv), |
|
|
KS_COL_NAME, kserver, sizeof (kserver)-1); |
|
|
if (!strnicmp (kserver, "ldap://", 7)) |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSERVER_INDEX), FALSE); |
|
|
else |
|
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSERVER_INDEX), TRUE); |
|
|
} |
|
|
return TRUE; |
|
480 |
|
|
481 |
case WM_DESTROY: |
case WM_DESTROY: |
482 |
|
balloon_msg_disable (); |
483 |
if (lv) { |
if (lv) { |
484 |
listview_release (lv); |
listview_release (lv); |
485 |
lv = NULL; |
lv = NULL; |
486 |
} |
} |
487 |
lv_idx = 0; |
lv_idx = 0; |
488 |
save_pattern_from_combox (dlg, IDC_KEYSERVER_SEARCH, "KSsearch"); |
save_pattern_from_combox (dlg, IDC_KEYSERVER_SEARCH, "KSsearch"); |
489 |
return FALSE; |
break; |
|
|
|
|
case WM_SYSCOMMAND: |
|
|
if (LOWORD (wparam) == SC_CLOSE) |
|
|
EndDialog (dlg, TRUE); |
|
|
return FALSE; |
|
490 |
|
|
491 |
case WM_COMMAND: |
case WM_COMMAND: |
492 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
500 |
if (!lv_idx) |
if (!lv_idx) |
501 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
502 |
|
|
503 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, |
504 |
msg_box (dlg, _("Please enter the search pattern."), |
pattern, DIM (pattern)-1)) { |
505 |
_("Keyserver"), MB_INFO); |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYSERVER_SEARCH), |
506 |
return TRUE; |
_("Please enter the search pattern."), |
507 |
|
IDI_WARNING); |
508 |
|
return FALSE; |
509 |
} |
} |
510 |
|
|
511 |
if (lv_idx != -1) { |
if (lv_idx != -1) { |
512 |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
513 |
kserver, sizeof (kserver)-1); |
kserver, DIM (kserver)-1); |
514 |
ksc.name = kserver; |
ksc.name = kserver; |
515 |
ksc.port = kserver_get_port (lv); |
ksc.port = kserver_get_port (lv); |
516 |
} |
} |
528 |
if (!lv_idx) { |
if (!lv_idx) { |
529 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
530 |
if (lv_idx == -1) { |
if (lv_idx == -1) { |
531 |
msg_box (dlg, _("Please select one of the keyservers."), |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYSERVER_LIST), |
532 |
_("Keyserver"), MB_INFO); |
_("Please select one of the keyservers."), |
533 |
return TRUE; |
IDI_WARNING); |
534 |
|
return FALSE; |
535 |
} |
} |
536 |
} |
} |
|
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
|
|
proto, sizeof (proto)-1); |
|
537 |
proto_nr = KSPROTO_HTTP; |
proto_nr = KSPROTO_HTTP; |
|
if (!strnicmp (proto, "ldap", 4)) |
|
|
proto_nr = KSPROTO_LDAP; |
|
|
else if (!strnicmp (proto, "finger", 6)) |
|
|
proto_nr = KSPROTO_FINGER; |
|
538 |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
539 |
kserver, sizeof (kserver)-1); |
kserver, DIM (kserver)-1); |
540 |
if (!GetDlgItemText(dlg, IDC_KEYSERVER_SEARCH, |
if (!GetDlgItemText(dlg, IDC_KEYSERVER_SEARCH, |
541 |
pattern, sizeof (pattern)-1)) { |
pattern, DIM (pattern)-1)) { |
542 |
msg_box (dlg, _("Please enter the search pattern."), |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYSERVER_SEARCH), |
543 |
_("Keyserver"), MB_INFO); |
_("Please enter the search pattern."), |
544 |
|
IDI_WARNING); |
545 |
return FALSE; |
return FALSE; |
546 |
} |
} |
547 |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
if (check_pattern (pattern)) { |
548 |
msg_box (dlg, _("Only keyids are allowed."), |
show_balloon_msg (GetDlgItem (dlg, IDC_KEYSERVER_SEARCH), |
549 |
_("Keyserver"), MB_INFO); |
_("Only email addresses or keyids are allowed."), |
550 |
|
IDI_ERROR); |
551 |
return FALSE; |
return FALSE; |
552 |
} |
} |
|
else if (proto_nr == KSPROTO_FINGER) { |
|
|
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
|
|
msg_box (dlg, _("Only enter the name of the user."), |
|
|
_("Keyserver"), MB_INFO); |
|
|
return TRUE; |
|
|
} |
|
|
} |
|
|
else if (check_pattern (pattern)) { |
|
|
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
|
|
_("Keyserver"), MB_INFO); |
|
|
return TRUE; |
|
|
} |
|
553 |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
554 |
pattern, proto_nr, 0, |
pattern, proto_nr, 0, &fpr); |
|
&fpr); |
|
555 |
if (!rc && fpr != NULL) { |
if (!rc && fpr != NULL) { |
556 |
keycache_update (0, fpr); |
keycache_update (0, fpr); |
557 |
free_if_alloc (fpr); |
free_if_alloc (fpr); |
560 |
add_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, pattern); |
add_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, pattern); |
561 |
return TRUE; |
return TRUE; |
562 |
|
|
|
case IDC_KEYSERVER_DEFAULT: |
|
|
save_default_ks (lv); |
|
|
return TRUE; |
|
|
|
|
|
case ID_KSERVCTX_ADD: |
|
|
memset (&edit, 0, sizeof (edit)); |
|
|
edit.mode = false; |
|
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg, |
|
|
keyserver_modify_dlg_proc, |
|
|
(LPARAM)&edit, _("Edit Keyserver"), 0); |
|
|
if (!edit.cancel) |
|
|
keyserver_add (lv, &edit); |
|
|
return TRUE; |
|
|
|
|
|
case ID_KSERVCTX_EDIT: |
|
|
memset (&edit, 0, sizeof (edit)); |
|
|
edit.mode = true; |
|
|
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
|
|
edit.name, sizeof (edit.name)-1); |
|
|
listview_get_item_text (lv, lv_idx, KS_COL_PORT, pattern, 32); |
|
|
edit.port = atoi (pattern); |
|
|
if (!strnicmp (edit.name, "hkp", 3) || !strnicmp (edit.name, "http", 4)) |
|
|
edit.proto = KSPROTO_HTTP; |
|
|
else if (!strnicmp (edit.name, "ldap", 4)) |
|
|
edit.proto = KSPROTO_LDAP; |
|
|
else |
|
|
edit.proto = KSPROTO_FINGER; |
|
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg, |
|
|
keyserver_modify_dlg_proc, |
|
|
(LPARAM)&edit, _("Edit Keyserver"), 0); |
|
|
if (!edit.cancel) |
|
|
keyserver_edit (lv, &edit); |
|
|
break; |
|
|
|
|
|
case ID_KSERVCTX_DEL: |
|
|
keyserver_remove (lv); |
|
|
return TRUE; |
|
|
|
|
563 |
case IDCANCEL: |
case IDCANCEL: |
564 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
565 |
return TRUE; |
return TRUE; |