BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) { struct name_record *namerec = NULL; struct in_addr dns_ip; unstring qname; pull_ascii_nstring(qname, sizeof(qname), question->name); DEBUG(3,("DNS search for %s - ", nmb_namestr(question))); /* Unblock TERM signal so we can be killed in DNS lookup. */ BlockSignals(False, SIGTERM); dns_ip.s_addr = interpret_addr(qname); /* Re-block TERM signal. */ BlockSignals(True, SIGTERM); namerec = add_dns_result(question, dns_ip); if(namerec == NULL) { send_wins_name_query_response(NAM_ERR, p, NULL); } else { send_wins_name_query_response(0, p, namerec); } return False; }
/*************************************************************************** we use this when we can't do async DNS lookups ****************************************************************************/ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, struct name_record **n) { char *qname = question->name; struct in_addr dns_ip; DEBUG(3,("DNS search for %s - ", nmb_namestr(question))); /* Unblock TERM signal so we can be killed in DNS lookup. */ BlockSignals(False, SIGTERM); dns_ip.s_addr = interpret_addr(qname); /* Re-block TERM signal. */ BlockSignals(True, SIGTERM); *n = add_dns_result(question, dns_ip); if(*n == NULL) send_wins_name_query_response(NAM_ERR, p, NULL); else send_wins_name_query_response(0, p, *n); return False; }
/*************************************************************************** check the DNS queue ****************************************************************************/ void run_dns_queue(void) { struct query_record r; struct packet_struct *p, *p2; struct name_record *namerec; int size; if (fd_in == -1) return; /* Allow SIGTERM to kill us. */ BlockSignals(False, SIGTERM); if (!process_exists(child_pid)) { close(fd_in); start_async_dns(); } if ((size=read_data(fd_in, (char *)&r, sizeof(r))) != sizeof(r)) { if (size) { DEBUG(0,("Incomplete DNS answer from child!\n")); fd_in = -1; } BlockSignals(True, SIGTERM); return; } BlockSignals(True, SIGTERM); namerec = add_dns_result(&r.name, r.result); if (dns_current) { if (query_current(&r)) { DEBUG(3,("DNS calling send_wins_name_query_response\n")); in_dns = 1; if(namerec == NULL) send_wins_name_query_response(NAM_ERR, dns_current, NULL); else send_wins_name_query_response(0,dns_current,namerec); in_dns = 0; } dns_current->locked = False; free_packet(dns_current); dns_current = NULL; } /* loop over the whole dns queue looking for entries that match the result we just got */ for (p = dns_queue; p;) { struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; if (nmb_name_equal(question, &r.name)) { DEBUG(3,("DNS calling send_wins_name_query_response\n")); in_dns = 1; if(namerec == NULL) send_wins_name_query_response(NAM_ERR, p, NULL); else send_wins_name_query_response(0,p,namerec); in_dns = 0; p->locked = False; if (p->prev) p->prev->next = p->next; else dns_queue = p->next; if (p->next) p->next->prev = p->prev; p2 = p->next; free_packet(p); p = p2; } else { p = p->next; } } if (dns_queue) { dns_current = dns_queue; dns_queue = dns_queue->next; if (dns_queue) dns_queue->prev = NULL; dns_current->next = NULL; if (!write_child(dns_current)) { DEBUG(3,("failed to send DNS query to child!\n")); return; } } }