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

abi <abi/4.0>,

include <tunables/global>

@{exec_path} = @{sbin}/update-smart-drivedb
@{att} = ""
profile update-smart-drivedb /{,usr/}{,s}bin/update-smart-drivedb flags=(complain) {
  include <abstractions/base-strict>
  include <abstractions/consoles>

  @{exec_path} r,
  @{sh_path}        rix,

  @{bin}/cat        rix,
  @{bin}/dirname    rix,
  @{bin}/sed        rix,
  @{bin}/rm         rix,
  @{bin}/dd         rix,
  @{bin}/wc         rix,
  @{bin}/touch      rix,
  @{bin}/mkdir      rix,
  @{bin}/chmod      rix,
  @{bin}/mv         rix,
  @{bin}/cmp        rix,

  @{bin}/          r,
  @{sbin}/smartctl  rpx,

  @{bin}/gpg{,2}    rcx -> gpg,
  @{bin}/wget       rcx -> browse,
  @{bin}/curl       rcx -> browse,
  @{bin}/lynx       rcx -> browse,

  /var/lib/smartmontools/drivedb/drivedb.h{,.*} rw,

  owner /var/lib/smartmontools/drivedb/.gnupg.@{int}.tmp/{,**} rw,

  # For shell pwd
  /root/ r,


  profile gpg flags=(complain) {
    include <abstractions/base-strict>
    include <abstractions/consoles>

    @{bin}/gpg{,2} mr,

    @{bin}/gpg-agent rix,

    owner @{PROC}/@{pid}/fd/ r,

    /var/lib/smartmontools/drivedb/drivedb.h.new.raw{,.asc} r,

    owner /var/lib/smartmontools/drivedb/.gnupg.@{int}.tmp/ rw,
    owner /var/lib/smartmontools/drivedb/.gnupg.@{int}.tmp/** rwkl -> /var/lib/smartmontools/drivedb/.gnupg.@{int}.tmp/**,

    include if exists <local/update-smart-drivedb_gpg>
  }

  profile browse flags=(complain) {
    include <abstractions/base-strict>
    include <abstractions/consoles>
    include <abstractions/nameservice-strict>
    include <abstractions/ssl_certs>

    network inet dgram,
    network inet6 dgram,
    network inet stream,
    network inet6 stream,

    @{bin}/wget mr,
    @{bin}/curl mr,
    @{bin}/lynx mr,

    @{sh_path}        rix,

    /etc/mime.types r,
    /etc/mailcap r,

    /etc/lynx/* r,
    /etc/wgetrc r,
    owner @{HOME}/.wget-hsts rwk,

    /usr/share/publicsuffix/public_suffix_list.* r,

    /var/lib/smartmontools/drivedb/drivedb.h.new{,.raw.asc} w,

    include if exists <local/update-smart-drivedb_browse>
  }

  include if exists <local/update-smart-drivedb>
}

# vim:syntax=apparmor
