Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: nils.carlson@ericsson.com (Nils Carlson)
Subject: [ltt-dev] [UST PATCH 5/6] Make root see all available pids
Date: Fri, 1 Apr 2011 09:32:19 +0200	[thread overview]
Message-ID: <1301643140-6880-5-git-send-email-nils.carlson@ericsson.com> (raw)
In-Reply-To: <1301643140-6880-1-git-send-email-nils.carlson@ericsson.com>

Changes since v1:
	* Fix a whitespace
	* Make functions that should be static static

Allow root (geteuid() == 0) to see all pids. This way the super-user
can connect to any program. A step on the way of carefully outlining
what UST does and doesn't.

Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
---
 libustcomm/ustcomm.h  |    4 ++-
 libustctl/libustctl.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/libustcomm/ustcomm.h b/libustcomm/ustcomm.h
index d16aec7..9952958 100644
--- a/libustcomm/ustcomm.h
+++ b/libustcomm/ustcomm.h
@@ -25,7 +25,9 @@
 #include <ust/kcompat/kcompat.h>
 
 #define SOCK_DIR "/tmp/ust-app-socks"
-#define USER_SOCK_DIR "/tmp/ust-socks-"
+#define USER_TMP_DIR "/tmp"
+#define USER_SOCK_DIR_BASE "ust-socks-"
+#define USER_SOCK_DIR USER_TMP_DIR "/" USER_SOCK_DIR_BASE
 
 struct ustcomm_sock {
 	struct cds_list_head list;
diff --git a/libustctl/libustctl.c b/libustctl/libustctl.c
index 5625f43..356d5ef 100644
--- a/libustctl/libustctl.c
+++ b/libustctl/libustctl.c
@@ -121,7 +121,7 @@ static void get_pids_in_dir(DIR *dir, pid_t **pid_list,
 	(*pid_list)[*pid_list_size - 1] = 0; /* Array end */
 }
 
-pid_t *ustctl_get_online_pids(void)
+static pid_t *get_pids_non_root(void)
 {
 	char *dir_name;
 	DIR *dir;
@@ -139,6 +139,9 @@ pid_t *ustctl_get_online_pids(void)
 	}
 
 	pid_list = malloc(pid_list_size * sizeof(pid_t));
+	if (!pid_list) {
+		goto close_dir;
+	}
 
 	get_pids_in_dir(dir, &pid_list, &pid_list_size);
 
@@ -158,6 +161,62 @@ free_dir_name:
 	return pid_list;
 }
 
+static pid_t *get_pids_root(void)
+{
+	char *dir_name;
+	DIR *tmp_dir, *dir;
+	unsigned int pid_list_size = 1;
+	pid_t *pid_list = NULL;
+	struct dirent *dirent;
+
+	tmp_dir = opendir(USER_TMP_DIR);
+	if (!tmp_dir) {
+		return NULL;
+	}
+
+	pid_list = malloc(pid_list_size * sizeof(pid_t));
+	if (!pid_list) {
+		goto close_tmp_dir;
+	}
+
+	while ((dirent = readdir(tmp_dir))) {
+		/* Compare the dir to check for the USER_SOCK_DIR_BASE prefix */
+		if (!strncmp(dirent->d_name, USER_SOCK_DIR_BASE,
+			     strlen(USER_SOCK_DIR_BASE))) {
+
+			if (asprintf(&dir_name, USER_TMP_DIR "/%s", dirent->d_name) < 0) {
+				goto close_tmp_dir;
+			}
+
+			dir = opendir(dir_name);
+
+			free(dir_name);
+
+			if (!dir) {
+				continue;
+			}
+
+			get_pids_in_dir(dir, &pid_list, &pid_list_size);
+
+			closedir(dir);
+		}
+	}
+
+close_tmp_dir:
+	closedir(tmp_dir);
+
+	return pid_list;
+}
+
+pid_t *ustctl_get_online_pids(void)
+{
+	if (geteuid()) {
+		return get_pids_non_root();
+	} else {
+		return get_pids_root();
+	}
+}
+
 /**
  * Sets marker state (USTCTL_MS_ON or USTCTL_MS_OFF).
  *
-- 
1.7.1





  parent reply	other threads:[~2011-04-01  7:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-01  7:32 [ltt-dev] [UST PATCH 1/6] Make app socket directories per-user v2 Nils Carlson
2011-04-01  7:14 ` Nils Carlson
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 2/6] Add mode setting to socket directory creation Nils Carlson
2011-04-01  7:15   ` Nils Carlson
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 3/6] Restructure the ustctl_get_online_pids command v2 Nils Carlson
2011-04-01  7:15   ` Nils Carlson
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 4/6] Add list-pids command to ustctl Nils Carlson
2011-04-01  7:16   ` Nils Carlson
2011-04-01  7:32 ` Nils Carlson [this message]
2011-04-01  7:17   ` [ltt-dev] [UST PATCH 5/6] Make root see all available pids Nils Carlson
2011-04-01  7:32 ` [ltt-dev] [UST PATCH 6/6] Make root able to connect to any traceable app Nils Carlson
2011-04-01  7:17   ` Nils Carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1301643140-6880-5-git-send-email-nils.carlson@ericsson.com \
    --to=nils.carlson@ericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox