khive-runtime 0.17.0

Composable Service API: entity/note CRUD, graph traversal, hybrid search, curation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
#[cfg(unix)]
use std::os::unix::fs::{MetadataExt, OpenOptionsExt, PermissionsExt};

#[cfg(unix)]
use std::os::unix::io::{AsRawFd, FromRawFd};

#[cfg(unix)]
use tokio::net::UnixStream;

#[cfg(unix)]
use super::{lock_path, recoverer_lock_path};

#[cfg(unix)]
pub(super) fn open_lock_file(path: &std::path::Path) -> std::io::Result<std::fs::File> {
    open_mutating_daemon_lock(path, false)
}

/// Open a lock for a mutating boot or recovery. The default directory may be
/// prepared; caller-specified parent directories must already be trusted.
#[cfg(unix)]
pub fn open_mutating_daemon_lock(
    path: &std::path::Path,
    read_write: bool,
) -> std::io::Result<std::fs::File> {
    let is_default_lock_parent = path.parent() == Some(super::khive_dir().as_path());
    if is_default_lock_parent {
        super::run_daemon::prepare_default_rendezvous_directory().map_err(lock_error)?;
    }
    // Preserve recursive creation for caller-selected lock locations. The
    // checked opener below still validates the resulting path before use.
    if !is_default_lock_parent {
        if let Some(parent) = path.parent() {
            let _ = std::fs::create_dir_all(parent);
        }
    }
    checked_open_lock(path, true, read_write, true)?
        .ok_or_else(|| std::io::Error::new(std::io::ErrorKind::NotFound, "created lock is absent"))
}

#[cfg(unix)]
fn lock_error(error: anyhow::Error) -> std::io::Error {
    std::io::Error::new(std::io::ErrorKind::PermissionDenied, format!("{error:#}"))
}

/// Open a basename relative to an ancestry-checked directory fd. Existing
/// locks can be tightened without allowing creation.
#[cfg(unix)]
pub(super) fn checked_open_lock(
    path: &std::path::Path,
    create: bool,
    read_write: bool,
    tighten: bool,
) -> std::io::Result<Option<std::fs::File>> {
    checked_open_lock_with_hooks(path, create, read_write, tighten, || {}, || {})
}

#[cfg(unix)]
pub(super) fn checked_open_lock_with_hooks(
    path: &std::path::Path,
    create: bool,
    read_write: bool,
    tighten: bool,
    before_openat: impl FnOnce(),
    after_open: impl FnOnce(),
) -> std::io::Result<Option<std::fs::File>> {
    checked_open_lock_with_faults(
        path,
        create,
        read_write,
        tighten,
        before_openat,
        after_open,
        (false, false),
    )
}

// Fault flags are used only by synthetic tests; production always passes false.
#[cfg(unix)]
pub(super) fn checked_open_lock_with_faults(
    path: &std::path::Path,
    create: bool,
    read_write: bool,
    tighten: bool,
    before_openat: impl FnOnce(),
    after_open: impl FnOnce(),
    faults: (bool, bool),
) -> std::io::Result<Option<std::fs::File>> {
    checked_open_lock_with_observe_hook(
        path,
        create,
        read_write,
        tighten,
        before_openat,
        after_open,
        (faults.0, faults.1, || {}),
    )
}

