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