ReactOS 0.4.15-dev-8102-g108db8f
setup.c File Reference
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "internal.h"
Include dependency graph for setup.c:

Go to the source code of this file.

Classes

struct  configcommandinfo
 
union  getline_ctx
 

Functions

static void readconfig (adns_state ads, const char *filename, int warnmissing)
 
static void addserver (adns_state ads, struct in_addr addr)
 
static void freesearchlist (adns_state ads)
 
static void saveerr (adns_state ads, int en)
 
static void configparseerr (adns_state ads, const char *fn, int lno, const char *fmt,...)
 
static int nextword (const char **bufp_io, const char **word_r, int *l_r)
 
static void ccf_nameserver (adns_state ads, const char *fn, int lno, const char *buf)
 
static void ccf_search (adns_state ads, const char *fn, int lno, const char *buf)
 
static void ccf_sortlist (adns_state ads, const char *fn, int lno, const char *buf)
 
static void ccf_options (adns_state ads, const char *fn, int lno, const char *buf)
 
static void ccf_clearnss (adns_state ads, const char *fn, int lno, const char *buf)
 
static void ccf_include (adns_state ads, const char *fn, int lno, const char *buf)
 
static int gl_file (adns_state ads, getline_ctx *src_io, const char *filename, int lno, char *buf, int buflen)
 
static int gl_text (adns_state ads, getline_ctx *src_io, const char *filename, int lno, char *buf, int buflen)
 
static void readconfiggeneric (adns_state ads, const char *filename, int(*getline)(adns_state ads, getline_ctx *, const char *filename, int lno, char *buf, int buflen), getline_ctx gl_ctx)
 
static const charinstrum_getenv (adns_state ads, const char *envvar)
 
static void readconfigtext (adns_state ads, const char *text, const char *showname)
 
static void readconfigenv (adns_state ads, const char *envvar)
 
static void readconfigenvtext (adns_state ads, const char *envvar)
 
int adns__setnonblock (adns_state ads, ADNS_SOCKET fd)
 
static int init_begin (adns_state *ads_r, adns_initflags flags, FILE *diagfile)
 
static int init_finish (adns_state ads)
 
static void init_abort (adns_state ads)
 
int adns_init (adns_state *ads_r, adns_initflags flags, FILE *diagfile)
 
int adns_init_strcfg (adns_state *ads_r, adns_initflags flags, FILE *diagfile, const char *configtext)
 
void adns_finish (adns_state ads)
 
void adns_forallqueries_begin (adns_state ads)
 
adns_query adns_forallqueries_next (adns_state ads, void **context_r)
 
void adns_addserver (adns_state ads, struct in_addr addr)
 
void adns_ccf_search (adns_state ads, const char *fn, int lno, const char *buf)
 
int adns_numservers (adns_state ads)
 

Variables

static const struct configcommandinfo configcommandinfos []
 

Function Documentation

◆ addserver()

static void addserver ( adns_state  ads,
struct in_addr  addr 
)
static

Definition at line 48 of file setup.c.

48 {
49 int i;
50 struct server *ss;
51
52 for (i=0; i<ads->nservers; i++) {
53 if (ads->servers[i].addr.s_addr == addr.s_addr) {
54 adns__debug(ads,-1,0,"duplicate nameserver %s ignored",inet_ntoa(addr));
55 return;
56 }
57 }
58
59 if (ads->nservers>=MAXSERVERS) {
60 adns__diag(ads,-1,0,"too many nameservers, ignoring %s",inet_ntoa(addr));
61 return;
62 }
63
65 ss->addr= addr;
66 ads->nservers++;
67}
adns_state ads
Definition: adh-query.c:35
GLenum const GLvoid * addr
Definition: glext.h:9621
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ss
Definition: i386-dis.c:441
#define inet_ntoa(addr)
Definition: inet.h:100
void adns__debug(adns_state ads, int serv, adns_query qu, const char *fmt,...)
Definition: general.c:86
void adns__diag(adns_state ads, int serv, adns_query qu, const char *fmt,...)
Definition: general.c:102
#define MAXSERVERS
Definition: internal.h:63
int nservers
Definition: internal.h:300
struct adns__state::server servers[MAXSERVERS]
static rfbScreenInfoPtr server
Definition: vnc.c:74

Referenced by adns_addserver(), ccf_nameserver(), and init_finish().

◆ adns__setnonblock()

int adns__setnonblock ( adns_state  ads,
ADNS_SOCKET  fd 
)

Definition at line 457 of file setup.c.

