• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Feb 19th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. :-dynamic subject/2.
2. :-dynamic object/2.
3.
4.
5. subject(s1, 0).
6. subject(s2, 1).
7. subject(s3, 1).
8. subject(s4, 2).
9. subject(s5, 2).
10. subject(s5, 2).
11. subject(s6, 3).
12. subject(s7, 4).
13. subject(s8, 5).
14. subject(s9, 5).
15. subject(s10, 6).
16. subject(s11, 7).
17.
18. object(o1, 0).
19. object(o2, 1).
20. object(o3, 2).
21. object(o4, 2).
22. object(o5, 3).
23. object(o6, 3).
24.
25. %strong_rule(a).
26. weak_rule(b).
27.
28. show_subjects:-
29.     forall(subject(S, L), (write("Subject "), write(S), write(" with level "), write(L), write("\n"))).
30.
31. show_objects:-
32.     forall(object(O, L), (write("Object "), write(O), write(" with level "), write(L), write("\n"))).
33.
34. try_to_read(S, O):-
35.     not(subject(S, _)), write("There is no such subject\n");
36.     not(object(O, _)), write("There is no such object\n");
37.     subject(S, L1), object(O, L2), L1 >= L2, write("Subject can read current object.\n");
38.     write("NRU rule doesn't allow you to do this.\n").
39. try_to_write(S, O):-
40.    not(subject(S, _)), write("There is no such subject\n");
41.    not(object(O, _)), write("There is no such object\n");
42.    subject(S, L1), object(O, L2), L2 >= L1, write("Subject can write in current object.\n");
43.    write("NWD rule doesn't allow you to do this.\n").
44. update(S, O):-
45.     not(subject(S, _)), write("There is no such subject\n");
46.     not(object(O, _)), write("There is no such object\n");
47.     write("Update rule can be executed between these subject and object.\n").
48.
49. read_systemz(S, O):-
50.     not(subject(S, _)), write("There is no such subject\n");
51.     not(object(O, _)), write("There is no such object\n");
52.     weak_rule(b), write("There is a weak calm rule in the system, security level probably will be decreased\n"), subject(S, L1), L1 > 3, L2 is L1 - 1, retractall(subject(S, L1)), asserta(subject(S, L2)), try_to_read(S, O);
53.     weak_rule(b), try_to_read(S, O);
54.     strong_rule(b), write("there is a strong calm rule in the system\n"), try_to_read(S, O);
55.     retractall(subject(S, _)), retractall(object(O, _)), asserta(subject(S, 0)), asserta(object(O, 0)), write("Object can be read\n").
56.
57. write_systemz(S, O):-
58.     not(subject(S, _)), write("There is no such subject\n");
59.     not(object(O, _)), write("There is no such object\n");
60.     weak_rule(b), write("There is a weak calm rule in the system, security level probably will be decreased\n"), subject(S, L1), L1 > 3, L2 is L1 - 1, retractall(subject(S, L1)), asserta(subject(S, L2)), try_to_write(S, O);
61.     weak_rule(b), try_to_write(S, O);
62.     strong_rule(b), write("there is a strong calm rule in the system\n"), try_to_write(S, O);
63.     retractall(subject(S, _)), retractall(object(O, _)), asserta(subject(S, 0)), asserta(object(O, 0)), write("Object can be read\n").
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top