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 | |
| 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')
| -rw-r--r-- | libbb/Makefile.in | 2 | ||||
| -rw-r--r-- | libbb/my_getgrgid.c | 46 | ||||
| -rw-r--r-- | libbb/my_getpwuid.c | 45 | ||||
| -rw-r--r-- | libbb/my_getug.c | 64 |
4 files changed, 90 insertions, 67 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 26ed5b132..f86664f15 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
| @@ -34,7 +34,7 @@ LIBBB_SRC:= \ | |||
| 34 | human_readable.c inet_common.c inode_hash.c interface.c isdirectory.c \ | 34 | human_readable.c inet_common.c inode_hash.c interface.c isdirectory.c \ |
| 35 | kernel_version.c last_char_is.c llist_add_to.c login.c loop.c \ | 35 | kernel_version.c last_char_is.c llist_add_to.c login.c loop.c \ |
| 36 | make_directory.c mode_string.c module_syscalls.c mtab.c mtab_file.c \ | 36 | make_directory.c mode_string.c module_syscalls.c mtab.c mtab_file.c \ |
| 37 | my_getgrgid.c my_getgrnam.c my_getpwnam.c \ | 37 | my_getgrgid.c my_getgrnam.c my_getpwnam.c my_getug.c\ |
| 38 | my_getpwuid.c obscure.c parse_mode.c parse_number.c perror_msg.c \ | 38 | my_getpwuid.c obscure.c parse_mode.c parse_number.c perror_msg.c \ |
| 39 | perror_msg_and_die.c print_file.c get_console.c \ | 39 | perror_msg_and_die.c print_file.c get_console.c \ |
| 40 | process_escape_sequence.c procps.c pwd2spwd.c pw_encrypt.c qmodule.c \ | 40 | process_escape_sequence.c procps.c pwd2spwd.c pw_encrypt.c qmodule.c \ |
diff --git a/libbb/my_getgrgid.c b/libbb/my_getgrgid.c index 8c530964c..9ac14a34e 100644 --- a/libbb/my_getgrgid.c +++ b/libbb/my_getgrgid.c | |||
| @@ -22,48 +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 *group cannot be set to NULL | 25 | * if bufsize is > 0 char *group cannot be set to NULL. |
| 26 | * on success groupname is written on static allocated buffer | 26 | * On success groupname is written on static allocated buffer group |
| 27 | * on failure gid as string is written to buffer and NULL is returned | 27 | * (and a pointer to it is returned). |
| 28 | * if bufsize is = 0 char *group can be set to NULL | 28 | * On failure gid as string is written to static allocated buffer |
| 29 | * on success groupname is returned | 29 | * group and NULL is returned. |
| 30 | * on failure NULL is returned | 30 | * if bufsize is = 0 char *group can be set to NULL. |
| 31 | * if bufsize is < 0 char *group can be set to NULL | 31 | * On success groupname is returned. |
| 32 | * on success groupname is returned | 32 | * On failure NULL is returned. |
| 33 | * on failure an error message is printed and the program exits | 33 | * if bufsize is < 0 char *group can be set to NULL. |
| 34 | * On success groupname is returned. | ||
| 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" | ||
| 41 | #include "grp_.h" | 39 | #include "grp_.h" |
| 42 | 40 | ||
| 43 | |||
| 44 | /* gets a groupname given a gid */ | 41 | /* gets a groupname given a gid */ |
| 45 | char * my_getgrgid(char *group, long gid, int bufsize) | 42 | char * my_getgrgid(char *group, long gid, int bufsize) |
| 46 | { | 43 | { |
| 47 | struct group *mygroup; | 44 | struct group *mygroup = getgrgid(gid); |
| 48 | 45 | ||
| 49 | mygroup = getgrgid(gid); | 46 | return my_getug(group, (mygroup) ? mygroup->gr_name : (char *)mygroup, gid, bufsize, 'g'); |
| 50 | if (mygroup==NULL) { | ||
| 51 | if(bufsize > 0) { | ||
| 52 | assert(group != NULL); | ||
| 53 | snprintf(group, bufsize, "%ld", (long)gid); | ||
| 54 | } | ||
| 55 | if( bufsize < 0 ) { | ||
| 56 | bb_error_msg_and_die("unknown gid %ld", (long)gid); | ||
| 57 | } | ||
| 58 | return NULL; | ||
| 59 | } else { | ||
| 60 | if(bufsize > 0) | ||
| 61 | { | ||
| 62 | assert(group != NULL); | ||
| 63 | return safe_strncpy(group, mygroup->gr_name, bufsize); | ||
| 64 | } | ||
| 65 | return mygroup->gr_name; | ||
| 66 | } | ||
| 67 | } | 47 | } |
| 68 | 48 | ||
| 69 | 49 | ||
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 */ |
diff --git a/libbb/my_getug.c b/libbb/my_getug.c new file mode 100644 index 000000000..894dc5fdd --- /dev/null +++ b/libbb/my_getug.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) 2004 by Tito Ragusa <farmatito@tiscali.it> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This program is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /* | ||
| 23 | * | ||
| 24 | * if bufsize is > 0 char *idname can not be set to NULL. | ||
| 25 | * On success idname is written on static allocated buffer | ||
| 26 | * (and a pointer to it is returned). | ||
| 27 | * On failure uid or gid as string is written to static allocated buffer | ||
| 28 | * and NULL is returned. | ||
| 29 | * if bufsize is = 0 char *idname can be set to NULL. | ||
| 30 | * On success idname is returned. | ||
| 31 | * On failure NULL is returned. | ||
| 32 | * if bufsize is < 0 char *idname can be set to NULL. | ||
| 33 | * On success idname is returned. | ||
| 34 | * On failure an error message is printed and the program exits. | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include <stdio.h> | ||
| 38 | #include <assert.h> | ||
| 39 | #include "libbb.h" | ||
| 40 | |||
| 41 | |||
| 42 | /* internal function for my_getpwuid and my_getgrgid */ | ||
| 43 | char * my_getug(char *buffer, char *idname, long id, int bufsize, char prefix) | ||
| 44 | { | ||
| 45 | if(bufsize > 0 ) { | ||
| 46 | assert(buffer!=NULL); | ||
| 47 | if(idname) { | ||
| 48 | return safe_strncpy(buffer, idname, bufsize); | ||
| 49 | } | ||
| 50 | snprintf(buffer, bufsize, "%ld", id); | ||
| 51 | } else if(bufsize < 0 && !idname) { | ||
| 52 | bb_error_msg_and_die("unknown %cid %ld", prefix, id); | ||
| 53 | } | ||
| 54 | return idname; | ||
| 55 | } | ||
| 56 | |||
| 57 | /* END CODE */ | ||
| 58 | /* | ||
| 59 | Local Variables: | ||
| 60 | c-file-style: "linux" | ||
| 61 | c-basic-offset: 4 | ||
| 62 | tab-width: 4 | ||
| 63 | End: | ||
| 64 | */ | ||
