-/* Copyright (C) 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
#include "nscd_proto.h"
-libc_locked_map_ptr (map_handle);
-/* Note that we only free the structure if necessary. The memory
- mapping is not removed since it is not visible to the malloc
- handling. */
-libc_freeres_fn (gr_map_free)
-{
- if (map_handle.mapped != NO_MAPPING)
- free (map_handle.mapped);
-}
+/* We use the same mapping as in nscd_getgr. */
+libc_locked_map_ptr (extern, __gr_map_handle) attribute_hidden;
int
/* If the mapping is available, try to search there instead of
communicating with the nscd. */
struct mapped_database *mapped;
- mapped = __nscd_get_map_ref (GETFDGR, "group", &map_handle, &gc_cycle);
+ mapped = __nscd_get_map_ref (GETFDGR, "group", &__gr_map_handle, &gc_cycle);
retry:;
const initgr_response_header *initgr_resp = NULL;
sock = __nscd_open_socket (user, userlen, INITGROUPS, &initgr_resp_mem,
sizeof (initgr_resp_mem));
if (sock == -1)
- /* nscd not running or wrong version or hosts caching disabled. */
- __nss_not_use_nscd_group = 1;
+ {
+ /* nscd not running or wrong version. */
+ __nss_not_use_nscd_group = 1;
+ goto out;
+ }
initgr_resp = &initgr_resp_mem;
}
(initgr_resp->ngrps + 1) * sizeof (gid_t));
if (newp == NULL)
/* We cannot increase the buffer size. */
- goto out;
+ goto out_close;
*groupsp = newp;
*size = initgr_resp->ngrps + 1;
if (respdata == NULL)
{
/* Read the data from the socket. */
- if ((size_t) TEMP_FAILURE_RETRY (__read (sock, *groupsp,
- initgr_resp->ngrps
- * sizeof (gid_t)))
+ if ((size_t) __readall (sock, *groupsp, initgr_resp->ngrps
+ * sizeof (gid_t))
== initgr_resp->ngrps * sizeof (gid_t))
retval = initgr_resp->ngrps;
}
}
else
{
+ if (__builtin_expect (initgr_resp->found == -1, 0))
+ {
+ /* The daemon does not cache this database. */
+ __nss_not_use_nscd_group = 1;
+ goto out_close;
+ }
+
/* No group found yet. */
retval = 0;
(*groupsp)[retval++] = group;
}
+ out_close:
if (sock != -1)
close_not_cancel_no_status (sock);
out: