diff options
author | ume <ume@FreeBSD.org> | 2014-08-12 12:36:06 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2014-08-12 12:36:06 +0000 |
commit | 228ba577ee2fd73c3d7730e20393d74b4d891111 (patch) | |
tree | 938ab439d250fb1516204993b2240002b1f6ab68 /lib/libc/resolv/res_init.c | |
parent | e288c0740572b3d645a22c8a24a9d70bd174d642 (diff) | |
download | FreeBSD-src-228ba577ee2fd73c3d7730e20393d74b4d891111.zip FreeBSD-src-228ba577ee2fd73c3d7730e20393d74b4d891111.tar.gz |
Update our stub resolver to final version of libbind.
Obtained from: ISC
Diffstat (limited to 'lib/libc/resolv/res_init.c')
-rw-r--r-- | lib/libc/resolv/res_init.c | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c index 5193c1d..b5444ef 100644 --- a/lib/libc/resolv/res_init.c +++ b/lib/libc/resolv/res_init.c @@ -66,7 +66,7 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static const char rcsid[] = "$Id: res_init.c,v 1.16.18.7 2007/07/09 01:52:58 marka Exp $"; +static const char rcsid[] = "$Id: res_init.c,v 1.26 2008/12/11 09:59:00 marka Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -91,6 +91,19 @@ __FBSDID("$FreeBSD$"); #include <unistd.h> #include <netdb.h> +#ifndef HAVE_MD5 +# include "../dst/md5.h" +#else +# ifdef SOLARIS2 +# include <sys/md5.h> +# elif _LIBC +# include <md5.h> +# endif +#endif +#ifndef _MD5_H_ +# define _MD5_H_ 1 /*%< make sure we do not include rsaref md5.h file */ +#endif + #include "un-namespace.h" #include "port_after.h" @@ -178,9 +191,12 @@ __res_vinit(res_state statp, int preinit) { statp->retrans = RES_TIMEOUT; statp->retry = RES_DFLRETRY; statp->options = RES_DEFAULT; - statp->id = res_randomid(); } + statp->_rnd = malloc(16); + res_rndinit(statp); + statp->id = res_nrandomid(statp); + memset(u, 0, sizeof(u)); #ifdef USELOOPBACK u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); @@ -715,12 +731,48 @@ net_mask(in) /*!< XXX - should really use system's version of this */ } #endif +static u_char srnd[16]; + +void +res_rndinit(res_state statp) +{ + struct timeval now; + u_int32_t u32; + u_int16_t u16; + u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd; + + gettimeofday(&now, NULL); + u32 = now.tv_sec; + memcpy(rnd, &u32, 4); + u32 = now.tv_usec; + memcpy(rnd + 4, &u32, 4); + u32 += now.tv_sec; + memcpy(rnd + 8, &u32, 4); + u16 = getpid(); + memcpy(rnd + 12, &u16, 2); +} + u_int -res_randomid(void) { +res_nrandomid(res_state statp) { struct timeval now; + u_int16_t u16; + MD5_CTX ctx; + u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd; gettimeofday(&now, NULL); - return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid())); + u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec); + memcpy(rnd + 14, &u16, 2); +#ifndef HAVE_MD5 + MD5_Init(&ctx); + MD5_Update(&ctx, rnd, 16); + MD5_Final(rnd, &ctx); +#else + MD5Init(&ctx); + MD5Update(&ctx, rnd, 16); + MD5Final(rnd, &ctx); +#endif + memcpy(&u16, rnd + 14, 2); + return ((u_int) u16); } /*% @@ -750,10 +802,15 @@ res_nclose(res_state statp) { void res_ndestroy(res_state statp) { res_nclose(statp); - if (statp->_u._ext.ext != NULL) + if (statp->_u._ext.ext != NULL) { free(statp->_u._ext.ext); + statp->_u._ext.ext = NULL; + } + if (statp->_rnd != NULL) { + free(statp->_rnd); + statp->_rnd = NULL; + } statp->options &= ~RES_INIT; - statp->_u._ext.ext = NULL; } #ifndef _LIBC |