diff --git a/secrules/rules04.py b/secrules/rules04.py
index 4f499d0118fc518f433672dc08c96d5a419beefa_c2VjcnVsZXMvcnVsZXMwNC5weQ==..b1f81770885a75d1b103a6a81d9a7a5d50a190ea_c2VjcnVsZXMvcnVsZXMwNC5weQ== 100644
--- a/secrules/rules04.py
+++ b/secrules/rules04.py
@@ -2,7 +2,6 @@
 __version__ = '1.0'
 
 from .common import level_rule
-import os, os.path
 from ovms.rtl import lib
 from ovms import starlet
 from ovms import ossdef, ssdef, rmsdef, dvsdef, dcdef, dvidef, itemList
@@ -6,6 +5,4 @@
 from ovms.rtl import lib
 from ovms import starlet
 from ovms import ossdef, ssdef, rmsdef, dvsdef, dcdef, dvidef, itemList
-from ovms import user
-from ovms import crtl
 from ovms.rtl.lib.FindFile import FindFile
@@ -11,4 +8,5 @@
 from ovms.rtl.lib.FindFile import FindFile
+from ovms import rms
 from secrules import get_security
 from ovms.starlet.DeviceScan import DeviceScan
 
@@ -226,6 +224,9 @@
             for fn in fi:  # type: ignore
                 fn: bytes
                 try:
+                    s = rms.search(fn)
+                    did = s[-1]
+                    dfn = lib.fid_to_name(s[1], did)[1]
                     retsec = starlet.get_security(
                         objnam=fn, clsnam=b'FILE', itmlst=it
                     )
@@ -229,6 +230,9 @@
                     retsec = starlet.get_security(
                         objnam=fn, clsnam=b'FILE', itmlst=it
                     )
+                    dretsec = starlet.get_security(
+                        objnam=dfn, clsnam=b'FILE', itmlst=it
+                    )
                     prot: int = retsec[2][
                         ossdef.OSS__PROTECTION
                     ]   # type: ignore
@@ -232,7 +236,10 @@
                     prot: int = retsec[2][
                         ossdef.OSS__PROTECTION
                     ]   # type: ignore
+                    dprot: int = dretsec[2][
+                        ossdef.OSS__PROTECTION
+                    ]   # type: ignore
                     wprot = (prot & 0xF000) >> 12
                     gprot = (prot & 0x0F00) >> 8
                     oprot = (prot & 0x00F0) >> 4
                     sprot = prot & 0x000F
@@ -235,5 +242,11 @@
                     wprot = (prot & 0xF000) >> 12
                     gprot = (prot & 0x0F00) >> 8
                     oprot = (prot & 0x00F0) >> 4
                     sprot = prot & 0x000F
+                    dwprot = (dprot & 0xF000) >> 12
+                    dgprot = (dprot & 0x0F00) >> 8
+                    doprot = (dprot & 0x00F0) >> 4
+                    dsprot = dprot & 0x000F
+                    fnprot = [sprot, oprot, gprot, wprot]
+                    dirprot = [dsprot, doprot, dgprot, dwprot]
 
@@ -239,8 +252,8 @@
 
-                    # ebit = 0x4
-                    # wbit = 0x2
-                    # dbit = 0x8
-                    # rbit = 0x1
+                    ebit = 0x4
+                    wbit = 0x2
+                    dbit = 0x8
+                    rbit = 0x1
 
                     for i in range(4):
                         mask = 1 << i
@@ -256,7 +269,16 @@
                             break
                     else:
                         found = False
-                    if found:
+                    for fp, dp in zip(fnprot, dirprot):
+                        if (fp & ebit == 0 or fp & rbit == 0) and not (dp & ebit == 0 or dp & rbit == 0):
+                            dfound = True
+                            break
+                        if fp & dbit == 0 and dp & wbit != 0:
+                            dfound = True
+                            break
+                    else:
+                        dfound = False
+                    if found or dfound:
                         if fmt:
                             print('0406"2"', fn.decode(), file=fo)
                         else:
@@ -266,6 +288,11 @@
                                 lib.format_sogw_prot(prot)[1].decode(),
                                 file=fo,
                             )
+                            print(
+                                ' ' * 10,
+                                lib.format_sogw_prot(dprot)[1].decode(),
+                                file=fo,
+                            )
                 except VMSError as e:
                     if e.errno not in (
                         rmsdef.RMS__FNF,
@@ -298,3 +325,4 @@
     rule0403(fo, len(sys.argv) > 2)
     rule0404(fo, len(sys.argv) > 2)
     rule0405(fo, len(sys.argv) > 2)
+    rule0406(fo, len(sys.argv) > 2)