? procman-selinux-support-1.patch
Index: configure.in
===================================================================
RCS file: /cvs/gnome/procman/configure.in,v
retrieving revision 1.116
diff -u -p -r1.116 configure.in
--- configure.in	26 Oct 2004 23:13:17 -0000	1.116
+++ configure.in	28 Oct 2004 00:08:39 -0000
@@ -82,6 +82,17 @@ else
   AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, "${prefix}/${DATADIRNAME}/locale")
 fi
 
+AC_ARG_ENABLE(selinux, AC_HELP_STRING(--enable-selinux,enable SELinux support),enable_selinux=$enableval, enable_selinux=no)
+
+if test x$enable_selinux = xyes; then
+   AC_DEFINE(ENABLE_SELINUX, 1, [Define to 1 to enable SELinux support])
+   AM_CONDITIONAL(ENABLE_SELINUX, test x$enable_selinux = xyes)
+   AC_MSG_RESULT(SELinux support enabled)
+else
+   AC_MSG_RESULT(SELinux support disabled)
+fi
+
+
 dnl Honor ACLOCAL_FLAGS for --enable-maintainer-mode
 ACLOCAL="$ACLOCAL $ACLOCAL_FLAGS"
 
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/procman/src/Makefile.am,v
retrieving revision 1.40
diff -u -p -r1.40 Makefile.am
--- src/Makefile.am	8 Nov 2003 14:28:48 -0000	1.40
+++ src/Makefile.am	28 Oct 2004 00:08:39 -0000
@@ -23,7 +23,11 @@ gnome_system_monitor_SOURCES = \
 	favorites.c favorites.h \
 	defaulttable.h
 
-gnome_system_monitor_LDADD = @PROCMAN_LIBS@
+if ENABLE_SELINUX
+gnome_system_monitor_LDADD = @PROCMAN_LIBS@ -lselinux
+else
+gnome_system_monitor_LDADD = @PROCMAN_LIBS@ 
+endif
 
 specdir = $(datadir)/procman
 
Index: src/procman.h
===================================================================
RCS file: /cvs/gnome/procman/src/procman.h,v
retrieving revision 1.48
diff -u -p -r1.48 procman.h
--- src/procman.h	25 Oct 2004 13:02:46 -0000	1.48
+++ src/procman.h	28 Oct 2004 00:08:39 -0000
@@ -136,6 +136,7 @@ struct _ProcInfo
 	gint		memrss;
         gint            memxserver;
 	gchar		*status;
+	gchar           *security_context;
 	gboolean	running;
 	gboolean	is_thread;
 	gboolean	is_blacklisted;
Index: src/proctable.c
===================================================================
RCS file: /cvs/gnome/procman/src/proctable.c,v
retrieving revision 1.118
diff -u -p -r1.118 proctable.c
--- src/proctable.c	24 Oct 2004 20:43:49 -0000	1.118
+++ src/proctable.c	28 Oct 2004 00:08:40 -0000
@@ -47,6 +47,10 @@
 #include "favorites.h"
 
 
+#ifdef ENABLE_SELINUX
+#include <selinux/selinux.h>
+#endif
+
 
 static gint total_time = 0;
 static gint total_time_last = 0;
@@ -114,6 +118,44 @@ sort_ints (GtkTreeModel *model, GtkTreeI
 		return 0;
 }
 
+static gboolean
+can_show_security_context_column (void)
+{
+#ifdef ENABLE_SELINUX
+	switch (is_selinux_enabled()) {
+	case 1: /* We're running on an SELinux kernel */ 
+		return TRUE;
+
+	default:
+	case -1: 
+		/* Error; hide the security context column */
+
+	case 0: 
+		/* We're not running on an SELinux kernel: hide the security context column */
+		return FALSE;
+	}
+#else
+	/* Support disabled; hide the security context column */
+	return FALSE;
+#endif
+}
+
+static gchar*
+get_selinux_context (gint pid)
+{
+#ifdef ENABLE_SELINUX
+	/* Directly grab the SELinux security context: */
+	security_context_t con;
+	
+	if (!getpidcon (pid, &con)) {
+		gchar *result = g_strdup (con);
+		freecon (con);
+		return result;
+	}
+#endif
+
+	return NULL;
+}
 
 GtkWidget *
 proctable_new (ProcData * const procdata)
@@ -139,6 +181,7 @@ proctable_new (ProcData * const procdata
 		/* xgettext:no-c-format */ N_("% CPU"),
 		N_("Nice"),
 		N_("ID"),
+		N_("Security Context"), 
 		NULL,
 		"POINTER"
 	};
@@ -157,6 +200,7 @@ proctable_new (ProcData * const procdata
 				    G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
 				    G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
 				    G_TYPE_INT, G_TYPE_INT, G_TYPE_INT,
+				    G_TYPE_STRING,
 				    GDK_TYPE_PIXBUF, G_TYPE_POINTER);
 
 	proctree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
@@ -251,6 +295,13 @@ proctable_new (ProcData * const procdata
 
 	procman_get_tree_state (procdata->client, proctree, "/apps/procman/proctree");
 
+	/* Override column settings by hiding this column if it's meaningless: */
+	if (!can_show_security_context_column ()) {
+		GtkTreeViewColumn *column;
+		column = gtk_tree_view_get_column (GTK_TREE_VIEW (proctree), COL_SECURITYCONTEXT);
+		gtk_tree_view_column_set_visible (column, FALSE);
+	}
+
 	g_signal_connect (G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (proctree))),
 			  "changed",
 			  G_CALLBACK (cb_row_selected), procdata);
@@ -273,6 +324,7 @@ proctable_free_info (ProcInfo *info)
 	g_free (info->arguments);
 	g_free (info->user);
 	g_free (info->status);
+	g_free (info->security_context);
 	g_list_free (info->children);
 	g_free (info);
 }
@@ -448,6 +500,7 @@ insert_info_to_tree (ProcInfo *info, Pro
 			    COL_CPU, info->cpu,
 			    COL_PID, info->pid,
 			    COL_NICE, info->nice,
+			    COL_SECURITYCONTEXT, info->security_context,
 			    -1);
 	g_free (mem);
 	g_free (vmsize);
@@ -636,6 +689,7 @@ update_info (ProcData *procdata, ProcInf
 				    COL_CPU, info->cpu,
 				    COL_NICE, info->nice,
 				    -1);
+		/* We don't bother updating COL_SECURITYCONTEXT as it can never change */
 		g_free (mem);
 		g_free (vmsize);
 		g_free (memres);
@@ -710,6 +764,8 @@ get_info (ProcData *procdata, gint pid)
 	info->cpu_time_last = newcputime;
 	info->nice = procuid.nice;
 	get_process_status (info, &procstate);
+	
+	info->security_context = get_selinux_context (pid);
 
 	info->pixbuf = pretty_table_get_icon (procdata->pretty_table, info->name, pid);
 
Index: src/proctable.h
===================================================================
RCS file: /cvs/gnome/procman/src/proctable.h,v
retrieving revision 1.15
diff -u -p -r1.15 proctable.h
--- src/proctable.h	22 Oct 2004 23:03:23 -0000	1.15
+++ src/proctable.h	28 Oct 2004 00:08:40 -0000
@@ -36,6 +36,7 @@ enum
 	COL_CPU,
 	COL_NICE,
 	COL_PID,
+	COL_SECURITYCONTEXT,
 	COL_PIXBUF,
 	COL_POINTER,
 	NUM_COLUMNS
