Fix from Matt Kraai -- a better way to NULL terminate strings for the
my_* passwd and group routines. I should have thought of doing it this way...
This commit is contained in:
parent
77508b29fa
commit
bd193a42a5
@ -691,13 +691,11 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag,
|
|||||||
struct tm *tm = localtime (&(header.mtime));
|
struct tm *tm = localtime (&(header.mtime));
|
||||||
|
|
||||||
len=printf("%s ", mode_string(header.mode));
|
len=printf("%s ", mode_string(header.mode));
|
||||||
memset(buf, 0, 8*sizeof(char));
|
|
||||||
my_getpwuid(buf, header.uid);
|
my_getpwuid(buf, header.uid);
|
||||||
if (! *buf)
|
if (! *buf)
|
||||||
len+=printf("%d", header.uid);
|
len+=printf("%d", header.uid);
|
||||||
else
|
else
|
||||||
len+=printf("%s", buf);
|
len+=printf("%s", buf);
|
||||||
memset(buf, 0, 8*sizeof(char));
|
|
||||||
my_getgrgid(buf, header.gid);
|
my_getgrgid(buf, header.gid);
|
||||||
if (! *buf)
|
if (! *buf)
|
||||||
len+=printf("/%-d ", header.gid);
|
len+=printf("/%-d ", header.gid);
|
||||||
|
@ -31,12 +31,11 @@
|
|||||||
extern int id_main(int argc, char **argv)
|
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 user[9], group[9];
|
||||||
long gid;
|
long gid;
|
||||||
long pwnam, grnam;
|
long pwnam, grnam;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
cp = user = group = NULL;
|
|
||||||
gid = 0;
|
gid = 0;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ugr")) > 0) {
|
while ((opt = getopt(argc, argv, "ugr")) > 0) {
|
||||||
@ -57,11 +56,7 @@ extern int id_main(int argc, char **argv)
|
|||||||
|
|
||||||
if (no_user && no_group) usage(id_usage);
|
if (no_user && no_group) usage(id_usage);
|
||||||
|
|
||||||
user = argv[optind];
|
if (argv[optind] == NULL) {
|
||||||
|
|
||||||
if (user == NULL) {
|
|
||||||
user = xcalloc(9, sizeof(char));
|
|
||||||
group = xcalloc(9, sizeof(char));
|
|
||||||
if (print_real) {
|
if (print_real) {
|
||||||
my_getpwuid(user, getuid());
|
my_getpwuid(user, getuid());
|
||||||
my_getgrgid(group, getgid());
|
my_getgrgid(group, getgid());
|
||||||
@ -70,7 +65,8 @@ extern int id_main(int argc, char **argv)
|
|||||||
my_getgrgid(group, getegid());
|
my_getgrgid(group, getegid());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
group = xcalloc(9, sizeof(char));
|
strncpy(user, argv[optind], 8);
|
||||||
|
user[8] = '\0';
|
||||||
gid = my_getpwnamegid(user);
|
gid = my_getpwnamegid(user);
|
||||||
my_getgrgid(group, gid);
|
my_getgrgid(group, gid);
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
|
|
||||||
extern int logname_main(int argc, char **argv)
|
extern int logname_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *user = xmalloc(9);
|
char user[9];
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
usage(logname_usage);
|
usage(logname_usage);
|
||||||
|
|
||||||
my_getpwuid(user, geteuid());
|
my_getpwuid(user, geteuid());
|
||||||
if (user) {
|
if (*user) {
|
||||||
puts(user);
|
puts(user);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -600,13 +600,11 @@ int list_single(struct dnode *dn)
|
|||||||
break;
|
break;
|
||||||
case LIST_ID_NAME:
|
case LIST_ID_NAME:
|
||||||
#ifdef BB_FEATURE_LS_USERNAME
|
#ifdef BB_FEATURE_LS_USERNAME
|
||||||
memset(scratch, 0, sizeof(scratch));
|
|
||||||
my_getpwuid(scratch, dn->dstat.st_uid);
|
my_getpwuid(scratch, dn->dstat.st_uid);
|
||||||
if (*scratch)
|
if (*scratch)
|
||||||
fprintf(stdout, "%-8.8s ", scratch);
|
fprintf(stdout, "%-8.8s ", scratch);
|
||||||
else
|
else
|
||||||
fprintf(stdout, "%-8d ", dn->dstat.st_uid);
|
fprintf(stdout, "%-8d ", dn->dstat.st_uid);
|
||||||
memset(scratch, 0, sizeof(scratch));
|
|
||||||
my_getgrgid(scratch, dn->dstat.st_gid);
|
my_getgrgid(scratch, dn->dstat.st_gid);
|
||||||
if (*scratch)
|
if (*scratch)
|
||||||
fprintf(stdout, "%-8.8s", scratch);
|
fprintf(stdout, "%-8.8s", scratch);
|
||||||
|
@ -26,14 +26,14 @@
|
|||||||
|
|
||||||
extern int whoami_main(int argc, char **argv)
|
extern int whoami_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *user = xmalloc(9);
|
char user[9];
|
||||||
uid_t uid = geteuid();
|
uid_t uid = geteuid();
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
usage(whoami_usage);
|
usage(whoami_usage);
|
||||||
|
|
||||||
my_getpwuid(user, uid);
|
my_getpwuid(user, uid);
|
||||||
if (user) {
|
if (*user) {
|
||||||
puts(user);
|
puts(user);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
12
id.c
12
id.c
@ -31,12 +31,11 @@
|
|||||||
extern int id_main(int argc, char **argv)
|
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 user[9], group[9];
|
||||||
long gid;
|
long gid;
|
||||||
long pwnam, grnam;
|
long pwnam, grnam;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
cp = user = group = NULL;
|
|
||||||
gid = 0;
|
gid = 0;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ugr")) > 0) {
|
while ((opt = getopt(argc, argv, "ugr")) > 0) {
|
||||||
@ -57,11 +56,7 @@ extern int id_main(int argc, char **argv)
|
|||||||
|
|
||||||
if (no_user && no_group) usage(id_usage);
|
if (no_user && no_group) usage(id_usage);
|
||||||
|
|
||||||
user = argv[optind];
|
if (argv[optind] == NULL) {
|
||||||
|
|
||||||
if (user == NULL) {
|
|
||||||
user = xcalloc(9, sizeof(char));
|
|
||||||
group = xcalloc(9, sizeof(char));
|
|
||||||
if (print_real) {
|
if (print_real) {
|
||||||
my_getpwuid(user, getuid());
|
my_getpwuid(user, getuid());
|
||||||
my_getgrgid(group, getgid());
|
my_getgrgid(group, getgid());
|
||||||
@ -70,7 +65,8 @@ extern int id_main(int argc, char **argv)
|
|||||||
my_getgrgid(group, getegid());
|
my_getgrgid(group, getegid());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
group = xcalloc(9, sizeof(char));
|
strncpy(user, argv[optind], 8);
|
||||||
|
user[8] = '\0';
|
||||||
gid = my_getpwnamegid(user);
|
gid = my_getpwnamegid(user);
|
||||||
my_getgrgid(group, gid);
|
my_getgrgid(group, gid);
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
|
|
||||||
extern int logname_main(int argc, char **argv)
|
extern int logname_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *user = xmalloc(9);
|
char user[9];
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
usage(logname_usage);
|
usage(logname_usage);
|
||||||
|
|
||||||
my_getpwuid(user, geteuid());
|
my_getpwuid(user, geteuid());
|
||||||
if (user) {
|
if (*user) {
|
||||||
puts(user);
|
puts(user);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
2
ls.c
2
ls.c
@ -600,13 +600,11 @@ int list_single(struct dnode *dn)
|
|||||||
break;
|
break;
|
||||||
case LIST_ID_NAME:
|
case LIST_ID_NAME:
|
||||||
#ifdef BB_FEATURE_LS_USERNAME
|
#ifdef BB_FEATURE_LS_USERNAME
|
||||||
memset(scratch, 0, sizeof(scratch));
|
|
||||||
my_getpwuid(scratch, dn->dstat.st_uid);
|
my_getpwuid(scratch, dn->dstat.st_uid);
|
||||||
if (*scratch)
|
if (*scratch)
|
||||||
fprintf(stdout, "%-8.8s ", scratch);
|
fprintf(stdout, "%-8.8s ", scratch);
|
||||||
else
|
else
|
||||||
fprintf(stdout, "%-8d ", dn->dstat.st_uid);
|
fprintf(stdout, "%-8d ", dn->dstat.st_uid);
|
||||||
memset(scratch, 0, sizeof(scratch));
|
|
||||||
my_getgrgid(scratch, dn->dstat.st_gid);
|
my_getgrgid(scratch, dn->dstat.st_gid);
|
||||||
if (*scratch)
|
if (*scratch)
|
||||||
fprintf(stdout, "%-8.8s", scratch);
|
fprintf(stdout, "%-8.8s", scratch);
|
||||||
|
13
procps/ps.c
13
procps/ps.c
@ -121,8 +121,8 @@ extern int ps_main(int argc, char **argv)
|
|||||||
FILE *file;
|
FILE *file;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
char path[32], sbuf[512];
|
char path[32], sbuf[512];
|
||||||
char uidName[10] = "";
|
char uidName[9];
|
||||||
char groupName[10] = "";
|
char groupName[9];
|
||||||
int len, i, c;
|
int len, i, c;
|
||||||
#ifdef BB_FEATURE_AUTOWIDTH
|
#ifdef BB_FEATURE_AUTOWIDTH
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
struct winsize win = { 0, 0, 0, 0 };
|
||||||
@ -146,9 +146,6 @@ extern int ps_main(int argc, char **argv)
|
|||||||
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
|
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
|
||||||
"State", "Command");
|
"State", "Command");
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
uidName[0] = '\0';
|
|
||||||
groupName[0] = '\0';
|
|
||||||
|
|
||||||
if (!isdigit(*entry->d_name))
|
if (!isdigit(*entry->d_name))
|
||||||
continue;
|
continue;
|
||||||
sprintf(path, "/proc/%s/status", entry->d_name);
|
sprintf(path, "/proc/%s/status", entry->d_name);
|
||||||
@ -204,8 +201,8 @@ extern int ps_main(int argc, char **argv)
|
|||||||
pid_t num_pids;
|
pid_t num_pids;
|
||||||
pid_t* pid_array = NULL;
|
pid_t* pid_array = NULL;
|
||||||
struct pid_info info;
|
struct pid_info info;
|
||||||
char uidName[10] = "";
|
char uidName[9];
|
||||||
char groupName[10] = "";
|
char groupName[9];
|
||||||
#ifdef BB_FEATURE_AUTOWIDTH
|
#ifdef BB_FEATURE_AUTOWIDTH
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
struct winsize win = { 0, 0, 0, 0 };
|
||||||
int terminal_width = TERMINAL_WIDTH;
|
int terminal_width = TERMINAL_WIDTH;
|
||||||
@ -247,8 +244,6 @@ extern int ps_main(int argc, char **argv)
|
|||||||
"State", "Command");
|
"State", "Command");
|
||||||
|
|
||||||
for (i=1; i<pid_array[0] ; i++) {
|
for (i=1; i<pid_array[0] ; i++) {
|
||||||
uidName[0] = '\0';
|
|
||||||
groupName[0] = '\0';
|
|
||||||
info.pid = pid_array[i];
|
info.pid = pid_array[i];
|
||||||
|
|
||||||
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
|
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
|
||||||
|
13
ps.c
13
ps.c
@ -121,8 +121,8 @@ extern int ps_main(int argc, char **argv)
|
|||||||
FILE *file;
|
FILE *file;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
char path[32], sbuf[512];
|
char path[32], sbuf[512];
|
||||||
char uidName[10] = "";
|
char uidName[9];
|
||||||
char groupName[10] = "";
|
char groupName[9];
|
||||||
int len, i, c;
|
int len, i, c;
|
||||||
#ifdef BB_FEATURE_AUTOWIDTH
|
#ifdef BB_FEATURE_AUTOWIDTH
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
struct winsize win = { 0, 0, 0, 0 };
|
||||||
@ -146,9 +146,6 @@ extern int ps_main(int argc, char **argv)
|
|||||||
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
|
fprintf(stdout, "%5s %-8s %-3s %5s %s\n", "PID", "Uid", "Gid",
|
||||||
"State", "Command");
|
"State", "Command");
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
uidName[0] = '\0';
|
|
||||||
groupName[0] = '\0';
|
|
||||||
|
|
||||||
if (!isdigit(*entry->d_name))
|
if (!isdigit(*entry->d_name))
|
||||||
continue;
|
continue;
|
||||||
sprintf(path, "/proc/%s/status", entry->d_name);
|
sprintf(path, "/proc/%s/status", entry->d_name);
|
||||||
@ -204,8 +201,8 @@ extern int ps_main(int argc, char **argv)
|
|||||||
pid_t num_pids;
|
pid_t num_pids;
|
||||||
pid_t* pid_array = NULL;
|
pid_t* pid_array = NULL;
|
||||||
struct pid_info info;
|
struct pid_info info;
|
||||||
char uidName[10] = "";
|
char uidName[9];
|
||||||
char groupName[10] = "";
|
char groupName[9];
|
||||||
#ifdef BB_FEATURE_AUTOWIDTH
|
#ifdef BB_FEATURE_AUTOWIDTH
|
||||||
struct winsize win = { 0, 0, 0, 0 };
|
struct winsize win = { 0, 0, 0, 0 };
|
||||||
int terminal_width = TERMINAL_WIDTH;
|
int terminal_width = TERMINAL_WIDTH;
|
||||||
@ -247,8 +244,6 @@ extern int ps_main(int argc, char **argv)
|
|||||||
"State", "Command");
|
"State", "Command");
|
||||||
|
|
||||||
for (i=1; i<pid_array[0] ; i++) {
|
for (i=1; i<pid_array[0] ; i++) {
|
||||||
uidName[0] = '\0';
|
|
||||||
groupName[0] = '\0';
|
|
||||||
info.pid = pid_array[i];
|
info.pid = pid_array[i];
|
||||||
|
|
||||||
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
|
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
|
||||||
|
2
tar.c
2
tar.c
@ -691,13 +691,11 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag,
|
|||||||
struct tm *tm = localtime (&(header.mtime));
|
struct tm *tm = localtime (&(header.mtime));
|
||||||
|
|
||||||
len=printf("%s ", mode_string(header.mode));
|
len=printf("%s ", mode_string(header.mode));
|
||||||
memset(buf, 0, 8*sizeof(char));
|
|
||||||
my_getpwuid(buf, header.uid);
|
my_getpwuid(buf, header.uid);
|
||||||
if (! *buf)
|
if (! *buf)
|
||||||
len+=printf("%d", header.uid);
|
len+=printf("%d", header.uid);
|
||||||
else
|
else
|
||||||
len+=printf("%s", buf);
|
len+=printf("%s", buf);
|
||||||
memset(buf, 0, 8*sizeof(char));
|
|
||||||
my_getgrgid(buf, header.gid);
|
my_getgrgid(buf, header.gid);
|
||||||
if (! *buf)
|
if (! *buf)
|
||||||
len+=printf("/%-d ", header.gid);
|
len+=printf("/%-d ", header.gid);
|
||||||
|
@ -957,12 +957,14 @@ long my_getgrnam(char *name)
|
|||||||
/* gets a username given a uid */
|
/* gets a username given a uid */
|
||||||
void my_getpwuid(char *name, long uid)
|
void my_getpwuid(char *name, long uid)
|
||||||
{
|
{
|
||||||
|
name[0] = '\0';
|
||||||
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, long gid)
|
void my_getgrgid(char *group, long gid)
|
||||||
{
|
{
|
||||||
|
group[0] = '\0';
|
||||||
my_getid("/etc/group", group, gid, NULL);
|
my_getid("/etc/group", group, gid, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
whoami.c
4
whoami.c
@ -26,14 +26,14 @@
|
|||||||
|
|
||||||
extern int whoami_main(int argc, char **argv)
|
extern int whoami_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *user = xmalloc(9);
|
char user[9];
|
||||||
uid_t uid = geteuid();
|
uid_t uid = geteuid();
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
usage(whoami_usage);
|
usage(whoami_usage);
|
||||||
|
|
||||||
my_getpwuid(user, uid);
|
my_getpwuid(user, uid);
|
||||||
if (user) {
|
if (*user) {
|
||||||
puts(user);
|
puts(user);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user