|
|
b40826 |
2010-08-06 Ulrich Drepper <drepper@redhat.com>
|
|
|
b40826 |
|
|
|
b40826 |
* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
|
|
|
b40826 |
Also fail if tpwd after pwuid call is NULL.
|
|
|
b40826 |
|
|
|
b40826 |
2010-06-21 Andreas Schwab <schwab@redhat.com>
|
|
|
b40826 |
|
|
|
b40826 |
* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
|
|
|
b40826 |
Restore proper fallback handling.
|
|
|
b40826 |
|
|
|
b40826 |
2010-06-19 Ulrich Drepper <drepper@redhat.com>
|
|
|
b40826 |
|
|
|
b40826 |
* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Handle
|
|
|
b40826 |
OOM in getpwuid_r correctly. Return error number when the caller
|
|
|
b40826 |
should return, otherwise -1.
|
|
|
b40826 |
(getlogin_r): Adjust to return also for result of __getlogin_r_loginuid
|
|
|
b40826 |
call returning > 0 value.
|
|
|
b40826 |
* sysdeps/unix/sysv/linux/getlogin.c (getlogin): Likewise.
|
|
|
b40826 |
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/getlogin.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin.c
|
|
|
b40826 |
@@ -32,8 +32,9 @@
|
|
|
b40826 |
char *
|
|
|
b40826 |
getlogin (void)
|
|
|
b40826 |
{
|
|
|
b40826 |
- if (__getlogin_r_loginuid (name, sizeof (name)) == 0)
|
|
|
b40826 |
- return name;
|
|
|
b40826 |
+ int res = __getlogin_r_loginuid (name, sizeof (name));
|
|
|
b40826 |
+ if (res >= 0)
|
|
|
b40826 |
+ return res == 0 ? name : NULL;
|
|
|
b40826 |
|
|
|
b40826 |
return getlogin_fd0 ();
|
|
|
b40826 |
}
|
|
|
b40826 |
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin_r.c
|
|
|
b40826 |
===================================================================
|
|
|
b40826 |
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/getlogin_r.c
|
|
|
b40826 |
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin_r.c
|
|
|
b40826 |
@@ -27,6 +27,10 @@ static int getlogin_r_fd0 (char *name, s
|
|
|
b40826 |
#undef getlogin_r
|
|
|
b40826 |
|
|
|
b40826 |
|
|
|
b40826 |
+/* Try to determine login name from /proc/self/loginuid and return 0
|
|
|
b40826 |
+ if successful. If /proc/self/loginuid cannot be read return -1.
|
|
|
b40826 |
+ Otherwise return the error number. */
|
|
|
b40826 |
+
|
|
|
b40826 |
int
|
|
|
b40826 |
attribute_hidden
|
|
|
b40826 |
__getlogin_r_loginuid (name, namesize)
|
|
|
b40826 |
@@ -35,7 +39,7 @@ __getlogin_r_loginuid (name, namesize)
|
|
|
b40826 |
{
|
|
|
b40826 |
int fd = open_not_cancel_2 ("/proc/self/loginuid", O_RDONLY);
|
|
|
b40826 |
if (fd == -1)
|
|
|
b40826 |
- return 1;
|
|
|
b40826 |
+ return -1;
|
|
|
b40826 |
|
|
|
b40826 |
/* We are reading a 32-bit number. 12 bytes are enough for the text
|
|
|
b40826 |
representation. If not, something is wrong. */
|
|
|
b40826 |
@@ -51,37 +55,38 @@ __getlogin_r_loginuid (name, namesize)
|
|
|
b40826 |
|| (uidbuf[n] = '\0',
|
|
|
b40826 |
uid = strtoul (uidbuf, &endp, 10),
|
|
|
b40826 |
endp == uidbuf || *endp != '\0'))
|
|
|
b40826 |
- return 1;
|
|
|
b40826 |
+ return -1;
|
|
|
b40826 |
|
|
|
b40826 |
size_t buflen = 1024;
|
|
|
b40826 |
char *buf = alloca (buflen);
|
|
|
b40826 |
bool use_malloc = false;
|
|
|
b40826 |
struct passwd pwd;
|
|
|
b40826 |
struct passwd *tpwd;
|
|
|
b40826 |
+ int result = 0;
|
|
|
b40826 |
int res;
|
|
|
b40826 |
|
|
|
b40826 |
- while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) != 0)
|
|
|
b40826 |
+ while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) == ERANGE)
|
|
|
b40826 |
if (__libc_use_alloca (2 * buflen))
|
|
|
b40826 |
- extend_alloca (buf, buflen, 2 * buflen);
|
|
|
b40826 |
+ buf = extend_alloca (buf, buflen, 2 * buflen);
|
|
|
b40826 |
else
|
|
|
b40826 |
{
|
|
|
b40826 |
buflen *= 2;
|
|
|
b40826 |
char *newp = realloc (use_malloc ? buf : NULL, buflen);
|
|
|
b40826 |
if (newp == NULL)
|
|
|
b40826 |
{
|
|
|
b40826 |
- fail:
|
|
|
b40826 |
- if (use_malloc)
|
|
|
b40826 |
- free (buf);
|
|
|
b40826 |
- return 1;
|
|
|
b40826 |
+ result = ENOMEM;
|
|
|
b40826 |
+ goto out;
|
|
|
b40826 |
}
|
|
|
b40826 |
buf = newp;
|
|
|
b40826 |
use_malloc = true;
|
|
|
b40826 |
}
|
|
|
b40826 |
|
|
|
b40826 |
- if (tpwd == NULL)
|
|
|
b40826 |
- goto fail;
|
|
|
b40826 |
+ if (res != 0 || tpwd == NULL)
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ result = -1;
|
|
|
b40826 |
+ goto out;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
|
|
|
b40826 |
- int result = 0;
|
|
|
b40826 |
size_t needed = strlen (pwd.pw_name) + 1;
|
|
|
b40826 |
if (needed > namesize)
|
|
|
b40826 |
{
|
|
|
b40826 |
@@ -109,8 +114,9 @@ getlogin_r (name, namesize)
|
|
|
b40826 |
char *name;
|
|
|
b40826 |
size_t namesize;
|
|
|
b40826 |
{
|
|
|
b40826 |
- if (__getlogin_r_loginuid (name, namesize) == 0)
|
|
|
b40826 |
- return 0;
|
|
|
b40826 |
+ int res = __getlogin_r_loginuid (name, namesize);
|
|
|
b40826 |
+ if (res >= 0)
|
|
|
b40826 |
+ return res;
|
|
|
b40826 |
|
|
|
b40826 |
return getlogin_r_fd0 (name, namesize);
|
|
|
b40826 |
}
|