yp_dnslookup.c (27741) | yp_dnslookup.c (30827) |
---|---|
1/* 2 * Copyright (c) 1995, 1996 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. | 1/* 2 * Copyright (c) 1995, 1996 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. |
31 * 32 * $Id: yp_dnslookup.c,v 1.11 1997/07/27 03:41:53 wpaul Exp $ | |
33 */ 34 | 31 */ 32 |
33#ifndef lint 34static const char rcsid[] = 35 "$Id$"; 36#endif /* not lint */ 37 |
|
35/* 36 * Do standard and reverse DNS lookups using the resolver library. 37 * Take care of all the dirty work here so the main program only has to 38 * pass us a pointer to an array of characters. 39 * 40 * We have to use direct resolver calls here otherwise the YP server 41 * could end up looping by calling itself over and over again until 42 * it disappeared up its own belly button. 43 */ 44 45#include <sys/param.h> 46#include <sys/socket.h> 47#include <sys/time.h> 48#include <sys/fcntl.h> 49#include <sys/queue.h> 50#include <netinet/in.h> 51#include <arpa/inet.h> 52#include <arpa/nameser.h> 53 | 38/* 39 * Do standard and reverse DNS lookups using the resolver library. 40 * Take care of all the dirty work here so the main program only has to 41 * pass us a pointer to an array of characters. 42 * 43 * We have to use direct resolver calls here otherwise the YP server 44 * could end up looping by calling itself over and over again until 45 * it disappeared up its own belly button. 46 */ 47 48#include <sys/param.h> 49#include <sys/socket.h> 50#include <sys/time.h> 51#include <sys/fcntl.h> 52#include <sys/queue.h> 53#include <netinet/in.h> 54#include <arpa/inet.h> 55#include <arpa/nameser.h> 56 |
54#include <stdio.h> | |
55#include <ctype.h> | 57#include <ctype.h> |
56#include <resolv.h> | 58#include <errno.h> |
57#include <netdb.h> | 59#include <netdb.h> |
58#include <unistd.h> | 60#include <stdio.h> |
59#include <stdlib.h> 60#include <string.h> | 61#include <stdlib.h> 62#include <string.h> |
61#include <errno.h> 62#include <err.h> | 63#include <resolv.h> 64#include <unistd.h> |
63 64#include <rpcsvc/yp.h> 65#include "yp_extern.h" 66 | 65 66#include <rpcsvc/yp.h> 67#include "yp_extern.h" 68 |
67#ifndef lint 68static const char rcsid[] = "$Id: yp_dnslookup.c,v 1.11 1997/07/27 03:41:53 wpaul Exp $"; 69#endif 70 | |
71static char *parse(hp) 72 struct hostent *hp; 73{ 74 static char result[MAXHOSTNAMELEN * 2]; 75 int len,i; 76 struct in_addr addr; 77 78 if (hp == NULL) --- 63 unchanged lines hidden (view full) --- 142 143static struct circleq_dnsentry *yp_malloc_dnsent() 144{ 145 register struct circleq_dnsentry *q; 146 147 q = (struct circleq_dnsentry *)malloc(sizeof(struct circleq_dnsentry)); 148 149 if (q == NULL) { | 69static char *parse(hp) 70 struct hostent *hp; 71{ 72 static char result[MAXHOSTNAMELEN * 2]; 73 int len,i; 74 struct in_addr addr; 75 76 if (hp == NULL) --- 63 unchanged lines hidden (view full) --- 140 141static struct circleq_dnsentry *yp_malloc_dnsent() 142{ 143 register struct circleq_dnsentry *q; 144 145 q = (struct circleq_dnsentry *)malloc(sizeof(struct circleq_dnsentry)); 146 147 if (q == NULL) { |
150 yp_error("failed to malloc() circleq dns entry: %s", 151 strerror(errno)); | 148 yp_error("failed to malloc() circleq dns entry"); |
152 return(NULL); 153 } 154 155 return(q); 156} 157 158/* 159 * Transmit a query. --- 101 unchanged lines hidden (view full) --- 261 result_v1.YPVAL.val.valdat_len = strlen(buf); 262 result_v1.YPVAL.val.valdat_val = buf; 263 result_v1.YPVAL.stat = YP_TRUE; 264 } 265 result = (char *)&result_v1; 266 xdrfunc = (xdrproc_t)xdr_ypresponse; 267 break; 268 default: | 149 return(NULL); 150 } 151 152 return(q); 153} 154 155/* 156 * Transmit a query. --- 101 unchanged lines hidden (view full) --- 258 result_v1.YPVAL.val.valdat_len = strlen(buf); 259 result_v1.YPVAL.val.valdat_val = buf; 260 result_v1.YPVAL.stat = YP_TRUE; 261 } 262 result = (char *)&result_v1; 263 xdrfunc = (xdrproc_t)xdr_ypresponse; 264 break; 265 default: |
269 yp_error("Bad YP program version (%lu)!",q->ypvers); | 266 yp_error("bad YP program version (%lu)!", q->ypvers); |
270 return; 271 break; 272 } 273 274 if (debug) | 267 return; 268 break; 269 } 270 271 if (debug) |
275 yp_error("Sending dns reply to %s (%lu)", | 272 yp_error("sending dns reply to %s (%lu)", |
276 inet_ntoa(q->client_addr.sin_addr), q->id); 277 /* 278 * XXX This is disgusting. There's basically one transport 279 * handle for UDP, but we're holding off on replying to a 280 * client until we're ready, by which time we may have received 281 * several other queries from other clients with different 282 * transaction IDs. So to make the delayed response thing work, 283 * we have to save the transaction ID and client address of --- 63 unchanged lines hidden (view full) --- 347 char retrybuf[MAXHOSTNAMELEN]; 348 struct sockaddr_in sin; 349 int rval; 350 int len; 351 HEADER *hptr; 352 struct hostent *hent; 353 354 if (debug) | 273 inet_ntoa(q->client_addr.sin_addr), q->id); 274 /* 275 * XXX This is disgusting. There's basically one transport 276 * handle for UDP, but we're holding off on replying to a 277 * client until we're ready, by which time we may have received 278 * several other queries from other clients with different 279 * transaction IDs. So to make the delayed response thing work, 280 * we have to save the transaction ID and client address of --- 63 unchanged lines hidden (view full) --- 344 char retrybuf[MAXHOSTNAMELEN]; 345 struct sockaddr_in sin; 346 int rval; 347 int len; 348 HEADER *hptr; 349 struct hostent *hent; 350 351 if (debug) |
355 yp_error("Running dns queue"); | 352 yp_error("running dns queue"); |
356 357 bzero(buf, sizeof(buf)); 358 359 len = sizeof(struct sockaddr_in); 360 rval = recvfrom(resfd, buf, sizeof(buf), 0, 361 (struct sockaddr *)&sin, &len); 362 363 if (rval == -1) { --- 11 unchanged lines hidden (view full) --- 375 hptr = (HEADER *)&buf; 376 if (!pending || 377 (q = yp_find_dnsqent(ntohs(hptr->id), BY_DNS_ID)) == NULL) { 378 /* ignore */ 379 return; 380 } 381 382 if (debug) | 353 354 bzero(buf, sizeof(buf)); 355 356 len = sizeof(struct sockaddr_in); 357 rval = recvfrom(resfd, buf, sizeof(buf), 0, 358 (struct sockaddr *)&sin, &len); 359 360 if (rval == -1) { --- 11 unchanged lines hidden (view full) --- 372 hptr = (HEADER *)&buf; 373 if (!pending || 374 (q = yp_find_dnsqent(ntohs(hptr->id), BY_DNS_ID)) == NULL) { 375 /* ignore */ 376 return; 377 } 378 379 if (debug) |
383 yp_error("Got dns reply from %s", inet_ntoa(sin.sin_addr)); | 380 yp_error("got dns reply from %s", inet_ntoa(sin.sin_addr)); |
384 385 hent = __dns_getanswer(buf, rval, q->name, q->type); 386 387 /* 388 * If the lookup failed, try appending one of the domains 389 * from resolv.conf. If we have no domains to test, the 390 * query has failed. 391 */ 392 if (hent == NULL) { 393 if ((h_errno == TRY_AGAIN || h_errno == NO_RECOVERY) 394 && q->domain && *q->domain) { 395 snprintf(retrybuf, sizeof(retrybuf), "%s.%s", 396 q->name, *q->domain); 397 if (debug) | 381 382 hent = __dns_getanswer(buf, rval, q->name, q->type); 383 384 /* 385 * If the lookup failed, try appending one of the domains 386 * from resolv.conf. If we have no domains to test, the 387 * query has failed. 388 */ 389 if (hent == NULL) { 390 if ((h_errno == TRY_AGAIN || h_errno == NO_RECOVERY) 391 && q->domain && *q->domain) { 392 snprintf(retrybuf, sizeof(retrybuf), "%s.%s", 393 q->name, *q->domain); 394 if (debug) |
398 yp_error("Retrying with: %s", retrybuf); | 395 yp_error("retrying with: %s", retrybuf); |
399 q->id = yp_send_dns_query(retrybuf, q->type); 400 q->ttl = DEF_TTL; 401 q->domain++; 402 return; 403 } 404 } else { 405 if (q->type == T_PTR) { 406 hent->h_addr = (char *)&q->addr.s_addr; --- 60 unchanged lines hidden (view full) --- 467 return(YP_YPERR); 468 } 469 470 q->name = strdup(name); 471 CIRCLEQ_INSERT_HEAD(&qhead, q, links); 472 pending++; 473 474 if (debug) | 396 q->id = yp_send_dns_query(retrybuf, q->type); 397 q->ttl = DEF_TTL; 398 q->domain++; 399 return; 400 } 401 } else { 402 if (q->type == T_PTR) { 403 hent->h_addr = (char *)&q->addr.s_addr; --- 60 unchanged lines hidden (view full) --- 464 return(YP_YPERR); 465 } 466 467 q->name = strdup(name); 468 CIRCLEQ_INSERT_HEAD(&qhead, q, links); 469 pending++; 470 471 if (debug) |
475 yp_error("Queueing async DNS name lookup (%d)", q->id); | 472 yp_error("queueing async DNS name lookup (%d)", q->id); |
476 477 yp_prune_dnsq(); 478 return(YP_TRUE); 479} 480 481/* 482 * Queue and transmit an asynchronous DNS IP address lookup. 483 */ --- 48 unchanged lines hidden (view full) --- 532 } 533 534 inet_aton(addr, &q->addr); 535 q->name = strdup(buf); 536 CIRCLEQ_INSERT_HEAD(&qhead, q, links); 537 pending++; 538 539 if (debug) | 473 474 yp_prune_dnsq(); 475 return(YP_TRUE); 476} 477 478/* 479 * Queue and transmit an asynchronous DNS IP address lookup. 480 */ --- 48 unchanged lines hidden (view full) --- 529 } 530 531 inet_aton(addr, &q->addr); 532 q->name = strdup(buf); 533 CIRCLEQ_INSERT_HEAD(&qhead, q, links); 534 pending++; 535 536 if (debug) |
540 yp_error("Queueing async DNS address lookup (%d)", q->id); | 537 yp_error("queueing async DNS address lookup (%d)", q->id); |
541 542 yp_prune_dnsq(); 543 return(YP_TRUE); 544} | 538 539 yp_prune_dnsq(); 540 return(YP_TRUE); 541} |