Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/procstat/procstat_cred.c
/*- | /*- | ||||
* Copyright (c) 2007-2008 Robert N. M. Watson | * Copyright (c) 2007-2008 Robert N. M. Watson | ||||
* Copyright (c) 2015 Allan Jude <allanjude@freebsd.org> | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
Show All 32 Lines | |||||
void | void | ||||
procstat_cred(struct procstat *procstat, struct kinfo_proc *kipp) | procstat_cred(struct procstat *procstat, struct kinfo_proc *kipp) | ||||
{ | { | ||||
unsigned int i, ngroups; | unsigned int i, ngroups; | ||||
gid_t *groups; | gid_t *groups; | ||||
if (!hflag) | if (!hflag) | ||||
printf("%5s %-16s %5s %5s %5s %5s %5s %5s %5s %5s %-15s\n", | xo_emit("{T:/%5s %-16s %5s %5s %5s %5s %5s %5s %5s %5s %-15s}\n", | ||||
"PID", "COMM", "EUID", "RUID", "SVUID", "EGID", "RGID", | "PID", "COMM", "EUID", "RUID", "SVUID", "EGID", "RGID", | ||||
"SVGID", "UMASK", "FLAGS", "GROUPS"); | "SVGID", "UMASK", "FLAGS", "GROUPS"); | ||||
printf("%5d ", kipp->ki_pid); | xo_emit("{k:process_id/%5d/%d} ", kipp->ki_pid); | ||||
printf("%-16s ", kipp->ki_comm); | xo_emit("{:command/%-16s/%s} ", kipp->ki_comm); | ||||
printf("%5d ", kipp->ki_uid); | xo_emit("{:uid/%5d} ", kipp->ki_uid); | ||||
printf("%5d ", kipp->ki_ruid); | xo_emit("{:ruid/%5d} ", kipp->ki_ruid); | ||||
printf("%5d ", kipp->ki_svuid); | xo_emit("{:svuid/%5d} ", kipp->ki_svuid); | ||||
printf("%5d ", kipp->ki_groups[0]); | xo_emit("{:group/%5d} ", kipp->ki_groups[0]); | ||||
printf("%5d ", kipp->ki_rgid); | xo_emit("{:rgid/%5d} ", kipp->ki_rgid); | ||||
printf("%5d ", kipp->ki_svgid); | xo_emit("{:svgid/%5d} ", kipp->ki_svgid); | ||||
printf("%5s ", get_umask(procstat, kipp)); | xo_emit("{:umask/%5s} ", get_umask(procstat, kipp)); | ||||
printf("%s", kipp->ki_cr_flags & CRED_FLAG_CAPMODE ? "C" : "-"); | xo_emit("{:cr_flags/%s}", kipp->ki_cr_flags & CRED_FLAG_CAPMODE ? "C" : "-"); | ||||
printf(" "); | xo_emit("{P: }"); | ||||
groups = NULL; | groups = NULL; | ||||
/* | /* | ||||
* We may have too many groups to fit in kinfo_proc's statically | * We may have too many groups to fit in kinfo_proc's statically | ||||
* sized storage. If that occurs, attempt to retrieve them using | * sized storage. If that occurs, attempt to retrieve them using | ||||
* libprocstat. | * libprocstat. | ||||
*/ | */ | ||||
if (kipp->ki_cr_flags & KI_CRF_GRP_OVERFLOW) | if (kipp->ki_cr_flags & KI_CRF_GRP_OVERFLOW) | ||||
groups = procstat_getgroups(procstat, kipp, &ngroups); | groups = procstat_getgroups(procstat, kipp, &ngroups); | ||||
if (groups == NULL) { | if (groups == NULL) { | ||||
ngroups = kipp->ki_ngroups; | ngroups = kipp->ki_ngroups; | ||||
groups = kipp->ki_groups; | groups = kipp->ki_groups; | ||||
} | } | ||||
xo_open_list("groups"); | |||||
for (i = 0; i < ngroups; i++) | for (i = 0; i < ngroups; i++) | ||||
printf("%s%d", (i > 0) ? "," : "", groups[i]); | xo_emit("{D:/%s}{l:groups/%d}", (i > 0) ? "," : "", groups[i]); | ||||
if (groups != kipp->ki_groups) | if (groups != kipp->ki_groups) | ||||
procstat_freegroups(procstat, groups); | procstat_freegroups(procstat, groups); | ||||
printf("\n"); | xo_close_list("groups"); | ||||
xo_emit("\n"); | |||||
} | } | ||||
static const char * | static const char * | ||||
get_umask(struct procstat *procstat, struct kinfo_proc *kipp) | get_umask(struct procstat *procstat, struct kinfo_proc *kipp) | ||||
{ | { | ||||
u_short fd_cmask; | u_short fd_cmask; | ||||
static char umask[4]; | static char umask[4]; | ||||
if (procstat_getumask(procstat, kipp, &fd_cmask) == 0) { | if (procstat_getumask(procstat, kipp, &fd_cmask) == 0) { | ||||
snprintf(umask, 4, "%03o", fd_cmask); | snprintf(umask, 4, "%03o", fd_cmask); | ||||
return (umask); | return (umask); | ||||
} else { | } else { | ||||
return ("-"); | return ("-"); | ||||
} | } | ||||
} | } |