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