mirror of
https://github.com/sheumann/hush.git
synced 2024-08-20 19:29:02 +00:00
ls: use get_cached_username/groupname
This commit is contained in:
parent
9af7c9d6b6
commit
2405ad659e
@ -291,7 +291,7 @@ static void dfree(struct dnode **dnp, int nfiles)
|
|||||||
free(dnp); /* free the array holding the dnode pointers */
|
free(dnp); /* free the array holding the dnode pointers */
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define dfree(...) do {} while (0)
|
#define dfree(...) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
|
static struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
|
||||||
@ -375,7 +375,7 @@ static void dnsort(struct dnode **dn, int size)
|
|||||||
qsort(dn, size, sizeof(*dn), sortcmp);
|
qsort(dn, size, sizeof(*dn), sortcmp);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define dnsort(dn, size) do {} while (0)
|
#define dnsort(dn, size) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -541,9 +541,6 @@ static int list_single(struct dnode *dn)
|
|||||||
{
|
{
|
||||||
int i, column = 0;
|
int i, column = 0;
|
||||||
|
|
||||||
#if ENABLE_FEATURE_LS_USERNAME
|
|
||||||
char scratch[16];
|
|
||||||
#endif
|
|
||||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||||
char *filetime;
|
char *filetime;
|
||||||
time_t ttime, age;
|
time_t ttime, age;
|
||||||
@ -584,10 +581,9 @@ static int list_single(struct dnode *dn)
|
|||||||
break;
|
break;
|
||||||
case LIST_ID_NAME:
|
case LIST_ID_NAME:
|
||||||
#if ENABLE_FEATURE_LS_USERNAME
|
#if ENABLE_FEATURE_LS_USERNAME
|
||||||
bb_getpwuid(scratch, dn->dstat.st_uid, sizeof(scratch));
|
printf("%-8.8s %-8.8s",
|
||||||
printf("%-8.8s ", scratch);
|
get_cached_username(dn->dstat.st_uid),
|
||||||
bb_getgrgid(scratch, dn->dstat.st_gid, sizeof(scratch));
|
get_cached_groupname(dn->dstat.st_gid));
|
||||||
printf("%-8.8s", scratch);
|
|
||||||
column += 17;
|
column += 17;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -223,7 +223,6 @@ struct sysinfo {
|
|||||||
extern int sysinfo(struct sysinfo* info);
|
extern int sysinfo(struct sysinfo* info);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern void chomp(char *s);
|
extern void chomp(char *s);
|
||||||
extern void trim(char *s);
|
extern void trim(char *s);
|
||||||
extern char *skip_whitespace(const char *);
|
extern char *skip_whitespace(const char *);
|
||||||
@ -410,20 +409,26 @@ uint16_t xatou16(const char *numstr);
|
|||||||
/* These parse entries in /etc/passwd and /etc/group. This is desirable
|
/* These parse entries in /etc/passwd and /etc/group. This is desirable
|
||||||
* for BusyBox since we want to avoid using the glibc NSS stuff, which
|
* for BusyBox since we want to avoid using the glibc NSS stuff, which
|
||||||
* increases target size and is often not needed on embedded systems. */
|
* increases target size and is often not needed on embedded systems. */
|
||||||
extern long xuname2uid(const char *name);
|
long xuname2uid(const char *name);
|
||||||
extern long xgroup2gid(const char *name);
|
long xgroup2gid(const char *name);
|
||||||
/* wrapper: allows string to contain numeric uid or gid */
|
/* wrapper: allows string to contain numeric uid or gid */
|
||||||
extern unsigned long get_ug_id(const char *s, long (*xname2id)(const char *));
|
unsigned long get_ug_id(const char *s, long (*xname2id)(const char *));
|
||||||
/* from chpst. Does not die, returns 0 on failure */
|
/* from chpst. Does not die, returns 0 on failure */
|
||||||
struct bb_uidgid_t {
|
struct bb_uidgid_t {
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
};
|
};
|
||||||
extern int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok);
|
int get_uidgid(struct bb_uidgid_t*, const char*, int numeric_ok);
|
||||||
/* what is this? */
|
/* what is this? */
|
||||||
/*extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);*/
|
/*extern char *bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix);*/
|
||||||
extern char *bb_getpwuid(char *name, long uid, int bufsize);
|
char *bb_getpwuid(char *name, long uid, int bufsize);
|
||||||
extern char *bb_getgrgid(char *group, long gid, int bufsize);
|
char *bb_getgrgid(char *group, long gid, int bufsize);
|
||||||
|
/* versions which cache results (useful for ps, ls etc) */
|
||||||
|
const char* get_cached_username(uid_t uid);
|
||||||
|
const char* get_cached_groupname(gid_t gid);
|
||||||
|
void clear_username_cache(void);
|
||||||
|
/* internally usernames are saved in fixed-sized char[] buffers */
|
||||||
|
enum { USERNAME_MAX_SIZE = 16 - sizeof(int) };
|
||||||
|
|
||||||
|
|
||||||
enum { BB_GETOPT_ERROR = 0x80000000 };
|
enum { BB_GETOPT_ERROR = 0x80000000 };
|
||||||
@ -626,9 +631,6 @@ void free_procps_scan(procps_status_t* sp);
|
|||||||
procps_status_t* procps_scan(procps_status_t* sp, int flags);
|
procps_status_t* procps_scan(procps_status_t* sp, int flags);
|
||||||
pid_t *find_pid_by_name(const char* procName);
|
pid_t *find_pid_by_name(const char* procName);
|
||||||
pid_t *pidlist_reverse(pid_t *pidList);
|
pid_t *pidlist_reverse(pid_t *pidList);
|
||||||
void clear_username_cache(void);
|
|
||||||
const char* get_cached_username(uid_t uid);
|
|
||||||
const char* get_cached_groupname(gid_t gid);
|
|
||||||
|
|
||||||
|
|
||||||
extern const char bb_uuenc_tbl_base64[];
|
extern const char bb_uuenc_tbl_base64[];
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
typedef struct unsigned_to_name_map_t {
|
typedef struct unsigned_to_name_map_t {
|
||||||
unsigned id;
|
unsigned id;
|
||||||
char name[12];
|
char name[USERNAME_MAX_SIZE];
|
||||||
} unsigned_to_name_map_t;
|
} unsigned_to_name_map_t;
|
||||||
|
|
||||||
typedef struct cache_t {
|
typedef struct cache_t {
|
||||||
@ -137,7 +137,7 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags)
|
|||||||
if (flags & PSSCAN_UIDGID) {
|
if (flags & PSSCAN_UIDGID) {
|
||||||
if (stat(filename, &sb))
|
if (stat(filename, &sb))
|
||||||
break;
|
break;
|
||||||
/* Need comment - is this effective or read UID/GID? */
|
/* Need comment - is this effective or real UID/GID? */
|
||||||
sp->uid = sb.st_uid;
|
sp->uid = sb.st_uid;
|
||||||
sp->gid = sb.st_gid;
|
sp->gid = sb.st_gid;
|
||||||
}
|
}
|
||||||
@ -209,7 +209,7 @@ procps_status_t* procps_scan(procps_status_t* sp, int flags)
|
|||||||
if ((unsigned char)(buf[n]) < ' ')
|
if ((unsigned char)(buf[n]) < ' ')
|
||||||
buf[n] = ' ';
|
buf[n] = ' ';
|
||||||
} while (n);
|
} while (n);
|
||||||
sp->cmd = strdup(buf);
|
sp->cmd = xstrdup(buf);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user