Decode UID/GID in -y mode

* defs.h (RVAL_UID, RVAL_GID): New macro constants.
(printgid): New function declaration.
* ipc_msgctl.c (print_msqid_ds, print_msqid_ds): Use printgid for
printing GID.
* ipc_shmctl.c (print_shmid_ds, print_shmid_ds): Likewise.
* keyctl.c (keyctl_chown_key): Likewise.
* nlattr.c (decode_nla_gid): Likewise.
* linux/dummy.h (sys_getgid, sys_getgid16, sys_getresgid,
sys_getresgid16, sys_setfsgid, sys_setfsgid16, sys_setgid, sys_setgid16,
sys_setregid, sys_setregid16, sys_setresgid, sys_setresgid16): Remove
macros.
(sys_getegid): Define to sys_getgid instead of sys_getuid.
(sys_getegid16): Define to sys_getgid16 instead of sys_geteuid16.
* linux/syscall.h (getresgid16, getgid16, setfsgid16, setresgid16,
setregid16, setgid16): New external SYS_FUNC declarations.
* msghdr.c (print_scm_creds); Use PRINT_FIELD_GID for printing GID.
* net.c (print_get_ucred): Likewise.
* netlink_inet_diag.c (decode_inet_diag_msg): Likewise.
* netlink_smc_diag.c (decode_smc_diag_msg): Likewise.
* print_fields.h (PRINT_FIELD_UID); Use printuid for printing UID.
(PRINT_FIELD_GID): New macro.
* print_struct_stat.c (print_struct_stat): Use printuid for printing
UID, printgid for printing GID.
* printsiginfo.c (printsigsource): Use printuid for printing UID.
* resource.c (print_priority_who): New function.
(SYS_FUNC(getpriority), SYS_FUNC(setpriority)): Use print_priority_who
for printing the second argument.
* statx.c (SYS_FUNC(statx)): Use PRINT_FIELD_UID for printing UID,
PRINT_FIELD_GID for printing GID.
* syscall.c (syscall_exiting_trace): Handle RVAL_UID and RVAL_GID.
* tests/overflowuid.c: Include stdio.h.
(printuid): New function.
* tests/setfsugid.c (printugid): Rename from printuid, update call
sites.
* tests/setgroups.c: Likewise.
* tests/setugid.c: Likewise.
* tests/tests.h (printuid): New declaration.
* uid.c (printgid, sys_getresgid, sys_getgid, sys_setfsgid,
sys_setresgid, sys_setregid, sys_setgid): Add SIZEIFY wrappers.
(gid_t, gid_t_, gid_t__): Define similarly to uid_t, uid_t_, uid_t__.
Include grp.h, pwd.h, sys/types.h.
(enum id_type): New enumeration.
(SYS_FUNC(getuid), SYS_FUNC(setfsuid), ): Return RVAL_UID flag.
(SYS_FUNC(getgid), SYS_FUNC(setfsgid), SYS_FUNC(setgid),
SYS_FUNC(getresgid), SYS_FUNC(setregid), SYS_FUNC(setresgid)): New
functions.
(get_print_id): Rename from get_print_uid, add idt argument, call
printuid or printgid depending on it. Update call sites.
(SYS_FUNC(chown), SYS_FUNC(fchown), print_gid): Use printgid
for printing GID.
(ID_CACHE_SIZE): New macro constant.
(print_id): New function.
(printuid): Implement using print_id.
(printgid): New function.
* xlat/priorities.in: Provide fallback values.
This commit is contained in:
Eugene Syromyatnikov 2018-10-26 02:18:41 +02:00
parent ce366255c5
commit e6e005f70c
24 changed files with 257 additions and 76 deletions

3
defs.h
View File

