From 60158cb93eb0b3207dd1084cdf5bdd9226bd9e89 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 3 May 2005 06:25:50 +0000 Subject: A patch from Takeharu KATO to update/fix SE-Linux support. --- procps/ps.c | 52 +++++++++++++++++++++++++++++----------------------- procps/top.c | 4 ---- 2 files changed, 29 insertions(+), 27 deletions(-) (limited to 'procps') diff --git a/procps/ps.c b/procps/ps.c index 0b603314d..18a6db36f 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -31,9 +31,7 @@ #include #include "busybox.h" #ifdef CONFIG_SELINUX -#include -#include -#include /* for is_flask_enabled() */ +#include /* for is_selinux_enabled() */ #endif static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */ @@ -48,8 +46,8 @@ extern int ps_main(int argc, char **argv) #ifdef CONFIG_SELINUX int use_selinux = 0; - security_id_t sid; - if(is_flask_enabled() && argv[1] && !strcmp(argv[1], "-c") ) + security_context_t sid=NULL; + if(is_selinux_enabled() && argv[1] && !strcmp(argv[1], "-c") ) use_selinux = 1; #endif @@ -58,34 +56,42 @@ extern int ps_main(int argc, char **argv) terminal_width--; #ifdef CONFIG_SELINUX - if(use_selinux) - printf(" PID Context Stat Command\n"); + 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; + printf(" PID Uid VmSize Stat Command\n"); + while ((p = procps_scan(1)) != 0) { + char *namecmd = p->cmd; #ifdef CONFIG_SELINUX - if(use_selinux) - { + if ( use_selinux ) + { char sbuf[128]; len = sizeof(sbuf); - if(security_sid_to_context(sid, (security_context_t)&sbuf, &len)) - strcpy(sbuf, "unknown"); + if (is_selinux_enabled()) { + if (getpidcon(p->pid,&sid)<0) + sid=NULL; + } + + if (sid) { + /* I assume sid initilized with NULL */ + len = strlen(sid)+1; + safe_strncpy(sbuf, sid, len); + freecon(sid); + sid=NULL; + }else { + safe_strncpy(sbuf, "unknown",7); + } 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 - len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); + if(p->rss == 0) + len = printf("%5d %-8s %s ", p->pid, p->user, p->state); + else + len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state); i = terminal_width-len; if(namecmd != 0 && namecmd[0] != 0) { diff --git a/procps/top.c b/procps/top.c index c0f78f794..369a408d8 100644 --- a/procps/top.c +++ b/procps/top.c @@ -510,11 +510,7 @@ 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