Vodz' last_patch57:

Hi, Erik.

    my_getpw(uid/gid) and applets used it have problem:
    if username for uid not found, applets can`t detect it
    (but code pessent). Also "%8ld " format is bad:
    spaces not required (applets have self format
    or spec format (tar applet) and overflow for "id" applet...)
    This problem also pressent in stable version.
    Patch for unstable in attach.

    --w
    vodz
This commit is contained in:
Eric Andersen 2002-09-30 20:39:56 +00:00
parent a6f6e06107
commit 02e6ba91e8
9 changed files with 27 additions and 32 deletions

View File

@ -244,12 +244,10 @@ static inline int writeTarHeader(struct TarBallInfo *tbInfo,
TAR_MAGIC_LEN + TAR_VERSION_LEN);
/* Enter the user and group names (default to root if it fails) */
my_getpwuid(header.uname, statbuf->st_uid);
if (!*header.uname)
strcpy(header.uname, "root");
my_getgrgid(header.gname, statbuf->st_gid);
if (!*header.uname)
if (my_getpwuid(header.uname, statbuf->st_uid) == NULL)
strcpy(header.uname, "root");
if (my_getgrgid(header.gname, statbuf->st_gid) == NULL)
strcpy(header.gname, "root");
if (tbInfo->hlInfo) {
/* This is a hard link */

View File

@ -68,8 +68,7 @@ extern int id_main(int argc, char **argv)
my_getgrgid(group, getegid());
}
} else {
strncpy(user, argv[optind], 8);
user[8] = '\0';
safe_strncpy(user, argv[optind], sizeof(user));
gid = my_getpwnamegid(user);
my_getgrgid(group, gid);
}
@ -78,12 +77,12 @@ extern int id_main(int argc, char **argv)
grnam=my_getgrnam(group);
if (no_group) {
if(name_not_number && user)
if(name_not_number)
puts(user);
else
printf("%ld\n", pwnam);
} else if (no_user) {
if(name_not_number && group)
if(name_not_number)
puts(group);
else
printf("%ld\n", grnam);

View File

@ -32,8 +32,7 @@ extern int logname_main(int argc, char **argv)
if (argc > 1)
show_usage();
my_getpwuid(user, geteuid());
if (*user) {
if (my_getpwuid(user, geteuid())) {
puts(user);
return EXIT_SUCCESS;
}

View File

@ -35,8 +35,7 @@ extern int whoami_main(int argc, char **argv)
if (argc > 1)
show_usage();
my_getpwuid(user, uid);
if (*user) {
if (my_getpwuid(user, uid)) {
puts(user);
return EXIT_SUCCESS;
}

View File

@ -165,8 +165,8 @@ extern unsigned long parse_number(const char *numstr,
* increases target size and is often not needed embedded systems. */
extern long my_getpwnam(const char *name);
extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
extern char * my_getpwuid(char *name, long uid);
extern char * my_getgrgid(char *group, long gid);
extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);

View File

@ -27,15 +27,17 @@
/* gets a groupname given a gid */
void my_getgrgid(char *group, long gid)
char * my_getgrgid(char *group, long gid)
{
struct group *mygroup;
mygroup = getgrgid(gid);
if (mygroup==NULL)
sprintf(group, "%-8ld ", (long)gid);
else
strcpy(group, mygroup->gr_name);
if (mygroup==NULL) {
sprintf(group, "%ld", gid);
return NULL;
} else {
return strcpy(group, mygroup->gr_name);
}
}

View File

@ -28,15 +28,17 @@
/* gets a username given a uid */
void my_getpwuid(char *name, long uid)
char * my_getpwuid(char *name, long uid)
{
struct passwd *myuser;
myuser = getpwuid(uid);
if (myuser==NULL)
sprintf(name, "%-8ld ", (long)uid);
else
strcpy(name, myuser->pw_name);
if (myuser==NULL) {
sprintf(name, "%ld", (long)uid);
return NULL;
} else {
return strcpy(name, myuser->pw_name);
}
}
/* END CODE */

View File

@ -150,8 +150,6 @@ extern int ps_main(int argc, char **argv)
/* Make some adjustments as needed */
my_getpwuid(uidName, p.ruid);
if (*uidName == '\0')
sprintf(uidName, "%d", p.ruid);
sprintf(path, "/proc/%s/cmdline", entry->d_name);
file = fopen(path, "r");
@ -243,8 +241,6 @@ extern int ps_main(int argc, char **argv)
/* Make some adjustments as needed */
my_getpwuid(uidName, info.euid);
if (*uidName == '\0')
sprintf(uidName, "%ld", info.euid);
if(p.vmsize == 0)
len = printf("%5d %-8s %c ", p.pid, uidName, p.state);

View File

@ -121,7 +121,7 @@ extern int logger_main(int argc, char **argv)
pri = pencode(optarg);
break;
case 't':
strncpy(name, optarg, sizeof(name));
safe_strncpy(name, optarg, sizeof(name));
break;
default:
show_usage();
@ -144,7 +144,7 @@ extern int logger_main(int argc, char **argv)
} while (c != EOF);
} else {
len = 1; /* for the '\0' */
message=xcalloc(1, 1);
message = xcalloc(1, 1);
for (i = optind; i < argc; i++) {
len += strlen(argv[i]);
len += 1; /* for the space between the args */
@ -152,7 +152,7 @@ extern int logger_main(int argc, char **argv)
strcat(message, argv[i]);
strcat(message, " ");
}
message[strlen(message)-1] = '\0';
message[strlen(message) - 2] = '\0';
syslog(pri, "%s", message);
}