| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
import unittest |
| 21 |
import sepolgen.refparser as refparser |
| 22 |
import sepolgen.refpolicy as refpolicy |
| 23 |
|
| 24 |
interface_example = """######################################## |
| 25 |
## <summary> |
| 26 |
## Search the content of /etc. |
| 27 |
## </summary> |
| 28 |
## <param name="domain"> |
| 29 |
## <summary> |
| 30 |
## Domain allowed access. |
| 31 |
## </summary> |
| 32 |
## </param> |
| 33 |
# |
| 34 |
interface(`files_search_usr',` |
| 35 |
gen_require(` |
| 36 |
type usr_t; |
| 37 |
') |
| 38 |
|
| 39 |
allow $1 usr_t:dir search; |
| 40 |
allow { domain $1 } { usr_t usr_home_t }:{ file dir } { read write getattr }; |
| 41 |
typeattribute $1 file_type; |
| 42 |
|
| 43 |
if (foo) { |
| 44 |
allow $1 foo:bar baz; |
| 45 |
} |
| 46 |
|
| 47 |
if (bar) { |
| 48 |
allow $1 foo:bar baz; |
| 49 |
} else { |
| 50 |
allow $1 foo:bar baz; |
| 51 |
} |
| 52 |
') |
| 53 |
|
| 54 |
######################################## |
| 55 |
## <summary> |
| 56 |
## List the contents of generic |
| 57 |
## directories in /usr. |
| 58 |
## </summary> |
| 59 |
## <param name="domain"> |
| 60 |
## <summary> |
| 61 |
## Domain allowed access. |
| 62 |
## </summary> |
| 63 |
## </param> |
| 64 |
# |
| 65 |
interface(`files_list_usr',` |
| 66 |
gen_require(` |
| 67 |
type usr_t; |
| 68 |
') |
| 69 |
|
| 70 |
allow $1 usr_t:dir { read getattr }; |
| 71 |
|
| 72 |
optional_policy(` |
| 73 |
search_usr($1) |
| 74 |
') |
| 75 |
|
| 76 |
tunable_policy(`foo',` |
| 77 |
whatever($1) |
| 78 |
') |
| 79 |
|
| 80 |
') |
| 81 |
|
| 82 |
######################################## |
| 83 |
## <summary> |
| 84 |
## Execute generic programs in /usr in the caller domain. |
| 85 |
## </summary> |
| 86 |
## <param name="domain"> |
| 87 |
## <summary> |
| 88 |
## Domain allowed access. |
| 89 |
## </summary> |
| 90 |
## </param> |
| 91 |
# |
| 92 |
interface(`files_exec_usr_files',` |
| 93 |
gen_require(` |
| 94 |
type usr_t; |
| 95 |
') |
| 96 |
|
| 97 |
allow $1 usr_t:dir read; |
| 98 |
allow $1 usr_t:lnk_file { read getattr }; |
| 99 |
can_exec($1,usr_t) |
| 100 |
can_foo($1) |
| 101 |
|
| 102 |
') |
| 103 |
""" |
| 104 |
|
| 105 |
class TestParser(unittest.TestCase): |
| 106 |
def test_interface_parsing(self): |
| 107 |
h = refparser.parse(interface_example) |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
name = "files_search_usr" |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|