aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-09-10 03:20:33 +0000
committerUlrich Drepper <drepper@redhat.com>2005-09-10 03:20:33 +0000
commitff3cacc50c42290ff76922257247c95f27fa3736 (patch)
tree3763ebc50123e2cf7d51090539c2073125cc0014
parent[BZ #1318] (diff)
downloadglibc-ff3cacc50c42290ff76922257247c95f27fa3736.tar.gz
glibc-ff3cacc50c42290ff76922257247c95f27fa3736.tar.bz2
glibc-ff3cacc50c42290ff76922257247c95f27fa3736.zip
* inet/getnetgrent_r.c: Include assert.cvs/fedora-glibc-20050912T0656
(setup): Remove FUNC_NAME and ALL arguments, assume they are always "setnetgrent" and 1. (endnetgrent_hook): New function. (internal_endnetgrent): Use it. (__internal_setnetgrent_reuse): Use it. Adjust setup caller. If status is NSS_STATUS_SUCCESS, yet action is continue, call endnetgrent hook. (internal_getnetgrent_r): Use __nss_lookup_function rather than setup. Recompute getfct pointer after successful __internal_setnetgrent_reuse. Don't use __nss_next. (innetgr): Use __nss_lookup_function instead of __nss_lookup. Adjust setup caller. * nss/nss_files/files-netgrp.c (_nss_files_endnetgrent): Always clear data_size and cursor. Add libnss_files_hidden_proto and libnss_files_hidden_def. (_nss_files_setnetgrent): Call _nss_files_endnetgrent on failure. * nis/nss_nis/nis-netgrp.c (internal_endnetgrent): Always clear data_size and cursor. (_nss_nis_setnetgrent): Don't call internal_endnetgrent. (_nss_nis_getnetgrent_r): Remove result->cursor == NULL handling. * nis/nss_nisplus/nisplus-netgrp.c (internal_endnetgrent): Always clear data_size and position. (_nss_nisplus_setnetgrent): Don't call internal_endnetgrent. 2005-09-09 Ulrich Drepper <drepper@redhat.com> * nss/getent.c (netgroup_keys): Call endnetgrent. (main): Call mtrace. * nss/nss_files/files-netgrp.c (_nss_files_setnetgrent): We don't need locking for the stream. Use feof_unlocked. 2005-09-09 Jakub Jelinek <jakub@redhat.com>
-rw-r--r--ChangeLog35
-rw-r--r--inet/getnetgrent_r.c125
-rw-r--r--nis/nss_nis/nis-netgrp.c16
-rw-r--r--nis/nss_nisplus/nisplus-netgrp.c15
-rw-r--r--nss/getent.c21
-rw-r--r--nss/nss_files/files-netgrp.c24
6 files changed, 136 insertions, 100 deletions
diff --git a/ChangeLog b/ChangeLog
index 76357f0b9b..47ced660ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,40 @@
2005-09-09 Jakub Jelinek <jakub@redhat.com>
+ * inet/getnetgrent_r.c: Include assert.
+ (setup): Remove FUNC_NAME and ALL arguments, assume they are always
+ "setnetgrent" and 1.
+ (endnetgrent_hook): New function.
+ (internal_endnetgrent): Use it.
+ (__internal_setnetgrent_reuse): Use it. Adjust setup caller.
+ If status is NSS_STATUS_SUCCESS, yet action is continue, call
+ endnetgrent hook.
+ (internal_getnetgrent_r): Use __nss_lookup_function rather than
+ setup. Recompute getfct pointer after successful
+ __internal_setnetgrent_reuse. Don't use __nss_next.
+ (innetgr): Use __nss_lookup_function instead of __nss_lookup.
+ Adjust setup caller.
+ * nss/nss_files/files-netgrp.c (_nss_files_endnetgrent): Always clear
+ data_size and cursor. Add libnss_files_hidden_proto and
+ libnss_files_hidden_def.
+ (_nss_files_setnetgrent): Call _nss_files_endnetgrent on failure.
+ * nis/nss_nis/nis-netgrp.c (internal_endnetgrent): Always clear
+ data_size and cursor.
+ (_nss_nis_setnetgrent): Don't call internal_endnetgrent.
+ (_nss_nis_getnetgrent_r): Remove result->cursor == NULL handling.
+ * nis/nss_nisplus/nisplus-netgrp.c (internal_endnetgrent): Always clear
+ data_size and position.
+ (_nss_nisplus_setnetgrent): Don't call internal_endnetgrent.
+
+2005-09-09 Ulrich Drepper <drepper@redhat.com>
+
+ * nss/getent.c (netgroup_keys): Call endnetgrent.
+ (main): Call mtrace.
+
+ * nss/nss_files/files-netgrp.c (_nss_files_setnetgrent): We don't
+ need locking for the stream. Use feof_unlocked.
+
+2005-09-09 Jakub Jelinek <jakub@redhat.com>
+
[BZ #1318]
* locale/loadarchive.c (_nl_load_locale_from_archive): Free
normalized_codeset even if p was already normalized.
diff --git a/inet/getnetgrent_r.c b/inet/getnetgrent_r.c
index 640210ab2e..4dbccd94ea 100644
--- a/inet/getnetgrent_r.c
+++ b/inet/getnetgrent_r.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1996,1997,1998,1999,2002,2004 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 1999, 2002, 2004, 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
@@ -16,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <assert.h>
#include <bits/libc-lock.h>
#include <errno.h>
#include <netdb.h>
@@ -33,15 +35,13 @@ __libc_lock_define_initialized (static, lock)
static struct __netgrent dataset;
/* The lookup function for the first entry of this service. */
-extern int __nss_netgroup_lookup (service_user **nip, const char *name,
+extern int __nss_netgroup_lookup (service_user **nipp, const char *name,
void **fctp) internal_function;
-
-/* Set up NIP to run through the services. If ALL is zero, use NIP's
- current location if it's not nil. Return nonzero if there are no
+/* Set up NIP to run through the services. Return nonzero if there are no
services (left). */
-static enum nss_status
-setup (void **fctp, const char *func_name, int all, service_user **nipp)
+static int
+setup (void **fctp, service_user **nipp)
{
/* Remember the first service_entry, it's always the same. */
static service_user *startp;
@@ -51,7 +51,7 @@ setup (void **fctp, const char *func_name, int all, service_user **nipp)
{
/* Executing this more than once at the same time must yield the
same result every time. So we need no locking. */
- no_more = __nss_netgroup_lookup (nipp, func_name, fctp);
+ no_more = __nss_netgroup_lookup (nipp, "setnetgrent", fctp);
startp = no_more ? (service_user *) -1 : *nipp;
}
else if (startp == (service_user *) -1)
@@ -59,11 +59,10 @@ setup (void **fctp, const char *func_name, int all, service_user **nipp)
return 1;
else
{
- if (all || *nipp == NULL)
- /* Reset to the beginning of the service list. */
- *nipp = startp;
+ /* Reset to the beginning of the service list. */
+ *nipp = startp;
/* Look up the first function. */
- no_more = __nss_lookup (nipp, func_name, fctp);
+ no_more = __nss_lookup (nipp, "setnetgrent", fctp);
}
return no_more;
}
@@ -87,6 +86,20 @@ free_memory (struct __netgrent *data)
}
}
+static void
+endnetgrent_hook (struct __netgrent *datap)
+{
+ enum nss_status (*endfct) (struct __netgrent *);
+
+ if (datap->nip == NULL)
+ return;
+
+ endfct = __nss_lookup_function (datap->nip, "endnetgrent");
+ if (endfct != NULL)
+ (void) (*endfct) (datap);
+ datap->nip = NULL;
+}
+
static int
internal_function
__internal_setnetgrent_reuse (const char *group, struct __netgrent *datap,
@@ -100,14 +113,29 @@ __internal_setnetgrent_reuse (const char *group, struct __netgrent *datap,
enum nss_status status = NSS_STATUS_UNAVAIL;
struct name_list *new_elem;
+ /* Free data from previous service. */
+ endnetgrent_hook (datap);
+
/* Cycle through all the services and run their setnetgrent functions. */
- int no_more = setup (&fct.ptr, "setnetgrent", 1, &datap->nip);
+ int no_more = setup (&fct.ptr, &datap->nip);
while (! no_more)
{
+ assert (datap->data == NULL);
+
/* Ignore status, we force check in `__nss_next'. */
status = (*fct.f) (group, datap);
+ service_user *old_nip = datap->nip;
no_more = __nss_next (&datap->nip, "setnetgrent", &fct.ptr, status, 0);
+
+ if (status == NSS_STATUS_SUCCESS && ! no_more)
+ {
+ enum nss_status (*endfct) (struct __netgrent *);
+
+ endfct = __nss_lookup_function (old_nip, "endnetgrent");
+ if (endfct != NULL)
+ (void) (*endfct) (datap);
+ }
}
/* Add the current group to the list of known groups. */
@@ -157,34 +185,13 @@ setnetgrent (const char *group)
return result;
}
-
void internal_endnetgrent (struct __netgrent *datap);
libc_hidden_proto (internal_endnetgrent)
void
internal_endnetgrent (struct __netgrent *datap)
{
- service_user *old_nip;
- union
- {
- enum nss_status (*f) (struct __netgrent *);
- void *ptr;
- } fct;
-
- /* Remember which was the last used service. */
- old_nip = datap->nip;
-
- /* Cycle through all the services and run their endnetgrent functions. */
- int no_more = setup (&fct.ptr, "endnetgrent", 1, &datap->nip);
- while (! no_more)
- {
- /* Ignore status, we force check in `__nss_next'. */
- (void) (*fct.f) (datap);
-
- no_more = (datap->nip == old_nip
- || __nss_next (&datap->nip, "endnetgrent", &fct.ptr, 0, 1));
- }
-
+ endnetgrent_hook (datap);
/* Now free list of all netgroup names from last run. */
free_memory (datap);
}
@@ -213,11 +220,7 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
struct __netgrent *datap,
char *buffer, size_t buflen, int *errnop)
{
- union
- {
- enum nss_status (*f) (struct __netgrent *, char *, size_t, int *);
- void *ptr;
- } fct;
+ enum nss_status (*fct) (struct __netgrent *, char *, size_t, int *);
/* Initialize status to return if no more functions are found. */
enum nss_status status = NSS_STATUS_NOTFOUND;
@@ -225,10 +228,12 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
/* Run through available functions, starting with the same function last
run. We will repeat each function as long as it succeeds, and then go
on to the next service action. */
- int no_more = setup (&fct.ptr, "getnetgrent_r", 0, &datap->nip);
+ int no_more = (datap->nip == NULL
+ || (fct = __nss_lookup_function (datap->nip, "getnetgrent_r"))
+ == NULL);
while (! no_more)
{
- status = (*fct.f) (datap, buffer, buflen, &errno);
+ status = (*fct) (datap, buffer, buflen, &errno);
if (status == NSS_STATUS_RETURN)
{
@@ -246,8 +251,12 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
datap, errnop);
}
- if (found)
- continue;
+ if (found && datap->nip != NULL)
+ {
+ fct = __nss_lookup_function (datap->nip, "getnetgrent_r");
+ if (fct != NULL)
+ continue;
+ }
}
else if (status == NSS_STATUS_SUCCESS && datap->type == group_val)
{
@@ -279,7 +288,7 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp,
}
}
- no_more = __nss_next (&datap->nip, "getnetgrent_r", &fct.ptr, status, 0);
+ break;
}
if (status == NSS_STATUS_SUCCESS)
@@ -322,16 +331,8 @@ innetgr (const char *netgroup, const char *host, const char *user,
int (*f) (const char *, struct __netgrent *);
void *ptr;
} setfct;
- union
- {
- void (*f) (struct __netgrent *);
- void *ptr;
- } endfct;
- union
- {
- int (*f) (struct __netgrent *, char *, size_t, int *);
- void *ptr;
- } getfct;
+ void (*endfct) (struct __netgrent *);
+ int (*getfct) (struct __netgrent *, char *, size_t, int *);
struct __netgrent entry;
int result = 0;
const char *current_group = netgroup;
@@ -345,18 +346,21 @@ innetgr (const char *netgroup, const char *host, const char *user,
the work during one walk through the service list. */
while (1)
{
- int no_more = setup (&setfct.ptr, "setnetgrent", 1, &entry.nip);
+ int no_more = setup (&setfct.ptr, &entry.nip);
while (! no_more)
{
+ assert (entry.data == NULL);
+
/* Open netgroup. */
enum nss_status status = (*setfct.f) (current_group, &entry);
if (status == NSS_STATUS_SUCCESS
- && __nss_lookup (&entry.nip, "getnetgrent_r", &getfct.ptr) == 0)
+ && (getfct = __nss_lookup_function (entry.nip, "getnetgrent_r"))
+ != NULL)
{
char buffer[1024];
- while ((*getfct.f) (&entry, buffer, sizeof buffer, &errno)
+ while ((*getfct) (&entry, buffer, sizeof buffer, &errno)
== NSS_STATUS_SUCCESS)
{
if (entry.type == group_val)
@@ -414,8 +418,9 @@ innetgr (const char *netgroup, const char *host, const char *user,
}
/* Free all resources of the service. */
- if (__nss_lookup (&entry.nip, "endnetgrent", &endfct.ptr) == 0)
- (*endfct.f) (&entry);
+ endfct = __nss_lookup_function (entry.nip, "endnetgrent");
+ if (endfct != NULL)
+ (*endfct) (&entry);
/* Look for the next service. */
no_more = __nss_next (&entry.nip, "setnetgrent",
diff --git a/nis/nss_nis/nis-netgrp.c b/nis/nss_nis/nis-netgrp.c
index 7bd6527f2d..049bd8cdb4 100644
--- a/nis/nss_nis/nis-netgrp.c
+++ b/nis/nss_nis/nis-netgrp.c
@@ -41,13 +41,10 @@ _nss_netgroup_parseline (char **cursor, struct __netgrent *netgrp,
static void
internal_nis_endnetgrent (struct __netgrent *netgrp)
{
- if (netgrp->data != NULL)
- {
- free (netgrp->data);
- netgrp->data = NULL;
- netgrp->data_size = 0;
- netgrp->cursor = NULL;
- }
+ free (netgrp->data);
+ netgrp->data = NULL;
+ netgrp->data_size = 0;
+ netgrp->cursor = NULL;
}
enum nss_status
@@ -65,8 +62,6 @@ _nss_nis_setnetgrent (const char *group, struct __netgrent *netgrp)
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- internal_nis_endnetgrent (netgrp);
-
status = yperr2nss (yp_match (domain, "netgroup", group, strlen (group),
&netgrp->data, &len));
if (status == NSS_STATUS_SUCCESS)
@@ -99,9 +94,6 @@ enum nss_status
_nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
int *errnop)
{
- if (result->cursor == NULL)
- return NSS_STATUS_NOTFOUND;
-
return _nss_netgroup_parseline (&result->cursor, result, buffer, buflen,
errnop);
}
diff --git a/nis/nss_nisplus/nisplus-netgrp.c b/nis/nss_nisplus/nisplus-netgrp.c
index 607bc2c1ca..344d65f4c4 100644
--- a/nis/nss_nisplus/nisplus-netgrp.c
+++ b/nis/nss_nisplus/nisplus-netgrp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -141,13 +141,10 @@ _nss_nisplus_getnetgrent_r (struct __netgrent *result, char *buffer,
static void
internal_endnetgrent (struct __netgrent *netgrp)
{
- if (netgrp->data != NULL)
- {
- nis_freeresult ((nis_result *) netgrp->data);
- netgrp->data = NULL;
- netgrp->data_size = 0;
- netgrp->position = 0;
- }
+ nis_freeresult ((nis_result *) netgrp->data);
+ netgrp->data = NULL;
+ netgrp->data_size = 0;
+ netgrp->position = 0;
}
enum nss_status
@@ -161,8 +158,6 @@ _nss_nisplus_setnetgrent (const char *group, struct __netgrent *netgrp)
status = NSS_STATUS_SUCCESS;
- internal_endnetgrent (netgrp);
-
sprintf (buf, "[name=%s],netgroup.org_dir", group);
netgrp->data = (char *) nis_list (buf, EXPAND_NAME, NULL, NULL);
diff --git a/nss/getent.c b/nss/getent.c
index 7124e6303f..02bba39752 100644
--- a/nss/getent.c
+++ b/nss/getent.c
@@ -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>
@@ -410,6 +411,8 @@ netgroup_keys (int number, char *key[])
}
}
+ endnetgrent ();
+
return result;
}
@@ -838,7 +841,8 @@ more_help (int key, const char *text, void *input)
int
main (int argc, char *argv[])
{
- int remaining, i;
+ /* Debugging support. */
+ mtrace ();
/* Set locale via LC_ALL. */
setlocale (LC_ALL, "");
@@ -846,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)
@@ -855,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-netgrp.c b/nss/nss_files/files-netgrp.c
index 8bdc68bd14..45f3b8ac42 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,6 +144,9 @@ _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;
@@ -150,16 +157,13 @@ int
_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)