#[cfg(unix)]
pub(super) fn checked_open_lock_with_observe_hook(
    path: &std::path::Path,
    create: bool,
    read_write: bool,
    tighten: bool,
    before_openat: impl FnOnce(),
    after_open: impl FnOnce(),
    faults_and_observer: (bool, bool, impl FnOnce()),
) -> std::io::Result<Option<std::fs::File>> {
    use std::os::unix::ffi::OsStrExt;
    let (fail_metadata, fail_chmod, after_observe) = faults_and_observer;

    let parent = path
        .parent()
        .filter(|p| !p.as_os_str().is_empty())
        .unwrap_or_else(|| std::path::Path::new("."));
    let leaf = path.file_name().ok_or_else(|| {
        std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            "lock path has no basename",
        )
    })?;
    let leaf = std::ffi::CString::new(leaf.as_bytes()).map_err(|_| {
        std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            "lock basename contains NUL",
        )
    })?;
    let observed_parent = match std::fs::symlink_metadata(parent) {
        Ok(metadata) => metadata,
        Err(error) if !create && error.kind() == std::io::ErrorKind::NotFound => return Ok(None),
        Err(error) => {
            return Err(std::io::Error::new(
                error.kind(),
                format!("cannot inspect lock parent {}: {error}", parent.display()),
            ))
        }
    };
    super::ensure_pid_file_dir_is_trusted(path).map_err(lock_error)?;
    let directory = std::fs::OpenOptions::new()
        .read(true)
        .custom_flags(libc::O_DIRECTORY | libc::O_NOFOLLOW | libc::O_CLOEXEC)
        .open(parent)
        .map_err(|error| {
            std::io::Error::new(
                error.kind(),
                format!(
                    "refusing lock parent {} (mode {:04o}): {error}",
                    parent.display(),
                    observed_parent.mode() & 0o7777
                ),
            )
        })?;
    let opened_parent = directory.metadata()?;
    if !observed_parent.is_dir()
        || !opened_parent.is_dir()
        || observed_parent.dev() != opened_parent.dev()
        || observed_parent.ino() != opened_parent.ino()
    {
        return Err(std::io::Error::new(
            std::io::ErrorKind::PermissionDenied,
            "lock parent changed during open",
        ));
    }
    before_openat();
    let current_parent = std::fs::symlink_metadata(parent)?;
    if !current_parent.is_dir()
        || current_parent.dev() != opened_parent.dev()
        || current_parent.ino() != opened_parent.ino()
    {
        return Err(std::io::Error::new(
            std::io::ErrorKind::PermissionDenied,
            "lock parent changed before openat",
        ));
    }
    // SAFETY: `geteuid` takes no arguments and always succeeds.
    let uid = unsafe { libc::geteuid() } as u32;
    let mut observed = match std::fs::symlink_metadata(path) {
        Ok(metadata) => {
            if !metadata.is_file() || metadata.uid() != uid || metadata.nlink() != 1 {
                return Err(std::io::Error::new(
                    std::io::ErrorKind::PermissionDenied,
                    format!(
                        "refusing lock {}: owner uid {}, mode {:04o}",
                        path.display(),
                        metadata.uid(),
                        metadata.mode() & 0o7777
                    ),
                ));
            }
            Some(metadata)
        }
        Err(error) if error.kind() == std::io::ErrorKind::NotFound => None,
        Err(error) => return Err(error),
    };
    if observed.is_none() && !create {
        return Ok(None);
    }
    after_observe();
    let access = if read_write {
        libc::O_RDWR
    } else if tighten && !create {
        libc::O_RDONLY
    } else if create {
        libc::O_WRONLY
    } else {
        libc::O_RDONLY
    };
    let mut flags = access | libc::O_NOFOLLOW | libc::O_NONBLOCK | libc::O_CLOEXEC;
    let mut created = observed.is_none();
    if created {
        flags |= libc::O_CREAT | libc::O_EXCL;
    }
    // SAFETY: the parent fd is live, and leaf is a NUL-terminated basename.
    let mut fd = unsafe { libc::openat(directory.as_raw_fd(), leaf.as_ptr(), flags, 0o600) };
    if fd < 0
        && created
        && std::io::Error::last_os_error().kind() == std::io::ErrorKind::AlreadyExists
    {
        // Another opener created the lock after our absence observation. Retry
        // once as an existing entry, retaining all no-follow and identity checks.
        let metadata = std::fs::symlink_metadata(path)?;
        if !metadata.is_file() || metadata.uid() != uid || metadata.nlink() != 1 {
            return Err(std::io::Error::new(
                std::io::ErrorKind::PermissionDenied,
                format!(
                    "refusing lock {}: owner uid {}, mode {:04o}",
                    path.display(),
                    metadata.uid(),
                    metadata.mode() & 0o7777
                ),
            ));
        }
        observed = Some(metadata);
        created = false;
        flags &= !(libc::O_CREAT | libc::O_EXCL);
        // SAFETY: the validated directory descriptor and basename remain live.
        fd = unsafe { libc::openat(directory.as_raw_fd(), leaf.as_ptr(), flags, 0o600) };
    }
    if fd < 0
        && !create
        && tighten
        && !read_write
        && std::io::Error::last_os_error().kind() == std::io::ErrorKind::PermissionDenied
    {
        flags = (flags & !libc::O_ACCMODE) | libc::O_WRONLY;
        // SAFETY: the same validated parent fd and basename remain live.
        fd = unsafe { libc::openat(directory.as_raw_fd(), leaf.as_ptr(), flags, 0o600) };
    }
    if fd < 0 {
        let error = std::io::Error::last_os_error();
        let observed_mode = observed
            .as_ref()
            .map(|metadata| format!("{:04o}", metadata.mode() & 0o7777))
            .unwrap_or_else(|| "absent".to_owned());
        return Err(std::io::Error::new(
            error.kind(),
            format!(
                "cannot safely open lock {} (observed mode {observed_mode}): {error}",
                path.display()
            ),
        ));
    }
    // SAFETY: `openat` returned a new owned file descriptor.
    let file = unsafe { std::fs::File::from_raw_fd(fd) };
    let identity_changed = std::cell::Cell::new(false);
    let result = (|| -> std::io::Result<()> {
        if fail_metadata {
            return Err(std::io::Error::other("injected metadata failure"));
        }
        let opened = file.metadata()?;
        if !opened.is_file()
            || opened.uid() != uid
            || opened.nlink() != 1
            || observed.as_ref().is_some_and(|metadata| {
                metadata.dev() != opened.dev() || metadata.ino() != opened.ino()
            })
        {
            identity_changed.set(true);
            return Err(std::io::Error::new(
                std::io::ErrorKind::PermissionDenied,
                format!(
                    "lock {} changed during open (mode {:04o})",
                    path.display(),
                    opened.mode() & 0o7777
                ),
            ));
        }
        after_open();
        let check_identity = || -> std::io::Result<()> {
            let current_parent = std::fs::symlink_metadata(parent)?;
            let current_lock = std::fs::symlink_metadata(path)?;
            if !current_parent.is_dir()
                || current_parent.dev() != opened_parent.dev()
                || current_parent.ino() != opened_parent.ino()
                || !current_lock.is_file()
                || current_lock.dev() != opened.dev()
                || current_lock.ino() != opened.ino()
            {
                return Err(std::io::Error::new(
                    std::io::ErrorKind::PermissionDenied,
                    "lock or parent changed during open",
                ));
            }
            Ok(())
        };
        check_identity().inspect_err(|_| {
            identity_changed.set(true);
        })?;
        if tighten {
            let latest = file.metadata()?;
            if !latest.is_file() || latest.uid() != uid || latest.nlink() != 1 {
                identity_changed.set(true);
                return Err(std::io::Error::new(
                    std::io::ErrorKind::PermissionDenied,
                    "lock ownership changed",
                ));
            }
            let mode = latest.mode() & 0o7777;
            let target = if created { 0o600 } else { mode & 0o600 };
            if target != mode {
                if fail_chmod {
                    return Err(std::io::Error::other("injected chmod failure"));
                }
                file.set_permissions(std::fs::Permissions::from_mode(target))?;
            }
        }
        check_identity().inspect_err(|_| {
            identity_changed.set(true);
        })?;
        Ok(())
    })();
    if let Err(error) = result {
        if created {
            let guidance = if identity_changed.get() {
                "the lock path or its parent changed; inspect the path and do not remove the replacement"
            } else {
                "after confirming no daemon is running and verifying the entry is the leftover lock, remove it and retry; do not remove an unverified entry"
            };
            return Err(std::io::Error::new(
                error.kind(),
                format!(
                    "failed to finish creating lock {}: {error}; {guidance}",
                    path.display()
                ),
            ));
        }
        return Err(error);
    }
    Ok(Some(file))
}

