aboutsummaryrefslogtreecommitdiff
path: root/nis/nss_nis
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1996-12-11 01:40:39 +0000
committerUlrich Drepper <drepper@redhat.com>1996-12-11 01:40:39 +0000
commit6259ec0d78fd301572fcb616fdfa0500b828a824 (patch)
treeb1a008ed66281799defcaf56a92d3b592ca1f34a /nis/nss_nis
parentaee321f468f9214700b24e7aef39ef27bda4c42c (diff)
downloadglibc-6259ec0d78fd301572fcb616fdfa0500b828a824.tar
glibc-6259ec0d78fd301572fcb616fdfa0500b828a824.tar.gz
glibc-6259ec0d78fd301572fcb616fdfa0500b828a824.tar.bz2
glibc-6259ec0d78fd301572fcb616fdfa0500b828a824.zip
update from main arcive 961210cvs/libc-961211
Wed Dec 11 01:04:30 1996 Ulrich Drepper <drepper@cygnus.com> Add NIS NSS implementation. * shlib-versions: Add versions for NIS libraries. * sysdeps/unix/inet/Subdirs: Add nis. * nis/Banner: New file. * nis/Makefile: New file. * nis/nss-nis.h: New file. * nis/yp_xdr.h: New file. * nis/ypclnt.h: New file. * nis/ypupdate_xdr.c: New file. * nis/nss_compat/compat-grp.c: New file. * nis/nss_compat/compat-pwd.c: New file. * nis/nss_compat/compat-spwd.c: New file. * nis/nss_nis/nis-alias.c: New file. * nis/nss_nis/nis-ethers.c: New file. * nis/nss_nis/nis-grp.c: New file. * nis/nss_nis/nis-hosts.c: New file. * nis/nss_nis/nis-netgrp.c: New file. * nis/nss_nis/nis-network.c: New file. * nis/nss_nis/nis-proto.c: New file. * nis/nss_nis/nis-publickey.c: New file. * nis/nss_nis/nis-pwd.c: New file. * nis/nss_nis/nis-rpc.c: New file. * nis/nss_nis/nis-service.c: New file. * nis/nss_nis/nis-spwd.c: New file. * nis/rpcsvc/yp.h: New file. * nis/rpcsvc/yp.x: New file. * nis/rpcsvc/yp_prot.h: New file. * nis/rpcsvc/ypclnt.h: New file. * nis/rpcsvc/ypupd.h: New file. * libio/_G_config.h: Define _G_HAVE_SYS_WAIT and _G_HAVE_PRINTF_FP. * locale/C-numeric.c: Update copyright. * locale/Makefile: Add rules to build libBrokenLocale. * locale/broken_cur_max.c: New file. * locale/mb_cur_max.c: Update copyright. (__ctype_get_mb_cur_max): Make function weak. * new-malloc/malloc.c: Correct copyright. * new-malloc/thread-m.h: Correct key handling. * shadow/lckpwdf.c: Update copyright. (PWD_LOCKFILE): Change to /etc/.pwd.lock. * stdlib/strtod.c: Add another assertion. * stdlib/tst-strtod.c: Add another test case. * sysdeps/generic/paths.h: Add _PATH_PRESERVE. Needed by nvi. * sysdeps/unix/sysv/linux/paths.h: Likewise. * sysdeps/gnu/utmpbits.h: Rename ut_addr field to ut_addr_v6. ut_addr names a single element in ut_addr_v6. * sysdeps/mach/hurd/xmknod.c: Remove alias from __mknod to mknod. Patch by Thomas Bushnell, n/BSG. Tue Dec 10 11:35:28 1996 Richard Henderson <rth@tamu.edu> * sysdeps/alpha/strncmp.S: Fix aligned short truncated compare corner condition. * sysdeps/alpha/memchr.S: Don't read ahead, even if the load did fit nicely into that delay slot (patch from David Mosberger-Tang). Mon Dec 9 23:53:43 1996 Thomas Bushnell, n/BSG <thomas@gnu.ai.mit.edu> * sysdeps/mach/hurd/ttyname_r.c (__ttyname_r): Renamed from `ttyname_r'. (ttyname_r): New alias. * stdio-common/printf_fp.c (__guess_grouping): Fix off by one
Diffstat (limited to 'nis/nss_nis')
-rw-r--r--nis/nss_nis/nis-alias.c269
-rw-r--r--nis/nss_nis/nis-ethers.c264
-rw-r--r--nis/nss_nis/nis-grp.c246
-rw-r--r--nis/nss_nis/nis-hosts.c389
-rw-r--r--nis/nss_nis/nis-netgrp.c128
-rw-r--r--nis/nss_nis/nis-network.c292
-rw-r--r--nis/nss_nis/nis-proto.c246
-rw-r--r--nis/nss_nis/nis-publickey.c220
-rw-r--r--nis/nss_nis/nis-pwd.c246
-rw-r--r--nis/nss_nis/nis-rpc.c270
-rw-r--r--nis/nss_nis/nis-service.c249
-rw-r--r--nis/nss_nis/nis-spwd.c196
12 files changed, 3015 insertions, 0 deletions
diff --git a/nis/nss_nis/nis-alias.c b/nis/nss_nis/nis-alias.c
new file mode 100644
index 0000000000..af83d9cd7c
--- /dev/null
+++ b/nis/nss_nis/nis-alias.c
@@ -0,0 +1,269 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <aliases.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+__libc_lock_define_initialized (static, lock)
+
+static bool_t new_start = 1;
+static char *oldkey = NULL;
+static int oldkeylen = 0;
+
+static int
+_nss_nis_parse_aliasent (char *key, char *alias, struct aliasent *result,
+ char *buffer, size_t buflen)
+{
+ char *first_unused = buffer + strlen (alias) + 1;
+ size_t room_left =
+ buflen - (buflen % __alignof__ (char *)) - strlen (alias) - 2;
+ char *line;
+ char *cp;
+
+ result->alias_members_len = 0;
+ *first_unused = '\0';
+ first_unused++;
+ strcpy (first_unused, key);
+
+ if (first_unused[room_left - 1] != '\0')
+ {
+ /* The line is too long for our buffer. */
+ no_more_room:
+ __set_errno (ERANGE);
+ return -1;
+ }
+
+ result->alias_name = first_unused;
+
+ /* Terminate the line for any case. */
+ cp = strpbrk (alias, "#\n");
+ if (cp != NULL)
+ *cp = '\0';
+
+ first_unused += strlen (result->alias_name) + 1;
+ /* Adjust the pointer so it is aligned for
+ storing pointers. */
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
+ result->alias_members = (char **) first_unused;
+
+ line = alias;
+
+ while (*line != '\0')
+ {
+ /* Skip leading blanks. */
+ while (isspace (*line))
+ line++;
+
+ if (*line == '\0')
+ break;
+
+ if (room_left < sizeof (char *))
+ goto no_more_room;
+ room_left -= sizeof (char *);
+ result->alias_members[result->alias_members_len] = line;
+
+ while (*line != '\0' && *line != ',')
+ line++;
+
+ if (line != result->alias_members[result->alias_members_len])
+ {
+ *line = '\0';
+ line++;
+ result->alias_members_len++;
+ }
+ }
+ return result->alias_members_len == 0 ? 0 : 1;
+}
+
+enum nss_status
+_nss_nis_setaliasent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endaliasent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+static enum nss_status
+internal_nis_getaliasent_r (struct aliasent *alias, char *buffer,
+ size_t buflen)
+{
+ char *domain;
+ char *result;
+ int len;
+ char *outkey;
+ int keylen;
+ char *p;
+ int parse_res;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ alias->alias_local = 0;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "mail.aliases",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "mail.aliases", oldkey,
+ oldkeylen, &outkey, &keylen,
+ &result, &len));
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer, buflen);
+ if (parse_res == -1)
+ {
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getaliasent_r (struct aliasent *alias, char *buffer, size_t buflen)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getaliasent_r (alias, buffer, buflen);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getaliasbyname_r (const char *name, struct aliasent *alias,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ int parse_res;
+ char *domain;
+ char *result;
+ int len;
+ char *p;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ retval = yperr2nss (yp_match (domain, "mail.aliases", name, strlen (name),
+ &result, &len));
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ alias->alias_local = 0;
+ parse_res = _nss_nis_parse_aliasent (name, p, alias, buffer, buflen);
+ if (parse_res == -1)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ if (parse_res == 0)
+ return NSS_STATUS_NOTFOUND;
+ else
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nis/nss_nis/nis-ethers.c b/nis/nss_nis/nis-ethers.c
new file mode 100644
index 0000000000..26449720bb
--- /dev/null
+++ b/nis/nss_nis/nis-ethers.c
@@ -0,0 +1,264 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+#include <netinet/if_ether.h>
+
+#include "nss-nis.h"
+
+/* Protect global state against multiple changers */
+__libc_lock_define_initialized (static, lock)
+
+struct ether
+{
+ char *e_name;
+ struct ether_addr e_addr;
+};
+
+static bool_t new_start = 1;
+static char *oldkey = NULL;
+static int oldkeylen = 0;
+
+enum nss_status
+_nss_nis_setetherent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endetherent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+static enum nss_status
+internal_nis_getetherent_r (struct ether *eth, char *buffer, size_t buflen)
+{
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+ char *p;
+
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "ethers.byaddr",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "ethers.byaddr",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_etherent (p, eth, buffer, buflen);
+ if (!parse_res && errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getetherent_r (struct ether *result, char *buffer, size_t buflen)
+{
+ int status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getetherent_r (result, buffer, buflen);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getethernam_r (const char *name, struct ether *eth,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ retval = yperr2nss (yp_match (domain, "ethers.byname", name,
+ strlen (name), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_etherent (p, eth, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getetherbyaddr_r (struct ether_addr *addr, struct ether *eth,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[33];
+
+ if (addr == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ nlen = sprintf (buf, "%x:%x:%x:%x:%x:%x",
+ (int) addr->ether_addr_octet[0],
+ (int) addr->ether_addr_octet[1],
+ (int) addr->ether_addr_octet[2],
+ (int) addr->ether_addr_octet[3],
+ (int) addr->ether_addr_octet[4],
+ (int) addr->ether_addr_octet[5]);
+
+ retval = yperr2nss (yp_match (domain, "ethers.byaddr", buf,
+ nlen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_etherent (p, eth, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nis/nss_nis/nis-grp.c b/nis/nss_nis/nis-grp.c
new file mode 100644
index 0000000000..1bab862c2f
--- /dev/null
+++ b/nis/nss_nis/nis-grp.c
@@ -0,0 +1,246 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <grp.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+/* Protect global state against multiple changers */
+__libc_lock_define_initialized (static, lock)
+
+static bool_t new_start = 1;
+static char *oldkey = NULL;
+static int oldkeylen = 0;
+
+enum nss_status
+_nss_nis_setgrent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endgrent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+static enum nss_status
+internal_nis_getgrent_r (struct group *grp, char *buffer, size_t buflen)
+{
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+ char *p;
+
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "group.byname",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "group.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_grent (p, grp, buffer, buflen);
+ if (!parse_res && errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getgrent_r (struct group *result, char *buffer, size_t buflen)
+{
+ int status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getgrent_r (result, buffer, buflen);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getgrnam_r (const char *name, struct group *grp,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ retval = yperr2nss (yp_match (domain, "group.byname", name,
+ strlen (name), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_grent (p, grp, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getgrgid_r (gid_t gid, struct group *grp,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[32];
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ nlen = sprintf (buf, "%d", gid);
+
+ retval = yperr2nss (yp_match (domain, "group.bygid", buf,
+ nlen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_grent (p, grp, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nis/nss_nis/nis-hosts.c b/nis/nss_nis/nis-hosts.c
new file mode 100644
index 0000000000..9adce18ca3
--- /dev/null
+++ b/nis/nss_nis/nis-hosts.c
@@ -0,0 +1,389 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <ctype.h>
+#include <netdb.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <resolv.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+/* Get implementation for some internal functions. */
+#include "../../resolv/mapv4v6addr.h"
+#include "../../resolv/mapv4v6hostent.h"
+
+#define ENTNAME hostent
+#define DATABASE "hosts"
+#define NEED_H_ERRNO
+
+#define ENTDATA hostent_data
+struct hostent_data
+ {
+ unsigned char host_addr[16]; /* IPv4 or IPv6 address. */
+ char *h_addr_ptrs[2]; /* Points to that and null terminator. */
+ };
+
+#define TRAILING_LIST_MEMBER h_aliases
+#define TRAILING_LIST_SEPARATOR_P isspace
+#include "../../nss/nss_files/files-parse.c"
+LINE_PARSER
+("#",
+ {
+ char *addr;
+
+ STRING_FIELD (addr, isspace, 1);
+
+ /* Parse address. */
+ if ((_res.options & RES_USE_INET6)
+ && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
+ {
+ result->h_addrtype = AF_INET6;
+ result->h_length = IN6ADDRSZ;
+ }
+ else
+ if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
+ {
+ if (_res.options & RES_USE_INET6)
+ {
+ map_v4v6_address ((char *) entdata->host_addr,
+ (char *) entdata->host_addr);
+ result->h_addrtype = AF_INET6;
+ result->h_length = IN6ADDRSZ;
+ }
+ else
+ {
+ result->h_addrtype = AF_INET;
+ result->h_length = INADDRSZ;
+ }
+ }
+ else
+ /* Illegal address: ignore line. */
+ return 0;
+
+ /* Store a pointer to the address in the expected form. */
+ entdata->h_addr_ptrs[0] = entdata->host_addr;
+ entdata->h_addr_ptrs[1] = NULL;
+ result->h_addr_list = entdata->h_addr_ptrs;
+
+ /* If we need the host entry in IPv6 form change it now. */
+ if (_res.options & RES_USE_INET6)
+ {
+ char *bufptr = data->linebuffer;
+ size_t buflen = (char *) data + datalen - bufptr;
+ map_v4v6_hostent (result, &bufptr, &buflen);
+ }
+
+ STRING_FIELD (result->h_name, isspace, 1);
+ }
+)
+
+__libc_lock_define_initialized (static, lock)
+
+static bool_t new_start = 1;
+static char *oldkey = NULL;
+static int oldkeylen = 0;
+
+enum nss_status
+_nss_nis_sethostent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endhostent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+static enum nss_status
+internal_nis_gethostent_r (struct hostent *host, char *buffer,
+ size_t buflen, int *h_errnop)
+{
+ char *domain;
+ char *result;
+ int len, parse_res;
+ char *outkey;
+ int keylen;
+ struct parser_data *data = (void *) buffer;
+ size_t linebuflen = buffer + buflen - data->linebuffer;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ if (buflen < sizeof *data + 1)
+ {
+ __set_errno (ERANGE);
+ *h_errnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+ char *p;
+
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "hosts.byname",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "hosts.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ switch (retval)
+ {
+ case NSS_STATUS_TRYAGAIN:
+ __set_errno (EAGAIN);
+ *h_errnop = TRY_AGAIN;
+ break;
+ case NSS_STATUS_NOTFOUND:
+ *h_errnop = HOST_NOT_FOUND;
+ break;
+ default:
+ *h_errnop = NO_RECOVERY;
+ break;
+ }
+ return retval;
+ }
+
+ if (len + 1 > linebuflen)
+ {
+ free (result);
+ *h_errnop = NETDB_INTERNAL;
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (data->linebuffer, result, len);
+ data->linebuffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = parse_line (p, host, data, buflen);
+ if (!parse_res && errno == ERANGE)
+ {
+ *h_errnop = NETDB_INTERNAL;;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
+ }
+ while (!parse_res);
+
+ *h_errnop = NETDB_SUCCESS;
+ return NSS_STATUS_SUCCESS;
+}
+
+int
+_nss_nis_gethostent_r (struct hostent *host, char *buffer, size_t buflen,
+ int *h_errnop)
+{
+ int status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_gethostent_r (host, buffer, buflen, h_errnop);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_gethostbyname_r (const char *name, struct hostent *host,
+ char *buffer, size_t buflen, int *h_errnop)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+ struct parser_data *data = (void *) buffer;
+ size_t linebuflen = buffer + buflen - data->linebuffer;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ if (buflen < sizeof *data + 1)
+ {
+ *h_errnop = NETDB_INTERNAL;
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+ retval = yperr2nss (yp_match (domain, "hosts.byname", name,
+ strlen (name), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ {
+ *h_errnop = TRY_AGAIN;
+ __set_errno (EAGAIN);
+ }
+ if (retval == NSS_STATUS_NOTFOUND)
+ *h_errnop = HOST_NOT_FOUND;
+ return retval;
+ }
+
+ if (len + 1 > linebuflen)
+ {
+ free (result);
+ *h_errnop = NETDB_INTERNAL;
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (data->linebuffer, result, len);
+ data->linebuffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = parse_line (p, host, data, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ {
+ *h_errnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+ }
+
+ *h_errnop = NETDB_SUCCESS;
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_gethostbyaddr_r (char *addr, int addrlen, int type,
+ struct hostent *host, char *buffer, size_t buflen,
+ int *h_errnop)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+ char *buf;
+ struct parser_data *data = (void *) buffer;
+ size_t linebuflen = buffer + buflen - data->linebuffer;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ if (buflen < sizeof *data + 1)
+ {
+ __set_errno (ERANGE);
+ *h_errnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ buf = inet_ntoa (*(struct in_addr *) addr);
+
+ retval = yperr2nss (yp_match (domain, "hosts.byaddr", buf,
+ strlen (buf), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ {
+ *h_errnop = TRY_AGAIN;
+ __set_errno (EAGAIN);
+ }
+ if (retval == NSS_STATUS_NOTFOUND)
+ *h_errnop = HOST_NOT_FOUND;
+ return retval;
+ }
+
+ if (len + 1 > linebuflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ *h_errnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (data->linebuffer, result, len);
+ data->linebuffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = parse_line (p, host, data, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ {
+ *h_errnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ *h_errnop = HOST_NOT_FOUND;
+ return NSS_STATUS_NOTFOUND;
+ }
+ }
+
+ *h_errnop = NETDB_SUCCESS;
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nis/nss_nis/nis-netgrp.c b/nis/nss_nis/nis-netgrp.c
new file mode 100644
index 0000000000..7609ea08ed
--- /dev/null
+++ b/nis/nss_nis/nis-netgrp.c
@@ -0,0 +1,128 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <ctype.h>
+#include <errno.h>
+#include <libc-lock.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netgroup.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+/* Locks the static variables in this file. */
+__libc_lock_define_initialized (static, lock)
+
+static char *data = NULL;
+static size_t data_size = 0;
+static char *cursor = NULL;;
+
+extern enum nss_status
+_nss_netgroup_parseline (char **cursor, struct __netgrent *result,
+ char *buffer, size_t buflen);
+
+enum nss_status
+_nss_nis_setnetgrent (char *group)
+{
+ char *domain;
+ char *result;
+ int len, group_len;
+ enum nss_status status;
+
+ status = NSS_STATUS_SUCCESS;
+
+ if (group[0] == '\0')
+ return NSS_STATUS_UNAVAIL;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ __libc_lock_lock (lock);
+
+ if (data != NULL)
+ {
+ free (data);
+ data = NULL;
+ data_size = 0;
+ cursor = NULL;
+ }
+
+ group_len = strlen (group);
+
+ status = yperr2nss (yp_match (domain, "netgroup", group, group_len,
+ &result, &len));
+ if (status == NSS_STATUS_SUCCESS)
+ {
+ if (len > 0)
+ {
+ data = malloc (len + 1);
+ data_size = len;
+ cursor = strncpy (data, result, len + 1);
+ data[len] = '\0';
+ free (result);
+ }
+ else
+ status = NSS_STATUS_NOTFOUND;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+
+enum nss_status
+_nss_nis_endnetgrent (void)
+{
+ __libc_lock_lock (lock);
+
+ if (data != NULL)
+ {
+ free (data);
+ data = NULL;
+ data_size = 0;
+ cursor = NULL;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen)
+{
+ enum nss_status status;
+
+ if (cursor == NULL)
+ return NSS_STATUS_NOTFOUND;
+
+ __libc_lock_lock (lock);
+
+ status = _nss_netgroup_parseline (&cursor, result, buffer, buflen);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
diff --git a/nis/nss_nis/nis-network.c b/nis/nss_nis/nis-network.c
new file mode 100644
index 0000000000..2795feb421
--- /dev/null
+++ b/nis/nss_nis/nis-network.c
@@ -0,0 +1,292 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+__libc_lock_define_initialized (static, lock)
+
+static bool_t new_start = 1;
+static char *oldkey = NULL;
+static int oldkeylen = 0;
+
+enum nss_status
+_nss_nis_setnetent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endnetent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+static enum nss_status
+internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
+ int *herrnop)
+{
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+ char *p;
+
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "networks.byname",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "networks.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ {
+ *herrnop = NETDB_INTERNAL;
+ __set_errno (EAGAIN);
+ }
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ *herrnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_netent (p, net, buffer, buflen);
+ if (!parse_res && errno == ERANGE)
+ {
+ *herrnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
+ int *herrnop)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getnetent_r (net, buffer, buflen, herrnop);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getnetbyname_r (const char *name, struct netent *net,
+ char *buffer, size_t buflen, int *herrnop)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ *herrnop = NETDB_INTERNAL;
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ retval = yperr2nss (yp_match (domain, "networks.byname", name,
+ strlen (name), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ {
+ __set_errno (EAGAIN);
+ *herrnop = NETDB_INTERNAL;
+ }
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ *herrnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_netent (p, net, buffer, buflen);
+
+ if (!parse_res)
+ {
+ *herrnop = NETDB_INTERNAL;
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getnetbyaddr_r (unsigned long addr, int type, struct netent *net,
+ char *buffer, size_t buflen, int *herrnop)
+{
+ char *domain;
+ char *result;
+ int len;
+ char buf[256];
+ int blen;
+ struct in_addr in;
+ char *p;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ in = inet_makeaddr (addr, 0);
+ strcpy (buf, inet_ntoa (in));
+ blen = strlen (buf);
+
+ while (1)
+ {
+ enum nss_status retval;
+ int parse_res;
+
+ retval = yperr2nss (yp_match (domain, "networks.byaddr", buf,
+ strlen (buf), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_NOTFOUND)
+ {
+ if (buf[blen - 2] == '.' && buf[blen - 1] == '0')
+ {
+ /* Try again, but with trailing dot(s)
+ removed (one by one) */
+ buf[blen - 2] = '\0';
+ blen -= 2;
+ continue;
+ }
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ *herrnop = NETDB_INTERNAL;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_netent (p, net, buffer, buflen);
+
+
+ if (!parse_res)
+ {
+ *herrnop = NETDB_INTERNAL;
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+ }
+}
diff --git a/nis/nss_nis/nis-proto.c b/nis/nss_nis/nis-proto.c
new file mode 100644
index 0000000000..f62dfb1492
--- /dev/null
+++ b/nis/nss_nis/nis-proto.c
@@ -0,0 +1,246 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+__libc_lock_define_initialized (static, lock)
+
+static bool_t new_start = 1;
+static char *oldkey = NULL;
+static int oldkeylen = 0;
+
+enum nss_status
+_nss_nis_setprotoent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endprotoent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+static enum nss_status
+internal_nis_getprotoent_r (struct protoent *proto,
+ char *buffer, size_t buflen)
+{
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+ char *p;
+
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "protocols.bynumber",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "protocols.bynumber",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_protoent (p, proto, buffer, buflen);
+ if (!parse_res && errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getprotoent_r (struct protoent *proto, char *buffer, size_t buflen)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getprotoent_r (proto, buffer, buflen);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getprotobyname_r (const char *name, struct protoent *proto,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ retval = yperr2nss (yp_match (domain, "protocols.byname", name,
+ strlen (name), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_protoent (p, proto, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getprotobynumber_r (int number, struct protoent *proto,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[32];
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ nlen = sprintf (buf, "%d", number);
+
+ retval = yperr2nss (yp_match (domain, "protocols.bynumber", buf,
+ nlen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_protoent (p, proto, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nis/nss_nis/nis-publickey.c b/nis/nss_nis/nis-publickey.c
new file mode 100644
index 0000000000..b9eda6a742
--- /dev/null
+++ b/nis/nss_nis/nis-publickey.c
@@ -0,0 +1,220 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <syslog.h>
+#include <libc-lock.h>
+#include <rpc/key_prot.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+extern int xdecrypt (char *, char *);
+
+/* If we found the entry, we give a SUCCESS and an empty key back. */
+enum nss_status
+_nss_nis_getpublickey (const char *netname, char *pkey)
+{
+ enum nss_status retval;
+ char *domain, *result;
+ int len;
+
+ pkey[0] = 0;
+
+ if (netname == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ domain = strchr (netname, '@');
+ if (!domain)
+ return NSS_STATUS_UNAVAIL;
+ domain++;
+
+ retval = yperr2nss (yp_match (domain, "publickey.byname", netname,
+ strlen (netname), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (result != NULL)
+ {
+ char *p = strchr (result, ':');
+ if (p != NULL)
+ *p = 0;
+ strcpy (pkey, result);
+ }
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getsecretkey (const char *netname, char *skey, char *passwd)
+{
+ enum nss_status retval;
+ char buf[1024];
+ char *domain, *result;
+ int len;
+
+ skey[0] = 0;
+
+ if (netname == NULL || passwd == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ domain = strchr (netname, '@');
+ if (!domain)
+ return NSS_STATUS_UNAVAIL;
+ domain++;
+
+ retval = yperr2nss (yp_match (domain, "publickey.byname", netname,
+ strlen (netname), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (result != NULL)
+ {
+ char *p = strchr (result, ':');
+ if (p == NULL)
+ return NSS_STATUS_SUCCESS;
+
+ p++;
+ strcpy (buf, p);
+ if (!xdecrypt (buf, passwd))
+ return NSS_STATUS_SUCCESS;
+
+ if (memcmp (buf, &(buf[HEXKEYBYTES]), KEYCHECKSUMSIZE) != 0)
+ return NSS_STATUS_SUCCESS;
+
+ buf[HEXKEYBYTES] = 0;
+ strcpy (skey, buf);
+ }
+ return NSS_STATUS_SUCCESS;
+}
+
+/* Parse uid and group information from the passed string.
+ The format of the string passed is uid:gid,grp,grp, ... */
+static enum nss_status
+parse_netid_str (const char *s, uid_t *uidp, gid_t *gidp, int *gidlenp,
+ gid_t *gidlist)
+{
+ char *p;
+
+ if (!s || !isdigit (*s))
+ {
+ syslog (LOG_ERR, "netname2user: expecting uid '%s'", s);
+ return NSS_STATUS_NOTFOUND; /* XXX need a better error */
+ }
+
+ /* Fetch the uid */
+ *uidp = (atoi (s));
+
+ if (*uidp == 0)
+ {
+ syslog (LOG_ERR, "netname2user: should not have uid 0");
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ /* Now get the group list */
+ p = strchr (s, ':');
+ if (!p)
+ {
+ syslog (LOG_ERR, "netname2user: missing group id list in '%s'", s);
+ return NSS_STATUS_NOTFOUND;
+ }
+ ++p; /* skip ':' */
+ if (!p || (!isdigit (*p)))
+ {
+ syslog (LOG_ERR, "netname2user: missing group id list in '%s'.", p);
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ *gidp = (atoi (p));
+
+ *gidlenp = 0;
+#if 0
+ while ((p = strchr (p, ',')) != NULL)
+ {
+ p++;
+ gidlist[*gidlenp++] = atoi (p);
+ }
+#endif
+
+ return NSS_STATUS_SUCCESS;
+}
+
+
+enum nss_status
+_nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
+ gid_t *gidp, int *gidlenp, gid_t *gidlist)
+{
+ char *domain;
+ int yperr;
+ char *lookup;
+ int len;
+
+ domain = strchr (netname, '@');
+ if (!domain)
+ return NSS_STATUS_UNAVAIL;
+
+ /* Point past the '@' character */
+ domain++;
+ lookup = NULL;
+ yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
+ &lookup, &len);
+ switch (yperr)
+ {
+ case YPERR_SUCCESS:
+ break; /* the successful case */
+ case YPERR_DOMAIN:
+ case YPERR_KEY:
+ return NSS_STATUS_NOTFOUND;
+ case YPERR_MAP:
+ default:
+ return NSS_STATUS_UNAVAIL;
+ }
+ if (lookup)
+ {
+ enum nss_status err;
+
+ lookup[len] = '\0';
+ err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
+ free (lookup);
+ return err;
+ }
+ else
+ return NSS_STATUS_NOTFOUND;
+
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nis/nss_nis/nis-pwd.c b/nis/nss_nis/nis-pwd.c
new file mode 100644
index 0000000000..afcc7a428e
--- /dev/null
+++ b/nis/nss_nis/nis-pwd.c
@@ -0,0 +1,246 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <pwd.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+/* Protect global state against multiple changers */
+__libc_lock_define_initialized (static, lock)
+
+static bool_t new_start = 1;
+static char *oldkey = NULL;
+static int oldkeylen = 0;
+
+enum nss_status
+_nss_nis_setpwent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endpwent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+static enum nss_status
+internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen)
+{
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+ char *p;
+
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "passwd.byname",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "passwd.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_pwent (p, pwd, buffer, buflen);
+ if (!parse_res && errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getpwent_r (struct passwd *result, char *buffer, size_t buflen)
+{
+ int status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getpwent_r (result, buffer, buflen);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ retval = yperr2nss (yp_match (domain, "passwd.byname", name,
+ strlen (name), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_pwent (p, pwd, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[32];
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ nlen = sprintf (buf, "%d", uid);
+
+ retval = yperr2nss (yp_match (domain, "passwd.byuid", buf,
+ nlen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_pwent (p, pwd, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nis/nss_nis/nis-rpc.c b/nis/nss_nis/nis-rpc.c
new file mode 100644
index 0000000000..91f54be3a9
--- /dev/null
+++ b/nis/nss_nis/nis-rpc.c
@@ -0,0 +1,270 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+__libc_lock_define_initialized (static, lock)
+
+struct intern_t
+{
+ bool_t new_start;
+ char *oldkey;
+ int oldkeylen;
+};
+typedef struct intern_t intern_t;
+
+static intern_t intern = {TRUE, NULL, 0};
+
+static enum nss_status
+internal_nis_setrpcent (intern_t *data)
+{
+ data->new_start = 1;
+ if (data->oldkey != NULL)
+ {
+ free (data->oldkey);
+ data->oldkey = NULL;
+ data->oldkeylen = 0;
+ }
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_setrpcent (void)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_setrpcent (&intern);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+static enum nss_status
+internal_nis_endrpcent (intern_t *data)
+{
+ data->new_start = 1;
+ if (data->oldkey != NULL)
+ {
+ free (data->oldkey);
+ data->oldkey = NULL;
+ data->oldkeylen = 0;
+ }
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endrpcent (void)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_endrpcent (&intern);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+static enum nss_status
+internal_nis_getrpcent_r (struct rpcent *rpc, char *buffer, size_t buflen,
+ intern_t *data)
+{
+ char *domain;
+ char *result;
+ int len, parse_res;
+ char *outkey;
+ int keylen;
+ char *p;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+
+ if (data->new_start)
+ retval = yperr2nss (yp_first (domain, "rpc.bynumber",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "rpc.bynumber",
+ data->oldkey, data->oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_rpcent (p, rpc, buffer, buflen);
+ if (!parse_res && errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+
+ free (data->oldkey);
+ data->oldkey = outkey;
+ data->oldkeylen = keylen;
+ data->new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getrpcent_r (struct rpcent *rpc, char *buffer, size_t buflen)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getrpcent_r (rpc, buffer, buflen, &intern);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
+ char *buffer, size_t buflen)
+{
+ intern_t data = {TRUE, NULL, 0};
+ enum nss_status status;
+ int found;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ status = internal_nis_setrpcent (&data);
+ if (status != NSS_STATUS_SUCCESS)
+ return status;
+
+ found = 0;
+ while (!found &&
+ ((status = internal_nis_getrpcent_r (rpc, buffer, buflen, &data))
+ == NSS_STATUS_SUCCESS))
+ {
+ if (strcmp (rpc->r_name, name) == 0)
+ found = 1;
+ else
+ {
+ int i = 0;
+
+ while (rpc->r_aliases[i] != NULL)
+ {
+ if (strcmp (rpc->r_aliases[i], name) == 0)
+ {
+ found = 1;
+ break;
+ }
+ else
+ ++i;
+ }
+ }
+ }
+
+ internal_nis_endrpcent (&data);
+
+ if (!found && status == NSS_STATUS_SUCCESS)
+ return NSS_STATUS_NOTFOUND;
+ else
+ return status;
+}
+
+enum nss_status
+_nss_nis_getrpcbynumber_r (int number, struct rpcent *rpc,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[32];
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ nlen = sprintf (buf, "%d", number);
+
+ retval = yperr2nss (yp_match (domain, "rpc.bynumber", buf,
+ nlen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_rpcent (p, rpc, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}
diff --git a/nis/nss_nis/nis-service.c b/nis/nss_nis/nis-service.c
new file mode 100644
index 0000000000..03a9fbf48e
--- /dev/null
+++ b/nis/nss_nis/nis-service.c
@@ -0,0 +1,249 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <netdb.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+__libc_lock_define_initialized (static, lock)
+
+struct intern_t
+{
+ bool_t new_start;
+ char *oldkey;
+ int oldkeylen;
+};
+typedef struct intern_t intern_t;
+
+static intern_t intern = {TRUE, NULL, 0};
+
+static enum nss_status
+internal_nis_setservent (intern_t * intern)
+{
+ intern->new_start = 1;
+ if (intern->oldkey != NULL)
+ {
+ free (intern->oldkey);
+ intern->oldkey = NULL;
+ intern->oldkeylen = 0;
+ }
+ return NSS_STATUS_SUCCESS;
+}
+enum nss_status
+_nss_nis_setservent (void)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_setservent (&intern);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+static enum nss_status
+internal_nis_endservent (intern_t * intern)
+{
+ intern->new_start = 1;
+ if (intern->oldkey != NULL)
+ {
+ free (intern->oldkey);
+ intern->oldkey = NULL;
+ intern->oldkeylen = 0;
+ }
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endservent (void)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_endservent (&intern);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+static enum nss_status
+internal_nis_getservent_r (struct servent *serv, char *buffer,
+ size_t buflen, intern_t *data)
+{
+ char *domain;
+ char *result;
+ int len, parse_res;
+ char *outkey;
+ int keylen;
+ char *p;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+
+ if (data->new_start)
+ retval = yperr2nss (yp_first (domain, "services.byname",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "services.byname",
+ data->oldkey, data->oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_servent (p, serv, buffer, buflen);
+ if (!parse_res && errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+
+ free (data->oldkey);
+ data->oldkey = outkey;
+ data->oldkeylen = keylen;
+ data->new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getservent_r (struct servent *serv, char *buffer, size_t buflen)
+{
+ enum nss_status status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getservent_r (serv, buffer, buflen, &intern);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getservbyname_r (const char *name, char *protocol,
+ struct servent *serv, char *buffer, size_t buflen)
+{
+ intern_t data = {TRUE, NULL, 0};
+ enum nss_status status;
+ int found;
+
+ if (name == NULL || protocol == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ status = internal_nis_setservent (&data);
+ if (status != NSS_STATUS_SUCCESS)
+ return status;
+
+ found = 0;
+ while (!found &&
+ ((status = internal_nis_getservent_r (serv, buffer, buflen, &data))
+ == NSS_STATUS_SUCCESS))
+ {
+ if (strcmp (serv->s_name, name) == 0)
+ {
+ if (strcmp (serv->s_proto, protocol) == 0)
+ {
+ found = 1;
+ }
+ }
+ }
+
+ internal_nis_endservent (&data);
+
+ if (!found && status == NSS_STATUS_SUCCESS)
+ return NSS_STATUS_NOTFOUND;
+ else
+ return status;
+}
+
+enum nss_status
+_nss_nis_getservbyport_r (int port, char *protocol, struct servent *serv,
+ char *buffer, size_t buflen)
+{
+ intern_t data = {TRUE, NULL, 0};
+ enum nss_status status;
+ int found;
+
+ if (protocol == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ status = internal_nis_setservent (&data);
+ if (status != NSS_STATUS_SUCCESS)
+ return status;
+
+ found = 0;
+ while (!found &&
+ ((status = internal_nis_getservent_r (serv, buffer, buflen, &data))
+ == NSS_STATUS_SUCCESS))
+ {
+ if (htons (serv->s_port) == port)
+ {
+ if (strcmp (serv->s_proto, protocol) == 0)
+ {
+ found = 1;
+ }
+ }
+ }
+
+ internal_nis_endservent (&data);
+
+ if (!found && status == NSS_STATUS_SUCCESS)
+ return NSS_STATUS_NOTFOUND;
+ else
+ return status;
+}
diff --git a/nis/nss_nis/nis-spwd.c b/nis/nss_nis/nis-spwd.c
new file mode 100644
index 0000000000..928489245b
--- /dev/null
+++ b/nis/nss_nis/nis-spwd.c
@@ -0,0 +1,196 @@
+/* Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <nss.h>
+#include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <shadow.h>
+#include <libc-lock.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
+
+#include "nss-nis.h"
+
+/* Protect global state against multiple changers */
+__libc_lock_define_initialized (static, lock)
+
+static bool_t new_start = 1;
+static char *oldkey = NULL;
+static int oldkeylen = 0;
+
+enum nss_status
+_nss_nis_setspent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_endspent (void)
+{
+ __libc_lock_lock (lock);
+
+ new_start = 1;
+ if (oldkey != NULL)
+ {
+ free (oldkey);
+ oldkey = NULL;
+ oldkeylen = 0;
+ }
+
+ __libc_lock_unlock (lock);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+static enum nss_status
+internal_nis_getspent_r (struct spwd *sp, char *buffer, size_t buflen)
+{
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ enum nss_status retval;
+ char *p;
+
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "shadow.byname",
+ &outkey, &keylen, &result, &len));
+ else
+ retval = yperr2nss ( yp_next (domain, "shadow.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_spent (p, sp, buffer, buflen);
+ if (!parse_res && errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
+ }
+ while (!parse_res);
+
+ return NSS_STATUS_SUCCESS;
+}
+
+enum nss_status
+_nss_nis_getspent_r (struct spwd *result, char *buffer, size_t buflen)
+{
+ int status;
+
+ __libc_lock_lock (lock);
+
+ status = internal_nis_getspent_r (result, buffer, buflen);
+
+ __libc_lock_unlock (lock);
+
+ return status;
+}
+
+enum nss_status
+_nss_nis_getspnam_r (const char *name, struct spwd *sp,
+ char *buffer, size_t buflen)
+{
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
+ if (name == NULL)
+ {
+ __set_errno (EINVAL);
+ return NSS_STATUS_UNAVAIL;
+ }
+
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
+
+ retval = yperr2nss (yp_match (domain, "shadow.byname", name,
+ strlen (name), &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ __set_errno (EAGAIN);
+ return retval;
+ }
+
+ if (len + 1 > buflen)
+ {
+ free (result);
+ __set_errno (ERANGE);
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+
+ parse_res = _nss_files_parse_spent (p, sp, buffer, buflen);
+
+ if (!parse_res)
+ {
+ if (errno == ERANGE)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ else
+ return NSS_STATUS_SUCCESS;
+}