diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-29 21:40:54 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-04-29 21:45:58 +0200 |
commit | cfeaa44a09756a93a881f786678973d9b1e382db (patch) | |
tree | c86172a848d4ca1716e1b2b82427e819f025e51c /src/shared | |
parent | cfa9677bd164574600d29a9bf99f9d1f28a7a170 (diff) |
sd-bus: properly handle creds that are known but undefined for a process
A number of fields do not apply to all processes, including: there a
processes without a controlling tty, without parent process, without
service, user services or session. To distuingish these cases from the
case where we simply don't have the data, always return ENXIO for them,
while returning ENODATA for the case where we really lack the
information.
Also update the credentials dumping code to show this properly. Fields
that are known but do not apply are now shown as "n/a".
Note that this also changes some of the calls in process-util.c and
cgroup-util.c to return ENXIO for these cases.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/audit.c | 2 | ||||
-rw-r--r-- | src/shared/audit.h | 1 | ||||
-rw-r--r-- | src/shared/cgroup-util.c | 20 | ||||
-rw-r--r-- | src/shared/terminal-util.c | 2 |
4 files changed, 13 insertions, 12 deletions
diff --git a/src/shared/audit.c b/src/shared/audit.c index 84181d3321..54148fcf18 100644 --- a/src/shared/audit.c +++ b/src/shared/audit.c @@ -46,7 +46,7 @@ int audit_session_from_pid(pid_t pid, uint32_t *id) { if (r < 0) return r; - if (u == (uint32_t) -1 || u <= 0) + if (u == AUDIT_SESSION_INVALID || u <= 0) return -ENXIO; *id = u; diff --git a/src/shared/audit.h b/src/shared/audit.h index 781866ae1c..6de331c73e 100644 --- a/src/shared/audit.h +++ b/src/shared/audit.h @@ -25,6 +25,7 @@ #include <stdbool.h> #include <sys/types.h> +#define AUDIT_SESSION_INVALID ((uint32_t) -1) int audit_session_from_pid(pid_t pid, uint32_t *id); int audit_loginuid_from_pid(pid_t pid, uid_t *uid); diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 5b04702ac2..7521b8b5f9 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -1150,7 +1150,7 @@ int cg_path_decode_unit(const char *cgroup, char **unit){ c = cg_unescape(c); if (!unit_name_is_valid(c, TEMPLATE_INVALID)) - return -EINVAL; + return -ENXIO; s = strdup(c); if (!s) @@ -1258,7 +1258,7 @@ int cg_path_get_user_unit(const char *path, char **unit) { if (!t) t = skip_user_manager(e); if (!t) - return -ENOENT; + return -ENXIO; /* ... and skip more slices if there are any */ e = skip_slices(t); @@ -1318,17 +1318,17 @@ int cg_path_get_session(const char *path, char **session) { n = strchrnul(e, '/'); if (e == n) - return -ENOENT; + return -ENXIO; s = strndupa(e, n - e); s = cg_unescape(s); x = startswith(s, "session-"); if (!x) - return -ENOENT; + return -ENXIO; y = endswith(x, ".scope"); if (!y || x == y) - return -ENOENT; + return -ENXIO; if (session) { char *r; @@ -1369,17 +1369,17 @@ int cg_path_get_owner_uid(const char *path, uid_t *uid) { start = startswith(slice, "user-"); if (!start) - return -ENOENT; + return -ENXIO; end = endswith(slice, ".slice"); if (!end) - return -ENOENT; + return -ENXIO; s = strndupa(start, end - start); if (!s) - return -ENOENT; + return -ENXIO; if (parse_uid(s, &u) < 0) - return -EIO; + return -ENXIO; if (uid) *uid = u; @@ -1415,7 +1415,7 @@ int cg_path_get_slice(const char *p, char **slice) { char *s; if (!e) - return -ENOENT; + return -ENXIO; s = strndup(e, m); if (!s) diff --git a/src/shared/terminal-util.c b/src/shared/terminal-util.c index f5b6590993..042b88f222 100644 --- a/src/shared/terminal-util.c +++ b/src/shared/terminal-util.c @@ -1009,7 +1009,7 @@ int get_ctty_devnr(pid_t pid, dev_t *d) { return -EIO; if (major(ttynr) == 0 && minor(ttynr) == 0) - return -ENOENT; + return -ENXIO; if (d) *d = (dev_t) ttynr; |