457 {
458#ifdef ADNS_JGAA_WIN32
459 unsigned long Val = 1;
460 return (ioctlsocket (fd, FIONBIO, &Val) == 0) ? 0 : -1;
461#else
462 int r;
463
464 r= fcntl(fd,F_GETFL,0); if (r<0) return errno;
465 r |= O_NONBLOCK;
466 r= fcntl(fd,F_SETFL,r); if (r<0) return errno;
467 return 0;
468#endif
469}
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define O_NONBLOCK
Definition: port.h:158
#define ioctlsocket
Definition: ncftp.h:481
#define errno
Definition: errno.h:18
static int fd
Definition: io.c:51
#define FIONBIO
Definition: winsock.h:149

Referenced by adns__tcp_tryconnect(), and init_finish().

◆ adns_addserver()

void adns_addserver ( adns_state  ads,
struct in_addr  addr 
)

Definition at line 712 of file setup.c.

712 {
714}
static void addserver(adns_state ads, struct in_addr addr)
Definition: setup.c:48

Referenced by Query_Main().

◆ adns_ccf_search()

void adns_ccf_search ( adns_state  ads,
const char fn,
int  lno,
const char buf 
)

Definition at line 715 of file setup.c.

715 {
716 ccf_search(ads, fn, lno, buf);
717}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static void ccf_search(adns_state ads, const char *fn, int lno, const char *buf)
Definition: setup.c:121
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159

Referenced by Query_Main().

◆ adns_finish()

void adns_finish ( adns_state  ads)

Definition at line 650 of file setup.c.

650 {
652 for (;;) {
653 if (ads->udpw.head) adns_cancel(ads->udpw.head);
654 else if (ads->tcpw.head) adns_cancel(ads->tcpw.head);
655 else if (ads->childw.head) adns_cancel(ads->childw.head);
656 else if (ads->output.head) adns_cancel(ads->output.head);
657 else break;
658 }
664 free(ads);
665#ifdef ADNS_JGAA_WIN32
666 WSACleanup();
667#endif /* WIN32 */
668
669}
void adns__consistency(adns_state ads, adns_query qu, consistency_checks cc)
Definition: check.c:185
ADNS_API void adns_cancel(adns_query query)
Definition: query.c:430
#define adns_socket_close(sck)
Definition: adns_win32.h:99
#define free
Definition: debug_ros.c:5
void adns__vbuf_free(vbuf *vb)
Definition: general.c:155
@ cc_entex
Definition: internal.h:86
static void freesearchlist(adns_state ads)
Definition: setup.c:69
ADNS_SOCKET tcpsocket
Definition: internal.h:298
vbuf tcprecv
Definition: internal.h:299
struct query_queue udpw tcpw childw output
Definition: internal.h:295
ADNS_SOCKET udpsocket
Definition: internal.h:298
vbuf tcpsend
Definition: internal.h:299
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60

Referenced by DnsReleaseContextHandle(), main(), proclog(), Query_Main(), and quitnow().

◆ adns_forallqueries_begin()

void adns_forallqueries_begin ( adns_state  ads)

Definition at line 671 of file setup.c.

671 {
674 ads->udpw.head ? ads->udpw.head :
675 ads->tcpw.head ? ads->tcpw.head :
676 ads->childw.head ? ads->childw.head :
677 ads->output.head;
678}
adns_query forallnext
Definition: internal.h:296

Referenced by main().

◆ adns_forallqueries_next()

adns_query adns_forallqueries_next ( adns_state  ads,
void **  context_r 
)

Definition at line 680 of file setup.c.

680 {
681 adns_query qu, nqu;
682
684 nqu= ads->forallnext;
685 for (;;) {
686 qu= nqu;
687 if (!qu) return 0;
688 if (qu->next) {
689 nqu= qu->next;
690 } else if (qu == ads->udpw.tail) {
691 nqu=
692 ads->tcpw.head ? ads->tcpw.head :
693 ads->childw.head ? ads->childw.head :
694 ads->output.head;
695 } else if (qu == ads->tcpw.tail) {
696 nqu=
697 ads->childw.head ? ads->childw.head :
698 ads->output.head;
699 } else if (qu == ads->childw.tail) {
700 nqu= ads->output.head;
701 } else {
702 nqu= 0;
703 }
704 if (!qu->parent) break;
705 }
706 ads->forallnext= nqu;
707 if (context_r) *context_r= qu->ctx.ext;
708 return qu;
709}
adns_query parent
Definition: internal.h:184
adns_query next
Definition: internal.h:184
qcontext ctx
Definition: internal.h:233
void * ext
Definition: internal.h:173

Referenced by main().

◆ adns_init()

int adns_init ( adns_state ads_r,
adns_initflags  flags,
FILE diagfile 
)

