Skip to content

Commit c7db198

Browse files
committed
sd-bus: get rid of kdbus flags cruft
We only need three bits from the old kdbus flags cruft, hence let's make them proper booleans.
1 parent 56d820b commit c7db198

File tree

7 files changed

+25
-152
lines changed

7 files changed

+25
-152
lines changed

src/libsystemd/sd-bus/bus-control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ _public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **r
631631
}
632632

633633
#define internal_match(bus, m) \
634-
((bus)->hello_flags & KDBUS_HELLO_MONITOR \
634+
((bus)->is_monitor \
635635
? (isempty(m) ? "eavesdrop='true'" : strjoina((m), ",eavesdrop='true'")) \
636636
: (m))
637637

src/libsystemd/sd-bus/bus-internal.h

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ struct sd_bus {
213213
bool exit_triggered:1;
214214
bool is_local:1;
215215
bool watch_bind:1;
216+
bool is_monitor:1;
217+
bool accept_fd:1;
218+
bool attach_timestamp:1;
216219

217220
int use_memfd;
218221

@@ -289,9 +292,6 @@ struct sd_bus {
289292

290293
pid_t original_pid;
291294

292-
uint64_t hello_flags;
293-
uint64_t attach_flags;
294-
295295
sd_event_source *input_io_event_source;
296296
sd_event_source *output_io_event_source;
297297
sd_event_source *time_event_source;
@@ -407,65 +407,3 @@ int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error);
407407
if (!assert_log(expr, #expr)) \
408408
return sd_bus_error_set_errno(error, r); \
409409
} while (false)
410-
411-
/**
412-
* enum kdbus_attach_flags - flags for metadata attachments
413-
* @KDBUS_ATTACH_TIMESTAMP: Timestamp
414-
* @KDBUS_ATTACH_CREDS: Credentials
415-
* @KDBUS_ATTACH_PIDS: PIDs
416-
* @KDBUS_ATTACH_AUXGROUPS: Auxiliary groups
417-
* @KDBUS_ATTACH_NAMES: Well-known names
418-
* @KDBUS_ATTACH_TID_COMM: The "comm" process identifier of the TID
419-
* @KDBUS_ATTACH_PID_COMM: The "comm" process identifier of the PID
420-
* @KDBUS_ATTACH_EXE: The path of the executable
421-
* @KDBUS_ATTACH_CMDLINE: The process command line
422-
* @KDBUS_ATTACH_CGROUP: The croup membership
423-
* @KDBUS_ATTACH_CAPS: The process capabilities
424-
* @KDBUS_ATTACH_SECLABEL: The security label
425-
* @KDBUS_ATTACH_AUDIT: The audit IDs
426-
* @KDBUS_ATTACH_CONN_DESCRIPTION: The human-readable connection name
427-
* @_KDBUS_ATTACH_ALL: All of the above
428-
* @_KDBUS_ATTACH_ANY: Wildcard match to enable any kind of
429-
* metatdata.
430-
*/
431-
enum kdbus_attach_flags {
432-
KDBUS_ATTACH_TIMESTAMP = 1ULL << 0,
433-
KDBUS_ATTACH_CREDS = 1ULL << 1,
434-
KDBUS_ATTACH_PIDS = 1ULL << 2,
435-
KDBUS_ATTACH_AUXGROUPS = 1ULL << 3,
436-
KDBUS_ATTACH_NAMES = 1ULL << 4,
437-
KDBUS_ATTACH_TID_COMM = 1ULL << 5,
438-
KDBUS_ATTACH_PID_COMM = 1ULL << 6,
439-
KDBUS_ATTACH_EXE = 1ULL << 7,
440-
KDBUS_ATTACH_CMDLINE = 1ULL << 8,
441-
KDBUS_ATTACH_CGROUP = 1ULL << 9,
442-
KDBUS_ATTACH_CAPS = 1ULL << 10,
443-
KDBUS_ATTACH_SECLABEL = 1ULL << 11,
444-
KDBUS_ATTACH_AUDIT = 1ULL << 12,
445-
KDBUS_ATTACH_CONN_DESCRIPTION = 1ULL << 13,
446-
_KDBUS_ATTACH_ALL = (1ULL << 14) - 1,
447-
_KDBUS_ATTACH_ANY = ~0ULL
448-
};
449-
450-
/**
451-
* enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
452-
* @KDBUS_HELLO_ACCEPT_FD: The connection allows the reception of
453-
* any passed file descriptors
454-
* @KDBUS_HELLO_ACTIVATOR: Special-purpose connection which registers
455-
* a well-know name for a process to be started
456-
* when traffic arrives
457-
* @KDBUS_HELLO_POLICY_HOLDER: Special-purpose connection which registers
458-
* policy entries for a name. The provided name
459-
* is not activated and not registered with the
460-
* name database, it only allows unprivileged
461-
* connections to acquire a name, talk or discover
462-
* a service
463-
* @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
464-
* bus traffic
465-
*/
466-
enum kdbus_hello_flags {
467-
KDBUS_HELLO_ACCEPT_FD = 1ULL << 0,
468-
KDBUS_HELLO_ACTIVATOR = 1ULL << 1,
469-
KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2,
470-
KDBUS_HELLO_MONITOR = 1ULL << 3,
471-
};

src/libsystemd/sd-bus/bus-kernel.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -66,49 +66,3 @@ void bus_flush_memfd(sd_bus *b) {
6666
for (i = 0; i < b->n_memfd_cache; i++)
6767
close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped);
6868
}
69-
70-
uint64_t attach_flags_to_kdbus(uint64_t mask) {
71-
uint64_t m = 0;
72-
73-
if (mask & (SD_BUS_CREDS_UID|SD_BUS_CREDS_EUID|SD_BUS_CREDS_SUID|SD_BUS_CREDS_FSUID|
74-
SD_BUS_CREDS_GID|SD_BUS_CREDS_EGID|SD_BUS_CREDS_SGID|SD_BUS_CREDS_FSGID))
75-
m |= KDBUS_ATTACH_CREDS;
76-
77-
if (mask & (SD_BUS_CREDS_PID|SD_BUS_CREDS_TID|SD_BUS_CREDS_PPID))
78-
m |= KDBUS_ATTACH_PIDS;
79-
80-
if (mask & SD_BUS_CREDS_COMM)
81-
m |= KDBUS_ATTACH_PID_COMM;
82-
83-
if (mask & SD_BUS_CREDS_TID_COMM)
84-
m |= KDBUS_ATTACH_TID_COMM;
85-
86-
if (mask & SD_BUS_CREDS_EXE)
87-
m |= KDBUS_ATTACH_EXE;
88-
89-
if (mask & SD_BUS_CREDS_CMDLINE)
90-
m |= KDBUS_ATTACH_CMDLINE;
91-
92-
if (mask & (SD_BUS_CREDS_CGROUP|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_USER_UNIT|SD_BUS_CREDS_SLICE|SD_BUS_CREDS_SESSION|SD_BUS_CREDS_OWNER_UID))
93-
m |= KDBUS_ATTACH_CGROUP;
94-
95-
if (mask & (SD_BUS_CREDS_EFFECTIVE_CAPS|SD_BUS_CREDS_PERMITTED_CAPS|SD_BUS_CREDS_INHERITABLE_CAPS|SD_BUS_CREDS_BOUNDING_CAPS))
96-
m |= KDBUS_ATTACH_CAPS;
97-
98-
if (mask & SD_BUS_CREDS_SELINUX_CONTEXT)
99-
m |= KDBUS_ATTACH_SECLABEL;
100-
101-
if (mask & (SD_BUS_CREDS_AUDIT_SESSION_ID|SD_BUS_CREDS_AUDIT_LOGIN_UID))
102-
m |= KDBUS_ATTACH_AUDIT;
103-
104-
if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES)
105-
m |= KDBUS_ATTACH_NAMES;
106-
107-
if (mask & SD_BUS_CREDS_DESCRIPTION)
108-
m |= KDBUS_ATTACH_CONN_DESCRIPTION;
109-
110-
if (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS)
111-
m |= KDBUS_ATTACH_AUXGROUPS;
112-
113-
return m;
114-
}

src/libsystemd/sd-bus/bus-kernel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,3 @@ struct memfd_cache {
4141

4242
void close_and_munmap(int fd, void *address, size_t size);
4343
void bus_flush_memfd(sd_bus *bus);
44-
45-
uint64_t attach_flags_to_kdbus(uint64_t sd_bus_flags);

src/libsystemd/sd-bus/bus-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ int bus_process_object(sd_bus *bus, sd_bus_message *m) {
13691369
assert(bus);
13701370
assert(m);
13711371

1372-
if (bus->hello_flags & KDBUS_HELLO_MONITOR)
1372+
if (bus->is_monitor)
13731373
return 0;
13741374

13751375
if (m->header->type != SD_BUS_MESSAGE_METHOD_CALL)

src/libsystemd/sd-bus/bus-socket.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static int bus_socket_auth_verify_client(sd_bus *b) {
191191
if (!e)
192192
return 0;
193193

194-
if (b->hello_flags & KDBUS_HELLO_ACCEPT_FD) {
194+
if (b->accept_fd) {
195195
f = memmem(e + 2, b->rbuffer_size - (e - (char*) b->rbuffer) - 2, "\r\n", 2);
196196
if (!f)
197197
return 0;
@@ -478,7 +478,7 @@ static int bus_socket_auth_verify_server(sd_bus *b) {
478478
r = bus_socket_auth_write_ok(b);
479479
}
480480
} else if (line_equals(line, l, "NEGOTIATE_UNIX_FD")) {
481-
if (b->auth == _BUS_AUTH_INVALID || !(b->hello_flags & KDBUS_HELLO_ACCEPT_FD))
481+
if (b->auth == _BUS_AUTH_INVALID || !b->accept_fd)
482482
r = bus_socket_auth_write(b, "ERROR\r\n");
483483
else {
484484
b->can_fds = true;
@@ -655,7 +655,7 @@ static int bus_socket_start_auth_client(sd_bus *b) {
655655
if (!b->auth_buffer)
656656
return -ENOMEM;
657657

658-
if (b->hello_flags & KDBUS_HELLO_ACCEPT_FD)
658+
if (b->accept_fd)
659659
auth_suffix = "\r\nNEGOTIATE_UNIX_FD\r\nBEGIN\r\n";
660660
else
661661
auth_suffix = "\r\nBEGIN\r\n";
@@ -679,11 +679,11 @@ int bus_socket_start_auth(sd_bus *b) {
679679
b->auth_timeout = now(CLOCK_MONOTONIC) + BUS_AUTH_TIMEOUT;
680680

681681
if (sd_is_socket(b->input_fd, AF_UNIX, 0, 0) <= 0)
682-
b->hello_flags &= ~KDBUS_HELLO_ACCEPT_FD;
682+
b->accept_fd = false;
683683

684684
if (b->output_fd != b->input_fd)
685685
if (sd_is_socket(b->output_fd, AF_UNIX, 0, 0) <= 0)
686-
b->hello_flags &= ~KDBUS_HELLO_ACCEPT_FD;
686+
b->accept_fd = false;
687687

688688
if (b->is_server)
689689
return bus_socket_read_auth(b);

src/libsystemd/sd-bus/sd-bus.c

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ _public_ int sd_bus_new(sd_bus **ret) {
196196
r->inotify_fd = -1;
197197
r->message_version = 1;
198198
r->creds_mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME;
199-
r->hello_flags |= KDBUS_HELLO_ACCEPT_FD;
200-
r->attach_flags |= KDBUS_ATTACH_NAMES;
199+
r->accept_fd = true;
201200
r->original_pid = getpid_cached();
202201
r->n_groups = (size_t) -1;
203202

@@ -286,7 +285,7 @@ _public_ int sd_bus_set_monitor(sd_bus *bus, int b) {
286285
assert_return(bus->state == BUS_UNSET, -EPERM);
287286
assert_return(!bus_pid_changed(bus), -ECHILD);
288287

289-
SET_FLAG(bus->hello_flags, KDBUS_HELLO_MONITOR, b);
288+
bus->is_monitor = b;
290289
return 0;
291290
}
292291

@@ -295,30 +294,23 @@ _public_ int sd_bus_negotiate_fds(sd_bus *bus, int b) {
295294
assert_return(bus->state == BUS_UNSET, -EPERM);
296295
assert_return(!bus_pid_changed(bus), -ECHILD);
297296

298-
SET_FLAG(bus->hello_flags, KDBUS_HELLO_ACCEPT_FD, b);
297+
bus->accept_fd = b;
299298
return 0;
300299
}
301300

302301
_public_ int sd_bus_negotiate_timestamp(sd_bus *bus, int b) {
303-
uint64_t new_flags;
304302
assert_return(bus, -EINVAL);
305303
assert_return(!IN_SET(bus->state, BUS_CLOSING, BUS_CLOSED), -EPERM);
306304
assert_return(!bus_pid_changed(bus), -ECHILD);
307305

308-
new_flags = bus->attach_flags;
309-
SET_FLAG(new_flags, KDBUS_ATTACH_TIMESTAMP, b);
310-
311-
if (bus->attach_flags == new_flags)
312-
return 0;
313-
314-
bus->attach_flags = new_flags;
306+
/* This is not actually supported by any of our transports these days, but we do honour it for synthetic
307+
* replies, and maybe one day classic D-Bus learns this too */
308+
bus->attach_timestamp = b;
315309

316310
return 0;
317311
}
318312

319313
_public_ int sd_bus_negotiate_creds(sd_bus *bus, int b, uint64_t mask) {
320-
uint64_t new_flags;
321-
322314
assert_return(bus, -EINVAL);
323315
assert_return(mask <= _SD_BUS_CREDS_ALL, -EINVAL);
324316
assert_return(!IN_SET(bus->state, BUS_CLOSING, BUS_CLOSED), -EPERM);
@@ -329,13 +321,6 @@ _public_ int sd_bus_negotiate_creds(sd_bus *bus, int b, uint64_t mask) {
329321
/* The well knowns we need unconditionally, so that matches can work */
330322
bus->creds_mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME;
331323

332-
/* Make sure we don't lose the timestamp flag */
333-
new_flags = (bus->attach_flags & KDBUS_ATTACH_TIMESTAMP) | attach_flags_to_kdbus(bus->creds_mask);
334-
if (bus->attach_flags == new_flags)
335-
return 0;
336-
337-
bus->attach_flags = new_flags;
338-
339324
return 0;
340325
}
341326

@@ -1094,7 +1079,6 @@ _public_ int sd_bus_open(sd_bus **ret) {
10941079
* be safe, and authenticate everything */
10951080
b->trusted = false;
10961081
b->is_local = false;
1097-
b->attach_flags |= KDBUS_ATTACH_CAPS | KDBUS_ATTACH_CREDS;
10981082
b->creds_mask |= SD_BUS_CREDS_UID | SD_BUS_CREDS_EUID | SD_BUS_CREDS_EFFECTIVE_CAPS;
10991083

11001084
r = sd_bus_start(b);
@@ -1140,7 +1124,6 @@ _public_ int sd_bus_open_system(sd_bus **ret) {
11401124
/* Let's do per-method access control on the system bus. We
11411125
* need the caller's UID and capability set for that. */
11421126
b->trusted = false;
1143-
b->attach_flags |= KDBUS_ATTACH_CAPS | KDBUS_ATTACH_CREDS;
11441127
b->creds_mask |= SD_BUS_CREDS_UID | SD_BUS_CREDS_EUID | SD_BUS_CREDS_EFFECTIVE_CAPS;
11451128
b->is_local = true;
11461129

@@ -1419,11 +1402,11 @@ _public_ int sd_bus_can_send(sd_bus *bus, char type) {
14191402
assert_return(bus->state != BUS_UNSET, -ENOTCONN);
14201403
assert_return(!bus_pid_changed(bus), -ECHILD);
14211404

1422-
if (bus->hello_flags & KDBUS_HELLO_MONITOR)
1405+
if (bus->is_monitor)
14231406
return 0;
14241407

14251408
if (type == SD_BUS_TYPE_UNIX_FD) {
1426-
if (!(bus->hello_flags & KDBUS_HELLO_ACCEPT_FD))
1409+
if (!bus->accept_fd)
14271410
return 0;
14281411

14291412
r = bus_ensure_running(bus);
@@ -1491,7 +1474,7 @@ int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) {
14911474

14921475
/* Fake some timestamps, if they were requested, and not
14931476
* already initialized */
1494-
if (b->attach_flags & KDBUS_ATTACH_TIMESTAMP) {
1477+
if (b->attach_timestamp) {
14951478
if (m->realtime <= 0)
14961479
m->realtime = now(CLOCK_REALTIME);
14971480

@@ -1936,7 +1919,7 @@ _public_ int sd_bus_call(
19361919

19371920
if (incoming->header->type == SD_BUS_MESSAGE_METHOD_RETURN) {
19381921

1939-
if (incoming->n_fds <= 0 || (bus->hello_flags & KDBUS_HELLO_ACCEPT_FD)) {
1922+
if (incoming->n_fds <= 0 || bus->accept_fd) {
19401923
if (reply)
19411924
*reply = incoming;
19421925
else
@@ -2262,7 +2245,7 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) {
22622245

22632246
slot = container_of(c, sd_bus_slot, reply_callback);
22642247

2265-
if (m->n_fds > 0 && !(bus->hello_flags & KDBUS_HELLO_ACCEPT_FD)) {
2248+
if (m->n_fds > 0 && !bus->accept_fd) {
22662249

22672250
/* If the reply contained a file descriptor which we
22682251
* didn't want we pass an error instead. */
@@ -2394,7 +2377,7 @@ static int process_builtin(sd_bus *bus, sd_bus_message *m) {
23942377
assert(bus);
23952378
assert(m);
23962379

2397-
if (bus->hello_flags & KDBUS_HELLO_MONITOR)
2380+
if (bus->is_monitor)
23982381
return 0;
23992382

24002383
if (bus->manual_peer_interface)
@@ -2452,13 +2435,13 @@ static int process_fd_check(sd_bus *bus, sd_bus_message *m) {
24522435
* delivered to us later even though we ourselves did not
24532436
* negotiate it. */
24542437

2455-
if (bus->hello_flags & KDBUS_HELLO_MONITOR)
2438+
if (bus->is_monitor)
24562439
return 0;
24572440

24582441
if (m->n_fds <= 0)
24592442
return 0;
24602443

2461-
if (bus->hello_flags & KDBUS_HELLO_ACCEPT_FD)
2444+
if (bus->accept_fd)
24622445
return 0;
24632446

24642447
if (m->header->type != SD_BUS_MESSAGE_METHOD_CALL)
@@ -3769,7 +3752,7 @@ _public_ int sd_bus_is_monitor(sd_bus *bus) {
37693752
assert_return(bus, -EINVAL);
37703753
assert_return(!bus_pid_changed(bus), -ECHILD);
37713754

3772-
return !!(bus->hello_flags & KDBUS_HELLO_MONITOR);
3755+
return bus->is_monitor;
37733756
}
37743757

37753758
static void flush_close(sd_bus *bus) {

0 commit comments

Comments
 (0)