#include #include #include bool check_access(const char *subject, const char *object, char access) { if (strcmp(object, "/home/report") == 0) { if (strcmp(subject, "alice") == 0) return (access == 'r' || access == 'w'); if (strcmp(subject, "bob") == 0) return (access == 'r'); return false; } if (strcmp(object, "/etc/config") == 0) { return (strcmp(subject, "root") == 0); } return false; } int main(void) { struct { const char *user; const char *file; char mode; } tests[] = { {"alice", "/home/report", 'w'}, {"bob", "/home/report", 'w'}, {"bob", "/home/report", 'r'}, {"root", "/etc/config", 'r'}, {"alice", "/etc/config", 'r'} }; int n = sizeof(tests) / sizeof(tests[0]); for (int i = 0; i < n; i++) { bool ok = check_access(tests[i].user, tests[i].file, tests[i].mode); printf("%s %c %s -> %s\n", tests[i].user, tests[i].mode, tests[i].file, ok ? "yes" : "no"); } return 0; }