| 1 |
/* |
| 2 |
* DBus Driver |
| 3 |
*/ |
| 4 |
|
| 5 |
#include <c-dvar.h> |
| 6 |
#include <c-dvar-type.h> |
| 7 |
#include <c-stdaux.h> |
| 8 |
#include <stdlib.h> |
| 9 |
#include <sys/epoll.h> |
| 10 |
#include "broker/broker.h" |
| 11 |
#include "broker/controller.h" |
| 12 |
#include "bus/activation.h" |
| 13 |
#include "bus/bus.h" |
| 14 |
#include "bus/driver.h" |
| 15 |
#include "bus/match.h" |
| 16 |
#include "bus/peer.h" |
| 17 |
#include "catalog/catalog-ids.h" |
| 18 |
#include "dbus/address.h" |
| 19 |
#include "dbus/message.h" |
| 20 |
#include "dbus/protocol.h" |
| 21 |
#include "dbus/socket.h" |
| 22 |
#include "util/apparmor.h" |
| 23 |
#include "util/error.h" |
| 24 |
#include "util/misc.h" |
| 25 |
#include "util/selinux.h" |
| 26 |
#include "util/string.h" |
| 27 |
|
| 28 |
typedef struct DriverCredentials DriverCredentials; |
| 29 |
typedef struct DriverInterface DriverInterface; |
| 30 |
typedef struct DriverMethod DriverMethod; |
| 31 |
typedef int (*DriverMethodFn) (Peer *peer, const char *path, CDVar *var_in, uint32_t serial, CDVar *var_out); |
| 32 |
|
| 33 |
struct DriverCredentials { |
| 34 |
pid_t pid; |
| 35 |
int pid_fd; |
| 36 |
uid_t uid; |
| 37 |
gid_t *gids; |
| 38 |
size_t n_gids; |
| 39 |
const char *seclabel; |
| 40 |
size_t n_seclabel; |
| 41 |
}; |
| 42 |
|
| 43 |
#define DRIVER_CREDENTIALS_NULL { \ |
| 44 |
.pid_fd = -1, \ |
| 45 |
.uid = -1, \ |
| 46 |
} |
| 47 |
|
| 48 |
struct DriverMethod { |
| 49 |
const char *name; |
| 50 |
bool needs_registration; |
| 51 |
const char *path; |
| 52 |
DriverMethodFn fn; |
| 53 |
const CDVarType *in; |
| 54 |
const CDVarType *out; |
| 55 |
bool writes_own_header; |
| 56 |
}; |
| 57 |
|
| 58 |
struct DriverInterface { |
| 59 |
const char *name; |
| 60 |
const DriverMethod *methods; |
| 61 |
}; |
| 62 |
|
| 63 |
/* |
| 64 |
* This macro defines a c-dvar type for DBus Messages. It evaluates to: |
| 65 |
* |
| 66 |
* ((yyyyuua(yv))X) |
| 67 |
* |
| 68 |
* ..where 'X' is provided via @_body. That is, it evaluates to the combination |
| 69 |
* of DBus Header and DBus Body for a given body-type. |
| 70 |
*/ |
| 71 |
#define DRIVER_T_MESSAGE(_body) \ |
| 72 |
C_DVAR_T_TUPLE2( \ |
| 73 |
C_DVAR_T_TUPLE7( \ |
| 74 |
C_DVAR_T_y, \ |
| 75 |
C_DVAR_T_y, \ |
| 76 |
C_DVAR_T_y, \ |
| 77 |
C_DVAR_T_y, \ |
| 78 |
C_DVAR_T_u, \ |
| 79 |
C_DVAR_T_u, \ |
| 80 |
C_DVAR_T_ARRAY( \ |
| 81 |
C_DVAR_T_TUPLE2( \ |
| 82 |
C_DVAR_T_y, \ |
| 83 |
C_DVAR_T_v \ |
| 84 |
) \ |
| 85 |
) \ |
| 86 |
), \ |
| 87 |
_body \ |
| 88 |
) |
| 89 |
|
| 90 |
static const CDVarType driver_type_in_s[] = { |
| 91 |
C_DVAR_T_INIT( |
| 92 |
C_DVAR_T_TUPLE1( |
| 93 |
C_DVAR_T_s |
| 94 |
) |
| 95 |
) |
| 96 |
}; |
| 97 |
static const CDVarType driver_type_in_su[] = { |
| 98 |
C_DVAR_T_INIT( |
| 99 |
C_DVAR_T_TUPLE2( |
| 100 |
C_DVAR_T_s, |
| 101 |
C_DVAR_T_u |
| 102 |
) |
| 103 |
) |
| 104 |
}; |
| 105 |
static const CDVarType driver_type_in_ss[] = { |
| 106 |
C_DVAR_T_INIT( |
| 107 |
C_DVAR_T_TUPLE2( |
| 108 |
C_DVAR_T_s, |
| 109 |
C_DVAR_T_s |
| 110 |
) |
| 111 |
) |
| 112 |
}; |
| 113 |
static const CDVarType driver_type_in_ssv[] = { |
| 114 |
C_DVAR_T_INIT( |
| 115 |
C_DVAR_T_TUPLE3( |
| 116 |
C_DVAR_T_s, |
| 117 |
C_DVAR_T_s, |
| 118 |
C_DVAR_T_v |
| 119 |
) |
| 120 |
) |
| 121 |
}; |
| 122 |
static const CDVarType driver_type_in_apss[] = { |
| 123 |
C_DVAR_T_INIT( |
| 124 |
C_DVAR_T_TUPLE1( |
| 125 |
C_DVAR_T_ARRAY( |
| 126 |
C_DVAR_T_PAIR( |
| 127 |
C_DVAR_T_s, |
| 128 |
C_DVAR_T_s |
| 129 |
) |
| 130 |
) |
| 131 |
) |
| 132 |
) |
| 133 |
}; |
| 134 |
static const CDVarType driver_type_in_asu[] = { |
| 135 |
C_DVAR_T_INIT( |
| 136 |
C_DVAR_T_TUPLE2( |
| 137 |
C_DVAR_T_ARRAY( |
| 138 |
C_DVAR_T_s |
| 139 |
), |
| 140 |
C_DVAR_T_u |
| 141 |
) |
| 142 |
) |
| 143 |
}; |
| 144 |
static const CDVarType driver_type_out_unit[] = { |
| 145 |
C_DVAR_T_INIT( |
| 146 |
DRIVER_T_MESSAGE( |
| 147 |
C_DVAR_T_TUPLE0 |
| 148 |
) |
| 149 |
) |
| 150 |
}; |
| 151 |
static const CDVarType driver_type_out_s[] = { |
| 152 |
C_DVAR_T_INIT( |
| 153 |
DRIVER_T_MESSAGE( |
| 154 |
C_DVAR_T_TUPLE1( |
| 155 |
C_DVAR_T_s |
| 156 |
) |
| 157 |
) |
| 158 |
) |
| 159 |
}; |
| 160 |
static const CDVarType driver_type_out_b[] = { |
| 161 |
C_DVAR_T_INIT( |
| 162 |
DRIVER_T_MESSAGE( |
| 163 |
C_DVAR_T_TUPLE1( |
| 164 |
C_DVAR_T_b |
| 165 |
) |
| 166 |
) |
| 167 |
) |
| 168 |
}; |
| 169 |
static const CDVarType driver_type_out_u[] = { |
| 170 |
C_DVAR_T_INIT( |
| 171 |
DRIVER_T_MESSAGE( |
| 172 |
C_DVAR_T_TUPLE1( |
| 173 |
C_DVAR_T_u |
| 174 |
) |
| 175 |
) |
| 176 |
) |
| 177 |
}; |
| 178 |
static const CDVarType driver_type_out_v[] = { |
| 179 |
C_DVAR_T_INIT( |
| 180 |
DRIVER_T_MESSAGE( |
| 181 |
C_DVAR_T_TUPLE1( |
| 182 |
C_DVAR_T_v |
| 183 |
) |
| 184 |
) |
| 185 |
) |
| 186 |
}; |
| 187 |
static const CDVarType driver_type_out_as[] = { |
| 188 |
C_DVAR_T_INIT( |
| 189 |
DRIVER_T_MESSAGE( |
| 190 |
C_DVAR_T_TUPLE1( |
| 191 |
C_DVAR_T_ARRAY( |
| 192 |
C_DVAR_T_s |
| 193 |
) |
| 194 |
) |
| 195 |
) |
| 196 |
) |
| 197 |
}; |
| 198 |
static const CDVarType driver_type_out_ay[] = { |
| 199 |
C_DVAR_T_INIT( |
| 200 |
DRIVER_T_MESSAGE( |
| 201 |
C_DVAR_T_TUPLE1( |
| 202 |
C_DVAR_T_ARRAY( |
| 203 |
C_DVAR_T_y |
| 204 |
) |
| 205 |
) |
| 206 |
) |
| 207 |
) |
| 208 |
}; |
| 209 |
static const CDVarType driver_type_out_apsv[] = { |
| 210 |
C_DVAR_T_INIT( |
| 211 |
DRIVER_T_MESSAGE( |
| 212 |
C_DVAR_T_TUPLE1( |
| 213 |
C_DVAR_T_ARRAY( |
| 214 |
C_DVAR_T_PAIR( |
| 215 |
C_DVAR_T_s, |
| 216 |
C_DVAR_T_v |
| 217 |
) |
| 218 |
) |
| 219 |
) |
| 220 |
) |
| 221 |
) |
| 222 |
}; |
| 223 |
static const CDVarType driver_type_out_apsas[] = { |
| 224 |
C_DVAR_T_INIT( |
| 225 |
DRIVER_T_MESSAGE( |
| 226 |
C_DVAR_T_TUPLE1( |
| 227 |
C_DVAR_T_ARRAY( |
| 228 |
C_DVAR_T_PAIR( |
| 229 |
C_DVAR_T_s, |
| 230 |
C_DVAR_T_ARRAY( |
| 231 |
C_DVAR_T_s |
| 232 |
) |
| 233 |
) |
| 234 |
) |
| 235 |
) |
| 236 |
) |
| 237 |
) |
| 238 |
}; |
| 239 |
|
| 240 |
static void driver_write_bytes(CDVar *var, const char *bytes, size_t n_bytes) { |
| 241 |
c_dvar_write(var, "["); |
| 242 |
for (size_t i = 0; i < n_bytes; ++i) |
| 243 |
c_dvar_write(var, "y", bytes[i]); |
| 244 |
c_dvar_write(var, "]"); |
| 245 |
} |
| 246 |
|
| 247 |
static void driver_dvar_write_unique_name(CDVar *var, Peer *peer) { |
| 248 |
c_dvar_write(var, "s", address_to_string(&(Address)ADDRESS_INIT_ID(peer->id))); |
| 249 |
} |
| 250 |
|
| 251 |
static void driver_dvar_write_signature_out(CDVar *var, const CDVarType *type) { |
| 252 |
char signature[C_DVAR_TYPE_LENGTH_MAX + 1]; |
| 253 |
|
| 254 |
c_assert(type->length < sizeof(signature) + strlen("((yyyyuua(yv))())")); |
| 255 |
c_assert(type[0].element == '('); |
| 256 |
c_assert(type[1].element == '('); |
| 257 |
c_assert(type[2].element == 'y'); |
| 258 |
c_assert(type[3].element == 'y'); |
| 259 |
c_assert(type[4].element == 'y'); |
| 260 |
c_assert(type[5].element == 'y'); |
| 261 |
c_assert(type[6].element == 'u'); |
| 262 |
c_assert(type[7].element == 'u'); |
| 263 |
c_assert(type[8].element == 'a'); |
| 264 |
c_assert(type[9].element == '('); |
| 265 |
c_assert(type[10].element == 'y'); |
| 266 |
c_assert(type[11].element == 'v'); |
| 267 |
c_assert(type[12].element == ')'); |
| 268 |
c_assert(type[13].element == ')'); |
| 269 |
c_assert(type[14].element == '('); |
| 270 |
c_assert(type[type->length - 2].element == ')'); |
| 271 |
c_assert(type[type->length - 1].element == ')'); |
| 272 |
|
| 273 |
for (unsigned int i = strlen("((yyyyuua(yv))("), j = 0; i < type->length - strlen("))"); i++, j++) |
| 274 |
signature[j] = type[i].element; |
| 275 |
|
| 276 |
signature[type->length - strlen("((yyyyuua(yv))())")] = '\0'; |
| 277 |
|
| 278 |
c_dvar_write(var, "g", signature); |
| 279 |
} |
| 280 |
|
| 281 |
static int driver_dvar_verify_signature_in(const CDVarType *type, const char *signature) { |
| 282 |
if (type->length != strlen(signature) + 2) |
| 283 |
return DRIVER_E_UNEXPECTED_SIGNATURE; |
| 284 |
|
| 285 |
c_assert(type[0].element == '('); |
| 286 |
c_assert(type[type->length - 1].element == ')'); |
| 287 |
|
| 288 |
for (unsigned int i = 1; i + 1 < type->length; i++) |
| 289 |
if (signature[i - 1] != type[i].element) |
| 290 |
return DRIVER_E_UNEXPECTED_SIGNATURE; |
| 291 |
|
| 292 |
return 0; |
| 293 |
} |
| 294 |
|
| 295 |
static void driver_write_reply_header(CDVar *var, Peer *peer, uint32_t serial, const CDVarType *type, size_t n_fds) { |
| 296 |
c_dvar_write(var, "(yyyyuu[(y<u>)(y<s>)(y<", |
| 297 |
c_dvar_is_big_endian(var) ? 'B' : 'l', DBUS_MESSAGE_TYPE_METHOD_RETURN, DBUS_HEADER_FLAG_NO_REPLY_EXPECTED, 1, 0, (uint32_t)-1, |
| 298 |
DBUS_MESSAGE_FIELD_REPLY_SERIAL, c_dvar_type_u, serial, |
| 299 |
DBUS_MESSAGE_FIELD_SENDER, c_dvar_type_s, "org.freedesktop.DBus", |
| 300 |
DBUS_MESSAGE_FIELD_DESTINATION, c_dvar_type_s); |
| 301 |
driver_dvar_write_unique_name(var, peer); |
| 302 |
c_dvar_write(var, ">)(y<", |
| 303 |
DBUS_MESSAGE_FIELD_SIGNATURE, c_dvar_type_g); |
| 304 |
driver_dvar_write_signature_out(var, type); |
| 305 |
c_dvar_write(var, ">)"); |
| 306 |
if (n_fds > 0) |
| 307 |
c_dvar_write(var, "(y<u>)", DBUS_MESSAGE_FIELD_UNIX_FDS, c_dvar_type_u, n_fds); |
| 308 |
c_dvar_write(var, "])"); |
| 309 |
} |
| 310 |
|
| 311 |
static void driver_write_signal_header(CDVar *var, Peer *peer, const char *member, const char *signature) { |
| 312 |
c_dvar_write(var, "(yyyyuu[(y<s>)", |
| 313 |
c_dvar_is_big_endian(var) ? 'B' : 'l', DBUS_MESSAGE_TYPE_SIGNAL, DBUS_HEADER_FLAG_NO_REPLY_EXPECTED, 1, 0, (uint32_t)-1, |
| 314 |
DBUS_MESSAGE_FIELD_SENDER, c_dvar_type_s, "org.freedesktop.DBus"); |
| 315 |
|
| 316 |
if (peer) { |
| 317 |
c_dvar_write(var, "(y<", DBUS_MESSAGE_FIELD_DESTINATION, c_dvar_type_s); |
| 318 |
driver_dvar_write_unique_name(var, peer); |
| 319 |
c_dvar_write(var, ">)"); |
| 320 |
} |
| 321 |
|
| 322 |
c_dvar_write(var, "(y<o>)(y<s>)(y<s>)(y<g>)])", |
| 323 |
DBUS_MESSAGE_FIELD_PATH, c_dvar_type_o, "/org/freedesktop/DBus", |
| 324 |
DBUS_MESSAGE_FIELD_INTERFACE, c_dvar_type_s, "org.freedesktop.DBus", |
| 325 |
DBUS_MESSAGE_FIELD_MEMBER, c_dvar_type_s, member, |
| 326 |
DBUS_MESSAGE_FIELD_SIGNATURE, c_dvar_type_g, signature); |
| 327 |
} |
| 328 |
|
| 329 |
static const char *driver_error_to_string(int r) { |
| 330 |
static const char *error_strings[_DRIVER_E_MAX] = { |
| 331 |
[DRIVER_E_UNIMPLEMENTED] = "Unimplemented functionality", |
| 332 |
[DRIVER_E_PEER_ALREADY_REGISTERED] = "Hello() already called", |
| 333 |
[DRIVER_E_PEER_NOT_YET_REGISTERED] = "Hello() was not yet called", |
| 334 |
[DRIVER_E_PEER_NOT_REGISTERED] = "Message forwarding attempted without calling Hello()", |
| 335 |
[DRIVER_E_PEER_NOT_PRIVILEGED] = "The caller does not have the necessary privileged to call this method", |
| 336 |
[DRIVER_E_MONITOR_READ_ONLY] = "Monitor attempted to send message", |
| 337 |
[DRIVER_E_UNEXPECTED_FDS] = "Peer does not support file descriptor passing.", |
| 338 |
[DRIVER_E_UNEXPECTED_MESSAGE_TYPE] = "Unexpected message type", |
| 339 |
[DRIVER_E_UNEXPECTED_PATH] = "Invalid object path", |
| 340 |
[DRIVER_E_UNEXPECTED_INTERFACE] = "Invalid interface", |
| 341 |
[DRIVER_E_UNEXPECTED_METHOD] = "Invalid method call", |
| 342 |
[DRIVER_E_UNEXPECTED_PROPERTY] = "Invalid property", |
| 343 |
[DRIVER_E_READONLY_PROPERTY] = "Cannot set read-only property", |
| 344 |
[DRIVER_E_UNEXPECTED_SIGNATURE] = "Invalid signature for method", |
| 345 |
[DRIVER_E_UNEXPECTED_REPLY] = "No pending reply with that serial", |
| 346 |
[DRIVER_E_FORWARD_FAILED] = "Request could not be forwarded to the parent process", |
| 347 |
[DRIVER_E_QUOTA] = "Sending user's quota exceeded", |
| 348 |
[DRIVER_E_UNEXPECTED_FLAGS] = "Invalid flags", |
| 349 |
[DRIVER_E_UNEXPECTED_ENVIRONMENT_UPDATE] = "User is not authorized to update environment variables", |
| 350 |
[DRIVER_E_SEND_DENIED] = "Sender is not authorized to send message", |
| 351 |
[DRIVER_E_RECEIVE_DENIED] = "Receiver is not authorized to receive message", |
| 352 |
[DRIVER_E_EXPECTED_REPLY_EXISTS] = "Pending reply with that serial already exists", |
| 353 |
[DRIVER_E_NAME_RESERVED] = "org.freedesktop.DBus is a reserved name", |
| 354 |
[DRIVER_E_NAME_UNIQUE] = "The name is a unique name", |
| 355 |
[DRIVER_E_NAME_INVALID] = "The name is not a valid well-known name", |
| 356 |
[DRIVER_E_NAME_REFUSED] = "Request to own name refused by policy", |
| 357 |
[DRIVER_E_NAME_NOT_FOUND] = "The name does not exist", |
| 358 |
[DRIVER_E_NAME_NOT_ACTIVATABLE] = "The name is not activatable", |
| 359 |
[DRIVER_E_NAME_OWNER_NOT_FOUND] = "The name does not have an owner", |
| 360 |
[DRIVER_E_PEER_NOT_FOUND] = "The connection does not exist", |
| 361 |
[DRIVER_E_DESTINATION_NOT_FOUND] = "Destination does not exist", |
| 362 |
[DRIVER_E_MATCH_INVALID] = "Invalid match rule", |
| 363 |
[DRIVER_E_MATCH_NOT_FOUND] = "The match does not exist", |
| 364 |
[DRIVER_E_ADT_NOT_SUPPORTED] = "Solaris ADT is not supported", |
| 365 |
[DRIVER_E_SELINUX_NOT_SUPPORTED] = "SELinux is not supported", |
| 366 |
}; |
| 367 |
c_assert(r >= 0 && r < _DRIVER_E_MAX && error_strings[r]); |
| 368 |
|
| 369 |
return error_strings[r]; |
| 370 |
} |
| 371 |
|
| 372 |
static int driver_monitor(Bus *bus, Peer *sender, Message *message) { |
| 373 |
_c_cleanup_(c_list_flush) CList destinations = C_LIST_INIT(destinations); |
| 374 |
MatchOwner *match_owner; |
| 375 |
int r; |
| 376 |
|
| 377 |
if (!bus->n_monitors) |
| 378 |
return 0; |
| 379 |
|
| 380 |
r = message_parse_metadata(message); |
| 381 |
if (r) |
| 382 |
return error_fold(r); |
| 383 |
|
| 384 |
bus_get_monitor_destinations(bus, &destinations, sender, &message->metadata); |
| 385 |
|
| 386 |
while ((match_owner = c_list_first_entry(&destinations, MatchOwner, destinations_link))) { |
| 387 |
Peer *receiver = c_container_of(match_owner, Peer, owned_matches); |
| 388 |
|
| 389 |
c_list_unlink(&match_owner->destinations_link); |
| 390 |
|
| 391 |
r = connection_queue(&receiver->connection, NULL, message); |
| 392 |
if (r) { |
| 393 |
if (r == CONNECTION_E_QUOTA || r == CONNECTION_E_UNEXPECTED_FDS) { |
| 394 |
NameSet sender_names = NAME_SET_INIT_FROM_OWNER(sender ? &sender->owned_names : NULL); |
| 395 |
|
| 396 |
connection_shutdown(&receiver->connection); |
| 397 |
|
| 398 |
log_append_here(bus->log, LOG_WARNING, 0, DBUS_BROKER_CATALOG_RECEIVE_FAILED); |
| 399 |
bus_log_append_transaction(bus, sender ? sender->id : ADDRESS_ID_INVALID, receiver->id, |
| 400 |
&sender_names, NULL, |
| 401 |
sender ? sender->policy->seclabel : bus->seclabel, receiver->policy->seclabel, |
| 402 |
message); |
| 403 |
if (r == CONNECTION_E_QUOTA) |
| 404 |
r = log_commitf(bus->log, "Monitor :1.%llu is being disconnected as it does not have the resources to receive a message it subscribed to.", receiver->id); |
| 405 |
else |
| 406 |
r = log_commitf(bus->log, "Monitor :1.%llu is being disconnected as it does not support receiving file descriptors it subscribed to.", receiver->id); |
| 407 |
if (r) |
| 408 |
return error_fold(r); |
| 409 |
} else { |
| 410 |
return error_fold(r); |
| 411 |
} |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
return 0; |
| 416 |
} |
| 417 |
|
| 418 |
static int driver_send_unicast(Peer *receiver, Message *message) { |
| 419 |
int r; |
| 420 |
|
| 421 |
r = driver_monitor(receiver->bus, NULL, message); |
| 422 |
if (r) |
| 423 |
return error_fold(r); |
| 424 |
|
| 425 |
r = connection_queue(&receiver->connection, NULL, message); |
| 426 |
if (r) { |
| 427 |
if (r == CONNECTION_E_QUOTA || r == CONNECTION_E_UNEXPECTED_FDS) { |
| 428 |
NameSet receiver_names = NAME_SET_INIT_FROM_OWNER(&receiver->owned_names); |
| 429 |
|
| 430 |
connection_shutdown(&receiver->connection); |
| 431 |
|
| 432 |
log_append_here(receiver->bus->log, LOG_WARNING, 0, DBUS_BROKER_CATALOG_RECEIVE_FAILED); |
| 433 |
bus_log_append_transaction(receiver->bus, ADDRESS_ID_INVALID, receiver->id, NULL, &receiver_names, |
| 434 |
receiver->bus->seclabel, receiver->policy->seclabel, |
| 435 |
message); |
| 436 |
if (r == CONNECTION_E_QUOTA) |
| 437 |
r = log_commitf(receiver->bus->log, "Peer :1.%llu is being disconnected as it does not have the resources to receive a reply or unicast signal it expects.", receiver->id); |
| 438 |
else |
| 439 |
r = log_commitf(receiver->bus->log, "Peer :1.%llu is being disconnected as it does not support receiving file descriptors it expects.", receiver->id); |
| 440 |
if (r) |
| 441 |
return error_fold(r); |
| 442 |
} else { |
| 443 |
return error_fold(r); |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
return 0; |
| 448 |
} |
| 449 |
|
| 450 |
static int driver_send_error(Peer *receiver, uint32_t serial, const char *error, const char *error_message) { |
| 451 |
static const CDVarType type[] = { |
| 452 |
C_DVAR_T_INIT( |
| 453 |
DRIVER_T_MESSAGE( |
| 454 |
C_DVAR_T_TUPLE1( |
| 455 |
C_DVAR_T_s |
| 456 |
) |
| 457 |
) |
| 458 |
) |
| 459 |
}; |
| 460 |
_c_cleanup_(c_dvar_deinit) CDVar var = C_DVAR_INIT; |
| 461 |
_c_cleanup_(message_unrefp) Message *message = NULL; |
| 462 |
_c_cleanup_(c_freep) void *data = NULL; |
| 463 |
size_t n_data; |
| 464 |
int r; |
| 465 |
|
| 466 |
/* If no reply was expected, never send an error. */ |
| 467 |
if (!serial) |
| 468 |
return 0; |
| 469 |
|
| 470 |
c_dvar_begin_write(&var, (__BYTE_ORDER == __BIG_ENDIAN), type, 1); |
| 471 |
c_dvar_write(&var, "((yyyyuu[(y<u>)(y<s>)(y<s>)(y<g>)(y<", |
| 472 |
c_dvar_is_big_endian(&var) ? 'B' : 'l', DBUS_MESSAGE_TYPE_ERROR, DBUS_HEADER_FLAG_NO_REPLY_EXPECTED, 1, 0, (uint32_t)-1, |
| 473 |
DBUS_MESSAGE_FIELD_REPLY_SERIAL, c_dvar_type_u, serial, |
| 474 |
DBUS_MESSAGE_FIELD_SENDER, c_dvar_type_s, "org.freedesktop.DBus", |
| 475 |
DBUS_MESSAGE_FIELD_ERROR_NAME, c_dvar_type_s, error, |
| 476 |
DBUS_MESSAGE_FIELD_SIGNATURE, c_dvar_type_g, "s", |
| 477 |
DBUS_MESSAGE_FIELD_DESTINATION, c_dvar_type_s); |
| 478 |
driver_dvar_write_unique_name(&var, receiver); |
| 479 |
c_dvar_write(&var, ">)])(s))", error_message); |
| 480 |
|
| 481 |
r = c_dvar_end_write(&var, &data, &n_data); |
| 482 |
if (r) |
| 483 |
return error_origin(r); |
| 484 |
|
| 485 |
r = message_new_outgoing(&message, data, n_data); |
| 486 |
if (r) |
| 487 |
return error_fold(r); |
| 488 |
data = NULL; |
| 489 |
|
| 490 |
r = driver_send_unicast(receiver, message); |
| 491 |
if (r) |
| 492 |
return error_trace(r); |
| 493 |
|
| 494 |
return 0; |
| 495 |
} |
| 496 |
|
| 497 |
static int driver_send_reply_with_fds(Peer *peer, CDVar *var, uint32_t serial, int *fds, size_t n_fds) { |
| 498 |
_c_cleanup_(message_unrefp) Message *message = NULL; |
| 499 |
_c_cleanup_(c_freep) void *data = NULL; |
| 500 |
size_t n_data; |
| 501 |
int r; |
| 502 |
|
| 503 |
c_assert(fds || n_fds == 0); |
| 504 |
|
| 505 |
/* |
| 506 |
* The message was correctly handled and the reply is serialized in |
| 507 |
* @var. Lets finish it up and queue the reply on the destination. |
| 508 |
* Note that any failure in doing so must be a fatal error, so there is |
| 509 |
* no point in reverting the operation on failure. |
| 510 |
*/ |
| 511 |
|
| 512 |
c_dvar_write(var, ")"); |
| 513 |
|
| 514 |
r = c_dvar_end_write(var, &data, &n_data); |
| 515 |
if (r) |
| 516 |
return error_origin(r); |
| 517 |
|
| 518 |
/* If no reply was expected, simply discard the message. */ |
| 519 |
if (!serial) |
| 520 |
return 0; |
| 521 |
|
| 522 |
r = message_new_outgoing(&message, data, n_data); |
| 523 |
if (r) |
| 524 |
return error_fold(r); |
| 525 |
data = NULL; |
| 526 |
|
| 527 |
if (n_fds > 0) { |
| 528 |
r = fdlist_new_dup_fds(&message->fds, fds, n_fds); |
| 529 |
if (r) |
| 530 |
return error_fold(r); |
| 531 |
} |
| 532 |
|
| 533 |
r = driver_send_unicast(peer, message); |
| 534 |
if (r) |
| 535 |
return error_trace(r); |
| 536 |
|
| 537 |
return 0; |
| 538 |
} |
| 539 |
|
| 540 |
static int driver_send_reply(Peer *peer, CDVar *var, uint32_t serial) { |
| 541 |
return driver_send_reply_with_fds(peer, var, serial, NULL, 0); |
| 542 |
} |
| 543 |
|
| 544 |
static int driver_notify_name_acquired(Peer *peer, const char *name) { |
| 545 |
static const CDVarType type[] = { |
| 546 |
C_DVAR_T_INIT( |
| 547 |
DRIVER_T_MESSAGE( |
| 548 |
C_DVAR_T_TUPLE1( |
| 549 |
C_DVAR_T_s |
| 550 |
) |
| 551 |
) |
| 552 |
) |
| 553 |
}; |
| 554 |
_c_cleanup_(c_dvar_deinit) CDVar var = C_DVAR_INIT; |
| 555 |
_c_cleanup_(message_unrefp) Message *message = NULL; |
| 556 |
_c_cleanup_(c_freep) void *data = NULL; |
| 557 |
size_t n_data; |
| 558 |
int r; |
| 559 |
|
| 560 |
c_dvar_begin_write(&var, (__BYTE_ORDER == __BIG_ENDIAN), type, 1); |
| 561 |
c_dvar_write(&var, "("); |
| 562 |
driver_write_signal_header(&var, peer, "NameAcquired", "s"); |
| 563 |
c_dvar_write(&var, "(s)", name); |
| 564 |
c_dvar_write(&var, ")"); |
| 565 |
r = c_dvar_end_write(&var, &data, &n_data); |
| 566 |
if (r) |
| 567 |
return error_origin(r); |
| 568 |
|
| 569 |
r = message_new_outgoing(&message, data, n_data); |
| 570 |
if (r) |
| 571 |
return error_fold(r); |
| 572 |
data = NULL; |
| 573 |
|
| 574 |
r = driver_send_unicast(peer, message); |
| 575 |
if (r) |
| 576 |
return error_trace(r); |
| 577 |
|
| 578 |
return 0; |
| 579 |
} |
| 580 |
|
| 581 |
static int driver_notify_name_lost(Peer *peer, const char *name) { |
| 582 |
static const CDVarType type[] = { |
| 583 |
C_DVAR_T_INIT( |
| 584 |
DRIVER_T_MESSAGE( |
| 585 |
C_DVAR_T_TUPLE1( |
| 586 |
C_DVAR_T_s |
| 587 |
) |
| 588 |
) |
| 589 |
) |
| 590 |
}; |
| 591 |
_c_cleanup_(c_dvar_deinit) CDVar var = C_DVAR_INIT; |
| 592 |
_c_cleanup_(message_unrefp) Message *message = NULL; |
| 593 |
_c_cleanup_(c_freep) void *data = NULL; |
| 594 |
size_t n_data; |
| 595 |
int r; |
| 596 |
|
| 597 |
c_dvar_begin_write(&var, (__BYTE_ORDER == __BIG_ENDIAN), type, 1); |
| 598 |
c_dvar_write(&var, "("); |
| 599 |
driver_write_signal_header(&var, peer, "NameLost", "s"); |
| 600 |
c_dvar_write(&var, "(s)", name); |
| 601 |
c_dvar_write(&var, ")"); |
| 602 |
r = c_dvar_end_write(&var, &data, &n_data); |
| 603 |
if (r) |
| 604 |
return error_origin(r); |
| 605 |
|
| 606 |
r = message_new_outgoing(&message, data, n_data); |
| 607 |
if (r) |
| 608 |
return error_fold(r); |
| 609 |
data = NULL; |
| 610 |
|
| 611 |
r = driver_send_unicast(peer, message); |
| 612 |
if (r) |
| 613 |
return error_trace(r); |
| 614 |
|
| 615 |
return 0; |
| 616 |
} |
| 617 |
|
| 618 |
static int driver_notify_name_owner_changed(Bus *bus, MatchRegistry *matches, const char *name, const char *old_owner, const char *new_owner) { |
| 619 |
_c_cleanup_(c_list_flush) CList destinations = C_LIST_INIT(destinations); |
| 620 |
MessageMetadata metadata = { |
| 621 |
.header = { |
| 622 |
.type = DBUS_MESSAGE_TYPE_SIGNAL, |
| 623 |
}, |
| 624 |
.sender_id = ADDRESS_ID_INVALID, |
| 625 |
.fields = { |
| 626 |
.path = "/org/freedesktop/DBus", |
| 627 |
.interface = "org.freedesktop.DBus", |
| 628 |
.member = "NameOwnerChanged", |
| 629 |
}, |
| 630 |
.args = { |
| 631 |
{ |
| 632 |
.value = name, |
| 633 |
.element = 's', |
| 634 |
}, |
| 635 |
{ |
| 636 |
.value = old_owner, |
| 637 |
.element = 's', |
| 638 |
}, |
| 639 |
{ |
| 640 |
.value = new_owner, |
| 641 |
.element = 's', |
| 642 |
}, |
| 643 |
}, |
| 644 |
.n_args = 3, |
| 645 |
}; |
| 646 |
int r; |
| 647 |
|
| 648 |
bus_get_monitor_destinations(bus, &destinations, NULL, &metadata); |
| 649 |
bus_get_broadcast_destinations(bus, &destinations, matches, NULL, &metadata); |
| 650 |
|
| 651 |
if (!c_list_is_empty(&destinations)) { |
| 652 |
static const CDVarType type[] = { |
| 653 |
C_DVAR_T_INIT( |
| 654 |
DRIVER_T_MESSAGE( |
| 655 |
C_DVAR_T_TUPLE3( |
| 656 |
C_DVAR_T_s, |
| 657 |
C_DVAR_T_s, |
| 658 |
C_DVAR_T_s |
| 659 |
) |
| 660 |
) |
| 661 |
) |
| 662 |
}; |
| 663 |
_c_cleanup_(c_dvar_deinit) CDVar var = C_DVAR_INIT; |
| 664 |
_c_cleanup_(message_unrefp) Message *message = NULL; |
| 665 |
_c_cleanup_(c_freep) void *data = NULL; |
| 666 |
MatchOwner *match_owner; |
| 667 |
size_t n_data; |
| 668 |
|
| 669 |
c_dvar_begin_write(&var, (__BYTE_ORDER == __BIG_ENDIAN), type, 1); |
| 670 |
c_dvar_write(&var, "("); |
| 671 |
driver_write_signal_header(&var, NULL, "NameOwnerChanged", "sss"); |
| 672 |
c_dvar_write(&var, "(sss)", name, old_owner, new_owner); |
| 673 |
c_dvar_write(&var, ")"); |
| 674 |
r = c_dvar_end_write(&var, &data, &n_data); |
| 675 |
if (r) |
| 676 |
return error_origin(r); |
| 677 |
|
| 678 |
r = message_new_outgoing(&message, data, n_data); |
| 679 |
if (r) |
| 680 |
return error_fold(r); |
| 681 |
data = NULL; |
| 682 |
|
| 683 |
while ((match_owner = c_list_first_entry(&destinations, MatchOwner, destinations_link))) { |
| 684 |
Peer *receiver = c_container_of(match_owner, Peer, owned_matches); |
| 685 |
|
| 686 |
c_list_unlink(&match_owner->destinations_link); |
| 687 |
|
| 688 |
r = policy_snapshot_check_receive(receiver->policy, |
| 689 |
NULL, |
| 690 |
NULL, |
| 691 |
0, |
| 692 |
metadata.fields.interface, |
| 693 |
metadata.fields.member, |
| 694 |
metadata.fields.path, |
| 695 |
metadata.header.type, |
| 696 |
true, |
| 697 |
0); |
| 698 |
if (r) { |
| 699 |
if (r == POLICY_E_ACCESS_DENIED || |
| 700 |
r == POLICY_E_SELINUX_ACCESS_DENIED || |
| 701 |
r == POLICY_E_APPARMOR_ACCESS_DENIED) |
| 702 |
continue; |
| 703 |
|
| 704 |
return error_fold(r); |
| 705 |
} |
| 706 |
|
| 707 |
r = connection_queue(&receiver->connection, NULL, message); |
| 708 |
if (r) { |
| 709 |
if (r == CONNECTION_E_QUOTA || r == CONNECTION_E_UNEXPECTED_FDS) { |
| 710 |
NameSet receiver_names = NAME_SET_INIT_FROM_OWNER(&receiver->owned_names); |
| 711 |
|
| 712 |
connection_shutdown(&receiver->connection); |
| 713 |
|
| 714 |
log_append_here(bus->log, LOG_WARNING, 0, DBUS_BROKER_CATALOG_RECEIVE_FAILED); |
| 715 |
bus_log_append_transaction(bus, ADDRESS_ID_INVALID, receiver->id, NULL, &receiver_names, |
| 716 |
receiver->bus->seclabel, receiver->policy->seclabel, |
| 717 |
message); |
| 718 |
if (r == CONNECTION_E_QUOTA) |
| 719 |
r = log_commitf(bus->log, "Peer :1.%llu is being disconnected as it does not have the resources to receive a signal it subscribed to.", receiver->id); |
| 720 |
else |
| 721 |
r = log_commitf(bus->log, "Peer :1.%llu is being disconnected as it does not support receiving the file descriptors it subscribed to.", receiver->id); |
| 722 |
if (r) |
| 723 |
return error_fold(r); |
| 724 |
} else { |
| 725 |
return error_fold(r); |
| 726 |
} |
| 727 |
} |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
return 0; |
| 732 |
} |
| 733 |
|
| 734 |
static int driver_name_owner_changed(Bus *bus, MatchRegistry *matches, const char *name, Peer *old_owner, Peer *new_owner) { |
| 735 |
const char *old_owner_str, *new_owner_str; |
| 736 |
int r; |
| 737 |
|
| 738 |
c_assert(old_owner || new_owner); |
| 739 |
c_assert(name || !old_owner || !new_owner); |
| 740 |
|
| 741 |
old_owner_str = old_owner ? address_to_string(&(Address)ADDRESS_INIT_ID(old_owner->id)) : ""; |
| 742 |
new_owner_str = new_owner ? address_to_string(&(Address)ADDRESS_INIT_ID(new_owner->id)) : ""; |
| 743 |
name = name ?: (old_owner ? old_owner_str : new_owner_str); |
| 744 |
|
| 745 |
if (old_owner) { |
| 746 |
r = driver_notify_name_lost(old_owner, name); |
| 747 |
if (r) |
| 748 |
return error_trace(r); |
| 749 |
} |
| 750 |
|
| 751 |
r = driver_notify_name_owner_changed(bus, matches, name, old_owner_str, new_owner_str); |
| 752 |
if (r) |
| 753 |
return error_trace(r); |
| 754 |
|
| 755 |
if (new_owner) { |
| 756 |
r = driver_notify_name_acquired(new_owner, name); |
| 757 |
if (r) |
| 758 |
return error_trace(r); |
| 759 |
} |
| 760 |
|
| 761 |
return 0; |
| 762 |
} |
| 763 |
|
| 764 |
int driver_name_activation_failed(Bus *bus, Activation *activation, uint64_t serial, unsigned int name_error) { |
| 765 |
ActivationRequest *request, *request_safe; |
| 766 |
ActivationMessage *message, *message_safe; |
| 767 |
_c_cleanup_(c_freep) char *error = NULL; |
| 768 |
int r; |
| 769 |
|
| 770 |
/* |
| 771 |
* If there is no pending activation, or if it is an event for an old |
| 772 |
* activation, we ignore it silently. |
| 773 |
*/ |
| 774 |
if (!activation->pending || serial != activation->pending) |
| 775 |
return 0; |
| 776 |
|
| 777 |
r = asprintf( |
| 778 |
&error, |
| 779 |
"Could not activate remote peer '%s': %s", |
| 780 |
activation->name->name, |
| 781 |
controller_name_error_to_human_readable(name_error) |
| 782 |
); |
| 783 |
if (r < 0) |
| 784 |
return error_origin(-errno); |
| 785 |
|
| 786 |
activation->pending = 0; |
| 787 |
|
| 788 |
c_list_for_each_entry_safe(request, request_safe, &activation->activation_requests, link) { |
| 789 |
Peer *sender; |
| 790 |
|
| 791 |
sender = peer_registry_find_peer(&bus->peers, request->sender_id); |
| 792 |
if (sender) { |
| 793 |
r = driver_send_error(sender, request->serial, "org.freedesktop.DBus.Error.ServiceUnknown", error); |
| 794 |
if (r) |
| 795 |
return error_trace(r); |
| 796 |
} |
| 797 |
|
| 798 |
activation_request_free(request); |
| 799 |
} |
| 800 |
|
| 801 |
c_list_for_each_entry_safe(message, message_safe, &activation->activation_messages, link) { |
| 802 |
Peer *sender; |
| 803 |
|
| 804 |
sender = peer_registry_find_peer(&bus->peers, message->message->metadata.sender_id); |
| 805 |
if (sender) { |
| 806 |
r = driver_send_error(sender, message_read_serial(message->message), "org.freedesktop.DBus.Error.NameHasNoOwner", error); |
| 807 |
if (r) |
| 808 |
return error_trace(r); |
| 809 |
} |
| 810 |
|
| 811 |
activation_message_free(message); |
| 812 |
} |
| 813 |
|
| 814 |
return 0; |
| 815 |
} |
| 816 |
|
| 817 |
static int driver_name_activated(Activation *activation, Peer *receiver) { |
| 818 |
ActivationRequest *request, *request_safe; |
| 819 |
ActivationMessage *message, *message_safe; |
| 820 |
int r; |
| 821 |
|
| 822 |
if (!activation) |
| 823 |
return 0; |
| 824 |
|
| 825 |
/* in case the name is dropped again in the future, we should request it again */ |
| 826 |
activation->pending = 0; |
| 827 |
|
| 828 |
c_list_for_each_entry_safe(request, request_safe, &activation->activation_requests, link) { |
| 829 |
Peer *sender; |
| 830 |
|
| 831 |
sender = peer_registry_find_peer(&receiver->bus->peers, request->sender_id); |
| 832 |
if (sender) { |
| 833 |
_c_cleanup_(c_dvar_deinit) CDVar var = C_DVAR_INIT; |
| 834 |
|
| 835 |
c_dvar_begin_write(&var, (__BYTE_ORDER == __BIG_ENDIAN), driver_type_out_u, 1); |
| 836 |
c_dvar_write(&var, "("); |
| 837 |
driver_write_reply_header(&var, sender, request->serial, driver_type_out_u, /* n_fds= */ 0); |
| 838 |
c_dvar_write(&var, "(u)", DBUS_START_REPLY_SUCCESS); |
| 839 |
|
| 840 |
r = driver_send_reply(sender, &var, request->serial); |
| 841 |
if (r) |
| 842 |
return error_trace(r); |
| 843 |
} |
| 844 |
|
| 845 |
activation_request_free(request); |
| 846 |
} |
| 847 |
|
| 848 |
c_list_for_each_entry_safe(message, message_safe, &activation->activation_messages, link) { |
| 849 |
NameSet sender_names = NAME_SET_INIT_FROM_SNAPSHOT(message->senders_names); |
| 850 |
Peer *sender; |
| 851 |
|
| 852 |
sender = peer_registry_find_peer(&receiver->bus->peers, message->message->metadata.sender_id); |
| 853 |
|
| 854 |
r = peer_queue_unicast(message->senders_policy, &sender_names, sender ? &sender->owned_replies : NULL, message->user, message->message->metadata.sender_id, receiver, message->message); |
| 855 |
if (r) { |
| 856 |
switch (r) { |
| 857 |
case PEER_E_QUOTA: |
| 858 |
if (sender) |
| 859 |
r = driver_send_error(sender, message_read_serial(message->message), |
| 860 |
"org.freedesktop.DBus.Error.LimitsExceeded", |
| 861 |
driver_error_to_string(DRIVER_E_QUOTA)); |
| 862 |
else |
| 863 |
r = 0; |
| 864 |
|
| 865 |
break; |
| 866 |
case PEER_E_EXPECTED_REPLY_EXISTS: |
| 867 |
if (sender) |
| 868 |
r = driver_send_error(sender, message_read_serial(message->message), |
| 869 |
"org.freedesktop.DBus.Error.AccessDenied", |
| 870 |
driver_error_to_string(DRIVER_E_EXPECTED_REPLY_EXISTS)); |
| 871 |
else |
| 872 |
r = 0; |
| 873 |
|
| 874 |
break; |
| 875 |
case PEER_E_RECEIVE_DENIED: |
| 876 |
if (sender) |
| 877 |
r = driver_send_error(sender, message_read_serial(message->message), |
| 878 |
"org.freedesktop.DBus.Error.AccessDenied", |
| 879 |
driver_error_to_string(DRIVER_E_RECEIVE_DENIED)); |
| 880 |
else |
| 881 |
r = 0; |
| 882 |
|
| 883 |
break; |
| 884 |
case PEER_E_SEND_DENIED: |
| 885 |
if (sender) |
| 886 |
r = driver_send_error(sender, message_read_serial(message->message), |
| 887 |
"org.freedesktop.DBus.Error.AccessDenied", |
| 888 |
driver_error_to_string(DRIVER_E_SEND_DENIED)); |
| 889 |
else |
| 890 |
r = 0; |
| 891 |
|
| 892 |
break; |
| 893 |
case PEER_E_UNEXPECTED_FDS: |
| 894 |
if (sender) |
| 895 |
r = driver_send_error(sender, message_read_serial(message->message), |
| 896 |
"org.freedesktop.DBus.Error.Failed", |
| 897 |
driver_error_to_string(DRIVER_E_UNEXPECTED_FDS)); |
| 898 |
else |
| 899 |
r = 0; |
| 900 |
|
| 901 |
break; |
| 902 |
} |
| 903 |
|
| 904 |
if (r) |
| 905 |
return error_fold(r); |
| 906 |
} |
| 907 |
|
| 908 |
activation_message_free(message); |
| 909 |
} |
| 910 |
|
| 911 |
return 0; |
| 912 |
} |
| 913 |
|
| 914 |
static int driver_end_read(CDVar *var) { |
| 915 |
int r; |
| 916 |
|
| 917 |
/* |
| 918 |
* Messages passed to the driver have already been verified, |
| 919 |
* so we simply fold away any errors here as they would be |
| 920 |
* caused by our own programming errors. |
| 921 |
*/ |
| 922 |
r = c_dvar_end_read(var); |
| 923 |
if (r) |
| 924 |
return error_fold(r); |
| 925 |
|
| 926 |
return 0; |
| 927 |
} |
| 928 |
|
| 929 |
static int driver_method_hello(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 930 |
const char *unique_name; |
| 931 |
int r; |
| 932 |
|
| 933 |
if (_c_unlikely_(peer_is_registered(peer))) |
| 934 |
return DRIVER_E_PEER_ALREADY_REGISTERED; |
| 935 |
|
| 936 |
c_dvar_read(in_v, "()"); |
| 937 |
|
| 938 |
r = driver_end_read(in_v); |
| 939 |
if (r) |
| 940 |
return error_trace(r); |
| 941 |
|
| 942 |
peer_register(peer); |
| 943 |
unique_name = address_to_string(&(Address)ADDRESS_INIT_ID(peer->id)); |
| 944 |
|
| 945 |
c_dvar_write(out_v, "(s)", unique_name); |
| 946 |
|
| 947 |
r = driver_send_reply(peer, out_v, serial); |
| 948 |
if (r) |
| 949 |
return error_trace(r); |
| 950 |
|
| 951 |
r = driver_name_owner_changed(peer->bus, &peer->name_owner_changed_matches, NULL, NULL, peer); |
| 952 |
if (r) |
| 953 |
return error_trace(r); |
| 954 |
|
| 955 |
return 0; |
| 956 |
} |
| 957 |
|
| 958 |
static int driver_method_request_name(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 959 |
NameChange change = NAME_CHANGE_INIT; |
| 960 |
const char *name; |
| 961 |
uint32_t flags, reply; |
| 962 |
int r; |
| 963 |
|
| 964 |
c_dvar_read(in_v, "(su)", &name, &flags); |
| 965 |
|
| 966 |
r = driver_end_read(in_v); |
| 967 |
if (r) |
| 968 |
return error_trace(r); |
| 969 |
|
| 970 |
if (!dbus_validate_name(name, strlen(name))) |
| 971 |
return DRIVER_E_NAME_INVALID; |
| 972 |
|
| 973 |
r = peer_request_name(peer, name, flags, &change); |
| 974 |
if (!r) |
| 975 |
reply = DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER; |
| 976 |
else if (r == PEER_E_NAME_ALREADY_OWNER) |
| 977 |
reply = DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER; |
| 978 |
else if (r == PEER_E_NAME_IN_QUEUE) |
| 979 |
reply = DBUS_REQUEST_NAME_REPLY_IN_QUEUE; |
| 980 |
else if (r == PEER_E_NAME_EXISTS) |
| 981 |
reply = DBUS_REQUEST_NAME_REPLY_EXISTS; |
| 982 |
else if (r == PEER_E_QUOTA) |
| 983 |
return DRIVER_E_QUOTA; |
| 984 |
else if (r == PEER_E_NAME_RESERVED) |
| 985 |
return DRIVER_E_NAME_RESERVED; |
| 986 |
else if (r == PEER_E_NAME_UNIQUE) |
| 987 |
return DRIVER_E_NAME_UNIQUE; |
| 988 |
else if (r == PEER_E_NAME_REFUSED) |
| 989 |
return DRIVER_E_NAME_REFUSED; |
| 990 |
else |
| 991 |
return error_fold(r); |
| 992 |
|
| 993 |
c_dvar_write(out_v, "(u)", reply); |
| 994 |
|
| 995 |
if (change.name) { |
| 996 |
r = driver_name_owner_changed(peer->bus, |
| 997 |
&change.name->name_owner_changed_matches, |
| 998 |
change.name->name, |
| 999 |
c_container_of(change.old_owner, Peer, owned_names), |
| 1000 |
c_container_of(change.new_owner, Peer, owned_names)); |
| 1001 |
if (r) |
| 1002 |
return error_trace(r); |
| 1003 |
|
| 1004 |
r = driver_name_activated(change.name->activation, |
| 1005 |
c_container_of(change.new_owner, Peer, owned_names)); |
| 1006 |
if (r) |
| 1007 |
return error_trace(r); |
| 1008 |
} |
| 1009 |
|
| 1010 |
name_change_deinit(&change); |
| 1011 |
|
| 1012 |
r = driver_send_reply(peer, out_v, serial); |
| 1013 |
if (r) |
| 1014 |
return error_trace(r); |
| 1015 |
|
| 1016 |
return 0; |
| 1017 |
} |
| 1018 |
|
| 1019 |
static int driver_method_release_name(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1020 |
NameChange change = NAME_CHANGE_INIT; |
| 1021 |
const char *name; |
| 1022 |
uint32_t reply; |
| 1023 |
int r; |
| 1024 |
|
| 1025 |
c_dvar_read(in_v, "(s)", &name); |
| 1026 |
|
| 1027 |
r = driver_end_read(in_v); |
| 1028 |
if (r) |
| 1029 |
return error_trace(r); |
| 1030 |
|
| 1031 |
if (!dbus_validate_name(name, strlen(name))) |
| 1032 |
return DRIVER_E_NAME_INVALID; |
| 1033 |
|
| 1034 |
r = peer_release_name(peer, name, &change); |
| 1035 |
if (!r) |
| 1036 |
reply = DBUS_RELEASE_NAME_REPLY_RELEASED; |
| 1037 |
else if (r == PEER_E_NAME_NOT_FOUND) |
| 1038 |
reply = DBUS_RELEASE_NAME_REPLY_NON_EXISTENT; |
| 1039 |
else if (r == PEER_E_NAME_NOT_OWNER) |
| 1040 |
reply = DBUS_RELEASE_NAME_REPLY_NOT_OWNER; |
| 1041 |
else if (r == PEER_E_NAME_RESERVED) |
| 1042 |
return DRIVER_E_NAME_RESERVED; |
| 1043 |
else if (r == PEER_E_NAME_UNIQUE) |
| 1044 |
return DRIVER_E_NAME_UNIQUE; |
| 1045 |
else |
| 1046 |
return error_fold(r); |
| 1047 |
|
| 1048 |
c_dvar_write(out_v, "(u)", reply); |
| 1049 |
|
| 1050 |
if (change.name) { |
| 1051 |
r = driver_name_owner_changed(peer->bus, |
| 1052 |
&change.name->name_owner_changed_matches, |
| 1053 |
change.name->name, |
| 1054 |
c_container_of(change.old_owner, Peer, owned_names), |
| 1055 |
c_container_of(change.new_owner, Peer, owned_names)); |
| 1056 |
if (r) |
| 1057 |
return error_trace(r); |
| 1058 |
} |
| 1059 |
|
| 1060 |
name_change_deinit(&change); |
| 1061 |
|
| 1062 |
r = driver_send_reply(peer, out_v, serial); |
| 1063 |
if (r) |
| 1064 |
return error_trace(r); |
| 1065 |
|
| 1066 |
return 0; |
| 1067 |
} |
| 1068 |
|
| 1069 |
static int driver_method_list_queued_owners(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1070 |
NameOwnership *ownership; |
| 1071 |
const char *name_str; |
| 1072 |
Peer *owner; |
| 1073 |
Name *name; |
| 1074 |
int r; |
| 1075 |
|
| 1076 |
c_dvar_read(in_v, "(s)", &name_str); |
| 1077 |
|
| 1078 |
r = driver_end_read(in_v); |
| 1079 |
if (r) |
| 1080 |
return error_trace(r); |
| 1081 |
|
| 1082 |
c_dvar_write(out_v, "(["); |
| 1083 |
if (!strcmp(name_str, "org.freedesktop.DBus")) { |
| 1084 |
c_dvar_write(out_v, "s", "org.freedesktop.DBus"); |
| 1085 |
} else { |
| 1086 |
owner = bus_find_peer_by_name(peer->bus, &name, name_str); |
| 1087 |
if (!owner) |
| 1088 |
return DRIVER_E_NAME_NOT_FOUND; |
| 1089 |
|
| 1090 |
if (name) { |
| 1091 |
c_list_for_each_entry(ownership, &name->ownership_list, name_link) |
| 1092 |
driver_dvar_write_unique_name(out_v, c_container_of(ownership->owner, Peer, owned_names)); |
| 1093 |
} else { |
| 1094 |
driver_dvar_write_unique_name(out_v, owner); |
| 1095 |
} |
| 1096 |
} |
| 1097 |
c_dvar_write(out_v, "])"); |
| 1098 |
|
| 1099 |
r = driver_send_reply(peer, out_v, serial); |
| 1100 |
if (r) |
| 1101 |
return error_trace(r); |
| 1102 |
|
| 1103 |
return 0; |
| 1104 |
} |
| 1105 |
|
| 1106 |
static int driver_method_list_names(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1107 |
Peer *p; |
| 1108 |
Name *name; |
| 1109 |
int r; |
| 1110 |
|
| 1111 |
c_dvar_read(in_v, "()"); |
| 1112 |
|
| 1113 |
r = driver_end_read(in_v); |
| 1114 |
if (r) |
| 1115 |
return error_trace(r); |
| 1116 |
|
| 1117 |
c_dvar_write(out_v, "(["); |
| 1118 |
c_dvar_write(out_v, "s", "org.freedesktop.DBus"); |
| 1119 |
c_rbtree_for_each_entry(p, &peer->bus->peers.peer_tree, registry_node) { |
| 1120 |
if (!peer_is_registered(p)) |
| 1121 |
continue; |
| 1122 |
|
| 1123 |
driver_dvar_write_unique_name(out_v, p); |
| 1124 |
} |
| 1125 |
c_rbtree_for_each_entry(name, &peer->bus->names.name_tree, registry_node) { |
| 1126 |
if (!name_primary(name)) |
| 1127 |
continue; |
| 1128 |
|
| 1129 |
c_dvar_write(out_v, "s", name->name); |
| 1130 |
} |
| 1131 |
c_dvar_write(out_v, "])"); |
| 1132 |
|
| 1133 |
r = driver_send_reply(peer, out_v, serial); |
| 1134 |
if (r) |
| 1135 |
return error_trace(r); |
| 1136 |
|
| 1137 |
return 0; |
| 1138 |
} |
| 1139 |
|
| 1140 |
static int driver_method_list_activatable_names(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1141 |
Name *name; |
| 1142 |
int r; |
| 1143 |
|
| 1144 |
c_dvar_read(in_v, "()"); |
| 1145 |
|
| 1146 |
r = driver_end_read(in_v); |
| 1147 |
if (r) |
| 1148 |
return error_trace(r); |
| 1149 |
|
| 1150 |
c_dvar_write(out_v, "(["); |
| 1151 |
c_dvar_write(out_v, "s", "org.freedesktop.DBus"); |
| 1152 |
c_rbtree_for_each_entry(name, &peer->bus->names.name_tree, registry_node) { |
| 1153 |
if (!name->activation) |
| 1154 |
continue; |
| 1155 |
|
| 1156 |
c_dvar_write(out_v, "s", name->name); |
| 1157 |
} |
| 1158 |
c_dvar_write(out_v, "])"); |
| 1159 |
|
| 1160 |
r = driver_send_reply(peer, out_v, serial); |
| 1161 |
if (r) |
| 1162 |
return error_trace(r); |
| 1163 |
|
| 1164 |
return 0; |
| 1165 |
} |
| 1166 |
|
| 1167 |
static int driver_method_name_has_owner(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1168 |
Peer *connection; |
| 1169 |
const char *name; |
| 1170 |
int r; |
| 1171 |
|
| 1172 |
c_dvar_read(in_v, "(s)", &name); |
| 1173 |
|
| 1174 |
r = driver_end_read(in_v); |
| 1175 |
if (r) |
| 1176 |
return error_trace(r); |
| 1177 |
|
| 1178 |
if (strcmp(name, "org.freedesktop.DBus") == 0) { |
| 1179 |
c_dvar_write(out_v, "(b)", true); |
| 1180 |
} else { |
| 1181 |
connection = bus_find_peer_by_name(peer->bus, NULL, name); |
| 1182 |
|
| 1183 |
c_dvar_write(out_v, "(b)", !!connection); |
| 1184 |
} |
| 1185 |
|
| 1186 |
r = driver_send_reply(peer, out_v, serial); |
| 1187 |
if (r) |
| 1188 |
return error_trace(r); |
| 1189 |
|
| 1190 |
return 0; |
| 1191 |
} |
| 1192 |
|
| 1193 |
static int driver_method_start_service_by_name(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1194 |
const char *service; |
| 1195 |
Name *name; |
| 1196 |
NameOwnership *ownership; |
| 1197 |
uint32_t flags; |
| 1198 |
int r; |
| 1199 |
|
| 1200 |
/* flags are silently ignored */ |
| 1201 |
c_dvar_read(in_v, "(su)", &service, &flags); |
| 1202 |
|
| 1203 |
r = driver_end_read(in_v); |
| 1204 |
if (r) |
| 1205 |
return error_trace(r); |
| 1206 |
|
| 1207 |
name = name_registry_find_name(&peer->bus->names, service); |
| 1208 |
if (!name || !name->activation) |
| 1209 |
return DRIVER_E_NAME_NOT_ACTIVATABLE; |
| 1210 |
|
| 1211 |
ownership = name_primary(name); |
| 1212 |
if (ownership) { |
| 1213 |
c_dvar_write(out_v, "(u)", DBUS_START_REPLY_ALREADY_RUNNING); |
| 1214 |
|
| 1215 |
r = driver_send_reply(peer, out_v, serial); |
| 1216 |
if (r) |
| 1217 |
return error_trace(r); |
| 1218 |
} else { |
| 1219 |
r = activation_queue_request(name->activation, peer->user, peer->id, serial); |
| 1220 |
if (r) { |
| 1221 |
if (r == ACTIVATION_E_QUOTA) |
| 1222 |
return DRIVER_E_QUOTA; |
| 1223 |
|
| 1224 |
return error_fold(r); |
| 1225 |
} |
| 1226 |
} |
| 1227 |
|
| 1228 |
return 0; |
| 1229 |
} |
| 1230 |
|
| 1231 |
static int driver_method_update_activation_environment(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1232 |
_c_cleanup_(c_freep) const char **env = NULL; |
| 1233 |
const char *key, *value; |
| 1234 |
size_t n_env = 0, z_env = 0; |
| 1235 |
const char **t; |
| 1236 |
int r; |
| 1237 |
|
| 1238 |
if (!peer_is_privileged(peer)) |
| 1239 |
return DRIVER_E_PEER_NOT_PRIVILEGED; |
| 1240 |
|
| 1241 |
c_dvar_read(in_v, "(["); |
| 1242 |
while (c_dvar_more(in_v)) { |
| 1243 |
c_dvar_read(in_v, "{ss}", &key, &value); |
| 1244 |
|
| 1245 |
if (n_env + 1 >= z_env) { |
| 1246 |
z_env = (z_env * 2) ?: 128; |
| 1247 |
t = realloc(env, z_env * sizeof(*env)); |
| 1248 |
if (!t) |
| 1249 |
return error_origin(-ENOMEM); |
| 1250 |
|
| 1251 |
env = t; |
| 1252 |
} |
| 1253 |
|
| 1254 |
env[n_env++] = key; |
| 1255 |
env[n_env++] = value; |
| 1256 |
} |
| 1257 |
c_dvar_read(in_v, "])"); |
| 1258 |
|
| 1259 |
r = driver_end_read(in_v); |
| 1260 |
if (r) |
| 1261 |
return error_trace(r); |
| 1262 |
|
| 1263 |
r = broker_update_environment(BROKER(peer->bus), env, n_env / 2); |
| 1264 |
if (r) |
| 1265 |
return error_fold(r); |
| 1266 |
|
| 1267 |
c_dvar_write(out_v, "()"); |
| 1268 |
|
| 1269 |
r = driver_send_reply(peer, out_v, serial); |
| 1270 |
if (r) |
| 1271 |
return error_trace(r); |
| 1272 |
|
| 1273 |
return 0; |
| 1274 |
} |
| 1275 |
|
| 1276 |
static int driver_method_get_name_owner(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1277 |
const char *name_str, *owner_str; |
| 1278 |
Address addr; |
| 1279 |
int r; |
| 1280 |
|
| 1281 |
c_dvar_read(in_v, "(s)", &name_str); |
| 1282 |
|
| 1283 |
r = driver_end_read(in_v); |
| 1284 |
if (r) |
| 1285 |
return error_trace(r); |
| 1286 |
|
| 1287 |
if (!strcmp(name_str, "org.freedesktop.DBus")) { |
| 1288 |
addr = (Address)ADDRESS_INIT_NAME("org.freedesktop.DBus"); |
| 1289 |
} else { |
| 1290 |
Peer *owner; |
| 1291 |
|
| 1292 |
owner = bus_find_peer_by_name(peer->bus, NULL, name_str); |
| 1293 |
if (!owner) |
| 1294 |
return DRIVER_E_NAME_OWNER_NOT_FOUND; |
| 1295 |
|
| 1296 |
addr = (Address)ADDRESS_INIT_ID(owner->id); |
| 1297 |
} |
| 1298 |
|
| 1299 |
owner_str = address_to_string(&addr); |
| 1300 |
|
| 1301 |
c_dvar_write(out_v, "(s)", owner_str); |
| 1302 |
|
| 1303 |
r = driver_send_reply(peer, out_v, serial); |
| 1304 |
if (r) |
| 1305 |
return error_trace(r); |
| 1306 |
|
| 1307 |
return 0; |
| 1308 |
} |
| 1309 |
|
| 1310 |
static int driver_method_get_connection_unix_user(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1311 |
Peer *connection; |
| 1312 |
const char *name; |
| 1313 |
int r; |
| 1314 |
|
| 1315 |
c_dvar_read(in_v, "(s)", &name); |
| 1316 |
|
| 1317 |
r = driver_end_read(in_v); |
| 1318 |
if (r) |
| 1319 |
return error_trace(r); |
| 1320 |
|
| 1321 |
if (!strcmp(name, "org.freedesktop.DBus")) { |
| 1322 |
c_dvar_write(out_v, "(u)", peer->bus->user->uid); |
| 1323 |
} else { |
| 1324 |
connection = bus_find_peer_by_name(peer->bus, NULL, name); |
| 1325 |
if (!connection) |
| 1326 |
return DRIVER_E_PEER_NOT_FOUND; |
| 1327 |
|
| 1328 |
c_dvar_write(out_v, "(u)", connection->user->uid); |
| 1329 |
} |
| 1330 |
|
| 1331 |
r = driver_send_reply(peer, out_v, serial); |
| 1332 |
if (r) |
| 1333 |
return error_trace(r); |
| 1334 |
|
| 1335 |
return 0; |
| 1336 |
} |
| 1337 |
|
| 1338 |
static int driver_method_get_connection_unix_process_id(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1339 |
Peer *connection; |
| 1340 |
const char *name; |
| 1341 |
int r; |
| 1342 |
|
| 1343 |
c_dvar_read(in_v, "(s)", &name); |
| 1344 |
|
| 1345 |
r = driver_end_read(in_v); |
| 1346 |
if (r) |
| 1347 |
return error_trace(r); |
| 1348 |
|
| 1349 |
if (!strcmp(name, "org.freedesktop.DBus")) { |
| 1350 |
c_dvar_write(out_v, "(u)", peer->bus->pid); |
| 1351 |
} else { |
| 1352 |
connection = bus_find_peer_by_name(peer->bus, NULL, name); |
| 1353 |
if (!connection) |
| 1354 |
return DRIVER_E_PEER_NOT_FOUND; |
| 1355 |
|
| 1356 |
c_dvar_write(out_v, "(u)", connection->pid); |
| 1357 |
} |
| 1358 |
|
| 1359 |
r = driver_send_reply(peer, out_v, serial); |
| 1360 |
if (r) |
| 1361 |
return error_trace(r); |
| 1362 |
|
| 1363 |
return 0; |
| 1364 |
} |
| 1365 |
|
| 1366 |
static void driver_fetch_credentials(Bus *bus, Peer *peer, DriverCredentials *credp) { |
| 1367 |
if (peer) { |
| 1368 |
credp->pid = peer->pid; |
| 1369 |
credp->pid_fd = peer->pid_fd; |
| 1370 |
credp->uid = peer->user->uid; |
| 1371 |
credp->gids = peer->gids; |
| 1372 |
credp->n_gids = peer->n_gids; |
| 1373 |
credp->seclabel = peer->seclabel; |
| 1374 |
credp->n_seclabel = peer->n_seclabel; |
| 1375 |
} else { |
| 1376 |
credp->pid = bus->pid; |
| 1377 |
credp->pid_fd = bus->pid_fd; |
| 1378 |
credp->uid = bus->user->uid; |
| 1379 |
credp->gids = bus->gids; |
| 1380 |
credp->n_gids = bus->n_gids; |
| 1381 |
credp->seclabel = bus->seclabel; |
| 1382 |
credp->n_seclabel = bus->n_seclabel; |
| 1383 |
} |
| 1384 |
} |
| 1385 |
|
| 1386 |
static void driver_append_credentials(CDVar *v, const DriverCredentials *cred, size_t *fd_iter) { |
| 1387 |
c_dvar_write(v, "["); |
| 1388 |
|
| 1389 |
if (cred->uid != (uid_t)-1) |
| 1390 |
c_dvar_write(v, "{s<u>}", "UnixUserID", c_dvar_type_u, cred->uid); |
| 1391 |
if (cred->pid != 0) |
| 1392 |
c_dvar_write(v, "{s<u>}", "ProcessID", c_dvar_type_u, cred->pid); |
| 1393 |
|
| 1394 |
/* |
| 1395 |
* Append all groups of the peer as 'UnixGroupIDs'. This list includes |
| 1396 |
* the primary group of the peer. Furthermore, it is sorted and |
| 1397 |
* deduplicated, so its behavior is deterministic. |
| 1398 |
* |
| 1399 |
* Note that this also implies that the list cannot be empty, since the |
| 1400 |
* primary group must exist. So if the list is present, it has at least |
| 1401 |
* one element. |
| 1402 |
*/ |
| 1403 |
if (cred->n_gids > 0) { |
| 1404 |
static const CDVarType type_au[] = { |
| 1405 |
C_DVAR_T_INIT( |
| 1406 |
C_DVAR_T_ARRAY( |
| 1407 |
C_DVAR_T_u |
| 1408 |
) |
| 1409 |
) |
| 1410 |
}; |
| 1411 |
|
| 1412 |
c_dvar_write(v, "{s<[", "UnixGroupIDs", type_au); |
| 1413 |
for (size_t i = 0; i < cred->n_gids; ++i) |
| 1414 |
c_dvar_write(v, "u", cred->gids[i]); |
| 1415 |
c_dvar_write(v, "]>}"); |
| 1416 |
} |
| 1417 |
|
| 1418 |
if (cred->n_seclabel) { |
| 1419 |
/* |
| 1420 |
* The DBus specification says that the security-label is a |
| 1421 |
* byte array of non-0 values. The kernel disagrees. |
| 1422 |
* Unfortunately, the spec does not provide any transformation |
| 1423 |
* rules. Hence, we simply ignore that part of the spec and |
| 1424 |
* insert the label unmodified, followed by a zero byte, which |
| 1425 |
* is mandated by the spec. |
| 1426 |
* Our seclabel-fields always have a trailing zero-byte, |
| 1427 |
* so we can safely copy from it. |
| 1428 |
*/ |
| 1429 |
c_dvar_write(v, "{s<", "LinuxSecurityLabel", (const CDVarType[]){ C_DVAR_T_INIT(C_DVAR_T_ARRAY(C_DVAR_T_y)) }); |
| 1430 |
driver_write_bytes(v, cred->seclabel, cred->n_seclabel + 1); |
| 1431 |
c_dvar_write(v, ">}"); |
| 1432 |
} |
| 1433 |
|
| 1434 |
if (fd_iter && cred->pid_fd >= 0) { |
| 1435 |
/* If @fd_iter is set, it must refer to the pidfd. */ |
| 1436 |
c_dvar_write(v, "{s<h>}", "ProcessFD", c_dvar_type_h, *fd_iter); |
| 1437 |
++*fd_iter; |
| 1438 |
} |
| 1439 |
|
| 1440 |
c_dvar_write(v, "]"); |
| 1441 |
} |
| 1442 |
|
| 1443 |
static int driver_method_get_connection_credentials(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1444 |
DriverCredentials cred = DRIVER_CREDENTIALS_NULL; |
| 1445 |
Peer *connection = NULL; |
| 1446 |
const char *name; |
| 1447 |
size_t n_fds = 0, n_fds_expected; |
| 1448 |
int r; |
| 1449 |
|
| 1450 |
c_dvar_read(in_v, "(s)", &name); |
| 1451 |
|
| 1452 |
r = driver_end_read(in_v); |
| 1453 |
if (r) |
| 1454 |
return error_trace(r); |
| 1455 |
|
| 1456 |
if (strcmp(name, "org.freedesktop.DBus") != 0) { |
| 1457 |
connection = bus_find_peer_by_name(peer->bus, NULL, name); |
| 1458 |
if (!connection) |
| 1459 |
return DRIVER_E_PEER_NOT_FOUND; |
| 1460 |
} |
| 1461 |
|
| 1462 |
driver_fetch_credentials(peer->bus, connection, &cred); |
| 1463 |
n_fds_expected = (cred.pid_fd >= 0) ? 1 : 0; |
| 1464 |
driver_write_reply_header(out_v, peer, serial, driver_type_out_apsv, n_fds_expected); |
| 1465 |
|
| 1466 |
c_dvar_write(out_v, "("); |
| 1467 |
driver_append_credentials(out_v, &cred, &n_fds); |
| 1468 |
c_dvar_write(out_v, ")"); |
| 1469 |
|
| 1470 |
c_assert(n_fds == n_fds_expected); |
| 1471 |
|
| 1472 |
if (n_fds == 1) |
| 1473 |
r = driver_send_reply_with_fds(peer, out_v, serial, &cred.pid_fd, n_fds); |
| 1474 |
else |
| 1475 |
r = driver_send_reply(peer, out_v, serial); |
| 1476 |
if (r) |
| 1477 |
return error_trace(r); |
| 1478 |
|
| 1479 |
return 0; |
| 1480 |
} |
| 1481 |
|
| 1482 |
static int driver_method_get_adt_audit_session_data(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1483 |
Peer *connection; |
| 1484 |
const char *name; |
| 1485 |
int r; |
| 1486 |
|
| 1487 |
c_dvar_read(in_v, "(s)", &name); |
| 1488 |
|
| 1489 |
r = driver_end_read(in_v); |
| 1490 |
if (r) |
| 1491 |
return error_trace(r); |
| 1492 |
|
| 1493 |
if (strcmp(name, "org.freedesktop.DBus")) { |
| 1494 |
connection = bus_find_peer_by_name(peer->bus, NULL, name); |
| 1495 |
if (!connection) |
| 1496 |
return DRIVER_E_PEER_NOT_FOUND; |
| 1497 |
} |
| 1498 |
|
| 1499 |
/* |
| 1500 |
* ADT Audit Session Data is not supported on Linux |
| 1501 |
*/ |
| 1502 |
return DRIVER_E_ADT_NOT_SUPPORTED; |
| 1503 |
} |
| 1504 |
|
| 1505 |
static int driver_method_get_connection_selinux_security_context(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1506 |
const char *name, *seclabel; |
| 1507 |
size_t n_seclabel; |
| 1508 |
int r; |
| 1509 |
|
| 1510 |
c_dvar_read(in_v, "(s)", &name); |
| 1511 |
|
| 1512 |
r = driver_end_read(in_v); |
| 1513 |
if (r) |
| 1514 |
return error_trace(r); |
| 1515 |
|
| 1516 |
if (!strcmp(name, "org.freedesktop.DBus")) { |
| 1517 |
seclabel = peer->bus->seclabel; |
| 1518 |
n_seclabel = peer->bus->n_seclabel; |
| 1519 |
} else { |
| 1520 |
Peer *connection; |
| 1521 |
|
| 1522 |
connection = bus_find_peer_by_name(peer->bus, NULL, name); |
| 1523 |
if (!connection) |
| 1524 |
return DRIVER_E_PEER_NOT_FOUND; |
| 1525 |
|
| 1526 |
seclabel = connection->seclabel; |
| 1527 |
n_seclabel = connection->n_seclabel; |
| 1528 |
} |
| 1529 |
|
| 1530 |
/* |
| 1531 |
* Unlike "LinuxSecurityLabel" in GetConnectionCredentials(), this |
| 1532 |
* call is specific to SELinux. Hence, we better only return the |
| 1533 |
* label if we are running on SELinux. |
| 1534 |
*/ |
| 1535 |
if (!bus_selinux_is_enabled()) |
| 1536 |
return DRIVER_E_SELINUX_NOT_SUPPORTED; |
| 1537 |
|
| 1538 |
/* |
| 1539 |
* Unlike the "LinuxSecurityLabel", this call does not include a |
| 1540 |
* trailing 0-byte in the data blob. |
| 1541 |
*/ |
| 1542 |
c_dvar_write(out_v, "("); |
| 1543 |
driver_write_bytes(out_v, seclabel, n_seclabel); |
| 1544 |
c_dvar_write(out_v, ")"); |
| 1545 |
|
| 1546 |
r = driver_send_reply(peer, out_v, serial); |
| 1547 |
if (r) |
| 1548 |
return error_trace(r); |
| 1549 |
|
| 1550 |
return 0; |
| 1551 |
} |
| 1552 |
|
| 1553 |
static int driver_method_add_match(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1554 |
const char *rule_string; |
| 1555 |
int r; |
| 1556 |
|
| 1557 |
c_dvar_read(in_v, "(s)", &rule_string); |
| 1558 |
|
| 1559 |
r = driver_end_read(in_v); |
| 1560 |
if (r) |
| 1561 |
return error_trace(r); |
| 1562 |
|
| 1563 |
r = peer_add_match(peer, rule_string); |
| 1564 |
if (r) { |
| 1565 |
if (r == PEER_E_QUOTA) |
| 1566 |
return DRIVER_E_QUOTA; |
| 1567 |
else if (r == PEER_E_MATCH_INVALID) |
| 1568 |
return DRIVER_E_MATCH_INVALID; |
| 1569 |
else |
| 1570 |
return error_trace(r); |
| 1571 |
} |
| 1572 |
|
| 1573 |
c_dvar_write(out_v, "()"); |
| 1574 |
|
| 1575 |
r = driver_send_reply(peer, out_v, serial); |
| 1576 |
if (r) |
| 1577 |
return error_trace(r); |
| 1578 |
|
| 1579 |
return 0; |
| 1580 |
} |
| 1581 |
|
| 1582 |
static int driver_method_remove_match(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1583 |
const char *rule_string; |
| 1584 |
int r; |
| 1585 |
|
| 1586 |
c_dvar_read(in_v, "(s)", &rule_string); |
| 1587 |
|
| 1588 |
r = driver_end_read(in_v); |
| 1589 |
if (r) |
| 1590 |
return error_trace(r); |
| 1591 |
|
| 1592 |
r = peer_remove_match(peer, rule_string); |
| 1593 |
if (r) { |
| 1594 |
if (r == PEER_E_MATCH_NOT_FOUND) |
| 1595 |
return DRIVER_E_MATCH_NOT_FOUND; |
| 1596 |
else if (r == PEER_E_MATCH_INVALID) |
| 1597 |
return DRIVER_E_MATCH_INVALID; |
| 1598 |
else |
| 1599 |
return error_fold(r); |
| 1600 |
} |
| 1601 |
|
| 1602 |
c_dvar_write(out_v, "()"); |
| 1603 |
|
| 1604 |
r = driver_send_reply(peer, out_v, serial); |
| 1605 |
if (r) |
| 1606 |
return error_trace(r); |
| 1607 |
|
| 1608 |
return 0; |
| 1609 |
} |
| 1610 |
|
| 1611 |
int driver_reload_config_completed(Bus *bus, uint64_t sender_id, uint32_t reply_serial) { |
| 1612 |
Peer *sender; |
| 1613 |
int r; |
| 1614 |
|
| 1615 |
sender = peer_registry_find_peer(&bus->peers, sender_id); |
| 1616 |
if (sender) { |
| 1617 |
_c_cleanup_(c_dvar_deinit) CDVar var = C_DVAR_INIT; |
| 1618 |
|
| 1619 |
c_dvar_begin_write(&var, (__BYTE_ORDER == __BIG_ENDIAN), driver_type_out_unit, 1); |
| 1620 |
c_dvar_write(&var, "("); |
| 1621 |
driver_write_reply_header(&var, sender, reply_serial, driver_type_out_unit, /* n_fds=*/ 0); |
| 1622 |
c_dvar_write(&var, "()"); |
| 1623 |
|
| 1624 |
r = driver_send_reply(sender, &var, reply_serial); |
| 1625 |
if (r) |
| 1626 |
return error_trace(r); |
| 1627 |
} |
| 1628 |
|
| 1629 |
return 0; |
| 1630 |
} |
| 1631 |
|
| 1632 |
int driver_reload_config_invalid(Bus *bus, uint64_t sender_id, uint32_t reply_serial) { |
| 1633 |
Peer *sender; |
| 1634 |
int r; |
| 1635 |
|
| 1636 |
sender = peer_registry_find_peer(&bus->peers, sender_id); |
| 1637 |
if (sender) { |
| 1638 |
r = driver_send_error(sender, reply_serial, "org.freedesktop.DBus.Error.Failed", "Config invalid. Reload ignored."); |
| 1639 |
if (r) |
| 1640 |
return error_trace(r); |
| 1641 |
} |
| 1642 |
|
| 1643 |
return 0; |
| 1644 |
} |
| 1645 |
|
| 1646 |
static int driver_method_reload_config(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1647 |
int r; |
| 1648 |
|
| 1649 |
/* verify the input argument */ |
| 1650 |
c_dvar_read(in_v, "()"); |
| 1651 |
|
| 1652 |
r = driver_end_read(in_v); |
| 1653 |
if (r) |
| 1654 |
return error_trace(r); |
| 1655 |
|
| 1656 |
r = broker_reload_config(BROKER(peer->bus), peer->user, peer->id, serial); |
| 1657 |
if (r) { |
| 1658 |
if (r == BROKER_E_FORWARD_FAILED) |
| 1659 |
return DRIVER_E_FORWARD_FAILED; |
| 1660 |
|
| 1661 |
return error_fold(r); |
| 1662 |
} |
| 1663 |
|
| 1664 |
return 0; |
| 1665 |
} |
| 1666 |
|
| 1667 |
static int driver_method_get_id(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1668 |
char buffer[sizeof(peer->bus->guid) * 2 + 1] = {}; |
| 1669 |
int r; |
| 1670 |
|
| 1671 |
/* verify the input argument */ |
| 1672 |
c_dvar_read(in_v, "()"); |
| 1673 |
|
| 1674 |
r = driver_end_read(in_v); |
| 1675 |
if (r) |
| 1676 |
return error_trace(r); |
| 1677 |
|
| 1678 |
/* write the output message */ |
| 1679 |
string_to_hex(peer->bus->guid, sizeof(peer->bus->guid), buffer); |
| 1680 |
c_dvar_write(out_v, "(s)", buffer); |
| 1681 |
|
| 1682 |
r = driver_send_reply(peer, out_v, serial); |
| 1683 |
if (r) |
| 1684 |
return error_trace(r); |
| 1685 |
|
| 1686 |
return 0; |
| 1687 |
} |
| 1688 |
|
| 1689 |
static int driver_method_introspect(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1690 |
static const char *introspection_org_freedesktop_DBus = |
| 1691 |
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" |
| 1692 |
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n" |
| 1693 |
"<node>\n" |
| 1694 |
" <interface name=\"org.freedesktop.DBus\">\n" |
| 1695 |
" <method name=\"Hello\">\n" |
| 1696 |
" <arg direction=\"out\" type=\"s\"/>\n" |
| 1697 |
" </method>\n" |
| 1698 |
" <method name=\"RequestName\">\n" |
| 1699 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1700 |
" <arg direction=\"in\" type=\"u\"/>\n" |
| 1701 |
" <arg direction=\"out\" type=\"u\"/>\n" |
| 1702 |
" </method>\n" |
| 1703 |
" <method name=\"ReleaseName\">\n" |
| 1704 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1705 |
" <arg direction=\"out\" type=\"u\"/>\n" |
| 1706 |
" </method>\n" |
| 1707 |
" <method name=\"StartServiceByName\">\n" |
| 1708 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1709 |
" <arg direction=\"in\" type=\"u\"/>\n" |
| 1710 |
" <arg direction=\"out\" type=\"u\"/>\n" |
| 1711 |
" </method>\n" |
| 1712 |
" <method name=\"UpdateActivationEnvironment\">\n" |
| 1713 |
" <arg direction=\"in\" type=\"a{ss}\"/>\n" |
| 1714 |
" </method>\n" |
| 1715 |
" <method name=\"NameHasOwner\">\n" |
| 1716 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1717 |
" <arg direction=\"out\" type=\"b\"/>\n" |
| 1718 |
" </method>\n" |
| 1719 |
" <method name=\"ListNames\">\n" |
| 1720 |
" <arg direction=\"out\" type=\"as\"/>\n" |
| 1721 |
" </method>\n" |
| 1722 |
" <method name=\"ListActivatableNames\">\n" |
| 1723 |
" <arg direction=\"out\" type=\"as\"/>\n" |
| 1724 |
" </method>\n" |
| 1725 |
" <method name=\"AddMatch\">\n" |
| 1726 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1727 |
" </method>\n" |
| 1728 |
" <method name=\"RemoveMatch\">\n" |
| 1729 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1730 |
" </method>\n" |
| 1731 |
" <method name=\"GetNameOwner\">\n" |
| 1732 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1733 |
" <arg direction=\"out\" type=\"s\"/>\n" |
| 1734 |
" </method>\n" |
| 1735 |
" <method name=\"ListQueuedOwners\">\n" |
| 1736 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1737 |
" <arg direction=\"out\" type=\"as\"/>\n" |
| 1738 |
" </method>\n" |
| 1739 |
" <method name=\"GetConnectionUnixUser\">\n" |
| 1740 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1741 |
" <arg direction=\"out\" type=\"u\"/>\n" |
| 1742 |
" </method>\n" |
| 1743 |
" <method name=\"GetConnectionUnixProcessID\">\n" |
| 1744 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1745 |
" <arg direction=\"out\" type=\"u\"/>\n" |
| 1746 |
" </method>\n" |
| 1747 |
" <method name=\"GetAdtAuditSessionData\">\n" |
| 1748 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1749 |
" <arg direction=\"out\" type=\"ay\"/>\n" |
| 1750 |
" </method>\n" |
| 1751 |
" <method name=\"GetConnectionSELinuxSecurityContext\">\n" |
| 1752 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1753 |
" <arg direction=\"out\" type=\"ay\"/>\n" |
| 1754 |
" </method>\n" |
| 1755 |
" <method name=\"ReloadConfig\">\n" |
| 1756 |
" </method>\n" |
| 1757 |
" <method name=\"GetId\">\n" |
| 1758 |
" <arg direction=\"out\" type=\"s\"/>\n" |
| 1759 |
" </method>\n" |
| 1760 |
" <method name=\"GetConnectionCredentials\">\n" |
| 1761 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1762 |
" <arg direction=\"out\" type=\"a{sv}\"/>\n" |
| 1763 |
" </method>\n" |
| 1764 |
" <property name=\"Features\" type=\"as\" access=\"read\">\n" |
| 1765 |
" <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"const\"/>\n" |
| 1766 |
" </property>\n" |
| 1767 |
" <property name=\"Interfaces\" type=\"as\" access=\"read\">\n" |
| 1768 |
" <annotation name=\"org.freedesktop.DBus.Property.EmitsChangedSignal\" value=\"const\"/>\n" |
| 1769 |
" </property>\n" |
| 1770 |
" <signal name=\"NameOwnerChanged\">\n" |
| 1771 |
" <arg type=\"s\"/>\n" |
| 1772 |
" <arg type=\"s\"/>\n" |
| 1773 |
" <arg type=\"s\"/>\n" |
| 1774 |
" </signal>\n" |
| 1775 |
" <signal name=\"NameLost\">\n" |
| 1776 |
" <arg type=\"s\"/>\n" |
| 1777 |
" </signal>\n" |
| 1778 |
" <signal name=\"NameAcquired\">\n" |
| 1779 |
" <arg type=\"s\"/>\n" |
| 1780 |
" </signal>\n" |
| 1781 |
" </interface>\n" |
| 1782 |
" <interface name=\"org.freedesktop.DBus.Properties\">\n" |
| 1783 |
" <method name=\"Get\">\n" |
| 1784 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1785 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1786 |
" <arg direction=\"out\" type=\"v\"/>\n" |
| 1787 |
" </method>\n" |
| 1788 |
" <method name=\"GetAll\">\n" |
| 1789 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1790 |
" <arg direction=\"out\" type=\"a{sv}\"/>\n" |
| 1791 |
" </method>\n" |
| 1792 |
" <method name=\"Set\">\n" |
| 1793 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1794 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1795 |
" <arg direction=\"in\" type=\"v\"/>\n" |
| 1796 |
" </method>\n" |
| 1797 |
" <signal name=\"PropertiesChanged\">\n" |
| 1798 |
" <arg type=\"s\" name=\"interface_name\"/>\n" |
| 1799 |
" <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" |
| 1800 |
" <arg type=\"as\" name=\"invalidated_properties\"/>\n" |
| 1801 |
" </signal>\n" |
| 1802 |
" </interface>\n" |
| 1803 |
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n" |
| 1804 |
" <method name=\"Introspect\">\n" |
| 1805 |
" <arg direction=\"out\" type=\"s\"/>\n" |
| 1806 |
" </method>\n" |
| 1807 |
" </interface>\n" |
| 1808 |
" <interface name=\"org.freedesktop.DBus.Monitoring\">\n" |
| 1809 |
" <method name=\"BecomeMonitor\">\n" |
| 1810 |
" <arg direction=\"in\" type=\"as\"/>\n" |
| 1811 |
" <arg direction=\"in\" type=\"u\"/>\n" |
| 1812 |
" </method>\n" |
| 1813 |
" </interface>\n" |
| 1814 |
" <interface name=\"org.freedesktop.DBus.Peer\">\n" |
| 1815 |
" <method name=\"GetMachineId\">\n" |
| 1816 |
" <arg direction=\"out\" type=\"s\"/>\n" |
| 1817 |
" </method>\n" |
| 1818 |
" <method name=\"Ping\">\n" |
| 1819 |
" </method>\n" |
| 1820 |
" </interface>\n" |
| 1821 |
" <interface name=\"org.freedesktop.DBus.Debug.Stats\">\n" |
| 1822 |
" <method name=\"GetStats\">\n" |
| 1823 |
" <arg direction=\"out\" type=\"a{sv}\"/>\n" |
| 1824 |
" </method>\n" |
| 1825 |
" <method name=\"GetConnectionStats\">\n" |
| 1826 |
" <arg direction=\"in\" type=\"s\"/>\n" |
| 1827 |
" <arg direction=\"out\" type=\"a{sv}\"/>\n" |
| 1828 |
" </method>\n" |
| 1829 |
" <method name=\"GetAllMatchRules\">\n" |
| 1830 |
" <arg direction=\"out\" type=\"a{sas}\"/>\n" |
| 1831 |
" </method>\n" |
| 1832 |
" </interface>\n" |
| 1833 |
"</node>\n"; |
| 1834 |
static const char *introspection_org_freedesktop = |
| 1835 |
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" |
| 1836 |
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n" |
| 1837 |
"<node>\n" |
| 1838 |
" <node name=\"DBus\"/>\n" |
| 1839 |
"</node>\n"; |
| 1840 |
static const char *introspection_org = |
| 1841 |
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" |
| 1842 |
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n" |
| 1843 |
"<node>\n" |
| 1844 |
" <node name=\"freedesktop/DBus\"/>\n" |
| 1845 |
"</node>\n"; |
| 1846 |
static const char *introspection = |
| 1847 |
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" |
| 1848 |
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n" |
| 1849 |
"<node>\n" |
| 1850 |
" <node name=\"org/freedesktop/DBus\"/>\n" |
| 1851 |
"</node>\n"; |
| 1852 |
static const char *introspection_any = |
| 1853 |
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" |
| 1854 |
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n" |
| 1855 |
"<node>\n" |
| 1856 |
"</node>\n"; |
| 1857 |
int r; |
| 1858 |
|
| 1859 |
c_dvar_read(in_v, "()"); |
| 1860 |
|
| 1861 |
r = driver_end_read(in_v); |
| 1862 |
if (r) |
| 1863 |
return error_trace(r); |
| 1864 |
|
| 1865 |
/* |
| 1866 |
* We return the same intropsection data for the canonical path as the reference |
| 1867 |
* implementation does, and all methods behave the same. However, we only expose |
| 1868 |
* simplified intropsection data for all other paths, as if all interfaces were |
| 1869 |
* only implemented on the canonical path. The only reason they are implemented |
| 1870 |
* on arbitrary paths is for backwards compatibility. |
| 1871 |
*/ |
| 1872 |
if (!strcmp(path, "/org/freedesktop/DBus")) |
| 1873 |
c_dvar_write(out_v, "(s)", introspection_org_freedesktop_DBus); |
| 1874 |
else if (!strcmp(path, "/org/freedesktop")) |
| 1875 |
c_dvar_write(out_v, "(s)", introspection_org_freedesktop); |
| 1876 |
else if (!strcmp(path, "/org")) |
| 1877 |
c_dvar_write(out_v, "(s)", introspection_org); |
| 1878 |
else if (!strcmp(path, "/")) |
| 1879 |
c_dvar_write(out_v, "(s)", introspection); |
| 1880 |
else |
| 1881 |
c_dvar_write(out_v, "(s)", introspection_any); |
| 1882 |
|
| 1883 |
r = driver_send_reply(peer, out_v, serial); |
| 1884 |
if (r) |
| 1885 |
return error_trace(r); |
| 1886 |
|
| 1887 |
return 0; |
| 1888 |
} |
| 1889 |
|
| 1890 |
static int driver_method_become_monitor(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1891 |
MatchOwner owned_matches; |
| 1892 |
const char *match_string; |
| 1893 |
uint32_t flags; |
| 1894 |
int r; |
| 1895 |
|
| 1896 |
if (!peer_is_privileged(peer)) |
| 1897 |
return DRIVER_E_PEER_NOT_PRIVILEGED; |
| 1898 |
|
| 1899 |
r = bus_apparmor_check_eavesdrop(peer->policy->apparmor, peer->policy->seclabel); |
| 1900 |
if (r == BUS_APPARMOR_E_DENIED) |
| 1901 |
return DRIVER_E_PEER_NOT_PRIVILEGED; |
| 1902 |
else if (r) |
| 1903 |
return error_fold(r); |
| 1904 |
|
| 1905 |
/* first create all the match objects before modifying the peer */ |
| 1906 |
match_owner_init(&owned_matches); |
| 1907 |
|
| 1908 |
c_dvar_read(in_v, "(["); |
| 1909 |
do { |
| 1910 |
/* |
| 1911 |
* dbus-daemon treats an empty match-array as if an array with |
| 1912 |
* a single empty string was passed. This effectively becomes a |
| 1913 |
* wildcard match, thus the monitor receives everything. |
| 1914 |
*/ |
| 1915 |
if (c_dvar_more(in_v)) |
| 1916 |
c_dvar_read(in_v, "s", &match_string); |
| 1917 |
else |
| 1918 |
match_string = ""; |
| 1919 |
|
| 1920 |
/* |
| 1921 |
* We pass `true` for `allow_eavesdrop` for compatibility |
| 1922 |
* reasons. We do not support eavesdropping, but `dbus-monitor` |
| 1923 |
* seems to prepend `eavesdrop=true` unconditionally to all |
| 1924 |
* match-rules it installs. However, there is no reason to do |
| 1925 |
* that with `BecomeMonitor()`, because this is already |
| 1926 |
* implicitly set. |
| 1927 |
* Regardless, we must allow these rules to specify `eavesdrop` |
| 1928 |
* filters, even though we will just silently ignore them. |
| 1929 |
*/ |
| 1930 |
r = match_owner_ref_rule(&owned_matches, NULL, peer->user, match_string, true); |
| 1931 |
if (r) { |
| 1932 |
r = (r == MATCH_E_INVALID) ? DRIVER_E_MATCH_INVALID : error_fold(r); |
| 1933 |
goto error; |
| 1934 |
} |
| 1935 |
} while (c_dvar_more(in_v)); |
| 1936 |
c_dvar_read(in_v, "]u)", &flags); |
| 1937 |
|
| 1938 |
/* verify the input arguments*/ |
| 1939 |
r = driver_end_read(in_v); |
| 1940 |
if (r) { |
| 1941 |
r = error_trace(r); |
| 1942 |
goto error; |
| 1943 |
} |
| 1944 |
|
| 1945 |
if (flags) { |
| 1946 |
r = DRIVER_E_UNEXPECTED_FLAGS; |
| 1947 |
goto error; |
| 1948 |
} |
| 1949 |
|
| 1950 |
/* write the output message */ |
| 1951 |
c_dvar_write(out_v, "()"); |
| 1952 |
|
| 1953 |
r = driver_send_reply(peer, out_v, serial); |
| 1954 |
if (r) { |
| 1955 |
r = error_trace(r); |
| 1956 |
goto error; |
| 1957 |
} |
| 1958 |
|
| 1959 |
/* only fatal errors from here on */ |
| 1960 |
|
| 1961 |
r = driver_goodbye(peer, false); |
| 1962 |
if (r) { |
| 1963 |
r = error_trace(r); |
| 1964 |
goto error; |
| 1965 |
} |
| 1966 |
|
| 1967 |
r = peer_become_monitor(peer, &owned_matches); |
| 1968 |
if (r) { |
| 1969 |
r = error_fold(r); |
| 1970 |
goto error; |
| 1971 |
} |
| 1972 |
|
| 1973 |
match_owner_deinit(&owned_matches); |
| 1974 |
|
| 1975 |
return 0; |
| 1976 |
|
| 1977 |
error: |
| 1978 |
while (owned_matches.rule_tree.root) |
| 1979 |
match_rule_user_unref(c_container_of(owned_matches.rule_tree.root, MatchRule, owner_node)); |
| 1980 |
|
| 1981 |
return r; |
| 1982 |
} |
| 1983 |
|
| 1984 |
static int driver_method_ping(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 1985 |
int r; |
| 1986 |
|
| 1987 |
c_dvar_read(in_v, "()"); |
| 1988 |
|
| 1989 |
r = driver_end_read(in_v); |
| 1990 |
if (r) |
| 1991 |
return error_trace(r); |
| 1992 |
|
| 1993 |
c_dvar_write(out_v, "()"); |
| 1994 |
|
| 1995 |
r = driver_send_reply(peer, out_v, serial); |
| 1996 |
if (r) |
| 1997 |
return error_trace(r); |
| 1998 |
|
| 1999 |
return 0; |
| 2000 |
} |
| 2001 |
|
| 2002 |
static int driver_method_get_machine_id(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 2003 |
int r; |
| 2004 |
|
| 2005 |
/* verify the input argument */ |
| 2006 |
c_dvar_read(in_v, "()"); |
| 2007 |
|
| 2008 |
r = driver_end_read(in_v); |
| 2009 |
if (r) |
| 2010 |
return error_trace(r); |
| 2011 |
|
| 2012 |
/* write the output message */ |
| 2013 |
c_dvar_write(out_v, "(s)", peer->bus->machine_id); |
| 2014 |
|
| 2015 |
r = driver_send_reply(peer, out_v, serial); |
| 2016 |
if (r) |
| 2017 |
return error_trace(r); |
| 2018 |
|
| 2019 |
return 0; |
| 2020 |
} |
| 2021 |
|
| 2022 |
static void driver_append_property_features(CDVar *v) { |
| 2023 |
static const CDVarType variant_type[] = { |
| 2024 |
C_DVAR_T_INIT( |
| 2025 |
C_DVAR_T_ARRAY( |
| 2026 |
C_DVAR_T_s |
| 2027 |
) |
| 2028 |
) |
| 2029 |
}; |
| 2030 |
|
| 2031 |
c_dvar_write(v, "<[", variant_type); |
| 2032 |
if (bus_selinux_is_enabled()) |
| 2033 |
c_dvar_write(v, "s", "SELinux"); |
| 2034 |
c_dvar_write(v, "]>"); |
| 2035 |
} |
| 2036 |
|
| 2037 |
static void driver_append_property_interfaces(CDVar *v) { |
| 2038 |
static const CDVarType variant_type[] = { |
| 2039 |
C_DVAR_T_INIT( |
| 2040 |
C_DVAR_T_ARRAY( |
| 2041 |
C_DVAR_T_s |
| 2042 |
) |
| 2043 |
) |
| 2044 |
}; |
| 2045 |
|
| 2046 |
c_dvar_write(v, "<[s]>", variant_type, "org.freedesktop.DBus.Monitoring"); |
| 2047 |
} |
| 2048 |
|
| 2049 |
static int driver_method_get(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 2050 |
const char *interface, *property; |
| 2051 |
int r; |
| 2052 |
|
| 2053 |
/* verify the input argument */ |
| 2054 |
c_dvar_read(in_v, "(ss)", &interface, &property); |
| 2055 |
|
| 2056 |
r = driver_end_read(in_v); |
| 2057 |
if (r) |
| 2058 |
return error_trace(r); |
| 2059 |
|
| 2060 |
/* only one interface is supported */ |
| 2061 |
if (strcmp(interface, "org.freedesktop.DBus") != 0) |
| 2062 |
return DRIVER_E_UNEXPECTED_INTERFACE; |
| 2063 |
|
| 2064 |
c_dvar_write(out_v, "("); |
| 2065 |
/* append the right property */ |
| 2066 |
if (strcmp(property, "Features") == 0) |
| 2067 |
driver_append_property_features(out_v); |
| 2068 |
else if (strcmp(property, "Interfaces") == 0) |
| 2069 |
driver_append_property_interfaces(out_v); |
| 2070 |
else |
| 2071 |
return DRIVER_E_UNEXPECTED_PROPERTY; |
| 2072 |
c_dvar_write(out_v, ")"); |
| 2073 |
|
| 2074 |
r = driver_send_reply(peer, out_v, serial); |
| 2075 |
if (r) |
| 2076 |
return error_trace(r); |
| 2077 |
|
| 2078 |
return 0; |
| 2079 |
} |
| 2080 |
|
| 2081 |
static int driver_method_set(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 2082 |
const char *interface, *property; |
| 2083 |
int r; |
| 2084 |
|
| 2085 |
c_dvar_read(in_v, "(ss", &interface, &property); |
| 2086 |
c_dvar_skip(in_v, "<*>)", NULL); |
| 2087 |
|
| 2088 |
r = driver_end_read(in_v); |
| 2089 |
if (r) |
| 2090 |
return error_trace(r); |
| 2091 |
|
| 2092 |
/* only one interface is supported */ |
| 2093 |
if (strcmp(interface, "org.freedesktop.DBus") != 0) |
| 2094 |
return DRIVER_E_UNEXPECTED_INTERFACE; |
| 2095 |
|
| 2096 |
if (strcmp(property, "Features") != 0 && strcmp(property, "Interfaces") != 0) |
| 2097 |
return DRIVER_E_UNEXPECTED_PROPERTY; |
| 2098 |
|
| 2099 |
return DRIVER_E_READONLY_PROPERTY; |
| 2100 |
} |
| 2101 |
|
| 2102 |
static int driver_method_get_all(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 2103 |
const char *interface; |
| 2104 |
int r; |
| 2105 |
|
| 2106 |
/* verify the input argument */ |
| 2107 |
c_dvar_read(in_v, "(s)", &interface); |
| 2108 |
|
| 2109 |
r = driver_end_read(in_v); |
| 2110 |
if (r) |
| 2111 |
return error_trace(r); |
| 2112 |
|
| 2113 |
/* only one interfaces is supported */ |
| 2114 |
if (strcmp(interface, "org.freedesktop.DBus") != 0) |
| 2115 |
return DRIVER_E_UNEXPECTED_INTERFACE; |
| 2116 |
|
| 2117 |
/* append both supported properties */ |
| 2118 |
c_dvar_write(out_v, "([{s", "Features"); |
| 2119 |
driver_append_property_features(out_v); |
| 2120 |
c_dvar_write(out_v, "}{s", "Interfaces"); |
| 2121 |
driver_append_property_interfaces(out_v); |
| 2122 |
c_dvar_write(out_v, "}])"); |
| 2123 |
|
| 2124 |
r = driver_send_reply(peer, out_v, serial); |
| 2125 |
if (r) |
| 2126 |
return error_trace(r); |
| 2127 |
|
| 2128 |
return 0; |
| 2129 |
} |
| 2130 |
|
| 2131 |
static void driver_append_peer_accounting_stats(CDVar *v, Peer *peer) { |
| 2132 |
unsigned int n_name_objects, n_match_bytes, n_matches, n_reply_objects, |
| 2133 |
n_conn_in_bytes, n_conn_in_fds, n_conn_out_bytes, n_conn_out_fds, |
| 2134 |
n_activation_bytes, n_activation_fds; |
| 2135 |
|
| 2136 |
name_owner_get_stats(&peer->owned_names, &n_name_objects); |
| 2137 |
match_owner_get_stats(&peer->owned_matches, &n_match_bytes, &n_matches); |
| 2138 |
reply_owner_get_stats(&peer->owned_replies, &n_reply_objects); |
| 2139 |
connection_get_stats(&peer->connection, &n_conn_in_bytes, &n_conn_in_fds, |
| 2140 |
&n_conn_out_bytes, &n_conn_out_fds); |
| 2141 |
name_registry_get_activation_stats_for(&peer->bus->names, peer->id, |
| 2142 |
&n_activation_bytes, &n_activation_fds); |
| 2143 |
|
| 2144 |
c_dvar_write(v, "[" |
| 2145 |
"{su}" |
| 2146 |
"{su}" |
| 2147 |
"{su}" |
| 2148 |
"{su}" |
| 2149 |
"{su}" |
| 2150 |
"{su}" |
| 2151 |
"{su}" |
| 2152 |
"{su}" |
| 2153 |
"{su}" |
| 2154 |
"{su}" |
| 2155 |
"]", |
| 2156 |
"NameObjects", n_name_objects, |
| 2157 |
"MatchBytes", n_match_bytes, |
| 2158 |
"Matches", n_matches, |
| 2159 |
"ReplyObjects", n_reply_objects, |
| 2160 |
"IncomingBytes", n_conn_in_bytes, |
| 2161 |
"IncomingFds", n_conn_in_fds, |
| 2162 |
"OutgoingBytes", n_conn_out_bytes, |
| 2163 |
"OutgoingFds", n_conn_out_fds, |
| 2164 |
"ActivationRequestBytes", n_activation_bytes, |
| 2165 |
"ActivationRequestFds", n_activation_fds); |
| 2166 |
} |
| 2167 |
|
| 2168 |
static void driver_append_peer_accounting(CDVar *v, Bus *bus) { |
| 2169 |
static const CDVarType dump_type[] = { |
| 2170 |
C_DVAR_T_INIT( |
| 2171 |
C_DVAR_T_ARRAY( |
| 2172 |
C_DVAR_T_TUPLE3( |
| 2173 |
C_DVAR_T_s, |
| 2174 |
C_DVAR_T_ARRAY( |
| 2175 |
C_DVAR_T_PAIR( |
| 2176 |
C_DVAR_T_s, |
| 2177 |
C_DVAR_T_v |
| 2178 |
) |
| 2179 |
), |
| 2180 |
C_DVAR_T_ARRAY( |
| 2181 |
C_DVAR_T_PAIR( |
| 2182 |
C_DVAR_T_s, |
| 2183 |
C_DVAR_T_u |
| 2184 |
) |
| 2185 |
) |
| 2186 |
) |
| 2187 |
) |
| 2188 |
) |
| 2189 |
}; |
| 2190 |
Peer *p; |
| 2191 |
|
| 2192 |
c_dvar_write(v, "<[", dump_type); |
| 2193 |
|
| 2194 |
c_rbtree_for_each_entry(p, &bus->peers.peer_tree, registry_node) { |
| 2195 |
DriverCredentials cred = DRIVER_CREDENTIALS_NULL; |
| 2196 |
|
| 2197 |
if (!peer_is_registered(p)) |
| 2198 |
continue; |
| 2199 |
|
| 2200 |
c_dvar_write(v, "("); |
| 2201 |
driver_dvar_write_unique_name(v, p); |
| 2202 |
driver_fetch_credentials(bus, p, &cred); |
| 2203 |
driver_append_credentials(v, &cred, NULL); |
| 2204 |
driver_append_peer_accounting_stats(v, p); |
| 2205 |
c_dvar_write(v, ")"); |
| 2206 |
} |
| 2207 |
|
| 2208 |
c_dvar_write(v, "]>"); |
| 2209 |
} |
| 2210 |
|
| 2211 |
static void driver_append_user_accounting(CDVar *v, Bus *bus) { |
| 2212 |
static const CDVarType dump_type[] = { |
| 2213 |
C_DVAR_T_INIT( |
| 2214 |
C_DVAR_T_ARRAY( |
| 2215 |
C_DVAR_T_TUPLE3( |
| 2216 |
C_DVAR_T_u, |
| 2217 |
C_DVAR_T_ARRAY( |
| 2218 |
C_DVAR_T_TUPLE3( |
| 2219 |
C_DVAR_T_s, |
| 2220 |
C_DVAR_T_u, |
| 2221 |
C_DVAR_T_u |
| 2222 |
) |
| 2223 |
), |
| 2224 |
C_DVAR_T_ARRAY( |
| 2225 |
C_DVAR_T_PAIR( |
| 2226 |
C_DVAR_T_u, |
| 2227 |
C_DVAR_T_ARRAY( |
| 2228 |
C_DVAR_T_PAIR( |
| 2229 |
C_DVAR_T_s, |
| 2230 |
C_DVAR_T_u |
| 2231 |
) |
| 2232 |
) |
| 2233 |
) |
| 2234 |
) |
| 2235 |
) |
| 2236 |
) |
| 2237 |
) |
| 2238 |
}; |
| 2239 |
UserUsage *usage; |
| 2240 |
User *user; |
| 2241 |
|
| 2242 |
c_assert(_USER_SLOT_N == bus->users.n_slots); |
| 2243 |
|
| 2244 |
c_dvar_write(v, "<[", dump_type); |
| 2245 |
|
| 2246 |
c_rbtree_for_each_entry(user, &bus->users.user_tree, registry_node) { |
| 2247 |
c_dvar_write(v, "(u[" |
| 2248 |
"(suu)" |
| 2249 |
"(suu)" |
| 2250 |
"(suu)" |
| 2251 |
"(suu)" |
| 2252 |
"][", |
| 2253 |
user->uid, |
| 2254 |
"Bytes", user->slots[0].n, user->slots[0].max, |
| 2255 |
"Fds", user->slots[1].n, user->slots[1].max, |
| 2256 |
"Matches", user->slots[2].n, user->slots[2].max, |
| 2257 |
"Objects", user->slots[3].n, user->slots[3].max); |
| 2258 |
c_rbtree_for_each_entry(usage, &user->usage_tree, user_node) { |
| 2259 |
c_dvar_write(v, "{u[" |
| 2260 |
"{su}" |
| 2261 |
"{su}" |
| 2262 |
"{su}" |
| 2263 |
"{su}" |
| 2264 |
"]}", |
| 2265 |
usage->uid, |
| 2266 |
"Bytes", usage->slots[0], |
| 2267 |
"Fds", usage->slots[1], |
| 2268 |
"Matches", usage->slots[2], |
| 2269 |
"Objects", usage->slots[3]); |
| 2270 |
} |
| 2271 |
c_dvar_write(v, "])"); |
| 2272 |
} |
| 2273 |
|
| 2274 |
c_dvar_write(v, "]>"); |
| 2275 |
} |
| 2276 |
|
| 2277 |
static int driver_method_get_stats(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 2278 |
Bus *bus = peer->bus; |
| 2279 |
int r; |
| 2280 |
|
| 2281 |
c_dvar_read(in_v, "()"); |
| 2282 |
|
| 2283 |
r = driver_end_read(in_v); |
| 2284 |
if (r) |
| 2285 |
return error_trace(r); |
| 2286 |
|
| 2287 |
c_dvar_write(out_v, "([{s", "org.bus1.DBus.Debug.Stats.PeerAccounting"); |
| 2288 |
driver_append_peer_accounting(out_v, peer->bus); |
| 2289 |
c_dvar_write(out_v, "}{s", "org.bus1.DBus.Debug.Stats.UserAccounting"); |
| 2290 |
driver_append_user_accounting(out_v, peer->bus); |
| 2291 |
c_dvar_write(out_v, "}" |
| 2292 |
"{s<u>}" |
| 2293 |
"{s<u>}" |
| 2294 |
"{s<u>}" |
| 2295 |
"{s<u>}" |
| 2296 |
"{s<u>}" |
| 2297 |
"{s<u>}" |
| 2298 |
"{s<u>}" |
| 2299 |
"{s<u>}" |
| 2300 |
"{s<u>}" |
| 2301 |
"])", |
| 2302 |
"Serial", c_dvar_type_u, |
| 2303 |
util_t2u_saturating(++peer->bus->stats_ids), |
| 2304 |
"ActiveConnections", c_dvar_type_u, |
| 2305 |
util_z2u_saturating(bus->peers.n_registered), |
| 2306 |
"IncompleteConnections", c_dvar_type_u, |
| 2307 |
util_z2u_saturating(bus->peers.n_peers - bus->peers.n_registered), |
| 2308 |
"BusNames", c_dvar_type_u, |
| 2309 |
util_z2u_saturating(bus->names.n_primaries), |
| 2310 |
"PeakBusNames", c_dvar_type_u, |
| 2311 |
util_z2u_saturating(bus->names.n_primaries_peak), |
| 2312 |
"PeakBusNamesPerConnection", c_dvar_type_u, |
| 2313 |
util_z2u_saturating(bus->names.n_owner_primaries_peak), |
| 2314 |
"MatchRules", c_dvar_type_u, |
| 2315 |
util_z2u_saturating(bus->match_counters.n_subscriptions), |
| 2316 |
"PeakMatchRules", c_dvar_type_u, |
| 2317 |
util_z2u_saturating(bus->match_counters.n_subscriptions_peak), |
| 2318 |
"PeakMatchRulesPerConnection", c_dvar_type_u, |
| 2319 |
util_z2u_saturating(bus->match_counters.n_owner_subscriptions_peak) |
| 2320 |
); |
| 2321 |
|
| 2322 |
r = driver_send_reply(peer, out_v, serial); |
| 2323 |
if (r) |
| 2324 |
return error_trace(r); |
| 2325 |
|
| 2326 |
return 0; |
| 2327 |
} |
| 2328 |
|
| 2329 |
static int driver_method_get_connection_stats(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 2330 |
return DRIVER_E_UNIMPLEMENTED; |
| 2331 |
} |
| 2332 |
|
| 2333 |
static int driver_method_get_all_match_rules(Peer *peer, const char *path, CDVar *in_v, uint32_t serial, CDVar *out_v) { |
| 2334 |
return DRIVER_E_UNIMPLEMENTED; |
| 2335 |
} |
| 2336 |
|
| 2337 |
static int driver_handle_method(const DriverMethod *method, Peer *peer, const char *path, uint32_t serial, const char *signature_in, Message *message_in) { |
| 2338 |
_c_cleanup_(c_dvar_deinit) CDVar var_in = C_DVAR_INIT, var_out = C_DVAR_INIT; |
| 2339 |
int r; |
| 2340 |
|
| 2341 |
/* |
| 2342 |
* Verify the path and the input signature and prepare the |
| 2343 |
* input & output variants for input parsing and output marshaling. |
| 2344 |
*/ |
| 2345 |
|
| 2346 |
if (method->path && strcmp(path, method->path) != 0) |
| 2347 |
return DRIVER_E_UNEXPECTED_PATH; |
| 2348 |
|
| 2349 |
r = driver_dvar_verify_signature_in(method->in, signature_in); |
| 2350 |
if (r) |
| 2351 |
return error_trace(r); |
| 2352 |
|
| 2353 |
c_dvar_begin_read(&var_in, message_in->big_endian, method->in, 1, message_in->body, message_in->n_body); |
| 2354 |
c_dvar_begin_write(&var_out, (__BYTE_ORDER == __BIG_ENDIAN), method->out, 1); |
| 2355 |
|
| 2356 |
/* |
| 2357 |
* Note that some driver-methods are responsible for writing the |
| 2358 |
* reply-header, given they might need to send file descriptors, which |
| 2359 |
* needs a specific count field to be added. |
| 2360 |
* They all are responsible for calling c_dvar_end_read(var_in), to |
| 2361 |
* assert that all read data was correct. |
| 2362 |
* We already verify that the payload matches the signature, and that |
| 2363 |
* the signature matches the method call, so this is just to catch |
| 2364 |
* programming errors in the broker. |
| 2365 |
*/ |
| 2366 |
|
| 2367 |
c_dvar_write(&var_out, "("); |
| 2368 |
if (!method->writes_own_header) |
| 2369 |
driver_write_reply_header(&var_out, peer, serial, method->out, /* n_fds= */ 0); |
| 2370 |
|
| 2371 |
r = method->fn(peer, path, &var_in, serial, &var_out); |
| 2372 |
if (r) |
| 2373 |
return error_trace(r); |
| 2374 |
|
| 2375 |
return 0; |
| 2376 |
} |
| 2377 |
|
| 2378 |
static const DriverMethod driver_methods[] = { |
| 2379 |
{ "Hello", false, NULL, driver_method_hello, c_dvar_type_unit, driver_type_out_s, false }, |
| 2380 |
{ "AddMatch", true, NULL, driver_method_add_match, driver_type_in_s, driver_type_out_unit, false }, |
| 2381 |
{ "RemoveMatch", true, NULL, driver_method_remove_match, driver_type_in_s, driver_type_out_unit, false }, |
| 2382 |
{ "RequestName", true, NULL, driver_method_request_name, driver_type_in_su, driver_type_out_u, false }, |
| 2383 |
{ "ReleaseName", true, NULL, driver_method_release_name, driver_type_in_s, driver_type_out_u, false }, |
| 2384 |
{ "GetConnectionCredentials", true, NULL, driver_method_get_connection_credentials, driver_type_in_s, driver_type_out_apsv, true }, |
| 2385 |
{ "GetConnectionUnixUser", true, NULL, driver_method_get_connection_unix_user, driver_type_in_s, driver_type_out_u, false }, |
| 2386 |
{ "GetConnectionUnixProcessID", true, NULL, driver_method_get_connection_unix_process_id, driver_type_in_s, driver_type_out_u, false }, |
| 2387 |
{ "GetAdtAuditSessionData", true, NULL, driver_method_get_adt_audit_session_data, driver_type_in_s, driver_type_out_ay, false }, |
| 2388 |
{ "GetConnectionSELinuxSecurityContext", true, NULL, driver_method_get_connection_selinux_security_context, driver_type_in_s, driver_type_out_ay, false }, |
| 2389 |
{ "StartServiceByName", true, NULL, driver_method_start_service_by_name, driver_type_in_su, driver_type_out_u, false }, |
| 2390 |
{ "ListQueuedOwners", true, NULL, driver_method_list_queued_owners, driver_type_in_s, driver_type_out_as, false }, |
| 2391 |
{ "ListNames", true, NULL, driver_method_list_names, c_dvar_type_unit, driver_type_out_as, false }, |
| 2392 |
{ "ListActivatableNames", true, NULL, driver_method_list_activatable_names, c_dvar_type_unit, driver_type_out_as, false }, |
| 2393 |
{ "NameHasOwner", true, NULL, driver_method_name_has_owner, driver_type_in_s, driver_type_out_b, false }, |
| 2394 |
{ "UpdateActivationEnvironment", true, "/org/freedesktop/DBus", driver_method_update_activation_environment, driver_type_in_apss, driver_type_out_unit, false }, |
| 2395 |
{ "GetNameOwner", true, NULL, driver_method_get_name_owner, driver_type_in_s, driver_type_out_s, false }, |
| 2396 |
{ "ReloadConfig", true, NULL, driver_method_reload_config, c_dvar_type_unit, driver_type_out_unit, false }, |
| 2397 |
{ "GetId", true, NULL, driver_method_get_id, c_dvar_type_unit, driver_type_out_s, false }, |
| 2398 |
{ }, |
| 2399 |
}; |
| 2400 |
|
| 2401 |
static const DriverMethod monitoring_methods[] = { |
| 2402 |
{ "BecomeMonitor", true, "/org/freedesktop/DBus", driver_method_become_monitor, driver_type_in_asu, driver_type_out_unit, false }, |
| 2403 |
{ }, |
| 2404 |
}; |
| 2405 |
|
| 2406 |
static const DriverMethod introspectable_methods[] = { |
| 2407 |
{ "Introspect", true, NULL, driver_method_introspect, c_dvar_type_unit, driver_type_out_s, false }, |
| 2408 |
{ }, |
| 2409 |
}; |
| 2410 |
|
| 2411 |
static const DriverMethod peer_methods[] = { |
| 2412 |
{ "Ping", true, NULL, driver_method_ping, c_dvar_type_unit, driver_type_out_unit, false }, |
| 2413 |
{ "GetMachineId", true, NULL, driver_method_get_machine_id, c_dvar_type_unit, driver_type_out_s, false }, |
| 2414 |
{ }, |
| 2415 |
}; |
| 2416 |
|
| 2417 |
static const DriverMethod properties_methods[] = { |
| 2418 |
{ "Get", true, "/org/freedesktop/DBus", driver_method_get, driver_type_in_ss, driver_type_out_v, false }, |
| 2419 |
{ "Set", true, "/org/freedesktop/DBus", driver_method_set, driver_type_in_ssv, driver_type_out_unit, false }, |
| 2420 |
{ "GetAll", true, "/org/freedesktop/DBus", driver_method_get_all, driver_type_in_s, driver_type_out_apsv, false }, |
| 2421 |
{ }, |
| 2422 |
}; |
| 2423 |
|
| 2424 |
static const DriverMethod debug_stats_methods[] = { |
| 2425 |
{ "GetStats", true, "/org/freedesktop/DBus", driver_method_get_stats, c_dvar_type_unit, driver_type_out_apsv, false }, |
| 2426 |
{ "GetConnectionStats", true, "/org/freedesktop/DBus", driver_method_get_connection_stats, driver_type_in_s, driver_type_out_apsv, false }, |
| 2427 |
{ "GetAllMatchRules", true, "/org/freedesktop/DBus", driver_method_get_all_match_rules, c_dvar_type_unit, driver_type_out_apsas, false }, |
| 2428 |
{ }, |
| 2429 |
}; |
| 2430 |
|
| 2431 |
static int driver_dispatch_method(Peer *peer, const DriverMethod *methods, uint32_t serial, const char *method, const char *path, const char *signature, Message *message) { |
| 2432 |
for (size_t i = 0; methods[i].name; i++) { |
| 2433 |
if (strcmp(methods[i].name, method) != 0) |
| 2434 |
continue; |
| 2435 |
|
| 2436 |
if (_c_likely_(peer_is_registered(peer)) || !methods[i].needs_registration) |
| 2437 |
return driver_handle_method(methods + i, peer, path, serial, signature, message); |
| 2438 |
} |
| 2439 |
|
| 2440 |
return DRIVER_E_UNEXPECTED_METHOD; |
| 2441 |
} |
| 2442 |
|
| 2443 |
static int driver_map_denied_error(int err) { |
| 2444 |
switch (err) { |
| 2445 |
case POLICY_E_SELINUX_ACCESS_DENIED: |
| 2446 |
return BUS_LOG_POLICY_TYPE_SELINUX; |
| 2447 |
case POLICY_E_APPARMOR_ACCESS_DENIED: |
| 2448 |
return BUS_LOG_POLICY_TYPE_APPARMOR; |
| 2449 |
default: |
| 2450 |
return BUS_LOG_POLICY_TYPE_INTERNAL; |
| 2451 |
} |
| 2452 |
} |
| 2453 |
|
| 2454 |
static int driver_dispatch_interface(Peer *peer, uint32_t serial, const char *interface, const char *member, const char *path, const char *signature, Message *message) { |
| 2455 |
static const DriverInterface interfaces[] = { |
| 2456 |
{ "org.freedesktop.DBus", driver_methods }, |
| 2457 |
{ "org.freedesktop.DBus.Monitoring", monitoring_methods }, |
| 2458 |
{ "org.freedesktop.DBus.Introspectable", introspectable_methods }, |
| 2459 |
{ "org.freedesktop.DBus.Peer", peer_methods }, |
| 2460 |
{ "org.freedesktop.DBus.Properties", properties_methods }, |
| 2461 |
{ "org.freedesktop.DBus.Debug.Stats", debug_stats_methods }, |
| 2462 |
}; |
| 2463 |
int r; |
| 2464 |
|
| 2465 |
if (message->header->type != DBUS_MESSAGE_TYPE_METHOD_CALL) |
| 2466 |
/* ignore */ |
| 2467 |
return 0; |
| 2468 |
|
| 2469 |
r = policy_snapshot_check_send(peer->policy, NULL, NULL, 0, interface, member, path, message->header->type, false, message->metadata.fields.unix_fds); |
| 2470 |
if (r) { |
| 2471 |
if (r == POLICY_E_ACCESS_DENIED || |
| 2472 |
r == POLICY_E_SELINUX_ACCESS_DENIED || |
| 2473 |
r == POLICY_E_APPARMOR_ACCESS_DENIED) { |
| 2474 |
NameSet names = NAME_SET_INIT_FROM_OWNER(&peer->owned_names); |
| 2475 |
|
| 2476 |
log_append_here(peer->bus->log, LOG_WARNING, 0, NULL); |
| 2477 |
bus_log_append_policy_send(peer->bus, |
| 2478 |
driver_map_denied_error(r), |
| 2479 |
peer->id, ADDRESS_ID_INVALID, &names, NULL, peer->policy->seclabel, peer->bus->seclabel, message); |
| 2480 |
r = log_commitf(peer->bus->log, "A security policy denied :1.%llu to send method call %s:%s.%s to org.freedesktop.DBus.", |
| 2481 |
peer->id, path, interface, member); |
| 2482 |
if (r) |
| 2483 |
return error_fold(r); |
| 2484 |
|
| 2485 |
return DRIVER_E_SEND_DENIED; |
| 2486 |
} |
| 2487 |
|
| 2488 |
return error_fold(r); |
| 2489 |
} |
| 2490 |
|
| 2491 |
if (interface) { |
| 2492 |
for (size_t i = 0; i < C_ARRAY_SIZE(interfaces); ++i) { |
| 2493 |
if (strcmp(interfaces[i].name, interface) != 0) |
| 2494 |
continue; |
| 2495 |
|
| 2496 |
return error_trace(driver_dispatch_method(peer, interfaces[i].methods, serial, member, path, signature, message)); |
| 2497 |
} |
| 2498 |
|
| 2499 |
return DRIVER_E_UNEXPECTED_INTERFACE; |
| 2500 |
} else { |
| 2501 |
for (size_t i = 0; i < C_ARRAY_SIZE(interfaces); ++i) { |
| 2502 |
r = driver_dispatch_method(peer, interfaces[i].methods, serial, member, path, signature, message); |
| 2503 |
if (r == DRIVER_E_UNEXPECTED_METHOD) |
| 2504 |
continue; |
| 2505 |
|
| 2506 |
return error_trace(r); |
| 2507 |
} |
| 2508 |
|
| 2509 |
return DRIVER_E_UNEXPECTED_METHOD; |
| 2510 |
} |
| 2511 |
} |
| 2512 |
|
| 2513 |
int driver_goodbye(Peer *peer, bool silent) { |
| 2514 |
ReplySlot *reply, *reply_safe; |
| 2515 |
NameOwnership *ownership, *ownership_safe; |
| 2516 |
int r; |
| 2517 |
|
| 2518 |
peer_flush_matches(peer); |
| 2519 |
|
| 2520 |
c_list_for_each_entry_safe(reply, reply_safe, &peer->owned_replies.reply_list, owner_link) |
| 2521 |
reply_slot_free(reply); |
| 2522 |
|
| 2523 |
match_registry_flush(&peer->sender_matches); |
| 2524 |
|
| 2525 |
c_rbtree_for_each_entry_safe_postorder_unlink(ownership, ownership_safe, &peer->owned_names.ownership_tree, owner_node) { |
| 2526 |
NameChange change; |
| 2527 |
|
| 2528 |
name_change_init(&change); |
| 2529 |
peer_release_name_ownership(peer, ownership, &change); |
| 2530 |
if (!silent && change.name) |
| 2531 |
r = driver_name_owner_changed(peer->bus, |
| 2532 |
&change.name->name_owner_changed_matches, |
| 2533 |
change.name->name, |
| 2534 |
c_container_of(change.old_owner, Peer, owned_names), |
| 2535 |
c_container_of(change.new_owner, Peer, owned_names)); |
| 2536 |
else |
| 2537 |
r = 0; |
| 2538 |
name_change_deinit(&change); |
| 2539 |
if (r) |
| 2540 |
return error_fold(r); |
| 2541 |
} |
| 2542 |
|
| 2543 |
if (peer_is_registered(peer)) { |
| 2544 |
if (!silent) { |
| 2545 |
r = driver_name_owner_changed(peer->bus, &peer->name_owner_changed_matches, NULL, peer, NULL); |
| 2546 |
if (r) |
| 2547 |
return error_trace(r); |
| 2548 |
} |
| 2549 |
peer_unregister(peer); |
| 2550 |
} else if (peer_is_monitor(peer)) { |
| 2551 |
peer_stop_monitor(peer); |
| 2552 |
} |
| 2553 |
|
| 2554 |
match_registry_flush(&peer->name_owner_changed_matches); |
| 2555 |
|
| 2556 |
c_rbtree_for_each_entry_safe_postorder_unlink(reply, reply_safe, &peer->replies.reply_tree, registry_node) { |
| 2557 |
Peer *sender = c_container_of(reply->owner, Peer, owned_replies); |
| 2558 |
|
| 2559 |
if (!silent) { |
| 2560 |
r = driver_send_error(sender, reply->serial, "org.freedesktop.DBus.Error.NoReply", "Remote peer disconnected"); |
| 2561 |
if (r) |
| 2562 |
return error_trace(r); |
| 2563 |
} |
| 2564 |
|
| 2565 |
reply_slot_free(reply); |
| 2566 |
} |
| 2567 |
|
| 2568 |
return 0; |
| 2569 |
} |
| 2570 |
|
| 2571 |
static int driver_forward_unicast(Peer *sender, const char *destination, Message *message) { |
| 2572 |
NameSet sender_names = NAME_SET_INIT_FROM_OWNER(&sender->owned_names); |
| 2573 |
Peer *receiver; |
| 2574 |
Name *name; |
| 2575 |
int r; |
| 2576 |
|
| 2577 |
receiver = bus_find_peer_by_name(sender->bus, &name, destination); |
| 2578 |
if (!receiver) { |
| 2579 |
if (message->metadata.header.flags & DBUS_HEADER_FLAG_NO_AUTO_START) |
| 2580 |
return DRIVER_E_DESTINATION_NOT_FOUND; |
| 2581 |
if (!name || !name->activation) |
| 2582 |
return DRIVER_E_NAME_NOT_ACTIVATABLE; |
| 2583 |
|
| 2584 |
r = activation_queue_message(name->activation, sender->user, &sender->owned_names, sender->policy, message); |
| 2585 |
if (r) { |
| 2586 |
if (r == ACTIVATION_E_QUOTA) |
| 2587 |
return DRIVER_E_QUOTA; |
| 2588 |
|
| 2589 |
return error_fold(r); |
| 2590 |
} |
| 2591 |
|
| 2592 |
return 0; |
| 2593 |
} |
| 2594 |
|
| 2595 |
r = peer_queue_unicast(sender->policy, &sender_names, &sender->owned_replies, sender->user, sender->id, receiver, message); |
| 2596 |
if (r) { |
| 2597 |
if (r == PEER_E_EXPECTED_REPLY_EXISTS) |
| 2598 |
return DRIVER_E_EXPECTED_REPLY_EXISTS; |
| 2599 |
else if (r == PEER_E_QUOTA) |
| 2600 |
return DRIVER_E_QUOTA; |
| 2601 |
else if (r == PEER_E_SEND_DENIED) |
| 2602 |
return DRIVER_E_SEND_DENIED; |
| 2603 |
else if (r == PEER_E_RECEIVE_DENIED) |
| 2604 |
return DRIVER_E_RECEIVE_DENIED; |
| 2605 |
else if (r == PEER_E_UNEXPECTED_FDS) |
| 2606 |
return DRIVER_E_UNEXPECTED_FDS; |
| 2607 |
else |
| 2608 |
return error_fold(r); |
| 2609 |
} |
| 2610 |
|
| 2611 |
return 0; |
| 2612 |
} |
| 2613 |
|
| 2614 |
static int driver_forward_broadcast(Peer *sender, Message *message) { |
| 2615 |
_c_cleanup_(c_list_flush) CList destinations = C_LIST_INIT(destinations); |
| 2616 |
NameSet sender_names = NAME_SET_INIT_FROM_OWNER(&sender->owned_names); |
| 2617 |
MatchOwner *match_owner; |
| 2618 |
int r; |
| 2619 |
|
| 2620 |
bus_get_broadcast_destinations(sender->bus, &destinations, &sender->sender_matches, sender, &message->metadata); |
| 2621 |
|
| 2622 |
while ((match_owner = c_list_first_entry(&destinations, MatchOwner, destinations_link))) { |
| 2623 |
Peer *receiver = c_container_of(match_owner, Peer, owned_matches); |
| 2624 |
NameSet receiver_names = NAME_SET_INIT_FROM_OWNER(&receiver->owned_names); |
| 2625 |
|
| 2626 |
c_list_unlink(&match_owner->destinations_link); |
| 2627 |
|
| 2628 |
r = policy_snapshot_check_send(sender->policy, |
| 2629 |
receiver->seclabel, |
| 2630 |
&receiver_names, |
| 2631 |
receiver->id, |
| 2632 |
message->metadata.fields.interface, |
| 2633 |
message->metadata.fields.member, |
| 2634 |
message->metadata.fields.path, |
| 2635 |
message->metadata.header.type, |
| 2636 |
true, |
| 2637 |
message->metadata.fields.unix_fds); |
| 2638 |
if (r) { |
| 2639 |
if (r == POLICY_E_ACCESS_DENIED || |
| 2640 |
r == POLICY_E_SELINUX_ACCESS_DENIED || |
| 2641 |
r == POLICY_E_APPARMOR_ACCESS_DENIED) |
| 2642 |
continue; |
| 2643 |
|
| 2644 |
return error_fold(r); |
| 2645 |
} |
| 2646 |
|
| 2647 |
r = policy_snapshot_check_receive(receiver->policy, |
| 2648 |
sender->seclabel, |
| 2649 |
&sender_names, |
| 2650 |
sender->id, |
| 2651 |
message->metadata.fields.interface, |
| 2652 |
message->metadata.fields.member, |
| 2653 |
message->metadata.fields.path, |
| 2654 |
message->metadata.header.type, |
| 2655 |
true, |
| 2656 |
message->metadata.fields.unix_fds); |
| 2657 |
if (r) { |
| 2658 |
if (r == POLICY_E_ACCESS_DENIED || |
| 2659 |
r == POLICY_E_SELINUX_ACCESS_DENIED || |
| 2660 |
r == POLICY_E_APPARMOR_ACCESS_DENIED) |
| 2661 |
continue; |
| 2662 |
|
| 2663 |
return error_fold(r); |
| 2664 |
} |
| 2665 |
|
| 2666 |
r = connection_queue(&receiver->connection, NULL, message); |
| 2667 |
if (r) { |
| 2668 |
if (r == CONNECTION_E_QUOTA || r == CONNECTION_E_UNEXPECTED_FDS) { |
| 2669 |
connection_shutdown(&receiver->connection); |
| 2670 |
|
| 2671 |
log_append_here(sender->bus->log, LOG_WARNING, 0, DBUS_BROKER_CATALOG_RECEIVE_FAILED); |
| 2672 |
bus_log_append_transaction(sender->bus, sender->id, receiver->id, &sender_names, &receiver_names, |
| 2673 |
sender->policy->seclabel, receiver->policy->seclabel, |
| 2674 |
message); |
| 2675 |
if (r == CONNECTION_E_QUOTA) |
| 2676 |
r = log_commitf(sender->bus->log, "Peer :1.%llu is being disconnected as it does not have the resources to receive a signal it subscribed to.", receiver->id); |
| 2677 |
else |
| 2678 |
r = log_commitf(sender->bus->log, "Peer :1.%llu is being disconnected as it does not support receiving the file descriptors it subscribed to.", receiver->id); |
| 2679 |
if (r) |
| 2680 |
return error_fold(r); |
| 2681 |
} else { |
| 2682 |
return error_fold(r); |
| 2683 |
} |
| 2684 |
} |
| 2685 |
} |
| 2686 |
|
| 2687 |
return 0; |
| 2688 |
} |
| 2689 |
|
| 2690 |
static int driver_dispatch_internal(Peer *peer, Message *message) { |
| 2691 |
int r; |
| 2692 |
|
| 2693 |
r = driver_monitor(peer->bus, peer, message); |
| 2694 |
if (r) |
| 2695 |
return error_trace(r); |
| 2696 |
|
| 2697 |
if (_c_unlikely_(message->metadata.header.type == DBUS_MESSAGE_TYPE_METHOD_CALL && |
| 2698 |
!message->metadata.fields.destination)) { |
| 2699 |
/* |
| 2700 |
* The empty destination is treated as a special peer, only implementing the Peer |
| 2701 |
* interface. |
| 2702 |
*/ |
| 2703 |
if (message->metadata.fields.interface && |
| 2704 |
strcmp(message->metadata.fields.interface, "org.freedesktop.DBus.Peer") != 0) |
| 2705 |
return DRIVER_E_UNEXPECTED_METHOD; |
| 2706 |
|
| 2707 |
return error_trace(driver_dispatch_method(peer, |
| 2708 |
peer_methods, |
| 2709 |
message_read_serial(message), |
| 2710 |
message->metadata.fields.member, |
| 2711 |
message->metadata.fields.path, |
| 2712 |
message->metadata.fields.signature, |
| 2713 |
message)); |
| 2714 |
} |
| 2715 |
|
| 2716 |
if (string_equal(message->metadata.fields.destination, "org.freedesktop.DBus")) { |
| 2717 |
r = driver_dispatch_interface(peer, |
| 2718 |
message_read_serial(message), |
| 2719 |
message->metadata.fields.interface, |
| 2720 |
message->metadata.fields.member, |
| 2721 |
message->metadata.fields.path, |
| 2722 |
message->metadata.fields.signature, |
| 2723 |
message); |
| 2724 |
if (r) { |
| 2725 |
if (_c_unlikely_(!peer_is_registered(peer)) && |
| 2726 |
(r == DRIVER_E_UNEXPECTED_INTERFACE || |
| 2727 |
r == DRIVER_E_UNEXPECTED_METHOD)) |
| 2728 |
return DRIVER_E_PEER_NOT_YET_REGISTERED; |
| 2729 |
|
| 2730 |
return error_trace(r); |
| 2731 |
} |
| 2732 |
|
| 2733 |
return 0; |
| 2734 |
} |
| 2735 |
|
| 2736 |
if (!peer_is_registered(peer)) |
| 2737 |
return DRIVER_E_PEER_NOT_REGISTERED; |
| 2738 |
|
| 2739 |
if (!message->metadata.fields.destination) { |
| 2740 |
if (message->metadata.header.type == DBUS_MESSAGE_TYPE_SIGNAL) { |
| 2741 |
r = driver_forward_broadcast(peer, message); |
| 2742 |
if (r) |
| 2743 |
return error_trace(r); |
| 2744 |
|
| 2745 |
return 0; |
| 2746 |
} else { |
| 2747 |
return DRIVER_E_UNEXPECTED_MESSAGE_TYPE; |
| 2748 |
} |
| 2749 |
} |
| 2750 |
|
| 2751 |
switch (message->metadata.header.type) { |
| 2752 |
case DBUS_MESSAGE_TYPE_SIGNAL: |
| 2753 |
case DBUS_MESSAGE_TYPE_METHOD_CALL: |
| 2754 |
return error_trace(driver_forward_unicast(peer, |
| 2755 |
message->metadata.fields.destination, |
| 2756 |
message)); |
| 2757 |
case DBUS_MESSAGE_TYPE_METHOD_RETURN: |
| 2758 |
case DBUS_MESSAGE_TYPE_ERROR: |
| 2759 |
r = peer_queue_reply(peer, |
| 2760 |
message->metadata.fields.destination, |
| 2761 |
message->metadata.fields.reply_serial, |
| 2762 |
message); |
| 2763 |
if (r == PEER_E_UNEXPECTED_REPLY) |
| 2764 |
return DRIVER_E_UNEXPECTED_REPLY; |
| 2765 |
else |
| 2766 |
return error_fold(r); |
| 2767 |
default: |
| 2768 |
return DRIVER_E_UNEXPECTED_MESSAGE_TYPE; |
| 2769 |
} |
| 2770 |
} |
| 2771 |
|
| 2772 |
int driver_dispatch(Peer *peer, Message *message) { |
| 2773 |
int r; |
| 2774 |
|
| 2775 |
if (peer_is_monitor(peer)) |
| 2776 |
return DRIVER_E_MONITOR_READ_ONLY; |
| 2777 |
|
| 2778 |
r = driver_dispatch_internal(peer, message); |
| 2779 |
switch (r) { |
| 2780 |
case DRIVER_E_PEER_NOT_REGISTERED: |
| 2781 |
return r; |
| 2782 |
case DRIVER_E_UNIMPLEMENTED: |
| 2783 |
case DRIVER_E_PEER_ALREADY_REGISTERED: |
| 2784 |
case DRIVER_E_UNEXPECTED_FDS: |
| 2785 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.Failed", driver_error_to_string(r)); |
| 2786 |
break; |
| 2787 |
case DRIVER_E_PEER_NOT_YET_REGISTERED: |
| 2788 |
case DRIVER_E_UNEXPECTED_PATH: |
| 2789 |
case DRIVER_E_UNEXPECTED_MESSAGE_TYPE: |
| 2790 |
case DRIVER_E_UNEXPECTED_REPLY: |
| 2791 |
case DRIVER_E_UNEXPECTED_ENVIRONMENT_UPDATE: |
| 2792 |
case DRIVER_E_EXPECTED_REPLY_EXISTS: |
| 2793 |
case DRIVER_E_SEND_DENIED: |
| 2794 |
case DRIVER_E_RECEIVE_DENIED: |
| 2795 |
case DRIVER_E_PEER_NOT_PRIVILEGED: |
| 2796 |
case DRIVER_E_NAME_REFUSED: |
| 2797 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.AccessDenied", driver_error_to_string(r)); |
| 2798 |
break; |
| 2799 |
case DRIVER_E_UNEXPECTED_INTERFACE: |
| 2800 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.UnknownInterface", driver_error_to_string(r)); |
| 2801 |
break; |
| 2802 |
case DRIVER_E_UNEXPECTED_METHOD: |
| 2803 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.UnknownMethod", driver_error_to_string(r)); |
| 2804 |
break; |
| 2805 |
case DRIVER_E_UNEXPECTED_PROPERTY: |
| 2806 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.UnknownProperty", driver_error_to_string(r)); |
| 2807 |
break; |
| 2808 |
case DRIVER_E_READONLY_PROPERTY: |
| 2809 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.PropertyReadOnly", driver_error_to_string(r)); |
| 2810 |
break; |
| 2811 |
case DRIVER_E_UNEXPECTED_SIGNATURE: |
| 2812 |
case DRIVER_E_UNEXPECTED_FLAGS: |
| 2813 |
case DRIVER_E_NAME_RESERVED: |
| 2814 |
case DRIVER_E_NAME_UNIQUE: |
| 2815 |
case DRIVER_E_NAME_INVALID: |
| 2816 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.InvalidArgs", driver_error_to_string(r)); |
| 2817 |
break; |
| 2818 |
case DRIVER_E_FORWARD_FAILED: |
| 2819 |
case DRIVER_E_QUOTA: |
| 2820 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.LimitsExceeded", driver_error_to_string(r)); |
| 2821 |
break; |
| 2822 |
case DRIVER_E_PEER_NOT_FOUND: |
| 2823 |
case DRIVER_E_NAME_NOT_FOUND: |
| 2824 |
case DRIVER_E_NAME_OWNER_NOT_FOUND: |
| 2825 |
case DRIVER_E_DESTINATION_NOT_FOUND: |
| 2826 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.NameHasNoOwner", driver_error_to_string(r)); |
| 2827 |
break; |
| 2828 |
case DRIVER_E_NAME_NOT_ACTIVATABLE: |
| 2829 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.ServiceUnknown", driver_error_to_string(r)); |
| 2830 |
break; |
| 2831 |
case DRIVER_E_MATCH_INVALID: |
| 2832 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.MatchRuleInvalid", driver_error_to_string(r)); |
| 2833 |
break; |
| 2834 |
case DRIVER_E_MATCH_NOT_FOUND: |
| 2835 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.MatchRuleNotFound", driver_error_to_string(r)); |
| 2836 |
break; |
| 2837 |
case DRIVER_E_ADT_NOT_SUPPORTED: |
| 2838 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.AdtAuditDataUnknown", driver_error_to_string(r)); |
| 2839 |
break; |
| 2840 |
case DRIVER_E_SELINUX_NOT_SUPPORTED: |
| 2841 |
r = driver_send_error(peer, message_read_serial(message), "org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown", driver_error_to_string(r)); |
| 2842 |
break; |
| 2843 |
default: |
| 2844 |
break; |
| 2845 |
} |
| 2846 |
|
| 2847 |
return error_trace(r); |
| 2848 |
} |