@ -351,6 +351,8 @@ extern const struct xlat whence_codes[];
#define RVAL_HEX 001 /* hex format */
#define RVAL_OCTAL 002 /* octal format */
#define RVAL_FD 010 /* file descriptor */
#define RVAL_UID 011 /* UID */
#define RVAL_GID 012 /* GID */
#define RVAL_MASK 013 /* mask for these values */
#define RVAL_STR 020 /* Print `auxstr' field after return val */
@ -889,6 +891,7 @@ extern int
decode_sockaddr(struct tcb *, kernel_ulong_t addr, int addrlen);
extern void printuid(const char *, const unsigned int);
extern void printgid(const char *, const unsigned int);
extern void
print_sigset_addr_len(struct tcb *, kernel_ulong_t addr, kernel_ulong_t len);

View File

@ -66,7 +66,7 @@ print_msqid_ds(struct tcb *const tcp, const kernel_ulong_t addr, int cmd)
tprints("{msg_perm={");
printuid("uid=", msqid_ds.msg_perm.uid);
printuid(", gid=", msqid_ds.msg_perm.gid);
printgid(", gid=", msqid_ds.msg_perm.gid);
tprints(", mode=");
print_numeric_umode_t(msqid_ds.msg_perm.mode);
@ -77,7 +77,7 @@ print_msqid_ds(struct tcb *const tcp, const kernel_ulong_t addr, int cmd)
tprintf(", key=%u", (unsigned) msqid_ds.msg_perm.__key);
printuid(", cuid=", msqid_ds.msg_perm.cuid);
printuid(", cgid=", msqid_ds.msg_perm.cgid);
printgid(", cgid=", msqid_ds.msg_perm.cgid);
tprints("}");
tprintf(", msg_stime=%u", (unsigned) msqid_ds.msg_stime);
tprintf(", msg_rtime=%u", (unsigned) msqid_ds.msg_rtime);

View File

@ -66,7 +66,7 @@ print_shmid_ds(struct tcb *const tcp, const kernel_ulong_t addr, int cmd)
tprints("{shm_perm={");
printuid("uid=", shmid_ds.shm_perm.uid);
printuid(", gid=", shmid_ds.shm_perm.gid);
printgid(", gid=", shmid_ds.shm_perm.gid);
tprints(", mode=");
print_numeric_umode_t(shmid_ds.shm_perm.mode);
@ -77,7 +77,7 @@ print_shmid_ds(struct tcb *const tcp, const kernel_ulong_t addr, int cmd)
tprintf(", key=%u", (unsigned) shmid_ds.shm_perm.__key);
printuid(", cuid=", shmid_ds.shm_perm.cuid);
printuid(", cgid=", shmid_ds.shm_perm.cgid);
printgid(", cgid=", shmid_ds.shm_perm.cgid);
tprints("}");
tprintf(", shm_segsz=%u", (unsigned) shmid_ds.shm_segsz);
tprintf(", shm_cpid=%u", (unsigned) shmid_ds.shm_cpid);

View File

