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); TAR_MAGIC_LEN + TAR_VERSION_LEN);
/* Enter the user and group names (default to root if it fails) */ /* Enter the user and group names (default to root if it fails) */
my_getpwuid(header.uname, statbuf->st_uid); if (my_getpwuid(header.uname, statbuf->st_uid) == NULL)
if (!*header.uname)
strcpy(header.uname, "root");
my_getgrgid(header.gname, statbuf->st_gid);
if (!*header.uname)
strcpy(header.uname, "root"); strcpy(header.uname, "root");
if (my_getgrgid(header.gname, statbuf->st_gid) == NULL)
strcpy(header.gname, "root");
if (tbInfo->hlInfo) { if (tbInfo->hlInfo) {
/* This is a hard link */ /* This is a hard link */

View File

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

View File

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

View File

@ -35,8 +35,7 @@ extern int whoami_main(int argc, char **argv)
if (argc > 1) if (argc > 1)
show_usage(); show_usage();
my_getpwuid(user, uid); if (my_getpwuid(user, uid)) {
if (*user) {
puts(user); puts(user);
return EXIT_SUCCESS; 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. */ * increases target size and is often not needed embedded systems. */
extern long my_getpwnam(const char *name); extern long my_getpwnam(const char *name);
extern long my_getgrnam(const char *name); extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid); extern char * my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid); extern char * my_getgrgid(char *group, long gid);
extern long my_getpwnamegid(const char *name); extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode); extern int device_open(char *device, int mode);

View File

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

View File

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

View File

@ -150,8 +150,6 @@ extern int ps_main(int argc, char **argv)
/* Make some adjustments as needed */ /* Make some adjustments as needed */
my_getpwuid(uidName, p.ruid); my_getpwuid(uidName, p.ruid);
if (*uidName == '\0')
sprintf(uidName, "%d", p.ruid);
sprintf(path, "/proc/%s/cmdline", entry->d_name); sprintf(path, "/proc/%s/cmdline", entry->d_name);
file = fopen(path, "r"); file = fopen(path, "r");
@ -243,8 +241,6 @@ extern int ps_main(int argc, char **argv)
/* Make some adjustments as needed */ /* Make some adjustments as needed */
my_getpwuid(uidName, info.euid); my_getpwuid(uidName, info.euid);
if (*uidName == '\0')
sprintf(uidName, "%ld", info.euid);
if(p.vmsize == 0) if(p.vmsize == 0)
len = printf("%5d %-8s %c ", p.pid, uidName, p.state); 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); pri = pencode(optarg);
break; break;
case 't': case 't':
strncpy(name, optarg, sizeof(name)); safe_strncpy(name, optarg, sizeof(name));
break; break;
default: default:
show_usage(); show_usage();
@ -144,7 +144,7 @@ extern int logger_main(int argc, char **argv)
} while (c != EOF); } while (c != EOF);
} else { } else {
len = 1; /* for the '\0' */ len = 1; /* for the '\0' */
message=xcalloc(1, 1); message = xcalloc(1, 1);
for (i = optind; i < argc; i++) { for (i = optind; i < argc; i++) {
len += strlen(argv[i]); len += strlen(argv[i]);
len += 1; /* for the space between the args */ 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, argv[i]);
strcat(message, " "); strcat(message, " ");
} }
message[strlen(message)-1] = '\0'; message[strlen(message) - 2] = '\0';
syslog(pri, "%s", message); syslog(pri, "%s", message);
} }