Date: Fri, 19 Aug 2005 11:44:34 GMT From: soc-bushman <soc-bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 82267 for review Message-ID: <200508191144.j7JBiYPH027357@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=82267 Change 82267 by soc-bushman@soc-bushman_stinger on 2005/08/19 11:43:43 update +libc patch to work with cached Affected files ... .. //depot/projects/soc2005/nsswitch_cached/Makefile#4 edit .. //depot/projects/soc2005/nsswitch_cached/cached/Makefile#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/cached.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/cached.conf#3 edit .. //depot/projects/soc2005/nsswitch_cached/cached/config.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/config.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/debug.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/debug.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/log.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/log.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/parser.c#3 edit .. //depot/projects/soc2005/nsswitch_cached/cached/parser.h#3 edit .. //depot/projects/soc2005/nsswitch_cached/cached/protocol.c#4 edit .. //depot/projects/soc2005/nsswitch_cached/cached/protocol.h#4 edit .. //depot/projects/soc2005/nsswitch_cached/cached/query.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/query.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/singletons.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/cached/singletons.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/include/nsswitch.h#6 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getgrent.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getpwent.c#3 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/Makefile.inc#3 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#13 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#3 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/Makefile#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/cached_client.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/cached_client.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/getservent.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/getservent.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/group_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/group_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/host_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/host_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/libc_private.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/namespace.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/netgroup_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/netgroup_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/networks_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/networks_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscachedcli.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscachedcli.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch_test.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch_test.core#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nss_backends.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nss_tls.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsswitch.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/passwd_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/passwd_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/protocols_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/protocols_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/reentrant.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/rpc_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/rpc_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/services_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/services_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/shells_marshal.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/shells_marshal.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/un-namespace.h#2 edit Differences ... ==== //depot/projects/soc2005/nsswitch_cached/Makefile#4 (text+ko) ==== @@ -1,3 +1,3 @@ -SUBDIR+="cachelib" "cached" +SUBDIR+="cachelib" "cached" "release" .include <bsd.subdir.mk> ==== //depot/projects/soc2005/nsswitch_cached/cached/Makefile#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/cached.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/cached.conf#3 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/config.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/config.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/debug.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/debug.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/log.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/log.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/parser.c#3 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/parser.h#3 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/protocol.c#4 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/protocol.h#4 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/query.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/query.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/singletons.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/cached/singletons.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/src/include/nsswitch.h#6 (text+ko) ==== @@ -195,17 +195,10 @@ nss_lt_all = 3 }; -typedef int (*nss_cache_id_func_t)(char *, size_t *, char *, size_t *, va_list); -typedef int (*nss_cache_marshal_func_t)(char *, size_t, void *, va_list); -typedef int (*nss_cache_unmarshal_func_t)(char *, size_t, void *, va_list); - -typedef struct _nss_cache_info { - nss_cache_id_func_t id_func; - nss_cache_marshal_func_t marshal_func; - nss_cache_unmarshal_func_t unmarshal_func; -} nss_cache_info; - -extern int nss_cache_process(void *, void *, va_list); +#ifdef NS_CACHING +#include "nscachedcli.h" +#include "nscache.h" +#endif /* NS_CACHING */ #ifdef _NS_PRIVATE /* ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getgrent.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getpwent.c#3 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/Makefile.inc#3 (text+ko) ==== @@ -16,9 +16,9 @@ inet_netof.c inet_network.c inet_ntoa.c inet_ntop.c \ inet_pton.c ip6opt.c linkaddr.c map_v4v6.c name6.c \ ns_name.c ns_netint.c ns_parse.c ns_print.c ns_ttl.c \ - nsdispatch.c nslexer.c nsparser.c nss_cache.c nss_compat.c \ - nsap_addr.c rcmd.c rcmdsh.c recv.c res_comp.c res_data.c res_debug.c \ - res_init.c res_mkquery.c res_mkupdate.c res_query.c res_send.c \ + nscache.c nscachedcli.c nsdispatch.c nslexer.c nsparser.c \ + nss_compat.c nsap_addr.c rcmd.c rcmdsh.c recv.c res_comp.c res_data.c \ + res_debug.c res_init.c res_mkquery.c res_mkupdate.c res_query.c res_send.c \ res_update.c rthdr.c send.c sockatmark.c vars.c CFLAGS+=-DINET6 -I${.OBJDIR} ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#13 (text+ko) ==== @@ -141,6 +141,13 @@ static struct servent *getserv(int (*fn)(struct key, struct servent *, char *, size_t, struct servent **), struct key); +#ifdef NS_CACHING +/* caching routines */ +static int serv_id_func(char *, size_t, va_list, void *); +static int serv_marshal_func(char *, size_t *, void *, va_list, void *); +static int serv_unmarshal_func(char *, size_t, void *, va_list, void *); +#endif /* NS_CACHING */ + static int servent_unpack(char *p, struct servent * serv, char ** aliases, size_t aliases_size, @@ -668,6 +675,200 @@ return (NS_UNAVAIL); } +#ifdef NS_CACHING +static int +serv_id_func(char *buffer, size_t buffer_size, va_list ap, void *cache_mdata) +{ + char *name; + char *proto; + int port; + int res; + + switch ((enum nss_lookup_type)cache_mdata) { + case nss_lt_name: + name = va_arg(ap, char *); + proto = va_arg(ap, char *); + res = snprintf(buffer, buffer_size, "%s_%s", name, proto); + res = (res >= buffer_size) ? NS_RETURN : NS_SUCCESS; + break; + case nss_lt_id: + port = va_arg(ap, int); + proto = va_arg(ap, char *); + if (proto == NULL) + exit(0); + res = snprintf(buffer, buffer_size, "%d_%s", port, proto); + res = (res >= buffer_size) ? NS_RETURN : NS_SUCCESS; + break; + default: + /* should be unreachable */ + res = NS_UNAVAIL; + break; + } + + TRACE_OUT(serv_id_func); + return (res); +} + +static int +serv_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, + void *cache_mdata) +{ + char *name; + char *proto; + int port; + struct servent *serv; + char *orig_buf; + size_t orig_buf_size; + + struct servent new_serv; + size_t desired_size; + char **alias; + char *p; + size_t size; + size_t aliases_size; + + TRACE_IN(serv_marshal_func); + switch ((enum nss_lookup_type)cache_mdata) { + case nss_lt_name: + name = va_arg(ap, char *); + proto = va_arg(ap, char *); + break; + case nss_lt_id: + port = va_arg(ap, int); + proto = va_arg(ap, char *); + break; + case nss_lt_all: + break; + default: + /* should be unreachable */ + break; + } + + serv = va_arg(ap, struct servent *); + orig_buf = va_arg(ap, char *); + orig_buf_size = va_arg(ap, size_t); + + desired_size = _ALIGNBYTES + sizeof(struct servent) + sizeof(char *) + + strlen(serv->s_name) + 1 + + strlen(serv->s_proto) + 1; + + aliases_size = 0; + if (serv->s_aliases != NULL) { + for (alias = serv->s_aliases; *alias; ++alias) { + desired_size += strlen(*alias) + 1; + ++aliases_size; + } + + desired_size += _ALIGNBYTES + sizeof(char *) * (aliases_size + 1); + } + + if (*buffer_size < desired_size) { + /* this assignment is here for future use */ + *buffer_size = desired_size; + TRACE_OUT(serv_marshal_func); + return (NS_RETURN); + } + + memcpy(&new_serv, serv, sizeof(struct servent)); + memset(buffer, 0, desired_size); + + *buffer_size = desired_size; + p = buffer + sizeof(struct servent) + sizeof(char *); + memcpy(buffer + sizeof(struct servent), &p, sizeof(char *)); + p = (char *)_ALIGN(p); + + size = strlen(new_serv.s_name); + memcpy(p, new_serv.s_name, size); + new_serv.s_name = p; + p += size + 1; + + size = strlen(new_serv.s_proto); + memcpy(p, new_serv.s_proto, size); + new_serv.s_proto = p; + p += size + 1; + + if (new_serv.s_aliases != NULL) { + for (alias = new_serv.s_aliases; *alias; ++alias) { + size = strlen(*alias); + memcpy(p, *alias, size); + *alias = p; + p += size + 1; + } + + memcpy((char *)_ALIGN(p), new_serv.s_aliases, sizeof(char *) * aliases_size); + new_serv.s_aliases = (char **)_ALIGN(p); + } + + memcpy(buffer, &new_serv, sizeof(struct servent)); + return (NS_SUCCESS); +} + +static int +serv_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, + void *cache_mdata) +{ + char *name; + char *proto; + int port; + struct servent *serv; + char *orig_buf; + char *p; + char **alias; + size_t orig_buf_size; + int *ret_errno; + + switch ((enum nss_lookup_type)cache_mdata) { + case nss_lt_name: + name = va_arg(ap, char *); + proto = va_arg(ap, char *); + break; + case nss_lt_id: + port = va_arg(ap, int); + proto = va_arg(ap, char *); + break; + case nss_lt_all: + break; + default: + return (NS_UNAVAIL); + break; + } + + serv = va_arg(ap, struct servent *); + orig_buf = va_arg(ap, char *); + orig_buf_size = va_arg(ap, size_t); + ret_errno = va_arg(ap, int *); + + TRACE_POINT(); + if (orig_buf_size < buffer_size - sizeof(struct servent) - sizeof(char *)) { + *ret_errno = ERANGE; + return (NS_RETURN); + } + + memcpy(serv, buffer, sizeof(struct servent)); + memcpy(&p, buffer + sizeof(struct servent), sizeof(char *)); + + orig_buf = (char *)_ALIGN(orig_buf); + memcpy(orig_buf, buffer + sizeof(struct servent) + sizeof(char *) + (_ALIGN(p) - (size_t)p), + buffer_size - sizeof(struct servent) - sizeof(char *)); + p = (char *)_ALIGN(p); + + NS_APPLY_OFFSET(serv->s_name, orig_buf, p, char *); + NS_APPLY_OFFSET(serv->s_proto, orig_buf, p, char *); + if (serv->s_aliases != NULL) { + NS_APPLY_OFFSET(serv->s_aliases, orig_buf, p, char **); + + for (alias = serv->s_aliases; *alias; ++alias) + NS_APPLY_OFFSET(*alias, orig_buf, p, char *); + } + + if (retval != NULL) + *((struct servent **)retval) = serv; + return (NS_SUCCESS); +} + +NSS_MP_CACHE_HANDLING(services_mp); +#endif /* NS_CACHING */ + /* get**_r functions implementation */ int getservbyname_r(const char *name, const char *proto, @@ -675,13 +876,21 @@ { static const struct servent_mdata mdata = { nss_lt_name, 0 }; static const struct servent_mdata compat_mdata = { nss_lt_name, 1 }; - +#ifdef NS_CACHING + static const nss_cache_info cache_info = NS_COMMON_CACHE_INFO_INITIALIZER( + services, (void *)nss_lt_name, + serv_id_func, serv_marshal_func, serv_unmarshal_func); +#endif /* NS_CACHING */ + static const ns_dtab dtab[] = { { NSSRC_FILES, files_servent, (void *)&mdata }, #ifdef YP { NSSRC_NIS, nis_servent, (void *)nss_lt_name }, #endif { NSSRC_COMPAT, files_servent, (void *)&compat_mdata }, +#ifdef NS_CACHING + NS_CACHE_CB(&cache_info), +#endif /* NS_CACHING */ { NULL, NULL, NULL } }; @@ -704,6 +913,11 @@ { static const struct servent_mdata mdata = { nss_lt_id, 0 }; static const struct servent_mdata compat_mdata = { nss_lt_id, 1 }; +#ifdef NS_CACHING + static const nss_cache_info cache_info = NS_COMMON_CACHE_INFO_INITIALIZER( + services, (void *)nss_lt_id, + serv_id_func, serv_marshal_func, serv_unmarshal_func); +#endif /* NS_CACHING */ static const ns_dtab dtab[] = { { NSSRC_FILES, files_servent, (void *)&mdata }, @@ -711,6 +925,9 @@ { NSSRC_NIS, nis_servent, (void *)nss_lt_id }, #endif { NSSRC_COMPAT, files_servent, (void *)&compat_mdata }, +#ifdef NS_CACHING + NS_CACHE_CB(&cache_info), +#endif /* NS_CACHING */ { NULL, NULL, NULL } }; int rv, ret_errno; @@ -732,6 +949,11 @@ { static const struct servent_mdata mdata = { nss_lt_all, 0 }; static const struct servent_mdata compat_mdata = { nss_lt_all, 1 }; +#ifdef NS_CACHING + static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( + services_mp, (void *)nss_lt_all, + serv_marshal_func, serv_unmarshal_func); +#endif /* NS_CACHING */ static const ns_dtab dtab[] = { { NSSRC_FILES, files_servent, (void *)&mdata }, @@ -739,6 +961,9 @@ { NSSRC_NIS, nis_servent, (void *)nss_lt_all }, #endif { NSSRC_COMPAT, files_servent, (void *)&compat_mdata }, +#ifdef NS_CACHING + NS_CACHE_CB(&cache_info), +#endif /* NS_CACHING */ { NULL, NULL, NULL } }; int rv, ret_errno; @@ -757,12 +982,21 @@ void setservent(int stayopen) { +#ifdef NS_CACHING + static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( + services_mp, (void *)nss_lt_all, + NULL, NULL); +#endif /* NS_CACHING */ + static const ns_dtab dtab[] = { { NSSRC_FILES, files_setservent, (void *)SETSERVENT }, #ifdef YP { NSSRC_NIS, nis_setservent, (void *)SETSERVENT }, #endif { NSSRC_COMPAT, compat_setservent, (void *)SETSERVENT }, +#ifdef NS_CACHING + NS_CACHE_CB(&cache_info), +#endif /* NS_CACHING */ { NULL, NULL, NULL } }; @@ -772,12 +1006,21 @@ void endservent() { +#ifdef NS_CACHING + static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( + services_mp, (void *)nss_lt_all, + NULL, NULL); +#endif /* NS_CACHING */ + static const ns_dtab dtab[] = { { NSSRC_FILES, files_setservent, (void *)ENDSERVENT }, #ifdef YP { NSSRC_NIS, nis_setservent, (void *)ENDSERVENT }, #endif { NSSRC_COMPAT, compat_setservent, (void *)ENDSERVENT }, +#ifdef NS_CACHING + NS_CACHE_CB(&cache_info), +#endif /* NS_CACHING */ { NULL, NULL, NULL } }; ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#3 (text+ko) ==== @@ -231,8 +231,6 @@ *count = 0; } - - /* * Comparison functions for vector_search. */ @@ -257,60 +255,6 @@ } /* - * NSS caching function - */ -#include "nss_cache.h" -int -nss_cache_process(void *retval, void *mdata, va_list ap) -{ - char entry_name[256]; - size_t entry_name_size; - char key[256]; - size_t key_size; - char buffer[1024]; - size_t buf_size; - int res; - - nss_cache_info *cache_info; - - cache_info = (nss_cache_info *)mdata; - memset(entry_name, 0, sizeof(entry_name)); - entry_name_size = sizeof(entry_name); - memset(key, 0, sizeof(key)); - key_size = sizeof(key); - memset(buffer, 0, sizeof(buffer)); - buf_size = sizeof(buffer); - - res = cache_info->id_func(entry_name, entry_name_size, key, key_size, ap); - if (res != 0) - return (NS_UNAVAIL); - - if (*key != '\0') { - /* we've got common cache entry */ - struct cached_connection_params params; - memset(¶ms, 0, sizeof(struct cached_connection_params)); - params.socket_path = "/tmp/cached"; - - cached_connection connection = open_cached_connection(¶ms); - if (connection == NULL) - return (NS_UNAVAIL); - - res = cached_read(connection, entry_name, key, buffer, &buf_size); - close_cached_connection(connection); - - if (res == 0) - res = cache_info->unmarshal_func(buffer, buf_size, retval, ap); - - return (res == 0 ? NS_SUCCESS : NS_NOTFOUND); - } else { - /* we've got multipart cache entry */ - return (NS_UNAVAIL); - } - - return (NS_SUCCESS); -} - -/* * NSS nsmap management. */ void @@ -634,7 +578,12 @@ nss_method method; void *mdata; int isthreaded, serrno, i, result, srclistsize; - nss_cache_info cinfo; + +#ifdef NS_CACHING + nss_cache_data cache_data; + nss_cache_data *cache_data_p; + int cache_flag; +#endif /* NS_CACHING */ isthreaded = __isthreaded; serrno = errno; @@ -661,24 +610,70 @@ while (srclist[srclistsize].name != NULL) srclistsize++; } - - cinfo = NULL; + +#ifdef NS_CACHING + cache_data_p = NULL; + cache_flag = 0; +#endif /* NS_CACHING */ for (i = 0; i < srclistsize; i++) { - result = NS_NOTFOUND; + TRACE_STR((char *)srclist[i].name); + + result = NS_NOTFOUND; method = nss_method_lookup(srclist[i].name, database, method_name, disp_tab, &mdata); - if (strcmp(srclist[i].name, NSSRC_CACHE) == 0) - cinfo = (nss_cache_info)mdata; + if (method != NULL) { +#ifdef NS_CACHING + if (strcmp(srclist[i].name, NSSRC_CACHE) == 0) { + cache_flag = 1; + + memset(&cache_data, 0, sizeof(nss_cache_data)); + cache_data.info = (nss_cache_info const *)mdata; + cache_data_p = &cache_data; + + va_start(ap, defaults); + if (cache_data.info->id_func != NULL) + result = nss_common_cache_read(retval, cache_data_p, ap); + else if (cache_data.info->marshal_func != NULL) + result = nss_mp_cache_read(retval, cache_data_p, ap); + else + result = nss_mp_cache_end(retval, cache_data_p, ap); + va_end(ap); + } else { + cache_flag = 0; + va_start(ap, defaults); + result = method(retval, mdata, ap); + va_end(ap); + } +#else /* NS_CACHING */ va_start(ap, defaults); result = method(retval, mdata, ap); - va_end(ap); - if (result & (srclist[i].flags)) { - + va_end(ap); +#endif /* NS_CACHING */ + + if (result & (srclist[i].flags)) break; - } + } + } + +#ifdef NS_CACHING + if ((cache_data_p != NULL) && + (result & (NS_TERMINATE | NS_NOTFOUND)) && + (cache_flag == 0)) { + va_start(ap, defaults); + if (result == NS_SUCCESS) { + if (cache_data.info->id_func != NULL) + nss_common_cache_write(retval, cache_data_p, ap); + else if (cache_data.info->marshal_func != NULL) + result = nss_mp_cache_write(retval, cache_data_p, ap); + } else if ((result == NS_RETURN) || (result == NS_NOTFOUND)) { + if (cache_data.info->marshal_func != NULL) + result = nss_mp_cache_write_submit(retval, cache_data_p, ap); } + va_end(ap); } +#endif /* NS_CACHING */ + if (isthreaded) (void)_pthread_rwlock_unlock(&nss_lock); fin: ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/Makefile#2 (text+ko) ==== @@ -4,7 +4,7 @@ PROGNAME=nsdispatch_test MAN= -SRCS=nsdispatch_test.c nsdispatch.c getservent.c nscache.c nscachedcli.c passwd_marshal.c group_marshal.c host_marshal.c +SRCS=nsdispatch_test.c nsdispatch.c getservent.c nscache.c nscachedcli.c passwd_marshal.c group_marshal.c host_marshal.c protocols_marshal.c rpc_marshal.c getrpcent.c getprotoent.c WARNS?=2 LDADD+=${.CURDIR}/../common/libtest.a CFLAGS+= -DNS_CACHING ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/cached_client.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/cached_client.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/getservent.c#2 (text+ko) ==== @@ -770,9 +770,9 @@ TRACE_INT(desired_size); memcpy(&new_serv, serv, sizeof(struct servent)); + memset(buffer, 0, desired_size); - *buffer_size = desired_size; - memset(buffer, 0, desired_size); + *buffer_size = desired_size; p = buffer + sizeof(struct servent) + sizeof(char *); memcpy(buffer + sizeof(struct servent), &p, sizeof(char *)); p = (char *)_ALIGN(p); @@ -842,7 +842,7 @@ ret_errno = va_arg(ap, int *); TRACE_POINT(); - if (orig_buf_size < buffer_size - _ALIGNBYTES - sizeof(struct servent) - sizeof(char *)) { + if (orig_buf_size < buffer_size - sizeof(struct servent) - sizeof(char *)) { TRACE_INT(orig_buf_size); TRACE_INT(buffer_size); TRACE_OUT(serv_unmarshal_func); @@ -869,7 +869,8 @@ NS_APPLY_OFFSET(*alias, orig_buf, p, char *); } - *((struct servent **)retval) = serv; + if (retval != NULL) + *((struct servent **)retval) = serv; TRACE_POINT(); TRACE_OUT(serv_unmarshal_func); return (NS_SUCCESS); ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/getservent.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/group_marshal.c#2 (text+ko) ==== @@ -94,6 +94,7 @@ } memcpy(&new_grp, grp, sizeof(struct group)); + memset(buffer, 0, desired_size); *buffer_size = desired_size; p = buffer + sizeof(struct group) + sizeof(char *); @@ -160,7 +161,7 @@ orig_buf_size = va_arg(ap, size_t); ret_errno = va_arg(ap, int *); - if (orig_buf_size < buffer_size - _ALIGNBYTES - sizeof(struct group) - sizeof(char *)) { + if (orig_buf_size < buffer_size - sizeof(struct group) - sizeof(char *)) { *ret_errno = ERANGE; return (NS_RETURN); } @@ -182,7 +183,8 @@ NS_APPLY_OFFSET(*mem, orig_buf, p, char *); } - *((struct group **)retval) = grp; + if (retval != NULL) + *((struct group **)retval) = grp; TRACE_OUT(grp_unmarshal_func); return (NS_SUCCESS); ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/group_marshal.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/host_marshal.c#2 (text+ko) ==== @@ -9,6 +9,7 @@ #include "../common/test.h" #include "../common/debug.h" #include "nsswitch.h" +#include "netdb_private.h" int host_id_func(char *buffer, size_t buffer_size, va_list ap, void *cache_mdata) @@ -75,7 +76,7 @@ TRACE_OUT(host_marshal_func); return (NS_UNAVAIL); } - ht = *((struct hostent **)retval); + ht = va_arg(ap, struct hostent *); desired_size = _ALIGNBYTES + sizeof(struct hostent) + sizeof(char *) + strlen(ht->h_name) + 1; @@ -126,10 +127,6 @@ *iter = p; p += size + 1; } - - memcpy((char *)_ALIGN(p), new_ht.h_aliases, sizeof(char *) * aliases_size); - new_ht.h_aliases = (char **)_ALIGN(p); - p = (char *)_ALIGN(p) + sizeof(char *) * (aliases_size + 1); } if (new_ht.h_addr_list != NULL) { @@ -138,12 +135,20 @@ memcpy(p, *iter, size); *iter = p; p += size + 1; - } - + } + } + + if (new_ht.h_aliases != NULL) { + memcpy((char *)_ALIGN(p), new_ht.h_aliases, sizeof(char *) * aliases_size); + new_ht.h_aliases = (char **)_ALIGN(p); + p = (char *)_ALIGN(p) + sizeof(char *) * (aliases_size + 1); + } + + if (new_ht.h_addr_list != NULL) { memcpy((char *)_ALIGN(p), new_ht.h_addr_list, sizeof(char *) * addr_size); new_ht.h_addr_list = (char **)_ALIGN(p); } - + TRACE_OUT(host_marshal_func); return (NS_SUCCESS); } @@ -152,7 +157,87 @@ host_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, void *cache_mdata) { + char *str; + int len, type; + struct hostent *ht; + struct hostent_data *ht_data; + + char *p; + char **iter; + size_t size, aliases_size, addr_size; + TRACE_IN(host_unmarshal_func); + switch ((enum nss_lookup_type)cache_mdata) { + case nss_lt_name: + str = va_arg(ap, char *); + type = va_arg(ap, int); + break; + case nss_lt_id: + str = va_arg(ap, char *); + len = va_arg(ap, int); + type = va_arg(ap, int); + break; + default: + /* should be unreachable */ + TRACE_OUT(host_marshal_func); + return (NS_UNAVAIL); + } + + ht = va_arg(ap, struct hostent *); + ht_data = va_arg(ap, struct hostent_data *); + + /* we don't make check for the buffer size - because hostent_data should + * be enough in all cases */ + memcpy(ht, buffer, sizeof(struct hostent)); + memcpy(&p, buffer + sizeof(struct hostent), sizeof(char *)); + + buffer = buffer + sizeof(struct hostent) + sizeof(char *) + _ALIGN(p) - (size_t)p; + + if ((ht->h_aliases == NULL) && (ht->h_addr_list == NULL)) + size = buffer_size - sizeof(struct hostent) - sizeof(char *) - (_ALIGN(p) - (size_t)p); + else if (ht->h_aliases != NULL) { + size = (char *)ht->h_aliases - (char *)_ALIGN(p); + } else if (ht->h_addr_list != NULL) + size = (char *)ht->h_addr_list - (char *)_ALIGN(p); + + if (ht->h_aliases != NULL) { + if (ht->h_addr_list != NULL) + aliases_size = (char *)ht->h_addr_list - (char *)ht->h_aliases; + else + aliases_size = buffer_size - sizeof(struct hostent) - sizeof(char *) - + (_ALIGN(p) - (size_t)p) - ((char *)_ALIGN(p) - (char *)ht->h_aliases); + } else + aliases_size = 0; + + if (ht->h_addr_list != NULL) { + addr_size = buffer_size - sizeof(struct hostent) - sizeof(char *) - + (_ALIGN(p) - (size_t)p) - ((char *)_ALIGN(p) - (char *)ht->h_addr_list); + } else + addr_size = 0; + + if ((size > sizeof(ht_data->hostbuf)) || + (aliases_size > sizeof(ht_data->host_aliases)) || + (addr_size > sizeof(ht_data->h_addr_ptrs))) { + errno = ERANGE; + return (NS_RETURN); + } + + p = (char *)_ALIGN(p); + NS_APPLY_OFFSET(ht->h_name, ht_data->hostbuf, p, char *); + if (ht->h_aliases != NULL) { + memcpy(ht_data->host_aliases, NS_GET_NEWP(ht->h_aliases, buffer, p), aliases_size); + ht->h_aliases = &ht_data->host_aliases[0]; + for (iter = ht->h_aliases; *iter; ++iter) + NS_APPLY_OFFSET(*iter, ht_data->hostbuf, p, char *); + } + + if (ht->h_addr_list != NULL) { + memcpy(ht_data->h_addr_ptrs, NS_GET_NEWP(ht->h_addr_list, buffer, p), addr_size); + ht->h_addr_list = &ht_data->h_addr_ptrs[0]; + for (iter = ht->h_addr_list; *iter; ++iter) + NS_APPLY_OFFSET(*iter, ht_data->hostbuf, p, char *); + } + TRACE_OUT(host_unmarshal_func); - return (0); + return (NS_SUCCESS); } ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/host_marshal.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/libc_private.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/namespace.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/netgroup_marshal.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/netgroup_marshal.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/networks_marshal.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/networks_marshal.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.h#2 (text+ko) ==== @@ -93,7 +93,7 @@ struct name##_mp_state *mp_state; \ int res; \ \ - res = name##_mp_getstate(&mp_state); \ + res = name##_mp_getstate(&mp_state); \ if (res != 0) \ return (INVALID_CACHED_MP_READ_SESSION); \ \ @@ -112,6 +112,11 @@ #define NS_APPLY_OFFSET(cp, cb, ib, p_type) \ if ((cp) != NULL) \ (cp) = (p_type)((char *)(cb) + (size_t)(cp) - (size_t)(ib)) +/* gets new pointer from the marshalled buffer by uisng initial address and initial + * buffer address */ +#define NS_GET_NEWP(cp, cb, ib) \ + ((char *)(cb) + (size_t)(cp) - (size_t)(ib)) + //((cp) == NULL ? NULL : ((char *)(cb) + (size_t)(cp) - (size_t)(ib))) typedef struct _nss_cache_data { char *key; ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscachedcli.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscachedcli.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch_test.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch_test.core#2 (text+ko) ==== @@ -1,488 +1,0 @@ -ELF -@ - - - - - - - - - - - - -(>āA(N(n8(āO( ( - (Þ(N(þČ<(.> -(ũ (V(ĻS(`J( - (@(Ĩ(>$(^nō(īÐ(ð$(Ļ<(`ę((I(Ð(.>NĀ·(nĻN(ĻU(Ā( - ( - -p - -ry was found -nt.c: 995 -993 -ispatch.c: 337 -: 302 - - - - - - ervices: compat >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508191144.j7JBiYPH027357>