1 |
/* wptKeyserverDlg.cpp - Keyserver dialog |
/* wptKeyserverDlg.cpp - Keyserver dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005, 2006 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
24 |
|
|
25 |
#include <windows.h> |
#include <windows.h> |
26 |
#include <commctrl.h> |
#include <commctrl.h> |
27 |
#include <malloc.h> |
#include <ctype.h> |
28 |
|
|
29 |
#include "resource.h" |
#include "resource.h" |
|
#include "wptKeyserver.h" |
|
30 |
#include "wptErrors.h" |
#include "wptErrors.h" |
31 |
#include "wptTypes.h" |
#include "wptTypes.h" |
32 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
34 |
#include "wptW32API.h" |
#include "wptW32API.h" |
35 |
#include "wptVersion.h" |
#include "wptVersion.h" |
36 |
#include "wptGPG.h" |
#include "wptGPG.h" |
37 |
#include "wptKeyManager.h" |
#include "wptGPGME.h" |
38 |
|
#include "wptKeyserver.h" |
39 |
#include "wptContext.h" /* for passphrase_s */ |
#include "wptContext.h" /* for passphrase_s */ |
40 |
|
#include "wptKeyManager.h" |
41 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
42 |
#include "wptUTF8.h" |
#include "wptUTF8.h" |
43 |
|
#include "wptRegistry.h" |
44 |
|
#include "wptKeylist.h" |
|
#define MAX_KEYSIZE 70000 |
|
45 |
|
|
46 |
char* get_reg_entry_keyserver (const char *); |
char* get_reg_entry_keyserver (const char *); |
47 |
int set_reg_entry_keyserver (const char *, const char *); |
int set_reg_entry_keyserver (const char *, const char *); |
48 |
|
|
49 |
|
/* Symbolic column IDs */ |
50 |
|
enum { KS_COL_NAME = 0, KS_COL_PORT }; |
51 |
|
|
52 |
|
/* Callback context to modify (add, edit) keyserver items. */ |
53 |
|
struct keyserver_rec_s { |
54 |
|
char name[200]; /* hostname */ |
55 |
|
int proto; /* protocol */ |
56 |
|
int port; /* used port */ |
57 |
|
bool mode; /* true = edit */ |
58 |
|
bool cancel; |
59 |
|
}; |
60 |
|
typedef struct keyserver_rec_s *keyserver_rec_t; |
61 |
|
|
62 |
|
|
63 |
/* Print out keyserver error and a possible Winsock error. */ |
/* Print out keyserver error and a possible Winsock error. */ |
64 |
static void |
static void |
65 |
hkp_err_box (HWND dlg, const char *host, WORD port, int rc) |
hkp_err_box (HWND dlg, const char *host, WORD port, int rc) |
66 |
{ |
{ |
67 |
const char *err = kserver_strerror (); |
const char *err = kserver_strerror (); |
68 |
|
const char *ws_err = wsock_strerror (); |
69 |
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", |
|
70 |
host, port, winpt_strerror (rc)); |
if (ws_err && strlen (ws_err) > 0) |
71 |
if (err) |
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s", host, port, ws_err); |
72 |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
else |
73 |
|
log_box (_("Keyserver"), MB_ERR, "%s:%d: %s\n%s", |
74 |
|
host, port, winpt_strerror (rc), err? err : ""); |
75 |
} |
} |
76 |
|
|
77 |
|
|
81 |
int |
int |
82 |
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern) |
hkp_send_key (HWND dlg, const char *kserver, WORD port, const char *pattern) |
83 |
{ |
{ |
84 |
gpgme_ctx_t ctx; |
GPGME *gpg; |
|
gpgme_data_t keydata; |
|
85 |
gpgme_error_t ec; |
gpgme_error_t ec; |
86 |
char *rawkey = NULL; |
char *rawkey = NULL; |
87 |
char msg[384]; |
char msg[256]; |
|
size_t n; |
|
88 |
|
|
89 |
ec = gpgme_new (&ctx); |
gpg = new GPGME (); |
90 |
if (ec) |
gpg->setArmor (true); |
91 |
BUG (NULL); |
ec = gpg->exportToBuffer (pattern, &rawkey); |
|
gpgme_set_armor (ctx, 1); |
|
|
ec = gpgme_data_new (&keydata); |
|
|
if (ec) |
|
|
BUG (NULL); |
|
|
ec = gpgme_op_export (ctx, pattern, 0, keydata); |
|
92 |
if (ec) { |
if (ec) { |
93 |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
msg_box (dlg, gpgme_strerror (ec), _("Export"), MB_ERR); |
94 |
goto leave; |
goto leave; |
95 |
} |
} |
96 |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
op_begin (); |
97 |
ec = kserver_sendkey (kserver, port, rawkey, n); |
ec = kserver_sendkey (kserver, port, rawkey, strlen (rawkey)); |
98 |
|
op_end (); |
99 |
if (ec) { |
if (ec) { |
100 |
hkp_err_box (dlg, kserver, port, ec); |
hkp_err_box (dlg, kserver, port, ec); |
101 |
goto leave; |
goto leave; |
105 |
status_box (dlg, msg, _("GnuPG status")); |
status_box (dlg, msg, _("GnuPG status")); |
106 |
|
|
107 |
leave: |
leave: |
108 |
gpgme_release (ctx); |
delete gpg; |
109 |
if (rawkey) |
free_if_alloc (rawkey); |
|
gpgme_free (rawkey); |
|
110 |
return ec? -1 : 0; |
return ec? -1 : 0; |
111 |
} |
} |
112 |
|
|
143 |
s = _("Key(s) successfully received but nothing was changed."); |
s = _("Key(s) successfully received but nothing was changed."); |
144 |
else |
else |
145 |
s = _("Key(s) sucessfully received and imported."); |
s = _("Key(s) sucessfully received and imported."); |
146 |
|
// nice to have the amount of new signatures... |
147 |
gpgme_data_write (msg, s, strlen (s)); |
gpgme_data_write (msg, s, strlen (s)); |
148 |
gpgme_data_write (msg, "\n\n", 2); |
gpgme_data_write (msg, "\n\n", 2); |
149 |
|
|
150 |
for (t=res->imports; t; t = t->next) { |
for (t=res->imports; t; t = t->next) { |
151 |
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
if (!gpgme_get_key (ctx, t->fpr, &key, 0)) { |
152 |
s = uid = utf8_to_wincp2 (key->uids->uid); |
s = uid = utf8_to_native (key->uids->uid); |
153 |
gpgme_data_write (msg, s, strlen (s)); |
gpgme_data_write (msg, s, strlen (s)); |
154 |
gpgme_data_write (msg, "\n", 1); |
gpgme_data_write (msg, "\n", 1); |
155 |
gpgme_key_release (key); |
gpgme_key_release (key); |
156 |
free (uid); |
safe_free (uid); |
157 |
} |
} |
158 |
} |
} |
159 |
gpgme_data_write (msg, "\0", 1); |
gpgme_data_write (msg, "\0", 1); |
173 |
keyserver_recv_key (HWND dlg, const char *kserver, WORD port, |
keyserver_recv_key (HWND dlg, const char *kserver, WORD port, |
174 |
const char *pattern, int proto, int flags, |
const char *pattern, int proto, int flags, |
175 |
char **r_fpr) |
char **r_fpr) |
176 |
{ |
{ |
177 |
gpgme_ctx_t ctx; |
gpgme_import_result_t import_res = NULL; |
178 |
gpgme_data_t keydata; |
gpgme_error_t err; |
179 |
gpgme_error_t ec; |
GPGME *gpg = NULL; |
|
gpgme_import_result_t import_res = NULL; |
|
180 |
char *rawkey = NULL; |
char *rawkey = NULL; |
181 |
|
size_t keylen = 0; |
182 |
int rc; |
int rc; |
183 |
|
|
|
/* XXX: implement dynamic buffers. */ |
|
|
rawkey = new char[MAX_KEYSIZE]; |
|
|
if (!rawkey) |
|
|
BUG (0); |
|
|
memset (rawkey, 0, MAX_KEYSIZE); |
|
184 |
if (proto == KSPROTO_LDAP) { |
if (proto == KSPROTO_LDAP) { |
185 |
rc = ldap_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
rc = ldap_recvkey (kserver, pattern, &rawkey, &keylen); |
186 |
if (rc) { |
if (rc) { |
187 |
msg_box (dlg, _("LDAP key import failed.\n" |
msg_box (dlg, _("LDAP key import failed.\n" |
188 |
"Please make sure you have an online connection" |
"Please make sure you have an online connection" |
193 |
} |
} |
194 |
} |
} |
195 |
else if (proto == KSPROTO_FINGER) { |
else if (proto == KSPROTO_FINGER) { |
196 |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
rc = finger_recvkey (kserver, pattern, &rawkey, &keylen); |
197 |
if (rc) { |
if (rc) { |
198 |
log_box (_("Keyserver"), MB_ERR, |
log_box (_("Keyserver"), MB_ERR, |
199 |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
_("Finger key import failed: %s\n"), winpt_strerror (rc)); |
203 |
} |
} |
204 |
else if ((rc = kserver_recvkey (kserver, port, |
else if ((rc = kserver_recvkey (kserver, port, |
205 |
kserver_check_keyid (pattern), |
kserver_check_keyid (pattern), |
206 |
rawkey, MAX_KEYSIZE-1))) { |
&rawkey, &keylen))) { |
207 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, rc); |
208 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
209 |
return rc; |
return rc; |
210 |
} |
} |
211 |
else { |
|
212 |
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
if (!strstr (rawkey, "BEGIN PGP PUBLIC KEY BLOCK")) { |
213 |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
msg_box (dlg, _("This is not a valid OpenPGP key."), |
214 |
_("Keyserver"), MB_ERR); |
_("Keyserver"), MB_ERR); |
215 |
goto leave; |
goto leave; |
216 |
} |
} |
217 |
ec = gpgme_new (&ctx); |
gpg = new GPGME (); |
218 |
if (ec) |
err = gpg->importFromBuffer (rawkey); |
219 |
BUG (NULL); |
if (err) { |
220 |
gpgme_data_new_from_mem (&keydata, rawkey, strlen (rawkey), 1); |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
221 |
rc = gpgme_op_import (ctx, keydata); |
goto leave; |
222 |
if (rc) { |
} |
223 |
msg_box (dlg, gpgme_strerror ((gpgme_error_t)rc), _("Import"), MB_ERR); |
import_res = gpg->importGetResult (); |
224 |
goto leave; |
if (import_res && r_fpr) |
225 |
} |
*r_fpr = m_strdup (import_res->imports->fpr); |
|
import_res = gpgme_op_import_result (ctx); |
|
|
if (import_res && r_fpr) |
|
|
*r_fpr = m_strdup (import_res->imports->fpr); |
|
|
} |
|
226 |
|
|
227 |
/* 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 |
228 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
229 |
if (!(flags & KM_KS_REFRESH)) { |
if (import_res && !(flags & KM_KS_REFRESH)) { |
230 |
show_imported_keys (import_res); |
show_imported_keys (import_res); |
231 |
if (import_res && import_res->unchanged == import_res->considered) { |
if (import_res->unchanged == import_res->considered) { |
232 |
rc = WPTERR_GENERAL; /* no keys updated. */ |
rc = WPTERR_GENERAL; /* no keys updated. */ |
233 |
goto leave; |
goto leave; |
234 |
} |
} |
236 |
|
|
237 |
leave: |
leave: |
238 |
free_if_alloc (rawkey); |
free_if_alloc (rawkey); |
239 |
gpgme_release (ctx); |
if (gpg != NULL) |
240 |
gpgme_data_release (keydata); |
delete gpg; |
|
|
|
241 |
return rc; |
return rc; |
242 |
} |
} |
243 |
|
|
252 |
proto, flags, NULL); |
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, |
260 |
|
proto, 0, r_fpr); |
261 |
|
} |
262 |
|
|
|
#define my_iskeychar(a) (((a) >='0' && (a) <= '9' ) || ((a) >= 'A' && (a) <= 'F')) |
|
263 |
|
|
264 |
static int |
/* Utility function to fetch a key from the keyserver |
265 |
check_pattern (const char *pattern) |
based on a given signature (@sig). |
266 |
|
Return 0 on success. */ |
267 |
|
int |
268 |
|
fetch_key_from_keyserver (HWND dlg, gpgme_signature_t sig) |
269 |
{ |
{ |
270 |
int rc = 1; |
const char *keyid; |
271 |
|
char timebuf[128]; |
272 |
/* Whitespace are not allowed! */ |
int id; |
273 |
if (strchr( pattern, ' ')) { |
|
274 |
rc = WPTERR_GENERAL; |
// XXX: we have a problem with v3 keys here |
275 |
goto leave; |
if (!sig->fpr) |
276 |
} |
return FALSE; |
277 |
|
if (!get_locale_timedate (sig->timestamp, timebuf, DIM (timebuf)-1)) |
278 |
if (((strstr (pattern, "0x")) && (strlen (pattern) == 10)) || |
_snprintf (timebuf, DIM (timebuf)-1, "'unknown time'"); |
279 |
(strstr(pattern, "0x")) && (strlen (pattern) == 18)) { |
keyid = get_keyid_from_fpr (sig->fpr); |
280 |
rc = 0; /* Either long or short keyid */ |
id = log_box (_("Verify"), MB_INFO|MB_YESNO, |
281 |
goto leave; |
_("Signature made %s using %s key ID 0x%s\n" |
282 |
} |
"Cannot check signature: public key not found\n\n" |
283 |
|
"Do you want to try to retrieve the key from the keyserver?"), |
284 |
if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern ) == 8 ) ) |
timebuf, get_key_pubalgo (sig->pubkey_algo), keyid); |
285 |
|| (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) { |
if (id == IDNO) { |
286 |
rc = 0; |
msg_box (dlg, get_gpg_sigstat (GPGME_SIGSUM_KEY_MISSING), |
287 |
goto leave; |
_("Verify"), MB_WARN); |
288 |
|
return -1; |
289 |
|
} |
290 |
|
|
291 |
|
if (!hkp_recv_key (dlg, default_keyserver, default_keyserver_port, |
292 |
|
keyid, 0, 0)) { |
293 |
|
keycache_update (0, keyid); |
294 |
|
return 0; |
295 |
} |
} |
296 |
|
return -1; |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
/* Check if the given pattern are either a valid |
301 |
|
email address, a {long, short} keyid or a fingerprint. |
302 |
|
Return 0 on success. */ |
303 |
|
static int |
304 |
|
check_pattern (const char *pattern) |
305 |
|
{ |
306 |
|
size_t i; |
307 |
|
|
308 |
|
if (strchr (pattern, ' ')) |
309 |
|
return WPTERR_GENERAL; /* do not allow white spaces. */ |
310 |
|
|
311 |
if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) { |
if (strchr (pattern, '@') && strlen (pattern) >= 3 && |
312 |
rc = 0; |
!check_email_address (pattern)) |
313 |
goto leave; |
return 0; |
314 |
|
|
315 |
|
if (strstr (pattern, "0x")) |
316 |
|
pattern += 2; |
317 |
|
if (strlen (pattern) != 8 && |
318 |
|
strlen (pattern) != 16 && |
319 |
|
strlen (pattern) != 40) |
320 |
|
return WPTERR_GENERAL; |
321 |
|
|
322 |
|
for (i=0; i < strlen (pattern); i++) { |
323 |
|
if (!isxdigit (pattern[i])) |
324 |
|
return WPTERR_GENERAL; |
325 |
} |
} |
326 |
|
return 0; |
327 |
leave: |
} |
|
return rc; |
|
|
} /* check_pattern */ |
|
328 |
|
|
329 |
|
|
330 |
static void |
/* Return human readable name for the proxy protocol. */ |
331 |
set_proxy (HWND dlg) |
static const char* |
332 |
|
name_from_proto (int proto) |
333 |
{ |
{ |
334 |
char proxy[256]; |
const char *s; |
335 |
int port = 0; |
|
336 |
|
switch (proto) { |
337 |
strcpy (proxy, "HTTP proxy: "); |
case PROXY_PROTO_NONE: s = ""; break; |
338 |
if (kserver_get_proxy (&port)) { |
case PROXY_PROTO_HTTP: s = "HTTP"; break; |
339 |
char t[128]; |
case PROXY_PROTO_SOCKS5: s = "SOCKS5"; break; |
340 |
const char *http = kserver_get_proxy (&port); |
default: s = "HTTP"; break; |
|
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
|
|
strcat (proxy, t); |
|
341 |
} |
} |
342 |
else |
return s; |
343 |
strcat (proxy, "none"); |
} |
|
SetDlgItemText (dlg, IDC_KEYSERVER_PROXY, proxy); |
|
|
} /* set_proxy */ |
|
344 |
|
|
345 |
|
|
346 |
static int inline |
static int inline |
352 |
} |
} |
353 |
|
|
354 |
|
|
355 |
static u16 inline |
static WORD inline |
356 |
kserver_get_port (listview_ctrl_t lv) |
kserver_get_port (listview_ctrl_t lv) |
357 |
{ |
{ |
358 |
char buf[16]; |
char buf[16]; |
359 |
|
|
360 |
listview_get_item_text (lv, kserver_get_pos (lv), 3, buf, 15); |
listview_get_item_text (lv, kserver_get_pos (lv), |
361 |
return (u16)strtoul (buf, NULL, 10); |
KS_COL_PORT, buf, sizeof (buf)-1); |
362 |
|
return (WORD)strtoul (buf, NULL, 10); |
363 |
} |
} |
364 |
|
|
365 |
|
|
366 |
static void |
static void |
367 |
load_default_ks (listview_ctrl_t lv) |
set_default_ks (listview_ctrl_t lv) |
368 |
{ |
{ |
369 |
char * p, buf[192]; |
char *p, buf[128]; |
370 |
int i; |
int i; |
371 |
|
|
372 |
p = get_reg_entry_keyserver ("Default"); |
p = get_reg_entry_keyserver ("Default"); |
373 |
if (!p) |
if (!p) |
374 |
return; |
return; |
375 |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
for (i=0; i < listview_count_items (lv, 0); i++) { |
376 |
listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 ); |
listview_get_item_text (lv, i, KS_COL_NAME, buf, sizeof (buf)-1); |
377 |
if( !strncmp( p, buf, strlen( p ) ) ) { |
if (!stricmp (buf, p)) { |
378 |
listview_add_sub_item( lv, i, 2, "x" ); |
listview_select_one (lv, i); |
379 |
break; |
break; |
380 |
} |
} |
381 |
} |
} |
382 |
free_if_alloc (p); |
free_if_alloc (p); |
383 |
} /* load_default_ks */ |
} |
384 |
|
|
385 |
|
|
386 |
|
/* Save the selected keyserver from @lv as the default server. */ |
387 |
static int |
static int |
388 |
save_default_ks (listview_ctrl_t lv) |
save_default_ks (listview_ctrl_t lv) |
389 |
{ |
{ |
390 |
char buf[192], port[32]; |
char buf[192], port[32]; |
391 |
int idx, i; |
int idx, i; |
392 |
|
|
393 |
idx = listview_get_curr_pos( lv ); |
idx = listview_get_curr_pos (lv); |
394 |
if( idx == -1 ) { |
if (idx == -1) { |
395 |
msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR ); |
msg_box (NULL, _("Please select one of the servers."), |
396 |
|
_("Keyserver"), MB_ERR); |
397 |
return -1; |
return -1; |
398 |
} |
} |
399 |
listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 ); |
listview_get_item_text (lv, idx, KS_COL_NAME, buf, sizeof (buf)-1); |
400 |
if( *buf != 'H' ) { |
if (strnicmp (buf, "http", 4) && strnicmp (buf, "hkp", 3)) { |
401 |
msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR ); |
msg_box (NULL, _("Only HKP keyserver can be used."), |
402 |
|
_("Keyserver"), MB_ERR); |
403 |
return -1; |
return -1; |
404 |
} |
} |
|
for (i = 0; i < listview_count_items( lv, 0 ); i++) |
|
|
listview_add_sub_item (lv, i, 2, ""); |
|
|
listview_add_sub_item (lv, idx, 2, "x"); |
|
|
listview_get_item_text (lv, idx, 0, buf, sizeof (buf)-1); |
|
405 |
set_reg_entry_keyserver ("Default", buf); |
set_reg_entry_keyserver ("Default", buf); |
406 |
i = kserver_get_port (lv); |
i = kserver_get_port (lv); |
407 |
sprintf (port, "%d", i); |
sprintf (port, "%d", i); |
408 |
set_reg_entry_keyserver ("Default_Port", port); |
set_reg_entry_keyserver ("Default_Port", port); |
409 |
keyserver_set_default (buf, (u16)i); |
keyserver_set_default (buf, (WORD)i); |
410 |
return 0; |
return 0; |
411 |
} /* save_default_ks */ |
} |
412 |
|
|
413 |
|
|
414 |
int |
int |
415 |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
416 |
{ |
{ |
417 |
struct listview_column_s keyserver[] = { |
struct listview_column_s keyserver[] = { |
418 |
{0, 160, (char *)_("DNS Name")}, |
{0, 180, (char *)_("DNS Name")}, |
419 |
{1, 52, (char *)_("Protocol")}, |
{1, 55, (char *)_("Port")}, |
|
{2, 46, (char *)_("Default")}, |
|
|
{3, 46, (char *)_("Port")}, |
|
420 |
{0, 0, NULL} |
{0, 0, NULL} |
421 |
}; |
}; |
422 |
HICON ico[1]; |
HICON ico[1]; |
425 |
int j; |
int j; |
426 |
|
|
427 |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_COMPUTER); |
ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_COMPUTER); |
428 |
listview_new (&lv); |
listview_new (&lv, hwnd); |
|
lv->ctrl = hwnd; |
|
429 |
for (j=0; keyserver[j].fieldname; j++) |
for (j=0; keyserver[j].fieldname; j++) |
430 |
listview_add_column (lv, &keyserver[j]); |
listview_add_column (lv, &keyserver[j]); |
431 |
listview_set_image_list (lv, ico, 1); |
listview_set_image_list (lv, 16, 16, ico, 1); |
432 |
for (j = 0; j<MAX_KEYSERVERS; j++) { |
for (j = 0; j < MAX_KEYSERVERS; j++) { |
433 |
if (!server[j].used) |
if (!server[j].used) |
434 |
continue; |
continue; |
435 |
listview_add_item_image (lv, " ", 0); |
listview_add_item_image (lv, " ", 0); |
436 |
listview_add_sub_item (lv, 0, 0, server[j].name); |
listview_add_sub_item (lv, 0, KS_COL_NAME, server[j].name); |
|
switch (server[j].proto) { |
|
|
case KSPROTO_HTTP: |
|
|
listview_add_sub_item( lv, 0, 1, "H" ); break; |
|
|
case KSPROTO_LDAP: |
|
|
listview_add_sub_item( lv, 0, 1, "L" ); break; |
|
|
case KSPROTO_FINGER: |
|
|
listview_add_sub_item( lv, 0, 1, "F" ); break; |
|
|
} |
|
437 |
sprintf (buf, "%d", server[j].port); |
sprintf (buf, "%d", server[j].port); |
438 |
listview_add_sub_item (lv, 0, 3, buf); |
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
439 |
} |
} |
|
load_default_ks (lv); |
|
440 |
if (listview_count_items (lv, 0) == 0) { |
if (listview_count_items (lv, 0) == 0) { |
441 |
listview_add_item (lv, ""); |
listview_add_item (lv, ""); |
442 |
listview_add_sub_item (lv, 0, 0, DEF_HKP_KEYSERVER); |
listview_add_sub_item (lv, 0, KS_COL_NAME, DEF_HKP_KEYSERVER); |
|
listview_add_sub_item (lv, 0, 1, "H"); |
|
443 |
} |
} |
444 |
listview_set_ext_style (lv); |
listview_set_ext_style (lv); |
445 |
*r_lv = lv; |
*r_lv = lv; |
447 |
} |
} |
448 |
|
|
449 |
|
|
450 |
|
static void |
451 |
|
keyserver_remove (listview_ctrl_t lv) |
452 |
|
{ |
453 |
|
char name[100]; |
454 |
|
int pos = listview_get_curr_pos (lv); |
455 |
|
int i; |
456 |
|
|
457 |
|
listview_get_item_text (lv, pos, KS_COL_NAME, name, sizeof (name)-1); |
458 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
459 |
|
if (server[i].name && stricmp (server[i].name, name) == 0) |
460 |
|
server[i].used = 0; |
461 |
|
} |
462 |
|
listview_del_item (lv, pos); |
463 |
|
} |
464 |
|
|
465 |
|
|
466 |
|
static void |
467 |
|
keyserver_edit (listview_ctrl_t lv, keyserver_rec_t ctx) |
468 |
|
{ |
469 |
|
char buf[16]; |
470 |
|
bool fnd = false; |
471 |
|
int i; |
472 |
|
|
473 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
474 |
|
if (server[i].name && stricmp (server[i].name, ctx->name) == 0) { |
475 |
|
fnd = true; |
476 |
|
break; |
477 |
|
} |
478 |
|
} |
479 |
|
if (!fnd) |
480 |
|
return; |
481 |
|
server[i].port = ctx->port; |
482 |
|
|
483 |
|
i = listview_get_curr_pos (lv); |
484 |
|
sprintf (buf, "%d", ctx->port); |
485 |
|
listview_add_sub_item (lv, i, KS_COL_NAME, ctx->name); |
486 |
|
listview_add_sub_item (lv, i, KS_COL_PORT, buf); |
487 |
|
} |
488 |
|
|
489 |
|
static void |
490 |
|
keyserver_add (listview_ctrl_t lv, keyserver_rec_t ctx) |
491 |
|
{ |
492 |
|
char buf[16]; |
493 |
|
bool fnd = false; |
494 |
|
int i; |
495 |
|
|
496 |
|
for (i=0; i < MAX_KEYSERVERS; i++) { |
497 |
|
if (server[i].used == 0) { |
498 |
|
fnd = true; |
499 |
|
break; |
500 |
|
} |
501 |
|
} |
502 |
|
if (!fnd) { |
503 |
|
msg_box (NULL, _("No space for new keyserver entry"), |
504 |
|
_("Keyserver"), MB_ERR); |
505 |
|
return; |
506 |
|
} |
507 |
|
free_if_alloc (server[i].name); |
508 |
|
server[i].name = m_strdup (ctx->name); |
509 |
|
server[i].port = ctx->port; |
510 |
|
server[i].proto = ctx->proto; |
511 |
|
server[i].used = 1; |
512 |
|
|
513 |
|
sprintf (buf, "%d", ctx->port); |
514 |
|
listview_add_item (lv, " "); |
515 |
|
listview_add_sub_item (lv, 0, KS_COL_NAME, ctx->name); |
516 |
|
listview_add_sub_item (lv, 0, KS_COL_PORT, buf); |
517 |
|
} |
518 |
|
|
519 |
|
|
520 |
|
static void |
521 |
|
fill_keyserv_types (HWND dlg) |
522 |
|
{ |
523 |
|
HWND h = GetDlgItem (dlg, IDC_KSERVADD_TYPES); |
524 |
|
combox_add_string (h, _("HKP Keyserver")); |
525 |
|
combox_add_string (h, _("LDAP Keyserver")); |
526 |
|
combox_add_string (h, _("Finger Keyserver")); |
527 |
|
SendMessage (h, CB_SETCURSEL, 0, 0); |
528 |
|
} |
529 |
|
|
530 |
|
|
531 |
|
/* Dialog box procedure for modify keyservers. */ |
532 |
|
BOOL CALLBACK |
533 |
|
keyserver_modify_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
534 |
|
{ |
535 |
|
static keyserver_rec_t ctx; |
536 |
|
char tmp[128]; |
537 |
|
|
538 |
|
switch (msg) { |
539 |
|
case WM_INITDIALOG: |
540 |
|
fill_keyserv_types (dlg); |
541 |
|
ctx = (keyserver_rec_t)lparam; |
542 |
|
if (ctx->mode) { |
543 |
|
SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_SETCURSEL, ctx->proto, 0); |
544 |
|
SetDlgItemText (dlg, IDC_KSERVADD_HOST, ctx->name); |
545 |
|
SetDlgItemInt (dlg, IDC_KSERVADD_PORT, ctx->port, FALSE); |
546 |
|
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_HOST), FALSE); |
547 |
|
EnableWindow (GetDlgItem (dlg, IDC_KSERVADD_TYPES), FALSE); |
548 |
|
} |
549 |
|
else |
550 |
|
SetDlgItemInt (dlg, IDC_KSERVADD_PORT, 11371, FALSE); |
551 |
|
SetWindowText (dlg, _("Edit Keyserver")); |
552 |
|
SetDlgItemText (dlg, IDOK, _("&Add")); |
553 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
554 |
|
SetDlgItemText (dlg, IDC_KSERVADD_TYPEINF, _("Type:")); |
555 |
|
SetDlgItemText (dlg, IDC_KSERVADD_PORTINF, _("Port:")); |
556 |
|
SetDlgItemText (dlg, IDC_KSERVADD_HOSTINF, _("Host name:")); |
557 |
|
SetForegroundWindow (dlg); |
558 |
|
break; |
559 |
|
|
560 |
|
case WM_COMMAND: |
561 |
|
switch (LOWORD (wparam)) { |
562 |
|
case IDOK: |
563 |
|
if (!GetDlgItemText (dlg, IDC_KSERVADD_HOST, tmp, sizeof (tmp)-1)) { |
564 |
|
msg_box (dlg, _("Please enter a host name"), _("Keyserver"), MB_ERR); |
565 |
|
return FALSE; |
566 |
|
} |
567 |
|
ctx->port = GetDlgItemInt (dlg, IDC_KSERVADD_PORT, NULL, FALSE); |
568 |
|
if (ctx->port > 65535) { |
569 |
|
msg_box (dlg, _("Invalid port, valid numbers are < 65535"), _("Keyserver"), MB_ERR); |
570 |
|
return FALSE; |
571 |
|
} |
572 |
|
ctx->proto = SendDlgItemMessage (dlg, IDC_KSERVADD_TYPES, CB_GETCURSEL, 0, 0); |
573 |
|
ctx->cancel = false; |
574 |
|
ctx->name[0] = '\0'; |
575 |
|
if (!strstr (tmp, "://")) { |
576 |
|
switch (ctx->proto) { |
577 |
|
case KSPROTO_HTTP: strcpy (ctx->name, "http://"); break; |
578 |
|
case KSPROTO_LDAP: strcpy (ctx->name, "ldap://"); break; |
579 |
|
case KSPROTO_FINGER:strcpy (ctx->name, "finger://"); break; |
580 |
|
} |
581 |
|
} |
582 |
|
strcat (ctx->name, tmp); |
583 |
|
ctx->cancel = false; |
584 |
|
EndDialog (dlg, TRUE); |
585 |
|
break; |
586 |
|
|
587 |
|
case IDCANCEL: |
588 |
|
ctx->cancel = true; |
589 |
|
EndDialog (dlg, FALSE); |
590 |
|
break; |
591 |
|
} |
592 |
|
break; |
593 |
|
} |
594 |
|
|
595 |
|
return FALSE; |
596 |
|
} |
597 |
|
|
598 |
|
|
599 |
|
/* XXX: factor out the pattern code for generic use. */ |
600 |
|
|
601 |
|
/* Add search pattern @patt to the combo box if it is |
602 |
|
not already available in the list. */ |
603 |
|
static void |
604 |
|
add_pattern_to_combox (HWND dlg, int ctlid, const char *patt) |
605 |
|
{ |
606 |
|
int err; |
607 |
|
|
608 |
|
err = SendDlgItemMessage (dlg, ctlid, CB_FINDSTRINGEXACT, |
609 |
|
0, (LPARAM)(LPCSTR)patt); |
610 |
|
if (err != CB_ERR) |
611 |
|
return; |
612 |
|
SendDlgItemMessage (dlg, IDC_KEYSERVER_SEARCH, CB_ADDSTRING, |
613 |
|
0, (LPARAM)(LPCSTR)patt); |
614 |
|
} |
615 |
|
|
616 |
|
|
617 |
|
/* Restore saved pattern from the registry back to the combo box. |
618 |
|
If no pattern were saved, do nothing and just return. */ |
619 |
|
static void |
620 |
|
load_pattern_to_combox (HWND dlg, int ctlid, const char *rkey_name) |
621 |
|
{ |
622 |
|
char *p, *tok; |
623 |
|
|
624 |
|
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", rkey_name); |
625 |
|
if (!p || strlen (p) < 2) { |
626 |
|
free_if_alloc (p); |
627 |
|
return; |
628 |
|
} |
629 |
|
tok = strtok (p, "$"); |
630 |
|
while (tok != NULL) { |
631 |
|
SendDlgItemMessage (dlg, ctlid, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)tok); |
632 |
|
tok = strtok (NULL, "$"); |
633 |
|
} |
634 |
|
free_if_alloc (p); |
635 |
|
} |
636 |
|
|
637 |
|
|
638 |
|
/* Save all entries from the combo box given in @ctlid to the |
639 |
|
registry. Concat all values and use '$' as a separator. */ |
640 |
|
static void |
641 |
|
save_pattern_from_combox (HWND dlg, int ctlid, const char *rkey_name) |
642 |
|
{ |
643 |
|
char *p, tmp[64]; |
644 |
|
int i; |
645 |
|
int n, len=0; |
646 |
|
|
647 |
|
n = SendDlgItemMessage (dlg, ctlid, CB_GETCOUNT, 0, 0); |
648 |
|
if (n == 0 || n == CB_ERR) |
649 |
|
return; |
650 |
|
/* it is very unlikely that the combox contain hundred of pattern |
651 |
|
but even so we limit the value to 16 which should be sufficient. */ |
652 |
|
if (n > 16) n = 16; |
653 |
|
for (i=0; i < n; i++) |
654 |
|
len += SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXTLEN, |
655 |
|
(WPARAM)i, 0) + 1 + 1; |
656 |
|
p = new char[len+1]; |
657 |
|
memset (p, 0, len+1); |
658 |
|
for (i=0; i < n; i++) { |
659 |
|
memset (tmp, 0, sizeof (tmp)); |
660 |
|
SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXT, |
661 |
|
(WPARAM)i, (LPARAM)tmp); |
662 |
|
strcat (p, tmp); |
663 |
|
strcat (p, "$"); |
664 |
|
} |
665 |
|
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", rkey_name, p); |
666 |
|
free_if_alloc (p); |
667 |
|
} |
668 |
|
|
669 |
|
|
670 |
/* Dialog box procedure to access keyservers. */ |
/* Dialog box procedure to access keyservers. */ |
671 |
BOOL CALLBACK |
BOOL CALLBACK |
672 |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
673 |
{ |
{ |
674 |
static listview_ctrl_t lv = NULL; |
static listview_ctrl_t lv = NULL; |
675 |
static int lv_idx = 0; |
static int lv_idx = 0; |
|
static struct genkey_s *key; |
|
676 |
keyserver_ctx ksc; |
keyserver_ctx ksc; |
677 |
|
struct keyserver_rec_s edit; |
678 |
char kserver[128], pattern[128]; |
char kserver[128], pattern[128]; |
679 |
char proto[16]; |
char proto[16], *fpr = NULL; |
680 |
int rc, proto_nr = 0; |
int rc, proto_nr = 0; |
681 |
|
|
682 |
switch (msg) { |
switch (msg) { |
683 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
|
if (lparam != 0) |
|
|
key = (struct genkey_s*)lparam; |
|
684 |
SetWindowText (dlg, _("Keyserver Access")); |
SetWindowText (dlg, _("Keyserver Access")); |
685 |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
686 |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
687 |
_("Send key (default is receiving)")); |
_("Send key (default is receiving)")); |
688 |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
689 |
_("Please enter the key ID or email address you search for")); |
_("Key ID or email address you want to search for")); |
690 |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
691 |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange proxy")); |
692 |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
693 |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
SetDlgItemText (dlg, IDCANCEL, _("&Close")); |
694 |
|
|
695 |
set_proxy (dlg); |
load_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, "KSsearch"); |
696 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
697 |
|
set_default_ks (lv); |
698 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
699 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
700 |
return TRUE; |
return TRUE; |
702 |
case WM_NOTIFY: |
case WM_NOTIFY: |
703 |
NMHDR *notify; |
NMHDR *notify; |
704 |
notify = (NMHDR *)lparam; |
notify = (NMHDR *)lparam; |
705 |
if (notify && notify->code == NM_CLICK |
if (!notify) |
706 |
|
break; |
707 |
|
if (notify->code == NM_CLICK |
708 |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
&& notify->idFrom == IDC_KEYSERVER_LIST) |
709 |
lv_idx = listview_get_curr_pos (lv); |
lv_idx = listview_get_curr_pos (lv); |
710 |
|
else if (notify->code == NM_RCLICK && |
711 |
|
notify->idFrom == IDC_KEYSERVER_LIST) { |
712 |
|
POINT p; |
713 |
|
GetCursorPos (&p); |
714 |
|
HMENU hm, pop; |
715 |
|
hm = LoadMenu (glob_hinst, (LPCTSTR)IDR_WINPT_KEYSERVER_CTX); |
716 |
|
pop = GetSubMenu (hm, 0); |
717 |
|
set_menu_text (pop, ID_KSERVCTX_ADD, _("&Add")); |
718 |
|
set_menu_text (pop, ID_KSERVCTX_DEL, _("&Remove")); |
719 |
|
set_menu_text (pop, ID_KSERVCTX_EDIT, _("&Edit")); |
720 |
|
TrackPopupMenu (pop, 0, p.x, p.y, 0, dlg, NULL); |
721 |
|
DestroyMenu (hm); |
722 |
|
DestroyMenu (pop); |
723 |
|
} |
724 |
|
else if (notify->code == LVN_ITEMCHANGED && |
725 |
|
((LPNMLISTVIEW)lparam)->uNewState) { |
726 |
|
listview_get_item_text (lv, listview_get_curr_pos (lv), |
727 |
|
KS_COL_NAME, kserver, sizeof (kserver)-1); |
728 |
|
if (!strnicmp (kserver, "ldap://", 7)) |
729 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSERVER_INDEX), FALSE); |
730 |
|
else |
731 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSERVER_INDEX), TRUE); |
732 |
|
} |
733 |
return TRUE; |
return TRUE; |
734 |
|
|
735 |
case WM_DESTROY: |
case WM_DESTROY: |
738 |
lv = NULL; |
lv = NULL; |
739 |
} |
} |
740 |
lv_idx = 0; |
lv_idx = 0; |
741 |
|
save_pattern_from_combox (dlg, IDC_KEYSERVER_SEARCH, "KSsearch"); |
742 |
return FALSE; |
return FALSE; |
743 |
|
|
744 |
case WM_SYSCOMMAND: |
case WM_SYSCOMMAND: |
745 |
if (LOWORD (wparam) == SC_CLOSE) |
if (LOWORD (wparam) == SC_CLOSE) |
746 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
747 |
return FALSE; |
return FALSE; |
748 |
|
|
749 |
case WM_COMMAND: |
case WM_COMMAND: |
750 |
switch (LOWORD (wparam)) { |
switch (LOWORD (wparam)) { |
751 |
case IDC_KEYSERVER_PROXSETT: |
case IDC_KEYSERVER_PROXSETT: |
752 |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, |
753 |
dlg, keyserver_proxy_dlg_proc, NULL, |
dlg, keyserver_proxy_dlg_proc, 0, |
754 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY); |
|
set_proxy (dlg); |
|
755 |
return TRUE; |
return TRUE; |
756 |
|
|
757 |
case IDC_KEYSERVER_INDEX: |
case IDC_KEYSERVER_INDEX: |
758 |
if (!lv_idx) { |
if (!lv_idx) |
759 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
760 |
if (lv_idx == -1) { |
|
|
msg_box (dlg, _("Please select one of the keyservers."), |
|
|
_("Keyserver"), MB_INFO); |
|
|
return FALSE; |
|
|
} |
|
|
} |
|
|
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
|
|
if (*proto == 'L') { |
|
|
msg_box (dlg, _("This is not implemented yet!"), |
|
|
_("Keyserver"), MB_ERR); |
|
|
return FALSE; |
|
|
} |
|
|
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
|
761 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
762 |
msg_box (dlg, _("Please enter the search pattern."), |
msg_box (dlg, _("Please enter the search pattern."), |
763 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
764 |
return FALSE; |
return TRUE; |
765 |
} |
} |
766 |
ksc.name = kserver; |
|
767 |
|
if (lv_idx != -1) { |
768 |
|
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
769 |
|
kserver, sizeof (kserver)-1); |
770 |
|
ksc.name = kserver; |
771 |
|
ksc.port = kserver_get_port (lv); |
772 |
|
} |
773 |
|
else { |
774 |
|
ksc.name = DEF_HKP_KEYSERVER; |
775 |
|
ksc.port = HKP_PORT; |
776 |
|
} |
777 |
ksc.pattern = pattern; |
ksc.pattern = pattern; |
|
ksc.port = kserver_get_port (lv); |
|
778 |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
779 |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
hkpsearch_dlg_proc, (LPARAM) &ksc); |
780 |
return TRUE; |
return TRUE; |
781 |
|
|
782 |
case IDC_KEYSERVER_RECV: |
case IDC_KEYSERVER_RECV: |
783 |
memset (&kserver, 0, sizeof (kserver)); |
memset (&kserver, 0, sizeof (kserver)); |
784 |
if (!lv_idx) { |
if (!lv_idx) { |
785 |
lv_idx = kserver_get_pos (lv); |
lv_idx = kserver_get_pos (lv); |
786 |
if (lv_idx == -1) { |
if (lv_idx == -1) { |
787 |
msg_box (dlg, _("Please select one of the keyservers."), |
msg_box (dlg, _("Please select one of the keyservers."), |
788 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
789 |
return FALSE; |
return TRUE; |
790 |
} |
} |
791 |
} |
} |
792 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
793 |
|
proto, sizeof (proto)-1); |
794 |
proto_nr = KSPROTO_HTTP; |
proto_nr = KSPROTO_HTTP; |
795 |
if (*proto == 'L') |
if (!strnicmp (proto, "ldap", 4)) |
796 |
proto_nr = KSPROTO_LDAP; |
proto_nr = KSPROTO_LDAP; |
797 |
else if (*proto == 'F') |
else if (!strnicmp (proto, "finger", 6)) |
798 |
proto_nr = KSPROTO_FINGER; |
proto_nr = KSPROTO_FINGER; |
799 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
800 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
kserver, sizeof (kserver)-1); |
801 |
|
if (!GetDlgItemText(dlg, IDC_KEYSERVER_SEARCH, |
802 |
|
pattern, sizeof (pattern)-1)) { |
803 |
msg_box (dlg, _("Please enter the search pattern."), |
msg_box (dlg, _("Please enter the search pattern."), |
804 |
_("Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
805 |
return FALSE; |
return FALSE; |
806 |
} |
} |
807 |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
if (proto_nr == KSPROTO_LDAP && strchr (pattern, '@')) { |
808 |
msg_box (dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO); |
msg_box (dlg, _("Only keyids are allowed."), |
809 |
|
_("Keyserver"), MB_INFO); |
810 |
return FALSE; |
return FALSE; |
811 |
} |
} |
812 |
else if (proto_nr == KSPROTO_FINGER) { |
else if (proto_nr == KSPROTO_FINGER) { |
813 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
814 |
msg_box (dlg, _("Only enter the name of the user."), |
msg_box (dlg, _("Only enter the name of the user."), |
815 |
_("FINGER Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
816 |
return FALSE; |
return TRUE; |
817 |
} |
} |
818 |
} |
} |
819 |
else if (check_pattern (pattern)) { |
else if (check_pattern (pattern)) { |
820 |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
msg_box (dlg, _("Only email addresses or keyids are allowed."), |
821 |
_("HKP Keyserver"), MB_INFO); |
_("Keyserver"), MB_INFO); |
822 |
return FALSE; |
return TRUE; |
823 |
} |
} |
824 |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
rc = keyserver_recv_key (dlg, kserver, kserver_get_port (lv), |
825 |
pattern, proto_nr, 0, |
pattern, proto_nr, 0, |
826 |
key? &key->fpr : NULL); |
&fpr); |
827 |
if (!rc && key->fpr != NULL) { |
if (!rc && fpr != NULL) { |
828 |
keycache_update (0, key->fpr); |
keycache_update (0, fpr); |
829 |
get_pubkey (key->fpr, &key->newkey); |
free_if_alloc (fpr); |
|
/* we do not need the fingerprint any longer. */ |
|
|
free_if_alloc (key->fpr); |
|
830 |
} |
} |
831 |
|
if (!rc) |
832 |
|
add_pattern_to_combox (dlg, IDC_KEYSERVER_SEARCH, pattern); |
833 |
return TRUE; |
return TRUE; |
834 |
|
|
835 |
case IDC_KEYSERVER_DEFAULT: |
case IDC_KEYSERVER_DEFAULT: |
836 |
save_default_ks (lv); |
save_default_ks (lv); |
837 |
|
return TRUE; |
838 |
|
|
839 |
|
case ID_KSERVCTX_ADD: |
840 |
|
memset (&edit, 0, sizeof (edit)); |
841 |
|
edit.mode = false; |
842 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg, |
843 |
|
keyserver_modify_dlg_proc, |
844 |
|
(LPARAM)&edit, _("Edit Keyserver"), 0); |
845 |
|
if (!edit.cancel) |
846 |
|
keyserver_add (lv, &edit); |
847 |
|
return TRUE; |
848 |
|
|
849 |
|
case ID_KSERVCTX_EDIT: |
850 |
|
memset (&edit, 0, sizeof (edit)); |
851 |
|
edit.mode = true; |
852 |
|
listview_get_item_text (lv, lv_idx, KS_COL_NAME, |
853 |
|
edit.name, sizeof (edit.name)-1); |
854 |
|
listview_get_item_text (lv, lv_idx, KS_COL_PORT, pattern, 32); |
855 |
|
edit.port = atoi (pattern); |
856 |
|
if (!strnicmp (edit.name, "hkp", 3) || !strnicmp (edit.name, "http", 4)) |
857 |
|
edit.proto = KSPROTO_HTTP; |
858 |
|
else if (!strnicmp (edit.name, "ldap", 4)) |
859 |
|
edit.proto = KSPROTO_LDAP; |
860 |
|
else |
861 |
|
edit.proto = KSPROTO_FINGER; |
862 |
|
dialog_box_param (glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_ADD, dlg, |
863 |
|
keyserver_modify_dlg_proc, |
864 |
|
(LPARAM)&edit, _("Edit Keyserver"), 0); |
865 |
|
if (!edit.cancel) |
866 |
|
keyserver_edit (lv, &edit); |
867 |
break; |
break; |
868 |
|
|
869 |
|
case ID_KSERVCTX_DEL: |
870 |
|
keyserver_remove (lv); |
871 |
|
return TRUE; |
872 |
|
|
873 |
case IDCANCEL: |
case IDCANCEL: |
874 |
EndDialog (dlg, FALSE); |
EndDialog (dlg, FALSE); |
875 |
return FALSE; |
return TRUE; |
876 |
} |
} |
877 |
break; |
break; |
878 |
} |
} |