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