Some more portability updates

-Erik
This commit is contained in:
Erik Andersen 2000-05-17 05:24:24 +00:00
parent 499f65fb98
commit 5b46d792f1
5 changed files with 25 additions and 25 deletions

View File

@ -32,8 +32,8 @@
#include <pwd.h> #include <pwd.h>
static uid_t uid = -1; static unsigned long uid = -1;
static gid_t gid = -1; static unsigned long gid = -1;
static int whichApp; static int whichApp;
static char *invocationName = NULL; static char *invocationName = NULL;
static char *theMode = NULL; static char *theMode = NULL;

View File

@ -43,7 +43,7 @@ extern int id_main(int argc, char **argv)
{ {
int no_user = 0, no_group = 0, print_real = 0; int no_user = 0, no_group = 0, print_real = 0;
char *cp, *user, *group; char *cp, *user, *group;
gid_t gid; unsigned long gid;
cp = user = group = NULL; cp = user = group = NULL;
@ -82,10 +82,10 @@ extern int id_main(int argc, char **argv)
my_getgrgid(group, gid); my_getgrgid(group, gid);
} }
if (no_group) printf("%u\n", my_getpwnam(user)); if (no_group) printf("%lu\n", my_getpwnam(user));
else if (no_user) printf("%u\n", my_getgrnam(group)); else if (no_user) printf("%lu\n", my_getgrnam(group));
else else
printf("uid=%u(%s) gid=%u(%s)\n", printf("uid=%lu(%s) gid=%lu(%s)\n",
my_getpwnam(user), user, my_getgrnam(group), group); my_getpwnam(user), user, my_getgrnam(group), group);

8
id.c
View File

@ -43,7 +43,7 @@ extern int id_main(int argc, char **argv)
{ {
int no_user = 0, no_group = 0, print_real = 0; int no_user = 0, no_group = 0, print_real = 0;
char *cp, *user, *group; char *cp, *user, *group;
gid_t gid; unsigned long gid;
cp = user = group = NULL; cp = user = group = NULL;
@ -82,10 +82,10 @@ extern int id_main(int argc, char **argv)
my_getgrgid(group, gid); my_getgrgid(group, gid);
} }
if (no_group) printf("%u\n", my_getpwnam(user)); if (no_group) printf("%lu\n", my_getpwnam(user));
else if (no_user) printf("%u\n", my_getgrnam(group)); else if (no_user) printf("%lu\n", my_getgrnam(group));
else else
printf("uid=%u(%s) gid=%u(%s)\n", printf("uid=%lu(%s) gid=%lu(%s)\n",
my_getpwnam(user), user, my_getgrnam(group), group); my_getpwnam(user), user, my_getgrnam(group), group);

View File

@ -257,11 +257,11 @@ extern char *cstring_lineFromFile(FILE *f);
/* These parse entries in /etc/passwd and /etc/group. This is desirable /* These parse entries in /etc/passwd and /etc/group. This is desirable
* for BusyBox since we want to avoid using the glibc NSS stuff, which * for BusyBox since we want to avoid using the glibc NSS stuff, which
* increases target size and is often not needed embedded systems. */ * increases target size and is often not needed embedded systems. */
extern uid_t my_getpwnam(char *name); extern unsigned long my_getpwnam(char *name);
extern gid_t my_getgrnam(char *name); extern unsigned long my_getgrnam(char *name);
extern void my_getpwuid(char *name, uid_t uid); extern void my_getpwuid(char *name, unsigned long uid);
extern void my_getgrgid(char *group, gid_t gid); extern void my_getgrgid(char *group, unsigned long gid);
extern gid_t my_getpwnamegid(char *name); extern unsigned long my_getpwnamegid(char *name);
#if defined BB_INIT || defined BB_SYSLOGD #if defined BB_INIT || defined BB_SYSLOGD

View File

@ -797,12 +797,12 @@ extern int parse_mode(const char *s, mode_t * theMode)
* This uses buf as storage to hold things. * This uses buf as storage to hold things.
* *
*/ */
uid_t my_getid(const char *filename, char *name, uid_t id, gid_t *gid) unsigned long my_getid(const char *filename, char *name, unsigned long id, unsigned long *gid)
{ {
FILE *file; FILE *file;
char *rname, *start, *end, buf[128]; char *rname, *start, *end, buf[128];
id_t rid; id_t rid;
gid_t rgid = 0; unsigned long rgid = 0;
file = fopen(filename, "r"); file = fopen(filename, "r");
if (file == NULL) { if (file == NULL) {
@ -830,13 +830,13 @@ uid_t my_getid(const char *filename, char *name, uid_t id, gid_t *gid)
/* uid in passwd, gid in group */ /* uid in passwd, gid in group */
start = end + 1; start = end + 1;
rid = (uid_t) strtol(start, &end, 10); rid = (unsigned long) strtol(start, &end, 10);
if (end == start) if (end == start)
continue; continue;
/* gid in passwd */ /* gid in passwd */
start = end + 1; start = end + 1;
rgid = (gid_t) strtol(start, &end, 10); rgid = (unsigned long) strtol(start, &end, 10);
if (name) { if (name) {
if (0 == strcmp(rname, name)) { if (0 == strcmp(rname, name)) {
@ -857,33 +857,33 @@ uid_t my_getid(const char *filename, char *name, uid_t id, gid_t *gid)
} }
/* returns a uid given a username */ /* returns a uid given a username */
uid_t my_getpwnam(char *name) unsigned long my_getpwnam(char *name)
{ {
return my_getid("/etc/passwd", name, -1, NULL); return my_getid("/etc/passwd", name, -1, NULL);
} }
/* returns a gid given a group name */ /* returns a gid given a group name */
gid_t my_getgrnam(char *name) unsigned long my_getgrnam(char *name)
{ {
return my_getid("/etc/group", name, -1, NULL); return my_getid("/etc/group", name, -1, NULL);
} }
/* gets a username given a uid */ /* gets a username given a uid */
void my_getpwuid(char *name, uid_t uid) void my_getpwuid(char *name, unsigned long uid)
{ {
my_getid("/etc/passwd", name, uid, NULL); my_getid("/etc/passwd", name, uid, NULL);
} }
/* gets a groupname given a gid */ /* gets a groupname given a gid */
void my_getgrgid(char *group, gid_t gid) void my_getgrgid(char *group, unsigned long gid)
{ {
my_getid("/etc/group", group, gid, NULL); my_getid("/etc/group", group, gid, NULL);
} }
/* gets a gid given a user name */ /* gets a gid given a user name */
gid_t my_getpwnamegid(char *name) unsigned long my_getpwnamegid(char *name)
{ {
gid_t gid; unsigned long gid;
my_getid("/etc/passwd", name, -1, &gid); my_getid("/etc/passwd", name, -1, &gid);
return gid; return gid;
} }