# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2021 Mikhail Morfikov
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/fritzing{,.real}
profile fritzing @{exec_path} {
  include <abstractions/base>
  include <abstractions/X>
  include <abstractions/gtk>
  include <abstractions/fonts>
  include <abstractions/fontconfig-cache-read>
  include <abstractions/freedesktop.org>
  include <abstractions/nameservice-strict>
  include <abstractions/mesa>
  include <abstractions/dri-enumerate>
  include <abstractions/qt5>
  include <abstractions/qt5-settings-write>

  network inet dgram,
  network inet6 dgram,
  network inet stream,
  network inet6 stream,
  network netlink dgram,
  network netlink raw,

  @{exec_path} mrix,

  owner @{user_config_dirs}/Fritzing/ rw,
  owner @{user_config_dirs}/Fritzing/** rwkl -> @{user_config_dirs}/Fritzing/**,

  owner @{HOME}/@{XDG_DOCUMENTS_DIR}/Fritzing/ rw,
  owner @{HOME}/@{XDG_DOCUMENTS_DIR}/Fritzing/** rw,

  /usr/share/fritzing/{,**} r,

  /usr/share/hwdata/pnp.ids r,

  owner @{PROC}/@{pid}/cmdline r,
  owner @{PROC}/@{pid}/mountinfo r,
  owner @{PROC}/@{pid}/mounts r,

  /etc/fstab r,

  /var/lib/dbus/machine-id r,
  /etc/machine-id r,

  /etc/debian_version r,

  @{sys}/bus/ r,
  @{sys}/class/ r,
  @{sys}/class/tty/ r,
  @{sys}/devices/**/tty*/uevent r,
  @{sys}/devices/**/tty/**/uevent r,

  @{run}/udev/data/c4:@{int}   r,         # for /dev/tty[0-9]*
  @{run}/udev/data/c5:@{int}   r,         # for /dev/tty, /dev/console, /dev/ptmx
  @{run}/udev/data/c166:@{int} r,         # for /dev/ttyACM[0-9]*

  /dev/ttyS@{int} rw,
  /dev/ttyACM@{int} rw,

  owner @{run}/lock/LCK..ttyACM[0-9]* rwk,

  include if exists <local/fritzing>
}
