PERFORCE change 80435 for review
soc-bushman
soc-bushman at FreeBSD.org
Mon Jul 18 11:48:20 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=80435
Change 80435 by soc-bushman at soc-bushman_stinger on 2005/07/18 11:47:36
openssh patch finished - port submitted
Affected files ...
.. //depot/projects/soc2005/nsswitch_cached/src/include/nsswitch.h#4 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getproto.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoent.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoname.c#2 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/netdb_private.h#6 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/auth-rh-rsa.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/auth.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/auth.h#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/auth2-hostbased.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/auth2.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/config.h.in#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/configure#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/configure.ac#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/hostfile.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/hostfile.h#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/initial_copy.sh#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/key.h#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/make.sh#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-auth-rh.rsa.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-auth.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-auth.h#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-auth2-hostbased.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-config.h.in#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-configure#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-configure.ac#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-hostfile.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-hostfile.h#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/patches/patch-sshconnect.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/Makefile#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/distinfo#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/batch.patch#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/gss-serv.c.patch#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-auth-pam.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-auth-rh.rsa.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-auth.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-auth.h#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-auth1.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-auth2-hostbased.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-auth2.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-clientloop.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-config.h.in#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-configure#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-configure.ac#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-fake-rfc2553.h#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-hostfile.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-hostfile.h#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-loginrec.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-regress-test-exec.sh#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-session.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-sshconnect.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-sshd.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-sshd_config#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/patch-sshpty.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/servconf.c.patch#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/files/sshd.sh#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/pkg-descr#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/pkg-message#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/port/pkg-plist#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/result_copy.sh#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_hostkeys_test/sshconnect.c#1 add
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/auth.c#3 delete
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/auth.h#3 delete
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/auth2-hostbased.c#3 delete
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/auth2.c#3 delete
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/hostfile.c#3 delete
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/hostfile.h#3 delete
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/key.h#3 delete
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/make.sh#2 delete
.. //depot/projects/soc2005/nsswitch_cached/tests/ssh_keys/sshconnect.c#3 delete
Differences ...
==== //depot/projects/soc2005/nsswitch_cached/src/include/nsswitch.h#4 (text+ko) ====
@@ -83,6 +83,8 @@
#define NSDB_SERVICES "services"
#define NSDB_SERVICES_COMPAT "services_compat"
#define NSDB_SSH_HOSTKEYS "ssh_hostkeys"
+#define NSDB_PROTOCOLS "protocols"
+#define NSDB_RPC "rpc"
/*
* suggested databases to implement
@@ -96,9 +98,7 @@
#define NSDB_NETMASKS "netmasks"
#define NSDB_PHONES "phones"
#define NSDB_PRINTCAP "printcap"
-#define NSDB_PROTOCOLS "protocols"
#define NSDB_REMOTE "remote"
-#define NSDB_RPC "rpc"
#define NSDB_SENDMAILVARS "sendmailvars"
#define NSDB_TERMCAP "termcap"
#define NSDB_TTYS "ttys"
==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getproto.c#2 (text+ko) ====
@@ -37,31 +37,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/lib/libc/net/getproto.c,v 1.4 2005/04/19 14:41:13 ume Exp $");
-#include <netdb.h>
-#include "netdb_private.h"
-
-int
-getprotobynumber_r(int proto, struct protoent *pe, struct protoent_data *ped)
-{
- int error;
-
- setprotoent_r(ped->stayopen, ped);
- while ((error = getprotoent_r(pe, ped)) == 0)
- if (pe->p_proto == proto)
- break;
- if (!ped->stayopen)
- endprotoent_r(ped);
- return (error);
-}
-
-struct protoent *
-getprotobynumber(int proto)
-{
- struct protodata *pd;
-
- if ((pd = __protodata_init()) == NULL)
- return (NULL);
- if (getprotobynumber_r(proto, &pd->proto, &pd->data) != 0)
- return (NULL);
- return (&pd->proto);
-}
+/* This file is obsolete. The getproto* functions are currently implemented via the
+ * nsswitch subsystem. The functionality of all getserv*_r functions is currently
+ * incapsulated in the files_protoent functions in the getprotoent.c file */
==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoent.c#2 (text+ko) ====
@@ -39,108 +39,83 @@
#include <sys/types.h>
#include <sys/socket.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"
-static struct protodata protodata;
-static thread_key_t protodata_key;
-static once_t protodata_init_once = ONCE_INITIALIZER;
-static int protodata_thr_keycreated = 0;
-
-static void
-protoent_data_clear(struct protoent_data *ped)
+/* nsswitch declarations */
+enum constants
{
- if (ped->fp) {
- fclose(ped->fp);
- ped->fp = NULL;
- }
-}
+ SETPROTOENT = 1,
+ ENDPROTOENT = 2,
+ PROTOENT_STORAGE_INITIAL = 1 << 10, /* 1 KByte */
+ PROTOENT_STORAGE_MAX = 1 << 20, /* 1 MByte */
+};
-static void
-protodata_free(void *ptr)
-{
- struct protodata *pd = ptr;
+static const ns_src defaultsrc[] = {
+ { NSSRC_FILES, NS_SUCCESS },
+ { NULL, 0 }
+};
- if (pd == NULL)
- return;
- protoent_data_clear(&pd->data);
- free(pd);
-}
-
-static void
-protodata_keycreate(void)
+/* files backend declarations */
+struct files_state
{
- protodata_thr_keycreated =
- (thr_keycreate(&protodata_key, protodata_free) == 0);
-}
+ FILE *fp;
+ int stayopen;
+};
+static void files_endstate(void *);
+NSS_TLS_HANDLING(files);
-struct protodata *
-__protodata_init(void)
-{
- struct protodata *pd;
+static int files_protoent(void *, void *, va_list);
+static int files_setprotoent(void *, void *, va_list);
- if (thr_main() != 0)
- return (&protodata);
- if (thr_once(&protodata_init_once, protodata_keycreate) != 0 ||
- !protodata_thr_keycreated)
- return (NULL);
- if ((pd = thr_getspecific(protodata_key)) != NULL)
- return (pd);
- if ((pd = calloc(1, sizeof(*pd))) == NULL)
- return (NULL);
- if (thr_setspecific(protodata_key, pd) == 0)
- return (pd);
- free(pd);
- return (NULL);
-}
+/* 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);
-void
-setprotoent_r(int f, struct protoent_data *ped)
-{
- if (ped->fp == NULL)
- ped->fp = fopen(_PATH_PROTOCOLS, "r");
- else
- rewind(ped->fp);
- ped->stayopen |= f;
-}
+union key {
+ const char *name;
+ int proto;
+};
-void
-endprotoent_r(struct protoent_data *ped)
-{
- if (ped->fp) {
- fclose(ped->fp);
- ped->fp = NULL;
- }
- ped->stayopen = 0;
-}
+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);
-int
-getprotoent_r(struct protoent *pe, struct protoent_data *ped)
+static int
+protoent_unpack(char *p, struct protoent *pe, char **aliases,
+ size_t aliases_size, int *errnop)
{
- char *p;
char *cp, **q, *endp;
long l;
-
- if (ped->fp == NULL && (ped->fp = fopen(_PATH_PROTOCOLS, "r")) == NULL)
+
+ if (*p == '#')
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;
+ return (-1);
*cp++ = '\0';
while (*cp == ' ' || *cp == '\t')
cp++;
@@ -149,9 +124,9 @@
*p++ = '\0';
l = strtol(cp, &endp, 10);
if (endp == cp || *endp != '\0' || l < 0 || l > USHRT_MAX)
- goto again;
+ return -1;
pe->p_proto = l;
- q = pe->p_aliases = ped->aliases;
+ q = pe->p_aliases = aliases;
if (p != NULL) {
cp = p;
while (cp && *cp) {
@@ -159,45 +134,386 @@
cp++;
continue;
}
- if (q < &ped->aliases[_MAXALIASES - 1])
+ if (q < &(aliases[aliases_size - 1]))
*q++ = cp;
+ else {
+ *errnop = ERANGE;
+ return -1;
+ }
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
}
}
*q = NULL;
- return (0);
+ 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)
+{
+ 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;
+ }
+
+ 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);
+}
+
+static int
+files_setprotoent(void *retval, void *mdata, va_list ap)
+{
+ 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);
+}
+
+/* get**_r functions implementation */
+int
+getprotobyname_r(const char *name, struct protoent *pe, char *buffer,
+ size_t bufsize, struct protoent **result)
+{
+ static const ns_dtab dtab[] = {
+ { NSSRC_FILES, files_protoent, (void *)nss_lt_name },
+ { NULL, NULL, NULL }
+ };
+
+ int rv, ret_errno;
+
+ ret_errno = 0;
+ *result = NULL;
+ rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobyname_r", defaultsrc,
+ name, pe, buffer, bufsize, &ret_errno);
+
+ if (rv == NS_SUCCESS)
+ return (0);
+ else
+ return (ret_errno);
+}
+
+int
+getprotobynumber_r(int number, struct protoent *pe, char *buffer,
+ size_t bufsize, struct protoent **result)
+{
+ static const ns_dtab dtab[] = {
+ { NSSRC_FILES, files_protoent, (void *)nss_lt_id },
+ { NULL, NULL, NULL }
+ };
+ int rv, ret_errno;
+
+ ret_errno = 0;
+ *result = NULL;
+ rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotobynumber_r", defaultsrc,
+ number, pe, buffer, bufsize, &ret_errno);
+
+ if (rv == NS_SUCCESS)
+ return (0);
+ else
+ return (ret_errno);
+}
+
+int
+getprotoent_r(struct protoent *pe, char *buffer, size_t bufsize,
+ struct protoent **result)
+{
+ static const ns_dtab dtab[] = {
+ { NSSRC_FILES, files_protoent, (void *)nss_lt_all },
+ { NULL, NULL, NULL }
+ };
+ int rv, ret_errno;
+
+ ret_errno = 0;
+ *result = NULL;
+ rv = nsdispatch(result, dtab, NSDB_PROTOCOLS, "getprotoent_r", defaultsrc,
+ pe, buffer, bufsize, &ret_errno);
+
+ if (rv == NS_SUCCESS)
+ return (0);
+ else
+ return (ret_errno);
+}
+
+void
+setprotoent(int stayopen)
+{
+ static const ns_dtab dtab[] = {
+ { NSSRC_FILES, files_setprotoent, (void *)SETPROTOENT },
+ { NULL, NULL, NULL }
+ };
+
+ (void)nsdispatch(NULL, dtab, NSDB_PROTOCOLS, "setprotoent", defaultsrc, stayopen);
}
-void
-setprotoent(int f)
+void
+endprotoent()
{
- struct protodata *pd;
+ static const ns_dtab dtab[] = {
+ { NSSRC_FILES, files_setprotoent, (void *)ENDPROTOENT },
+ { NULL, NULL, NULL }
+ };
+
+ (void)nsdispatch(NULL, dtab, NSDB_PROTOCOLS, "endprotoent", defaultsrc);
+}
- if ((pd = __protodata_init()) == NULL)
+/* get** wrappers for get**_r functions implementation */
+static void
+protoent_endstate(void *p)
+{
+ if (p == NULL)
return;
- setprotoent_r(f, &pd->data);
+
+ 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);
}
-void
-endprotoent(void)
+struct protoent *
+getprotobyname(const char *name)
{
- struct protodata *pd;
+ union key key;
- if ((pd = __protodata_init()) == NULL)
- return;
- endprotoent_r(&pd->data);
+ key.name = name;
+
+ return (getpe(wrap_getprotobyname_r, key));
}
struct protoent *
-getprotoent(void)
+getprotobynumber(int number)
{
- struct protodata *pd;
+ union key key;
+
+ key.proto = number;
+
+ return (getpe(wrap_getprotobynumber_r, key));
+}
- if ((pd = __protodata_init()) == NULL)
- return (NULL);
- if (getprotoent_r(&pd->proto, &pd->data) != 0)
- return (NULL);
- return (&pd->proto);
+struct protoent *
+getprotoent()
+{
+ union key key;
+
+ key.proto = 0; /* not used */
+
+ return (getpe(wrap_getprotoent_r, key));
}
==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoname.c#2 (text+ko) ====
@@ -37,39 +37,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: src/lib/libc/net/getprotoname.c,v 1.4 2005/04/19 14:41:13 ume Exp $");
-#include <netdb.h>
-#include <string.h>
-#include "netdb_private.h"
-
-int
-getprotobyname_r(const char *name, struct protoent *pe,
- struct protoent_data *ped)
-{
- char **cp;
- int error;
-
- setprotoent_r(ped->stayopen, ped);
- while ((error = getprotoent_r(pe, ped)) == 0) {
- if (strcmp(pe->p_name, name) == 0)
- break;
- for (cp = pe->p_aliases; *cp != 0; cp++)
- if (strcmp(*cp, name) == 0)
- goto found;
- }
-found:
- if (!ped->stayopen)
- endprotoent_r(ped);
- return (error);
-}
-
-struct protoent *
-getprotobyname(const char *name)
-{
- struct protodata *pd;
-
- if ((pd = __protodata_init()) == NULL)
- return (NULL);
- if (getprotobyname_r(name, &pd->proto, &pd->data) != 0)
- return (NULL);
- return (&pd->proto);
-}
+/* This file is obsolete. The getproto* functions are currently implemented via the
+ * nsswitch subsystem. The functionality of all getserv*_r functions is currently
+ * incapsulated in the files_protoent functions in the getprotoent.c file */
==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/netdb_private.h#6 (text+ko) ====
@@ -58,13 +58,6 @@
#endif
};
-struct protoent_data {
- FILE *fp;
- char *aliases[_MAXALIASES];
- int stayopen;
- char line[_MAXLINELEN + 1];
-};
-
struct hostdata {
struct hostent host;
struct hostent_data data;
@@ -75,11 +68,6 @@
struct netent_data data;
};
-struct protodata {
- struct protoent proto;
- struct protoent_data data;
-};
-
#define endhostent_r __endhostent_r
#define endnetent_r __endnetent_r
#define endprotoent_r __endprotoent_r
@@ -131,9 +119,12 @@
struct netent_data *);
int getnetbyname_r(const char *, struct netent *, struct netent_data *);
int getnetent_r(struct netent *, struct netent_data *);
-int getprotobyname_r(const char *, struct protoent *, struct protoent_data *);
-int getprotobynumber_r(int, struct protoent *, struct protoent_data *);
-int getprotoent_r(struct protoent *, struct protoent_data *);
+int getprotobyname_r(const char *, struct protoent *, char *, size_t,
+ struct protoent **);
+int getprotobynumber_r(int, struct protoent *, char *, size_t,
+ struct protoent **);
+int getprotoent_r(struct protoent *, char *, size_t,
+ struct protoent **);
int getservbyname_r(const char *, const char *, struct servent *,
char *, size_t, struct servent **);
int getservbyport_r(int, const char *, struct servent *,
More information about the p4-projects
mailing list