summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorEric Andersen2004-09-02 22:21:41 +0000
committerEric Andersen2004-09-02 22:21:41 +0000
commit7eb79fff10915afc4d561a65e54851efa869db89 (patch)
treededb5229f5b92441ba10aa00667463ef100ccd6f /libbb
parentb225e2a76bcd2b1f3f919a09dba1e186c0d4fa65 (diff)
downloadbusybox-7eb79fff10915afc4d561a65e54851efa869db89.zip
busybox-7eb79fff10915afc4d561a65e54851efa869db89.tar.gz
Tito writes:
Hi Erik, Hi to all, This is part five of the my_get*id story. I've tweaked a bit this two functions to make them more flexible, but this changes will not affect existing code. Now they work so: 1) my_getpwuid( char *user, uid_t uid, int bufsize) if bufsize is > 0 char *user cannot 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 be set to NULL on success username is returned on failure an error message is printed and the program exits 2) 1) my_getgrgid( char *group, uid_t uid, int bufsize) if bufsize is > 0 char *group cannot be set to NULL on success groupname is written on static allocated buffer on failure gid as string is written to buffer and NULL is returned if bufsize is = 0 char *group can be set to NULL on success groupname is returned on failure NULL is returned if bufsize is < 0 char *group can be set to nULL on success groupname is returned on failure an error message is printed and the program exits This changes were needed mainly for my new id applet. It is somewhat bigger then the previous but matches the behaviour of GNU id and is capable to handle usernames of whatever length. BTW: at a first look it seems to me that it will integrate well (with just a few changes) with the pending patch in patches/id_groups_alias.patch. The increase in size is balanced by the removal of my_getpwnamegid.c from libbb as this was used only in previous id applet and by size optimizations made possible in whoami.c and in passwd.c. I know that we are in feature freeze but I think that i've tested it enough (at least I hope so.......).
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Makefile.in2
-rw-r--r--libbb/my_getgrgid.c30
-rw-r--r--libbb/my_getpwuid.c30
3 files changed, 57 insertions, 5 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index f993b21..26ed5b1 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -34,7 +34,7 @@ LIBBB_SRC:= \
human_readable.c inet_common.c inode_hash.c interface.c isdirectory.c \
kernel_version.c last_char_is.c llist_add_to.c login.c loop.c \
make_directory.c mode_string.c module_syscalls.c mtab.c mtab_file.c \
- my_getgrgid.c my_getgrnam.c my_getpwnam.c my_getpwnamegid.c \
+ my_getgrgid.c my_getgrnam.c my_getpwnam.c \
my_getpwuid.c obscure.c parse_mode.c parse_number.c perror_msg.c \
perror_msg_and_die.c print_file.c get_console.c \
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 e6b8776..8c53096 100644
--- a/libbb/my_getgrgid.c
+++ b/libbb/my_getgrgid.c
@@ -19,8 +19,23 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+ /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more
+ * flexible :
+ *
+ * if bufsize is > 0 char *group cannot be set to NULL
+ * on success groupname is written on static allocated buffer
+ * on failure gid as string is written to buffer and NULL is returned
+ * if bufsize is = 0 char *group can be set to NULL
+ * on success groupname is returned
+ * on failure NULL is returned
+ * if bufsize is < 0 char *group can be set to NULL
+ * on success groupname 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"
@@ -33,10 +48,21 @@ char * my_getgrgid(char *group, long gid, int bufsize)
mygroup = getgrgid(gid);
if (mygroup==NULL) {
- snprintf(group, bufsize, "%ld", gid);
+ if(bufsize > 0) {
+ assert(group != NULL);
+ snprintf(group, bufsize, "%ld", (long)gid);
+ }
+ if( bufsize < 0 ) {
+ bb_error_msg_and_die("unknown gid %ld", (long)gid);
+ }
return NULL;
} else {
- return safe_strncpy(group, mygroup->gr_name, bufsize);
+ if(bufsize > 0)
+ {
+ assert(group != NULL);
+ return safe_strncpy(group, mygroup->gr_name, bufsize);
+ }
+ return mygroup->gr_name;
}
}
diff --git a/libbb/my_getpwuid.c b/libbb/my_getpwuid.c
index 53f6c77..1e8b11a 100644
--- a/libbb/my_getpwuid.c
+++ b/libbb/my_getpwuid.c
@@ -19,8 +19,23 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+ /* 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 be set to NULL
+ * 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"
@@ -34,10 +49,21 @@ char * my_getpwuid(char *name, long uid, int bufsize)
myuser = getpwuid(uid);
if (myuser==NULL) {
- snprintf(name, bufsize, "%ld", (long)uid);
+ 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 {
- return safe_strncpy(name, myuser->pw_name, bufsize);
+ if(bufsize > 0 )
+ {
+ assert(name != NULL);
+ return safe_strncpy(name, myuser->pw_name, bufsize);
+ }
+ return myuser->pw_name;
}
}