X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-bus%2Fbus-creds.c;h=9978ddfa3836918417185d7361798f8549d914ad;hp=7a73387fb6f5b35c6042927698c44a5f18f4ea58;hb=2822da4fb7f891e5320f02f1d00f64b72221ced4;hpb=0258159049d5b381c6097533a69a1b29c3ba7ce2 diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index 7a73387fb..9978ddfa3 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -51,10 +51,14 @@ void bus_creds_done(sd_bus_creds *c) { free(c->slice); free(c->unescaped_description); - strv_free(c->cmdline_array); - strv_free(c->well_known_names); + free(c->well_known_names); /* note that this is an strv, but + * we only free the array, not the + * strings the array points to. The + * full strv we only free if + * c->allocated is set, see + * below. */ - free(c->supplementary_gids); + strv_free(c->cmdline_array); } _public_ sd_bus_creds *sd_bus_creds_ref(sd_bus_creds *c) { @@ -85,8 +89,6 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) { c->n_ref--; if (c->n_ref == 0) { - bus_creds_done(c); - free(c->comm); free(c->tid_comm); free(c->exe); @@ -97,6 +99,13 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) { free(c->unique_name); free(c->cgroup_root); free(c->description); + free(c->supplementary_gids); + + strv_free(c->well_known_names); + c->well_known_names = NULL; + + bus_creds_done(c); + free(c); } } else { @@ -285,18 +294,6 @@ _public_ int sd_bus_creds_get_tid(sd_bus_creds *c, pid_t *tid) { return 0; } -_public_ int sd_bus_creds_get_pid_starttime(sd_bus_creds *c, uint64_t *usec) { - assert_return(c, -EINVAL); - assert_return(usec, -EINVAL); - - if (!(c->mask & SD_BUS_CREDS_PID_STARTTIME)) - return -ENODATA; - - assert(c->pid_starttime > 0); - *usec = c->pid_starttime; - return 0; -} - _public_ int sd_bus_creds_get_selinux_context(sd_bus_creds *c, const char **ret) { assert_return(c, -EINVAL); @@ -542,6 +539,28 @@ _public_ int sd_bus_creds_get_well_known_names(sd_bus_creds *c, char ***well_kno if (!(c->mask & SD_BUS_CREDS_WELL_KNOWN_NAMES)) return -ENODATA; + /* As a special hack we return the bus driver as well-known + * names list when this is requested. */ + if (c->well_known_names_driver) { + static const char* const wkn[] = { + "org.freedesktop.DBus", + NULL + }; + + *well_known_names = (char**) wkn; + return 0; + } + + if (c->well_known_names_local) { + static const char* const wkn[] = { + "org.freedesktop.DBus.Local", + NULL + }; + + *well_known_names = (char**) wkn; + return 0; + } + *well_known_names = c->well_known_names; return 0; } @@ -828,19 +847,6 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) { } } - if (missing & (SD_BUS_CREDS_PID_STARTTIME)) { - unsigned long long st; - - r = get_starttime_of_pid(pid, &st); - if (r < 0) { - if (r != -EPERM && r != -EACCES) - return r; - } else { - c->pid_starttime = ((usec_t) st * USEC_PER_SEC) / (usec_t) sysconf(_SC_CLK_TCK); - c->mask |= SD_BUS_CREDS_PID_STARTTIME; - } - } - if (missing & SD_BUS_CREDS_SELINUX_CONTEXT) { const char *p; @@ -1021,11 +1027,6 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret) n->mask |= SD_BUS_CREDS_TID; } - if (c->mask & mask & SD_BUS_CREDS_PID_STARTTIME) { - n->pid_starttime = c->pid_starttime; - n->mask |= SD_BUS_CREDS_PID_STARTTIME; - } - if (c->mask & mask & SD_BUS_CREDS_COMM) { n->comm = strdup(c->comm); if (!n->comm) @@ -1080,11 +1081,17 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret) n->mask |= c->mask & mask & (SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS); } + if (c->mask & mask & SD_BUS_CREDS_SELINUX_CONTEXT) { + n->label = strdup(c->label); + if (!n->label) + return -ENOMEM; + n->mask |= SD_BUS_CREDS_SELINUX_CONTEXT; + } + if (c->mask & mask & SD_BUS_CREDS_AUDIT_SESSION_ID) { n->audit_session_id = c->audit_session_id; n->mask |= SD_BUS_CREDS_AUDIT_SESSION_ID; } - if (c->mask & mask & SD_BUS_CREDS_AUDIT_LOGIN_UID) { n->audit_login_uid = c->audit_login_uid; n->mask |= SD_BUS_CREDS_AUDIT_LOGIN_UID; @@ -1094,12 +1101,21 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret) n->unique_name = strdup(c->unique_name); if (!n->unique_name) return -ENOMEM; + n->mask |= SD_BUS_CREDS_UNIQUE_NAME; } if (c->mask & mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) { n->well_known_names = strv_copy(c->well_known_names); if (!n->well_known_names) return -ENOMEM; + n->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES; + } + + if (c->mask & mask & SD_BUS_CREDS_DESCRIPTION) { + n->description = strdup(c->description); + if (!n->description) + return -ENOMEM; + n->mask |= SD_BUS_CREDS_DESCRIPTION; } /* Get more data */