summaryrefslogtreecommitdiff
path: root/nss/getent.c
diff options
context:
space:
mode:
Diffstat (limited to 'nss/getent.c')
-rw-r--r--nss/getent.c86
1 files changed, 38 insertions, 48 deletions
diff --git a/nss/getent.c b/nss/getent.c
index 14ec3c4755..c0a273241f 100644
--- a/nss/getent.c
+++ b/nss/getent.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998-2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1998-2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@@ -21,23 +21,22 @@
#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>
@@ -84,7 +83,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\
-"), "2006");
+"), "2004");
fprintf (stream, gettext ("Written by %s.\n"), "Thorsten Kukuk");
}
@@ -280,9 +279,9 @@ hosts_keys (int number, char *key[])
char addr[IN6ADDRSZ];
if (inet_pton (AF_INET6, key[i], &addr) > 0)
- host = gethostbyaddr (addr, IN6ADDRSZ, AF_INET6);
+ host = gethostbyaddr (addr, sizeof (addr), AF_INET6);
else if (inet_pton (AF_INET, key[i], &addr) > 0)
- host = gethostbyaddr (addr, INADDRSZ, AF_INET);
+ host = gethostbyaddr (addr, sizeof (addr), AF_INET);
else if ((host = gethostbyname2 (key[i], AF_INET6)) == NULL)
host = gethostbyname2 (key[i], AF_INET);
@@ -411,8 +410,6 @@ netgroup_keys (int number, char *key[])
}
}
- endnetgrent ();
-
return result;
}
@@ -760,27 +757,12 @@ D(shadow)
static error_t
parse_option (int key, char *arg, struct argp_state *state)
{
- char *endp;
+ int i;
switch (key)
{
case 's':
- 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"));
- }
+ for (i = 0; databases[i].name; ++i)
+ __nss_configure_lookup (databases[i].name, arg);
break;
default:
@@ -794,20 +776,31 @@ 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. */
- fp = open_memstream (&doc, &len);
- if (fp != NULL)
+#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)
{
- fputs_unlocked (_("Supported databases:\n"), fp);
+ p = stpcpy (doc, long_doc);
+ *p++ = '\n';
- for (int i = 0, col = 0; databases[i].name != NULL; ++i)
+ for (int i = 0, col = 0; databases[i].name; ++i)
{
len = strlen (databases[i].name);
if (i != 0)
@@ -815,18 +808,17 @@ more_help (int key, const char *text, void *input)
if (col + len > 72)
{
col = 0;
- fputc_unlocked ('\n', fp);
+ *p++ = '\n';
}
else
- fputc_unlocked (' ', fp);
+ *p++ = ' ';
}
- fputs_unlocked (databases[i].name, fp);
+ p = mempcpy (p, databases[i].name, len);
col += len + 1;
}
- if (fclose (fp) == 0)
- return doc;
+ return doc;
}
break;
@@ -841,8 +833,7 @@ more_help (int key, const char *text, void *input)
int
main (int argc, char *argv[])
{
- /* Debugging support. */
- mtrace ();
+ int remaining, i;
/* Set locale via LC_ALL. */
setlocale (LC_ALL, "");
@@ -850,7 +841,6 @@ 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)
@@ -860,7 +850,7 @@ main (int argc, char *argv[])
return 1;
}
- for (int i = 0; databases[i].name; ++i)
+ for (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]);