X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-bus%2Fbus-util.c;h=bdaa4494a1994a9c2122fb0df01936e877fedfab;hb=840ceb897ff2b44275dcf2fe8227a750941789f0;hp=c97bf7d99d04ba775d66158512b3f39592f5b221;hpb=430e21c2f7e77d600257ead56419f511e48e854a;p=elogind.git diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c index c97bf7d99..bdaa4494a 100644 --- a/src/libsystemd/sd-bus/bus-util.c +++ b/src/libsystemd/sd-bus/bus-util.c @@ -212,13 +212,19 @@ int bus_verify_polkit( #ifdef ENABLE_POLKIT else { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - int authorized = false, challenge = false; + int authorized = false, challenge = false, c; const char *sender; sender = sd_bus_message_get_sender(call); if (!sender) return -EBADMSG; + c = sd_bus_message_get_allow_interactive_authorization(call); + if (c < 0) + return c; + if (c > 0) + interactive = true; + r = sd_bus_call_method( call->bus, "org.freedesktop.PolicyKit1", @@ -231,7 +237,7 @@ int bus_verify_polkit( "system-bus-name", 1, "name", "s", sender, action, 0, - interactive ? 1 : 0, + !!interactive, ""); if (r < 0) { @@ -334,6 +340,7 @@ int bus_verify_polkit_async( const char *sender; sd_bus_message_handler_t callback; void *userdata; + int c; #endif int r; @@ -375,6 +382,9 @@ int bus_verify_polkit_async( if (authorized) return 1; + if (challenge) + return sd_bus_error_set(error, SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED, "Interactive authentication required."); + return -EACCES; } #endif @@ -399,7 +409,13 @@ int bus_verify_polkit_async( if (!sender) return -EBADMSG; - r = hashmap_ensure_allocated(registry, trivial_hash_func, trivial_compare_func); + c = sd_bus_message_get_allow_interactive_authorization(call); + if (c < 0) + return c; + if (c > 0) + interactive = true; + + r = hashmap_ensure_allocated(registry, NULL); if (r < 0) return r; @@ -419,7 +435,7 @@ int bus_verify_polkit_async( "system-bus-name", 1, "name", "s", sender, action, 0, - interactive ? 1 : 0, + !!interactive, NULL); if (r < 0) return r; @@ -505,7 +521,7 @@ int bus_open_system_systemd(sd_bus **_bus) { if (r < 0) return r; - r = sd_bus_set_address(bus, KERNEL_SYSTEM_BUS_PATH); + r = sd_bus_set_address(bus, KERNEL_SYSTEM_BUS_ADDRESS); if (r < 0) return r; @@ -558,7 +574,7 @@ int bus_open_user_systemd(sd_bus **_bus) { if (r < 0) return r; - if (asprintf(&bus->address, KERNEL_USER_BUS_FMT, getuid()) < 0) + if (asprintf(&bus->address, KERNEL_USER_BUS_ADDRESS_FMT, getuid()) < 0) return -ENOMEM; bus->bus_client = true; @@ -624,14 +640,21 @@ int bus_print_property(const char *name, sd_bus_message *property, bool all) { if (r < 0) return r; - if (all || !isempty(s)) - printf("%s=%s\n", name, s); + if (all || !isempty(s)) { + _cleanup_free_ char *escaped = NULL; + + escaped = xescape(s, "\n"); + if (!escaped) + return -ENOMEM; + + printf("%s=%s\n", name, escaped); + } return 1; } case SD_BUS_TYPE_BOOLEAN: { - bool b; + int b; r = sd_bus_message_read_basic(property, type, &b); if (r < 0) @@ -716,10 +739,16 @@ int bus_print_property(const char *name, sd_bus_message *property, bool all) { return r; while((r = sd_bus_message_read_basic(property, SD_BUS_TYPE_STRING, &str)) > 0) { + _cleanup_free_ char *escaped = NULL; + if (first) printf("%s=", name); - printf("%s%s", first ? "" : " ", str); + escaped = xescape(str, "\n "); + if (!escaped) + return -ENOMEM; + + printf("%s%s", first ? "" : " ", escaped); first = false; } @@ -974,32 +1003,17 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_ return r; } -int bus_map_all_properties(sd_bus *bus, - const char *destination, - const char *path, - const struct bus_properties_map *map, - void *userdata) { - _cleanup_bus_message_unref_ sd_bus_message *m = NULL; +int bus_message_map_all_properties(sd_bus *bus, + sd_bus_message *m, + const struct bus_properties_map *map, + void *userdata) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; int r; assert(bus); - assert(destination); - assert(path); + assert(m); assert(map); - r = sd_bus_call_method( - bus, - destination, - path, - "org.freedesktop.DBus.Properties", - "GetAll", - &error, - &m, - "s", ""); - if (r < 0) - return r; - r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}"); if (r < 0) return r; @@ -1052,7 +1066,70 @@ int bus_map_all_properties(sd_bus *bus, return r; } - return r; + return sd_bus_message_exit_container(m); +} + +int bus_message_map_properties_changed(sd_bus *bus, + sd_bus_message *m, + const struct bus_properties_map *map, + void *userdata) { + const char *member; + int r, invalidated, i; + + assert(bus); + assert(m); + assert(map); + + r = bus_message_map_all_properties(bus, m, map, userdata); + if (r < 0) + return r; + + r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "s"); + if (r < 0) + return r; + + invalidated = 0; + while ((r = sd_bus_message_read_basic(m, SD_BUS_TYPE_STRING, &member)) > 0) + for (i = 0; map[i].member; i++) + if (streq(map[i].member, member)) { + ++invalidated; + break; + } + + r = sd_bus_message_exit_container(m); + if (r < 0) + return r; + + return invalidated; +} + +int bus_map_all_properties(sd_bus *bus, + const char *destination, + const char *path, + const struct bus_properties_map *map, + void *userdata) { + _cleanup_bus_message_unref_ sd_bus_message *m = NULL; + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + int r; + + assert(bus); + assert(destination); + assert(path); + assert(map); + + r = sd_bus_call_method( + bus, + destination, + path, + "org.freedesktop.DBus.Properties", + "GetAll", + &error, + &m, + "s", ""); + if (r < 0) + return r; + + return bus_message_map_all_properties(bus, m, map, userdata); } int bus_open_transport(BusTransport transport, const char *host, bool user, sd_bus **bus) { @@ -1186,13 +1263,11 @@ int bus_property_get_ulong( #endif int bus_log_parse_error(int r) { - log_error("Failed to parse bus message: %s", strerror(-r)); - return r; + return log_error_errno(r, "Failed to parse bus message: %m"); } int bus_log_create_error(int r) { - log_error("Failed to create bus message: %s", strerror(-r)); - return r; + return log_error_errno(r, "Failed to create bus message: %m"); } int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) {