X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsetup.c;h=3646968cd7a3b27d9126f412f749212464abae6c;hb=HEAD;hp=c67b042fa42b273b54a4c2674737b4278dd7bd74;hpb=8b9cc94c86219c75366c091e8a604d3420c155a0;p=adns.git diff --git a/src/setup.c b/src/setup.c index c67b042..a10cbf8 100644 --- a/src/setup.c +++ b/src/setup.c @@ -4,12 +4,8 @@ * - management of global state */ /* - * This file is part of adns, which is - * Copyright (C) 1997-2000,2003,2006,2014 Ian Jackson - * Copyright (C) 2014 Mark Wooding - * Copyright (C) 1999-2000,2003,2006 Tony Finch - * Copyright (C) 1991 Massachusetts Institute of Technology - * (See the file INSTALL for full details.) + * This file is part of adns, which is Copyright Ian Jackson + * and contributors (see the file INSTALL for full details). * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -147,11 +143,17 @@ static void ccf_search(adns_state ads, const char *fn, tl= 0; while (nextword(&bufp,&word,&l)) { count++; tl += l+1; } - newptrs= malloc(sizeof(char*)*count); - if (!newptrs) { saveerr(ads,errno); return; } + if (count) { + newptrs= malloc(sizeof(char*)*count); + if (!newptrs) { saveerr(ads,errno); return; } - newchars= malloc(tl); - if (!newchars) { saveerr(ads,errno); free(newptrs); return; } + newchars= malloc(tl); + if (!newchars) { saveerr(ads,errno); free(newptrs); return; } + } else { + assert(!tl); + newptrs= 0; + newchars= 0; + } bufp= buf; pp= newptrs; @@ -222,11 +224,12 @@ static void ccf_sortlist(adns_state ads, const char *fn, } } else { maskwhat = "prefix length"; - initial= strtoul(slash,&ep,10); - if (*ep || initial>adns__addr_width(sl->base.sa.sa_family)) { + unsigned long prefixlen = strtoul(slash,&ep,10); + if (*ep || prefixlen>adns__addr_width(sl->base.sa.sa_family)) { configparseerr(ads,fn,lno,"mask length `%s' invalid",slash); continue; } + initial= prefixlen; sl->mask.sa.sa_family= sl->base.sa.sa_family; adns__prefix_mask(&sl->mask, initial); } @@ -341,6 +344,8 @@ static void ccf_options(adns_state ads, const char *fn, /* adns normally does IPv6 if the application wants it; control * this with the adns_af: option if you like */ WORD_IS("inet6") || + /* adns trusts the resolver anyway */ + WORD_IS("trust-ad") || /* adns does not do edns0 and this is not a problem */ WORD_IS("edns0")) continue; @@ -735,7 +740,7 @@ static int init_files(adns_state *ads_r, adns_initflags flags, r= init_finish(ads); if (r) return r; - adns__consistency(ads,0,cc_entex); + adns__consistency(ads,0,cc_exit); *ads_r= ads; return 0; } @@ -761,7 +766,7 @@ static int init_strcfg(adns_state *ads_r, adns_initflags flags, } r= init_finish(ads); if (r) return r; - adns__consistency(ads,0,cc_entex); + adns__consistency(ads,0,cc_exit); *ads_r= ads; return 0; } @@ -785,15 +790,20 @@ int adns_init_logfn(adns_state *newstate_r, adns_initflags flags, return init_files(newstate_r, flags, logfn, logfndata); } +static void cancel_all(adns_query qu) { + if (!qu->parent) adns__cancel(qu); + else cancel_all(qu->parent); +} + void adns_finish(adns_state ads) { int i; - adns__consistency(ads,0,cc_entex); + adns__consistency(ads,0,cc_enter); 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 if (ads->intdone.head) adns__cancel(ads->output.head); + if (ads->udpw.head) cancel_all(ads->udpw.head); + else if (ads->tcpw.head) cancel_all(ads->tcpw.head); + else if (ads->childw.head) cancel_all(ads->childw.head); + else if (ads->output.head) cancel_all(ads->output.head); + else if (ads->intdone.head) cancel_all(ads->output.head); else break; } for (i=0; inudpsockets; i++) close(ads->udpsockets[i].fd); @@ -805,7 +815,7 @@ void adns_finish(adns_state ads) { } void adns_forallqueries_begin(adns_state ads) { - adns__consistency(ads,0,cc_entex); + adns__consistency(ads,0,cc_enter); ads->forallnext= ads->udpw.head ? ads->udpw.head : ads->tcpw.head ? ads->tcpw.head : @@ -816,7 +826,7 @@ void adns_forallqueries_begin(adns_state ads) { adns_query adns_forallqueries_next(adns_state ads, void **context_r) { adns_query qu, nqu; - adns__consistency(ads,0,cc_entex); + adns__consistency(ads,0,cc_enter); nqu= ads->forallnext; for (;;) { qu= nqu;