summaryrefslogtreecommitdiff
path: root/nss
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
committerJakub Jelinek <jakub@redhat.com>2007-07-12 18:26:36 +0000
commit0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch)
tree2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /nss
parent7d58530341304d403a6626d7f7a1913165fe2f32 (diff)
downloadglibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.gz
2.5-18.1
Diffstat (limited to 'nss')
-rw-r--r--nss/databases.def5
-rw-r--r--nss/function.def3
-rw-r--r--nss/getXXbyYY_r.c11
-rw-r--r--nss/getent.c86
-rw-r--r--nss/nss_files/files-alias.c6
-rw-r--r--nss/nss_files/files-hosts.c10
-rw-r--r--nss/nss_files/files-key.c3
-rw-r--r--nss/nss_files/files-netgrp.c26
-rw-r--r--nss/nsswitch.c11
9 files changed, 94 insertions, 67 deletions
diff --git a/nss/databases.def b/nss/databases.def
index 27c15fc04f..c35d7f18c2 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, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -18,7 +18,8 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-/* This list must be kept sorted!!! */
+/* This list must be kept sorted!!! If any long name is added the
+ field size for it must be increases. */
DEFINE_DATABASE (aliases)
DEFINE_DATABASE (ethers)
diff --git a/nss/function.def b/nss/function.def
index 59a06a2d31..505fb9307f 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, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 2005 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
@@ -37,6 +37,7 @@ DEFINE_GET (files, grnam)
DEFINE_ENT (files, host)
DEFINE_GETBY (files, host, addr)
DEFINE_GETBY (files, host, name)
+DEFINE_GETBY (files, host, name2)
DEFINE_GET (files, hostton)
DEFINE_GET (files, ntohost)
DEFINE_GETBY (dns, host, addr)
diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
index 34c305f3b2..080163aac9 100644
--- a/nss/getXXbyYY_r.c
+++ b/nss/getXXbyYY_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2002, 2003, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -18,6 +18,7 @@
02111-1307 USA. */
#include <assert.h>
+#include <atomic.h>
#include <errno.h>
#include <stdbool.h>
#include "nsswitch.h"
@@ -173,9 +174,6 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
startp = (service_user *) -1l;
else
{
- startp = nip;
- start_fct = fct.l;
-
#ifdef NEED__RES
/* The resolver code will really be used so we have to
initialize it. */
@@ -190,6 +188,11 @@ INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
if (!_res_hconf.initialized)
_res_hconf_init ();
#endif /* need _res_hconf */
+
+ start_fct = fct.l;
+ /* Make sure start_fct is written before startp. */
+ atomic_write_barrier ();
+ startp = nip;
}
}
else
diff --git a/nss/getent.c b/nss/getent.c
index c0a273241f..14ec3c4755 100644
--- a/nss/getent.c
+++ b/nss/getent.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998-2003, 2004 Free Software Foundation, Inc.
+/* Copyright (c) 1998-2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@@ -21,22 +21,23 @@
#include <aliases.h>
#include <argp.h>
-#include <grp.h>
-#include <pwd.h>
-#include <shadow.h>
#include <ctype.h>
#include <error.h>
+#include <grp.h>
#include <libintl.h>
#include <locale.h>
+#include <mcheck.h>
#include <netdb.h>
+#include <pwd.h>
+#include <shadow.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/ether.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
+#include <netinet/ether.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
/* Get libc version number. */
#include <version.h>
@@ -83,7 +84,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\
-"), "2004");
+"), "2006");
fprintf (stream, gettext ("Written by %s.\n"), "Thorsten Kukuk");
}
@@ -279,9 +280,9 @@ hosts_keys (int number, char *key[])
char addr[IN6ADDRSZ];
if (inet_pton (AF_INET6, key[i], &addr) > 0)
- host = gethostbyaddr (addr, sizeof (addr), AF_INET6);
+ host = gethostbyaddr (addr, IN6ADDRSZ, AF_INET6);
else if (inet_pton (AF_INET, key[i], &addr) > 0)
- host = gethostbyaddr (addr, sizeof (addr), AF_INET);
+ host = gethostbyaddr (addr, INADDRSZ, AF_INET);
else if ((host = gethostbyname2 (key[i], AF_INET6)) == NULL)
host = gethostbyname2 (key[i], AF_INET);
@@ -410,6 +411,8 @@ netgroup_keys (int number, char *key[])
}
}
+ endnetgrent ();
+
return result;
}
@@ -757,12 +760,27 @@ D(shadow)
static error_t
parse_option (int key, char *arg, struct argp_state *state)
{
- int i;
+ char *endp;
switch (key)
{
case 's':
- for (i = 0; databases[i].name; ++i)
- __nss_configure_lookup (databases[i].name, arg);
+ endp = strchr (arg, ':');
+ if (endp == NULL)
+ /* No specific database, change them all. */
+ for (int i = 0; databases[i].name != NULL; ++i)
+ __nss_configure_lookup (databases[i].name, arg);
+ else
+ {
+ int i;
+ for (i = 0; databases[i].name != NULL; ++i)
+ if (strncmp (databases[i].name, arg, endp - arg) == 0)
+ {
+ __nss_configure_lookup (databases[i].name, endp + 1);
+ break;
+ }
+ if (databases[i].name == NULL)
+ error (EXIT_FAILURE, 0, gettext ("Unknown database name"));
+ }
break;
default:
@@ -776,31 +794,20 @@ parse_option (int key, char *arg, struct argp_state *state)
static char *
more_help (int key, const char *text, void *input)
{
- int len;
- char *long_doc, *doc, *p;
-
switch (key)
{
+ size_t len;
+ char *doc;
+ FILE *fp;
+
case ARGP_KEY_HELP_EXTRA:
/* We print some extra information. */
-#if 0
- return xstrdup (gettext ("\
-For bug reporting instructions, please see:\n\
-<http://www.gnu.org/software/libc/bugs.html>.\n"));
-#endif
- long_doc = _("Supported databases:");
- len = strlen (long_doc) + 2;
-
- for (int i = 0; databases[i].name; ++i)
- len += strlen (databases[i].name) + 1;
-
- doc = (char *) malloc (len);
- if (doc != NULL)
+ fp = open_memstream (&doc, &len);
+ if (fp != NULL)
{
- p = stpcpy (doc, long_doc);
- *p++ = '\n';
+ fputs_unlocked (_("Supported databases:\n"), fp);
- for (int i = 0, col = 0; databases[i].name; ++i)
+ for (int i = 0, col = 0; databases[i].name != NULL; ++i)
{
len = strlen (databases[i].name);
if (i != 0)
@@ -808,17 +815,18 @@ For bug reporting instructions, please see:\n\
if (col + len > 72)
{
col = 0;
- *p++ = '\n';
+ fputc_unlocked ('\n', fp);
}
else
- *p++ = ' ';
+ fputc_unlocked (' ', fp);
}
- p = mempcpy (p, databases[i].name, len);
+ fputs_unlocked (databases[i].name, fp);
col += len + 1;
}
- return doc;
+ if (fclose (fp) == 0)
+ return doc;
}
break;
@@ -833,7 +841,8 @@ For bug reporting instructions, please see:\n\
int
main (int argc, char *argv[])
{
- int remaining, i;
+ /* Debugging support. */
+ mtrace ();
/* Set locale via LC_ALL. */
setlocale (LC_ALL, "");
@@ -841,6 +850,7 @@ main (int argc, char *argv[])
textdomain (PACKAGE);
/* Parse and process arguments. */
+ int remaining;
argp_parse (&argp, argc, argv, 0, &remaining, NULL);
if ((argc - remaining) < 1)
@@ -850,7 +860,7 @@ main (int argc, char *argv[])
return 1;
}
- for (i = 0; databases[i].name; ++i)
+ for (int i = 0; databases[i].name; ++i)
if (argv[remaining][0] == databases[i].name[0]
&& !strcmp (argv[remaining], databases[i].name))
return databases[i].func (argc - remaining - 1, &argv[remaining + 1]);
diff --git a/nss/nss_files/files-alias.c b/nss/nss_files/files-alias.c
index 8ee54f121f..c4717e1242 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,97,98,99,2002 Free Software Foundation, Inc.
+ Copyright (C) 1996,97,98,99,2002,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -298,8 +298,8 @@ get_next_alias (const char *match, struct aliasent *result,
first_unused[room_left - 1] = '\0';
strncpy (first_unused, old_line, room_left);
- if (old_line != NULL)
- free (old_line);
+ free (old_line);
+ line = first_unused;
if (first_unused[room_left - 1] != '\0')
goto no_more_room;
diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
index 8d1a8ee588..b1ba3aa76d 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -1,5 +1,6 @@
/* Hosts file parser in nss_files module.
- Copyright (C) 1996-2001, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1996-2001, 2003, 2004, 2007
+ 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
@@ -86,6 +87,10 @@ _nss_files_get##name##_r (proto, \
{ \
enum nss_status status; \
\
+ uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct hostent_data); \
+ buffer += pad; \
+ buflen = buflen > pad ? buflen - pad : 0; \
+ \
__libc_lock_lock (lock); \
\
/* Reset file pointer to beginning or open file. */ \
@@ -106,7 +111,8 @@ _nss_files_get##name##_r (proto, \
{ \
/* We have to get all host entries from the file. */ \
const size_t tmp_buflen = MIN (buflen, 4096); \
- char tmp_buffer[tmp_buflen]; \
+ char tmp_buffer[tmp_buflen] \
+ __attribute__ ((__aligned__ (__alignof__ (struct hostent_data))));\
struct hostent tmp_result_buf; \
int naddrs = 1; \
int naliases = 0; \
diff --git a/nss/nss_files/files-key.c b/nss/nss_files/files-key.c
index f00fc1cfe9..5c7ad0999a 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, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 2006 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
@@ -78,6 +78,7 @@ search (const char *netname, char *result, int *errnop, int secret)
p = __strtok_r (NULL, ":\n", &save_ptr);
if (p == NULL) /* malformed line? */
continue;
+ fclose (stream);
strcpy (result, p);
return NSS_STATUS_SUCCESS;
}
diff --git a/nss/nss_files/files-netgrp.c b/nss/nss_files/files-netgrp.c
index 8bdc68bd14..4b5d774fdd 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, 1997, 2000, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 2000, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -22,6 +22,7 @@
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include "nsswitch.h"
@@ -29,6 +30,7 @@
#define DATAFILE "/etc/netgroup"
+libnss_files_hidden_proto (_nss_files_endnetgrent)
#define EXPAND(needed) \
do \
@@ -75,7 +77,9 @@ _nss_files_setnetgrent (const char *group, struct __netgrent *result)
status = NSS_STATUS_NOTFOUND;
result->cursor = result->data;
- while (!feof (fp))
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
+ while (!feof_unlocked (fp))
{
ssize_t curlen = getline (&line, &line_len, fp);
int found;
@@ -140,26 +144,26 @@ _nss_files_setnetgrent (const char *group, struct __netgrent *result)
/* We don't need the file and the line buffer anymore. */
free (line);
fclose (fp);
+
+ if (status != NSS_STATUS_SUCCESS)
+ _nss_files_endnetgrent (result);
}
return status;
}
-int
+enum nss_status
_nss_files_endnetgrent (struct __netgrent *result)
{
/* Free allocated memory for data if some is present. */
- if (result->data != NULL)
- {
- free (result->data);
- result->data = NULL;
- result->data_size = 0;
- result->cursor = NULL;
- }
-
+ free (result->data);
+ result->data = NULL;
+ result->data_size = 0;
+ result->cursor = NULL;
return NSS_STATUS_SUCCESS;
}
+libnss_files_hidden_def (_nss_files_endnetgrent)
static char *
strip_whitespace (char *str)
diff --git a/nss/nsswitch.c b/nss/nsswitch.c
index 895b17825a..21174dfbab 100644
--- a/nss/nsswitch.c
+++ b/nss/nsswitch.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004
+/* Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -59,9 +59,9 @@ static service_library *nss_new_service (name_database *database,
#undef DEFINE_DATABASE
/* Structure to map database name to variable. */
-static struct
+static const struct
{
- const char *name;
+ const char name[10];
service_user **dbp;
} databases[] =
{
@@ -70,6 +70,7 @@ static struct
#include "databases.def"
#undef DEFINE_DATABASE
};
+#define ndatabases (sizeof (databases) / sizeof (databases[0]))
__libc_lock_define_initialized (static, lock)
@@ -211,7 +212,7 @@ __nss_configure_lookup (const char *dbname, const char *service_line)
service_user *new_db;
size_t cnt;
- for (cnt = 0; cnt < sizeof databases; ++cnt)
+ for (cnt = 0; cnt < ndatabases; ++cnt)
{
int cmp = strcmp (dbname, databases[cnt].name);
if (cmp == 0)
@@ -223,7 +224,7 @@ __nss_configure_lookup (const char *dbname, const char *service_line)
}
}
- if (cnt == sizeof databases)
+ if (cnt == ndatabases)
{
__set_errno (EINVAL);
return -1;