diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2004-09-15 03:04:08 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2004-09-15 03:04:08 +0000 |
commit | f15dfc557048ca28c8b71ecbcfb9b8f229f2e2e0 (patch) | |
tree | f34d5e6241ef8f0a1a95502128789b2edd2c1a71 /libbb/my_getpwuid.c | |
parent | 995d96a99d5f2d546d5e15b2614ae7408da27631 (diff) | |
download | busybox-w32-f15dfc557048ca28c8b71ecbcfb9b8f229f2e2e0.tar.gz busybox-w32-f15dfc557048ca28c8b71ecbcfb9b8f229f2e2e0.tar.bz2 busybox-w32-f15dfc557048ca28c8b71ecbcfb9b8f229f2e2e0.zip |
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.c | 45 |
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 @@ | |||
22 | /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more | 22 | /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more |
23 | * flexible : | 23 | * flexible : |
24 | * | 24 | * |
25 | * if bufsize is > 0 char *user can not be set to NULL | 25 | * if bufsize is > 0 char *user can not be set to NULL. |
26 | * on success username is written on static allocated buffer | 26 | * On success username is written on static allocated buffer name |
27 | * on failure uid as string is written to buffer and NULL is returned | 27 | * (and a pointer to it is returned). |
28 | * if bufsize is = 0 char *user can be set to NULL | 28 | * On failure uid as string is written to static allocated buffer name |
29 | * on success username is returned | 29 | * and NULL is returned. |
30 | * on failure NULL is returned | 30 | * if bufsize is = 0 char *user can be set to NULL. |
31 | * On success username is returned. | ||
32 | * On failure NULL is returned. | ||
31 | * if bufsize is < 0 char *user can be set to NULL | 33 | * if bufsize is < 0 char *user can be set to NULL |
32 | * on success username is returned | 34 | * On success username is returned. |
33 | * on failure an error message is printed and the program exits | 35 | * On failure an error message is printed and the program exits. |
34 | */ | 36 | */ |
35 | 37 | ||
36 | #include <stdio.h> | ||
37 | #include <string.h> | ||
38 | #include <assert.h> | ||
39 | #include "libbb.h" | 38 | #include "libbb.h" |
40 | #include "pwd_.h" | 39 | #include "pwd_.h" |
41 | #include "grp_.h" | ||
42 | |||
43 | |||
44 | 40 | ||
45 | /* gets a username given a uid */ | 41 | /* gets a username given a uid */ |
46 | char * my_getpwuid(char *name, long uid, int bufsize) | 42 | char * my_getpwuid(char *name, long uid, int bufsize) |
47 | { | 43 | { |
48 | struct passwd *myuser; | 44 | struct passwd *myuser = getpwuid(uid); |
49 | 45 | ||
50 | myuser = getpwuid(uid); | 46 | return my_getug(name, (myuser) ? myuser->pw_name : (char *)myuser , uid, bufsize, 'u'); |
51 | if (myuser==NULL) { | ||
52 | if(bufsize > 0) { | ||
53 | assert(name != NULL); | ||
54 | snprintf(name, bufsize, "%ld", (long)uid); | ||
55 | } | ||
56 | if (bufsize < 0 ) { | ||
57 | bb_error_msg_and_die("unknown uid %ld", (long)uid); | ||
58 | } | ||
59 | return NULL; | ||
60 | } else { | ||
61 | if(bufsize > 0 ) | ||
62 | { | ||
63 | assert(name != NULL); | ||
64 | return safe_strncpy(name, myuser->pw_name, bufsize); | ||
65 | } | ||
66 | return myuser->pw_name; | ||
67 | } | ||
68 | } | 47 | } |
69 | 48 | ||
70 | /* END CODE */ | 49 | /* END CODE */ |