summaryrefslogtreecommitdiff
path: root/nss
diff options
context:
space:
mode:
Diffstat (limited to 'nss')
-rw-r--r--nss/Makefile11
-rw-r--r--nss/XXX-lookup.c2
-rw-r--r--nss/alias-lookup.c2
-rw-r--r--nss/bug17079.c244
-rw-r--r--nss/databases.def2
-rw-r--r--nss/db-Makefile20
-rw-r--r--nss/digits_dots.c2
-rw-r--r--nss/ethers-lookup.c2
-rw-r--r--nss/function.def2
-rw-r--r--nss/getXXbyYY.c4
-rw-r--r--nss/getXXbyYY_r.c2
-rw-r--r--nss/getXXent.c4
-rw-r--r--nss/getXXent_r.c4
-rw-r--r--nss/getent.c80
-rw-r--r--nss/getnssent.c2
-rw-r--r--nss/getnssent_r.c2
-rw-r--r--nss/grp-lookup.c2
-rw-r--r--nss/hosts-lookup.c2
-rw-r--r--nss/key-lookup.c2
-rw-r--r--nss/makedb.c10
-rw-r--r--nss/netgrp-lookup.c2
-rw-r--r--nss/network-lookup.c2
-rw-r--r--nss/nss.h2
-rw-r--r--nss/nss_db/db-XXX.c4
-rw-r--r--nss/nss_db/db-init.c2
-rw-r--r--nss/nss_db/db-initgroups.c2
-rw-r--r--nss/nss_db/db-netgrp.c4
-rw-r--r--nss/nss_db/db-open.c2
-rw-r--r--nss/nss_db/nss_db.h4
-rw-r--r--nss/nss_files/files-XXX.c4
-rw-r--r--nss/nss_files/files-alias.c4
-rw-r--r--nss/nss_files/files-ethers.c2
-rw-r--r--nss/nss_files/files-grp.c2
-rw-r--r--nss/nss_files/files-have_o_cloexec.c2
-rw-r--r--nss/nss_files/files-hosts.c2
-rw-r--r--nss/nss_files/files-init.c2
-rw-r--r--nss/nss_files/files-initgroups.c2
-rw-r--r--nss/nss_files/files-key.c2
-rw-r--r--nss/nss_files/files-netgrp.c2
-rw-r--r--nss/nss_files/files-network.c2
-rw-r--r--nss/nss_files/files-parse.c2
-rw-r--r--nss/nss_files/files-proto.c2
-rw-r--r--nss/nss_files/files-pwd.c2
-rw-r--r--nss/nss_files/files-rpc.c2
-rw-r--r--nss/nss_files/files-service.c2
-rw-r--r--nss/nss_files/files-sgrp.c2
-rw-r--r--nss/nss_files/files-spwd.c2
-rw-r--r--nss/nsswitch.c4
-rw-r--r--nss/nsswitch.h2
-rw-r--r--nss/proto-lookup.c2
-rw-r--r--nss/pwd-lookup.c2
-rw-r--r--nss/rewrite_field.c52
-rw-r--r--nss/rpc-lookup.c2
-rw-r--r--nss/service-lookup.c2
-rw-r--r--nss/sgrp-lookup.c2
-rw-r--r--nss/spwd-lookup.c2
-rw-r--r--nss/test-digits-dots.c2
-rw-r--r--nss/test-netdb.c2
-rw-r--r--nss/tst-field.c101
-rw-r--r--nss/tst-nss-getpwent.c2
-rw-r--r--nss/valid_field.c32
-rw-r--r--nss/valid_list_field.c36
62 files changed, 557 insertions, 153 deletions
diff --git a/nss/Makefile b/nss/Makefile
index 65ab7b5419..b1693a875c 100644
--- a/nss/Makefile
+++ b/nss/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1996-2015 Free Software Foundation, Inc.
+# Copyright (C) 1996-2016 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -26,6 +26,7 @@ headers := nss.h
# This is the trivial part which goes into libc itself.
routines = nsswitch getnssent getnssent_r digits_dots \
+ valid_field valid_list_field rewrite_field \
$(addsuffix -lookup,$(databases))
# These are the databases that go through nss dispatch.
@@ -47,7 +48,10 @@ install-bin := getent makedb
makedb-modules = xmalloc hash-string
extra-objs += $(makedb-modules:=.o)
-tests = test-netdb tst-nss-test1 test-digits-dots tst-nss-getpwent
+tests-static = tst-field
+tests = test-netdb tst-nss-test1 test-digits-dots \
+ tst-nss-getpwent bug17079 \
+ $(tests-static)
xtests = bug-erange
# Specify rules for the nss_* modules. We have some services.
@@ -82,8 +86,7 @@ libnss_db-inhibit-o = $(filter-out .os,$(object-suffixes))
ifeq ($(build-static-nss),yes)
routines += $(libnss_files-routines)
static-only-routines += $(libnss_files-routines)
-tests-static = tst-nss-static
-tests += $(tests-static)
+tests-static += tst-nss-static
endif
include ../Rules
diff --git a/nss/XXX-lookup.c b/nss/XXX-lookup.c
index ba8bad11c1..6119468c6f 100644
--- a/nss/XXX-lookup.c
+++ b/nss/XXX-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/alias-lookup.c b/nss/alias-lookup.c
index 1153a4534a..8361c5c954 100644
--- a/nss/alias-lookup.c
+++ b/nss/alias-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/bug17079.c b/nss/bug17079.c
new file mode 100644
index 0000000000..367daaef5e
--- /dev/null
+++ b/nss/bug17079.c
@@ -0,0 +1,244 @@
+/* Test for bug 17079: heap overflow in NSS with small buffers.
+ Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <pwd.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Check if two passwd structs contain the same data. */
+static bool
+equal (const struct passwd *a, const struct passwd *b)
+{
+ return strcmp (a->pw_name, b->pw_name) == 0
+ && strcmp (a->pw_passwd, b->pw_passwd) == 0
+ && a->pw_uid == b->pw_uid
+ && a->pw_gid == b->pw_gid
+ && strcmp (a->pw_gecos, b->pw_gecos) == 0
+ && strcmp (a->pw_dir, b->pw_dir) == 0
+ && strcmp (a->pw_shell, b->pw_shell) == 0;
+}
+
+enum { MAX_TEST_ITEMS = 10 };
+static struct passwd test_items[MAX_TEST_ITEMS];
+static int test_count;
+
+/* Initialize test_items and test_count above, with data from the
+ passwd database. */
+static bool
+init_test_items (void)
+{
+ setpwent ();
+ do
+ {
+ struct passwd *pwd = getpwent ();
+ if (pwd == NULL)
+ break;
+ struct passwd *target = test_items + test_count;
+ target->pw_name = strdup (pwd->pw_name);
+ target->pw_passwd = strdup (pwd->pw_passwd);
+ target->pw_uid = pwd->pw_uid;
+ target->pw_gid = pwd->pw_gid;
+ target->pw_gecos = strdup (pwd->pw_gecos);
+ target->pw_dir = strdup (pwd->pw_dir);
+ target->pw_shell = strdup (pwd->pw_shell);
+ }
+ while (++test_count < MAX_TEST_ITEMS);
+ endpwent ();
+
+ /* Filter out those test items which cannot be looked up by name or
+ UID. */
+ bool found = false;
+ for (int i = 0; i < test_count; ++i)
+ {
+ struct passwd *pwd1 = getpwnam (test_items[i].pw_name);
+ struct passwd *pwd2 = getpwuid (test_items[i].pw_uid);
+ if (pwd1 == NULL || !equal (pwd1, test_items + i)
+ || pwd2 == NULL || !equal (pwd2, test_items + i))
+ {
+ printf ("info: skipping user \"%s\", UID %ld due to inconsistency\n",
+ test_items[i].pw_name, (long) test_items[i].pw_uid);
+ test_items[i].pw_name = NULL;
+ }
+ else
+ found = true;
+ }
+
+ if (!found)
+ puts ("error: no accounts found which can be looked up by name and UID.");
+ return found;
+}
+
+/* Set to true if an error is encountered. */
+static bool errors;
+
+/* Return true if the padding has not been tampered with. */
+static bool
+check_padding (char *buffer, size_t size, char pad)
+{
+ char *end = buffer + size;
+ while (buffer < end)
+ {
+ if (*buffer != pad)
+ return false;
+ ++buffer;
+ }
+ return true;
+}
+
+/* Test one buffer size and padding combination. */
+static void
+test_one (const struct passwd *item, size_t buffer_size,
+ char pad, size_t padding_size)
+{
+ char *buffer = malloc (buffer_size + padding_size);
+ if (buffer == NULL)
+ {
+ puts ("error: malloc failure");
+ errors = true;
+ return;
+ }
+
+ struct passwd pwd;
+ struct passwd *result;
+ int ret;
+
+ /* Test getpwname_r. */
+ memset (buffer, pad, buffer_size + padding_size);
+ pwd = (struct passwd) {};
+ ret = getpwnam_r (item->pw_name, &pwd, buffer, buffer_size, &result);
+ if (!check_padding (buffer + buffer_size, padding_size, pad))
+ {
+ printf ("error: padding change: "
+ "name \"%s\", buffer size %zu, padding size %zu, pad 0x%02x\n",
+ item->pw_name, buffer_size, padding_size, (unsigned char) pad);
+ errors = true;
+ }
+ if (ret == 0)
+ {
+ if (result == NULL)
+ {
+ printf ("error: no data: name \"%s\", buffer size %zu\n",
+ item->pw_name, buffer_size);
+ errors = true;
+ }
+ else if (!equal (item, result))
+ {
+ printf ("error: lookup mismatch: name \"%s\", buffer size %zu\n",
+ item->pw_name, buffer_size);
+ errors = true;
+ }
+ }
+ else if (ret != ERANGE)
+ {
+ errno = ret;
+ printf ("error: lookup failure for name \"%s\": %m (%d)\n",
+ item->pw_name, ret);
+ errors = true;
+ }
+
+ /* Test getpwuid_r. */
+ memset (buffer, pad, buffer_size + padding_size);
+ pwd = (struct passwd) {};
+ ret = getpwuid_r (item->pw_uid, &pwd, buffer, buffer_size, &result);
+ if (!check_padding (buffer + buffer_size, padding_size, pad))
+ {
+ printf ("error: padding change: "
+ "UID %ld, buffer size %zu, padding size %zu, pad 0x%02x\n",
+ (long) item->pw_uid, buffer_size, padding_size,
+ (unsigned char) pad);
+ errors = true;
+ }
+ if (ret == 0)
+ {
+ if (result == NULL)
+ {
+ printf ("error: no data: UID %ld, buffer size %zu\n",
+ (long) item->pw_uid, buffer_size);
+ errors = true;
+ }
+ else if (!equal (item, result))
+ {
+ printf ("error: lookup mismatch: UID %ld, buffer size %zu\n",
+ (long) item->pw_uid, buffer_size);
+ errors = true;
+ }
+ }
+ else if (ret != ERANGE)
+ {
+ errno = ret;
+ printf ("error: lookup failure for UID \"%ld\": %m (%d)\n",
+ (long) item->pw_uid, ret);
+ errors = true;
+ }
+
+ free (buffer);
+}
+
+/* Test one buffer size with different paddings. */
+static void
+test_buffer_size (size_t buffer_size)
+{
+ for (int i = 0; i < test_count; ++i)
+ for (size_t padding_size = 0; padding_size < 3; ++padding_size)
+ {
+ /* Skip entries with inconsistent name/UID lookups. */
+ if (test_items[i].pw_name == NULL)
+ continue;
+
+ test_one (test_items + i, buffer_size, '\0', padding_size);
+ if (padding_size > 0)
+ {
+ test_one (test_items + i, buffer_size, ':', padding_size);
+ test_one (test_items + i, buffer_size, '\n', padding_size);
+ test_one (test_items + i, buffer_size, '\xff', padding_size);
+ test_one (test_items + i, buffer_size, '@', padding_size);
+ }
+ }
+}
+
+int
+do_test (void)
+{
+ if (!init_test_items ())
+ return 1;
+ printf ("info: %d test items\n", test_count);
+
+ for (size_t buffer_size = 0; buffer_size <= 65; ++buffer_size)
+ test_buffer_size (buffer_size);
+ for (size_t buffer_size = 64 + 4; buffer_size < 256; buffer_size += 4)
+ test_buffer_size (buffer_size);
+ test_buffer_size (255);
+ test_buffer_size (257);
+ for (size_t buffer_size = 256; buffer_size < 512; buffer_size += 8)
+ test_buffer_size (buffer_size);
+ test_buffer_size (511);
+ test_buffer_size (513);
+ test_buffer_size (1024);
+ test_buffer_size (2048);
+
+ if (errors)
+ return 1;
+ else
+ return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/nss/databases.def b/nss/databases.def
index 1ff1a1b157..08cdeb6c4e 100644
--- a/nss/databases.def
+++ b/nss/databases.def
@@ -1,5 +1,5 @@
/* List of all databases defined for the NSS in GNU C Library.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/db-Makefile b/nss/db-Makefile
index fc62344d60..0511dad919 100644
--- a/nss/db-Makefile
+++ b/nss/db-Makefile
@@ -1,5 +1,5 @@
# Makefile to (re-)generate db versions of system database files.
-# Copyright (C) 1996-2015 Free Software Foundation, Inc.
+# Copyright (C) 1996-2016 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
#
@@ -31,7 +31,7 @@ all: $(patsubst %,$(VAR_DB)/%.db,$(notdir $(DATABASES)))
$(VAR_DB)/passwd.db: /etc/passwd
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
@@ -41,7 +41,7 @@ $(VAR_DB)/passwd.db: /etc/passwd
@echo "done."
$(VAR_DB)/group.db: /etc/group
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
@@ -63,7 +63,7 @@ $(VAR_DB)/group.db: /etc/group
@echo "done."
$(VAR_DB)/ethers.db: /etc/ethers
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
/^[^#]/ { printf ".%s ", $$1; print; \
@@ -72,7 +72,7 @@ $(VAR_DB)/ethers.db: /etc/ethers
@echo "done."
$(VAR_DB)/protocols.db: /etc/protocols
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
/^[^#]/ { printf ".%s ", $$1; print; \
@@ -83,7 +83,7 @@ $(VAR_DB)/protocols.db: /etc/protocols
@echo "done."
$(VAR_DB)/rpc.db: /etc/rpc
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) '/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
/^[^#]/ { printf ".%s ", $$1; print; \
@@ -94,7 +94,7 @@ $(VAR_DB)/rpc.db: /etc/rpc
@echo "done."
$(VAR_DB)/services.db: /etc/services
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) 'BEGIN { FS="[ \t/]+" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
@@ -110,7 +110,7 @@ $(VAR_DB)/services.db: /etc/services
@echo "done."
$(VAR_DB)/shadow.db: /etc/shadow
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
@@ -130,7 +130,7 @@ $(VAR_DB)/shadow.db: /etc/shadow
fi
$(VAR_DB)/gshadow.db: /etc/gshadow
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) 'BEGIN { FS=":"; OFS=":" } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
@@ -150,7 +150,7 @@ $(VAR_DB)/gshadow.db: /etc/gshadow
fi
$(VAR_DB)/netgroup.db: /etc/netgroup
- @echo -n "$(patsubst %.db,%,$(@F))... "
+ @printf %s "$(patsubst %.db,%,$(@F))... "
@$(AWK) 'BEGIN { ini=1 } \
/^[ \t]*$$/ { next } \
/^[ \t]*#/ { next } \
diff --git a/nss/digits_dots.c b/nss/digits_dots.c
index d4453e4f93..57f0e4db67 100644
--- a/nss/digits_dots.c
+++ b/nss/digits_dots.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by H.J. Lu <hjl@gnu.ai.mit.edu>, 1997.
diff --git a/nss/ethers-lookup.c b/nss/ethers-lookup.c
index 7faaaae6ab..a3c2b853d6 100644
--- a/nss/ethers-lookup.c
+++ b/nss/ethers-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/function.def b/nss/function.def
index e5869e3365..479613d4d6 100644
--- a/nss/function.def
+++ b/nss/function.def
@@ -1,5 +1,5 @@
/* List of functions defined for static NSS in GNU C Library.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/getXXbyYY.c b/nss/getXXbyYY.c
index 15fecf8491..f9e05fd99a 100644
--- a/nss/getXXbyYY.c
+++ b/nss/getXXbyYY.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -17,7 +17,7 @@
#include <assert.h>
#include <errno.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include <stdlib.h>
#include <resolv.h>
diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
index 198f8cfebd..113c687e06 100644
--- a/nss/getXXbyYY_r.c
+++ b/nss/getXXbyYY_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/getXXent.c b/nss/getXXent.c
index e1c796da01..654e621680 100644
--- a/nss/getXXent.c
+++ b/nss/getXXent.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -16,7 +16,7 @@
<http://www.gnu.org/licenses/>. */
#include <errno.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include <stdlib.h>
#include "nsswitch.h"
diff --git a/nss/getXXent_r.c b/nss/getXXent_r.c
index 16334581c2..97ccd0dc37 100644
--- a/nss/getXXent_r.c
+++ b/nss/getXXent_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -17,7 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <errno.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include "nsswitch.h"
diff --git a/nss/getent.c b/nss/getent.c
index 34df8487a9..de7b83ff38 100644
--- a/nss/getent.c
+++ b/nss/getent.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998-2015 Free Software Foundation, Inc.
+/* Copyright (c) 1998-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@@ -87,7 +87,7 @@ print_version (FILE *stream, struct argp_state *state)
Copyright (C) %s Free Software Foundation, Inc.\n\
This is free software; see the source for copying conditions. There is NO\n\
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "2015");
+"), "2016");
fprintf (stream, gettext ("Written by %s.\n"), "Thorsten Kukuk");
}
@@ -184,20 +184,8 @@ ethers_keys (int number, char *key[])
static void
print_group (struct group *grp)
{
- unsigned int i = 0;
-
- printf ("%s:%s:%lu:", grp->gr_name ? grp->gr_name : "",
- grp->gr_passwd ? grp->gr_passwd : "",
- (unsigned long int) grp->gr_gid);
-
- while (grp->gr_mem[i] != NULL)
- {
- fputs_unlocked (grp->gr_mem[i], stdout);
- ++i;
- if (grp->gr_mem[i] != NULL)
- putchar_unlocked (',');
- }
- putchar_unlocked ('\n');
+ if (putgrent (grp, stdout) != 0)
+ fprintf (stderr, "error writing group entry: %m\n");
}
static int
@@ -241,32 +229,8 @@ group_keys (int number, char *key[])
static void
print_gshadow (struct sgrp *sg)
{
- unsigned int i = 0;
-
- printf ("%s:%s:",
- sg->sg_namp ? sg->sg_namp : "",
- sg->sg_passwd ? sg->sg_passwd : "");
-
- while (sg->sg_adm[i] != NULL)
- {
- fputs_unlocked (sg->sg_adm[i], stdout);
- ++i;
- if (sg->sg_adm[i] != NULL)
- putchar_unlocked (',');
- }
-
- putchar_unlocked (':');
-
- i = 0;
- while (sg->sg_mem[i] != NULL)
- {
- fputs_unlocked (sg->sg_mem[i], stdout);
- ++i;
- if (sg->sg_mem[i] != NULL)
- putchar_unlocked (',');
- }
-
- putchar_unlocked ('\n');
+ if (putsgent (sg, stdout) != 0)
+ fprintf (stderr, "error writing gshadow entry: %m\n");
}
static int
@@ -603,14 +567,8 @@ networks_keys (int number, char *key[])
static void
print_passwd (struct passwd *pwd)
{
- printf ("%s:%s:%lu:%lu:%s:%s:%s\n",
- pwd->pw_name ? pwd->pw_name : "",
- pwd->pw_passwd ? pwd->pw_passwd : "",
- (unsigned long int) pwd->pw_uid,
- (unsigned long int) pwd->pw_gid,
- pwd->pw_gecos ? pwd->pw_gecos : "",
- pwd->pw_dir ? pwd->pw_dir : "",
- pwd->pw_shell ? pwd->pw_shell : "");
+ if (putpwent (pwd, stdout) != 0)
+ fprintf (stderr, "error writing passwd entry: %m\n");
}
static int
@@ -812,26 +770,8 @@ services_keys (int number, char *key[])
static void
print_shadow (struct spwd *sp)
{
- printf ("%s:%s:",
- sp->sp_namp ? sp->sp_namp : "",
- sp->sp_pwdp ? sp->sp_pwdp : "");
-
-#define SHADOW_FIELD(n) \
- if (sp->n == -1) \
- putchar_unlocked (':'); \
- else \
- printf ("%ld:", sp->n)
-
- SHADOW_FIELD (sp_lstchg);
- SHADOW_FIELD (sp_min);
- SHADOW_FIELD (sp_max);
- SHADOW_FIELD (sp_warn);
- SHADOW_FIELD (sp_inact);
- SHADOW_FIELD (sp_expire);
- if (sp->sp_flag == ~0ul)
- putchar_unlocked ('\n');
- else
- printf ("%lu\n", sp->sp_flag);
+ if (putspent (sp, stdout) != 0)
+ fprintf (stderr, "error writing shadow entry: %m\n");
}
static int
diff --git a/nss/getnssent.c b/nss/getnssent.c
index 594505bf95..efbfecadc2 100644
--- a/nss/getnssent.c
+++ b/nss/getnssent.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2015 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/getnssent_r.c b/nss/getnssent_r.c
index f5b903671c..456907b018 100644
--- a/nss/getnssent_r.c
+++ b/nss/getnssent_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2015 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/grp-lookup.c b/nss/grp-lookup.c
index 22a364bb1f..ebdd7868de 100644
--- a/nss/grp-lookup.c
+++ b/nss/grp-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/hosts-lookup.c b/nss/hosts-lookup.c
index 905b128d76..c0a935ebaa 100644
--- a/nss/hosts-lookup.c
+++ b/nss/hosts-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/key-lookup.c b/nss/key-lookup.c
index eab6a80c4d..5dfb3481c5 100644
--- a/nss/key-lookup.c
+++ b/nss/key-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/makedb.c b/nss/makedb.c
index c7b466ab43..6312920216 100644
--- a/nss/makedb.c
+++ b/nss/makedb.c
@@ -1,5 +1,5 @@
/* Create simple DB database from textual input.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -386,7 +386,7 @@ print_version (FILE *stream, struct argp_state *state)
Copyright (C) %s Free Software Foundation, Inc.\n\
This is free software; see the source for copying conditions. There is NO\n\
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "2015");
+"), "2016");
fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper");
}
@@ -415,11 +415,7 @@ valstr_compare (const void *p1, const void *p2)
static int
-process_input (input, inname, to_lowercase, be_quiet)
- FILE *input;
- const char *inname;
- int to_lowercase;
- int be_quiet;
+process_input (FILE *input, const char *inname, int to_lowercase, int be_quiet)
{
char *line;
size_t linelen;
diff --git a/nss/netgrp-lookup.c b/nss/netgrp-lookup.c
index 286f507200..79bb3cdcbf 100644
--- a/nss/netgrp-lookup.c
+++ b/nss/netgrp-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/network-lookup.c b/nss/network-lookup.c
index fef6a9f849..e5cb2780c8 100644
--- a/nss/network-lookup.c
+++ b/nss/network-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/nss.h b/nss/nss.h
index fedf5fc081..e0681b2f5c 100644
--- a/nss/nss.h
+++ b/nss/nss.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c
index 4a0766ab52..03c18d70de 100644
--- a/nss/nss_db/db-XXX.c
+++ b/nss/nss_db/db-XXX.c
@@ -1,5 +1,5 @@
/* Common code for DB-based databases in nss_db module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -20,7 +20,7 @@
#include <fcntl.h>
#include <stdint.h>
#include <sys/mman.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include "nsswitch.h"
#include "nss_db.h"
diff --git a/nss/nss_db/db-init.c b/nss/nss_db/db-init.c
index 099d89b1f8..87ff025a83 100644
--- a/nss/nss_db/db-init.c
+++ b/nss/nss_db/db-init.c
@@ -1,5 +1,5 @@
/* Initialization in nss_db module.
- Copyright (C) 2011-2015 Free Software Foundation, Inc.
+ Copyright (C) 2011-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_db/db-initgroups.c b/nss/nss_db/db-initgroups.c
index d182fc4f42..2cf6b8f112 100644
--- a/nss/nss_db/db-initgroups.c
+++ b/nss/nss_db/db-initgroups.c
@@ -1,5 +1,5 @@
/* Initgroups handling in nss_db module.
- Copyright (C) 2011-2015 Free Software Foundation, Inc.
+ Copyright (C) 2011-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gmail.com>.
diff --git a/nss/nss_db/db-netgrp.c b/nss/nss_db/db-netgrp.c
index 94d6adac68..1ea6519e11 100644
--- a/nss/nss_db/db-netgrp.c
+++ b/nss/nss_db/db-netgrp.c
@@ -1,5 +1,5 @@
/* Netgroup file parser in nss_db modules.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -24,7 +24,7 @@
#include <netgroup.h>
#include <string.h>
#include <stdint.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include <paths.h>
#include <stdlib.h>
diff --git a/nss/nss_db/db-open.c b/nss/nss_db/db-open.c
index c482232b3c..d54d6fe52b 100644
--- a/nss/nss_db/db-open.c
+++ b/nss/nss_db/db-open.c
@@ -1,5 +1,5 @@
/* Common database routines for nss_db.
- Copyright (C) 2000-2015 Free Software Foundation, Inc.
+ Copyright (C) 2000-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_db/nss_db.h b/nss/nss_db/nss_db.h
index 4af2229ac1..8a16ca9a27 100644
--- a/nss/nss_db/nss_db.h
+++ b/nss/nss_db/nss_db.h
@@ -1,5 +1,5 @@
/* Common database open/close routines for nss_db.
- Copyright (C) 1999-2015 Free Software Foundation, Inc.
+ Copyright (C) 1999-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -21,7 +21,7 @@
#include <nss.h>
#include <stdint.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
/* String table index type. */
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
index f002f431e5..3215393ff1 100644
--- a/nss/nss_files/files-XXX.c
+++ b/nss/nss_files/files-XXX.c
@@ -1,5 +1,5 @@
/* Common code for file-based databases in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -20,7 +20,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include "nsswitch.h"
#include <kernel-features.h>
diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
index 071c01d158..94872b7569 100644
--- a/nss/nss_files/files-alias.c
+++ b/nss/nss_files/files-alias.c
@@ -1,5 +1,5 @@
/* Mail alias file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -21,7 +21,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/nss/nss_files/files-ethers.c b/nss/nss_files/files-ethers.c
index 47fa7843fd..57104f07c8 100644
--- a/nss/nss_files/files-ethers.c
+++ b/nss/nss_files/files-ethers.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-grp.c b/nss/nss_files/files-grp.c
index 42155bc2e3..29d1e5e40a 100644
--- a/nss/nss_files/files-grp.c
+++ b/nss/nss_files/files-grp.c
@@ -1,5 +1,5 @@
/* Group file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-have_o_cloexec.c b/nss/nss_files/files-have_o_cloexec.c
index 0b61a44859..30f79ac40c 100644
--- a/nss/nss_files/files-have_o_cloexec.c
+++ b/nss/nss_files/files-have_o_cloexec.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2015 Free Software Foundation, Inc.
+/* Copyright (C) 2007-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
index 4117458c92..2a4a665d7e 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -1,5 +1,5 @@
/* Hosts file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-init.c b/nss/nss_files/files-init.c
index 72eced41bf..9d465292ae 100644
--- a/nss/nss_files/files-init.c
+++ b/nss/nss_files/files-init.c
@@ -1,5 +1,5 @@
/* Initialization in nss_files module.
- Copyright (C) 2011-2015 Free Software Foundation, Inc.
+ Copyright (C) 2011-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-initgroups.c b/nss/nss_files/files-initgroups.c
index 084d36be8a..6e0d8258da 100644
--- a/nss/nss_files/files-initgroups.c
+++ b/nss/nss_files/files-initgroups.c
@@ -1,5 +1,5 @@
/* Initgroups handling in nss_files module.
- Copyright (C) 2011-2015 Free Software Foundation, Inc.
+ Copyright (C) 2011-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-key.c b/nss/nss_files/files-key.c
index 2d64744b2d..5af7ea2dd0 100644
--- a/nss/nss_files/files-key.c
+++ b/nss/nss_files/files-key.c
@@ -1,5 +1,5 @@
/* Public key file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-netgrp.c b/nss/nss_files/files-netgrp.c
index 8886c2625a..a1c46b3ca9 100644
--- a/nss/nss_files/files-netgrp.c
+++ b/nss/nss_files/files-netgrp.c
@@ -1,5 +1,5 @@
/* Netgroup file parser in nss_files modules.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c
index 46e99451a1..8c95ed5286 100644
--- a/nss/nss_files/files-network.c
+++ b/nss/nss_files/files-network.c
@@ -1,5 +1,5 @@
/* Networks file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c
index 9911633013..36487541f1 100644
--- a/nss/nss_files/files-parse.c
+++ b/nss/nss_files/files-parse.c
@@ -1,5 +1,5 @@
/* Common code for file-based database parsers in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-proto.c b/nss/nss_files/files-proto.c
index 370266a04c..90a85f07c4 100644
--- a/nss/nss_files/files-proto.c
+++ b/nss/nss_files/files-proto.c
@@ -1,5 +1,5 @@
/* Protocols file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-pwd.c b/nss/nss_files/files-pwd.c
index 84ce5bb1fb..823e58ad06 100644
--- a/nss/nss_files/files-pwd.c
+++ b/nss/nss_files/files-pwd.c
@@ -1,5 +1,5 @@
/* User file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-rpc.c b/nss/nss_files/files-rpc.c
index 34f6aec690..5b9a91f058 100644
--- a/nss/nss_files/files-rpc.c
+++ b/nss/nss_files/files-rpc.c
@@ -1,5 +1,5 @@
/* SunRPC program number file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-service.c b/nss/nss_files/files-service.c
index 7fccbdbdbd..7a6e2266d1 100644
--- a/nss/nss_files/files-service.c
+++ b/nss/nss_files/files-service.c
@@ -1,5 +1,5 @@
/* Services file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-sgrp.c b/nss/nss_files/files-sgrp.c
index ac74324d70..15dc65964c 100644
--- a/nss/nss_files/files-sgrp.c
+++ b/nss/nss_files/files-sgrp.c
@@ -1,5 +1,5 @@
/* User file parser in nss_files module.
- Copyright (C) 2009-2015 Free Software Foundation, Inc.
+ Copyright (C) 2009-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nss_files/files-spwd.c b/nss/nss_files/files-spwd.c
index a255454fd4..652dc1394a 100644
--- a/nss/nss_files/files-spwd.c
+++ b/nss/nss_files/files-spwd.c
@@ -1,5 +1,5 @@
/* User file parser in nss_files module.
- Copyright (C) 1996-2015 Free Software Foundation, Inc.
+ Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index 9712623157..bb644cb373 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -20,7 +20,7 @@
#include <dlfcn.h>
#include <errno.h>
#include <netdb.h>
-#include <bits/libc-lock.h>
+#include <libc-lock.h>
#include <search.h>
#include <stdio.h>
#include <stdio_ext.h>
diff --git a/nss/nsswitch.h b/nss/nsswitch.h
index a5318fa82b..0074ee1d65 100644
--- a/nss/nsswitch.h
+++ b/nss/nsswitch.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/proto-lookup.c b/nss/proto-lookup.c
index f4a9781366..7c72db6ad0 100644
--- a/nss/proto-lookup.c
+++ b/nss/proto-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/pwd-lookup.c b/nss/pwd-lookup.c
index f9f58d0a03..b1b3d5d084 100644
--- a/nss/pwd-lookup.c
+++ b/nss/pwd-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/rewrite_field.c b/nss/rewrite_field.c
new file mode 100644
index 0000000000..6be16ebe67
--- /dev/null
+++ b/nss/rewrite_field.c
@@ -0,0 +1,52 @@
+/* Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <nss.h>
+#include <string.h>
+
+/* Rewrite VALUE to a valid field value in the NSS database. Invalid
+ characters are replaced with a single space character ' '. If
+ VALUE is NULL, the empty string is returned. *TO_BE_FREED is
+ overwritten with a pointer the caller has to free if the function
+ returns successfully. On failure, return NULL. */
+const char *
+internal_function
+__nss_rewrite_field (const char *value, char **to_be_freed)
+{
+ *to_be_freed = NULL;
+ if (value == NULL)
+ return "";
+
+ /* Search for non-allowed characters. */
+ const char *p = strpbrk (value, __nss_invalid_field_characters);
+ if (p == NULL)
+ return value;
+ *to_be_freed = __strdup (value);
+ if (*to_be_freed == NULL)
+ return NULL;
+
+ /* Switch pointer to freshly-allocated buffer. */
+ char *bad = *to_be_freed + (p - value);
+ do
+ {
+ *bad = ' ';
+ bad = strpbrk (bad + 1, __nss_invalid_field_characters);
+ }
+ while (bad != NULL);
+
+ return *to_be_freed;
+}
diff --git a/nss/rpc-lookup.c b/nss/rpc-lookup.c
index ad0312d4f8..84d422d1dc 100644
--- a/nss/rpc-lookup.c
+++ b/nss/rpc-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/service-lookup.c b/nss/service-lookup.c
index 6462832ec6..6d308bd61f 100644
--- a/nss/service-lookup.c
+++ b/nss/service-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/sgrp-lookup.c b/nss/sgrp-lookup.c
index a384a4e307..aa9c29b536 100644
--- a/nss/sgrp-lookup.c
+++ b/nss/sgrp-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2009-2015 Free Software Foundation, Inc.
+/* Copyright (C) 2009-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2009.
diff --git a/nss/spwd-lookup.c b/nss/spwd-lookup.c
index 3074e91f2c..e7d305e51b 100644
--- a/nss/spwd-lookup.c
+++ b/nss/spwd-lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
diff --git a/nss/test-digits-dots.c b/nss/test-digits-dots.c
index 98202fc40a..e3bf5e2099 100644
--- a/nss/test-digits-dots.c
+++ b/nss/test-digits-dots.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2013-2015 Free Software Foundation, Inc.
+/* Copyright (C) 2013-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/test-netdb.c b/nss/test-netdb.c
index 7088549311..e198e1665a 100644
--- a/nss/test-netdb.c
+++ b/nss/test-netdb.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Andreas Jaeger <aj@suse.de>, 1998.
diff --git a/nss/tst-field.c b/nss/tst-field.c
new file mode 100644
index 0000000000..1418b068bc
--- /dev/null
+++ b/nss/tst-field.c
@@ -0,0 +1,101 @@
+/* Test for invalid field handling in file-style NSS databases. [BZ #18724]
+ Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* This test needs to be statically linked because it access hidden
+ functions. */
+
+#include <nss.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static bool errors;
+
+static void
+check (const char *what, bool expr)
+{
+ if (!expr)
+ {
+ printf ("FAIL: %s\n", what);
+ errors = true;
+ }
+}
+
+#define CHECK(expr) check (#expr, (expr))
+
+static void
+check_rewrite (const char *input, const char *expected)
+{
+ char *to_free;
+ const char *result = __nss_rewrite_field (input, &to_free);
+ CHECK (result != NULL);
+ if (result != NULL && strcmp (result, expected) != 0)
+ {
+ printf ("FAIL: rewrite \"%s\" -> \"%s\", expected \"%s\"\n",
+ input, result, expected);
+ errors = true;
+ }
+ free (to_free);
+}
+
+static int
+do_test (void)
+{
+ CHECK (__nss_valid_field (NULL));
+ CHECK (__nss_valid_field (""));
+ CHECK (__nss_valid_field ("+"));
+ CHECK (__nss_valid_field ("-"));
+ CHECK (__nss_valid_field (" "));
+ CHECK (__nss_valid_field ("abcdef"));
+ CHECK (__nss_valid_field ("abc def"));
+ CHECK (__nss_valid_field ("abc\tdef"));
+ CHECK (!__nss_valid_field ("abcdef:"));
+ CHECK (!__nss_valid_field ("abcde:f"));
+ CHECK (!__nss_valid_field (":abcdef"));
+ CHECK (!__nss_valid_field ("abcdef\n"));
+ CHECK (!__nss_valid_field ("\nabcdef"));
+ CHECK (!__nss_valid_field (":"));
+ CHECK (!__nss_valid_field ("\n"));
+
+ CHECK (__nss_valid_list_field (NULL));
+ CHECK (__nss_valid_list_field ((char *[]) {(char *) "good", NULL}));
+ CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g,ood", NULL}));
+ CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g\nood", NULL}));
+ CHECK (!__nss_valid_list_field ((char *[]) {(char *) "g:ood", NULL}));
+
+ check_rewrite (NULL, "");
+ check_rewrite ("", "");
+ check_rewrite ("abc", "abc");
+ check_rewrite ("abc\n", "abc ");
+ check_rewrite ("abc:", "abc ");
+ check_rewrite ("\nabc", " abc");
+ check_rewrite (":abc", " abc");
+ check_rewrite (":", " ");
+ check_rewrite ("\n", " ");
+ check_rewrite ("a:b:c", "a b c");
+ check_rewrite ("a\nb\nc", "a b c");
+ check_rewrite ("a\nb:c", "a b c");
+ check_rewrite ("aa\nbb\ncc", "aa bb cc");
+ check_rewrite ("aa\nbb:cc", "aa bb cc");
+
+ return errors;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/nss/tst-nss-getpwent.c b/nss/tst-nss-getpwent.c
index f2e8abce60..e8c13b14b4 100644
--- a/nss/tst-nss-getpwent.c
+++ b/nss/tst-nss-getpwent.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2015 Free Software Foundation, Inc.
+/* Copyright (C) 2015-2016 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
diff --git a/nss/valid_field.c b/nss/valid_field.c
new file mode 100644
index 0000000000..de239434ae
--- /dev/null
+++ b/nss/valid_field.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <nss.h>
+#include <string.h>
+
+const char __nss_invalid_field_characters[] = NSS_INVALID_FIELD_CHARACTERS;
+
+/* Check that VALUE is either NULL or a NUL-terminated string which
+ does not contain characters not permitted in NSS database
+ fields. */
+_Bool
+internal_function
+__nss_valid_field (const char *value)
+{
+ return value == NULL
+ || strpbrk (value, __nss_invalid_field_characters) == NULL;
+}
diff --git a/nss/valid_list_field.c b/nss/valid_list_field.c
new file mode 100644
index 0000000000..e5c55ef015
--- /dev/null
+++ b/nss/valid_list_field.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 2015-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <nss.h>
+#include <stdbool.h>
+#include <string.h>
+
+static const char invalid_characters[] = NSS_INVALID_FIELD_CHARACTERS ",";
+
+/* Check that all list members match the field syntax requirements and
+ do not contain the character ','. */
+_Bool
+internal_function
+__nss_valid_list_field (char **list)
+{
+ if (list == NULL)
+ return true;
+ for (; *list != NULL; ++list)
+ if (strpbrk (*list, invalid_characters) != NULL)
+ return false;
+ return true;
+}