Definition at line 568 of file setup.c.

568 {
570 const char *res_options, *adns_res_options;
571 int r;
572#ifdef ADNS_JGAA_WIN32
573 #define SECURE_PATH_LEN (MAX_PATH - 64)
574 char PathBuf[MAX_PATH];
575#endif
576
577 r= init_begin(&ads, flags, diagfile ? diagfile : stderr);
578 if (r) return r;
579
580 res_options= instrum_getenv(ads,"RES_OPTIONS");
581 adns_res_options= instrum_getenv(ads,"ADNS_RES_OPTIONS");
582 ccf_options(ads,"RES_OPTIONS",-1,res_options);
583 ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);
584
585#ifdef ADNS_JGAA_WIN32
586 GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
587 strcat(PathBuf,"\\resolv.conf");
588 readconfig(ads,PathBuf,1);
589 GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
590 strcat(PathBuf,"\\resolv-adns.conf");
591 readconfig(ads,PathBuf,0);
592 GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
593 strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv.conf");
594 readconfig(ads,PathBuf,1);
595 GetWindowsDirectory(PathBuf, SECURE_PATH_LEN);
596 strcat(PathBuf,"\\System32\\Drivers\\etc\\resolv-adns.conf");
597 readconfig(ads,PathBuf,0);
598#else
599 readconfig(ads,"/etc/resolv.conf",1);
600 readconfig(ads,"/etc/resolv-adns.conf",0);
601#endif
602
603 readconfigenv(ads,"RES_CONF");
604 readconfigenv(ads,"ADNS_RES_CONF");
605
606 readconfigenvtext(ads,"RES_CONF_TEXT");
607 readconfigenvtext(ads,"ADNS_RES_CONF_TEXT");
608
609 ccf_options(ads,"RES_OPTIONS",-1,res_options);
610 ccf_options(ads,"ADNS_RES_OPTIONS",-1,adns_res_options);
611
612 ccf_search(ads,"LOCALDOMAIN",-1,instrum_getenv(ads,"LOCALDOMAIN"));
613 ccf_search(ads,"ADNS_LOCALDOMAIN",-1,instrum_getenv(ads,"ADNS_LOCALDOMAIN"));
614
615 if (ads->configerrno && ads->configerrno != EINVAL) {
616 r= ads->configerrno;
618 return r;
619 }
620
621 r= init_finish(ads);
622 if (r) return r;
623
625 *ads_r= ads;
626 return 0;
627}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define EINVAL
Definition: acclib.h:90
#define MAX_PATH
Definition: compat.h:34
GLbitfield flags
Definition: glext.h:7161
#define stderr
Definition: stdio.h:100
static void ccf_options(adns_state ads, const char *fn, int lno, const char *buf)
Definition: setup.c:221
static int init_begin(adns_state *ads_r, adns_initflags flags, FILE *diagfile)
Definition: setup.c:471
static void readconfig(adns_state ads, const char *filename, int warnmissing)
Definition: setup.c:406
static void readconfigenvtext(adns_state ads, const char *envvar)
Definition: setup.c:445
static const char * instrum_getenv(adns_state ads, const char *envvar)
Definition: setup.c:397
static void init_abort(adns_state ads)
Definition: setup.c:556
static int init_finish(adns_state ads)
Definition: setup.c:523
static void readconfigenv(adns_state ads, const char *envvar)
Definition: setup.c:434
int configerrno
Definition: internal.h:294
#define GetWindowsDirectory
Definition: winbase.h:3857

Referenced by DnsAcquireContextHandle_W(), ensure_adns_init(), main(), proclog(), Query_Main(), and startup().

◆ adns_init_strcfg()

int adns_init_strcfg ( adns_state ads_r,
adns_initflags  flags,
FILE diagfile,
const char configtext 
)

Definition at line 629 of file setup.c.

630 {
632 int r;
633
634 r= init_begin(&ads, flags, diagfile); if (r) return r;
635
636 readconfigtext(ads,configtext,"<supplied configuration text>");
637 if (ads->configerrno) {
638 r= ads->configerrno;
640 return r;
641 }
642
643 r= init_finish(ads); if (r) return r;
645 *ads_r= ads;
646 return 0;
647}
static void readconfigtext(adns_state ads, const char *text, const char *showname)
Definition: setup.c:427

Referenced by ensure_adns_init(), main(), proclog(), and startup().

◆ adns_numservers()

int adns_numservers ( adns_state  ads)

Definition at line 718 of file setup.c.

718 {
719 return ads->nservers;
720}

Referenced by Query_Main().

◆ ccf_clearnss()