#[cfg(unix)]
fn acquire_flock_blocking(path: &std::path::Path, label: &str) -> Option<std::fs::File> {
    let file = match open_lock_file(path) {
        Ok(f) => f,
        Err(e) => {
            tracing::warn!(target: "khive_runtime::daemon", error = %e, path = ?path, "cannot open {label} lock file");
            return None;
        }
    };
    // SAFETY: flock is a POSIX advisory lock with no memory side-effects.
    let rc = unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX) };
    if rc != 0 {
        tracing::warn!(target: "khive_runtime::daemon", "flock LOCK_EX failed on {label} lock");
        return None;
    }
    Some(file)
}

/// Acquire an exclusive advisory flock on the recovery/startup lock file.
///
/// The returned `File` holds the lock for its lifetime; dropping it releases
/// it.  Used by both the client (serializing kill+spawn) and the daemon server
/// (serializing cleanup+bind+pid-write) so the two critical sections are
/// mutually exclusive across processes.
#[cfg(unix)]
pub fn acquire_recovery_lock() -> Option<std::fs::File> {
    acquire_flock_blocking(&lock_path(), "recovery")
}

/// Attempt to acquire an exclusive advisory flock on `path`, retrying with a
/// non-blocking `flock(LOCK_NB)` until `deadline` elapses. Bounded alternative
/// to `acquire_recovery_lock`/`acquire_daemon_boot_guard`'s unbounded blocking
/// flock — see `docs/api/daemon.md#try_acquire_flock_until` for why a caller
/// merely detecting lock freedom needs a deadline instead.
///
/// - `Ok(Some(file))` — the lock was free within the deadline.
/// - `Ok(None)` — `deadline` elapsed while the lock stayed held; an explicit
///   "could not confirm" outcome, distinct from a hard I/O error.
/// - `Err(_)` — the lock file could not be opened, or `flock` failed for a
///   reason other than contention.
///
/// Blocking (paces retries with `std::thread::sleep`) — async callers must
/// run this via `spawn_blocking`.
#[cfg(unix)]
fn try_acquire_flock_until(
    path: &std::path::Path,
    deadline: std::time::Instant,
) -> std::io::Result<Option<std::fs::File>> {
    let file = open_lock_file(path)?;
    let poll_interval = std::time::Duration::from_millis(10);
    loop {
        // SAFETY: flock is a POSIX advisory lock with no memory side-effects.
        let rc = unsafe { libc::flock(file.as_raw_fd(), libc::LOCK_EX | libc::LOCK_NB) };
        if rc == 0 {
            return Ok(Some(file));
        }
        let err = std::io::Error::last_os_error();
        if err.raw_os_error() != Some(libc::EWOULDBLOCK) {
            return Err(err);
        }
        let now = std::time::Instant::now();
        if now >= deadline {
            return Ok(None);
        }
        std::thread::sleep(poll_interval.min(deadline - now));
    }
}

