*ret = TAKE_PTR(s);
return 0;
}
+
+int varlink_check_privileged_peer(sd_varlink *vl) {
+ int r;
+
+ assert(vl);
+
+ uid_t uid;
+ r = sd_varlink_get_peer_uid(vl, &uid);
+ if (r < 0)
+ return log_debug_errno(r, "Failed to get peer UID: %m");
+
+ if (uid != 0)
+ return sd_varlink_error(vl, SD_VARLINK_ERROR_PERMISSION_DENIED, /* parameters= */ NULL);
+
+ return 0;
+}
sd_varlink_server **ret,
sd_varlink_server_flags_t flags,
void *userdata);
+
+int varlink_check_privileged_peer(sd_varlink *vl);
p.remote = p.remote_user || p.remote_host;
/* Before we continue processing this, let's ensure the peer is privileged */
- uid_t peer_uid;
- r = sd_varlink_get_peer_uid(link, &peer_uid);
+ r = varlink_check_privileged_peer(link);
if (r < 0)
- return log_debug_errno(r, "Failed to get peer UID: %m");
- if (peer_uid != 0)
- return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, /* parameters= */ NULL);
+ return r;
if (!pidref_is_set(&p.pid)) {
r = varlink_get_peer_pidref(link, &p.pid);
};
int r, mnt_id = 0;
struct stat userns_st;
- uid_t peer_uid;
assert(link);
assert(parameters);
return r;
/* Allowlisting arbitrary mounts is a privileged operation */
- r = sd_varlink_get_peer_uid(link, &peer_uid);
+ r = varlink_check_privileged_peer(link);
if (r < 0)
return r;
- if (peer_uid != 0)
- return sd_varlink_error(link, SD_VARLINK_ERROR_PERMISSION_DENIED, NULL);
r = sd_varlink_dispatch(link, parameters, parameter_dispatch_table, &p);
if (r != 0)