diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2005-03-30 02:58:29 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2005-03-30 02:58:29 +0000 |
commit | 2888f4c4d0bbd1e24c59ba84c0a7de66b9e4ed20 (patch) | |
tree | 11ec334e5e40ff7983088bb0863ebb71d9919a0e /lib | |
parent | 424c347dcc972c68eabb182bda67376354129ddb (diff) |
make the resolver stat resolv.conf and update if it changes.
useful feedback and ok deraadt@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 10 | ||||
-rw-r--r-- | lib/libc/net/gethostnamadr.c | 8 | ||||
-rw-r--r-- | lib/libc/net/getnetnamadr.c | 8 | ||||
-rw-r--r-- | lib/libc/net/getrrsetbyname.c | 4 | ||||
-rw-r--r-- | lib/libc/net/res_debug.c | 8 | ||||
-rw-r--r-- | lib/libc/net/res_init.c | 38 | ||||
-rw-r--r-- | lib/libc/net/res_mkquery.c | 6 | ||||
-rw-r--r-- | lib/libc/net/res_query.c | 10 | ||||
-rw-r--r-- | lib/libc/net/res_send.c | 6 | ||||
-rw-r--r-- | lib/libc/net/sethostent.c | 4 |
10 files changed, 68 insertions, 34 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index c7cc0500c33..19967e84327 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo.c,v 1.51 2005/03/25 13:24:12 otto Exp $ */ +/* $OpenBSD: getaddrinfo.c,v 1.52 2005/03/30 02:58:28 tedu Exp $ */ /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ /* @@ -516,7 +516,7 @@ explore_fqdn(const struct addrinfo *pai, const char *hostname, return 0; } - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_res_init(0) == -1) strlcpy(lookups, "f", sizeof lookups); else { bcopy(_resp->lookups, lookups, sizeof lookups); @@ -1525,7 +1525,7 @@ res_queryN(const char *name, struct res_target *target) rcode = NOERROR; ancount = 0; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { h_errno = NETDB_INTERNAL; free(buf); return (-1); @@ -1631,7 +1631,7 @@ res_searchN(const char *name, struct res_target *target) int trailing_dot, ret, saved_herrno; int got_nodata = 0, got_servfail = 0, tried_as_is = 0; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { h_errno = NETDB_INTERNAL; return (-1); } @@ -1768,7 +1768,7 @@ res_querydomainN(const char *name, const char *domain, const char *longname = nbuf; size_t n, d; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { h_errno = NETDB_INTERNAL; return (-1); } diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 0a42d0a27ea..c643f2382ae 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -48,7 +48,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.60 2004/07/29 03:09:40 itojun Exp $"; +static const char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.61 2005/03/30 02:58:28 tedu Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -479,7 +479,7 @@ gethostbyname(const char *name) struct hostent *hp; extern struct hostent *_gethtbyname2(const char *, int); - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_res_init(0) == -1) hp = _gethtbyname2(name, AF_INET); else if (_resp->options & RES_USE_INET6) { @@ -505,7 +505,7 @@ gethostbyname2(const char *name, int af) extern struct hostent *_gethtbyname2(const char *, int); extern struct hostent *_yp_gethtbyname(const char *); - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_res_init(0) == -1) return (_gethtbyname2(name, af)); switch (af) { @@ -653,7 +653,7 @@ gethostbyaddr(const char *addr, int len, int af) extern struct hostent *_gethtbyaddr(const char *, int, int); extern struct hostent *_yp_gethtbyaddr(const char *); - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { res = _gethtbyaddr(addr, len, af); return (res); } diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c index 42410264b13..303ac2cc54a 100644 --- a/lib/libc/net/getnetnamadr.c +++ b/lib/libc/net/getnetnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr.c,v 1.24 2005/03/25 13:24:12 otto Exp $ */ +/* $OpenBSD: getnetnamadr.c,v 1.25 2005/03/30 02:58:28 tedu Exp $ */ /* * Copyright (c) 1997, Jason Downs. All rights reserved. @@ -66,7 +66,7 @@ static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.24 2005/03/25 13:24:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.25 2005/03/30 02:58:28 tedu Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -259,7 +259,7 @@ getnetbyaddr(in_addr_t net, int net_type) char lookups[MAXDNSLUS]; int i; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_res_init(0) == -1) return(_getnetbyaddr(net, net_type)); bcopy(_resp->lookups, lookups, sizeof lookups); @@ -347,7 +347,7 @@ getnetbyname(const char *net) char lookups[MAXDNSLUS]; int i; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_res_init(0) == -1) return (_getnetbyname(net)); bcopy(_resp->lookups, lookups, sizeof lookups); diff --git a/lib/libc/net/getrrsetbyname.c b/lib/libc/net/getrrsetbyname.c index dcfc86a6918..e679eb5d963 100644 --- a/lib/libc/net/getrrsetbyname.c +++ b/lib/libc/net/getrrsetbyname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getrrsetbyname.c,v 1.9 2005/03/25 13:24:12 otto Exp $ */ +/* $OpenBSD: getrrsetbyname.c,v 1.10 2005/03/30 02:58:28 tedu Exp $ */ /* * Copyright (c) 2001 Jakob Schlyter. All rights reserved. @@ -126,7 +126,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass, } /* initialize resolver */ - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { result = ERRSET_FAIL; goto fail; } diff --git a/lib/libc/net/res_debug.c b/lib/libc/net/res_debug.c index 02f9e4a1ea1..82a067c1f0a 100644 --- a/lib/libc/net/res_debug.c +++ b/lib/libc/net/res_debug.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_debug.c,v 1.19 2005/03/25 13:24:12 otto Exp $ */ +/* $OpenBSD: res_debug.c,v 1.20 2005/03/30 02:58:28 tedu Exp $ */ /* * ++Copyright++ 1985, 1990, 1993 @@ -78,7 +78,7 @@ static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$From: res_debug.c,v 8.19 1996/11/26 10:11:23 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_debug.c,v 1.19 2005/03/25 13:24:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: res_debug.c,v 1.20 2005/03/30 02:58:28 tedu Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -264,7 +264,7 @@ __fp_nquery(const u_char *msg, int len, FILE *file) const HEADER *hp; int n; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_res_init(0) == -1) return; #define TruncTest(x) if (x > endMark) goto trunc @@ -462,7 +462,7 @@ __p_rr(const u_char *cp, const u_char *msg, FILE *file) char rrname[MAXDNAME]; /* The fqdn of this RR */ char base64_key[MAX_KEY_BASE64]; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { h_errno = NETDB_INTERNAL; return (NULL); } diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c index f4a8d31cb1f..110542a4042 100644 --- a/lib/libc/net/res_init.c +++ b/lib/libc/net/res_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_init.c,v 1.31 2005/03/25 13:24:12 otto Exp $ */ +/* $OpenBSD: res_init.c,v 1.32 2005/03/30 02:58:28 tedu Exp $ */ /* * ++Copyright++ 1985, 1989, 1993 @@ -60,7 +60,7 @@ static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; static char rcsid[] = "$From: res_init.c,v 8.7 1996/09/28 06:51:07 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_init.c,v 1.31 2005/03/25 13:24:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: res_init.c,v 1.32 2005/03/30 02:58:28 tedu Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -68,6 +68,7 @@ static char rcsid[] = "$OpenBSD: res_init.c,v 1.31 2005/03/25 13:24:12 otto Exp #include <sys/param.h> #include <sys/socket.h> #include <sys/time.h> +#include <sys/stat.h> #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> @@ -131,6 +132,8 @@ void *__THREAD_NAME(_res_ext); struct __res_state_ext _res_ext; #endif /* INET6 */ +int __res_chktime = 30; + /* * Set up default settings. If the configuration file exist, the values * there will have precedence. Otherwise, the server address is set to @@ -155,6 +158,14 @@ struct __res_state_ext _res_ext; int res_init(void) { + + return (_res_init(1)); +} + +int +_res_init(int usercall) +{ + struct stat sb; struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); #ifdef INET6 struct __res_state_ext *_res_extp = _THREAD_PRIVATE(_res_ext, _res_ext, @@ -176,6 +187,29 @@ res_init(void) int dots; #endif + if (usercall == 0) { + if (_resp->options & RES_INIT && + _resp->reschktime >= time(NULL)) + return (0); + _resp->reschktime = time(NULL) + __res_chktime; + if (stat(_PATH_RESCONF, &sb) != -1) { + if (timespeccmp(&sb.st_mtimespec, + &_resp->restimespec, ==)) + return (0); + else + _resp->restimespec = sb.st_mtimespec; + } else { + /* + * Lost the file, in chroot? + * Don' trash settings + */ + if (timespecisset(&_resp->restimespec)) + return (0); + } + } else + _resp->reschktime = time(NULL) + __res_chktime; + + /* * These three fields used to be statically initialized. This made * it hard to use this code in a shared library. It is necessary, diff --git a/lib/libc/net/res_mkquery.c b/lib/libc/net/res_mkquery.c index 28ae92056d8..a6c37379f9d 100644 --- a/lib/libc/net/res_mkquery.c +++ b/lib/libc/net/res_mkquery.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_mkquery.c,v 1.15 2005/03/25 13:24:12 otto Exp $ */ +/* $OpenBSD: res_mkquery.c,v 1.16 2005/03/30 02:58:28 tedu Exp $ */ /* * ++Copyright++ 1985, 1993 @@ -56,7 +56,7 @@ static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$From: res_mkquery.c,v 8.5 1996/08/27 08:33:28 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.15 2005/03/25 13:24:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: res_mkquery.c,v 1.16 2005/03/30 02:58:28 tedu Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -94,7 +94,7 @@ res_mkquery(int op, int n; u_char *dnptrs[20], **dpp, **lastdnptr; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { h_errno = NETDB_INTERNAL; return (-1); } diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c index 677c411a6e4..4af1651cf13 100644 --- a/lib/libc/net/res_query.c +++ b/lib/libc/net/res_query.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_query.c,v 1.22 2005/03/25 13:24:12 otto Exp $ */ +/* $OpenBSD: res_query.c,v 1.23 2005/03/30 02:58:28 tedu Exp $ */ /* * ++Copyright++ 1988, 1993 @@ -56,7 +56,7 @@ static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$From: res_query.c,v 8.9 1996/09/22 00:13:28 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_query.c,v 1.22 2005/03/25 13:24:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: res_query.c,v 1.23 2005/03/30 02:58:28 tedu Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -111,7 +111,7 @@ res_query(const char *name, hp->rcode = NOERROR; /* default */ - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { h_errno = NETDB_INTERNAL; return (-1); } @@ -193,7 +193,7 @@ res_search(const char *name, int trailing_dot, ret, saved_herrno; int got_nodata = 0, got_servfail = 0, tried_as_is = 0; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { h_errno = NETDB_INTERNAL; return (-1); } @@ -332,7 +332,7 @@ res_querydomain(const char *name, const char *longname = nbuf; int n; - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { h_errno = NETDB_INTERNAL; return (-1); } diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c index 04eb268d902..ee7ce430350 100644 --- a/lib/libc/net/res_send.c +++ b/lib/libc/net/res_send.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_send.c,v 1.17 2005/03/25 13:24:12 otto Exp $ */ +/* $OpenBSD: res_send.c,v 1.18 2005/03/30 02:58:28 tedu Exp $ */ /* * ++Copyright++ 1985, 1989, 1993 @@ -60,7 +60,7 @@ static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$From: res_send.c,v 8.12 1996/10/08 04:51:06 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: res_send.c,v 1.17 2005/03/25 13:24:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: res_send.c,v 1.18 2005/03/30 02:58:28 tedu Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -343,7 +343,7 @@ res_send(const u_char *buf, int buflen, u_char *ans, int anssiz) int n; u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { + if (_res_init(0) == -1) { /* errno should have been set by res_init() in this case. */ return (-1); } diff --git a/lib/libc/net/sethostent.c b/lib/libc/net/sethostent.c index 2140d65d08b..c0eae942ca0 100644 --- a/lib/libc/net/sethostent.c +++ b/lib/libc/net/sethostent.c @@ -28,7 +28,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: sethostent.c,v 1.7 2005/03/25 13:24:12 otto Exp $"; +static char rcsid[] = "$OpenBSD: sethostent.c,v 1.8 2005/03/30 02:58:28 tedu Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -44,7 +44,7 @@ sethostent(int stayopen) { struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res); - if ((_resp->options & RES_INIT) == 0 && res_init() == -1) + if (_res_init(0) == -1) return; if (stayopen) _resp->options |= RES_STAYOPEN | RES_USEVC; |