int adns_wait_poll(adns_state ads, adns_query *query_io, adns_answer **answer_r, void **context_r) { int r, nfds, to; struct pollfd fds[MAX_POLLFDS]; adns__consistency(ads,0,cc_entex); for (;;) { r= adns__internal_check(ads,query_io,answer_r,context_r); if (r != EAGAIN) goto xit; nfds= MAX_POLLFDS; to= -1; adns_beforepoll(ads,fds,&nfds,&to,0); r= poll(fds,nfds,to); if (r == -1) { if (errno == EINTR) { if (ads->iflags & adns_if_eintr) { r= EINTR; goto xit; } } else { adns__diag(ads,-1,0,"poll failed in wait: %s",strerror(errno)); adns_globalsystemfailure(ads); } } else { assert(r >= 0); adns_afterpoll(ads,fds,nfds,0); } } xit: adns__consistency(ads,0,cc_entex); return r; }
int adns_beforepoll(adns_state ads, struct pollfd *fds, int *nfds_io, int *timeout_io, const struct timeval *now) { #ifdef HAVE_POLL struct timeval tv_nowbuf, tv_tobuf, *tv_to; int space, found, timeout_ms, r; struct pollfd fds_tmp[MAX_POLLFDS]; adns__consistency(ads,0,cc_entex); if (timeout_io) { adns__must_gettimeofday(ads,&now,&tv_nowbuf); if (!now) { *nfds_io= 0; r= 0; goto xit; } timeout_ms= *timeout_io; if (timeout_ms == -1) { tv_to= 0; } else { tv_tobuf.tv_sec= timeout_ms / 1000; tv_tobuf.tv_usec= (timeout_ms % 1000)*1000; tv_to= &tv_tobuf; } adns__timeouts(ads, 0, &tv_to,&tv_tobuf, *now); if (tv_to) { assert(tv_to == &tv_tobuf); timeout_ms= (tv_tobuf.tv_usec+999)/1000; assert(tv_tobuf.tv_sec < (INT_MAX-timeout_ms)/1000); timeout_ms += tv_tobuf.tv_sec*1000; } else { timeout_ms= -1; } *timeout_io= timeout_ms; } space= *nfds_io; if (space >= MAX_POLLFDS) { found= adns__pollfds(ads,fds); *nfds_io= found; } else { found= adns__pollfds(ads,fds_tmp); *nfds_io= found; if (space < found) { r= ERANGE; goto xit; } memcpy(fds,fds_tmp,sizeof(struct pollfd)*found); } r= 0; xit: adns__consistency(ads,0,cc_entex); return r; #else errno = ENOSYS; return -1; #endif }
void adns_afterpoll(adns_state ads, const struct pollfd *fds, int nfds, const struct timeval *now) { struct timeval tv_buf; adns__consistency(ads,0,cc_entex); adns__must_gettimeofday(ads,&now,&tv_buf); if (now) { adns__timeouts(ads, 1, 0,0, *now); adns__fdevents(ads, fds,nfds, 0,0,0,0, *now,0); } adns__consistency(ads,0,cc_entex); }
int adns__rereadconfig(adns_state ads) { struct in_addr ia; adns__consistency(ads,0,cc_entex); ads->nservers = 0; readconfig(ads,"/etc/resolv.conf",0); if (!ads->nservers) { ia.s_addr= htonl(INADDR_LOOPBACK); addserver(ads,ia); } adns__consistency(ads,0,cc_entex); return 0; }
adns_query adns_forallqueries_next(adns_state ads, void **context_r) { adns_query qu, nqu; adns__consistency(ads,0,cc_entex); nqu= ads->forallnext; for (;;) { qu= nqu; if (!qu) return 0; if (qu->next) { nqu= qu->next; } else if (qu == ads->udpw.tail) { nqu= ads->tcpw.head ? ads->tcpw.head : ads->childw.head ? ads->childw.head : ads->output.head; } else if (qu == ads->tcpw.tail) { nqu= ads->childw.head ? ads->childw.head : ads->output.head; } else if (qu == ads->childw.tail) { nqu= ads->output.head; } else { nqu= 0; } if (!qu->parent) break; } ads->forallnext= nqu; if (context_r) *context_r= qu->ctx.ext; return qu; }
void adns_forallqueries_begin(adns_state ads) { adns__consistency(ads,0,cc_entex); ads->forallnext= ads->udpw.head ? ads->udpw.head : ads->tcpw.head ? ads->tcpw.head : ads->childw.head ? ads->childw.head : ads->output.head; }
int adns__rereadconfig(adns_state ads) { struct in_addr ia; adns__consistency(ads,0,cc_entex); ads->nservers = 0; ads->servers[0].addr.s_addr = 0; #ifndef VMS readconfig(ads,"/etc/resolv.conf",1); readconfig(ads,"/etc/resolv-adns.conf",0); #else readconfig(ads,"[]resolv.conf",0); #endif if (!ads->nservers) { ia.s_addr= htonl(INADDR_LOOPBACK); addserver(ads,ia); } adns__consistency(ads,0,cc_entex); return 0; }
void adns_finish(adns_state ads) { adns__consistency(ads,0,cc_entex); for (;;) { if (ads->udpw.head) adns_cancel(ads->udpw.head); else if (ads->tcpw.head) adns_cancel(ads->tcpw.head); else if (ads->childw.head) adns_cancel(ads->childw.head); else if (ads->output.head) adns_cancel(ads->output.head); else break; } close(ads->udpsocket); if (ads->tcpsocket >= 0) close(ads->tcpsocket); adns__vbuf_free(&ads->tcpsend); adns__vbuf_free(&ads->tcprecv); freesearchlist(ads); free(ads); }
int adns_init(adns_state *ads_r, adns_initflags flags, FBFILE *diagfile) { adns_state ads; const char *res_options, *adns_res_options; int r; r= init_begin(&ads, flags, diagfile); if (r) return r; res_options= instrum_getenv(ads,"RES_OPTIONS"); adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS"); ccf_options(ads,"RES_OPTIONS",-1,res_options); ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options); #ifndef VMS readconfig(ads,"/etc/resolv.conf",0); readconfig(ads,"/etc/resolv-adns.conf",0); #else ilog(L_CRIT, "Opening IRCD$CONFDIR:RESOLV.CONF (VMS)"); readconfig(ads,"IRCD$CONFDIR:RESOLV.CONF",0); #endif readconfigenv(ads,"RES_CONF"); readconfigenv(ads,"ADNS_RES_CONF"); readconfigenvtext(ads,"RES_CONF_TEXT"); readconfigenvtext(ads,"ADNS_RES_CONF_TEXT"); ccf_options(ads,"RES_OPTIONS",-1,res_options); ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options); ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN")); ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN")); if (ads->configerrno && ads->configerrno != EINVAL) { ilog(L_CRIT, "Failed at 1"); r= ads->configerrno; init_abort(ads); return r; } r= init_finish(ads); if (r) return r; adns__consistency(ads,0,cc_entex); *ads_r= ads; return 0; }
/* void dns_select(void) * Input: None. * Output: None * Side effects: Re-register ADNS fds with the fd system. Also calls the * callbacks into core ircd. */ void dns_select(void) { struct adns_pollfd pollfds[MAXFD_POLL]; int npollfds, i, fd; adns__consistency(dns_state, 0, cc_entex); npollfds = adns__pollfds(dns_state, pollfds); for (i = 0; i < npollfds; i++) { fd = pollfds[i].fd; if(pollfds[i].events & ADNS_POLLIN) comm_setselect(fd, FDLIST_SERVER, COMM_SELECT_READ, dns_readable, NULL); if(pollfds[i].events & ADNS_POLLOUT) comm_setselect(fd, FDLIST_SERVICE, COMM_SELECT_WRITE, dns_writeable, NULL); } }
int adns_init_strcfg(adns_state *ads_r, adns_initflags flags, FILE *diagfile, const char *configtext) { adns_state ads; int r; r= init_begin(&ads, flags, diagfile); if (r) return r; readconfigtext(ads,configtext,"<supplied configuration text>"); if (ads->configerrno) { r= ads->configerrno; init_abort(ads); return r; } r= init_finish(ads); if (r) return r; adns__consistency(ads,0,cc_entex); *ads_r= ads; return 0; }
int adns_init(adns_state *ads_r, adns_initflags flags, FILE *diagfile) { adns_state ads; const char *res_options, *adns_res_options; int r; r= init_begin(&ads, flags, diagfile ? diagfile : stderr); if (r) return r; res_options= instrum_getenv(ads,"RES_OPTIONS"); adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS"); ccf_options(ads,"RES_OPTIONS",-1,res_options); ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options); readconfig(ads,"/etc/resolv.conf",1); readconfig(ads,"/etc/resolv-adns.conf",0); /* checking in the current dir for cygwin */ readconfig(ads,"resolv.conf",0); readconfigenv(ads,"RES_CONF"); readconfigenv(ads,"ADNS_RES_CONF"); readconfigenvtext(ads,"RES_CONF_TEXT"); readconfigenvtext(ads,"ADNS_RES_CONF_TEXT"); ccf_options(ads,"RES_OPTIONS",-1,res_options); ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options); ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN")); ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN")); if (ads->configerrno && ads->configerrno != EINVAL) { r= ads->configerrno; init_abort(ads); return r; } r= init_finish(ads); if (r) return r; adns__consistency(ads,0,cc_entex); *ads_r= ads; return 0; }
void adns_finish(adns_state ads) { adns__consistency(ads,0,cc_entex); for (;;) { if (ads->udpw.head) adns_cancel(ads->udpw.head); else if (ads->tcpw.head) adns_cancel(ads->tcpw.head); else if (ads->childw.head) adns_cancel(ads->childw.head); else if (ads->output.head) adns_cancel(ads->output.head); else break; } adns_socket_close(ads->udpsocket); if (ads->tcpsocket >= 0) adns_socket_close(ads->tcpsocket); adns__vbuf_free(&ads->tcpsend); adns__vbuf_free(&ads->tcprecv); freesearchlist(ads); free(ads); #ifdef ADNS_JGAA_WIN32 WSACleanup(); #endif /* WIN32 */ }
/* void dns_select(void) * Input: None. * Output: None * Side effects: Re-register ADNS fds with the fd system. Also calls the * callbacks into core ircd. */ void dns_select(void) { struct adns_pollfd pollfds[MAXFD_POLL]; int npollfds, i, fd; adns__consistency(dns_state,0,cc_entex); npollfds = adns__pollfds(dns_state, pollfds); for(i = 0; i < npollfds; i++) { fd = pollfds[i].fd; if (pollfds[i].events & ADNS_POLLIN) comm_setselect(fd, FDLIST_SERVER, COMM_SELECT_READ, dns_readable, NULL, 0); if (pollfds[i].events & ADNS_POLLOUT) comm_setselect(fd, FDLIST_SERVICE, COMM_SELECT_WRITE, dns_writeable, NULL, 0); } /* Call our callbacks, now that they may have some relevant data... */ /* *dns_do_callbacks(); */ }
int adns_init(adns_state *ads_r, adns_initflags flags, FILE *diagfile) { adns_state ads; const char *res_options, *adns_res_options; int r; #ifdef ADNS_JGAA_WIN32 #define SECURE_PATH_LEN (MAX_PATH - 64) char PathBuf[MAX_PATH]; struct in_addr addr; #define ADNS_PFIXED_INFO_BLEN (2048) PFIXED_INFO network_info = (PFIXED_INFO)alloca(ADNS_PFIXED_INFO_BLEN); ULONG network_info_blen = ADNS_PFIXED_INFO_BLEN; DWORD network_info_result; PIP_ADDR_STRING pip; const char *network_err_str = ""; #endif r= init_begin(&ads, flags, diagfile ? diagfile : stderr); if (r) return r; res_options= instrum_getenv(ads,"RES_OPTIONS"); adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS"); ccf_options(ads,"RES_OPTIONS",-1,res_options); ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options); #ifdef ADNS_JGAA_WIN32 GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\resolv.conf"); readconfig(ads,PathBuf,1); GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\resolv-adns.conf"); readconfig(ads,PathBuf,0); GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv.conf"); readconfig(ads,PathBuf,1); GetWindowsDirectory(PathBuf, SECURE_PATH_LEN); strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv-adns.conf"); readconfig(ads,PathBuf,0); network_info_result = GetNetworkParams(network_info, &network_info_blen); if (network_info_result != ERROR_SUCCESS){ switch(network_info_result) { case ERROR_BUFFER_OVERFLOW: network_err_str = "ERROR_BUFFER_OVERFLOW"; break; case ERROR_INVALID_PARAMETER: network_err_str = "ERROR_INVALID_PARAMETER"; break; case ERROR_NO_DATA: network_err_str = "ERROR_NO_DATA"; break; case ERROR_NOT_SUPPORTED: network_err_str = "ERROR_NOT_SUPPORTED"; break;} adns__diag(ads,-1,0,"GetNetworkParams() failed with error [%d] %s", network_info_result,network_err_str); } else { for(pip = &(network_info->DnsServerList); pip; pip = pip->Next) { addr.s_addr = inet_addr(pip->IpAddress.String); if ((addr.s_addr != INADDR_ANY) && (addr.s_addr != INADDR_NONE)) addserver(ads, addr); } } #else readconfig(ads,"/etc/resolv.conf",1); readconfig(ads,"/etc/resolv-adns.conf",0); #endif readconfigenv(ads,"RES_CONF"); readconfigenv(ads,"ADNS_RES_CONF"); readconfigenvtext(ads,"RES_CONF_TEXT"); readconfigenvtext(ads,"ADNS_RES_CONF_TEXT"); ccf_options(ads,"RES_OPTIONS",-1,res_options); ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options); ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN")); ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN")); if (ads->configerrno && ads->configerrno != EINVAL) { r= ads->configerrno; init_abort(ads); return r; } r= init_finish(ads); if (r) return r; adns__consistency(ads,0,cc_entex); *ads_r= ads; return 0; }
void adns_checkconsistency(adns_state ads, adns_query qu) { adns__consistency(ads,qu,cc_user); }