1 #include <stdio.h> 2 #include <stdarg.h> 3 #include <sys/types.h> 4 5 #include <sepol/policydb/avtab.h> 6 #include <sepol/policydb/policydb.h> 7 8 9 #define STACK_SIZE 16 10 #define DEFAULT_LEVEL "systemlow" 11 #define DEFAULT_OBJECT "object_r" 12 13 // initial sid names aren't actually stored in the pp files, need to a have 14 // a mapping, taken from the linux kernel 15 static const char * const selinux_sid_to_str[] = { 16 NULL, 17 "kernel", 18 "security", 19 "unlabeled", 20 NULL, 21 "file", 22 NULL, 23 "init", 24 "any_socket", 25 "port", 26 "netif", 27 "netmsg", 28 "node", 29 NULL, 30 NULL, 31 NULL, 32 NULL, 33 NULL, 34 NULL, 35 NULL, 36 NULL, 37 NULL, 38 NULL, 39 NULL, 40 NULL, 41 NULL, 42 NULL, 43 "devnull", 44 }; 45 46 #define SELINUX_SID_SZ (sizeof(selinux_sid_to_str)/sizeof(selinux_sid_to_str[0])) 47 48 static const char * const xen_sid_to_str[] = { 49 "null", 50 "xen", 51 "dom0", 52 "domio", 53 "domxen", 54 "unlabeled", 55 "security", 56 "ioport", 57 "iomem", 58 "irq", 59 "device", 60 "domU", 61 "domDM", 62 }; 63 64 #define XEN_SID_SZ (sizeof(xen_sid_to_str)/sizeof(xen_sid_to_str[0])) 65 66 static const uint32_t avtab_flavors[] = { 67 AVTAB_ALLOWED, 68 AVTAB_AUDITALLOW, 69 AVTAB_AUDITDENY, 70 AVTAB_XPERMS_ALLOWED, 71 AVTAB_XPERMS_AUDITALLOW, 72 AVTAB_XPERMS_DONTAUDIT, 73 AVTAB_TRANSITION, 74 AVTAB_MEMBER, 75 AVTAB_CHANGE, 76 }; 77 78 #define AVTAB_FLAVORS_SZ (sizeof(avtab_flavors)/sizeof(avtab_flavors[0])) 79 80 struct strs { 81 char **list; 82 unsigned num; 83 size_t size; 84 }; 85 86 void sepol_indent(FILE *out, int indent); 87 __attribute__ ((format(printf, 2, 3))) 88 void sepol_printf(FILE *out, const char *fmt, ...); 89 90 __attribute__ ((format(printf, 1, 2))) 91 char *create_str(const char *fmt, ...); 92 93 int strs_init(struct strs **strs, size_t size); 94 void strs_destroy(struct strs **strs); 95 void strs_free_all(struct strs *strs); 96 int strs_add(struct strs *strs, char *s); 97 __attribute__ ((format(printf, 2, 3))) 98 int strs_create_and_add(struct strs *strs, const char *fmt, ...); 99 char *strs_remove_last(struct strs *strs); 100 int strs_add_at_index(struct strs *strs, char *s, size_t index); 101 char *strs_read_at_index(struct strs *strs, size_t index); 102 void strs_sort(struct strs *strs); 103 unsigned strs_num_items(const struct strs *strs); 104 size_t strs_len_items(const struct strs *strs); 105 char *strs_to_str(const struct strs *strs); 106 void strs_write_each(const struct strs *strs, FILE *out); 107 void strs_write_each_indented(const struct strs *strs, FILE *out, int indent); 108 int hashtab_ordered_to_strs(char *key, void *data, void *args); 109 int ebitmap_to_strs(const struct ebitmap *map, struct strs *strs, char **val_to_name); 110 char *ebitmap_to_str(const struct ebitmap *map, char **val_to_name, int sort); 111 112 int strs_stack_init(struct strs **stack); 113 void strs_stack_destroy(struct strs **stack); 114 int strs_stack_push(struct strs *stack, char *s); 115 char *strs_stack_pop(struct strs *stack); 116 int strs_stack_empty(const struct strs *stack); 117 118 int sort_ocontexts(struct policydb *pdb); 119