/// Bounded, deadline-aware variant of [`acquire_daemon_boot_guard`]: attempts
/// the SAME boot/recovery lock ([`lock_path`]) but gives up at `deadline`
/// instead of blocking forever. For callers that need to detect "is a boot in
/// progress right now" without risking an unbounded wait behind a wedged
/// holder: e.g. khive-mcp's `confirm_genuinely_dead` re-probing rounds,
/// where `DEAD_CONFIRM_ROUNDS` must bound elapsed time, not just probe count.
#[cfg(unix)]
pub fn try_acquire_daemon_boot_guard_until(
    deadline: std::time::Instant,
) -> std::io::Result<Option<DaemonBootGuard>> {
    try_acquire_flock_until(&lock_path(), deadline)
}

/// Bounded, deadline-aware acquisition of the recoverer-only lock
/// ([`recoverer_lock_path`]). See [`try_acquire_daemon_boot_guard_until`] for
/// the shared rationale — a second recoverer waiting for a peer's dead
/// confirmation/kill/spawn critical section must give up and report
/// "uncertain" rather than block forever if that peer is itself wedged.
#[cfg(unix)]
pub fn try_acquire_recoverer_lock_until(
    deadline: std::time::Instant,
) -> std::io::Result<Option<std::fs::File>> {
    try_acquire_flock_until(&recoverer_lock_path(), deadline)
}

/// Guard returned by [`acquire_daemon_boot_guard`], held across cold-boot
/// schema initialization (migrations + pack schema plans / FTS DDL) through
/// daemon bind + pid-write.
#[cfg(unix)]
pub type DaemonBootGuard = std::fs::File;

/// Acquire the recovery/boot lock, treating failure as fatal.
///
/// Unlike [`acquire_recovery_lock`] (best-effort, `None` on failure: used by
/// shutdown cleanup, where skipping unlink is safer than blocking forever),
/// daemon-mode boot must hold this lock across migrations/FTS DDL through
/// bind+pid-write. Silently continuing with no lock reopens the cold-boot FTS
/// race this guard exists to close, so callers that are about to run
/// daemon-mode boot (or wait for one to quiesce) must fail loudly instead of
/// proceeding unguarded.
#[cfg(unix)]
pub fn acquire_daemon_boot_guard() -> anyhow::Result<DaemonBootGuard> {
    let explicit_rendezvous = super::lifecycle::path_override(super::lifecycle::PID_PATH_ENV)
        .is_some()
        || super::lifecycle::path_override(super::lifecycle::SOCKET_PATH_ENV).is_some();
    if !explicit_rendezvous {
        super::run_daemon::prepare_default_rendezvous_directory().map_err(|error| {
            tracing::warn!(target: "khive_runtime::daemon", %error, "cannot prepare default daemon rendezvous");
            anyhow::anyhow!("failed to acquire daemon boot/recovery lock")
        })?;
    }
    acquire_recovery_lock()
        .ok_or_else(|| anyhow::anyhow!("failed to acquire daemon boot/recovery lock"))
}

