summaryrefslogtreecommitdiffstats
path: root/src/resolve/resolved-varlink.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-08-16 11:06:50 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-08-19 04:36:32 +0200
commit470cea62daa1d024613b99ffe827e7564e0752d5 (patch)
tree4289226113954d4d1cba9045192727b2b9d37322 /src/resolve/resolved-varlink.c
parentresolve: support polkit authentication for io.systemd.Resolve.Monitor (diff)
downloadsystemd-470cea62daa1d024613b99ffe827e7564e0752d5.tar.xz
systemd-470cea62daa1d024613b99ffe827e7564e0752d5.zip
resolve: inherit server userdata
No functional change, just refactoring.
Diffstat (limited to '')
-rw-r--r--src/resolve/resolved-varlink.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/src/resolve/resolved-varlink.c b/src/resolve/resolved-varlink.c
index 3c6d70ae1e..fe0482dffb 100644
--- a/src/resolve/resolved-varlink.c
+++ b/src/resolve/resolved-varlink.c
@@ -1241,7 +1241,7 @@ static int verify_polkit(sd_varlink *link, sd_json_variant *parameters, const ch
};
int r;
- Manager *m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(ASSERT_PTR(link))));
+ Manager *m = ASSERT_PTR(sd_varlink_get_userdata(ASSERT_PTR(link)));
assert(action);
@@ -1258,13 +1258,9 @@ static int verify_polkit(sd_varlink *link, sd_json_variant *parameters, const ch
}
static int vl_method_subscribe_query_results(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
- Manager *m;
+ Manager *m = ASSERT_PTR(sd_varlink_get_userdata(ASSERT_PTR(link)));
int r;
- assert(link);
-
- m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link)));
-
/* if the client didn't set the more flag, it is using us incorrectly */
if (!FLAGS_SET(flags, SD_VARLINK_METHOD_MORE))
return sd_varlink_error(link, SD_VARLINK_ERROR_EXPECTED_MORE, NULL);
@@ -1291,7 +1287,7 @@ static int vl_method_subscribe_query_results(sd_varlink *link, sd_json_variant *
static int vl_method_dump_cache(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *list = NULL;
- Manager *m;
+ Manager *m = ASSERT_PTR(sd_varlink_get_userdata(ASSERT_PTR(link)));
int r;
assert(link);
@@ -1300,8 +1296,6 @@ static int vl_method_dump_cache(sd_varlink *link, sd_json_variant *parameters, s
if (r <= 0)
return r;
- m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link)));
-
LIST_FOREACH(scopes, s, m->dns_scopes) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
@@ -1339,18 +1333,14 @@ static int dns_server_dump_state_to_json_list(DnsServer *server, sd_json_variant
static int vl_method_dump_server_state(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *list = NULL;
- Manager *m;
- int r;
+ Manager *m = ASSERT_PTR(sd_varlink_get_userdata(ASSERT_PTR(link)));
Link *l;
-
- assert(link);
+ int r;
r = verify_polkit(link, parameters, "org.freedesktop.resolve1.dump-server-state");
if (r <= 0)
return r;
- m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link)));
-
LIST_FOREACH(servers, server, m->dns_servers) {
r = dns_server_dump_state_to_json_list(server, &list);
if (r < 0)
@@ -1381,7 +1371,7 @@ static int vl_method_dump_server_state(sd_varlink *link, sd_json_variant *parame
static int vl_method_dump_statistics(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
_cleanup_(sd_json_variant_unrefp) sd_json_variant *j = NULL;
- Manager *m;
+ Manager *m = ASSERT_PTR(sd_varlink_get_userdata(ASSERT_PTR(link)));
int r;
assert(link);
@@ -1390,8 +1380,6 @@ static int vl_method_dump_statistics(sd_varlink *link, sd_json_variant *paramete
if (r <= 0)
return r;
- m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link)));
-
r = dns_manager_dump_statistics_json(m, &j);
if (r < 0)
return r;
@@ -1400,17 +1388,13 @@ static int vl_method_dump_statistics(sd_varlink *link, sd_json_variant *paramete
}
static int vl_method_reset_statistics(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
- Manager *m;
+ Manager *m = ASSERT_PTR(sd_varlink_get_userdata(ASSERT_PTR(link)));
int r;
- assert(link);
-
r = verify_polkit(link, parameters, "org.freedesktop.resolve1.reset-statistics");
if (r <= 0)
return r;
- m = ASSERT_PTR(sd_varlink_server_get_userdata(sd_varlink_get_server(link)));
-
dns_manager_reset_statistics(m);
return sd_varlink_replyb(link, SD_JSON_BUILD_EMPTY_OBJECT);
@@ -1425,7 +1409,7 @@ static int varlink_monitor_server_init(Manager *m) {
if (m->varlink_monitor_server)
return 0;
- r = sd_varlink_server_new(&server, SD_VARLINK_SERVER_ACCOUNT_UID);
+ r = sd_varlink_server_new(&server, SD_VARLINK_SERVER_ACCOUNT_UID|SD_VARLINK_SERVER_INHERIT_USERDATA);
if (r < 0)
return log_error_errno(r, "Failed to allocate varlink server object: %m");