2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-30 13:58:22 +00:00

utils: fix make -C profiles check-logprof fails

On arch
  make -C profiles check-logprof

fails with
  *** Checking profiles from ./apparmor.d against logprof

  ERROR: Can't find AppArmor profiles in /etc/apparmor.d
  make: *** [Makefile:113: check-logprof] Error 1
  make: Leaving directory '/build/apparmor/src/apparmor-2.13.3/profiles'

because /etc/apparmor.d/ is not available in the build environment
and aa-logprofs --dir argument, is not being passed to init_aa()
but used to update profiles_dir after the fact.

Fix this by passing profiledir as an argument to init_aa()

Fixes: https://gitlab.com/apparmor/apparmor/-/issues/36
MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/663
Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-by: Christian Boltz <apparmor@cboltz.de>
(backported from commit 15dc06248c62ccceec00f70296a6c17f7c5096a1)
This commit is contained in:
John Johansen 2020-10-21 03:16:46 -07:00
parent 1808d14e35
commit 1335b80ff4
5 changed files with 11 additions and 32 deletions

View File

@ -72,20 +72,14 @@ if args.json:
aaui.set_json_mode()
profiling = args.program
profiledir = args.dir
apparmor.init_aa()
apparmor.init_aa(profiledir=args.dir)
apparmor.set_logfile(args.file)
aa_mountpoint = apparmor.check_for_apparmor()
if not aa_mountpoint:
raise apparmor.AppArmorException(_('It seems AppArmor was not started. Please enable AppArmor and try again.'))
if profiledir:
apparmor.profile_dir = apparmor.get_full_path(profiledir)
if not os.path.isdir(apparmor.profile_dir):
raise apparmor.AppArmorException(_("%s is not a directory.") %profiledir)
program = None
#if os.path.exists(apparmor.which(profiling.strip())):
if os.path.exists(profiling):

View File

@ -13,7 +13,6 @@
#
# ----------------------------------------------------------------------
import argparse
import os
import apparmor.aa as apparmor
import apparmor.ui as aaui
@ -36,21 +35,16 @@ args = parser.parse_args()
if args.json:
aaui.set_json_mode()
profiledir = args.dir
logmark = args.mark or ''
apparmor.init_aa()
apparmor.init_aa(profiledir=args.dir)
apparmor.set_logfile(args.file)
aa_mountpoint = apparmor.check_for_apparmor()
if not aa_mountpoint:
raise apparmor.AppArmorException(_('It seems AppArmor was not started. Please enable AppArmor and try again.'))
if profiledir:
apparmor.profile_dir = apparmor.get_full_path(profiledir)
if not os.path.isdir(apparmor.profile_dir):
raise apparmor.AppArmorException("%s is not a directory."%profiledir)
apparmor.loadincludes()
apparmor.do_logprof_pass(logmark)

View File

@ -14,7 +14,6 @@
#
# ----------------------------------------------------------------------
import argparse
import os
import apparmor.aa
import apparmor.aamode
@ -23,7 +22,6 @@ import apparmor.severity
import apparmor.cleanprofile as cleanprofile
import apparmor.ui as aaui
from apparmor.common import AppArmorException
from apparmor.regex import re_match_include
@ -43,15 +41,10 @@ args = parser.parse_args()
args.other = None
apparmor.aa.init_aa()
apparmor.aa.init_aa(profiledir=args.dir)
profiles = args.files
profiledir = args.dir
if profiledir:
apparmor.aa.profile_dir = apparmor.aa.get_full_path(profiledir)
if not os.path.isdir(apparmor.aa.profile_dir):
raise AppArmorException(_("%s is not a directory.") %profiledir)
def reset_aa():
apparmor.aa.aa = apparmor.aa.hasher()

View File

@ -3233,7 +3233,7 @@ def logger_path():
######Initialisations######
def init_aa(confdir="/etc/apparmor"):
def init_aa(confdir="/etc/apparmor", profiledir=None):
global CONFDIR
global conf
global cfg
@ -3256,7 +3256,11 @@ def init_aa(confdir="/etc/apparmor"):
if cfg['settings'].get('default_owner_prompt', False):
cfg['settings']['default_owner_prompt'] = ''
profile_dir = conf.find_first_dir(cfg['settings'].get('profiledir')) or '/etc/apparmor.d'
if profiledir:
profile_dir = profiledir
else:
profile_dir = conf.find_first_dir(cfg['settings'].get('profiledir')) or '/etc/apparmor.d'
profile_dir = os.path.abspath(profile_dir)
if not os.path.isdir(profile_dir):
raise AppArmorException('Can\'t find AppArmor profiles in %s' % (profile_dir))

View File

@ -25,10 +25,9 @@ _ = init_translation()
class aa_tools:
def __init__(self, tool_name, args):
apparmor.init_aa()
apparmor.init_aa(profiledir=args.dir)
self.name = tool_name
self.profiledir = args.dir
self.profiling = args.program
self.check_profile_dir()
self.silent = None
@ -43,11 +42,6 @@ class aa_tools:
self.silent = args.silent
def check_profile_dir(self):
if self.profiledir:
apparmor.profile_dir = apparmor.get_full_path(self.profiledir)
if not os.path.isdir(apparmor.profile_dir):
raise apparmor.AppArmorException("%s is not a directory." % self.profiledir)
if not user_perm(apparmor.profile_dir):
raise apparmor.AppArmorException("Cannot write to profile directory: %s" % (apparmor.profile_dir))