Date: Sun, 18 Jun 2006 13:55:58 GMT From: Michael Bushkov <bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 99518 for review Message-ID: <200606181355.k5IDtw6K017289@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=99518 Change 99518 by bushman@bushman_nss_ldap_cached on 2006/06/18 13:55:09 Support for "passwd" and "group" databases added to the nss-modules. IPv4 to IPv6 mapping was tested in ghby_emul test. Affected files ... .. //depot/projects/soc2006/nss_ldap_cached/src/lib/Makefile#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/Makefile.inc#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/Makefile#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_group.c#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_group.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_addrinfo.c#4 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_namadr.c#4 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_net.c#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_net.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_passwd.c#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_passwd.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/nss_dns.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/res_config.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/Makefile#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/files_group.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/files_hosts_namadr.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/nss_files.c#4 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/Makefile#2 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_group.c#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_group.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_hosts_namadr.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_net.c#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_net.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_passwd.c#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_passwd.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nss_nis.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/tests/ghby_emul/Makefile#2 edit .. //depot/projects/soc2006/nss_ldap_cached/tests/ghby_emul/ghby_emul_test.c#2 edit .. //depot/projects/soc2006/nss_ldap_cached/tests/ghby_emul/hosts_list#2 edit Differences ... ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/Makefile#3 (text+ko) ==== @@ -25,7 +25,7 @@ # Otherwise, the SUBDIR list should be in alphabetical order. SUBDIR= ${_csu} libbsm libcom_err libcrypt libkvm msun libmd libncurses \ - nss_files nss_dns\ + nss_files nss_dns nss_icmp ${_nss_nis}\ libnetgraph libradius librpcsvc libsbuf libtacplus libutil \ ${_libypclnt} libalias libarchive ${_libatm} \ libbegemot ${_libbluetooth} libbsnmp libbz2 libc ${_libc_r} \ ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/Makefile.inc#2 (text+ko) ==== @@ -5,8 +5,7 @@ .PATH: ${.CURDIR}/${MACHINE_ARCH}/net ${.CURDIR}/net SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c eui64.c \ - gai_strerror.c getaddrinfo.c \ - gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \ + gai_strerror.c getaddrinfo.c gethostnamadr.c \ getifaddrs.c getifmaddrs.c getnameinfo.c \ getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \ getproto.c getprotoent.c getprotoname.c getservent.c \ @@ -120,4 +119,3 @@ SRCS+= hesiod.c MAN+= hesiod.3 .endif - ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/Makefile#2 (text+ko) ==== @@ -3,14 +3,10 @@ LIB= nss_dns SHLIB_MAJOR= 1 SHLIBDIR?= /lib -#PROG= nss_dns +PROG= nss_dns CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../libc/gen -I${.CURDIR}/../libc/include\ - -I${.CURDIR}/../libc/net -I${.CURDIR}/../libnssutil -SRCS= nss_dns.c dns_hosts_namadr.c dns_hosts_name6.c\ - dns_hosts_addrinfo.c ${.CURDIR}/../libc/net/map_v4v6.c -DPADD+= nssutil -LDADD+= -lnssutil -LDFLAGS+= -L${.CURDIR}/../libnssutil + -I${.CURDIR}/../libc/net +SRCS= nss_dns.c dns_hosts_namadr.c dns_hosts_addrinfo.c dns_passwd.c INCS= MAN= ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_addrinfo.c#4 (text+ko) ==== @@ -182,6 +182,9 @@ static int res_querydomainN(const char *, const char *, struct res_target *, res_state); +static int str2number(const char *p); + + static int get_canonname(const struct addrinfo *pai, struct addrinfo *ai, const char *str) { @@ -992,6 +995,22 @@ } #endif /*RESOLVSORT*/ +static int +str2number(const char *p) +{ + char *ep; + unsigned long v; + + if (*p == '\0') + return -1; + ep = NULL; + errno = 0; + v = strtoul(p, &ep, 10); + if (errno == 0 && ep && *ep == '\0' && v <= UINT_MAX) + return v; + else + return -1; +} /*ARGSUSED*/ int ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/dns_hosts_namadr.c#4 (text+ko) ==== @@ -77,7 +77,6 @@ #include "reentrant.h" #include "netdb_private.h" #include "nss_dns.h" -#include "hosts_namadr.h" NETDB_THREAD_ALLOC(hostent) NETDB_THREAD_ALLOC(dns_hostent_data) @@ -99,6 +98,68 @@ free(hed); } +static int +__copy_hostent(struct hostent *he, struct hostent *hptr, char *buf, + size_t buflen) +{ + char *cp; + char **ptr; + int i, n; + int nptr, len; + + /* Find out the amount of space required to store the answer. */ + nptr = 2; /* NULL ptrs */ + len = (char *)ALIGN(buf) - buf; + for (i = 0; he->h_addr_list[i]; i++, nptr++) { + len += he->h_length; + } + for (i = 0; he->h_aliases[i]; i++, nptr++) { + len += strlen(he->h_aliases[i]) + 1; + } + len += strlen(he->h_name) + 1; + len += nptr * sizeof(char*); + + if (len > buflen) { + errno = ERANGE; + return (-1); + } + + /* copy address size and type */ + hptr->h_addrtype = he->h_addrtype; + n = hptr->h_length = he->h_length; + + ptr = (char **)ALIGN(buf); + cp = (char *)ALIGN(buf) + nptr * sizeof(char *); + + /* copy address list */ + hptr->h_addr_list = ptr; + for (i = 0; he->h_addr_list[i]; i++ , ptr++) { + memcpy(cp, he->h_addr_list[i], n); + hptr->h_addr_list[i] = cp; + cp += n; + } + hptr->h_addr_list[i] = NULL; + ptr++; + + /* copy official name */ + n = strlen(he->h_name) + 1; + strcpy(cp, he->h_name); + hptr->h_name = cp; + cp += n; + + /* copy aliases */ + hptr->h_aliases = ptr; + for (i = 0 ; he->h_aliases[i]; i++) { + n = strlen(he->h_aliases[i]) + 1; + strcpy(cp, he->h_aliases[i]); + hptr->h_aliases[i] = cp; + cp += n; + } + hptr->h_aliases[i] = NULL; + + return (0); +} + #define SPRINTF(x) ((size_t)sprintf x) static const char AskedForGot[] = @@ -163,7 +224,7 @@ static int gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype, - struct hostent *he, struct hostent_data *hed, res_state statp) + struct hostent *he, struct dns_hostent_data *hed, res_state statp) { const HEADER *hp; const u_char *cp; @@ -359,15 +420,15 @@ break; #else he->h_name = bp; - if (statp->options & RES_USE_INET6) { - n = strlen(bp) + 1; /* for the \0 */ - if (n >= MAXHOSTNAMELEN) { - had_error++; - break; - } - bp += n; - _map_v4v6_hostent(he, &bp, ep); - } +// if (statp->options & RES_USE_INET6) { +// n = strlen(bp) + 1; /* for the \0 */ +// if (n >= MAXHOSTNAMELEN) { +// had_error++; +// break; +// } +// bp += n; +// _map_v4v6_hostent(he, &bp, ep); +// } RES_SET_H_ERRNO(statp, NETDB_SUCCESS); return (0); #endif @@ -443,8 +504,8 @@ he->h_name = bp; bp += n; } - if (statp->options & RES_USE_INET6) - _map_v4v6_hostent(he, &bp, ep); +// if (statp->options & RES_USE_INET6) +// _map_v4v6_hostent(he, &bp, ep); RES_SET_H_ERRNO(statp, NETDB_SUCCESS); return (0); } @@ -458,13 +519,13 @@ __dns_getanswer(const char *answer, int anslen, const char *qname, int qtype) { struct hostent *he; - struct hostent_data *hed; + struct dns_hostent_data *hed; int error; res_state statp; statp = __res_state(); if ((he = __hostent_init()) == NULL || - (hed = __hostent_data_init()) == NULL) { + (hed = __dns_hostent_data_init()) == NULL) { RES_SET_H_ERRNO(statp, NETDB_INTERNAL); return (NULL); } @@ -699,11 +760,11 @@ memcpy(hed->host_addr, uaddr, len); hed->h_addr_ptrs[0] = (char *)hed->host_addr; hed->h_addr_ptrs[1] = NULL; - if (af == AF_INET && (statp->options & RES_USE_INET6)) { - _map_v4v6_address((char*)hed->host_addr, (char*)hed->host_addr); - he.h_addrtype = AF_INET6; - he.h_length = NS_IN6ADDRSZ; - } +// if (af == AF_INET && (statp->options & RES_USE_INET6)) { +// _map_v4v6_address((char*)hed->host_addr, (char*)hed->host_addr); +// he.h_addrtype = AF_INET6; +// he.h_length = NS_IN6ADDRSZ; +// } RES_SET_H_ERRNO(statp, NETDB_SUCCESS); if (__copy_hostent(&he, hptr, buffer, buflen) != 0) { *h_errnop = statp->res_h_errno; ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_dns/nss_dns.c#3 (text+ko) ==== @@ -32,14 +32,43 @@ #include <netdb.h> #include <stdlib.h> #include "dns_hosts_namadr.h" -#include "dns_hosts_name6.h" #include "dns_hosts_addrinfo.h" +#include "dns_passwd.h" +#include "dns_group.h" + +/* TODO: for testing purposes only */ +/*#ifdef NSDB_HOSTS +#undef NSDB_HOSTS +#endif +#define NSDB_HOSTS "hosts_"*/ static ns_mtab methods[] = { + {NSDB_GROUP, "getgrnam_r", __dns_group, (void *)nss_lt_name}, + {NSDB_GROUP, "getgrgid_r", __dns_group, (void *)nss_lt_id}, + {NSDB_GROUP, "getgrent_r", __dns_group, (void *)nss_lt_all}, + {NSDB_GROUP, "endgrent", __dns_setgrent, NULL}, + {NSDB_GROUP, "setgrent", __dns_setgrent, NULL}, + + {NSDB_PASSWD, "getpwnam_r", __dns_passwd, (void *)nss_lt_name}, + {NSDB_PASSWD, "getpwuid_r", __dns_passwd, (void *)nss_lt_id}, + {NSDB_PASSWD, "getpwent_r", __dns_passwd, (void *)nss_lt_all}, + {NSDB_PASSWD, "endpwent", __dns_setpwent, NULL}, + {NSDB_PASSWD, "setpwent", __dns_setpwent, NULL}, + + {NSDB_GROUP_COMPAT, "getgrnam_r", __dns_group, (void *)nss_lt_name}, + {NSDB_GROUP_COMPAT, "getgrgid_r", __dns_group, (void *)nss_lt_id}, + {NSDB_GROUP_COMPAT, "getgrent_r", __dns_group, (void *)nss_lt_all}, + {NSDB_GROUP_COMPAT, "endgrent", __dns_setgrent, NULL}, + {NSDB_GROUP_COMPAT, "setgrent", __dns_setgrent, NULL}, + + {NSDB_PASSWD_COMPAT, "getpwnam_r", __dns_passwd, (void *)nss_lt_name}, + {NSDB_PASSWD_COMPAT, "getpwuid_r", __dns_passwd, (void *)nss_lt_id}, + {NSDB_PASSWD_COMPAT, "getpwent_r", __dns_passwd, (void *)nss_lt_all}, + {NSDB_PASSWD_COMPAT, "endpwent", __dns_setpwent, NULL}, + {NSDB_PASSWD_COMPAT, "setpwent", __dns_setpwent, NULL}, + {NSDB_HOSTS, "gethostbyname2_r", __dns_gethostbyname2_r, NULL}, {NSDB_HOSTS, "gethostbyaddr_r", __dns_gethostbyaddr_r, NULL}, - {NSDB_HOSTS, "ghbyname", __dns_ghbyname, NULL}, - {NSDB_HOSTS, "ghbyaddr", __dns_ghbyaddr, NULL}, {NSDB_HOSTS, "getaddrinfo", __dns_getaddrinfo, NULL} }; ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/Makefile#2 (text+ko) ==== @@ -3,14 +3,14 @@ LIB= nss_files SHLIB_MAJOR= 1 SHLIBDIR?= /lib -#PROG= nss_files + CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../libc/gen -I${.CURDIR}/../libc/include\ -I${.CURDIR}/../libc/net -I${.CURDIR}/../libnssutil SRCS= nss_files.c files_passwd.c files_group.c files_hosts_namadr.c\ - files_hosts_name6.c files_hosts_addrinfo.c files_serv.c files_proto.c\ + files_hosts_addrinfo.c files_serv.c files_proto.c\ files_net.c files_rpc.c DPADD+= nssutil -LDADD+= -lnssutil +LDADD+= -lnssutil LDFLAGS+= -L${.CURDIR}/../libnssutil INCS= ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/files_group.c#2 (text+ko) ==== @@ -48,6 +48,7 @@ #include <unistd.h> #include "nss_files.h" #include "nss_tls.h" +#include "gr_scan.h" struct files_state { FILE *fp; @@ -69,107 +70,6 @@ free(p); } -static int -is_comment_line(const char *s, size_t n) -{ - const char *eom; - - eom = &s[n]; - - for (; s < eom; s++) - if (*s == '#' || !isspace((unsigned char)*s)) - break; - return (*s == '#' || s == eom); -} - -/* - * common group line matching and parsing - */ -int -__gr_match_entry(const char *line, size_t linesize, enum nss_lookup_type how, - const char *name, gid_t gid) -{ - size_t namesize; - const char *p, *eol; - char *q; - unsigned long n; - int i, needed; - - if (linesize == 0 || is_comment_line(line, linesize)) - return (NS_NOTFOUND); - switch (how) { - case nss_lt_name: needed = 1; break; - case nss_lt_id: needed = 2; break; - default: needed = 2; break; - } - eol = &line[linesize]; - for (p = line, i = 0; i < needed && p < eol; p++) - if (*p == ':') - i++; - if (i < needed) - return (NS_NOTFOUND); - switch (how) { - case nss_lt_name: - namesize = strlen(name); - if (namesize + 1 == (size_t)(p - line) && - memcmp(line, name, namesize) == 0) - return (NS_SUCCESS); - break; - case nss_lt_id: - n = strtoul(p, &q, 10); - if (q < eol && *q == ':' && gid == (gid_t)n) - return (NS_SUCCESS); - break; - case nss_lt_all: - return (NS_SUCCESS); - default: - break; - } - return (NS_NOTFOUND); -} - - -int -__gr_parse_entry(char *line, size_t linesize, struct group *grp, char *membuf, - size_t membufsize, int *errnop) -{ - char *s_gid, *s_mem, *p, **members; - unsigned long n; - int maxmembers; - - memset(grp, 0, sizeof(*grp)); - members = (char **)ALIGN(membuf); - membufsize -= (char *)members - membuf; - maxmembers = membufsize / sizeof(*members); - if (maxmembers <= 0 || - (grp->gr_name = strsep(&line, ":")) == NULL || - grp->gr_name[0] == '\0' || - (grp->gr_passwd = strsep(&line, ":")) == NULL || - (s_gid = strsep(&line, ":")) == NULL || - s_gid[0] == '\0') - return (NS_NOTFOUND); - s_mem = line; - n = strtoul(s_gid, &s_gid, 10); - if (s_gid[0] != '\0') - return (NS_NOTFOUND); - grp->gr_gid = (gid_t)n; - grp->gr_mem = members; - while (maxmembers > 1 && s_mem != NULL) { - p = strsep(&s_mem, ","); - if (p != NULL && *p != '\0') { - *members++ = p; - maxmembers--; - } - } - *members = NULL; - if (s_mem == NULL) - return (NS_SUCCESS); - else { - *errnop = ERANGE; - return (NS_RETURN); - } -} - int __files_setgrent(void *retval, void *mdata, va_list ap) { ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/files_hosts_namadr.c#3 (text+ko) ==== @@ -58,6 +58,7 @@ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> +#include <errno.h> #include <netdb.h> #include <stdio.h> #include <ctype.h> @@ -69,7 +70,6 @@ #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) @@ -83,7 +83,7 @@ static void files_hostent_data_free(void *ptr) { - struct hostent_data *hed = ptr; + struct files_hostent_data *hed = ptr; if (hed == NULL) return; @@ -95,6 +95,68 @@ free(hed); } +static int +__copy_hostent(struct hostent *he, struct hostent *hptr, char *buf, + size_t buflen) +{ + char *cp; + char **ptr; + int i, n; + int nptr, len; + + /* Find out the amount of space required to store the answer. */ + nptr = 2; /* NULL ptrs */ + len = (char *)ALIGN(buf) - buf; + for (i = 0; he->h_addr_list[i]; i++, nptr++) { + len += he->h_length; + } + for (i = 0; he->h_aliases[i]; i++, nptr++) { + len += strlen(he->h_aliases[i]) + 1; + } + len += strlen(he->h_name) + 1; + len += nptr * sizeof(char*); + + if (len > buflen) { + errno = ERANGE; + return (-1); + } + + /* copy address size and type */ + hptr->h_addrtype = he->h_addrtype; + n = hptr->h_length = he->h_length; + + ptr = (char **)ALIGN(buf); + cp = (char *)ALIGN(buf) + nptr * sizeof(char *); + + /* copy address list */ + hptr->h_addr_list = ptr; + for (i = 0; he->h_addr_list[i]; i++ , ptr++) { + memcpy(cp, he->h_addr_list[i], n); + hptr->h_addr_list[i] = cp; + cp += n; + } + hptr->h_addr_list[i] = NULL; + ptr++; + + /* copy official name */ + n = strlen(he->h_name) + 1; + strcpy(cp, he->h_name); + hptr->h_name = cp; + cp += n; + + /* copy aliases */ + hptr->h_aliases = ptr; + for (i = 0 ; he->h_aliases[i]; i++) { + n = strlen(he->h_aliases[i]) + 1; + strcpy(cp, he->h_aliases[i]); + hptr->h_aliases[i] = cp; + cp += n; + } + hptr->h_aliases[i] = NULL; + + return (0); +} + static void sethosthtent(int f, struct files_hostent_data *hed) { @@ -115,7 +177,7 @@ } static int -gethostent_p(struct hostent *he, struct files_hostent_data *hed, int mapped, +gethostent_p(struct hostent *he, struct files_hostent_data *hed, res_state statp) { char *p, *bp, *ep; @@ -144,15 +206,15 @@ af = AF_INET6; len = IN6ADDRSZ; } else if (inet_pton(AF_INET, p, hed->host_addr) > 0) { - if (mapped) { +/* if (mapped) { _map_v4v6_address((char *)hed->host_addr, (char *)hed->host_addr); af = AF_INET6; len = IN6ADDRSZ; - } else { + } else {*/ af = AF_INET; len = INADDRSZ; - } +/* }*/ } else { goto again; } @@ -231,15 +293,15 @@ } sethosthtent(0, hed); - while ((error = gethostent_p(&he, hed, 0, statp)) == 0) { + while ((error = gethostent_p(&he, hed, statp)) == 0) { if (he.h_addrtype != af) continue; - if (he.h_addrtype == AF_INET && +/* if (he.h_addrtype == AF_INET && statp->options & RES_USE_INET6) { _map_v4v6_address(he.h_addr, he.h_addr); he.h_length = IN6ADDRSZ; he.h_addrtype = AF_INET6; - } + }*/ if (strcasecmp(he.h_name, name) == 0) break; for (cp = he.h_aliases; *cp != 0; cp++) @@ -294,14 +356,14 @@ } sethosthtent(0, hed); - while ((error = gethostent_p(&he, hed, 0, statp)) == 0) + while ((error = gethostent_p(&he, hed, statp)) == 0) if (he.h_addrtype == af && !bcmp(he.h_addr, addr, len)) { - if (he.h_addrtype == AF_INET && +/* if (he.h_addrtype == AF_INET && statp->options & RES_USE_INET6) { _map_v4v6_address(he.h_addr, he.h_addr); he.h_length = IN6ADDRSZ; he.h_addrtype = AF_INET6; - } + }*/ break; } endhosthtent(hed); @@ -345,7 +407,7 @@ *h_errnop = statp->res_h_errno; return (NS_NOTFOUND); } - if (gethostent_p(&he, hed, statp->options & RES_USE_INET6, statp) != 0) + if (gethostent_p(&he, hed, statp) != 0) return (NS_NOTFOUND); if (__copy_hostent(&he, hptr, buffer, buflen) != 0) return (NS_NOTFOUND); ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_files/nss_files.c#4 (text+ko) ==== @@ -36,7 +36,6 @@ #include "files_passwd.h" #include "files_group.h" #include "files_hosts_namadr.h" -#include "files_hosts_name6.h" #include "files_hosts_addrinfo.h" #include "files_net.h" #include "files_proto.h" @@ -45,6 +44,12 @@ #include "netdb_private.h" #include "nss_files.h" +/* TODO: for testing purposes only */ +/*#ifdef NSDB_HOSTS +#undef NSDB_HOSTS +#endif +#define NSDB_HOSTS "hosts_"*/ + static struct servent_mdata getservbyname_mdata = { nss_lt_name, 0 }; static struct servent_mdata getservbyport_mdata = { nss_lt_id, 0 }; static struct servent_mdata getservent_mdata = { nss_lt_all, 0 }; @@ -76,8 +81,6 @@ {NSDB_HOSTS, "gethostbyname2_r", __files_gethostbyname2_r, NULL}, {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}, ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/Makefile#2 (text+ko) ==== @@ -3,15 +3,14 @@ LIB= nss_nis SHLIB_MAJOR= 1 SHLIBDIR?= /lib -PROG= nss_nis CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../libc/gen -I${.CURDIR}/../libc/include\ -I${.CURDIR}/../libc/net -I${.CURDIR}/../libnssutil -SRCS= nss_nis.c nis_hosts_namadr.c nis_hosts_name6.c\ - nis_hosts_addrinfo.c +SRCS= nss_nis.c nis_hosts_namadr.c nis_hosts_addrinfo.c nis_passwd.c\ + nis_group.c DPADD+= nssutil -LDADD+= -lnssutil +LDADD+= -lnssutil LDFLAGS+= -L${.CURDIR}/../libnssutil -INCS= +INCS= MAN= ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nis_hosts_namadr.c#3 (text+ko) ==== @@ -50,7 +50,6 @@ #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) @@ -71,6 +70,68 @@ free(hed); } +static int +__copy_hostent(struct hostent *he, struct hostent *hptr, char *buf, + size_t buflen) +{ + char *cp; + char **ptr; + int i, n; + int nptr, len; + + /* Find out the amount of space required to store the answer. */ + nptr = 2; /* NULL ptrs */ + len = (char *)ALIGN(buf) - buf; + for (i = 0; he->h_addr_list[i]; i++, nptr++) { + len += he->h_length; + } + for (i = 0; he->h_aliases[i]; i++, nptr++) { + len += strlen(he->h_aliases[i]) + 1; + } + len += strlen(he->h_name) + 1; + len += nptr * sizeof(char*); + + if (len > buflen) { + errno = ERANGE; + return (-1); + } + + /* copy address size and type */ + hptr->h_addrtype = he->h_addrtype; + n = hptr->h_length = he->h_length; + + ptr = (char **)ALIGN(buf); + cp = (char *)ALIGN(buf) + nptr * sizeof(char *); + + /* copy address list */ + hptr->h_addr_list = ptr; + for (i = 0; he->h_addr_list[i]; i++ , ptr++) { + memcpy(cp, he->h_addr_list[i], n); + hptr->h_addr_list[i] = cp; + cp += n; + } + hptr->h_addr_list[i] = NULL; + ptr++; + + /* copy official name */ + n = strlen(he->h_name) + 1; + strcpy(cp, he->h_name); + hptr->h_name = cp; + cp += n; + + /* copy aliases */ + hptr->h_aliases = ptr; + for (i = 0 ; he->h_aliases[i]; i++) { + n = strlen(he->h_aliases[i]) + 1; + strcpy(cp, he->h_aliases[i]); + hptr->h_aliases[i] = cp; + cp += n; + } + hptr->h_aliases[i] = NULL; + + return (0); +} + //#ifdef YP static int _gethostbynis(const char *name, char *map, int af, struct hostent *he, @@ -127,12 +188,12 @@ addrok = inet_aton(result, (struct in_addr *)hed->host_addr); if (addrok != 1) break; - if (statp->options & RES_USE_INET6) { +/* if (statp->options & RES_USE_INET6) { _map_v4v6_address((char *)hed->host_addr, (char *)hed->host_addr); af = AF_INET6; size = NS_IN6ADDRSZ; - } + }*/ break; case AF_INET6: addrok = inet_pton(af, result, hed->host_addr); ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/nss_nis/nss_nis.c#2 (text+ko) ==== @@ -32,14 +32,37 @@ #include <netdb.h> #include <stdlib.h> #include "nis_hosts_namadr.h" -#include "nis_hosts_name6.h" #include "nis_hosts_addrinfo.h" +#include "nis_passwd.h" +#include "nis_group.h" static ns_mtab methods[] = { + {NSDB_GROUP, "getgrnam_r", __nis_group, (void *)nss_lt_name}, + {NSDB_GROUP, "getgrgid_r", __nis_group, (void *)nss_lt_id}, + {NSDB_GROUP, "getgrent_r", __nis_group, (void *)nss_lt_all}, + {NSDB_GROUP, "endgrent", __nis_setgrent, NULL}, + {NSDB_GROUP, "setgrent", __nis_setgrent, NULL}, + + {NSDB_PASSWD, "getpwnam_r", __nis_passwd, (void *)nss_lt_name}, + {NSDB_PASSWD, "getpwuid_r", __nis_passwd, (void *)nss_lt_id}, + {NSDB_PASSWD, "getpwent_r", __nis_passwd, (void *)nss_lt_all}, + {NSDB_PASSWD, "endpwent", __nis_setpwent, NULL}, + {NSDB_PASSWD, "setpwent", __nis_setpwent, NULL}, + + {NSDB_GROUP_COMPAT, "getgrnam_r", __nis_group, (void *)nss_lt_name}, + {NSDB_GROUP_COMPAT, "getgrgid_r", __nis_group, (void *)nss_lt_id}, + {NSDB_GROUP_COMPAT, "getgrent_r", __nis_group, (void *)nss_lt_all}, + {NSDB_GROUP_COMPAT, "endgrent", __nis_setgrent, NULL}, + {NSDB_GROUP_COMPAT, "setgrent", __nis_setgrent, NULL}, + + {NSDB_PASSWD_COMPAT, "getpwnam_r", __nis_passwd, (void *)nss_lt_name}, + {NSDB_PASSWD_COMPAT, "getpwuid_r", __nis_passwd, (void *)nss_lt_id}, + {NSDB_PASSWD_COMPAT, "getpwent_r", __nis_passwd, (void *)nss_lt_all}, + {NSDB_PASSWD_COMPAT, "endpwent", __nis_setpwent, NULL}, + {NSDB_PASSWD_COMPAT, "setpwent", __nis_setpwent, NULL}, + {NSDB_HOSTS, "gethostbyname2_r", __nis_gethostbyname2_r, NULL}, {NSDB_HOSTS, "gethostbyaddr_r", __nis_gethostbyaddr_r, NULL}, - {NSDB_HOSTS, "ghbyname", __nis_ghbyname, NULL}, - {NSDB_HOSTS, "ghbyaddr", __nis_ghbyaddr, NULL}, {NSDB_HOSTS, "getaddrinfo", __nis_getaddrinfo, NULL} }; ==== //depot/projects/soc2006/nss_ldap_cached/tests/ghby_emul/Makefile#2 (text+ko) ==== ==== //depot/projects/soc2006/nss_ldap_cached/tests/ghby_emul/ghby_emul_test.c#2 (text+ko) ==== @@ -52,8 +52,7 @@ if (hed == NULL) return; - hed->stayopen = 0; - _endhosthtent(hed); + free(hed); } @@ -68,7 +67,7 @@ size_t buflen) { char *oldbuf, *cp; - char **ptr; + char **ptr, **list; int i, n; int nptr, len; @@ -84,10 +83,7 @@ for (i = 0; he->h_addr_list[i]; i++, nptr++) { len += IN6ADDRSZ; } - for (i = 0; he->h_aliases[i]; i++, nptr++) { - printf("2alias: %s\n", he->h_aliases[i]); - len += strlen(he->h_aliases[i]) + 1; - } + len += strlen(he->h_name) + 1; len += nptr * sizeof(char*); @@ -97,10 +93,13 @@ } oldbuf = buf; - /* TODO: len + ALIGNBYTES? */ - buf = (char *)malloc(len); - assert(buf != NULL); - memset(buf, 0, len); + /* NOTE: we add ALIGNBYTES in case if newly allocated memory segment + * wouldn't be properly aligned, whereas buf is aligned correctly */ + buf = (char *)malloc(len + ALIGNBYTES); + if (buf == NULL) { + errno = ENOMEM; + return (-1); + } /* copy address size and type */ hptr->h_addrtype = he->h_addrtype; @@ -109,17 +108,7 @@ ptr = (char **)ALIGN(buf); cp = (char *)ALIGN(buf) + nptr * sizeof(char *); - /* copy address list */ -/* hptr->h_addr_list = ptr; - for (i = 0; he->h_addr_list[i]; i++ , ptr++) { - memcpy(cp, he->h_addr_list[i], n); - hptr->h_addr_list[i] = cp; - cp += n; - } - hptr->h_addr_list[i] = NULL;*/ - /* TODO: use 1 memcpy here */ - - char **list = hptr->h_addr_list; + list = hptr->h_addr_list; hptr->h_addr_list = ptr; for (i = 0; list[i]; i++ , ptr++) { _map_v4v6_address(list[i], cp); @@ -129,8 +118,6 @@ hptr->h_addr_list[i] = NULL; ptr++; -// _map_v4v6_hostent(hptr, &cp, buf + len); - /* copy official name */ n = strlen(he->h_name) + 1; strcpy(cp, he->h_name); @@ -144,25 +131,26 @@ n = strlen(list[i]) + 1; strcpy(cp, list[i]); hptr->h_aliases[i] = cp; - printf("4alias %s\n", list[i]); cp += n; } hptr->h_aliases[i] = NULL; - - memcpy((char *)ALIGN(oldbuf), (char *)ALIGN(buf), len - (size_t)((char *)ALIGN(buf) - buf)); + + /* copying temporary buffer to the provided buffer and fixing + * hostent's pointers */ + oldbuf = (char *)ALIGN(oldbuf); + memcpy(oldbuf, (char *)ALIGN(buf), + len - (size_t)((char *)ALIGN(buf) - buf)); free(buf); buf = (char *)ALIGN(buf); - oldbuf = (char *)ALIGN(oldbuf); he->h_name = oldbuf + (size_t)(he->h_name - buf); - printf("name %s\n", he->h_name); - he->h_aliases = (char **)(oldbuf + (size_t)((char *)he->h_aliases - buf)); - he->h_addr_list = (char **)(oldbuf + (size_t)((char *)he->h_addr_list - buf)); + he->h_aliases = (char **)(oldbuf + + (size_t)((char *)he->h_aliases - buf)); + he->h_addr_list = (char **)(oldbuf + + (size_t)((char *)he->h_addr_list - buf)); char **p; - for (p = he->h_aliases; *p; ++p) { + for (p = he->h_aliases; *p; ++p) *p = oldbuf + (size_t)(*p - buf); - printf("alias %s\n", *p); - } for (p = he->h_addr_list; *p; ++p) *p = oldbuf + (size_t)(*p - buf); @@ -323,8 +311,8 @@ printf("rval: %d\n", rval); if ((*result != NULL) && (statp->options & RES_USE_INET6)) { - printf("yo\n"); -// __map_v4v6_hostent(hp, buf, buflen); + printf("mapping %p %p %ld\n", (void *)hp, (void *)buf, buflen); + __map_v4v6_hostent(hp, buf, buflen); } return ((rval == NS_SUCCESS) ? 0 : -1); @@ -390,6 +378,12 @@ "gethostbyaddr_r", default_src, uaddr, len, af, hp, buf, buflen, &ret_errno, h_errnop); + printf("rval: %d %p %d\n", rval, (void *)*result, statp->options & RES_USE_INET6); + if ((*result != NULL) && (statp->options & RES_USE_INET6)) { + printf("mapping %p %p %ld\n", (void *)hp, (void *)buf, buflen); + __map_v4v6_hostent(hp, buf, buflen); + } + return ((rval == NS_SUCCESS) ? 0 : -1); } @@ -515,7 +509,7 @@ assert(he1->h_name != NULL); assert(he2->h_name != NULL); if (strcmp(he1->h_name, he2->h_name) != 0) { - printf("ne %d\n", __LINE__); + printf("ne %d %s %s\n", __LINE__, he1->h_name, he2->h_name); return (-1); } @@ -523,6 +517,7 @@ char **p1, **p2; for (p1 = he1->h_aliases, p2 = he2->h_aliases; *p1 && *p2; ++p1, ++p2) { + printf("%s %s\n", *p1, *p2); if (strcmp(*p1, *p2) != 0) { printf("ne %d\n", __LINE__); return (-1); @@ -592,7 +587,7 @@ >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606181355.k5IDtw6K017289>