summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2010-08-12 16:49:25 -0400
committerDavid Zeuthen <davidz@redhat.com>2010-08-12 16:49:25 -0400
commit17f0600529dc926ae4a0c85dc56c393cc09e4011 (patch)
tree95bbfd9db521100d223fcff2568430e21f22e2e9
parent15f358ff2d55dde44287ee4a9270c3ac09a194f7 (diff)
downloadpolkit-17f0600529dc926ae4a0c85dc56c393cc09e4011.tar.gz
Fix scanning of unix-process subjects
In particular accept both "unix-process:<pid>,<starttime>" and "unix-process:<pid>". For the latter, return an error if we cannot lookup the starttime (for example if the given pid references a non-existing process). Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--src/polkit/polkitsubject.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/polkit/polkitsubject.c b/src/polkit/polkitsubject.c
index 19d60b9..51e60e0 100644
--- a/src/polkit/polkitsubject.c
+++ b/src/polkit/polkitsubject.c
@@ -24,6 +24,7 @@
#endif
#include <string.h>
+#include <stdio.h>
#include "polkitsubject.h"
#include "polkitunixprocess.h"
@@ -222,8 +223,6 @@ polkit_subject_from_string (const gchar *str,
GError **error)
{
PolkitSubject *subject;
- guint64 val;
- gchar *endptr;
g_return_val_if_fail (str != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -234,12 +233,15 @@ polkit_subject_from_string (const gchar *str,
if (g_str_has_prefix (str, "unix-process:"))
{
- val = g_ascii_strtoull (str + sizeof "unix-process:" - 1,
- &endptr,
- 10);
- if (*endptr == '\0')
+ gint scanned_pid;
+ guint64 scanned_starttime;
+ if (sscanf (str, "unix-process:%d:%" G_GUINT64_FORMAT, &scanned_pid, &scanned_starttime) == 2)
{
- subject = polkit_unix_process_new ((gint) val);
+ subject = polkit_unix_process_new_full (scanned_pid, scanned_starttime);
+ }
+ else if (sscanf (str, "unix-process:%d", &scanned_pid) == 1)
+ {
+ subject = polkit_unix_process_new_full (scanned_pid, 0);
if (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject)) == 0)
{
g_object_unref (subject);
@@ -247,8 +249,8 @@ polkit_subject_from_string (const gchar *str,
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
- "No process with pid %" G_GUINT64_FORMAT,
- val);
+ "Unable to determine start time for process with pid %d",
+ scanned_pid);
}
}
}
@@ -266,7 +268,7 @@ polkit_subject_from_string (const gchar *str,
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
- "Malformed subject string '%s'",
+ "Malformed subject string `%s'",
str);
}