Date: Thu, 15 Jun 2006 13:28:44 GMT From: Michael Bushkov <bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 99303 for review Message-ID: <200606151328.k5FDSibq046924@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=99303 Change 99303 by bushman@bushman_nss_ldap_cached on 2006/06/15 13:28:03 dns, nis and files module now use their own ***_hostent_data structures, instead of using the one, declared in libc (in netdb_private.h) some preparations to implement getipnodeby***() functions through gethostby***() functions were made Affected files ... .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_addrinfo.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_namadr.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_name6.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/nss_dns.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/files_hosts_namadr.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/files_hosts_name6.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/nss_files.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/nss_files.h#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_hosts_namadr.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_hosts_name6.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nss_nis.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/tests/ipnode_emul/Makefile#1 add .. //depot/projects/soc2006/nss_ldap_cached/tests/ipnode_emul/hosts_list#1 add .. //depot/projects/soc2006/nss_ldap_cached/tests/ipnode_emul/ipnode_emul_test.c#1 add Differences ... ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_addrinfo.c#3 (text+ko) ==== ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_namadr.c#3 (text+ko) ==== @@ -74,14 +74,13 @@ #include <syslog.h> #include <stdarg.h> #include <nsswitch.h> - #include "reentrant.h" #include "netdb_private.h" -#include "res_config.h" +#include "nss_dns.h" +#include "hosts_namadr.h" NETDB_THREAD_ALLOC(hostent) -NETDB_THREAD_ALLOC(hostent_data) -NETDB_THREAD_ALLOC(hostdata) +NETDB_THREAD_ALLOC(dns_hostent_data) static void hostent_free(void *ptr) @@ -90,26 +89,14 @@ } static void -hostent_data_free(void *ptr) +dns_hostent_data_free(void *ptr) { - struct hostent_data *hed = ptr; + struct dns_hostent_data *hed = ptr; if (hed == NULL) return; - hed->stayopen = 0; - - if (hed->hostf) { - (void) fclose(hed->hostf); - hed->hostf = NULL; - } - - free(hed); -} -static void -hostdata_free(void *ptr) -{ - free(ptr); + free(hed); } #define SPRINTF(x) ((size_t)sprintf x) @@ -507,7 +494,7 @@ size_t buflen; int *errnop, *h_errnop; struct hostent *hptr, he; - struct hostent_data *hed; + struct dns_hostent_data *hed; querybuf *buf; int n, type, error; res_state statp; @@ -523,7 +510,7 @@ *((struct hostent **)rval) = NULL; statp = __res_state(); - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __dns_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); @@ -588,7 +575,7 @@ int *errnop, *h_errnop; const u_char *uaddr; struct hostent *hptr, he; - struct hostent_data *hed; + struct dns_hostent_data *hed; int n; querybuf *buf; char qbuf[MAXDNAME+1], *qp; @@ -615,7 +602,7 @@ *((struct hostent **)rval) = NULL; statp = __res_state(); - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __dns_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_name6.c#3 (text+ko) ==== ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/files_hosts_namadr.c#2 (text+ko) ==== @@ -66,11 +66,37 @@ #include <nsswitch.h> #include <arpa/nameser.h> /* XXX */ #include <resolv.h> /* XXX */ +#include "reentrant.h" #include "netdb_private.h" +#include "nss_files.h" #include "hosts_namadr.h" +NETDB_THREAD_ALLOC(hostent) +NETDB_THREAD_ALLOC(files_hostent_data) + +static void +hostent_free(void *ptr) +{ + free(ptr); +} + +static void +files_hostent_data_free(void *ptr) +{ + struct hostent_data *hed = ptr; + + if (hed == NULL) + return; + + if (hed->hostf) { + (void) fclose(hed->hostf); + hed->hostf = NULL; + } + free(hed); +} + static void -sethosthtent(int f, struct hostent_data *hed) +sethosthtent(int f, struct files_hostent_data *hed) { if (!hed->hostf) hed->hostf = fopen(_PATH_HOSTS, "r"); @@ -80,7 +106,7 @@ } static void -endhosthtent(struct hostent_data *hed) +endhosthtent(struct files_hostent_data *hed) { if (hed->hostf && !hed->stayopen) { (void) fclose(hed->hostf); @@ -89,7 +115,7 @@ } static int -gethostent_p(struct hostent *he, struct hostent_data *hed, int mapped, +gethostent_p(struct hostent *he, struct files_hostent_data *hed, int mapped, res_state statp) { char *p, *bp, *ep; @@ -182,7 +208,7 @@ size_t buflen; int *errnop, *h_errnop; struct hostent *hptr, he; - struct hostent_data *hed; + struct files_hostent_data *hed; char **cp; res_state statp; int error; @@ -198,7 +224,7 @@ *((struct hostent **)rval) = NULL; statp = __res_state(); - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __files_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); @@ -245,7 +271,7 @@ size_t buflen; int *errnop, *h_errnop; struct hostent *hptr, he; - struct hostent_data *hed; + struct files_hostent_data *hed; res_state statp; int error; @@ -261,7 +287,7 @@ *((struct hostent **)rval) = NULL; statp = __res_state(); - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __files_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); @@ -296,7 +322,7 @@ char *buffer; size_t buflen; int *errnop, *h_errnop; - struct hostent_data *hed; + struct files_hostent_data *hed; struct hostent *hptr, he; res_state statp; @@ -314,7 +340,7 @@ *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); } - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __files_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); @@ -331,14 +357,14 @@ int __files_sethostent(void *rval, void *cb_data, va_list ap) { - struct hostent_data *hed; + struct files_hostent_data *hed; res_state statp; int f; f = va_arg(ap, int); statp = __res_state(); - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __files_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (NS_UNAVAIL); } @@ -351,11 +377,11 @@ int __files_endhostent(void *rval, void *cb_data, va_list ap) { - struct hostent_data *hed; + struct files_hostent_data *hed; res_state statp; statp = __res_state(); - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __files_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (NS_UNAVAIL); } ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/files_hosts_name6.c#2 (text+ko) ==== @@ -105,6 +105,20 @@ #include "netdb_private.h" #include "hosts_name6.h" +#ifndef _PATH_HOSTS +#define _PATH_HOSTS "/etc/hosts" +#endif + +#ifndef MAXALIASES +#define MAXALIASES 10 +#endif +#ifndef MAXADDRS +#define MAXADDRS 20 +#endif +#ifndef MAXDNAME +#define MAXDNAME 1025 +#endif + static FILE * _files_open(int *errp) { ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/nss_files.c#3 (text+ko) ==== @@ -78,6 +78,7 @@ {NSDB_HOSTS, "gethostbyaddr_r", __files_gethostbyaddr_r, NULL}, {NSDB_HOSTS, "ghbyname", __files_ghbyname, NULL}, {NSDB_HOSTS, "ghbyaddr", __files_ghbyaddr, NULL}, + {NSDB_HOSTS, "getaddrinfo", __files_getaddrinfo, NULL}, {NSDB_HOSTS_INTERNAL, "gethostent_r", __files_gethostent_r, NULL}, {NSDB_HOSTS_INTERNAL, "sethostent", __files_sethostent, NULL}, {NSDB_HOSTS_INTERNAL, "endhostent", __files_endhostent, NULL}, ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/nss_files.h#2 (text+ko) ==== @@ -30,3 +30,25 @@ nss_set_ent = 1, nss_end_ent = 2 }; + +#ifndef _MAXALIASES +#define _MAXALIASES 35 +#endif +#ifndef _MAXLINELEN +#define _MAXLINELEN 1024 +#endif +#ifndef _MAXADDRS +#define _MAXADDRS 35 +#endif +#ifndef _HOSTBUFSIZE +#define _HOSTBUFSIZE (8 * 1024) +#endif + +struct files_hostent_data { + uint32_t host_addr[4]; /* IPv4 or IPv6 */ + char *h_addr_ptrs[_MAXADDRS + 1]; + char *host_aliases[_MAXALIASES]; + char hostbuf[_HOSTBUFSIZE]; + FILE *hostf; + int stayopen; +}; ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_hosts_namadr.c#2 (text+ko) ==== @@ -40,19 +40,41 @@ #include <stdarg.h> #include <nsswitch.h> #include <resolv.h> /* XXX */ -#ifdef YP +//#ifdef YP #include <rpc/rpc.h> #include <rpcsvc/yp_prot.h> #include <rpcsvc/ypclnt.h> -#endif +//#endif #include <stdarg.h> #include <nsswitch.h> +#include "reentrant.h" #include "netdb_private.h" +#include "nss_nis.h" +#include "hosts_namadr.h" + +NETDB_THREAD_ALLOC(hostent) +NETDB_THREAD_ALLOC(nis_hostent_data) + +static void +hostent_free(void *ptr) +{ + free(ptr); +} + +static void +nis_hostent_data_free(void *ptr) +{ + struct nis_hostent_data *hed = ptr; + + if (hed == NULL) + return; + free(hed); +} -#ifdef YP +//#ifdef YP static int _gethostbynis(const char *name, char *map, int af, struct hostent *he, - struct hostent_data *hed) + struct nis_hostent_data *hed) { char *p, *bp, *ep; char *cp, **q; @@ -164,7 +186,7 @@ static int _gethostbynisname_r(const char *name, int af, struct hostent *he, - struct hostent_data *hed) + struct nis_hostent_data *hed) { char *map; @@ -181,7 +203,7 @@ static int _gethostbynisaddr_r(const void *addr, socklen_t len, int af, - struct hostent *he, struct hostent_data *hed) + struct hostent *he, struct nis_hostent_data *hed) { char *map; char numaddr[46]; @@ -198,22 +220,22 @@ return (-1); return (_gethostbynis(numaddr, map, af, he, hed)); } -#endif /* YP */ +//#endif /* YP */ /* XXX _gethostbynisname/_gethostbynisaddr only used by getipnodeby*() */ struct hostent * _gethostbynisname(const char *name, int af) { -#ifdef YP +//#ifdef YP struct hostent *he; - struct hostent_data *hed; + struct nis_hostent_data *hed; u_long oresopt; int error; res_state statp; statp = __res_state(); if ((he = __hostent_init()) == NULL || - (hed = __hostent_data_init()) == NULL) { + (hed = __nis_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (NULL); } @@ -223,24 +245,24 @@ error = _gethostbynisname_r(name, af, he, hed); statp->options = oresopt; return (error == 0) ? he : NULL; -#else - return (NULL); -#endif +//#else +// return (NULL); +//#endif } struct hostent * _gethostbynisaddr(const void *addr, socklen_t len, int af) { -#ifdef YP +//#ifdef YP struct hostent *he; - struct hostent_data *hed; + struct nis_hostent_data *hed; u_long oresopt; int error; res_state statp; statp = __res_state(); if ((he = __hostent_init()) == NULL || - (hed = __hostent_data_init()) == NULL) { + (hed = __nis_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (NULL); } @@ -250,22 +272,22 @@ error = _gethostbynisaddr_r(addr, len, af, he, hed); statp->options = oresopt; return (error == 0) ? he : NULL; -#else - return (NULL); -#endif +//#else +// return (NULL); +//#endif } int __nis_gethostbyname2_r(void *rval, void *cb_data, va_list ap) { -#ifdef YP +//#ifdef YP const char *name; int af; char *buffer; size_t buflen; int *errnop, *h_errnop; struct hostent *hptr, he; - struct hostent_data *hed; + struct nis_hostent_data *hed; res_state statp; name = va_arg(ap, const char *); @@ -279,7 +301,7 @@ *((struct hostent **)rval) = NULL; statp = __res_state(); - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __nis_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); @@ -295,16 +317,16 @@ } *((struct hostent **)rval) = hptr; return (NS_SUCCESS); -#else - *((struct hostent **)rval) = NULL; - return (NS_UNAVAIL); -#endif +//#else +// *((struct hostent **)rval) = NULL; +// return (NS_UNAVAIL); +//#endif } int __nis_gethostbyaddr_r(void *rval, void *cb_data, va_list ap) { -#ifdef YP +//#ifdef YP const void *addr; socklen_t len; int af; @@ -312,7 +334,7 @@ size_t buflen; int *errnop, *h_errnop; struct hostent *hptr, he; - struct hostent_data *hed; + struct nis_hostent_data *hed; res_state statp; addr = va_arg(ap, const void *); @@ -327,7 +349,7 @@ *((struct hostent **)rval) = NULL; statp = __res_state(); - if ((hed = __hostent_data_init()) == NULL) { + if ((hed = __nis_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); @@ -343,8 +365,8 @@ } *((struct hostent **)rval) = hptr; return (NS_SUCCESS); -#else - *((struct hostent **)rval) = NULL; - return (NS_UNAVAIL); -#endif +//#else +// *((struct hostent **)rval) = NULL; + //return (NS_UNAVAIL); +//#endif } ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_hosts_name6.c#2 (text+ko) ==== @@ -104,11 +104,11 @@ #include <stdarg.h> #include <nsswitch.h> #include <resolv.h> /* XXX */ -#ifdef YP +//#ifdef YP #include <rpc/rpc.h> #include <rpcsvc/yp_prot.h> #include <rpcsvc/ypclnt.h> -#endif +//#endif #include <stdarg.h> #include <nsswitch.h> #include "netdb_private.h"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606151328.k5FDSibq046924>