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
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 */
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);
}
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);
if (argc > 1)
show_usage();
- my_getpwuid(user, geteuid());
- if (*user) {
+ if (my_getpwuid(user, geteuid())) {
puts(user);
return EXIT_SUCCESS;
}
if (argc > 1)
show_usage();
- my_getpwuid(user, uid);
- if (*user) {
+ if (my_getpwuid(user, uid)) {
puts(user);
return EXIT_SUCCESS;
}
* 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);
/* 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);
+ }
}
/* 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 */
/* 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");
/* 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);
pri = pencode(optarg);
break;
case 't':
- strncpy(name, optarg, sizeof(name));
+ safe_strncpy(name, optarg, sizeof(name));
break;
default:
show_usage();
} 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 */
strcat(message, argv[i]);
strcat(message, " ");
}
- message[strlen(message)-1] = '\0';
+ message[strlen(message) - 2] = '\0';
syslog(pri, "%s", message);
}