aboutsummaryrefslogtreecommitdiff
path: root/libbb/my_getpwuid.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-09-15 03:04:08 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-09-15 03:04:08 +0000
commitf15dfc557048ca28c8b71ecbcfb9b8f229f2e2e0 (patch)
treef34d5e6241ef8f0a1a95502128789b2edd2c1a71 /libbb/my_getpwuid.c
parent995d96a99d5f2d546d5e15b2614ae7408da27631 (diff)
downloadbusybox-f15dfc557048ca28c8b71ecbcfb9b8f229f2e2e0.tar.gz
Tito writes,
"This patch fixes all the bugs in id previously spotted by vodz and me. The binary size increased a bit, but now it should work as expected."
Diffstat (limited to 'libbb/my_getpwuid.c')
-rw-r--r--libbb/my_getpwuid.c45
1 files changed, 12 insertions, 33 deletions
diff --git a/libbb/my_getpwuid.c b/libbb/my_getpwuid.c
index 1e8b11a09..3195a2182 100644
--- a/libbb/my_getpwuid.c
+++ b/libbb/my_getpwuid.c
@@ -22,49 +22,28 @@
/* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more
* flexible :
*
- * if bufsize is > 0 char *user can not be set to NULL
- * on success username is written on static allocated buffer
- * on failure uid as string is written to buffer and NULL is returned
- * if bufsize is = 0 char *user can be set to NULL
- * on success username is returned
- * on failure NULL is returned
+ * if bufsize is > 0 char *user can not be set to NULL.
+ * On success username is written on static allocated buffer name
+ * (and a pointer to it is returned).
+ * On failure uid as string is written to static allocated buffer name
+ * and NULL is returned.
+ * if bufsize is = 0 char *user can be set to NULL.
+ * On success username is returned.
+ * On failure NULL is returned.
* if bufsize is < 0 char *user can be set to NULL
- * on success username is returned
- * on failure an error message is printed and the program exits
+ * On success username is returned.
+ * On failure an error message is printed and the program exits.
*/
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
#include "libbb.h"
#include "pwd_.h"
-#include "grp_.h"
-
-
/* gets a username given a uid */
char * my_getpwuid(char *name, long uid, int bufsize)
{
- struct passwd *myuser;
+ struct passwd *myuser = getpwuid(uid);
- myuser = getpwuid(uid);
- if (myuser==NULL) {
- if(bufsize > 0) {
- assert(name != NULL);
- snprintf(name, bufsize, "%ld", (long)uid);
- }
- if (bufsize < 0 ) {
- bb_error_msg_and_die("unknown uid %ld", (long)uid);
- }
- return NULL;
- } else {
- if(bufsize > 0 )
- {
- assert(name != NULL);
- return safe_strncpy(name, myuser->pw_name, bufsize);
- }
- return myuser->pw_name;
- }
+ return my_getug(name, (myuser) ? myuser->pw_name : (char *)myuser , uid, bufsize, 'u');
}
/* END CODE */