357.2. kdos-powerd-0.2.0
The firewall's named services and the look of the machine before a login, for a desktop that is not root
| Version | 0.2.0, release 1 |
| Source tree | src/daemons/kdos-powerd/ |
| Phase | 50_desktop (Desktop), 64 of 92 in build order |
| Licence | MIT |
| Homepage | https://github.com/kunaldawn/kdos |
| Build time | 0.1 SBU |
| Installed size | 108.8 KiB in 4 files |
| Recipe | src/daemons/kdos-powerd/kpkgbuild |
About
kdos-powerd is the root daemon that lets a desktop which does not run as root change the machine’s settings that live in root’s files:
- which named services the firewall lets in;
- the accent colour of everything drawn before a login (the boot menu, the boot splash, the text console and the login screen), and the splash’s motion.
It also starts Samba once an account can share folders.
It offers the same verbs on two faces:
- The socket. The
kdoscommand and thekdos-powerclient write one-line requests to/run/kdos-powerd.sock, where the caller’s credentials are read from the socket withSO_PEERCRED. - The system bus. System Settings calls
io.kdos.Power1, where polkit decides each change. Starting Samba is on the bus face alone, for kded-kdos, which calls it at the login of asambasharemember.
Suspend, power-off and reboot are elogind’s: kdos-power suspend, poweroff and reboot run loginctl as the caller without reaching the daemon. Every verb, the rules for each caller and the bus interface are in kdos-powerd, and the pattern every root daemon shares is in The shape they share.
The port is KDOS’s own C, with no upstream source. build.sh compiles main.c and bus.c with the sources of libkbase and libkcolor and links basu for the bus face and nothing else, because every library a root daemon links is code running as root; see How the libraries are built.
Why it is in KDOS
The comment above it in script/phases/50_desktop/packages.txt:
The firewall's named services, the accent and the boot splash, for a desktop that is not root: a unix socket in /run gated by SO_PEERCRED, and io.kdos.Power1 on the system bus, which asks polkit for anyone not in wheel.
Sources
None: the port builds from its own directory, /kdos/src/daemons/kdos-powerd.
Dependencies
Depends on: basu.
Required by (2): kcm-kdos-firewall, kde-plasma.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/50_desktop/phase.env && kpkg install kdos-powerd'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /kdos/src/daemons/kdos-powerd.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/kdos-powerd
SRC=$SRC_ROOT/kdos-powerd-0.2.0
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
LIBS="$PORT_SRC/../../libs"
gcc $CFLAGS -O2 -std=gnu11 -D_GNU_SOURCE -Wall -Wextra \
-I"$LIBS/libkbase" -I"$LIBS/libkcolor" $(pkg-config --cflags basu) \
-o kdos-powerd "$PORT_SRC"/main.c "$PORT_SRC"/bus.c \
"$LIBS"/libkbase/*.c "$LIBS"/libkcolor/*.c \
$(pkg-config --libs basu) $LDFLAGS
install -Dm755 kdos-powerd "$PKG/usr/sbin/kdos-powerd"
install -d "$PKG/usr/bin"
ln -s ../sbin/kdos-powerd "$PKG/usr/bin/kdos-power"
install -Dm644 "$PORT_SRC/io.kdos.Power1.conf" \
"$PKG/usr/share/dbus-1/system.d/io.kdos.Power1.conf"
install -Dm644 "$PORT_SRC/io.kdos.power1.policy" \
"$PKG/usr/share/polkit-1/actions/io.kdos.power1.policy"
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/kdos-powerd, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf kdos-powerd-0.2.0-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/kdos-powerd, and runs the triggers its paths call for.
Other files in the port directory, read by build.sh: bus.c, io.kdos.Power1.conf, io.kdos.power1.policy, main.c, powerd.h.
Contents
Installed programs: kdos-power, kdos-powerd.
Notes
One binary has two names. Installed as /usr/sbin/kdos-powerd it serves the socket and the bus; the link /usr/bin/kdos-power runs it as the command-line client, which sends one request and prints the answer. The name it was started under is the whole switch, so the link must keep that name.
The recipe installs the bus policy /usr/share/dbus-1/system.d/io.kdos.Power1.conf, which lets root own the name and anybody call it, and three polkit actions in /usr/share/polkit-1/actions/io.kdos.power1.policy:
| Action | Who is granted it |
|---|---|
io.kdos.firewall.set |
an administrator’s password, kept for a few minutes for the process that gave it |
io.kdos.accent.set |
the person in the active session; it covers the splash’s motion as well |
io.kdos.filesharing.start |
the person in the active session, because the call takes no argument and starts only what the next boot would |
It installs no D-Bus activation file: /etc/init.d/55_powerd.sh starts the daemon under ksvc and waits for the name, and an activation file would let the bus start a second, unsupervised copy for a caller that came early. The daemon answers the socket before it reaches the bus and retries a bus it cannot reach every five seconds, so the kdos command still reaches the firewall on a machine whose system bus is down.
libkcolor is linked for the accent. Its argument is matched against the closed list of colour schemes compiled into the palette, which is the whole check on a verb a session that is not root can reach, so the list has to be the palette’s own rather than a copy in this program.
The firewall file it writes, /etc/nftables.d/50-kdos-services.nft, carries a named counter, kdos_knock_<name>, for every closed service, which counts the packets from another machine that service would have accepted before the input chain’s policy drops them. Each counting line starts with fib saddr type != local: this machine’s own broadcasts, kdeconnectd’s identity packet to port 1716 among them, loop back in on the network interface rather than on lo, and counted they would offer to let a phone in at every boot with no phone there. ListFirewallKnocks and kdos-power firewall knocks read them with nft list counters; the Firewall page and kdos-fwask from kcm-kdos-firewall use them to offer to let a blocked program in. The file shipped in the image is the daemon’s own output with every service closed, so the counters exist from the first boot.
The accent also restyles the login screen. The daemon copies one accent’s set from /usr/share/kdos/greeter/<accent>/, which kdos-plasma-look builds, into the sddm account’s ~/.config (kdeglobals, plasmarc, kcminputrc) and its ~/kdos-background.png, in a child process running as that account, so no file in a home another account owns is ever written as root.
The firewall verb runs /usr/sbin/nft from nftables and answers an error without it, and firewall ssh on|off runs /etc/init.d/70_sshd.sh. StartFileSharing runs /etc/init.d/83_samba.sh start from samba, which starts smbd only when the sambashare group has a member or a share exists, and refuses while /etc/service.disabled/samba exists or the script is missing. The accent runs kdos-bootctl theme and the splash motion kdos-bootctl splash, from kdos-tools, found through the daemon’s inherited PATH and skipped when absent; the reply then says the boot menu is unchanged. The client’s suspend, poweroff and reboot exec loginctl from elogind through PATH. polkitd, from polkit, is asked over the bus, and a polkit that does not answer is a refusal. None of these is a dependency: each reaches the image through a phase list, and the daemon still serves the rest without it.