Some cleanups, based on a patch from Ken Chalmers

-Erik
This commit is contained in:
Eric Andersen 2000-07-28 16:22:51 +00:00
parent d5704686b1
commit 6150df320a
2 changed files with 26 additions and 20 deletions

View File

@ -2,7 +2,6 @@
/*
* Mini id implementation for busybox
*
*
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@ -33,7 +32,8 @@ extern int id_main(int argc, char **argv)
{
int no_user = 0, no_group = 0, print_real = 0;
char *cp, *user, *group;
unsigned long gid;
long gid;
long pwnam, grnam;
int opt;
cp = user = group = NULL;
@ -59,8 +59,8 @@ extern int id_main(int argc, char **argv)
user = argv[optind];
if (user == NULL) {
user = xmalloc(9);
group = xmalloc(9);
user = xcalloc(9, sizeof(char));
group = xcalloc(9, sizeof(char));
if (print_real) {
my_getpwuid(user, getuid());
my_getgrgid(group, getgid());
@ -69,19 +69,22 @@ extern int id_main(int argc, char **argv)
my_getgrgid(group, getegid());
}
} else {
group = xmalloc(9);
group = xcalloc(9, sizeof(char));
gid = my_getpwnamegid(user);
my_getgrgid(group, gid);
}
pwnam=my_getpwnam(user);
grnam=my_getgrnam(group);
if (gid == -1 || pwnam==-1 || grnam==-1) {
fatalError("%s: No such user\n", user);
}
if (no_group)
printf("%lu\n", my_getpwnam(user));
printf("%ld\n", pwnam);
else if (no_user)
printf("%lu\n", my_getgrnam(group));
printf("%ld\n", grnam);
else
printf("uid=%lu(%s) gid=%lu(%s)\n",
my_getpwnam(user), user, my_getgrnam(group), group);
printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
return(0);
}

23
id.c
View File

@ -2,7 +2,6 @@
/*
* Mini id implementation for busybox
*
*
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@ -33,7 +32,8 @@ extern int id_main(int argc, char **argv)
{
int no_user = 0, no_group = 0, print_real = 0;
char *cp, *user, *group;
unsigned long gid;
long gid;
long pwnam, grnam;
int opt;
cp = user = group = NULL;
@ -59,8 +59,8 @@ extern int id_main(int argc, char **argv)
user = argv[optind];
if (user == NULL) {
user = xmalloc(9);
group = xmalloc(9);
user = xcalloc(9, sizeof(char));
group = xcalloc(9, sizeof(char));
if (print_real) {
my_getpwuid(user, getuid());
my_getgrgid(group, getgid());
@ -69,19 +69,22 @@ extern int id_main(int argc, char **argv)
my_getgrgid(group, getegid());
}
} else {
group = xmalloc(9);
group = xcalloc(9, sizeof(char));
gid = my_getpwnamegid(user);
my_getgrgid(group, gid);
}
pwnam=my_getpwnam(user);
grnam=my_getgrnam(group);
if (gid == -1 || pwnam==-1 || grnam==-1) {
fatalError("%s: No such user\n", user);
}
if (no_group)
printf("%lu\n", my_getpwnam(user));
printf("%ld\n", pwnam);
else if (no_user)
printf("%lu\n", my_getgrnam(group));
printf("%ld\n", grnam);
else
printf("uid=%lu(%s) gid=%lu(%s)\n",
my_getpwnam(user), user, my_getgrnam(group), group);
printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
return(0);
}