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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{bin}/gimp{,-*}
@{att} = /att/gimp/
profile gimp /{,usr/}bin/gimp{,-*}  flags=(attach_disconnected,attach_disconnected.path=@{att},complain) {
  include <abstractions/attached/base>
  include <abstractions/audio-client>
  include <abstractions/bus-session>
  include <abstractions/bus/org.freedesktop.FileManager1>
  include <abstractions/bus/session/org.gtk.Private.RemoteVolumeMonitor>
  include <abstractions/dconf-write>
  include <abstractions/desktop>
  include <abstractions/graphics>
  include <abstractions/nameservice-strict>
  include <abstractions/python>
  include <abstractions/thumbnails-cache-write>
  include <abstractions/user-download-strict>

  signal (send) set=(term, kill) peer=xsane-gimp,

  include <abstractions/bus/session/own>

  dbus bind bus=session name=org.gimp{,.*},
  dbus receive bus=session path=/org/gimp{,/**}
       interface=org.gimp{,.*}
       peer=(name="@{busname}"),
  dbus send bus=session path=/org/gimp{,/**}
       interface=org.gimp{,.*}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus (send receive) bus=session path=/org/gimp{,/**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.freedesktop.DBus}"),
  dbus receive bus=session path=/org/gimp{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="@{busname}"),
  dbus receive bus=session path=/org/gimp{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.gimp{,.*}}"),
  dbus send bus=session path=/org/gimp{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.freedesktop.DBus}"),

  unix type=stream addr=none peer=(label=gnome-shell, addr=none),

  dbus (send receive) bus=session path=/org/gnome/Shell/Screenshot{,/**}
       interface=org.gnome.Shell.Screenshot{,.*}
       peer=(name="{@{busname},org.gnome.Shell.Screenshot{,.*}}", label=gnome-shell),
  dbus (send receive) bus=session path=/org/gnome/Shell/Screenshot{,/**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.gnome.Shell.Screenshot{,.*}}", label=gnome-shell),
  dbus send bus=session path=/org/gnome/Shell/Screenshot{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="{@{busname},org.gnome.Shell.Screenshot{,.*}}", label=gnome-shell),
  dbus send bus=session path=/org/gnome/Shell/Screenshot{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.gnome.Shell.Screenshot{,.*}}", label=gnome-shell),
  dbus receive bus=session path=/org/gnome/Shell/Screenshot{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.gnome.Shell.Screenshot{,.*}}", label=gnome-shell),
  unix type=stream addr=none peer=(label="gvfsd{,-*}", addr=none),

  dbus (send receive) bus=session path=/org/gtk/vfs{,/**}
       interface=org.gtk.vfs{,.*}
       peer=(name="{@{busname},org.gtk.vfs{,.*}}", label="gvfsd{,-*}"),
  dbus (send receive) bus=session path=/org/gtk/vfs{,/**}
       interface=org.freedesktop.DBus.Properties
       member={Get,GetAll,Set,PropertiesChanged}
       peer=(name="{@{busname},org.gtk.vfs{,.*}}", label="gvfsd{,-*}"),
  dbus send bus=session path=/org/gtk/vfs{,/**}
       interface=org.freedesktop.DBus.Introspectable
       member=Introspect
       peer=(name="{@{busname},org.gtk.vfs{,.*}}", label="gvfsd{,-*}"),
  dbus send bus=session path=/org/gtk/vfs{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member=GetManagedObjects
       peer=(name="{@{busname},org.gtk.vfs{,.*}}", label="gvfsd{,-*}"),
  dbus receive bus=session path=/org/gtk/vfs{,/**}
       interface=org.freedesktop.DBus.ObjectManager
       member={InterfacesAdded,InterfacesRemoved}
       peer=(name="{@{busname},org.gtk.vfs{,.*}}", label="gvfsd{,-*}"),

  @{exec_path} mr,

  @{python_path}                         rix,
  @{bin}/env                             rix,
  @{bin}/gimp-debug-tool-3.0             rix,
  @{bin}/gimp-script-fu-interpreter-*    rix,
  @{bin}/gjs-console                     rix,
  @{bin}/lua                             rix,
  @{lib}/gimp/@{version}/extensions/*/*  rix,
  @{lib}/gimp/*/plug-ins/**              rix,

  @{bin}/darktable  rpux,
  @{bin}/xsane-gimp rpx,
  @{open_path}      rpx -> child-open-help,

  @{lib}/gimp/@{version}/plug-ins/python-console/__pycache__/{,*} w,
  @{lib}/@{multiarch}/gimp/@{version}/plug-ins/web-browser/web-browser ix,

  /usr/share/gimp/{,**} r,
  /usr/share/mypaint-data/{,**} r,
  /usr/share/xml/iso-codes/{,**} r,

  /etc/fstab r,
  /etc/gimp/{,**} r,

  owner @{HOME}/@{XDG_SCREENSHOTS_DIR}/{,**} rw,
  owner @{HOME}/@{XDG_WALLPAPERS_DIR}/{,**} rw,

  owner @{user_documents_dirs}/{,**} rw,
  owner @{user_pictures_dirs}/{,**} rw,
  owner @{user_work_dirs}/{,**} rw,

  owner @{user_cache_dirs}//thumbnails/normal/gimp-thumb* rw,
  owner @{user_cache_dirs}/babl/{,**} rw,
  owner @{user_cache_dirs}/gegl-@{version}/{,**} rw,
  owner @{user_cache_dirs}/gegl-@{version}/{,**} rw,
  owner @{user_cache_dirs}/gimp/{,**} rw,
  owner @{user_cache_dirs}/GIMP/{,**} rw,

  owner @{user_config_dirs}/gimp/{,**} rw,
  owner @{user_config_dirs}/GIMP/{,**} rw,

  owner @{user_share_dirs}/gegl-@{version}/{,**} r,
  owner @{user_share_dirs}/GIMP/{,**} rw,

  owner @{tmp}/gimp/{,**} rw,

  @{run}/mount/utab r,

  owner @{PROC}/@{pid}/cgroup r,
  owner @{PROC}/@{pid}/mountinfo r,
  owner @{PROC}/@{pid}/mounts r,
  owner @{PROC}/@{pid}/stat r,
  owner @{PROC}/@{pid}/task/@{tid}/stat r,

  include if exists <local/gimp>
}

# vim:syntax=apparmor
