8 struct security_class_mapping {
10 const char *perms[sizeof(unsigned) * 8 + 1];
14 #include "initial_sid_to_string.h"
16 #define max(x, y) (((int)(x) > (int)(y)) ? x : y)
20 static void usage(void)
22 printf("usage: %s flask.h av_permissions.h\n", progname);
26 static char *stoupperx(const char *s)
32 fprintf(stderr, "%s: out of memory\n", progname);
41 int main(int argc, char *argv[])
52 fout = fopen(argv[1], "w");
54 fprintf(stderr, "Could not open %s for writing: %s\n",
55 argv[1], strerror(errno));
59 for (i = 0; secclass_map[i].name; i++) {
60 struct security_class_mapping *map = &secclass_map[i];
61 map->name = stoupperx(map->name);
62 for (j = 0; map->perms[j]; j++)
63 map->perms[j] = stoupperx(map->perms[j]);
66 isids_len = sizeof(initial_sid_to_string) / sizeof (char *);
67 for (i = 1; i < isids_len; i++)
68 initial_sid_to_string[i] = stoupperx(initial_sid_to_string[i]);
70 fprintf(fout, "/* This file is automatically generated. Do not edit. */\n");
71 fprintf(fout, "#ifndef _SELINUX_FLASK_H_\n#define _SELINUX_FLASK_H_\n\n");
73 for (i = 0; secclass_map[i].name; i++) {
74 struct security_class_mapping *map = &secclass_map[i];
75 fprintf(fout, "#define SECCLASS_%s", map->name);
76 for (j = 0; j < max(1, 40 - strlen(map->name)); j++)
78 fprintf(fout, "%2d\n", i+1);
83 for (i = 1; i < isids_len; i++) {
84 const char *s = initial_sid_to_string[i];
85 fprintf(fout, "#define SECINITSID_%s", s);
86 for (j = 0; j < max(1, 40 - strlen(s)); j++)
88 fprintf(fout, "%2d\n", i);
90 fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1);
91 fprintf(fout, "\n#endif\n");
94 fout = fopen(argv[2], "w");
96 fprintf(stderr, "Could not open %s for writing: %s\n",
97 argv[2], strerror(errno));
101 fprintf(fout, "/* This file is automatically generated. Do not edit. */\n");
102 fprintf(fout, "#ifndef _SELINUX_AV_PERMISSIONS_H_\n#define _SELINUX_AV_PERMISSIONS_H_\n\n");
104 for (i = 0; secclass_map[i].name; i++) {
105 struct security_class_mapping *map = &secclass_map[i];
106 for (j = 0; map->perms[j]; j++) {
107 fprintf(fout, "#define %s__%s", map->name,
109 for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++)
111 fprintf(fout, "0x%08xUL\n", (1<<j));
115 fprintf(fout, "\n#endif\n");