static void ccf_clearnss ( adns_state  ads,
const char fn,
int  lno,
const char buf 
)
static

Definition at line 262 of file setup.c.

262 {
263 ads->nservers= 0;
264}

◆ ccf_include()

static void ccf_include ( adns_state  ads,
const char fn,
int  lno,
const char buf 
)
static

Definition at line 266 of file setup.c.

266 {
267 if (!*buf) {
268 configparseerr(ads,fn,lno,"`include' directive with no filename");
269 return;
270 }
271 readconfig(ads,buf,1);
272}
static void configparseerr(adns_state ads, const char *fn, int lno, const char *fmt,...)
Definition: setup.c:78

◆ ccf_nameserver()

static void ccf_nameserver ( adns_state  ads,
const char fn,
int  lno,
const char buf 
)
static

Definition at line 110 of file setup.c.

110 {
111 struct in_addr ia;
112
113 if (!inet_aton(buf,&ia)) {
114 configparseerr(ads,fn,lno,"invalid nameserver address `%s'",buf);
115 return;
116 }
117 adns__debug(ads,-1,0,"using nameserver %s",inet_ntoa(ia));
118 addserver(ads,ia);
119}
#define inet_aton(cp, addr)
Definition: inet.h:99
Definition: tcpip.h:126

◆ ccf_options()

static void ccf_options ( adns_state  ads,
const char fn,
int  lno,
const char buf 
)
static

Definition at line 221 of file setup.c.

221 {
222 const char *word;
223 char *ep;
224 unsigned long v;
225 int l;
226
227 if (!buf) return;
228
229 while (nextword(&buf,&word,&l)) {
230 if (l==5 && !memcmp(word,"debug",5)) {
232 continue;
233 }
234 if (l>=6 && !memcmp(word,"ndots:",6)) {
235 v= strtoul(word+6,&ep,10);
236 if (l==6 || ep != word+l || v > INT_MAX) {
237 configparseerr(ads,fn,lno,"option `%.*s' malformed or has bad value",l,word);
238 continue;
239 }
240 ads->searchndots= v;
241 continue;
242 }
243 if (l>=12 && !memcmp(word,"adns_checkc:",12)) {
244 if (!strcmp(word+12,"none")) {
245 ads->iflags &= ~adns_if_checkc_freq;
247 } else if (!strcmp(word+12,"entex")) {
248 ads->iflags &= ~adns_if_checkc_freq;
250 } else if (!strcmp(word+12,"freq")) {
252 } else {
253 configparseerr(ads,fn,lno, "option adns_checkc has bad value `%s' "
254 "(must be none, entex or freq", word+12);
255 }
256 continue;
257 }
258 adns__diag(ads,-1,0,"%s:%d: unknown option `%.*s'", fn,lno, l,word);
259 }
260}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
@ adns_if_checkc_freq
Definition: adns.h:97
@ adns_if_debug
Definition: adns.h:91
@ adns_if_checkc_entex
Definition: adns.h:96
r l[0]
Definition: byte_order.h:168
const GLdouble * v
Definition: gl.h:2040
#define INT_MAX
Definition: limits.h:40
const WCHAR * word
Definition: lex.c:36
static int nextword(const char **bufp_io, const char **word_r, int *l_r)
Definition: setup.c:93
int searchndots
Definition: internal.h:300
adns_initflags iflags
Definition: internal.h:292

Referenced by adns_init().

◆ ccf_search()

static void ccf_search ( adns_state  ads,
const char fn,
int  lno,
const char buf 
)
static

Definition at line 121 of file setup.c.

121 {
122 const char *bufp, *word;
123 char *newchars, **newptrs, **pp;
124 int count, tl, l;
125
126 if (!buf) return;
127
128 bufp= buf;
129 count= 0;
130 tl= 0;
131 while (nextword(&bufp,&word,&l)) { count++; tl += l+1; }
132
133 newptrs= malloc(sizeof(char*)*count); if (!newptrs) { saveerr(ads,errno); return; }
134 newchars= malloc(tl); if (!newchars) { saveerr(ads,errno); free(newptrs); return; }
135
136 bufp= buf;
137 pp= newptrs;
138 while (nextword(&bufp,&word,&l)) {
139 *pp++= newchars;
140 memcpy(newchars,word,l);
141 newchars += l;
142 *newchars++ = 0;
143 }
144
147 ads->searchlist= newptrs;
148}
#define malloc
Definition: debug_ros.c:4
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static void saveerr(adns_state ads, int en)
Definition: setup.c:74
int nsearchlist
Definition: internal.h:300
char ** searchlist
Definition: internal.h:322

