From 9e48045e45df7e3e205575a4eb3dc39d634b05aa Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 3 Jul 2003 10:07:04 +0000 Subject: Patch from Russell Coker: I've attached my latest SE Linux patch for busybox against the latest CVS version of busybox. --- procps/ps.c | 33 +++++++++++++++++++++++++++++++++ procps/top.c | 4 ++++ 2 files changed, 37 insertions(+) (limited to 'procps') diff --git a/procps/ps.c b/procps/ps.c index 5ccac7a95..691f490c7 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -31,6 +31,11 @@ #include #include #include "busybox.h" +#ifdef CONFIG_SELINUX +#include +#include +#include /* for is_flask_enabled() */ +#endif static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */ @@ -47,6 +52,13 @@ extern int ps_main(int argc, char **argv) #define terminal_width TERMINAL_WIDTH #endif +#ifdef CONFIG_SELINUX + int use_selinux = 0; + security_id_t sid; + if(is_flask_enabled() && argv[1] && !strcmp(argv[1], "-c") ) + use_selinux = 1; +#endif + #ifdef CONFIG_FEATURE_AUTOWIDTH ioctl(fileno(stdout), TIOCGWINSZ, &win); @@ -54,10 +66,31 @@ extern int ps_main(int argc, char **argv) terminal_width = win.ws_col - 1; #endif +#ifdef CONFIG_SELINUX + if(use_selinux) + printf(" PID Context Stat Command\n"); + else +#endif printf(" PID Uid VmSize Stat Command\n"); +#ifdef CONFIG_SELINUX + while ((p = procps_scan(1, use_selinux, &sid)) != 0) { +#else while ((p = procps_scan(1)) != 0) { +#endif char *namecmd = p->cmd; +#ifdef CONFIG_SELINUX + if(use_selinux) + { + char sbuf[128]; + len = sizeof(sbuf); + if(security_sid_to_context(sid, (security_context_t)&sbuf, &len)) + strcpy(sbuf, "unknown"); + + len = printf("%5d %-32s %s ", p->pid, sbuf, p->state); + } + else +#endif if(p->rss == 0) len = printf("%5d %-8s %s ", p->pid, p->user, p->state); else diff --git a/procps/top.c b/procps/top.c index b70a42a72..2e1bd3286 100644 --- a/procps/top.c +++ b/procps/top.c @@ -501,7 +501,11 @@ int top_main(int argc, char **argv) /* read process IDs & status for all the processes */ procps_status_t * p; +#ifdef CONFIG_SELINUX + while ((p = procps_scan(0, 0, NULL) ) != 0) { +#else while ((p = procps_scan(0)) != 0) { +#endif int n = ntop; top = xrealloc(top, (++ntop)*sizeof(procps_status_t)); -- cgit v1.2.3