@ -147,7 +147,7 @@ keyctl_chown_key(struct tcb *tcp, key_serial_t id, unsigned user,
{
print_keyring_serial_number(id);
printuid(", ", user);
printuid(", ", group);
printgid(", ", group);
}
static void

View File

@ -64,15 +64,11 @@
#define sys_fchdir sys_close
#define sys_fdatasync sys_close
#define sys_fsync sys_close
#define sys_getegid sys_getuid
#define sys_getegid16 sys_geteuid16
#define sys_getegid sys_getgid
#define sys_getegid16 sys_getgid16
#define sys_geteuid sys_getuid
#define sys_geteuid16 sys_getuid16
#define sys_getgid sys_getuid
#define sys_getgid16 sys_getuid16
#define sys_getpeername sys_getsockname
#define sys_getresgid sys_getresuid
#define sys_getresgid16 sys_getresuid16
#define sys_lstat sys_stat
#define sys_lstat64 sys_stat64
#define sys_mkdir sys_chmod
@ -86,14 +82,6 @@
#define sys_rmdir sys_chdir
#define sys_sched_get_priority_max sys_sched_get_priority_min
#define sys_setdomainname sys_sethostname
#define sys_setfsgid sys_setfsuid
#define sys_setfsgid16 sys_setfsuid16
#define sys_setgid sys_setuid
#define sys_setgid16 sys_setuid16
#define sys_setregid sys_setreuid
#define sys_setregid16 sys_setreuid16
#define sys_setresgid sys_setresuid
#define sys_setresgid16 sys_setresuid16
#define sys_swapoff sys_chdir
#define sys_symlink sys_link
#define sys_syncfs sys_close

View File

@ -38,12 +38,18 @@
extern SYS_FUNC(chown16);
extern SYS_FUNC(fchown16);
extern SYS_FUNC(getgroups16);
extern SYS_FUNC(getresgid16);
extern SYS_FUNC(getresuid16);
extern SYS_FUNC(getgid16);
extern SYS_FUNC(getuid16);
extern SYS_FUNC(setfsgid16);
extern SYS_FUNC(setfsuid16);
extern SYS_FUNC(setgroups16);
extern SYS_FUNC(setresgid16);
extern SYS_FUNC(setresuid16);
extern SYS_FUNC(setregid16);
extern SYS_FUNC(setreuid16);
extern SYS_FUNC(setgid16);
extern SYS_FUNC(setuid16);
#endif /* HAVE_ARCH_UID16_SYSCALLS */

View File

@ -88,7 +88,7 @@ print_scm_creds(struct tcb *tcp, const void *cmsg_data,
PRINT_FIELD_U("{", *uc, pid);
PRINT_FIELD_UID(", ", *uc, uid);
PRINT_FIELD_UID(", ", *uc, gid);
PRINT_FIELD_GID(", ", *uc, gid);
tprints("}");
}

2
net.c
View File

@ -677,7 +677,7 @@ print_get_ucred(struct tcb *const tcp, const kernel_ulong_t addr,
len,
QUOTE_FORCE_HEX);
} else {
PRINT_FIELD_UID(", ", uc, gid);
PRINT_FIELD_GID(", ", uc, gid);
}
}
}

View File

@ -457,7 +457,7 @@ DECL_NETLINK_DIAG_DECODER(decode_inet_diag_msg)
PRINT_FIELD_U(", ", msg, idiag_expires);
PRINT_FIELD_U(", ", msg, idiag_rqueue);
PRINT_FIELD_U(", ", msg, idiag_wqueue);
PRINT_FIELD_U(", ", msg, idiag_uid);
PRINT_FIELD_UID(", ", msg, idiag_uid);
PRINT_FIELD_U(", ", msg, idiag_inode);
decode_nla = true;
}

View File

@ -243,7 +243,7 @@ DECL_NETLINK_DIAG_DECODER(decode_smc_diag_msg)
* keeping the AF_INET sock address.
*/
PRINT_FIELD_INET_DIAG_SOCKID(", ", msg, id, AF_INET);
PRINT_FIELD_U(", ", msg, diag_uid);
PRINT_FIELD_UID(", ", msg, diag_uid);
PRINT_FIELD_U(", ", msg, diag_inode);
decode_nla = true;
}

View File

@ -260,7 +260,14 @@ decode_nla_gid(struct tcb *const tcp,
const unsigned int len,
const void *const opaque_data)
{
return decode_nla_uid(tcp, addr, len, opaque_data);
uint32_t gid;
if (len < sizeof(gid))
return false;
else if (!umove_or_printaddr(tcp, addr, &gid))
printgid("", gid);
return true;
}
bool

View File

