[systemd-devel] [PATCH] libsystemd-bus: Add checking masks creds in bus_creds_dump() function
Lukasz Skalski
l.skalski at partner.samsung.com
Wed Dec 11 06:23:36 PST 2013
log_assert_failed_return macro generates a lot of logs when we use
bus_message_dump() function without checking masks in creds.
---
src/libsystemd-bus/bus-dump.c | 93 +++++++++++++++++++++++++++----------------
1 file changed, 59 insertions(+), 34 deletions(-)
diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
index ddad418..85396aa 100644
--- a/src/libsystemd-bus/bus-dump.c
+++ b/src/libsystemd-bus/bus-dump.c
@@ -322,9 +322,12 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) {
fprintf(f, " TID=%lu", (unsigned long) c->tid);
if (c->mask & SD_BUS_CREDS_UID)
fprintf(f, " UID=%lu", (unsigned long) c->uid);
- r = sd_bus_creds_get_owner_uid(c, &owner);
- if (r >= 0)
- fprintf(f, " OwnerUID=%lu", (unsigned long) owner);
+ if (c->mask & SD_BUS_CREDS_OWNER_UID) {
+ r = sd_bus_creds_get_owner_uid(c, &owner);
+ if (r >= 0)
+ fprintf(f, " OwnerUID=%lu", (unsigned long) owner);
+ }
+
if (c->mask & SD_BUS_CREDS_GID)
fprintf(f, " GID=%lu", (unsigned long) c->gid);
@@ -359,29 +362,45 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) {
if (c->mask & SD_BUS_CREDS_CGROUP)
fprintf(f, " CGroup=%s", c->cgroup);
- sd_bus_creds_get_unit(c, &u);
- if (u)
- fprintf(f, " Unit=%s", u);
- sd_bus_creds_get_user_unit(c, &uu);
- if (uu)
- fprintf(f, " UserUnit=%s", uu);
- sd_bus_creds_get_slice(c, &sl);
- if (sl)
- fprintf(f, " Slice=%s", sl);
- sd_bus_creds_get_session(c, &s);
- if (s)
- fprintf(f, " Session=%s", s);
+ if (c->mask & SD_BUS_CREDS_UNIT) {
+ sd_bus_creds_get_unit(c, &u);
+ if (u)
+ fprintf(f, " Unit=%s", u);
+ }
+
+ if (c->mask & SD_BUS_CREDS_USER_UNIT) {
+ sd_bus_creds_get_user_unit(c, &uu);
+ if (uu)
+ fprintf(f, " UserUnit=%s", uu);
+ }
+
+ if (c->mask & SD_BUS_CREDS_SLICE) {
+ sd_bus_creds_get_slice(c, &sl);
+ if (sl)
+ fprintf(f, " Slice=%s", sl);
+ }
+
+ if (c->mask & SD_BUS_CREDS_SESSION) {
+ sd_bus_creds_get_session(c, &s);
+ if (s)
+ fprintf(f, " Session=%s", s);
+ }
if ((c->mask & SD_BUS_CREDS_CGROUP) || u || uu || sl || s)
fputs("\n", f);
- if (sd_bus_creds_get_audit_login_uid(c, &audit_loginuid) >= 0) {
- audit_loginuid_is_set = true;
- fprintf(f, " AuditLoginUID=%lu", (unsigned long) audit_loginuid);
+ if (c->mask & SD_BUS_CREDS_AUDIT_LOGIN_UID) {
+ if (sd_bus_creds_get_audit_login_uid(c, &audit_loginuid) >= 0) {
+ audit_loginuid_is_set = true;
+ fprintf(f, " AuditLoginUID=%lu", (unsigned long) audit_loginuid);
+ }
}
- if (sd_bus_creds_get_audit_session_id(c, &audit_sessionid) >= 0) {
- audit_sessionid_is_set = true;
- fprintf(f, " AuditSessionID=%lu", (unsigned long) audit_sessionid);
+
+ if (c->mask & SD_BUS_CREDS_AUDIT_SESSION_ID) {
+ if (sd_bus_creds_get_audit_session_id(c, &audit_sessionid) >= 0) {
+ audit_sessionid_is_set = true;
+ fprintf(f, " AuditSessionID=%lu", (unsigned long) audit_sessionid);
+ }
}
if (audit_loginuid_is_set || audit_sessionid_is_set)
@@ -390,27 +409,33 @@ int bus_creds_dump(sd_bus_creds *c, FILE *f) {
if (c->mask & SD_BUS_CREDS_UNIQUE_NAME)
fprintf(f, " UniqueName=%s", c->unique_name);
- if (sd_bus_creds_get_well_known_names(c, &well_known) >= 0) {
- char **i;
+ if (c->mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) {
+ if (sd_bus_creds_get_well_known_names(c, &well_known) >= 0) {
+ char **i;
- fputs(" WellKnownNames={", f);
- STRV_FOREACH(i, well_known) {
- if (i != well_known)
- fputc(' ', f);
+ fputs(" WellKnownNames={", f);
+ STRV_FOREACH(i, well_known) {
+ if (i != well_known)
+ fputc(' ', f);
- fputs(*i, f);
- }
+ fputs(*i, f);
+ }
- fputc('}', f);
+ fputc('}', f);
+ }
}
if (c->mask & SD_BUS_CREDS_UNIQUE_NAME || well_known)
fputc('\n', f);
- dump_capabilities(c, f, "EffectiveCapabilities", sd_bus_creds_has_effective_cap);
- dump_capabilities(c, f, "PermittedCapabilities", sd_bus_creds_has_permitted_cap);
- dump_capabilities(c, f, "InheritableCapabilities", sd_bus_creds_has_inheritable_cap);
- dump_capabilities(c, f, "BoundingCapabilities", sd_bus_creds_has_bounding_cap);
+ if (c->mask & SD_BUS_CREDS_EFFECTIVE_CAPS)
+ dump_capabilities(c, f, "EffectiveCapabilities", sd_bus_creds_has_effective_cap);
+ if (c->mask & SD_BUS_CREDS_PERMITTED_CAPS)
+ dump_capabilities(c, f, "PermittedCapabilities", sd_bus_creds_has_permitted_cap);
+ if (c->mask & SD_BUS_CREDS_INHERITABLE_CAPS)
+ dump_capabilities(c, f, "InheritableCapabilities", sd_bus_creds_has_inheritable_cap);
+ if (c->mask & SD_BUS_CREDS_BOUNDING_CAPS)
+ dump_capabilities(c, f, "BoundingCapabilities", sd_bus_creds_has_bounding_cap);
return 0;
}
--
1.8.3.2
More information about the systemd-devel
mailing list