aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-05-03 06:25:50 +0000
committerRob Landley <rob@landley.net>2005-05-03 06:25:50 +0000
commit60158cb93eb0b3207dd1084cdf5bdd9226bd9e89 (patch)
treefe97ec71775deb1f3078c6db0cb8db554bc6b76f /procps
parent988a78c61cffe91b005d37f0b7d6e2cb2c5ea713 (diff)
downloadbusybox-60158cb93eb0b3207dd1084cdf5bdd9226bd9e89.tar.gz
A patch from Takeharu KATO to update/fix SE-Linux support.
Diffstat (limited to 'procps')
-rw-r--r--procps/ps.c52
-rw-r--r--procps/top.c4
2 files changed, 29 insertions, 27 deletions
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 <sys/ioctl.h>
#include "busybox.h"
#ifdef CONFIG_SELINUX
-#include <fs_secure.h>
-#include <ss.h>
-#include <flask_util.h> /* for is_flask_enabled() */
+#include <selinux/selinux.h> /* 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));