Referenced by adns_ccf_search(), and adns_init().

◆ ccf_sortlist()

static void ccf_sortlist ( adns_state  ads,
const char fn,
int  lno,
const char buf 
)
static

Definition at line 150 of file setup.c.

150 {
151 const char *word;
152 char tbuf[200], *slash, *ep;
153 struct in_addr base, mask;
154 int l;
155 unsigned long initial, baselocal;
156
157 if (!buf) return;
158
159 ads->nsortlist= 0;
160 while (nextword(&buf,&word,&l)) {
161 if (ads->nsortlist >= MAXSORTLIST) {
162 adns__diag(ads,-1,0,"too many sortlist entries, ignoring %.*s onwards",l,word);
163 return;
164 }
165
166 if (l >= sizeof(tbuf)) {
167 configparseerr(ads,fn,lno,"sortlist entry `%.*s' too long",l,word);
168 continue;
169 }
170
171 memcpy(tbuf,word,l); tbuf[l]= 0;
172 slash= strchr(tbuf,'/');
173 if (slash) *slash++= 0;
174
175 if (!inet_aton(tbuf,&base)) {
176 configparseerr(ads,fn,lno,"invalid address `%s' in sortlist",tbuf);
177 continue;
178 }
179
180 if (slash) {
181 if (strchr(slash,'.')) {
182 if (!inet_aton(slash,&mask)) {
183 configparseerr(ads,fn,lno,"invalid mask `%s' in sortlist",slash);
184 continue;
185 }
186 if (base.s_addr & ~mask.s_addr) {
188 "mask `%s' in sortlist overlaps address `%s'",slash,tbuf);
189 continue;
190 }
191 } else {
192 initial= strtoul(slash,&ep,10);
193 if (*ep || initial>32) {
194 configparseerr(ads,fn,lno,"mask length `%s' invalid",slash);
195 continue;
196 }
197 mask.s_addr= htonl((0x0ffffffffUL) << (32-initial));
198 }
199 } else {
200 baselocal= ntohl(base.s_addr);
201 if (!(baselocal & 0x080000000UL)) /* class A */
202 mask.s_addr= htonl(0x0ff000000UL);
203 else if ((baselocal & 0x0c0000000UL) == 0x080000000UL)
204 mask.s_addr= htonl(0x0ffff0000UL); /* class B */
205 else if ((baselocal & 0x0f0000000UL) == 0x0e0000000UL)
206 mask.s_addr= htonl(0x0ff000000UL); /* class C */
207 else {
209 "network address `%s' in sortlist is not in classed ranges,"
210 " must specify mask explicitly", tbuf);
211 continue;
212 }
213 }
214
215 ads->sortlist[ads->nsortlist].base= base;
216 ads->sortlist[ads->nsortlist].mask= mask;
217 ads->nsortlist++;
218 }
219}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
GLenum GLint GLuint mask
Definition: glext.h:6028
#define ntohl(x)
Definition: module.h:205
#define htonl(x)
Definition: module.h:214
#define MAXSORTLIST
Definition: internal.h:64
struct adns__state::sortlist sortlist[MAXSORTLIST]
int nsortlist
Definition: internal.h:300

◆ configparseerr()

static void configparseerr ( adns_state  ads,
const char fn,
int  lno,
const char fmt,
  ... 
)
static

Definition at line 78 of file setup.c.

79 {
80 va_list al;
81
83 if (!ads->diagfile || (ads->iflags & adns_if_noerrprint)) return;
84
85 if (lno==-1) fprintf(ads->diagfile,"adns: %s: ",fn);
86 else fprintf(ads->diagfile,"adns: %s:%d: ",fn,lno);
87 va_start(al,fmt);
89 va_end(al);
90 fputc('\n',ads->diagfile);
91}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
@ adns_if_noerrprint
Definition: adns.h:89
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
_Check_return_opt_ _CRTIMP int __cdecl fputc(_In_ int _Ch, _Inout_ FILE *_File)
FILE * diagfile
Definition: internal.h:293
Definition: dsound.c:943

Referenced by ccf_include(), ccf_nameserver(), ccf_options(), and ccf_sortlist().

◆ freesearchlist()

static void freesearchlist ( adns_state  ads)
static

Definition at line 69 of file setup.c.

69 {
72}

Referenced by adns_finish(), and ccf_search().

◆ gl_file()

static int gl_file ( adns_state  ads,
getline_ctx src_io,
const char filename,
int  lno,
char buf,
int  buflen 
)
static

Definition at line 293 of file setup.c.

