znc: allow the /var/lib/znc datadir used by the systemd unit

The znc.service unit shipped by ZNC upstream (znc.service.in) and by Debian/Ubuntu runs znc -f --datadir=/var/lib/znc, but the profile only allows the default ~/.znc datadir. With the profile enforced, the service fails to start (from my test, see below):

apparmor="DENIED" operation="open" class="file" profile="znc" name="/var/lib/znc/configs/znc.conf" requested_mask="wr" denied_mask="wr" fsuid=110 ouid=110

This MR defines @{znc_dirs} = @{HOME}/.znc /var/lib/znc and uses it in the existing rules, so /var/lib/znc gets exactly the access the profile already grants for ~/.znc: same permissions, still owner. Users currently work around this by duplicating the rules for /var/lib/znc in local/znc (see the bug).

Tested in enforce mode on Ubuntu 24.04 with znc 1.9.0, using a copy with abi <abi/4.0> and /usr/bin/znc so that it loads with AppArmor 4.0. The packaged znc.service (user _znc) starts, accepts SSL, serves webadmin and rewrites its config on SIGUSR1. A regular user with ~/.znc works the same. There were no denials in either case. The unmodified file also compiles with the AppArmor 6.0 parser (apparmor_parser -QK on Ubuntu 27.04).

Candidate for the 5.0 branch: Ubuntu 26.04 ships 5.0.2, and its znc profile is identical to this one.

Fixes: https://bugs.launchpad.net/bugs/2175533

Merge request reports

Loading
Loading