1 |
/* wptKeyserverDlg.cpp - Keyserver dialog |
/* wptKeyserverDlg.cpp - Keyserver dialog |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2005 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
* 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 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
* (at your option) any later version. |
10 |
* |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
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 "wptKeyManager.h" |
39 |
#define MAX_KEYSIZE 70000 |
#include "wptContext.h" /* for passphrase_s */ |
40 |
|
#include "wptDlgs.h" |
41 |
char * get_reg_entry_keyserver (const char *); |
|
42 |
int set_reg_entry_keyserver (const char *, const char *); |
|
43 |
|
#define MAX_KEYSIZE 70000 |
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(); |
|
49 |
|
static void |
50 |
log_box( _("Keyserver"), MB_ERR, "%s:%d: %s", host, port, winpt_strerror (rc)); |
hkp_err_box (HWND dlg, const char * host, u16 port, int rc) |
51 |
if (err) |
{ |
52 |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
const char *err = kserver_strerror(); |
53 |
} /* hkp_err_box */ |
|
54 |
|
log_box( _("Keyserver"), MB_ERR, "%s:%d: %s", host, port, winpt_strerror (rc)); |
55 |
|
if (err) |
56 |
int |
msg_box (dlg, err, wsock_strerror (), MB_ERR); |
57 |
hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern) |
} /* hkp_err_box */ |
58 |
{ |
|
59 |
gpgme_ctx_t c; |
|
60 |
gpgme_data_t keydata; |
int |
61 |
gpgme_error_t ec; |
hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern) |
62 |
char *rawkey = NULL, msg[1024]; |
{ |
63 |
size_t n; |
gpgme_ctx_t c; |
64 |
int rc; |
gpgme_data_t keydata; |
65 |
|
gpgme_error_t ec; |
66 |
ec = gpgme_new( &c ); |
char *rawkey = NULL, msg[1024]; |
67 |
if( ec ) |
size_t n; |
68 |
BUG( NULL ); |
int rc; |
69 |
gpgme_set_armor (c, 1); |
|
70 |
ec = gpgme_data_new( &keydata ); |
ec = gpgme_new( &c ); |
71 |
if( ec ) |
if( ec ) |
72 |
BUG( NULL ); |
BUG( NULL ); |
73 |
rc = (int) gpgme_op_export( c, pattern, 0, keydata ); |
gpgme_set_armor (c, 1); |
74 |
if( rc ) { |
ec = gpgme_data_new( &keydata ); |
75 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR ); |
if( ec ) |
76 |
goto leave; |
BUG( NULL ); |
77 |
} |
rc = (int) gpgme_op_export( c, pattern, 0, keydata ); |
78 |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
if( rc ) { |
79 |
rc = kserver_sendkey (kserver, port, rawkey, n); |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR ); |
80 |
if (rc) { |
goto leave; |
81 |
hkp_err_box (dlg, kserver, port, rc); |
} |
82 |
goto leave; |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
83 |
} |
rc = kserver_sendkey (kserver, port, rawkey, n); |
84 |
|
if (rc) { |
85 |
_snprintf (msg, sizeof (msg) -1, _("Key '%s' successfully sent"), pattern); |
hkp_err_box (dlg, kserver, port, rc); |
86 |
status_box (dlg, msg, _("GnuPG status")); |
goto leave; |
87 |
|
} |
88 |
leave: |
|
89 |
gpgme_release (c); |
_snprintf (msg, sizeof (msg) -1, _("Key '%s' successfully sent"), pattern); |
90 |
if (rawkey) |
status_box (dlg, msg, _("GnuPG status")); |
91 |
gpgme_free (rawkey); |
|
92 |
return rc; |
leave: |
93 |
} /* hkp_send_key */ |
gpgme_release (c); |
94 |
|
if (rawkey) |
95 |
|
gpgme_free (rawkey); |
96 |
int |
return rc; |
97 |
hkp_recv_key (HWND dlg, const char *kserver, u16 port, |
} /* hkp_send_key */ |
98 |
const char *pattern, int proto, int flags) |
|
99 |
{ |
|
100 |
gpgme_ctx_t ctx; |
int |
101 |
gpgme_data_t keydata; |
hkp_recv_key (HWND dlg, const char *kserver, u16 port, |
102 |
gpgme_error_t ec; |
const char *pattern, int proto, int flags) |
103 |
gpgme_import_result_t import_res; |
{ |
104 |
int rc; |
gpgme_ctx_t ctx; |
105 |
char *rawkey = NULL, msg[384]; |
gpgme_data_t keydata; |
106 |
|
gpgme_error_t ec; |
107 |
rawkey = new char[MAX_KEYSIZE]; |
gpgme_import_result_t import_res; |
108 |
if (!rawkey) |
int rc; |
109 |
BUG (0); |
char *rawkey = NULL, msg[384]; |
110 |
memset (rawkey, 0, MAX_KEYSIZE); |
|
111 |
if( proto == KSPROTO_LDAP ) { |
rawkey = new char[MAX_KEYSIZE]; |
112 |
rc = ldap_recvkey( kserver, pattern, rawkey, MAX_KEYSIZE-1 ); |
if (!rawkey) |
113 |
if( rc ) { |
BUG (0); |
114 |
msg_box( dlg, _("LDAP key import failed.\n" |
memset (rawkey, 0, MAX_KEYSIZE); |
115 |
"Please make sure you have an online connection" |
if( proto == KSPROTO_LDAP ) { |
116 |
" and gpgkeys_ldap.exe is installed"), |
rc = ldap_recvkey( kserver, pattern, rawkey, MAX_KEYSIZE-1 ); |
117 |
_("Keyserver"), MB_ERR ); |
if( rc ) { |
118 |
free_if_alloc( rawkey ); |
msg_box( dlg, _("LDAP key import failed.\n" |
119 |
return rc; |
"Please make sure you have an online connection" |
120 |
} |
" and gpgkeys_ldap.exe is installed"), |
121 |
} |
_("Keyserver"), MB_ERR ); |
122 |
else if (proto == KSPROTO_FINGER) { |
free_if_alloc( rawkey ); |
123 |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
return rc; |
124 |
if (rc) { |
} |
125 |
log_box (_("Keyserver"), MB_ERR, _("Finger key import failed: %s\n"), |
} |
126 |
winpt_strerror (rc)); |
else if (proto == KSPROTO_FINGER) { |
127 |
free_if_alloc (rawkey); |
rc = finger_recvkey (kserver, pattern, rawkey, MAX_KEYSIZE-1); |
128 |
return rc; |
if (rc) { |
129 |
} |
log_box (_("Keyserver"), MB_ERR, _("Finger key import failed: %s\n"), |
130 |
} |
winpt_strerror (rc)); |
131 |
else if( ( rc = kserver_recvkey( kserver, port, kserver_check_keyid( pattern ), |
free_if_alloc (rawkey); |
132 |
rawkey, MAX_KEYSIZE-1 ) ) ) { |
return rc; |
133 |
hkp_err_box (dlg, kserver, port, rc); |
} |
134 |
free_if_alloc (rawkey); |
} |
135 |
return rc; |
else if( ( rc = kserver_recvkey( kserver, port, kserver_check_keyid( pattern ), |
136 |
} |
rawkey, MAX_KEYSIZE-1 ) ) ) { |
137 |
else { |
hkp_err_box (dlg, kserver, port, rc); |
138 |
if( !strstr( rawkey, "BEGIN PGP PUBLIC KEY BLOCK" ) ) { |
free_if_alloc (rawkey); |
139 |
msg_box( dlg, _("This is not a valid OpenPGP key."), _("Keyserver"), MB_ERR ); |
return rc; |
140 |
goto leave; |
} |
141 |
} |
else { |
142 |
ec = gpgme_new( &ctx ); |
if( !strstr( rawkey, "BEGIN PGP PUBLIC KEY BLOCK" ) ) { |
143 |
if( ec ) |
msg_box( dlg, _("This is not a valid OpenPGP key."), _("Keyserver"), MB_ERR ); |
144 |
BUG( NULL ); |
goto leave; |
145 |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
} |
146 |
rc = gpgme_op_import( ctx, keydata ); |
ec = gpgme_new( &ctx ); |
147 |
if( rc ) { |
if( ec ) |
148 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
BUG( NULL ); |
149 |
goto leave; |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
150 |
} |
rc = gpgme_op_import( ctx, keydata ); |
151 |
import_res = gpgme_op_import_result (ctx); |
if( rc ) { |
152 |
} |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
153 |
|
goto leave; |
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. */ |
import_res = gpgme_op_import_result (ctx); |
156 |
if (!(flags & KM_KS_REFRESH)) { |
} |
157 |
if (import_res->new_user_ids == 0) { |
|
158 |
_snprintf (msg, DIM (msg)-1, |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
159 |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
a summarize at the end is presented and not for each key. */ |
160 |
status_box (dlg, msg, _("GnuPG Status")); |
if (!(flags & KM_KS_REFRESH)) { |
161 |
rc = WPTERR_GENERAL; |
if (import_res->new_user_ids == 0) { |
162 |
goto leave; |
_snprintf (msg, DIM (msg)-1, |
163 |
} |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
164 |
_snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern); |
status_box (dlg, msg, _("GnuPG Status")); |
165 |
status_box (dlg, msg, _("GnuPG Status")); |
rc = WPTERR_GENERAL; |
166 |
} |
goto leave; |
167 |
|
} |
168 |
leave: |
_snprintf (msg, DIM (msg)-1, _("Key '%s' sucessfully received and imported."), pattern); |
169 |
free_if_alloc (rawkey); |
status_box (dlg, msg, _("GnuPG Status")); |
170 |
gpgme_release (ctx); |
} |
171 |
gpgme_data_release (keydata); |
|
172 |
|
leave: |
173 |
return rc; |
free_if_alloc (rawkey); |
174 |
} /* hkp_recv_key */ |
gpgme_release (ctx); |
175 |
|
gpgme_data_release (keydata); |
176 |
|
|
177 |
#define my_iskeychar(a) ( ( (a) >='0' && (a) <= '9' ) || ( (a) >= 'A' && (a) <= 'F' ) ) |
return rc; |
178 |
|
} /* hkp_recv_key */ |
179 |
static int |
|
180 |
check_pattern( const char *pattern ) |
|
181 |
{ |
#define my_iskeychar(a) ( ( (a) >='0' && (a) <= '9' ) || ( (a) >= 'A' && (a) <= 'F' ) ) |
182 |
int rc = 1; |
|
183 |
|
static int |
184 |
/* Whitespace are not allowed! */ |
check_pattern( const char *pattern ) |
185 |
if( strchr( pattern, ' ') ) { |
{ |
186 |
rc = WPTERR_GENERAL; |
int rc = 1; |
187 |
goto leave; |
|
188 |
} |
/* Whitespace are not allowed! */ |
189 |
|
if( strchr( pattern, ' ') ) { |
190 |
if( (( strstr( pattern, "0x" ) ) && ( strlen( pattern ) == 10 ) ) |
rc = WPTERR_GENERAL; |
191 |
|| (strstr(pattern, "0x")) && ( strlen( pattern ) == 18 ) ) { |
goto leave; |
192 |
rc = 0; |
} |
193 |
goto leave; |
|
194 |
} |
if( (( strstr( pattern, "0x" ) ) && ( strlen( pattern ) == 10 ) ) |
195 |
|
|| (strstr(pattern, "0x")) && ( strlen( pattern ) == 18 ) ) { |
196 |
if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern ) == 8 ) ) |
rc = 0; |
197 |
|| (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) { |
goto leave; |
198 |
rc = 0; |
} |
199 |
goto leave; |
|
200 |
} |
if( (( my_iskeychar( pattern[0] )) && ( strlen( pattern ) == 8 ) ) |
201 |
|
|| (my_iskeychar(pattern[0])) && ( strlen( pattern ) == 16) ) { |
202 |
if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) { |
rc = 0; |
203 |
rc = 0; |
goto leave; |
204 |
goto leave; |
} |
205 |
} |
|
206 |
|
if( ( strchr( pattern, '@' ) ) && ( strlen( pattern ) >= 3 ) ) { |
207 |
leave: |
rc = 0; |
208 |
return rc; |
goto leave; |
209 |
} /* check_pattern */ |
} |
210 |
|
|
211 |
|
leave: |
212 |
static void |
return rc; |
213 |
set_proxy (HWND dlg) |
} /* check_pattern */ |
214 |
{ |
|
215 |
char proxy[384]; |
|
216 |
int port = 0; |
static void |
217 |
|
set_proxy (HWND dlg) |
218 |
strcpy (proxy, "HTTP proxy: "); |
{ |
219 |
if (kserver_get_proxy (&port)) { |
char proxy[384]; |
220 |
char t[256]; |
int port = 0; |
221 |
const char *http = kserver_get_proxy (&port); |
|
222 |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
strcpy (proxy, "HTTP proxy: "); |
223 |
strcat (proxy, t); |
if (kserver_get_proxy (&port)) { |
224 |
} |
char t[256]; |
225 |
else |
const char *http = kserver_get_proxy (&port); |
226 |
strcat( proxy, "none" ); |
_snprintf (t, sizeof (t) - 1, "\"%s:%d\"", http, port); |
227 |
SetDlgItemText( dlg, IDC_KEYSERVER_PROXY, proxy ); |
strcat (proxy, t); |
228 |
} /* set_proxy */ |
} |
229 |
|
else |
230 |
|
strcat( proxy, "none" ); |
231 |
static int inline |
SetDlgItemText( dlg, IDC_KEYSERVER_PROXY, proxy ); |
232 |
kserver_get_pos (listview_ctrl_t lv) |
} /* set_proxy */ |
233 |
{ |
|
234 |
if (listview_count_items (lv, 0) == 1) |
|
235 |
return 0; |
static int inline |
236 |
return listview_get_curr_pos (lv); |
kserver_get_pos (listview_ctrl_t lv) |
237 |
} |
{ |
238 |
|
if (listview_count_items (lv, 0) == 1) |
239 |
|
return 0; |
240 |
static u16 inline |
return listview_get_curr_pos (lv); |
241 |
kserver_get_port (listview_ctrl_t lv) |
} |
242 |
{ |
|
243 |
char buf[16]; |
|
244 |
|
static u16 inline |
245 |
listview_get_item_text (lv, kserver_get_pos (lv), 3, buf, 15); |
kserver_get_port (listview_ctrl_t lv) |
246 |
return (u16)strtoul (buf, NULL, 10); |
{ |
247 |
} |
char buf[16]; |
248 |
|
|
249 |
static void |
listview_get_item_text (lv, kserver_get_pos (lv), 3, buf, 15); |
250 |
load_default_ks (listview_ctrl_t lv) |
return (u16)strtoul (buf, NULL, 10); |
251 |
{ |
} |
252 |
char * p, buf[192]; |
|
253 |
int i; |
static void |
254 |
|
load_default_ks (listview_ctrl_t lv) |
255 |
p = get_reg_entry_keyserver ("Default"); |
{ |
256 |
if (!p) |
char * p, buf[192]; |
257 |
return; |
int i; |
258 |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
|
259 |
listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 ); |
p = get_reg_entry_keyserver ("Default"); |
260 |
if( !strncmp( p, buf, strlen( p ) ) ) { |
if (!p) |
261 |
listview_add_sub_item( lv, i, 2, "x" ); |
return; |
262 |
break; |
for( i = 0; i < listview_count_items( lv, 0 ); i++ ) { |
263 |
} |
listview_get_item_text( lv, i, 0, buf, sizeof (buf)-1 ); |
264 |
} |
if( !strncmp( p, buf, strlen( p ) ) ) { |
265 |
free_if_alloc (p); |
listview_add_sub_item( lv, i, 2, "x" ); |
266 |
} /* load_default_ks */ |
break; |
267 |
|
} |
268 |
|
} |
269 |
static int |
free_if_alloc (p); |
270 |
save_default_ks (listview_ctrl_t lv) |
} /* load_default_ks */ |
271 |
{ |
|
272 |
char buf[192], port[32]; |
|
273 |
int idx, i; |
static int |
274 |
|
save_default_ks (listview_ctrl_t lv) |
275 |
idx = listview_get_curr_pos( lv ); |
{ |
276 |
if( idx == -1 ) { |
char buf[192], port[32]; |
277 |
msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR ); |
int idx, i; |
278 |
return -1; |
|
279 |
} |
idx = listview_get_curr_pos( lv ); |
280 |
listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 ); |
if( idx == -1 ) { |
281 |
if( *buf != 'H' ) { |
msg_box( NULL, _("Please select one of the servers."), _("Keyserver"), MB_ERR ); |
282 |
msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR ); |
return -1; |
283 |
return -1; |
} |
284 |
} |
listview_get_item_text( lv, idx, 1, buf, sizeof (buf)-1 ); |
285 |
for (i = 0; i < listview_count_items( lv, 0 ); i++) |
if( *buf != 'H' ) { |
286 |
listview_add_sub_item (lv, i, 2, ""); |
msg_box( NULL, _("Only HTTP keyserver can be used."), _("Keyserver"), MB_ERR ); |
287 |
listview_add_sub_item (lv, idx, 2, "x"); |
return -1; |
288 |
listview_get_item_text (lv, idx, 0, buf, sizeof (buf)-1); |
} |
289 |
set_reg_entry_keyserver ("Default", buf); |
for (i = 0; i < listview_count_items( lv, 0 ); i++) |
290 |
i = kserver_get_port (lv); |
listview_add_sub_item (lv, i, 2, ""); |
291 |
sprintf (port, "%d", i); |
listview_add_sub_item (lv, idx, 2, "x"); |
292 |
set_reg_entry_keyserver ("Default_Port", port); |
listview_get_item_text (lv, idx, 0, buf, sizeof (buf)-1); |
293 |
keyserver_set_default (buf, (u16)i); |
set_reg_entry_keyserver ("Default", buf); |
294 |
return 0; |
i = kserver_get_port (lv); |
295 |
} /* save_default_ks */ |
sprintf (port, "%d", i); |
296 |
|
set_reg_entry_keyserver ("Default_Port", port); |
297 |
|
keyserver_set_default (buf, (u16)i); |
298 |
int |
return 0; |
299 |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
} /* save_default_ks */ |
300 |
{ |
|
301 |
struct listview_column_s keyserver[] = { |
|
302 |
{0, 160, (char *)_("DNS Name")}, |
int |
303 |
{1, 52, (char *)_("Protocol")}, |
keyserver_list_build (listview_ctrl_t *r_lv, HWND hwnd) |
304 |
{2, 46, (char *)_("Default")}, |
{ |
305 |
{3, 46, (char *)_("Port")}, |
struct listview_column_s keyserver[] = { |
306 |
{0, 0, NULL} |
{0, 160, (char *)_("DNS Name")}, |
307 |
}; |
{1, 52, (char *)_("Protocol")}, |
308 |
listview_ctrl_t lv; |
{2, 46, (char *)_("Default")}, |
309 |
char buf[32]; |
{3, 46, (char *)_("Port")}, |
310 |
int j; |
{0, 0, NULL} |
311 |
|
}; |
312 |
listview_new (&lv); |
listview_ctrl_t lv; |
313 |
lv->ctrl = hwnd; |
char buf[32]; |
314 |
for (j=0; keyserver[j].fieldname; j++) |
int j; |
315 |
listview_add_column (lv, &keyserver[j]); |
|
316 |
for (j = 0; j<MAX_KEYSERVERS; j++) { |
listview_new (&lv); |
317 |
if (!server[j].used) |
lv->ctrl = hwnd; |
318 |
continue; |
for (j=0; keyserver[j].fieldname; j++) |
319 |
listview_add_item (lv, " "); |
listview_add_column (lv, &keyserver[j]); |
320 |
listview_add_sub_item (lv, 0, 0, server[j].name); |
for (j = 0; j<MAX_KEYSERVERS; j++) { |
321 |
switch (server[j].proto) { |
if (!server[j].used) |
322 |
case KSPROTO_HTTP: |
continue; |
323 |
listview_add_sub_item( lv, 0, 1, "H" ); break; |
listview_add_item (lv, " "); |
324 |
case KSPROTO_LDAP: |
listview_add_sub_item (lv, 0, 0, server[j].name); |
325 |
listview_add_sub_item( lv, 0, 1, "L" ); break; |
switch (server[j].proto) { |
326 |
case KSPROTO_FINGER: |
case KSPROTO_HTTP: |
327 |
listview_add_sub_item( lv, 0, 1, "F" ); break; |
listview_add_sub_item( lv, 0, 1, "H" ); break; |
328 |
} |
case KSPROTO_LDAP: |
329 |
sprintf (buf, "%d", server[j].port); |
listview_add_sub_item( lv, 0, 1, "L" ); break; |
330 |
listview_add_sub_item (lv, 0, 3, buf); |
case KSPROTO_FINGER: |
331 |
} |
listview_add_sub_item( lv, 0, 1, "F" ); break; |
332 |
load_default_ks (lv); |
} |
333 |
if (listview_count_items (lv, 0) == 0) { |
sprintf (buf, "%d", server[j].port); |
334 |
listview_add_item (lv, ""); |
listview_add_sub_item (lv, 0, 3, buf); |
335 |
listview_add_sub_item (lv, 0, 0, DEF_HKP_KEYSERVER); |
} |
336 |
listview_add_sub_item (lv, 0, 1, "H"); |
load_default_ks (lv); |
337 |
} |
if (listview_count_items (lv, 0) == 0) { |
338 |
listview_set_ext_style (lv); |
listview_add_item (lv, ""); |
339 |
*r_lv = lv; |
listview_add_sub_item (lv, 0, 0, DEF_HKP_KEYSERVER); |
340 |
return 0; |
listview_add_sub_item (lv, 0, 1, "H"); |
341 |
} |
} |
342 |
|
listview_set_ext_style (lv); |
343 |
|
*r_lv = lv; |
344 |
BOOL CALLBACK |
return 0; |
345 |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
} |
346 |
{ |
|
347 |
static listview_ctrl_t lv = NULL; |
|
348 |
static int lv_idx = 0; |
BOOL CALLBACK |
349 |
int rc, proto_nr = 0; |
keyserver_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
350 |
char kserver[128], pattern[128]; |
{ |
351 |
char proto[16]; |
static listview_ctrl_t lv = NULL; |
352 |
keyserver_ctx ksc; |
static int lv_idx = 0; |
353 |
|
int rc, proto_nr = 0; |
354 |
switch ( msg ) { |
char kserver[128], pattern[128]; |
355 |
case WM_INITDIALOG: |
char proto[16]; |
356 |
#ifndef LANG_DE |
keyserver_ctx ksc; |
357 |
SetWindowText( dlg, _("Keyserver Access") ); |
|
358 |
SetDlgItemText( dlg, IDC_KEYSERVER_SEND, |
switch ( msg ) { |
359 |
_("Send key (default is receiving)") ); |
case WM_INITDIALOG: |
360 |
SetDlgItemText( dlg, IDC_KEYSERVER_INFO, |
#ifndef LANG_DE |
361 |
_("Please enter the key ID or email address you search for")); |
SetWindowText (dlg, _("Keyserver Access")); |
362 |
SetDlgItemText( dlg, IDC_KEYSERVER_INDEX, _("&Search") ); |
SetDlgItemText (dlg, IDC_KEYSERVER_RECV, _("&Receive")); |
363 |
#endif |
SetDlgItemText (dlg, IDC_KEYSERVER_SEND, |
364 |
set_proxy (dlg); |
_("Send key (default is receiving)")); |
365 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
SetDlgItemText (dlg, IDC_KEYSERVER_INFO, |
366 |
center_window (dlg, NULL); |
_("Please enter the key ID or email address you search for")); |
367 |
SetForegroundWindow (dlg); |
SetDlgItemText (dlg, IDC_KEYSERVER_INDEX, _("&Search")); |
368 |
return TRUE; |
SetDlgItemText (dlg, IDC_KEYSERVER_PROXSETT, _("C&hange")); |
369 |
|
SetDlgItemText (dlg, IDC_KEYSERVER_DEFAULT, _("Set &default")); |
370 |
case WM_NOTIFY: |
#endif |
371 |
NMHDR *notify; |
set_proxy (dlg); |
372 |
notify = (NMHDR *)lparam; |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
373 |
if( notify && notify->code == NM_CLICK |
center_window (dlg, NULL); |
374 |
&& notify->idFrom == IDC_KEYSERVER_LIST ) |
SetForegroundWindow (dlg); |
375 |
lv_idx = listview_get_curr_pos( lv ); |
return TRUE; |
376 |
return TRUE; |
|
377 |
|
case WM_NOTIFY: |
378 |
case WM_DESTROY: |
NMHDR *notify; |
379 |
if( lv ) { |
notify = (NMHDR *)lparam; |
380 |
listview_release( lv ); |
if( notify && notify->code == NM_CLICK |
381 |
lv = NULL; |
&& notify->idFrom == IDC_KEYSERVER_LIST ) |
382 |
} |
lv_idx = listview_get_curr_pos( lv ); |
383 |
lv_idx = 0; |
return TRUE; |
384 |
return FALSE; |
|
385 |
|
case WM_DESTROY: |
386 |
case WM_SYSCOMMAND: |
if( lv ) { |
387 |
if( LOWORD( wparam ) == SC_CLOSE ) |
listview_release( lv ); |
388 |
EndDialog( dlg, TRUE ); |
lv = NULL; |
389 |
return FALSE; |
} |
390 |
|
lv_idx = 0; |
391 |
case WM_COMMAND: |
return FALSE; |
392 |
switch( LOWORD( wparam ) ) { |
|
393 |
case IDC_KEYSERVER_PROXSETT: |
case WM_SYSCOMMAND: |
394 |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd, |
if( LOWORD( wparam ) == SC_CLOSE ) |
395 |
keyserver_proxy_dlg_proc, NULL, |
EndDialog( dlg, TRUE ); |
396 |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY ); |
return FALSE; |
397 |
set_proxy( dlg ); |
|
398 |
return TRUE; |
case WM_COMMAND: |
399 |
|
switch( LOWORD( wparam ) ) { |
400 |
case IDC_KEYSERVER_INDEX: |
case IDC_KEYSERVER_PROXSETT: |
401 |
if (!lv_idx) { |
dialog_box_param( glob_hinst, (LPCTSTR)IDD_WINPT_KEYSERVER_PROXY, glob_hwnd, |
402 |
lv_idx = kserver_get_pos (lv); |
keyserver_proxy_dlg_proc, NULL, |
403 |
if (lv_idx == -1) { |
_("Proxy Settings"), IDS_WINPT_KEYSERVER_PROXY ); |
404 |
msg_box (dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO); |
set_proxy( dlg ); |
405 |
return FALSE; |
return TRUE; |
406 |
} |
|
407 |
} |
case IDC_KEYSERVER_INDEX: |
408 |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
if (!lv_idx) { |
409 |
if (*proto == 'L') { |
lv_idx = kserver_get_pos (lv); |
410 |
msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR ); |
if (lv_idx == -1) { |
411 |
return FALSE; |
msg_box (dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO); |
412 |
} |
return FALSE; |
413 |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
} |
414 |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
} |
415 |
msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO); |
listview_get_item_text (lv, lv_idx, 1, proto, sizeof (proto)-1); |
416 |
return FALSE; |
if (*proto == 'L') { |
417 |
} |
msg_box( dlg, _("This is not implemented yet!"), _("Keyserver"), MB_ERR ); |
418 |
ksc.name = kserver; |
return FALSE; |
419 |
ksc.pattern = pattern; |
} |
420 |
ksc.port = kserver_get_port (lv); |
listview_get_item_text (lv, lv_idx, 0, kserver, sizeof (kserver)-1); |
421 |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
if (!GetDlgItemText (dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1)) { |
422 |
hkpsearch_dlg_proc, (LPARAM) &ksc ); |
msg_box (dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO); |
423 |
return TRUE; |
return FALSE; |
424 |
|
} |
425 |
case IDC_KEYSERVER_RECV: |
ksc.name = kserver; |
426 |
memset (&kserver, 0, sizeof (kserver)); |
ksc.pattern = pattern; |
427 |
if (!lv_idx) { |
ksc.port = kserver_get_port (lv); |
428 |
lv_idx = kserver_get_pos (lv); |
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_HKPSEARCH, dlg, |
429 |
if (lv_idx == -1) { |
hkpsearch_dlg_proc, (LPARAM) &ksc ); |
430 |
msg_box( dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO ); |
return TRUE; |
431 |
return FALSE; |
|
432 |
} |
case IDC_KEYSERVER_RECV: |
433 |
} |
memset (&kserver, 0, sizeof (kserver)); |
434 |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
if (!lv_idx) { |
435 |
proto_nr = KSPROTO_HTTP; |
lv_idx = kserver_get_pos (lv); |
436 |
if( *proto == 'L' ) |
if (lv_idx == -1) { |
437 |
proto_nr = KSPROTO_LDAP; |
msg_box( dlg, _("Please select one of the keyservers."), _("Keyserver"), MB_INFO ); |
438 |
else if( *proto == 'F' ) |
return FALSE; |
439 |
proto_nr = KSPROTO_FINGER; |
} |
440 |
listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 ); |
} |
441 |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) { |
listview_get_item_text( lv, lv_idx, 1, proto, sizeof (proto)-1 ); |
442 |
msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO ); |
proto_nr = KSPROTO_HTTP; |
443 |
return FALSE; |
if( *proto == 'L' ) |
444 |
} |
proto_nr = KSPROTO_LDAP; |
445 |
if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) { |
else if( *proto == 'F' ) |
446 |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
proto_nr = KSPROTO_FINGER; |
447 |
return FALSE; |
listview_get_item_text( lv, lv_idx, 0, kserver, sizeof (kserver)-1 ); |
448 |
} |
if( !GetDlgItemText( dlg, IDC_KEYSERVER_SEARCH, pattern, sizeof (pattern)-1 ) ) { |
449 |
else if (proto_nr == KSPROTO_FINGER) { |
msg_box( dlg, _("Please enter the search pattern."), _("Keyserver"), MB_INFO ); |
450 |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
return FALSE; |
451 |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
} |
452 |
return FALSE; |
if( proto_nr == KSPROTO_LDAP && strchr( pattern, '@' ) ) { |
453 |
} |
msg_box( dlg, _("Only keyids are allowed."), _("LDAP Keyserver"), MB_INFO ); |
454 |
} |
return FALSE; |
455 |
else if( check_pattern( pattern ) ) { |
} |
456 |
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
else if (proto_nr == KSPROTO_FINGER) { |
457 |
return FALSE; |
if (strchr (pattern, '@') || strchr (pattern, ' ')) { |
458 |
} |
msg_box (dlg, _("Only enter the name of the user."), _("FINGER Keyserver"), MB_INFO); |
459 |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
return FALSE; |
460 |
if (!rc) |
} |
461 |
keycache_set_reload (1); |
} |
462 |
return TRUE; |
else if( check_pattern( pattern ) ) { |
463 |
|
msg_box( dlg, _("Only email addresses or keyids are allowed."), _("HKP Keyserver"), MB_INFO ); |
464 |
case IDC_KEYSERVER_DEFAULT: |
return FALSE; |
465 |
save_default_ks( lv ); |
} |
466 |
break; |
rc = hkp_recv_key (dlg, kserver, kserver_get_port (lv), pattern, proto_nr, 0); |
467 |
|
if (!rc) |
468 |
case IDCANCEL: |
keycache_set_reload (1); |
469 |
EndDialog( dlg, FALSE ); |
return TRUE; |
470 |
return FALSE; |
|
471 |
} |
case IDC_KEYSERVER_DEFAULT: |
472 |
break; |
save_default_ks( lv ); |
473 |
} |
break; |
474 |
|
|
475 |
return FALSE; |
case IDCANCEL: |
476 |
} /* keyserver_dlg_proc */ |
EndDialog( dlg, FALSE ); |
477 |
|
return FALSE; |
478 |
|
} |
479 |
|
break; |
480 |
|
} |
481 |
|
|
482 |
|
return FALSE; |
483 |
|
} /* keyserver_dlg_proc */ |