/// Identity of a bound Unix socket path, used to tell "the socket I bound" apart
/// from "a same-path socket some other daemon bound after mine was removed".
///
/// A socket path can be recreated by a different process between the time
/// this daemon captures its identity and the time it later checks it, so `dev`
/// and `ino` (not the path) are what must match for cleanup to be safe.
#[cfg(unix)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub(super) struct SocketIdentity {
    dev: u64,
    ino: u64,
}

#[cfg(unix)]
pub(super) fn socket_identity(path: &std::path::Path) -> Option<SocketIdentity> {
    use std::os::unix::fs::MetadataExt;
    let meta = std::fs::metadata(path).ok()?;
    Some(SocketIdentity {
        dev: meta.dev(),
        ino: meta.ino(),
    })
}

// ── connection principal ──────────────────────────────────────────────────────

/// The uid on the other end of an accepted connection, read from the kernel.
///
/// This is the only identity on this socket the caller cannot choose. Every
/// identity field on the request frame — `namespace`, `actor_id`,
/// `visible_namespaces`, `config_id` — is supplied by the connecting process,
/// so none of them can answer "who is this". A check reading self-asserted
/// fields is not a weak gate, it is not a gate: anyone who wants to pass it
/// asserts the passing values.
///
/// `getpeereid(2)` on macOS/BSD, `SO_PEERCRED` on Linux. Both report the peer's
/// credentials as recorded by the kernel at connect time.
#[cfg(unix)]
pub(crate) fn peer_uid(stream: &UnixStream) -> std::io::Result<u32> {
    use std::os::fd::AsRawFd;
    let fd = stream.as_raw_fd();

    #[cfg(any(target_os = "macos", target_os = "ios", target_vendor = "apple"))]
    {
        let mut uid: libc::uid_t = 0;
        let mut gid: libc::gid_t = 0;
        // SAFETY: `fd` is a live connected socket owned by `stream` for the
        // duration of this call; both out-params are valid initialized locals.
        let rc = unsafe { libc::getpeereid(fd, &mut uid, &mut gid) };
        if rc != 0 {
            return Err(std::io::Error::last_os_error());
        }
        Ok(uid as u32)
    }

    #[cfg(target_os = "linux")]
    {
        let mut cred = libc::ucred {
            pid: 0,
            uid: 0,
            gid: 0,
        };
        let mut len = std::mem::size_of::<libc::ucred>() as libc::socklen_t;
        // SAFETY: `fd` is a live connected socket owned by `stream`; `cred` is
        // an initialized local of exactly `len` bytes, which is what
        // SO_PEERCRED writes.
        let rc = unsafe {
            libc::getsockopt(
                fd,
                libc::SOL_SOCKET,
                libc::SO_PEERCRED,
                (&mut cred as *mut libc::ucred).cast::<libc::c_void>(),
                &mut len,
            )
        };
        if rc != 0 {
            return Err(std::io::Error::last_os_error());
        }
        Ok(cred.uid)
    }

    #[cfg(not(any(
        target_os = "linux",
        target_os = "macos",
        target_os = "ios",
        target_vendor = "apple"
    )))]
    {
        let _ = fd;
        Err(std::io::Error::new(
            std::io::ErrorKind::Unsupported,
            "peer-credential capture is not implemented for this platform",
        ))
    }
}

/// Whether a connection from `uid` may be served by this daemon.
///
/// ADR-096 accepted per-request identity threading **for the single-principal
/// owner-only socket only**, and rested that on three things: the `0600`
/// socket, all connections being the same uid, and the database being already
/// same-uid-accessible. The socket mode is asserted at bind. This asserts the
/// second, which previously had no representation in the code at all — nothing
/// read peer identity, so nothing could notice when it stopped being true.
///
/// **Principal is not attribution.** Many `actor_id`s over one socket is
/// exactly what ADR-096 shipped and what every seat on a normal host does;
/// refusing a second distinct actor would break the accepted design. The
/// principal is the uid, and this refuses only a genuinely foreign one.
///
/// **There is deliberately no configuration escape hatch.** A flag permitting
/// other uids would not weaken this assertion, it would delete it, in the way
/// hardest to notice later: the check still exists, its tests still pass, and
/// the deployment that matters has it off. A deployment that genuinely needs
/// multiple uids needs a code change and a gated ADR — which is precisely the
/// decision that should be impossible to make by accident.
#[cfg(unix)]
pub(crate) fn uid_is_permitted(peer: u32, daemon_euid: u32) -> bool {
    peer == daemon_euid
}