36 |
#include "wptW32API.h" |
#include "wptW32API.h" |
37 |
#include "wptGPG.h" |
#include "wptGPG.h" |
38 |
#include "wptRegistry.h" |
#include "wptRegistry.h" |
39 |
|
#include "wptUTF8.h" |
40 |
|
|
41 |
/* Map net_errno to a winsock error. */ |
/* Map net_errno to a winsock error. */ |
42 |
#define net_errno ((int)WSAGetLastError ()) |
#define net_errno ((int)WSAGetLastError ()) |
160 |
return hostname; |
return hostname; |
161 |
} |
} |
162 |
|
|
163 |
|
/* Parse the keyserver response and extract the human |
164 |
|
readable text passages. */ |
165 |
|
static int |
166 |
|
parse_keyserver_error (const char *resp, char *txt, size_t txtlen) |
167 |
|
{ |
168 |
|
char *p, *p2; |
169 |
|
|
170 |
|
/* If we find no 'Error' substring, we assume a success. */ |
171 |
|
if (!stristr (resp, "Error")) |
172 |
|
return 0; |
173 |
|
|
174 |
|
memset (txt, 0, txtlen); |
175 |
|
p = strstr (resp, "\r\n\r\n"); |
176 |
|
if (!p) |
177 |
|
return -1; |
178 |
|
resp += (p-resp); |
179 |
|
p = strstr (resp, "<h1>"); |
180 |
|
if (!p) |
181 |
|
return -1; |
182 |
|
resp += (p-resp)+strlen ("<h1>"); |
183 |
|
p = strstr (resp, "</h1>"); |
184 |
|
if (!p) |
185 |
|
return -1; |
186 |
|
resp += (p-resp)+strlen ("</h1>"); |
187 |
|
p2 = strstr (resp, "</body>"); |
188 |
|
if (p2 != NULL) |
189 |
|
memcpy (txt, resp, (p2-resp)); |
190 |
|
else { |
191 |
|
if (!strnicmp (resp, "<p>", 3)) |
192 |
|
resp += 3; |
193 |
|
while (resp && *resp == '\r' || *resp == '\n') |
194 |
|
resp++; |
195 |
|
memcpy (txt, resp, strlen (resp)); |
196 |
|
} |
197 |
|
return 0; |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
/* Check that the keyserver response indicates an OK. |
/* Check that the keyserver response indicates an OK. |
202 |
Return 0 on success. */ |
Return 0 on success. */ |
203 |
static int |
static int |
204 |
check_hkp_response (const char *resp, int recv) |
check_hkp_response (const char *resp, int recv) |
205 |
{ |
{ |
206 |
char *p, *end; |
int ec; |
|
int ec, len; |
|
207 |
|
|
208 |
log_debug ("check_hkp_response: '%s'\r\n", resp); |
log_debug ("check_hkp_response: '%s'\r\n", resp); |
209 |
ec = recv ? WPTERR_WINSOCK_RECVKEY : WPTERR_WINSOCK_SENDKEY; |
ec = recv ? WPTERR_WINSOCK_RECVKEY : WPTERR_WINSOCK_SENDKEY; |
210 |
if (!strstr (resp, "HTTP/1.0 200 OK") && |
if (!strstr (resp, "HTTP/1.0 200 OK") && |
211 |
!strstr (resp, "HTTP/1.1 200 OK")) /* http error */ |
!strstr (resp, "HTTP/1.1 200 OK") && |
212 |
return ec; |
!strstr (resp, "HTTP/1.0 500 OK") && |
213 |
if (strstr (resp, "Public Key Server -- Error") |
!strstr (resp, "HTTP/1.1 500 OK")) |
214 |
|| strstr (resp, "Public Key Server -- Error") |
return ec; /* http error */ |
215 |
|| strstr (resp, "No matching keys in database")) { |
|
216 |
p = strstr (resp, "<p>"); |
if (parse_keyserver_error (resp, hkp_errmsg, sizeof (hkp_errmsg)-2)) { |
217 |
if (p && strlen (p) < sizeof (hkp_errmsg)-1) { |
if (!strlen (hkp_errmsg)) |
218 |
end = strstr (p, "</p>"); |
_snprintf (hkp_errmsg, sizeof (hkp_errmsg)-1, |
219 |
len = end? (end - p + 1) : strlen (p); |
"Unknown keyserver error"); |
220 |
memset (hkp_errmsg, 0, sizeof (hkp_errmsg)); |
hkp_err = 1; |
|
strncpy (hkp_errmsg, p, len); |
|
|
hkp_err = 1; |
|
|
} |
|
221 |
return ec; |
return ec; |
222 |
} |
} |
223 |
return 0; |
return 0; |
560 |
port_from_proto (int proto) |
port_from_proto (int proto) |
561 |
{ |
{ |
562 |
switch (proto) { |
switch (proto) { |
563 |
case KSPROTO_LDAP: return 0; |
case KSPROTO_LDAP: return LDAP_PORT; |
564 |
case KSPROTO_FINGER: return FINGER_PORT; |
case KSPROTO_FINGER: return FINGER_PORT; |
565 |
case KSPROTO_HTTP: return HKP_PORT; |
case KSPROTO_HTTP: return HKP_PORT; |
566 |
} |
} |
574 |
{ |
{ |
575 |
if (strstr (buf, "ldap")) |
if (strstr (buf, "ldap")) |
576 |
return KSPROTO_LDAP; |
return KSPROTO_LDAP; |
577 |
else if (strstr( buf, "finger")) |
else if (strstr (buf, "finger")) |
578 |
return KSPROTO_FINGER; |
return KSPROTO_FINGER; |
579 |
return KSPROTO_HKP; |
return KSPROTO_HKP; |
580 |
} |
} |
1205 |
{ |
{ |
1206 |
enum uid_rec_t {ID=1, UID, CREATE, EXPIRE}; |
enum uid_rec_t {ID=1, UID, CREATE, EXPIRE}; |
1207 |
keyserver_uid_s *u, *n; |
keyserver_uid_s *u, *n; |
1208 |
char *p; |
char *p, *raw; |
1209 |
int recno = 0; |
int recno = 0; |
1210 |
|
|
1211 |
/* uid:Timo Schulz <[email protected]>:1138440360:: */ |
/* uid:Timo Schulz <[email protected]>:1138440360:: */ |
1221 |
break; |
break; |
1222 |
|
|
1223 |
case UID: |
case UID: |
1224 |
unhexify_buffer (p, &u->uid); |
unhexify_buffer (p, &raw); |
1225 |
|
u->uid = utf8_to_native (raw); |
1226 |
|
free_if_alloc (raw); |
1227 |
break; |
break; |
1228 |
|
|
1229 |
case CREATE: |
case CREATE: |
1541 |
{ |
{ |
1542 |
char *p; |
char *p; |
1543 |
char *url = *r_keyserver; |
char *url = *r_keyserver; |
1544 |
|
int off = 0; |
1545 |
|
|
1546 |
/* no port is given so use the default port. */ |
/* no port is given so use the default port. */ |
1547 |
p = strrchr (url, ':'); |
p = strrchr (url, ':'); |
1552 |
*r_port = port; |
*r_port = port; |
1553 |
return 0; |
return 0; |
1554 |
} |
} |
1555 |
/* XXX: remove / in .de/:11371 */ |
|
1556 |
*r_keyserver = substr (url, 0, (p-url)); |
if (url[(p-url)-1] == '/') /* remove / in .de/:11371 */ |
1557 |
|
off = 1; |
1558 |
|
|
1559 |
|
*r_keyserver = substr (url, 0, (p-url)-off); |
1560 |
*r_port = atoi (url+(p-url)+1); |
*r_port = atoi (url+(p-url)+1); |
1561 |
free_if_alloc (url); |
free_if_alloc (url); |
1562 |
return 0; |
return 0; |