294 {
295 FILE *file= src_io->file;
296 int c, i;
297 char *p;
298
299 p= buf;
300 buflen--;
301 i= 0;
302
303 for (;;) { /* loop over chars */
304 if (i == buflen) {
305 adns__diag(ads,-1,0,"%s:%d: line too long, ignored",filename,lno);
306 goto x_badline;
307 }
308 c= getc(file);
309 if (!c) {
310 adns__diag(ads,-1,0,"%s:%d: line contains nul, ignored",filename,lno);
311 goto x_badline;
312 } else if (c == '\n') {
313 break;
314 } else if (c == EOF) {
315 if (ferror(file)) {
317 adns__diag(ads,-1,0,"%s:%d: read error: %s",filename,lno,strerror(errno));
318 return -1;
319 }
320 if (!i) return -1;
321 break;
322 } else {
323 *p++= c;
324 i++;
325 }
326 }
327
328 *p++= 0;
329 return i;
330
331 x_badline:
333 while ((c= getc(file)) != EOF && c != '\n');
334 return -2;
335}
const GLubyte * c
Definition: glext.h:8905
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_ _CRTIMP int __cdecl ferror(_In_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE *_File)
#define EOF
Definition: stdio.h:24
const char * filename
Definition: ioapi.h:137
#define c
Definition: ke_i.h:80
const char * strerror(int err)
Definition: compat_str.c:23
Definition: fci.c:127
FILE * file
Definition: setup.c:289

Referenced by readconfig().

◆ gl_text()

static int gl_text ( adns_state  ads,
getline_ctx src_io,
const char filename,
int  lno,
char buf,
int  buflen 
)
static

Definition at line 337 of file setup.c.

338 {
339 const char *cp= src_io->text;
340 int l;
341
342 if (!cp || !*cp) return -1;
343
344 if (*cp == ';' || *cp == '\n') cp++;
345 l= strcspn(cp,";\n");
346 src_io->text = cp+l;
347
348 if (l >= buflen) {
349 adns__diag(ads,-1,0,"%s:%d: line too long, ignored",filename,lno);
351 return -2;
352 }
353
354 memcpy(buf,cp,l);
355 buf[l]= 0;
356 return l;
357}
POINT cp
Definition: magnifier.c:59
_Check_return_ _CRTIMP size_t __cdecl strcspn(_In_z_ const char *_Str, _In_z_ const char *_Control)
const char * text
Definition: setup.c:290

Referenced by readconfigtext(), and test_EM_GETLINE().

◆ init_abort()

static void init_abort ( adns_state  ads)
static

Definition at line 556 of file setup.c.

556 {
557 if (ads->nsearchlist) {
558 free(ads->searchlist[0]);
560 }
561 free(ads);
562#ifdef ADNS_JGAA_WIN32
563 WSACleanup();
564#endif /* WIN32 */
565
566}

Referenced by adns_init(), and adns_init_strcfg().

◆ init_begin()

static int init_begin ( adns_state ads_r,
adns_initflags  flags,
FILE diagfile 
)
static

Definition at line 471 of file setup.c.

471 {
473
474#ifdef ADNS_JGAA_WIN32
475 WORD wVersionRequested = MAKEWORD( 2, 0 );
476 WSADATA wsaData;
477 int err;
478#endif
479
480 ads= malloc(sizeof(*ads)); if (!ads) return errno;
481
482 ads->iflags= flags;
483 ads->diagfile= diagfile;
484 ads->configerrno= 0;
485 LIST_INIT(ads->udpw);
486 LIST_INIT(ads->tcpw);
487 LIST_INIT(ads->childw);
489 ads->forallnext= 0;
490 ads->nextid= 0x311f;
491 ads->udpsocket= ads->tcpsocket= -1;
494 ads->tcprecv_skip= 0;
496 ads->searchndots= 1;
497 ads->tcpstate= server_disconnected;
499 ads->searchlist= 0;
500
501 #ifdef ADNS_JGAA_WIN32
502 err= WSAStartup( wVersionRequested, &wsaData );
503 if ( err != 0 ) {
505 fprintf(ads->diagfile,"adns: WSAStartup() failed. \n");
506 return -1;}
507 if (LOBYTE( wsaData.wVersion ) != 2 ||
508 HIBYTE( wsaData.wVersion ) != 0 ) {
510 fprintf(ads->diagfile,"adns: Need Winsock 2.0 or better!\n");
511
512 WSACleanup();
513 return -1;}
514
515 /* The WinSock DLL is acceptable. Proceed. */
516#endif
517
518 *ads_r= ads;
519
520 return 0;
521}
#define timerclear(tvp)
Definition: rdesktop.h:190
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
unsigned short WORD
Definition: ntddk_ex.h:93
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
#define err(...)
void adns__vbuf_init(vbuf *vb)
Definition: general.c:112
WORD wVersion
Definition: winsock.h:517
int tcprecv_skip
Definition: internal.h:300
enum adns__state::adns__tcpstate tcpstate
int nextid
Definition: internal.h:297
struct timeval tcptimeout
Definition: internal.h:305
int tcpserver
Definition: internal.h:300
#define LIST_INIT(head)
Definition: queue.h:197
#define MAKEWORD(a, b)
Definition: typedefs.h:248

