From c1f79de8c7e95092759b8bf882668ce50bc83a7c Mon Sep 17 00:00:00 2001 From: rwatson Date: Thu, 24 Oct 2002 00:00:57 +0000 Subject: Use the MAC interface to list process MAC labels rather than using the LOMAC-specific interface (which is being deprecated). The revised LOMAC using the MAC framework will export levels listable using this mechanism. Approved by: re Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories --- bin/ps/print.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'bin/ps/print.c') diff --git a/bin/ps/print.c b/bin/ps/print.c index 3fd367a..31a857b 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -62,7 +63,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include "lomac.h" #include "ps.h" #define ps_pgtok(a) (((a) * getpagesize()) / 1024) @@ -726,10 +726,53 @@ rvar(KINFO *k, VARENT *ve) } void -lattr(KINFO *k, VARENT *ve) +label(KINFO *k, VARENT *ve) { + char *string; + mac_t label; + int error; VAR *v; v = ve->var; - (void)printf("%-*d", v->width, get_lattr(k->ki_p->ki_pid)); + string = NULL; + + if (mac_prepare_process_label(&label) == -1) { + perror("mac_prepare_process_label"); + goto out; + } + + error = mac_get_pid(k->ki_p->ki_pid, label); + if (error == 0) { + if (mac_to_text(label, &string) == -1) + string = NULL; + } + mac_free(label); + +out: + if (string != NULL) { + (void)printf("%-*s", v->width, string); + free(string); + } else + (void)printf("%-*s", v->width, ""); + return; +} + +int +s_label(KINFO *k) +{ + char *string = NULL; + mac_t label; + int error, size = 0; + + if (mac_prepare_process_label(&label) == -1) { + perror("mac_prepare_process_label"); + return (0); + } + error = mac_get_pid(k->ki_p->ki_pid, label); + if (error == 0 && mac_to_text(label, &string) == 0) { + size = strlen(string); + free(string); + } + mac_free(label); + return (size); } -- cgit v1.1