[tracker/tracker-0.10] tracker-control: List/control processes for the calling user only



commit 02ebb1d90b2d197688db120c987b68b9c928cbb6
Author: Martyn Russell <martyn lanedo com>
Date:   Tue Oct 11 10:57:49 2011 +0100

    tracker-control: List/control processes for the calling user only
    
    Fixes GB#655177.

 src/tracker-control/tracker-control-general.c |   60 ++++++++++++++++++++++++-
 1 files changed, 59 insertions(+), 1 deletions(-)
---
diff --git a/src/tracker-control/tracker-control-general.c b/src/tracker-control/tracker-control-general.c
index a0b9c93..ea4770b 100644
--- a/src/tracker-control/tracker-control-general.c
+++ b/src/tracker-control/tracker-control-general.c
@@ -283,6 +283,45 @@ get_uri_from_arg (const gchar *arg)
 	return uri;
 }
 
+static inline guint32
+get_uid_for_pid (const gchar  *pid_as_string,
+                 gchar       **filename)
+{
+	GFile *f;
+	GFileInfo *info;
+	GError *error = NULL;
+	gchar *fn;
+	guint uid;
+
+	fn = g_build_filename ("/proc", pid_as_string, "cmdline", NULL);
+
+	f = g_file_new_for_path (fn);
+	info = g_file_query_info (f,
+	                          G_FILE_ATTRIBUTE_UNIX_UID,
+	                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+	                          NULL,
+	                          &error);
+
+	if (error) {
+		g_warning ("Could not stat() file:'%s', %s", fn, error->message);
+		g_error_free (error);
+		uid = 0;
+	} else {
+		uid = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID);
+	}
+
+	if (filename) {
+		*filename = fn;
+	} else {
+		g_free (fn);
+	}
+
+	g_object_unref (info);
+	g_object_unref (f);
+
+	return uid;
+}
+
 void
 tracker_control_general_run_default (void)
 {
@@ -331,6 +370,10 @@ tracker_control_general_run (void)
 	if (kill_option != TERM_NONE ||
 	    terminate_option != TERM_NONE ||
 	    list_processes) {
+		guint32 own_pid;
+		guint32 own_uid;
+		gchar *own_uid_str;
+
 		pids = get_pids ();
 		str = g_strdup_printf (g_dngettext (NULL,
 		                                    "Found %d PIDâ",
@@ -340,12 +383,27 @@ tracker_control_general_run (void)
 		g_print ("%s\n", str);
 		g_free (str);
 
+		/* Establish own uid/pid */
+		own_pid = (guint32) getpid ();
+		own_uid_str = g_strdup_printf ("%d", own_pid);
+		own_uid = get_uid_for_pid (own_uid_str, NULL);
+		g_free (own_uid_str);
+
 		for (l = pids; l; l = l->next) {
+			GError *error = NULL;
 			gchar *filename;
 			gchar *contents = NULL;
 			gchar **strv;
+			guint uid;
+
+			uid = get_uid_for_pid (l->data, &filename);
+
+			/* Stat the file and make sure current user == file owner */
+			if (uid != own_uid) {
+				continue;
+			}
 
-			filename = g_build_filename ("/proc", l->data, "cmdline", NULL);
+			/* Get contents to determin basename */
 			if (!g_file_get_contents (filename, &contents, NULL, &error)) {
 				str = g_strdup_printf (_("Could not open '%s'"), filename);
 				g_printerr ("%s, %s\n",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]