Referenced by adns_init(), and adns_init_strcfg().

◆ init_finish()

static int init_finish ( adns_state  ads)
static

Definition at line 523 of file setup.c.

523 {
524 struct protoent *proto;
525 int r;
526/* Don't add loopback on ReactOS it slows down queries to non existent server */
527#ifndef __REACTOS__
528 struct in_addr ia;
529 if (!ads->nservers) {
531 fprintf(ads->diagfile,"adns: no nameservers, using localhost\n");
532 ia.s_addr= htonl(INADDR_LOOPBACK);
533 addserver(ads,ia);
534 }
535#endif
536 proto= getprotobyname("udp"); if (!proto) { r= ENOPROTOOPT; goto x_free; }
540 if (ads->udpsocket<0) { r= errno; goto x_free; }
541
543 if (r) { r= errno; goto x_closeudp; }
544 return 0;
545
546 x_closeudp:
548 x_free:
549 free(ads);
550#ifdef ADNS_JGAA_WIN32
551 WSACleanup();
552#endif /* WIN32 */
553 return r;
554}
#define ADNS_CLEAR_ERRNO
Definition: adns_win32.h:108
#define ADNS_CAPTURE_ERRNO
Definition: adns_win32.h:107
#define ENOPROTOOPT
Definition: errno.h:100
#define AF_INET
Definition: tcpip.h:117
LPPROTOENT WSAAPI getprotobyname(IN CONST CHAR FAR *name)
Definition: getproto.c:305
#define INADDR_LOOPBACK
Definition: inet.h:51
int adns__setnonblock(adns_state ads, ADNS_SOCKET fd)
Definition: setup.c:457
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define SOCK_DGRAM
Definition: winsock.h:336

Referenced by adns_init(), and adns_init_strcfg().

◆ instrum_getenv()

static const char * instrum_getenv ( adns_state  ads,
const char envvar 
)
static

Definition at line 397 of file setup.c.

397 {
398 const char *value;
399
400 value= getenv(envvar);
401 if (!value) adns__debug(ads,-1,0,"environment variable %s not set",envvar);
402 else adns__debug(ads,-1,0,"environment variable %s set to `%s'",envvar,value);
403 return value;
404}
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
Definition: pdh_main.c:94

Referenced by adns_init(), readconfigenv(), and readconfigenvtext().

◆ nextword()

static int nextword ( const char **  bufp_io,
const char **  word_r,
int l_r 
)
static

Definition at line 93 of file setup.c.

93 {
94 const char *p, *q;
95
96 p= *bufp_io;
97 while (ctype_whitespace(*p)) p++;
98 if (!*p) return 0;
99
100 q= p;
101 while (*q && !ctype_whitespace(*q)) q++;
102
103 *l_r= q-p;
104 *word_r= p;
105 *bufp_io= q;
106
107 return 1;
108}
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static int ctype_whitespace(int c)
Definition: internal.h:697

Referenced by ccf_options(), ccf_search(), and ccf_sortlist().

◆ readconfig()

static void readconfig ( adns_state  ads,
const char filename,
int  warnmissing 
)
static

Definition at line 406 of file setup.c.

