aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-06-06 06:06:02 +0000
committerUlrich Drepper <drepper@redhat.com>2004-06-06 06:06:02 +0000
commit40c38b6c9d4b49d509630dccb55cf529b3da3d89 (patch)
treedc727938810ecd6787700960f57ebd6c090ff42f
parentd4c4ee1ed59571c3214b546fbbdbab2beb97860c (diff)
downloadglibc-40c38b6c9d4b49d509630dccb55cf529b3da3d89.zip
glibc-40c38b6c9d4b49d509630dccb55cf529b3da3d89.tar.gz
glibc-40c38b6c9d4b49d509630dccb55cf529b3da3d89.tar.bz2
Update.
2004-06-05 Ulrich Drepper <drepper@redhat.com> * stdio-common/_itoa.h: Don't expand _itoa inline for libc. * stdio-common/_itoa.c: Add _itoa implementation. * nscd/nscd_gethst_r.c (__nscd_open_socket): Change implementation to also send request. Add parameter to allow this. Change callers. * nscd/nscd_getgr_r.c: Change __nscd_open_socket caller. * nscd/nscd_getpw_r.c: Likewise. * nscd/nscd-client.h: Change __nscd_open_socket prototype.
-rw-r--r--ChangeLog12
-rw-r--r--nscd/nscd-client.h6
-rw-r--r--nscd/nscd_getgr_r.c41
-rw-r--r--nscd/nscd_gethst_r.c60
-rw-r--r--nscd/nscd_getpw_r.c43
-rw-r--r--stdio-common/_itoa.c38
6 files changed, 109 insertions, 91 deletions
diff --git a/ChangeLog b/ChangeLog
index 59d9908..88bc3b7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2004-06-05 Ulrich Drepper <drepper@redhat.com>
+
+ * stdio-common/_itoa.h: Don't expand _itoa inline for libc.
+ * stdio-common/_itoa.c: Add _itoa implementation.
+
+ * nscd/nscd_gethst_r.c (__nscd_open_socket): Change implementation
+ to also send request. Add parameter to allow this.
+ Change callers.
+ * nscd/nscd_getgr_r.c: Change __nscd_open_socket caller.
+ * nscd/nscd_getpw_r.c: Likewise.
+ * nscd/nscd-client.h: Change __nscd_open_socket prototype.
+
2004-06-05 Andreas Jaeger <aj@suse.de>
* sysdeps/unix/sysv/linux/x86_64/makecontext.c (__makecontext):
diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h
index c0cf14b..470bc69 100644
--- a/nscd/nscd-client.h
+++ b/nscd/nscd-client.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@@ -111,6 +111,8 @@ typedef struct
/* Open socket connection to nscd server. */
-extern int __nscd_open_socket (void) attribute_hidden;
+extern int __nscd_open_socket (const char *key, size_t keylen,
+ request_type type, void *response,
+ size_t responselen) attribute_hidden;
#endif /* nscd.h */
diff --git a/nscd/nscd_getgr_r.c b/nscd/nscd_getgr_r.c
index f6b0b5c..c57c6e7 100644
--- a/nscd/nscd_getgr_r.c
+++ b/nscd/nscd_getgr_r.c
@@ -28,6 +28,7 @@
#include <sys/socket.h>
#include <sys/uio.h>
#include <sys/un.h>
+#include <not-cancel.h>
#include "nscd-client.h"
#include "nscd_proto.h"
@@ -53,12 +54,12 @@ int
__nscd_getgrgid_r (gid_t gid, struct group *resultbuf, char *buffer,
size_t buflen, struct group **result)
{
- char buf[12];
- size_t n;
+ char buf[3 * sizeof (gid_t)];
+ buf[sizeof (buf) - 1] = '\0';
+ char *cp = _itoa_word (gid, buf + sizeof (buf) - 1, 10, 0);
- n = __snprintf (buf, sizeof (buf), "%d", gid) + 1;
-
- return nscd_getgr_r (buf, n, GETGRBYGID, resultbuf, buffer, buflen, result);
+ return nscd_getgr_r (cp, buf + sizeof (buf) - cp, GETGRBYGID, resultbuf,
+ buffer, buflen, result);
}
@@ -68,13 +69,9 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
struct group *resultbuf, char *buffer, size_t buflen,
struct group **result)
{
- int sock = __nscd_open_socket ();
- request_header req;
gr_response_header gr_resp;
- ssize_t nbytes;
- struct iovec vec[2];
- int retval = -1;
-
+ int sock = __nscd_open_socket (key, keylen, type, &gr_resp,
+ sizeof (gr_resp));
if (sock == -1)
{
__nss_not_use_nscd_group = 1;
@@ -82,26 +79,9 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
}
/* No value found so far. */
+ int retval = -1;
*result = NULL;
- req.version = NSCD_VERSION;
- req.type = type;
- req.key_len = keylen;
-
- vec[0].iov_base = &req;
- vec[0].iov_len = sizeof (request_header);
- vec[1].iov_base = (void *) key;
- vec[1].iov_len = keylen;
-
- nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
- if (nbytes != (ssize_t) (sizeof (request_header) + keylen))
- goto out;
-
- nbytes = TEMP_FAILURE_RETRY (__read (sock, &gr_resp,
- sizeof (gr_response_header)));
- if (nbytes != (ssize_t) sizeof (gr_response_header))
- goto out;
-
if (gr_resp.found == -1)
{
/* The daemon does not cache this database. */
@@ -111,6 +91,7 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
if (gr_resp.found == 1)
{
+ struct iovec vec[2];
uint32_t *len;
char *p = buffer;
size_t total_len;
@@ -196,7 +177,7 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
}
out:
- __close (sock);
+ close_not_cancel_no_status (sock);
return retval;
}
diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c
index 8a498b6..7449aad 100644
--- a/nscd/nscd_gethst_r.c
+++ b/nscd/nscd_gethst_r.c
@@ -29,6 +29,7 @@
#include <sys/socket.h>
#include <sys/uio.h>
#include <sys/un.h>
+#include <not-cancel.h>
#include "nscd-client.h"
#include "nscd_proto.h"
@@ -90,7 +91,8 @@ __nscd_gethostbyaddr_r (const void *addr, socklen_t len, int type,
/* Create a socket connected to a name. */
int
-__nscd_open_socket (void)
+__nscd_open_socket (const char *key, size_t keylen, request_type type,
+ void *response, size_t responselen)
{
struct sockaddr_un addr;
int sock;
@@ -107,9 +109,33 @@ __nscd_open_socket (void)
strcpy (addr.sun_path, _PATH_NSCDSOCKET);
if (__connect (sock, (struct sockaddr *) &addr, sizeof (addr)) < 0)
{
- __close (sock);
__set_errno (saved_errno);
- return -1;
+ goto out;
+ }
+
+ request_header req;
+ req.version = NSCD_VERSION;
+ req.type = type;
+ req.key_len = keylen;
+
+ struct iovec vec[2];
+ vec[0].iov_base = &req;
+ vec[0].iov_len = sizeof (request_header);
+ vec[1].iov_base = (void *) key;
+ vec[1].iov_len = keylen;
+
+ ssize_t nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
+ if (nbytes != (ssize_t) (sizeof (request_header) + keylen))
+ {
+ out:
+ close_not_cancel_no_status (sock);
+ sock = -1;
+ }
+ else
+ {
+ nbytes = TEMP_FAILURE_RETRY (__read (sock, response, responselen));
+ if (nbytes != (ssize_t) responselen)
+ goto out;
}
return sock;
@@ -122,13 +148,9 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
struct hostent *resultbuf, char *buffer, size_t buflen,
struct hostent **result, int *h_errnop)
{
- int sock = __nscd_open_socket ();
hst_response_header hst_resp;
- request_header req;
- ssize_t nbytes;
- struct iovec vec[4];
- int retval = -1;
-
+ int sock = __nscd_open_socket (key, keylen, type, &hst_resp,
+ sizeof (hst_resp));
if (sock == -1)
{
__nss_not_use_nscd_hosts = 1;
@@ -136,26 +158,9 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
}
/* No value found so far. */
+ int retval = -1;
*result = NULL;
- req.version = NSCD_VERSION;
- req.type = type;
- req.key_len = keylen;
-
- vec[0].iov_base = &req;
- vec[0].iov_len = sizeof (request_header);
- vec[1].iov_base = (void *) key;
- vec[1].iov_len = req.key_len;
-
- nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
- if ((size_t) nbytes != sizeof (request_header) + req.key_len)
- goto out;
-
- nbytes = TEMP_FAILURE_RETRY (__read (sock, &hst_resp,
- sizeof (hst_response_header)));
- if (__builtin_expect (nbytes != sizeof (hst_response_header), 0))
- goto out;
-
if (hst_resp.found == -1)
{
/* The daemon does not cache this database. */
@@ -165,6 +170,7 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
if (hst_resp.found == 1)
{
+ struct iovec vec[4];
uint32_t *aliases_len;
char *cp = buffer;
uintptr_t align1;
diff --git a/nscd/nscd_getpw_r.c b/nscd/nscd_getpw_r.c
index 747c39b..21f214d 100644
--- a/nscd/nscd_getpw_r.c
+++ b/nscd/nscd_getpw_r.c
@@ -27,6 +27,8 @@
#include <sys/socket.h>
#include <sys/uio.h>
#include <sys/un.h>
+#include <not-cancel.h>
+#include <stdio-common/_itoa.h>
#include "nscd-client.h"
#include "nscd_proto.h"
@@ -53,12 +55,12 @@ int
__nscd_getpwuid_r (uid_t uid, struct passwd *resultbuf, char *buffer,
size_t buflen, struct passwd **result)
{
- char buf[12];
- size_t n;
+ char buf[3 * sizeof (uid_t)];
+ buf[sizeof (buf) - 1] = '\0';
+ char *cp = _itoa_word (uid, buf + sizeof (buf) - 1, 10, 0);
- n = __snprintf (buf, sizeof (buf), "%d", uid) + 1;
-
- return nscd_getpw_r (buf, n, GETPWBYUID, resultbuf, buffer, buflen, result);
+ return nscd_getpw_r (cp, buf + sizeof (buf) - cp, GETPWBYUID, resultbuf,
+ buffer, buflen, result);
}
@@ -68,13 +70,9 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
struct passwd *resultbuf, char *buffer, size_t buflen,
struct passwd **result)
{
- int sock = __nscd_open_socket ();
- request_header req;
pw_response_header pw_resp;
- ssize_t nbytes;
- struct iovec vec[2];
- int retval = -1;
-
+ int sock = __nscd_open_socket (key, keylen, type, &pw_resp,
+ sizeof (pw_resp));
if (sock == -1)
{
__nss_not_use_nscd_passwd = 1;
@@ -82,26 +80,9 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
}
/* No value found so far. */
+ int retval = -1;
*result = NULL;
- req.version = NSCD_VERSION;
- req.type = type;
- req.key_len = keylen;
-
- vec[0].iov_base = &req;
- vec[0].iov_len = sizeof (request_header);
- vec[1].iov_base = (void *) key;
- vec[1].iov_len = keylen;
-
- nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2));
- if (nbytes != (ssize_t) (sizeof (request_header) + keylen))
- goto out;
-
- nbytes = TEMP_FAILURE_RETRY (__read (sock, &pw_resp,
- sizeof (pw_response_header)));
- if (nbytes != (ssize_t) sizeof (pw_response_header))
- goto out;
-
if (__builtin_expect (pw_resp.found == -1, 0))
{
/* The daemon does not cache this database. */
@@ -142,7 +123,7 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
/* get pw_pshell */
resultbuf->pw_shell = p;
- nbytes = TEMP_FAILURE_RETRY (__read (sock, buffer, total));
+ ssize_t nbytes = TEMP_FAILURE_RETRY (__read (sock, buffer, total));
if (nbytes == (ssize_t) total)
{
@@ -159,7 +140,7 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
}
out:
- __close (sock);
+ close_not_cancel_no_status (sock);
return retval;
}
diff --git a/stdio-common/_itoa.c b/stdio-common/_itoa.c
index e39d88d..f61b23f 100644
--- a/stdio-common/_itoa.c
+++ b/stdio-common/_itoa.c
@@ -1,5 +1,5 @@
/* Internal function for converting integers to ASCII.
- Copyright (C) 1994, 1995, 1996, 1999, 2000, 2002, 2003
+ Copyright (C) 1994, 1995, 1996, 1999, 2000, 2002, 2003, 2004
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Torbjorn Granlund <tege@matematik.su.se>
@@ -166,6 +166,42 @@ extern const char _itoa_upper_digits_internal[] attribute_hidden;
char *
+_itoa_word (unsigned long value, char *buflim,
+ unsigned int base, int upper_case)
+{
+ const char *digits = (upper_case
+#if !defined NOT_IN_libc || defined IS_IN_rtld
+ ? INTUSE(_itoa_upper_digits)
+ : INTUSE(_itoa_lower_digits)
+#else
+ ? _itoa_upper_digits
+ : _itoa_lower_digits
+#endif
+ );
+
+ switch (base)
+ {
+#define SPECIAL(Base) \
+ case Base: \
+ do \
+ *--buflim = digits[value % Base]; \
+ while ((value /= Base) != 0); \
+ break
+
+ SPECIAL (10);
+ SPECIAL (16);
+ SPECIAL (8);
+ default:
+ do
+ *--buflim = digits[value % base];
+ while ((value /= base) != 0);
+ }
+ return buflim;
+}
+#undef SPECIAL
+
+
+char *
_itoa (value, buflim, base, upper_case)
unsigned long long int value;
char *buflim;