Date: Mon, 24 Apr 2006 13:55:27 GMT From: soc-bushman <soc-bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 95995 for review Message-ID: <200604241355.k3ODtRDd067427@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=95995 Change 95995 by soc-bushman@soc-bushman_stinger on 2006/04/24 13:54:31 changes that was needed for patch submission Affected files ... .. //depot/projects/soc2005/nsswitch_cached/src/include/nsswitch.h#9 edit .. //depot/projects/soc2005/nsswitch_cached/src/include/rpc/rpcent.h#4 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/include/nscache.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/include/nscachedcli.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getproto.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoent.c#10 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoname.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservbyname.c#8 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservbyport.c#8 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#21 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/netdb_private.h#10 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscache.c#10 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscachedcli.c#11 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#16 edit .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/cached/cached.c#2 edit Differences ... ==== //depot/projects/soc2005/nsswitch_cached/src/include/nsswitch.h#9 (text+ko) ==== @@ -195,11 +195,6 @@ nss_lt_all = 3 }; -#ifdef NS_CACHING -#include "nscachedcli.h" -#include "nscache.h" -#endif /* NS_CACHING */ - #ifdef _NS_PRIVATE /* * private data structures for back-end nsswitch implementation ==== //depot/projects/soc2005/nsswitch_cached/src/include/rpc/rpcent.h#4 (text+ko) ==== @@ -53,11 +53,6 @@ }; __BEGIN_DECLS -extern struct rpcent *getrpcbyname_r(const char *, struct rpcent *, char *, - int); -extern struct rpcent *getrpcbynumber_r(int, struct rpcent *, char *, int); -extern struct rpcent *getrpcent_r(struct rpcent *, char *, int); - /* These interfaces are currently implemented through nsswitch and MT-safe */ extern struct rpcent *getrpcbyname(char *); extern struct rpcent *getrpcbynumber(int); ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/include/nscache.h#2 (text+ko) ==== @@ -28,6 +28,8 @@ #ifndef __NS_CACHE_H__ #define __NS_CACHE_H__ +#include "nscachedcli.h" + typedef int (*nss_cache_id_func_t)(char *, size_t *, va_list, void *); typedef int (*nss_cache_marshal_func_t)(char *, size_t *, void *, va_list, void *); @@ -80,10 +82,10 @@ \ mp_state = (struct name##_mp_state *)s; \ if (mp_state->mp_write_session != INVALID_CACHED_MP_WRITE_SESSION)\ - abandon_cached_mp_write_session(mp_state->mp_write_session);\ + __abandon_cached_mp_write_session(mp_state->mp_write_session);\ \ if (mp_state->mp_read_session != INVALID_CACHED_MP_READ_SESSION)\ - close_cached_mp_read_session(mp_state->mp_read_session); \ + __close_cached_mp_read_session(mp_state->mp_read_session); \ } \ NSS_TLS_HANDLING(name##_mp); \ \ @@ -154,7 +156,7 @@ * Analog of other XXX_CB macros. Has the pointer to _nss_cache_info * structure as the only argument. */ -#define NS_CACHE_CB(cinfo) {NSSRC_CACHE, nss_cache_handler, (void *)(cinfo) }, +#define NS_CACHE_CB(cinfo) {NSSRC_CACHE, __nss_cache_handler, (void *)(cinfo) }, /* args are: current pointer, current buffer, initial buffer, pointer type */ #define NS_APPLY_OFFSET(cp, cb, ib, p_type) \ @@ -176,17 +178,17 @@ __BEGIN_DECLS /* dummy function, which is needed to make nss_method_lookup happy */ -extern int nss_cache_handler(void *, void *, va_list); +extern int __nss_cache_handler(void *, void *, va_list); #ifdef _NS_PRIVATE -extern int nss_common_cache_read(void *, void *, va_list); -extern int nss_common_cache_write(void *, void *, va_list); -extern int nss_common_cache_write_negative(void *); +extern int __nss_common_cache_read(void *, void *, va_list); +extern int __nss_common_cache_write(void *, void *, va_list); +extern int __nss_common_cache_write_negative(void *); -extern int nss_mp_cache_read(void *, void *, va_list); -extern int nss_mp_cache_write(void *, void *, va_list); -extern int nss_mp_cache_write_submit(void *, void *, va_list); -extern int nss_mp_cache_end(void *, void *, va_list); +extern int __nss_mp_cache_read(void *, void *, va_list); +extern int __nss_mp_cache_write(void *, void *, va_list); +extern int __nss_mp_cache_write_submit(void *, void *, va_list); +extern int __nss_mp_cache_end(void *, void *, va_list); #endif /* _NS_PRIVATE */ __END_DECLS ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/include/nscachedcli.h#2 (text+ko) ==== @@ -77,27 +77,27 @@ __BEGIN_DECLS /* initialization/destruction routines */ -extern cached_connection open_cached_connection( +extern cached_connection __open_cached_connection( struct cached_connection_params const *); -extern void close_cached_connection(cached_connection); +extern void __close_cached_connection(cached_connection); /* simple read/write operations */ -extern int cached_write(cached_connection, const char *, const char *, +extern int __cached_write(cached_connection, const char *, const char *, size_t, const char *, size_t); -extern int cached_read(cached_connection, const char *, const char *, +extern int __cached_read(cached_connection, const char *, const char *, size_t, char *, size_t *); /* multipart read/write operations */ -extern cached_mp_write_session open_cached_mp_write_session( +extern cached_mp_write_session __open_cached_mp_write_session( struct cached_connection_params const *, const char *); -extern int cached_mp_write(cached_mp_write_session, const char *, size_t); -extern int abandon_cached_mp_write_session(cached_mp_write_session); -extern int close_cached_mp_write_session(cached_mp_write_session); +extern int __cached_mp_write(cached_mp_write_session, const char *, size_t); +extern int __abandon_cached_mp_write_session(cached_mp_write_session); +extern int __close_cached_mp_write_session(cached_mp_write_session); -extern cached_mp_read_session open_cached_mp_read_session( +extern cached_mp_read_session __open_cached_mp_read_session( struct cached_connection_params const *, const char *); -extern int cached_mp_read(cached_mp_read_session, char *, size_t *); -extern int close_cached_mp_read_session(cached_mp_read_session); +extern int __cached_mp_read(cached_mp_read_session, char *, size_t *); +extern int __close_cached_mp_read_session(cached_mp_read_session); __END_DECLS ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getproto.c#5 (text+ko) ==== @@ -38,4 +38,108 @@ __FBSDID("$FreeBSD: src/lib/libc/net/getproto.c,v 1.5 2006/04/15 16:20:27 ume Exp $"); #include <netdb.h> +#include <nsswitch.h> #include "netdb_private.h" +#ifdef NS_CACHING +#include "nscache.h" +#endif +#include "nss_tls.h" + +static const ns_src defaultsrc[] = { + { NSSRC_FILES, NS_SUCCESS }, + { NULL, 0 } +}; + +#ifdef NS_CACHING +extern int __proto_id_func(char *, size_t *, va_list, void *); +extern int __proto_marshal_func(char *, size_t *, void *, va_list, void *); +extern int __proto_unmarshal_func(char *, size_t, void *, va_list, void *); +#endif + +int +__files_getprotobynumber(void *retval, void *mdata, va_list ap) +{ + struct protoent pe; + struct protoent_data *ped; + int error; + + int number; + struct protoent *pptr; + char *buffer; + size_t buflen; + int *errnop; + + number = va_arg(ap, int); + pptr = va_arg(ap, struct protoent *); + buffer = va_arg(ap, char *); + buflen = va_arg(ap, size_t); + errnop = va_arg(ap, int *); + + if ((ped = __protoent_data_init()) == NULL) { + *errnop = -1; + return (NS_NOTFOUND); + } + + __setprotoent_p(ped->stayopen, ped); + while ((error = __getprotoent_p(&pe, ped)) == 0) + if (pe.p_proto == number) + break; + if (!ped->stayopen) + __endprotoent_p(ped); + if (error != 0) { + *errnop = -1; + return (NS_NOTFOUND); + } + if (__copy_protoent(&pe, pptr, buffer, buflen) != 0) { + *errnop = -1; + return (NS_NOTFOUND); + } + + *((struct protoent **)retval) = pptr; + return (NS_SUCCESS); +} + +int +getprotobynumber_r(int proto, struct protoent *pptr, char *buffer, + size_t buflen, struct protoent **result) +{ +#ifdef NS_CACHING + static const nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER( + protocols, (void *)nss_lt_id, + __proto_id_func, __proto_marshal_func, __proto_unmarshal_func); +#endif + + static const ns_dtab dtab[] = { + { NSSRC_FILES, __files_getprotobynumber, NULL }, +#ifdef NS_CACHING + NS_CACHE_CB(&cache_info) +#endif + { NULL, NULL, NULL } + }; + int rv, ret_errno; + + ret_errno = 0; + *result = NULL; + rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobynumber_r", + defaultsrc, proto, pptr, buffer, buflen, &ret_errno); + + if (rv == NS_SUCCESS) + return (0); + else + return (ret_errno); +} + +struct protoent * +getprotobynumber(int proto) +{ + struct protodata *pd; + struct protoent *rval; + + if ((pd = __protodata_init()) == NULL) + return (NULL); + if (getprotobynumber_r(proto, &pd->proto, pd->data, sizeof(pd->data), + &rval) != 0) + return (NULL); + return (rval); +} ==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoent.c#10 (text+ko) ==== @@ -35,311 +35,62 @@ static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/lib/libc/net/getprotoent.c,v 1.6 2005/08/20 07:59:13 stefanf Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/net/getprotoent.c,v 1.7 2006/04/15 16:20:27 ume Exp $"); +#include <sys/param.h> #include <sys/types.h> #include <sys/socket.h> +#include <errno.h> #include <limits.h> -#include <errno.h> #include <netdb.h> #include <nsswitch.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "namespace.h" -#include "nss_tls.h" #include "reentrant.h" #include "un-namespace.h" #include "netdb_private.h" +#ifdef NS_CACHING #include "nscache.h" +#endif +#include "nss_tls.h" -/* nsswitch declarations */ -enum constants -{ - SETPROTOENT = 1, - ENDPROTOENT = 2, - PROTOENT_STORAGE_INITIAL = 1 << 10, /* 1 KByte */ - PROTOENT_STORAGE_MAX = 1 << 20, /* 1 MByte */ -}; - static const ns_src defaultsrc[] = { { NSSRC_FILES, NS_SUCCESS }, { NULL, 0 } }; -/* files backend declarations */ -struct files_state -{ - FILE *fp; - int stayopen; -}; -static void files_endstate(void *); -NSS_TLS_HANDLING(files); +NETDB_THREAD_ALLOC(protoent_data) +NETDB_THREAD_ALLOC(protodata) -static int files_protoent(void *, void *, va_list); -static int files_setprotoent(void *, void *, va_list); - -/* get** wrappers for get**_r functions declarations */ -struct protoent_state { - struct protoent pe; - char *buffer; - size_t bufsize; -}; -static void protoent_endstate(void *); -NSS_TLS_HANDLING(protoent); - -union key { - const char *name; - int proto; -}; - -static int wrap_getprotobyname_r(union key, struct protoent *, char *, - size_t, struct protoent **); -static int wrap_getprotobynumber_r(union key, struct protoent *, char *, - size_t, struct protoent **); -static int wrap_getprotoent_r(union key, struct protoent *, char *, - size_t, struct protoent **); -static struct protoent *getpe(int (*fn)(union key, struct protoent *, char *, - size_t, struct protoent **), union key); - -#ifdef NS_CACHING -static int proto_id_func(char *, size_t *, va_list, void *); -static int proto_marshal_func(char *, size_t *, void *, va_list, void *); -static int proto_unmarshal_func(char *, size_t, void *, va_list, void *); -#endif /* NS_CACHING */ - -static int -protoent_unpack(char *p, struct protoent *pe, char **aliases, - size_t aliases_size, int *errnop) +static void +protoent_data_clear(struct protoent_data *ped) { - char *cp, **q, *endp; - long l; - - if (*p == '#') - return (-1); - cp = strpbrk(p, "#\n"); - if (cp != NULL) - *cp = '\0'; - pe->p_name = p; - cp = strpbrk(p, " \t"); - if (cp == NULL) - return (-1); - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - p = strpbrk(cp, " \t"); - if (p != NULL) - *p++ = '\0'; - l = strtol(cp, &endp, 10); - if (endp == cp || *endp != '\0' || l < 0 || l > USHRT_MAX) - return -1; - pe->p_proto = l; - q = pe->p_aliases = aliases; - if (p != NULL) { - cp = p; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - if (q < &(aliases[aliases_size - 1])) - *q++ = cp; - else { - *errnop = ERANGE; - return -1; - } - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - } + if (ped->fp) { + fclose(ped->fp); + ped->fp = NULL; } - *q = NULL; - return (0); -} - -/* files backend implementation */ -static void -files_endstate(void *p) -{ - FILE * f; - - if (p == NULL) - return; - - f = ((struct files_state *)p)->fp; - if (f != NULL) - fclose(f); - - free(p); } -static int -files_protoent(void *retval, void *mdata, va_list ap) +static void +protoent_data_free(void *ptr) { - char *name; - int number; - struct protoent *pe; - char *buffer; - size_t bufsize; - int *errnop; - - char *line; - size_t linesize; - char **aliases; - int aliases_size; - char **rp; - - struct files_state *st; - int rv; - int stayopen; - enum nss_lookup_type how; - - how = (enum nss_lookup_type)mdata; - switch (how) - { - case nss_lt_name: - name = va_arg(ap, char *); - break; - case nss_lt_id: - number = va_arg(ap, int); - break; - case nss_lt_all: - break; - default: - return (NS_NOTFOUND); - } - - pe = va_arg(ap, struct protoent *); - buffer = va_arg(ap, char *); - bufsize = va_arg(ap, size_t); - errnop = va_arg(ap, int *); - - *errnop = files_getstate(&st); - if (*errnop != 0) - return (NS_UNAVAIL); - - if (st->fp == NULL && (st->fp = fopen(_PATH_PROTOCOLS, "r")) == NULL) { - *errnop = errno; - return (NS_UNAVAIL); - } - - if (how == nss_lt_all) - stayopen = 1; - else { - rewind(st->fp); - stayopen = st->stayopen; - } - - do { - if ((line = fgetln(st->fp, &linesize)) == NULL) { - *errnop = errno; - rv = NS_RETURN; - break; - } - - if (bufsize <= linesize + _ALIGNBYTES + sizeof(char *)) { - *errnop = ERANGE; - rv = NS_RETURN; - break; - } + struct protoent_data *ped = ptr; - aliases = (char **)_ALIGN(&buffer[linesize+1]); - aliases_size = (buffer + bufsize - (char *)aliases) / - sizeof(char *); - if (aliases_size < 1) { - *errnop = ERANGE; - rv = NS_RETURN; - break; - } - - memcpy(buffer, line, linesize); - buffer[linesize] = '\0'; - - rv = protoent_unpack(buffer, pe, aliases, aliases_size, errnop); - if (rv != 0) { - if (*errnop == 0) { - rv = NS_NOTFOUND; - continue; - } - else { - rv = NS_RETURN; - break; - } - } - - switch (how) - { - case nss_lt_name: - if (strcmp(pe->p_name, name) == 0) - goto done; - for (rp = pe->p_aliases; *rp != NULL; rp++) { - if (strcmp(*rp, name) == 0) - goto done; - } - rv = NS_NOTFOUND; - continue; -done: - rv = NS_SUCCESS; - break; - case nss_lt_id: - rv = (pe->p_proto == number) ? NS_SUCCESS : NS_NOTFOUND; - break; - case nss_lt_all: - rv = NS_SUCCESS; - break; - } - - } while (!(rv & NS_TERMINATE)); - - if (!stayopen && st->fp!=NULL) { - fclose(st->fp); - st->fp = NULL; - } - - if ((rv == NS_SUCCESS) && (retval != NULL)) - *((struct protoent **)retval) = pe; - - return (rv); + protoent_data_clear(ped); + free(ped); } -static int -files_setprotoent(void *retval, void *mdata, va_list ap) +static void +protodata_free(void *ptr) { - struct files_state *st; - int rv; - int f; - - rv = files_getstate(&st); - if (rv != 0) - return (NS_UNAVAIL); - - switch ((enum constants)mdata) - { - case SETPROTOENT: - f = va_arg(ap,int); - if (st->fp == NULL) - st->fp = fopen(_PATH_PROTOCOLS, "r"); - else - rewind(st->fp); - st->stayopen |= f; - break; - case ENDPROTOENT: - if (st->fp != NULL) { - fclose(st->fp); - st->fp = NULL; - } - st->stayopen = 0; - break; - default: - break; - } - - return (NS_UNAVAIL); + free(ptr); } #ifdef NS_CACHING -static int -proto_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) +int +__proto_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) { char *name; int proto; @@ -391,8 +142,8 @@ } -static int -proto_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, +int +__proto_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, void *cache_mdata) { char *name; @@ -478,8 +229,8 @@ return (NS_SUCCESS); } -static int -proto_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, +int +__proto_unmarshal_func(char *buffer, size_t buffer_size, void *retval, va_list ap, void *cache_mdata) { char *name; @@ -544,94 +295,206 @@ NSS_MP_CACHE_HANDLING(protocols); #endif /* NS_CACHING */ +int +__copy_protoent(struct protoent *pe, struct protoent *pptr, char *buf, + size_t buflen) +{ + char *cp; + int i, n; + int numptr, len; + + /* Find out the amount of space required to store the answer. */ + numptr = 1; /* NULL ptr */ + len = (char *)ALIGN(buf) - buf; + for (i = 0; pe->p_aliases[i]; i++, numptr++) { + len += strlen(pe->p_aliases[i]) + 1; + } + len += strlen(pe->p_name) + 1; + len += numptr * sizeof(char*); -/* get**_r functions implementation */ + if (len > (int)buflen) { + errno = ERANGE; + return (-1); + } + + /* copy protocol value*/ + pptr->p_proto = pe->p_proto; + + cp = (char *)ALIGN(buf) + numptr * sizeof(char *); + + /* copy official name */ + n = strlen(pe->p_name) + 1; + strcpy(cp, pe->p_name); + pptr->p_name = cp; + cp += n; + + /* copy aliases */ + pptr->p_aliases = (char **)ALIGN(buf); + for (i = 0 ; pe->p_aliases[i]; i++) { + n = strlen(pe->p_aliases[i]) + 1; + strcpy(cp, pe->p_aliases[i]); + pptr->p_aliases[i] = cp; + cp += n; + } + pptr->p_aliases[i] = NULL; + + return (0); +} + +void +__setprotoent_p(int f, struct protoent_data *ped) +{ + if (ped->fp == NULL) + ped->fp = fopen(_PATH_PROTOCOLS, "r"); + else + rewind(ped->fp); + ped->stayopen |= f; +} + +void +__endprotoent_p(struct protoent_data *ped) +{ + if (ped->fp) { + fclose(ped->fp); + ped->fp = NULL; + } + ped->stayopen = 0; +} + +int +__getprotoent_p(struct protoent *pe, struct protoent_data *ped) +{ + char *p; + char *cp, **q, *endp; + long l; + + if (ped->fp == NULL && (ped->fp = fopen(_PATH_PROTOCOLS, "r")) == NULL) + return (-1); +again: + if ((p = fgets(ped->line, sizeof ped->line, ped->fp)) == NULL) + return (-1); + if (*p == '#') + goto again; + cp = strpbrk(p, "#\n"); + if (cp != NULL) + *cp = '\0'; + pe->p_name = p; + cp = strpbrk(p, " \t"); + if (cp == NULL) + goto again; + *cp++ = '\0'; + while (*cp == ' ' || *cp == '\t') + cp++; + p = strpbrk(cp, " \t"); + if (p != NULL) + *p++ = '\0'; + l = strtol(cp, &endp, 10); + if (endp == cp || *endp != '\0' || l < 0 || l > USHRT_MAX) + goto again; + pe->p_proto = l; + q = pe->p_aliases = ped->aliases; + if (p != NULL) { + cp = p; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; + continue; + } + if (q < &ped->aliases[_MAXALIASES - 1]) + *q++ = cp; + cp = strpbrk(cp, " \t"); + if (cp != NULL) + *cp++ = '\0'; + } + } + *q = NULL; + return (0); +} + int -getprotobyname_r(const char *name, struct protoent *pe, char *buffer, - size_t bufsize, struct protoent **result) +__files_getprotoent_r(void *retval, void *mdata, va_list ap) { -#ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - protocols, (void *)nss_lt_name, - proto_id_func, proto_marshal_func, proto_unmarshal_func); -#endif + struct protoent pe; + struct protoent_data *ped; + + struct protoent *pptr; + char *buffer; + size_t buflen; + int *errnop; + + pptr = va_arg(ap, struct protoent *); + buffer = va_arg(ap, char *); + buflen = va_arg(ap, size_t); + errnop = va_arg(ap, int *); - static const ns_dtab dtab[] = { - { NSSRC_FILES, files_protoent, (void *)nss_lt_name }, -#ifdef NS_CACHING - NS_CACHE_CB(&cache_info) -#endif - { NULL, NULL, NULL } - }; + if ((ped = __protoent_data_init()) == NULL) + return (-1); - int rv, ret_errno; + if (__getprotoent_p(&pe, ped) != 0) { + *errnop = errno; + return (NS_NOTFOUND); + } - ret_errno = 0; - *result = NULL; - rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobyname_r", - defaultsrc, name, pe, buffer, bufsize, &ret_errno); + if (__copy_protoent(&pe, pptr, buffer, buflen) != 0) { + *errnop = errno; + return (NS_NOTFOUND); + } - if (rv == NS_SUCCESS) - return (0); - else - return (ret_errno); + *((struct protoent **)retval) = pptr; + return (NS_SUCCESS); } -int -getprotobynumber_r(int number, struct protoent *pe, char *buffer, - size_t bufsize, struct protoent **result) +int +__files_setprotoent(void *retval, void *mdata, va_list ap) { -#ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - protocols, (void *)nss_lt_id, - proto_id_func, proto_marshal_func, proto_unmarshal_func); -#endif + struct protoent_data *ped; + int f; + + f = va_arg(ap, int); + if ((ped = __protoent_data_init()) == NULL) + return (NS_UNAVAIL); - static const ns_dtab dtab[] = { - { NSSRC_FILES, files_protoent, (void *)nss_lt_id }, -#ifdef NS_CACHING - NS_CACHE_CB(&cache_info) -#endif - { NULL, NULL, NULL } - }; - int rv, ret_errno; + __setprotoent_p(f, ped); + return (NS_UNAVAIL); +} + +int +__files_endprotoent(void *retval, void *mdata, va_list ap) +{ + struct protoent_data *ped; - ret_errno = 0; - *result = NULL; - rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobynumber_r", - defaultsrc, number, pe, buffer, bufsize, &ret_errno); + if ((ped = __protoent_data_init()) == NULL) + return (NS_UNAVAIL); - if (rv == NS_SUCCESS) - return (0); - else - return (ret_errno); + __endprotoent_p(ped); + return (NS_UNAVAIL); } int -getprotoent_r(struct protoent *pe, char *buffer, size_t bufsize, - struct protoent **result) +getprotoent_r(struct protoent *pptr, char *buffer, size_t buflen, + struct protoent **result) { #ifdef NS_CACHING static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( protocols, (void *)nss_lt_all, - proto_marshal_func, proto_unmarshal_func); + __proto_marshal_func, __proto_unmarshal_func); #endif static const ns_dtab dtab[] = { - { NSSRC_FILES, files_protoent, (void *)nss_lt_all }, + { NSSRC_FILES, __files_getprotoent_r, (void *)nss_lt_all }, #ifdef NS_CACHING NS_CACHE_CB(&cache_info) #endif { NULL, NULL, NULL } }; - int rv, ret_errno; + + int rv, ret_errno; + ret_errno = 0; *result = NULL; rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotoent_r", - defaultsrc, pe, buffer, bufsize, &ret_errno); + defaultsrc, pptr, buffer, buflen, &ret_errno); if (rv == NS_SUCCESS) return (0); @@ -649,7 +512,7 @@ #endif static const ns_dtab dtab[] = { - { NSSRC_FILES, files_setprotoent, (void *)SETPROTOENT }, + { NSSRC_FILES, __files_setprotoent, NULL }, #ifdef NS_CACHING NS_CACHE_CB(&cache_info) #endif @@ -660,8 +523,8 @@ stayopen); } -void -endprotoent() +void +endprotoent(void) { #ifdef NS_CACHING static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( @@ -670,7 +533,7 @@ #endif static const ns_dtab dtab[] = { - { NSSRC_FILES, files_setprotoent, (void *)ENDPROTOENT }, + { NSSRC_FILES, __files_endprotoent, NULL }, #ifdef NS_CACHING NS_CACHE_CB(&cache_info) #endif @@ -680,105 +543,15 @@ (void)nsdispatch(NULL, dtab, NSDB_PROTOCOLS, "endprotoent", defaultsrc); } -/* get** wrappers for get**_r functions implementation */ -static void -protoent_endstate(void *p) -{ - if (p == NULL) - return; - - free(((struct protoent_state *)p)->buffer); - free(p); -} - -static int -wrap_getprotobyname_r(union key key, struct protoent *pe, char *buffer, - size_t bufsize, struct protoent **res) -{ - return (getprotobyname_r(key.name, pe, buffer, bufsize, res)); -} - -static int -wrap_getprotobynumber_r(union key key, struct protoent *pe, char *buffer, - size_t bufsize, struct protoent **res) -{ - return (getprotobynumber_r(key.proto, pe, buffer, bufsize, res)); -} - -static int -wrap_getprotoent_r(union key key, struct protoent *pe, char *buffer, - size_t bufsize, struct protoent **res) -{ - return (getprotoent_r(pe, buffer, bufsize, res)); -} - -static struct protoent * -getpe(int (*fn)(union key, struct protoent *, char *, size_t, - struct protoent **), union key key) -{ - int rv; - struct protoent *res; - struct protoent_state * st; - - rv=protoent_getstate(&st); - if (rv != 0) { - errno = rv; - return NULL; - } - - if (st->buffer == NULL) { - st->buffer = malloc(PROTOENT_STORAGE_INITIAL); - if (st->buffer == NULL) - return (NULL); - st->bufsize = PROTOENT_STORAGE_INITIAL; - } - do { - rv = fn(key, &st->pe, st->buffer, st->bufsize, &res); - if (res == NULL && rv == ERANGE) { - free(st->buffer); - if ((st->bufsize << 1) > PROTOENT_STORAGE_MAX) { - st->buffer = NULL; - errno = ERANGE; - return (NULL); - } - st->bufsize <<= 1; - st->buffer = malloc(st->bufsize); - if (st->buffer == NULL) - return (NULL); - } - } while (res == NULL && rv == ERANGE); - if (rv != 0) - errno = rv; - - return (res); -} - struct protoent * -getprotobyname(const char *name) +getprotoent(void) { >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604241355.k3ODtRDd067427>