406 {
407 getline_ctx gl_ctx;
408
409 gl_ctx.file= fopen(filename,"r");
410 if (!gl_ctx.file) {
411 if (errno == ENOENT) {
412 if (warnmissing)
413 adns__debug(ads,-1,0,"configuration file `%s' does not exist",filename);
414 return;
415 }
417 adns__diag(ads,-1,0,"cannot open configuration file `%s': %s",
419 return;
420 }
421
423
424 fclose(gl_ctx.file);
425}
#define ENOENT
Definition: acclib.h:79
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
static int gl_file(adns_state ads, getline_ctx *src_io, const char *filename, int lno, char *buf, int buflen)
Definition: setup.c:293
static void readconfiggeneric(adns_state ads, const char *filename, int(*getline)(adns_state ads, getline_ctx *, const char *filename, int lno, char *buf, int buflen), getline_ctx gl_ctx)
Definition: setup.c:359

Referenced by adns_init(), ccf_include(), and readconfigenv().

◆ readconfigenv()

static void readconfigenv ( adns_state  ads,
const char envvar 
)
static

Definition at line 434 of file setup.c.

434 {
435 const char *filename;
436
437 if (ads->iflags & adns_if_noenv) {
438 adns__debug(ads,-1,0,"not checking environment variable `%s'",envvar);
439 return;
440 }
441 filename= instrum_getenv(ads,envvar);
443}
@ adns_if_noenv
Definition: adns.h:88

Referenced by adns_init().

◆ readconfigenvtext()

static void readconfigenvtext ( adns_state  ads,
const char envvar 
)
static

Definition at line 445 of file setup.c.

445 {
446 const char *textdata;
447
448 if (ads->iflags & adns_if_noenv) {
449 adns__debug(ads,-1,0,"not checking environment variable `%s'",envvar);
450 return;
451 }
452 textdata= instrum_getenv(ads,envvar);
453 if (textdata) readconfigtext(ads,textdata,envvar);
454}

Referenced by adns_init().

◆ readconfiggeneric()

static void readconfiggeneric ( adns_state  ads,
const char filename,
int(*)(adns_state ads, getline_ctx *, const char *filename, int lno, char *buf, int buflen)  getline,
getline_ctx  gl_ctx 
)
static

Definition at line 359 of file setup.c.

367 {
368 char linebuf[2000], *p, *q;
369 int lno, l, dirl;
370 const struct configcommandinfo *ccip;
371
372 for (lno=1;
373 (l= getline(ads,&gl_ctx, filename,lno, linebuf,sizeof(linebuf))) != -1;
374 lno++) {
375 if (l == -2) continue;
376 while (l>0 && ctype_whitespace(linebuf[l-1])) l--;
377 linebuf[l]= 0;
378 p= linebuf;
379 while (ctype_whitespace(*p)) p++;
380 if (*p == '#' || !*p) continue;
381 q= p;
382 while (*q && !ctype_whitespace(*q)) q++;
383 dirl= q-p;
384 for (ccip=configcommandinfos;
385 ccip->name && !((int)strlen(ccip->name)==dirl && !memcmp(ccip->name,p,q-p));
386 ccip++);
387 if (!ccip->name) {
388 adns__diag(ads,-1,0,"%s:%d: unknown configuration directive `%.*s'",
389 filename,lno,q-p,p);
390 continue;
391 }
392 while (ctype_whitespace(*q)) q++;
393 ccip->fn(ads,filename,lno,q);
394 }
395}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define getline
Definition: schily.h:567
static const struct configcommandinfo configcommandinfos[]
void(* fn)(adns_state ads, const char *fn, int lno, const char *buf)
Definition: setup.c:276
const char * name
Definition: setup.c:275

Referenced by readconfig(), and readconfigtext().

◆ readconfigtext()

static void readconfigtext ( adns_state  ads,
const char text,
const char showname 
)
static

Definition at line 427 of file setup.c.

427 {
428 getline_ctx gl_ctx;
429
430 gl_ctx.text= text;
431 readconfiggeneric(ads,showname,gl_text,gl_ctx);
432}
const WCHAR * text
Definition: package.c:1799
static int gl_text(adns_state ads, getline_ctx *src_io, const char *filename, int lno, char *buf, int buflen)
Definition: setup.c:337

Referenced by adns_init_strcfg(), and readconfigenvtext().

◆ saveerr()

static void saveerr ( adns_state  ads,
int  en 
)
static

Definition at line 74 of file setup.c.

74 {
76}
int en
Definition: doserrmap.h:8

Referenced by ccf_search(), configparseerr(), gl_file(), gl_text(), and readconfig().

Variable Documentation

◆ configcommandinfos

const struct configcommandinfo configcommandinfos[]
static
Initial value:
= {
{ "nameserver", ccf_nameserver },
{ "domain", ccf_search },
{ "search", ccf_search },
{ "sortlist", ccf_sortlist },
{ "options", ccf_options },
{ "clearnameservers", ccf_clearnss },
{ "include", ccf_include },
{ 0 }
}
static void ccf_nameserver(adns_state ads, const char *fn, int lno, const char *buf)
Definition: setup.c:110
static void ccf_clearnss(adns_state ads, const char *fn, int lno, const char *buf)
Definition: setup.c:262
static void ccf_sortlist(adns_state ads, const char *fn, int lno, const char *buf)
Definition: setup.c:150
static void ccf_include(adns_state ads, const char *fn, int lno, const char *buf)
Definition: setup.c:266

Referenced by readconfiggeneric().