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