@ -118,7 +118,10 @@
zero_extend_signed_to_ull((where_).field_)); \
} while (0)
#define PRINT_FIELD_UID PRINT_FIELD_ID
#define PRINT_FIELD_UID(prefix_, where_, field_) \
printuid(prefix_ #field_ "=", (where_).field_)
#define PRINT_FIELD_GID(prefix_, where_, field_) \
printgid(prefix_ #field_ "=", (where_).field_)
#define PRINT_FIELD_U64(prefix_, where_, field_) \
do { \

View File

@ -46,8 +46,9 @@ print_struct_stat(struct tcb *tcp, const struct strace_stat *const st)
print_dev_t(st->dev);
tprintf(", st_ino=%llu, st_mode=", st->ino);
print_symbolic_mode_t(st->mode);
tprintf(", st_nlink=%llu, st_uid=%llu, st_gid=%llu",
st->nlink, st->uid, st->gid);
tprintf(", st_nlink=%llu", st->nlink);
printuid(", st_uid=", st->uid);
printgid(", st_gid=", st->gid);
tprintf(", st_blksize=%llu", st->blksize);
tprintf(", st_blocks=%llu", st->blocks);
} else {

View File

@ -71,9 +71,8 @@
static void
printsigsource(const siginfo_t *sip)
{
tprintf(", si_pid=%u, si_uid=%u",
(unsigned int) sip->si_pid,
(unsigned int) sip->si_uid);
tprintf(", si_pid=%u", (unsigned int) sip->si_pid);
printuid(", si_uid=", (unsigned int) sip->si_uid);
}
static void

View File

@ -249,10 +249,19 @@ SYS_FUNC(osf_getrusage)
#include "xlat/priorities.h"
static void
print_priority_who(const char * prefix, int which, int who)
{
if (which == PRIO_USER && who)
printuid(prefix, who);
tprintf("%s%d", prefix, who);
}
SYS_FUNC(getpriority)
{
printxval(priorities, tcp->u_arg[0], "PRIO_???");
tprintf(", %d", (int) tcp->u_arg[1]);
print_priority_who(", ", tcp->u_arg[0], tcp->u_arg[1]);
return RVAL_DECODED;
}
@ -260,7 +269,8 @@ SYS_FUNC(getpriority)
SYS_FUNC(setpriority)
{
printxval(priorities, tcp->u_arg[0], "PRIO_???");
tprintf(", %d, %d", (int) tcp->u_arg[1], (int) tcp->u_arg[2]);
print_priority_who(", ", tcp->u_arg[0], tcp->u_arg[1]);
tprintf(", %d", (int) tcp->u_arg[2]);
return RVAL_DECODED;
}

View File

@ -79,8 +79,8 @@ SYS_FUNC(statx)
if (!abbrev(tcp)) {
PRINT_FIELD_U(", ", stx, stx_nlink);
printuid(", stx_uid=", stx.stx_uid);
printuid(", stx_gid=", stx.stx_gid);
PRINT_FIELD_UID(", ", stx, stx_uid);
PRINT_FIELD_GID(", ", stx, stx_gid);
}
tprints(", stx_mode=");

View File

@ -996,6 +996,14 @@ syscall_exiting_trace(struct tcb *tcp, struct timespec *ts, int res)
} else
tprintf("= %" PRI_kld, tcp->u_rval);
break;
case RVAL_UID:
case RVAL_GID:
if (show_fd_path)
((sys_res & RVAL_MASK) == RVAL_UID
? printuid : printgid)("= ", tcp->u_rval);
else
tprintf("= %" PRI_kld, tcp->u_rval);
break;
default:
error_msg("invalid rval format");
break;

View File

@ -28,6 +28,7 @@
#include "tests.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -93,3 +94,11 @@ check_overflowgid(const int gid)
{
check_overflow_id(gid, "/proc/sys/kernel/overflowgid");
}
void printuid(const char *prefix, unsigned int val)
{
if (val == -1U)
printf("%s-1", prefix);
else
printf("%s%u", prefix, val);
}

View File

@ -32,7 +32,7 @@
#include <unistd.h>
void
printuid(unsigned UGID_TYPE id)
printugid(unsigned UGID_TYPE id)
{
if (id == (unsigned UGID_TYPE) -1U)
printf("-1");
@ -65,7 +65,7 @@ main(void)
rc = syscall(SYSCALL_NR, tests[i]);
printf("%s(", SYSCALL_NAME);
printuid(num);
printugid(num);
printf(") = %u\n", rc);
rc = syscall(SYSCALL_NR, ugid);

View File

@ -59,7 +59,7 @@
# include <unistd.h>
void
printuid(GID_TYPE id)
printugid(GID_TYPE id)
{
if (id == (GID_TYPE) -1U)
printf("-1");
@ -102,7 +102,7 @@ main(void)
rc = syscall(SYSCALL_NR, 1, g1);
errstr = sprintrc(rc);
printf("%s(1, [", SYSCALL_NAME);
printuid(*g1);
printugid(*g1);
printf("]) = %s\n", errstr);
rc = syscall(SYSCALL_NR, 1, g1 + 1);
@ -114,7 +114,7 @@ main(void)
rc = syscall(SYSCALL_NR, 2, g1);
errstr = sprintrc(rc);
printf("%s(2, [", SYSCALL_NAME);
printuid(*g1);
printugid(*g1);
printf(", ... /* %p */]) = %s\n", g1 + 1, errstr);
g2[0] = -2;
@ -122,17 +122,17 @@ main(void)
rc = syscall(SYSCALL_NR, 2, g2);
errstr = sprintrc(rc);
printf("%s(2, [", SYSCALL_NAME);
printuid(g2[0]);
printugid(g2[0]);
printf(", ");
printuid(g2[1]);
printugid(g2[1]);
printf("]) = %s\n", errstr);
rc = syscall(SYSCALL_NR, 3, g2);
errstr = sprintrc(rc);
printf("%s(3, [", SYSCALL_NAME);
printuid(g2[0]);
printugid(g2[0]);
printf(", ");
printuid(g2[1]);
printugid(g2[1]);
printf(", ... /* %p */]) = %s\n", g2 + 2, errstr);
g3[0] = 0;
@ -140,17 +140,17 @@ main(void)
rc = syscall(SYSCALL_NR, 3, g3);
errstr = sprintrc(rc);
printf("%s(3, [", SYSCALL_NAME);
printuid(g3[0]);
printugid(g3[0]);
printf(", ");
printuid(g3[1]);
printugid(g3[1]);
printf(", ...]) = %s\n", errstr);
rc = syscall(SYSCALL_NR, 4, g3);
errstr = sprintrc(rc);
printf("%s(4, [", SYSCALL_NAME);
printuid(g3[0]);
printugid(g3[0]);
printf(", ");
printuid(g3[1]);
printugid(g3[1]);
printf(", ...]) = %s\n", errstr);
rc = sysconf(_SC_NGROUPS_MAX);
@ -160,17 +160,17 @@ main(void)
rc = syscall(SYSCALL_NR, ngroups_max, g3);
errstr = sprintrc(rc);
printf("%s(%d, [", SYSCALL_NAME, ngroups_max);
printuid(g3[0]);
printugid(g3[0]);
printf(", ");
printuid(g3[1]);
printugid(g3[1]);
printf(", ...]) = %s\n", errstr);
rc = syscall(SYSCALL_NR, F8ILL_KULONG_MASK | ngroups_max, g3);
errstr = sprintrc(rc);
printf("%s(%d, [", SYSCALL_NAME, ngroups_max);
printuid(g3[0]);
printugid(g3[0]);
printf(", ");
printuid(g3[1]);
printugid(g3[1]);
printf(", ...]) = %s\n", errstr);
rc = syscall(SYSCALL_NR, ngroups_max + 1, g3);

View File

@ -33,7 +33,7 @@
#include <unistd.h>
void
printuid(unsigned UGID_TYPE id)
printugid(unsigned UGID_TYPE id)
{
if (id == (unsigned UGID_TYPE) -1U)
printf("-1");
@ -86,7 +86,7 @@ main(void)
}
printf("%s(", SYSCALL_NAME);
printuid(num);
printugid(num);
printf(") = %s\n", errstr);
}

View File

@ -196,6 +196,8 @@ void print_time_t_nsec(time_t, unsigned long long, int);
/* Print time_t and microseconds in symbolic format. */
void print_time_t_usec(time_t, unsigned long long, int);
void printuid(const char *prefix, unsigned int val);
/* Read an int from the file. */
int read_int_from_file(const char *, int *);

184
uid.c
View File

@ -40,16 +40,23 @@
# define SIZEIFY__(x, size) x ## size
# define printuid SIZEIFY(printuid)
# define printgid SIZEIFY(printgid)
# define sys_chown SIZEIFY(sys_chown)
# define sys_fchown SIZEIFY(sys_fchown)
# define sys_getgroups SIZEIFY(sys_getgroups)
# define sys_getresuid SIZEIFY(sys_getresuid)
# define sys_getresgid SIZEIFY(sys_getresgid)
# define sys_getuid SIZEIFY(sys_getuid)
# define sys_getgid SIZEIFY(sys_getgid)
# define sys_setfsuid SIZEIFY(sys_setfsuid)
# define sys_setfsgid SIZEIFY(sys_setfsgid)
# define sys_setgroups SIZEIFY(sys_setgroups)
# define sys_setresuid SIZEIFY(sys_setresuid)
# define sys_setresgid SIZEIFY(sys_setresgid)
# define sys_setreuid SIZEIFY(sys_setreuid)
# define sys_setregid SIZEIFY(sys_setregid)
# define sys_setuid SIZEIFY(sys_setuid)
# define sys_setgid SIZEIFY(sys_setgid)
#endif /* STRACE_UID_SIZE */
#include "defs.h"
@ -69,16 +76,44 @@
# define uid_t_(size) uid_t__(size)
# define uid_t__(size) uint ## size ## _t
# undef gid_t
# define gid_t gid_t_(STRACE_UID_SIZE)
# define gid_t_(size) gid_t__(size)
# define gid_t__(size) uint ## size ## _t
# include <grp.h>
# include <pwd.h>
# include <sys/types.h>
enum id_type {
IDT_UID,
IDT_GID,
IDT_COUNT
};
SYS_FUNC(getuid)
{
return RVAL_DECODED;
return RVAL_DECODED | RVAL_UID;
}
SYS_FUNC(getgid)
{
return RVAL_DECODED | RVAL_GID;
}
SYS_FUNC(setfsuid)
{
printuid("", tcp->u_arg[0]);
return RVAL_DECODED;
return RVAL_DECODED | RVAL_UID;
}
SYS_FUNC(setfsgid)
{
printgid("", tcp->u_arg[0]);
return RVAL_DECODED | RVAL_GID;
}
SYS_FUNC(setuid)
@ -88,15 +123,22 @@ SYS_FUNC(setuid)
return RVAL_DECODED;
}
static void
get_print_uid(struct tcb *const tcp, const char *const prefix,
const kernel_ulong_t addr)
SYS_FUNC(setgid)
{
uid_t uid;
printgid("", tcp->u_arg[0]);
return RVAL_DECODED;
}
static void
get_print_id(struct tcb *const tcp, const char *const prefix,
const kernel_ulong_t addr, enum id_type idt)
{
uid_t id;
tprints(prefix);
if (!umove_or_printaddr(tcp, addr, &uid)) {
printuid("[", uid);
if (!umove_or_printaddr(tcp, addr, &id)) {
(idt == IDT_UID ? printuid : printgid)("[", id);
tprints("]");
}
}
@ -106,9 +148,21 @@ SYS_FUNC(getresuid)
if (entering(tcp))
return 0;
get_print_uid(tcp, "", tcp->u_arg[0]);
get_print_uid(tcp, ", ", tcp->u_arg[1]);
get_print_uid(tcp, ", ", tcp->u_arg[2]);
get_print_id(tcp, "", tcp->u_arg[0], IDT_UID);
get_print_id(tcp, ", ", tcp->u_arg[1], IDT_UID);
get_print_id(tcp, ", ", tcp->u_arg[2], IDT_UID);
return 0;
}
SYS_FUNC(getresgid)
{
if (entering(tcp))
return 0;
get_print_id(tcp, "", tcp->u_arg[0], IDT_GID);
get_print_id(tcp, ", ", tcp->u_arg[1], IDT_GID);
get_print_id(tcp, ", ", tcp->u_arg[2], IDT_GID);
return 0;
}
@ -121,6 +175,14 @@ SYS_FUNC(setreuid)
return RVAL_DECODED;
}
SYS_FUNC(setregid)
{
printgid("", tcp->u_arg[0]);
printgid(", ", tcp->u_arg[1]);
return RVAL_DECODED;
}
SYS_FUNC(setresuid)
{
printuid("", tcp->u_arg[0]);
@ -130,11 +192,20 @@ SYS_FUNC(setresuid)
return RVAL_DECODED;
}
SYS_FUNC(setresgid)
{
printgid("", tcp->u_arg[0]);
printgid(", ", tcp->u_arg[1]);
printgid(", ", tcp->u_arg[2]);
return RVAL_DECODED;
}
SYS_FUNC(chown)
{
printpath(tcp, tcp->u_arg[0]);
printuid(", ", tcp->u_arg[1]);
printuid(", ", tcp->u_arg[2]);
printgid(", ", tcp->u_arg[2]);
return RVAL_DECODED;
}
@ -143,24 +214,97 @@ SYS_FUNC(fchown)
{
printfd(tcp, tcp->u_arg[0]);
printuid(", ", tcp->u_arg[1]);
printuid(", ", tcp->u_arg[2]);
printgid(", ", tcp->u_arg[2]);
return RVAL_DECODED;
}
void
printuid(const char *text, const unsigned int uid)
#define ID_CACHE_SIZE 32
static void
print_id(const char *prefix, const uid_t id, enum id_type t)
{
if ((uid_t) -1U == (uid_t) uid)
tprintf("%s-1", text);
else
tprintf("%s%u", text, (uid_t) uid);
static const uint32_t mask = 0x80000000;
if ((uid_t) -1U == (uid_t) id) {
tprintf("%s-1", prefix);
return;
}
tprintf("%s%u", prefix, (uid_t) id);
if (!show_fd_path)
return;
static struct cache_ent {
uint32_t id;
uint32_t str_len;
char *str;
} id_cache[IDT_COUNT * ID_CACHE_SIZE] = { { 0 } };
struct cache_ent *cache = id_cache + t * ID_CACHE_SIZE;
const size_t idx = (id ^ mask) % ID_CACHE_SIZE;
const char *str = NULL;
if ((cache[idx].id ^ mask) == id) {
str = cache[idx].str;
goto print;
}
switch (t) {
case IDT_UID: {
/* NB: not thread-safe */
struct passwd *pwd = getpwuid((uid_t) id);
if (!pwd)
break;
str = pwd->pw_name;
break;
}
case IDT_GID: {
/* NB: not thread-safe */
struct group *gr = getgrgid((gid_t) id);
if (!gr)
break;
str = gr->gr_name;
break;
}
default:
break;
}
free(cache[idx].str);
cache[idx].id = id ^ mask;
cache[idx].str = str ? xstrdup(str) : NULL;
cache[idx].str_len = str ? strlen(str) : 0;
print:
if (str) {
tprints("<");
print_quoted_string_ex(cache[idx].str, cache[idx].str_len,
QUOTE_OMIT_LEADING_TRAILING_QUOTES,
"<>");
tprints(">");
}
}
void
printuid(const char *prefix, const unsigned int uid)
{
print_id(prefix, uid, IDT_UID);
}
void
printgid(const char *prefix, const unsigned int gid)
{
print_id(prefix, gid, IDT_GID);
}
static bool
print_gid(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
{
printuid("", (*(uid_t *) elem_buf));
printgid("", (*(uid_t *) elem_buf));
return true;
}

View File

@ -1,3 +1,4 @@
PRIO_PROCESS
PRIO_PGRP
PRIO_USER
#value_indexed
PRIO_PROCESS 0
PRIO_PGRP 1
PRIO_USER 2