|
Lines 26-32
Link Here
|
| 26 |
from The Open Group. |
26 |
from The Open Group. |
| 27 |
|
27 |
|
| 28 |
*/ |
28 |
*/ |
| 29 |
/* $XFree86: xc/programs/xdm/xdmcp.c,v 3.21 2002/12/10 22:37:17 tsi Exp $ */ |
29 |
/* $Id: xc/programs/xdm/xdmcp.c,v 3.21 2002/12/10 22:37:17 tsi Exp $ */ |
| 30 |
|
30 |
|
| 31 |
/* |
31 |
/* |
| 32 |
* xdm - display manager daemon |
32 |
* xdm - display manager daemon |
|
Lines 55-68
Link Here
|
| 55 |
#include <un.h> |
55 |
#include <un.h> |
| 56 |
#endif |
56 |
#endif |
| 57 |
#endif |
57 |
#endif |
| 58 |
#if defined(__SVR4) && defined(__sun) |
|
|
| 59 |
/* |
| 60 |
* make sure we get the resolver's version of gethostbyname |
| 61 |
* otherwise we may not get all the addresses! |
| 62 |
*/ |
| 63 |
#define gethostbyname res_gethostbyname |
| 64 |
#endif |
| 65 |
#include <netdb.h> |
58 |
#include <netdb.h> |
|
|
59 |
#ifdef IPv6 |
| 60 |
#include <arpa/inet.h> |
| 61 |
#endif |
| 66 |
|
62 |
|
| 67 |
#include <time.h> |
63 |
#include <time.h> |
| 68 |
#define Time_t time_t |
64 |
#define Time_t time_t |
|
Lines 72-98
Link Here
|
| 72 |
/* |
68 |
/* |
| 73 |
* misc externs |
69 |
* misc externs |
| 74 |
*/ |
70 |
*/ |
| 75 |
extern int Rescan, ChildReady; |
71 |
extern volatile int Rescan; |
| 76 |
extern int sourceAddress; |
72 |
extern int sourceAddress, ChildReady; |
| 77 |
|
73 |
|
| 78 |
/* |
74 |
/* |
| 79 |
* Forward reference |
75 |
* Forward reference |
| 80 |
*/ |
76 |
*/ |
| 81 |
static void broadcast_respond (struct sockaddr *from, int fromlen, int length); |
77 |
static void broadcast_respond (struct sockaddr *from, int fromlen, int length, int fd); |
| 82 |
static void forward_respond (struct sockaddr *from, int fromlen, int length); |
78 |
static void forward_respond (struct sockaddr *from, int fromlen, int length, int fd); |
| 83 |
static void manage (struct sockaddr *from, int fromlen, int length); |
79 |
static void manage (struct sockaddr *from, int fromlen, int length, int fd); |
| 84 |
static void query_respond (struct sockaddr *from, int fromlen, int length); |
80 |
static void query_respond (struct sockaddr *from, int fromlen, int length, int fd); |
| 85 |
static void request_respond (struct sockaddr *from, int fromlen, int length); |
81 |
static void request_respond (struct sockaddr *from, int fromlen, int length, int fd); |
| 86 |
static void send_accept (struct sockaddr *to, int tolen, CARD32 sessionID, ARRAY8Ptr authenticationName, ARRAY8Ptr authenticationData, ARRAY8Ptr authorizationName, ARRAY8Ptr authorizationData); |
82 |
static void send_accept (struct sockaddr *to, int tolen, CARD32 sessionID, ARRAY8Ptr authenticationName, ARRAY8Ptr authenticationData, ARRAY8Ptr authorizationName, ARRAY8Ptr authorizationData, int fd); |
| 87 |
static void send_alive (struct sockaddr *from, int fromlen, int length); |
83 |
static void send_alive (struct sockaddr *from, int fromlen, int length, int fd); |
| 88 |
static void send_decline (struct sockaddr *to, int tolen, ARRAY8Ptr authenticationName, ARRAY8Ptr authenticationData, ARRAY8Ptr status); |
84 |
static void send_decline (struct sockaddr *to, int tolen, ARRAY8Ptr authenticationName, ARRAY8Ptr authenticationData, ARRAY8Ptr status, int fd); |
| 89 |
static void send_failed (struct sockaddr *from, int fromlen, char *name, CARD32 sessionID, char *reason); |
85 |
static void send_failed (struct sockaddr *from, int fromlen, char *name, CARD32 sessionID, char *reason, int fd); |
| 90 |
static void send_refuse (struct sockaddr *from, int fromlen, CARD32 sessionID); |
86 |
static void send_refuse (struct sockaddr *from, int fromlen, CARD32 sessionID, int fd); |
| 91 |
static void send_unwilling (struct sockaddr *from, int fromlen, ARRAY8Ptr authenticationName, ARRAY8Ptr status); |
87 |
static void send_unwilling (struct sockaddr *from, int fromlen, ARRAY8Ptr authenticationName, ARRAY8Ptr status, int fd); |
| 92 |
static void send_willing (struct sockaddr *from, int fromlen, ARRAY8Ptr authenticationName, ARRAY8Ptr status); |
88 |
static void send_willing (struct sockaddr *from, int fromlen, ARRAY8Ptr authenticationName, ARRAY8Ptr status, int fd); |
| 93 |
|
|
|
| 94 |
|
89 |
|
|
|
90 |
#ifdef STREAMSCONN |
| 95 |
int xdmcpFd = -1; |
91 |
int xdmcpFd = -1; |
|
|
92 |
#endif |
| 96 |
int chooserFd = -1; |
93 |
int chooserFd = -1; |
| 97 |
|
94 |
|
| 98 |
FD_TYPE WellKnownSocketsMask; |
95 |
FD_TYPE WellKnownSocketsMask; |
|
Lines 103-124
Link Here
|
| 103 |
void |
100 |
void |
| 104 |
DestroyWellKnownSockets (void) |
101 |
DestroyWellKnownSockets (void) |
| 105 |
{ |
102 |
{ |
|
|
103 |
#ifdef STREAMSCONN |
| 106 |
if (xdmcpFd != -1) |
104 |
if (xdmcpFd != -1) |
| 107 |
{ |
105 |
{ |
| 108 |
close (xdmcpFd); |
106 |
close (xdmcpFd); |
|
|
107 |
FD_CLR(xdmcpFd, &WellKnownSocketsMask); |
| 109 |
xdmcpFd = -1; |
108 |
xdmcpFd = -1; |
| 110 |
} |
109 |
} |
|
|
110 |
#endif |
| 111 |
if (chooserFd != -1) |
111 |
if (chooserFd != -1) |
| 112 |
{ |
112 |
{ |
| 113 |
close (chooserFd); |
113 |
close (chooserFd); |
|
|
114 |
FD_CLR(chooserFd, &WellKnownSocketsMask); |
| 114 |
chooserFd = -1; |
115 |
chooserFd = -1; |
| 115 |
} |
116 |
} |
|
|
117 |
CloseListenSockets(); |
| 118 |
} |
| 119 |
|
| 120 |
static int |
| 121 |
FD_ANYSET(fd_set *fds) |
| 122 |
{ |
| 123 |
int i; |
| 124 |
char *mask = (char *) fds; |
| 125 |
|
| 126 |
for (i = 0 ; i < sizeof(fds); i++) { |
| 127 |
if (mask[i]) |
| 128 |
return TRUE; |
| 129 |
} |
| 130 |
return FALSE; |
| 116 |
} |
131 |
} |
| 117 |
|
132 |
|
| 118 |
int |
133 |
int |
| 119 |
AnyWellKnownSockets (void) |
134 |
AnyWellKnownSockets (void) |
| 120 |
{ |
135 |
{ |
| 121 |
return xdmcpFd != -1 || chooserFd != -1; |
136 |
return |
|
|
137 |
#ifdef STREAMS_CONN |
| 138 |
xdmcpFd != -1 || |
| 139 |
#endif |
| 140 |
chooserFd != -1 || FD_ANYSET(&WellKnownSocketsMask); |
| 122 |
} |
141 |
} |
| 123 |
|
142 |
|
| 124 |
static XdmcpBuffer buffer; |
143 |
static XdmcpBuffer buffer; |
|
Lines 133-138
Link Here
|
| 133 |
#ifdef AF_INET |
152 |
#ifdef AF_INET |
| 134 |
struct sockaddr_in in_addr; |
153 |
struct sockaddr_in in_addr; |
| 135 |
#endif |
154 |
#endif |
|
|
155 |
#ifdef IPv6 |
| 156 |
struct sockaddr_in6 in6_addr; |
| 157 |
#endif |
| 136 |
#ifdef AF_DECnet |
158 |
#ifdef AF_DECnet |
| 137 |
#endif |
159 |
#endif |
| 138 |
struct sockaddr *addr; |
160 |
struct sockaddr *addr; |
|
Lines 155-167
Link Here
|
| 155 |
addrlen = sizeof (struct sockaddr_in); |
177 |
addrlen = sizeof (struct sockaddr_in); |
| 156 |
break; |
178 |
break; |
| 157 |
#endif |
179 |
#endif |
|
|
180 |
#ifdef IPv6 |
| 181 |
case FamilyInternetV6: |
| 182 |
addr = (struct sockaddr *) &in6_addr; |
| 183 |
bzero ((char *) &in6_addr, sizeof (in6_addr)); |
| 184 |
#ifdef SIN6_LEN |
| 185 |
in6_addr.sin6_len = sizeof(in6_addr); |
| 186 |
#endif |
| 187 |
in6_addr.sin6_family = AF_INET6; |
| 188 |
in6_addr.sin6_port = htons ((short) XDM_UDP_PORT); |
| 189 |
if (address->length != 16) |
| 190 |
return; |
| 191 |
memmove( (char *) &in6_addr.sin6_addr, address->data, address->length); |
| 192 |
addrlen = sizeof (struct sockaddr_in6); |
| 193 |
break; |
| 194 |
#endif |
| 158 |
#ifdef AF_DECnet |
195 |
#ifdef AF_DECnet |
| 159 |
case FamilyDECnet: |
196 |
case FamilyDECnet: |
| 160 |
#endif |
197 |
#endif |
| 161 |
default: |
198 |
default: |
| 162 |
return; |
199 |
return; |
| 163 |
} |
200 |
} |
| 164 |
XdmcpFlush (xdmcpFd, &buffer, (XdmcpNetaddr) addr, addrlen); |
201 |
XdmcpFlush (*((int *) closure), &buffer, (XdmcpNetaddr) addr, addrlen); |
| 165 |
return; |
202 |
return; |
| 166 |
} |
203 |
} |
| 167 |
|
204 |
|
|
Lines 193-199
Link Here
|
| 193 |
struct sockaddr *from, |
230 |
struct sockaddr *from, |
| 194 |
int fromlen, |
231 |
int fromlen, |
| 195 |
ARRAYofARRAY8Ptr authenticationNames, |
232 |
ARRAYofARRAY8Ptr authenticationNames, |
| 196 |
xdmOpCode type) |
233 |
xdmOpCode type, |
|
|
234 |
int fd) |
| 197 |
{ |
235 |
{ |
| 198 |
ARRAY8Ptr authenticationName; |
236 |
ARRAY8Ptr authenticationName; |
| 199 |
ARRAY8 status; |
237 |
ARRAY8 status; |
|
Lines 217-226
Link Here
|
| 217 |
|
255 |
|
| 218 |
authenticationName = ChooseAuthentication (authenticationNames); |
256 |
authenticationName = ChooseAuthentication (authenticationNames); |
| 219 |
if (Willing (&addr, connectionType, authenticationName, &status, type)) |
257 |
if (Willing (&addr, connectionType, authenticationName, &status, type)) |
| 220 |
send_willing (from, fromlen, authenticationName, &status); |
258 |
send_willing (from, fromlen, authenticationName, &status, fd); |
| 221 |
else |
259 |
else |
| 222 |
if (type == QUERY) |
260 |
if (type == QUERY) |
| 223 |
send_unwilling (from, fromlen, authenticationName, &status); |
261 |
send_unwilling (from, fromlen, authenticationName, &status, fd); |
| 224 |
XdmcpDisposeARRAY8 (&status); |
262 |
XdmcpDisposeARRAY8 (&status); |
| 225 |
} |
263 |
} |
| 226 |
|
264 |
|
|
Lines 228-234
Link Here
|
| 228 |
indirect_respond ( |
266 |
indirect_respond ( |
| 229 |
struct sockaddr *from, |
267 |
struct sockaddr *from, |
| 230 |
int fromlen, |
268 |
int fromlen, |
| 231 |
int length) |
269 |
int length, |
|
|
270 |
int fd) |
| 232 |
{ |
271 |
{ |
| 233 |
ARRAYofARRAY8 queryAuthenticationNames; |
272 |
ARRAYofARRAY8 queryAuthenticationNames; |
| 234 |
ARRAY8 clientAddress; |
273 |
ARRAY8 clientAddress; |
|
Lines 264-276
Link Here
|
| 264 |
XdmcpWriteARRAY8 (&buffer, &clientPort); |
303 |
XdmcpWriteARRAY8 (&buffer, &clientPort); |
| 265 |
XdmcpWriteARRAYofARRAY8 (&buffer, &queryAuthenticationNames); |
304 |
XdmcpWriteARRAYofARRAY8 (&buffer, &queryAuthenticationNames); |
| 266 |
|
305 |
|
| 267 |
localHostAsWell = ForEachMatchingIndirectHost (&clientAddress, connectionType, sendForward, (char *) 0); |
306 |
localHostAsWell = ForEachMatchingIndirectHost (&clientAddress, connectionType, sendForward, (char *) &fd); |
| 268 |
|
307 |
|
| 269 |
XdmcpDisposeARRAY8 (&clientAddress); |
308 |
XdmcpDisposeARRAY8 (&clientAddress); |
| 270 |
XdmcpDisposeARRAY8 (&clientPort); |
309 |
XdmcpDisposeARRAY8 (&clientPort); |
| 271 |
if (localHostAsWell) |
310 |
if (localHostAsWell) |
| 272 |
all_query_respond (from, fromlen, &queryAuthenticationNames, |
311 |
all_query_respond (from, fromlen, &queryAuthenticationNames, |
| 273 |
INDIRECT_QUERY); |
312 |
INDIRECT_QUERY, fd); |
| 274 |
} |
313 |
} |
| 275 |
else |
314 |
else |
| 276 |
{ |
315 |
{ |
|
Lines 279-294
Link Here
|
| 279 |
XdmcpDisposeARRAYofARRAY8 (&queryAuthenticationNames); |
318 |
XdmcpDisposeARRAYofARRAY8 (&queryAuthenticationNames); |
| 280 |
} |
319 |
} |
| 281 |
|
320 |
|
| 282 |
static void |
321 |
void |
| 283 |
ProcessRequestSocket (void) |
322 |
ProcessRequestSocket (int fd) |
| 284 |
{ |
323 |
{ |
| 285 |
XdmcpHeader header; |
324 |
XdmcpHeader header; |
|
|
325 |
#ifdef IPv6 |
| 326 |
struct sockaddr_storage addr; |
| 327 |
#else |
| 286 |
struct sockaddr addr; |
328 |
struct sockaddr addr; |
|
|
329 |
#endif |
| 287 |
int addrlen = sizeof addr; |
330 |
int addrlen = sizeof addr; |
| 288 |
|
331 |
|
| 289 |
Debug ("ProcessRequestSocket\n"); |
332 |
Debug ("ProcessRequestSocket\n"); |
| 290 |
bzero ((char *) &addr, sizeof (addr)); |
333 |
bzero ((char *) &addr, sizeof (addr)); |
| 291 |
if (!XdmcpFill (xdmcpFd, &buffer, (XdmcpNetaddr) &addr, &addrlen)) { |
334 |
if (!XdmcpFill (fd, &buffer, (XdmcpNetaddr) &addr, &addrlen)) { |
| 292 |
Debug ("XdmcpFill failed\n"); |
335 |
Debug ("XdmcpFill failed\n"); |
| 293 |
return; |
336 |
return; |
| 294 |
} |
337 |
} |
|
Lines 305-329
Link Here
|
| 305 |
switch (header.opcode) |
348 |
switch (header.opcode) |
| 306 |
{ |
349 |
{ |
| 307 |
case BROADCAST_QUERY: |
350 |
case BROADCAST_QUERY: |
| 308 |
broadcast_respond (&addr, addrlen, header.length); |
351 |
broadcast_respond ((struct sockaddr *) &addr, addrlen, header.length, fd); |
| 309 |
break; |
352 |
break; |
| 310 |
case QUERY: |
353 |
case QUERY: |
| 311 |
query_respond (&addr, addrlen, header.length); |
354 |
query_respond ((struct sockaddr *) &addr, addrlen, header.length, fd); |
| 312 |
break; |
355 |
break; |
| 313 |
case INDIRECT_QUERY: |
356 |
case INDIRECT_QUERY: |
| 314 |
indirect_respond (&addr, addrlen, header.length); |
357 |
indirect_respond ((struct sockaddr *) &addr, addrlen, header.length, fd); |
| 315 |
break; |
358 |
break; |
| 316 |
case FORWARD_QUERY: |
359 |
case FORWARD_QUERY: |
| 317 |
forward_respond (&addr, addrlen, header.length); |
360 |
forward_respond ((struct sockaddr *) &addr, addrlen, header.length, fd); |
| 318 |
break; |
361 |
break; |
| 319 |
case REQUEST: |
362 |
case REQUEST: |
| 320 |
request_respond (&addr, addrlen, header.length); |
363 |
request_respond ((struct sockaddr *) &addr, addrlen, header.length, fd); |
| 321 |
break; |
364 |
break; |
| 322 |
case MANAGE: |
365 |
case MANAGE: |
| 323 |
manage (&addr, addrlen, header.length); |
366 |
manage ((struct sockaddr *) &addr, addrlen, header.length, fd); |
| 324 |
break; |
367 |
break; |
| 325 |
case KEEPALIVE: |
368 |
case KEEPALIVE: |
| 326 |
send_alive (&addr, addrlen, header.length); |
369 |
send_alive ((struct sockaddr *) &addr, addrlen, header.length, fd); |
| 327 |
break; |
370 |
break; |
| 328 |
} |
371 |
} |
| 329 |
} |
372 |
} |
|
Lines 342-356
Link Here
|
| 342 |
nready, Rescan, ChildReady); |
385 |
nready, Rescan, ChildReady); |
| 343 |
if (nready > 0) |
386 |
if (nready > 0) |
| 344 |
{ |
387 |
{ |
|
|
388 |
#ifdef STREAMSCONN |
| 345 |
if (xdmcpFd >= 0 && FD_ISSET (xdmcpFd, &reads)) |
389 |
if (xdmcpFd >= 0 && FD_ISSET (xdmcpFd, &reads)) |
| 346 |
ProcessRequestSocket (); |
390 |
ProcessRequestSocket (); |
|
|
391 |
#endif |
| 347 |
if (chooserFd >= 0 && FD_ISSET (chooserFd, &reads)) |
392 |
if (chooserFd >= 0 && FD_ISSET (chooserFd, &reads)) |
|
|
393 |
{ |
| 348 |
#ifdef ISC |
394 |
#ifdef ISC |
| 349 |
if (!ChildReady) { |
395 |
if (!ChildReady) { |
| 350 |
WaitForSomething (); |
396 |
WaitForSomething (); |
| 351 |
} else |
397 |
} else |
| 352 |
#endif |
398 |
#endif |
| 353 |
ProcessChooserSocket (chooserFd); |
399 |
ProcessChooserSocket (chooserFd); |
|
|
400 |
FD_CLR(chooserFd, &reads); |
| 401 |
} |
| 402 |
ProcessListenSockets(&reads); |
| 354 |
} |
403 |
} |
| 355 |
if (ChildReady) |
404 |
if (ChildReady) |
| 356 |
{ |
405 |
{ |
|
Lines 384-390
Link Here
|
| 384 |
struct sockaddr *from, |
433 |
struct sockaddr *from, |
| 385 |
int fromlen, |
434 |
int fromlen, |
| 386 |
int length, |
435 |
int length, |
| 387 |
xdmOpCode type) |
436 |
xdmOpCode type, |
|
|
437 |
int fd) |
| 388 |
{ |
438 |
{ |
| 389 |
ARRAYofARRAY8 queryAuthenticationNames; |
439 |
ARRAYofARRAY8 queryAuthenticationNames; |
| 390 |
int expectedLen; |
440 |
int expectedLen; |
|
Lines 396-402
Link Here
|
| 396 |
for (i = 0; i < (int)queryAuthenticationNames.length; i++) |
446 |
for (i = 0; i < (int)queryAuthenticationNames.length; i++) |
| 397 |
expectedLen += 2 + queryAuthenticationNames.data[i].length; |
447 |
expectedLen += 2 + queryAuthenticationNames.data[i].length; |
| 398 |
if (length == expectedLen) |
448 |
if (length == expectedLen) |
| 399 |
all_query_respond (from, fromlen, &queryAuthenticationNames, type); |
449 |
all_query_respond (from, fromlen, &queryAuthenticationNames, type, fd); |
| 400 |
XdmcpDisposeARRAYofARRAY8 (&queryAuthenticationNames); |
450 |
XdmcpDisposeARRAYofARRAY8 (&queryAuthenticationNames); |
| 401 |
} |
451 |
} |
| 402 |
|
452 |
|
|
Lines 404-422
Link Here
|
| 404 |
query_respond ( |
454 |
query_respond ( |
| 405 |
struct sockaddr *from, |
455 |
struct sockaddr *from, |
| 406 |
int fromlen, |
456 |
int fromlen, |
| 407 |
int length) |
457 |
int length, |
|
|
458 |
int fd) |
| 408 |
{ |
459 |
{ |
| 409 |
Debug ("Query respond %d\n", length); |
460 |
Debug ("Query respond %d\n", length); |
| 410 |
direct_query_respond (from, fromlen, length, QUERY); |
461 |
direct_query_respond (from, fromlen, length, QUERY, fd); |
| 411 |
} |
462 |
} |
| 412 |
|
463 |
|
| 413 |
static void |
464 |
static void |
| 414 |
broadcast_respond ( |
465 |
broadcast_respond ( |
| 415 |
struct sockaddr *from, |
466 |
struct sockaddr *from, |
| 416 |
int fromlen, |
467 |
int fromlen, |
| 417 |
int length) |
468 |
int length, |
|
|
469 |
int fd) |
| 418 |
{ |
470 |
{ |
| 419 |
direct_query_respond (from, fromlen, length, BROADCAST_QUERY); |
471 |
direct_query_respond (from, fromlen, length, BROADCAST_QUERY, fd); |
| 420 |
} |
472 |
} |
| 421 |
|
473 |
|
| 422 |
/* computes an X display name */ |
474 |
/* computes an X display name */ |
|
Lines 431-436
Link Here
|
| 431 |
switch (connectionType) |
483 |
switch (connectionType) |
| 432 |
{ |
484 |
{ |
| 433 |
case FamilyInternet: |
485 |
case FamilyInternet: |
|
|
486 |
#ifdef IPv6 |
| 487 |
case FamilyInternetV6: |
| 488 |
{ |
| 489 |
CARD8 *data; |
| 490 |
struct hostent *hostent; |
| 491 |
char *hostname = NULL; |
| 492 |
char *name; |
| 493 |
char *localhost; |
| 494 |
int multiHomed = 0; |
| 495 |
struct addrinfo hints, *ai = NULL, *nai; |
| 496 |
int type; |
| 497 |
|
| 498 |
if (connectionType == FamilyInternetV6) |
| 499 |
type = AF_INET6; |
| 500 |
else |
| 501 |
type = AF_INET; |
| 502 |
|
| 503 |
data = connectionAddress->data; |
| 504 |
hostent = gethostbyaddr ((char *)data, |
| 505 |
connectionAddress->length, type); |
| 506 |
if (hostent) { |
| 507 |
if (sourceAddress) { |
| 508 |
bzero(&hints, sizeof(hints)); |
| 509 |
hints.ai_flags = AI_CANONNAME; |
| 510 |
if (getaddrinfo(hostent->h_name, NULL, &hints, &ai) == 0) { |
| 511 |
hostname = ai->ai_canonname; |
| 512 |
while ((nai = ai->ai_next) != NULL) { |
| 513 |
if ((ai->ai_protocol == nai->ai_protocol) && |
| 514 |
(ai->ai_addrlen == nai->ai_addrlen) && |
| 515 |
(memcmp(ai->ai_addr,nai->ai_addr, |
| 516 |
ai->ai_addrlen) != 0) ) { |
| 517 |
multiHomed = 1; |
| 518 |
} |
| 519 |
} |
| 520 |
} |
| 521 |
} else { |
| 522 |
hostname = hostent->h_name; |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
localhost = localHostname (); |
| 527 |
|
| 528 |
/* |
| 529 |
* protect against bogus host names |
| 530 |
*/ |
| 531 |
if (hostname && hostname[0] && (hostname[0] != '.') |
| 532 |
&& !multiHomed) |
| 533 |
{ |
| 534 |
if (!strcmp (localhost, hostname)) |
| 535 |
{ |
| 536 |
if (!getString (name, 10)) |
| 537 |
return 0; |
| 538 |
sprintf (name, ":%d", displayNumber); |
| 539 |
} |
| 540 |
else |
| 541 |
{ |
| 542 |
if (removeDomainname) |
| 543 |
{ |
| 544 |
char *localDot, *remoteDot; |
| 545 |
|
| 546 |
/* check for a common domain name. This |
| 547 |
* could reduce names by recognising common |
| 548 |
* super-domain names as well, but I don't think |
| 549 |
* this is as useful, and will confuse more |
| 550 |
* people |
| 551 |
*/ |
| 552 |
if ((localDot = strchr(localhost, '.')) && |
| 553 |
(remoteDot = strchr(hostname, '.'))) |
| 554 |
{ |
| 555 |
/* smash the name in place; it won't |
| 556 |
* be needed later. |
| 557 |
*/ |
| 558 |
if (!strcmp (localDot+1, remoteDot+1)) |
| 559 |
*remoteDot = '\0'; |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
if (!getString (name, strlen (hostname) + 10)) |
| 564 |
return 0; |
| 565 |
sprintf (name, "%s:%d", hostname, displayNumber); |
| 566 |
} |
| 567 |
} |
| 568 |
else |
| 569 |
{ |
| 570 |
if (!getString (name, INET6_ADDRSTRLEN + 10)) |
| 571 |
return 0; |
| 572 |
if (multiHomed) { |
| 573 |
if (connectionType == FamilyInternet) { |
| 574 |
data = (CARD8 *) |
| 575 |
&((struct sockaddr_in *)originalAddress)-> |
| 576 |
sin_addr; |
| 577 |
} else { |
| 578 |
data = (CARD8 *) |
| 579 |
&((struct sockaddr_in6 *)originalAddress)->sin6_addr; |
| 580 |
} |
| 581 |
} |
| 582 |
if (inet_ntop(type, data, name, INET6_ADDRSTRLEN) == NULL) { |
| 583 |
free(name); |
| 584 |
return 0; |
| 585 |
} |
| 586 |
sprintf(name + strlen(name), ":%d", displayNumber); |
| 587 |
} |
| 588 |
if (ai) |
| 589 |
freeaddrinfo(ai); |
| 590 |
return name; |
| 591 |
} |
| 592 |
#else /* IPv6 */ |
| 434 |
{ |
593 |
{ |
| 435 |
CARD8 *data; |
594 |
CARD8 *data; |
| 436 |
struct hostent *hostent; |
595 |
struct hostent *hostent; |
|
Lines 502-507
Link Here
|
| 502 |
} |
661 |
} |
| 503 |
return name; |
662 |
return name; |
| 504 |
} |
663 |
} |
|
|
664 |
#endif /* IPv6 */ |
| 505 |
#ifdef DNET |
665 |
#ifdef DNET |
| 506 |
case FamilyDECnet: |
666 |
case FamilyDECnet: |
| 507 |
return NULL; |
667 |
return NULL; |
|
Lines 516-522
Link Here
|
| 516 |
forward_respond ( |
676 |
forward_respond ( |
| 517 |
struct sockaddr *from, |
677 |
struct sockaddr *from, |
| 518 |
int fromlen, |
678 |
int fromlen, |
| 519 |
int length) |
679 |
int length, |
|
|
680 |
int fd) |
| 520 |
{ |
681 |
{ |
| 521 |
ARRAY8 clientAddress; |
682 |
ARRAY8 clientAddress; |
| 522 |
ARRAY8 clientPort; |
683 |
ARRAY8 clientPort; |
|
Lines 576-582
Link Here
|
| 576 |
client = (struct sockaddr *) &in_addr; |
737 |
client = (struct sockaddr *) &in_addr; |
| 577 |
clientlen = sizeof (in_addr); |
738 |
clientlen = sizeof (in_addr); |
| 578 |
all_query_respond (client, clientlen, &authenticationNames, |
739 |
all_query_respond (client, clientlen, &authenticationNames, |
| 579 |
FORWARD_QUERY); |
740 |
FORWARD_QUERY, fd); |
|
|
741 |
} |
| 742 |
break; |
| 743 |
#endif |
| 744 |
#ifdef IPv6 |
| 745 |
case AF_INET6: |
| 746 |
{ |
| 747 |
struct sockaddr_in6 in6_addr; |
| 748 |
|
| 749 |
if (clientAddress.length != 16 || |
| 750 |
clientPort.length != 2) |
| 751 |
{ |
| 752 |
goto badAddress; |
| 753 |
} |
| 754 |
bzero ((char *) &in6_addr, sizeof (in6_addr)); |
| 755 |
#ifdef SIN6_LEN |
| 756 |
in6_addr.sin6_len = sizeof(in6_addr); |
| 757 |
#endif |
| 758 |
in6_addr.sin6_family = AF_INET6; |
| 759 |
memmove(&in6_addr,clientAddress.data,clientAddress.length); |
| 760 |
memmove((char *) &in6_addr.sin6_port, clientPort.data, 2); |
| 761 |
client = (struct sockaddr *) &in6_addr; |
| 762 |
clientlen = sizeof (in6_addr); |
| 763 |
all_query_respond (client, clientlen, &authenticationNames, |
| 764 |
FORWARD_QUERY, fd); |
| 580 |
} |
765 |
} |
| 581 |
break; |
766 |
break; |
| 582 |
#endif |
767 |
#endif |
|
Lines 599-605
Link Here
|
| 599 |
clientlen = sizeof (un_addr); |
784 |
clientlen = sizeof (un_addr); |
| 600 |
#endif |
785 |
#endif |
| 601 |
all_query_respond (client, clientlen, &authenticationNames, |
786 |
all_query_respond (client, clientlen, &authenticationNames, |
| 602 |
FORWARD_QUERY); |
787 |
FORWARD_QUERY, fd); |
| 603 |
} |
788 |
} |
| 604 |
break; |
789 |
break; |
| 605 |
#endif |
790 |
#endif |
|
Lines 629-635
Link Here
|
| 629 |
struct sockaddr *from, |
814 |
struct sockaddr *from, |
| 630 |
int fromlen, |
815 |
int fromlen, |
| 631 |
ARRAY8Ptr authenticationName, |
816 |
ARRAY8Ptr authenticationName, |
| 632 |
ARRAY8Ptr status) |
817 |
ARRAY8Ptr status, |
|
|
818 |
int fd) |
| 633 |
{ |
819 |
{ |
| 634 |
XdmcpHeader header; |
820 |
XdmcpHeader header; |
| 635 |
|
821 |
|
|
Lines 647-653
Link Here
|
| 647 |
XdmcpWriteARRAY8 (&buffer, authenticationName); |
833 |
XdmcpWriteARRAY8 (&buffer, authenticationName); |
| 648 |
XdmcpWriteARRAY8 (&buffer, &Hostname); |
834 |
XdmcpWriteARRAY8 (&buffer, &Hostname); |
| 649 |
XdmcpWriteARRAY8 (&buffer, status); |
835 |
XdmcpWriteARRAY8 (&buffer, status); |
| 650 |
XdmcpFlush (xdmcpFd, &buffer, (XdmcpNetaddr) from, fromlen); |
836 |
XdmcpFlush (fd, &buffer, (XdmcpNetaddr) from, fromlen); |
| 651 |
} |
837 |
} |
| 652 |
|
838 |
|
| 653 |
static void |
839 |
static void |
|
Lines 655-661
Link Here
|
| 655 |
struct sockaddr *from, |
841 |
struct sockaddr *from, |
| 656 |
int fromlen, |
842 |
int fromlen, |
| 657 |
ARRAY8Ptr authenticationName, |
843 |
ARRAY8Ptr authenticationName, |
| 658 |
ARRAY8Ptr status) |
844 |
ARRAY8Ptr status, |
|
|
845 |
int fd) |
| 659 |
{ |
846 |
{ |
| 660 |
XdmcpHeader header; |
847 |
XdmcpHeader header; |
| 661 |
|
848 |
|
|
Lines 671-677
Link Here
|
| 671 |
XdmcpWriteHeader (&buffer, &header); |
858 |
XdmcpWriteHeader (&buffer, &header); |
| 672 |
XdmcpWriteARRAY8 (&buffer, &Hostname); |
859 |
XdmcpWriteARRAY8 (&buffer, &Hostname); |
| 673 |
XdmcpWriteARRAY8 (&buffer, status); |
860 |
XdmcpWriteARRAY8 (&buffer, status); |
| 674 |
XdmcpFlush (xdmcpFd, &buffer, (XdmcpNetaddr) from, fromlen); |
861 |
XdmcpFlush (fd, &buffer, (XdmcpNetaddr) from, fromlen); |
| 675 |
} |
862 |
} |
| 676 |
|
863 |
|
| 677 |
static unsigned long globalSessionID; |
864 |
static unsigned long globalSessionID; |
|
Lines 696-702
Link Here
|
| 696 |
request_respond ( |
883 |
request_respond ( |
| 697 |
struct sockaddr *from, |
884 |
struct sockaddr *from, |
| 698 |
int fromlen, |
885 |
int fromlen, |
| 699 |
int length) |
886 |
int length, |
|
|
887 |
int fd) |
| 700 |
{ |
888 |
{ |
| 701 |
CARD16 displayNumber; |
889 |
CARD16 displayNumber; |
| 702 |
ARRAY16 connectionTypes; |
890 |
ARRAY16 connectionTypes; |
|
Lines 821-834
Link Here
|
| 821 |
&authenticationName, |
1009 |
&authenticationName, |
| 822 |
&authenticationData, |
1010 |
&authenticationData, |
| 823 |
&authorizationName, |
1011 |
&authorizationName, |
| 824 |
&authorizationData); |
1012 |
&authorizationData, fd); |
| 825 |
} |
1013 |
} |
| 826 |
else |
1014 |
else |
| 827 |
{ |
1015 |
{ |
| 828 |
decline: ; |
1016 |
decline: ; |
| 829 |
send_decline (from, fromlen, &authenticationName, |
1017 |
send_decline (from, fromlen, &authenticationName, |
| 830 |
&authenticationData, |
1018 |
&authenticationData, |
| 831 |
reason); |
1019 |
reason, fd); |
| 832 |
if (pdpy) |
1020 |
if (pdpy) |
| 833 |
DisposeProtoDisplay (pdpy); |
1021 |
DisposeProtoDisplay (pdpy); |
| 834 |
} |
1022 |
} |
|
Lines 850-856
Link Here
|
| 850 |
ARRAY8Ptr authenticationName, |
1038 |
ARRAY8Ptr authenticationName, |
| 851 |
ARRAY8Ptr authenticationData, |
1039 |
ARRAY8Ptr authenticationData, |
| 852 |
ARRAY8Ptr authorizationName, |
1040 |
ARRAY8Ptr authorizationName, |
| 853 |
ARRAY8Ptr authorizationData) |
1041 |
ARRAY8Ptr authorizationData, |
|
|
1042 |
int fd) |
| 854 |
{ |
1043 |
{ |
| 855 |
XdmcpHeader header; |
1044 |
XdmcpHeader header; |
| 856 |
|
1045 |
|
|
Lines 868-874
Link Here
|
| 868 |
XdmcpWriteARRAY8 (&buffer, authenticationData); |
1057 |
XdmcpWriteARRAY8 (&buffer, authenticationData); |
| 869 |
XdmcpWriteARRAY8 (&buffer, authorizationName); |
1058 |
XdmcpWriteARRAY8 (&buffer, authorizationName); |
| 870 |
XdmcpWriteARRAY8 (&buffer, authorizationData); |
1059 |
XdmcpWriteARRAY8 (&buffer, authorizationData); |
| 871 |
XdmcpFlush (xdmcpFd, &buffer, (XdmcpNetaddr) to, tolen); |
1060 |
XdmcpFlush (fd, &buffer, (XdmcpNetaddr) to, tolen); |
| 872 |
} |
1061 |
} |
| 873 |
|
1062 |
|
| 874 |
static void |
1063 |
static void |
|
Lines 877-883
Link Here
|
| 877 |
int tolen, |
1066 |
int tolen, |
| 878 |
ARRAY8Ptr authenticationName, |
1067 |
ARRAY8Ptr authenticationName, |
| 879 |
ARRAY8Ptr authenticationData, |
1068 |
ARRAY8Ptr authenticationData, |
| 880 |
ARRAY8Ptr status) |
1069 |
ARRAY8Ptr status, |
|
|
1070 |
int fd) |
| 881 |
{ |
1071 |
{ |
| 882 |
XdmcpHeader header; |
1072 |
XdmcpHeader header; |
| 883 |
|
1073 |
|
|
Lines 892-905
Link Here
|
| 892 |
XdmcpWriteARRAY8 (&buffer, status); |
1082 |
XdmcpWriteARRAY8 (&buffer, status); |
| 893 |
XdmcpWriteARRAY8 (&buffer, authenticationName); |
1083 |
XdmcpWriteARRAY8 (&buffer, authenticationName); |
| 894 |
XdmcpWriteARRAY8 (&buffer, authenticationData); |
1084 |
XdmcpWriteARRAY8 (&buffer, authenticationData); |
| 895 |
XdmcpFlush (xdmcpFd, &buffer, (XdmcpNetaddr) to, tolen); |
1085 |
XdmcpFlush (fd, &buffer, (XdmcpNetaddr) to, tolen); |
| 896 |
} |
1086 |
} |
| 897 |
|
1087 |
|
| 898 |
static void |
1088 |
static void |
| 899 |
manage ( |
1089 |
manage ( |
| 900 |
struct sockaddr *from, |
1090 |
struct sockaddr *from, |
| 901 |
int fromlen, |
1091 |
int fromlen, |
| 902 |
int length) |
1092 |
int length, |
|
|
1093 |
int fd) |
| 903 |
{ |
1094 |
{ |
| 904 |
CARD32 sessionID; |
1095 |
CARD32 sessionID; |
| 905 |
CARD16 displayNumber; |
1096 |
CARD16 displayNumber; |
|
Lines 949-955
Link Here
|
| 949 |
Debug ("Session ID %ld refused\n", (long) sessionID); |
1140 |
Debug ("Session ID %ld refused\n", (long) sessionID); |
| 950 |
if (pdpy) |
1141 |
if (pdpy) |
| 951 |
Debug ("Existing Session ID %ld\n", (long) pdpy->sessionID); |
1142 |
Debug ("Existing Session ID %ld\n", (long) pdpy->sessionID); |
| 952 |
send_refuse (from, fromlen, sessionID); |
1143 |
send_refuse (from, fromlen, sessionID, fd); |
| 953 |
} |
1144 |
} |
| 954 |
else |
1145 |
else |
| 955 |
{ |
1146 |
{ |
|
Lines 960-966
Link Here
|
| 960 |
Debug ("Computed display name: %s\n", name); |
1151 |
Debug ("Computed display name: %s\n", name); |
| 961 |
if (!name) |
1152 |
if (!name) |
| 962 |
{ |
1153 |
{ |
| 963 |
send_failed (from, fromlen, "(no name)", sessionID, "out of memory"); |
1154 |
send_failed (from, fromlen, "(no name)", sessionID, |
|
|
1155 |
"out of memory", fd); |
| 964 |
goto abort; |
1156 |
goto abort; |
| 965 |
} |
1157 |
} |
| 966 |
d = FindDisplayByName (name); |
1158 |
d = FindDisplayByName (name); |
|
Lines 972-978
Link Here
|
| 972 |
class = malloc (displayClass.length + 1); |
1164 |
class = malloc (displayClass.length + 1); |
| 973 |
if (!class) |
1165 |
if (!class) |
| 974 |
{ |
1166 |
{ |
| 975 |
send_failed (from, fromlen, name, sessionID, "out of memory"); |
1167 |
send_failed (from, fromlen, name, sessionID, |
|
|
1168 |
"out of memory", fd); |
| 976 |
goto abort; |
1169 |
goto abort; |
| 977 |
} |
1170 |
} |
| 978 |
if (displayClass.length) |
1171 |
if (displayClass.length) |
|
Lines 988-994
Link Here
|
| 988 |
from_save = (XdmcpNetaddr) malloc (fromlen); |
1181 |
from_save = (XdmcpNetaddr) malloc (fromlen); |
| 989 |
if (!from_save) |
1182 |
if (!from_save) |
| 990 |
{ |
1183 |
{ |
| 991 |
send_failed (from, fromlen, name, sessionID, "out of memory"); |
1184 |
send_failed (from, fromlen, name, sessionID, |
|
|
1185 |
"out of memory", fd); |
| 992 |
goto abort; |
1186 |
goto abort; |
| 993 |
} |
1187 |
} |
| 994 |
memmove( from_save, from, fromlen); |
1188 |
memmove( from_save, from, fromlen); |
|
Lines 996-1002
Link Here
|
| 996 |
if (!d) |
1190 |
if (!d) |
| 997 |
{ |
1191 |
{ |
| 998 |
free ((char *) from_save); |
1192 |
free ((char *) from_save); |
| 999 |
send_failed (from, fromlen, name, sessionID, "out of memory"); |
1193 |
send_failed (from, fromlen, name, sessionID, |
|
|
1194 |
"out of memory", fd); |
| 1000 |
goto abort; |
1195 |
goto abort; |
| 1001 |
} |
1196 |
} |
| 1002 |
d->displayType.location = Foreign; |
1197 |
d->displayType.location = Foreign; |
|
Lines 1008-1013
Link Here
|
| 1008 |
d->displayNumber = pdpy->displayNumber; |
1203 |
d->displayNumber = pdpy->displayNumber; |
| 1009 |
ClientAddress (from, &clientAddress, &clientPort, &connectionType); |
1204 |
ClientAddress (from, &clientAddress, &clientPort, &connectionType); |
| 1010 |
d->useChooser = 0; |
1205 |
d->useChooser = 0; |
|
|
1206 |
d->xdmcpFd = fd; |
| 1011 |
if (IsIndirectClient (&clientAddress, connectionType)) |
1207 |
if (IsIndirectClient (&clientAddress, connectionType)) |
| 1012 |
{ |
1208 |
{ |
| 1013 |
Debug ("IsIndirectClient\n"); |
1209 |
Debug ("IsIndirectClient\n"); |
|
Lines 1028-1034
Link Here
|
| 1028 |
{ |
1224 |
{ |
| 1029 |
free ((char *) from_save); |
1225 |
free ((char *) from_save); |
| 1030 |
free ((char *) d); |
1226 |
free ((char *) d); |
| 1031 |
send_failed (from, fromlen, name, sessionID, "out of memory"); |
1227 |
send_failed (from, fromlen, name, sessionID, |
|
|
1228 |
"out of memory", fd); |
| 1032 |
goto abort; |
1229 |
goto abort; |
| 1033 |
} |
1230 |
} |
| 1034 |
d->authorizations[0] = pdpy->fileAuthorization; |
1231 |
d->authorizations[0] = pdpy->fileAuthorization; |
|
Lines 1052-1058
Link Here
|
| 1052 |
char *reason) |
1249 |
char *reason) |
| 1053 |
{ |
1250 |
{ |
| 1054 |
Debug ("Display start failed, sending Failed\n"); |
1251 |
Debug ("Display start failed, sending Failed\n"); |
| 1055 |
send_failed ((struct sockaddr *)(d->from), d->fromlen, d->name, d->sessionID, reason); |
1252 |
send_failed ((struct sockaddr *)(d->from), d->fromlen, d->name, |
|
|
1253 |
d->sessionID, reason, d->xdmcpFd); |
| 1056 |
} |
1254 |
} |
| 1057 |
|
1255 |
|
| 1058 |
static void |
1256 |
static void |
|
Lines 1061-1067
Link Here
|
| 1061 |
int fromlen, |
1259 |
int fromlen, |
| 1062 |
char *name, |
1260 |
char *name, |
| 1063 |
CARD32 sessionID, |
1261 |
CARD32 sessionID, |
| 1064 |
char *reason) |
1262 |
char *reason, |
|
|
1263 |
int fd) |
| 1065 |
{ |
1264 |
{ |
| 1066 |
static char buf[256]; |
1265 |
static char buf[256]; |
| 1067 |
XdmcpHeader header; |
1266 |
XdmcpHeader header; |
|
Lines 1078-1091
Link Here
|
| 1078 |
XdmcpWriteHeader (&buffer, &header); |
1277 |
XdmcpWriteHeader (&buffer, &header); |
| 1079 |
XdmcpWriteCARD32 (&buffer, sessionID); |
1278 |
XdmcpWriteCARD32 (&buffer, sessionID); |
| 1080 |
XdmcpWriteARRAY8 (&buffer, &status); |
1279 |
XdmcpWriteARRAY8 (&buffer, &status); |
| 1081 |
XdmcpFlush (xdmcpFd, &buffer, (XdmcpNetaddr) from, fromlen); |
1280 |
XdmcpFlush (fd, &buffer, (XdmcpNetaddr) from, fromlen); |
| 1082 |
} |
1281 |
} |
| 1083 |
|
1282 |
|
| 1084 |
static void |
1283 |
static void |
| 1085 |
send_refuse ( |
1284 |
send_refuse ( |
| 1086 |
struct sockaddr *from, |
1285 |
struct sockaddr *from, |
| 1087 |
int fromlen, |
1286 |
int fromlen, |
| 1088 |
CARD32 sessionID) |
1287 |
CARD32 sessionID, |
|
|
1288 |
int fd) |
| 1089 |
{ |
1289 |
{ |
| 1090 |
XdmcpHeader header; |
1290 |
XdmcpHeader header; |
| 1091 |
|
1291 |
|
|
Lines 1095-1108
Link Here
|
| 1095 |
header.length = 4; |
1295 |
header.length = 4; |
| 1096 |
XdmcpWriteHeader (&buffer, &header); |
1296 |
XdmcpWriteHeader (&buffer, &header); |
| 1097 |
XdmcpWriteCARD32 (&buffer, sessionID); |
1297 |
XdmcpWriteCARD32 (&buffer, sessionID); |
| 1098 |
XdmcpFlush (xdmcpFd, &buffer, (XdmcpNetaddr) from, fromlen); |
1298 |
XdmcpFlush (fd, &buffer, (XdmcpNetaddr) from, fromlen); |
| 1099 |
} |
1299 |
} |
| 1100 |
|
1300 |
|
| 1101 |
static void |
1301 |
static void |
| 1102 |
send_alive ( |
1302 |
send_alive ( |
| 1103 |
struct sockaddr *from, |
1303 |
struct sockaddr *from, |
| 1104 |
int fromlen, |
1304 |
int fromlen, |
| 1105 |
int length) |
1305 |
int length, |
|
|
1306 |
int fd) |
| 1106 |
{ |
1307 |
{ |
| 1107 |
CARD32 sessionID; |
1308 |
CARD32 sessionID; |
| 1108 |
CARD16 displayNumber; |
1309 |
CARD16 displayNumber; |
|
Lines 1136-1142
Link Here
|
| 1136 |
XdmcpWriteHeader (&buffer, &header); |
1337 |
XdmcpWriteHeader (&buffer, &header); |
| 1137 |
XdmcpWriteCARD8 (&buffer, sendRunning); |
1338 |
XdmcpWriteCARD8 (&buffer, sendRunning); |
| 1138 |
XdmcpWriteCARD32 (&buffer, sendSessionID); |
1339 |
XdmcpWriteCARD32 (&buffer, sendSessionID); |
| 1139 |
XdmcpFlush (xdmcpFd, &buffer, (XdmcpNetaddr) from, fromlen); |
1340 |
XdmcpFlush (fd, &buffer, (XdmcpNetaddr) from, fromlen); |
| 1140 |
} |
1341 |
} |
| 1141 |
} |
1342 |
} |
| 1142 |
} |
1343 |
} |
|
Lines 1151-1166
Link Here
|
| 1151 |
switch (connectionType) |
1352 |
switch (connectionType) |
| 1152 |
{ |
1353 |
{ |
| 1153 |
case FamilyInternet: |
1354 |
case FamilyInternet: |
|
|
1355 |
#ifdef IPv6 |
| 1356 |
case FamilyInternetV6: |
| 1357 |
#endif |
| 1154 |
{ |
1358 |
{ |
| 1155 |
struct hostent *hostent = NULL; |
1359 |
struct hostent *hostent = NULL; |
|
|
1360 |
#ifdef IPv6 |
| 1361 |
char dotted[INET6_ADDRSTRLEN]; |
| 1362 |
#else |
| 1156 |
char dotted[20]; |
1363 |
char dotted[20]; |
|
|
1364 |
#endif |
| 1157 |
char *local_name = ""; |
1365 |
char *local_name = ""; |
|
|
1366 |
int af_type; |
| 1367 |
|
| 1368 |
#ifdef IPv6 |
| 1369 |
if (connectionType == FamilyInternetV6) |
| 1370 |
af_type = AF_INET6; |
| 1371 |
else |
| 1372 |
#endif |
| 1373 |
af_type = AF_INET; |
| 1158 |
|
1374 |
|
| 1159 |
hostent = gethostbyaddr ((char *)connectionAddress->data, |
1375 |
hostent = gethostbyaddr ((char *)connectionAddress->data, |
| 1160 |
connectionAddress->length, AF_INET); |
1376 |
connectionAddress->length, af_type); |
| 1161 |
|
1377 |
|
| 1162 |
if (hostent) { |
1378 |
if (hostent) { |
| 1163 |
/* check for DNS spoofing */ |
1379 |
/* check for DNS spoofing */ |
|
|
1380 |
#ifdef IPv6 |
| 1381 |
struct addrinfo *ai = NULL, *nai; |
| 1382 |
if (getaddrinfo(hostent->h_name, NULL, NULL, &ai) == 0) { |
| 1383 |
while ((nai = ai->ai_next) != NULL) { |
| 1384 |
if ((af_type == nai->ai_family) && |
| 1385 |
(connectionAddress->length == nai->ai_addrlen) && |
| 1386 |
(memcmp(connectionAddress->data,nai->ai_addr, |
| 1387 |
nai->ai_addrlen) != 0) ) { |
| 1388 |
break; |
| 1389 |
} |
| 1390 |
} |
| 1391 |
if (nai == NULL) { |
| 1392 |
inet_ntop(af_type, connectionAddress->data, |
| 1393 |
dotted, sizeof(dotted)); |
| 1394 |
|
| 1395 |
LogError("Possible DNS spoof attempt %s->%s.", dotted, |
| 1396 |
hostent->h_name); |
| 1397 |
hostent = NULL; |
| 1398 |
} |
| 1399 |
freeaddrinfo(ai); |
| 1400 |
} else { |
| 1401 |
hostent = NULL; |
| 1402 |
} |
| 1403 |
#else |
| 1164 |
char *s = strdup(hostent->h_name); /* fscking non-reentrancy of getXXX() */ |
1404 |
char *s = strdup(hostent->h_name); /* fscking non-reentrancy of getXXX() */ |
| 1165 |
if ((hostent = gethostbyname(s))) { |
1405 |
if ((hostent = gethostbyname(s))) { |
| 1166 |
if (memcmp((char*)connectionAddress->data, hostent->h_addr, |
1406 |
if (memcmp((char*)connectionAddress->data, hostent->h_addr, |
|
Lines 1172-1186
Link Here
|
| 1172 |
} |
1412 |
} |
| 1173 |
} |
1413 |
} |
| 1174 |
free(s); |
1414 |
free(s); |
|
|
1415 |
#endif |
| 1175 |
} |
1416 |
} |
| 1176 |
|
1417 |
|
| 1177 |
if (!hostent) { |
1418 |
if (!hostent) { |
| 1178 |
/* can't get name, so use emergency fallback */ |
1419 |
/* can't get name, so use emergency fallback */ |
|
|
1420 |
#ifdef IPv6 |
| 1421 |
inet_ntop(af_type, connectionAddress->data, |
| 1422 |
dotted, sizeof(dotted)); |
| 1423 |
#else |
| 1179 |
sprintf(dotted, "%d.%d.%d.%d", |
1424 |
sprintf(dotted, "%d.%d.%d.%d", |
| 1180 |
connectionAddress->data[0], |
1425 |
connectionAddress->data[0], |
| 1181 |
connectionAddress->data[1], |
1426 |
connectionAddress->data[1], |
| 1182 |
connectionAddress->data[2], |
1427 |
connectionAddress->data[2], |
| 1183 |
connectionAddress->data[3]); |
1428 |
connectionAddress->data[3]); |
|
|
1429 |
#endif |
| 1184 |
local_name = dotted; |
1430 |
local_name = dotted; |
| 1185 |
LogError ("Cannot convert Internet address %s to host name\n", |
1431 |
LogError ("Cannot convert Internet address %s to host name\n", |
| 1186 |
dotted); |
1432 |
dotted); |
|
Lines 1198-1204
Link Here
|
| 1198 |
break; |
1444 |
break; |
| 1199 |
} |
1445 |
} |
| 1200 |
return name; |
1446 |
return name; |
| 1201 |
} |
1447 |
} |
| 1202 |
|
1448 |
|
| 1203 |
#if 0 |
1449 |
#if 0 |
| 1204 |
static int |
1450 |
static int |