summaryrefslogtreecommitdiff
path: root/blog/access-control/xdgfile.cil
blob: 67f5e31e38969a742eefb95cce0ecd95b9f71a4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
;; create out xdg namespace
(block xdg
    ;; we will create a subnamespace for each xdg file type (e.g config, cache, share, state)
    (block config
        ;; this next block isn't technically required but it shows that we are a subtype of .file.home
        (block home
            ;; create a macro to allow type transitions for files in our context
            (macro file_type_transition_file ((type ARG1) (class ARG2) (name ARG3))
                (call .home.file_type_transition_file (ARG1 file ARG2 ARG3)))
            
            ;; inherit the template which defines some types for us and also provides some macros
            (blockinherit .file.home.template)

            ;; define a context for the ~/.cache directory itself
            ;; hint: HOME_DIR is one of the few variables that can be interpolated into strings
            (filecon "HOME_DIR/\.config" dir file_context)
            (filecon "HOME_DIR/\.config/.*" file file_context)))

    (block cache
        (block home
            (macro file_type_transition_file ((type ARG1) (class ARG2) (name ARG3))
                (call .home.file_type_transition_file (ARG1 file ARG2 ARG3)))
            
            (blockinherit .file.home.template)

            (filecon "HOME_DIR/\.cache" dir file_context)
            (filecon "HOME_DIR/\.cache/.*" file file_context)))

    (block share
        (block home
            (macro file_type_transition_file ((type ARG1) (class ARG2) (name ARG3))
                (call .home.file_type_transition_file (ARG1 file ARG2 ARG3)))
            
            (blockinherit .file.home.template)

            (filecon "HOME_DIR/\.local/share" dir file_context)
            (filecon "HOME_DIR/\.local/share/.*" file file_context)))

    (block state
        (block home
            (macro file_type_transition_file ((type ARG1) (class ARG2) (name ARG3))
                (call .home.file_type_transition_file (ARG1 file ARG2 ARG3)))
            
            (blockinherit .file.home.template)

            (filecon "HOME_DIR/\.local/state" dir file_context)
            (filecon "HOME_DIR/\.local/state/.*" file file_context))))