SELinux: Auto-generate security_is_socket_class
authorHarry Ciao <qingtao.cao@windriver.com>
Wed, 2 Mar 2011 05:46:08 +0000 (13:46 +0800)
committerEric Paris <eparis@redhat.com>
Thu, 3 Mar 2011 20:19:43 +0000 (15:19 -0500)
The security_is_socket_class() is auto-generated by genheaders based
on classmap.h to reduce maintenance effort when a new class is defined
in SELinux kernel. The name for any socket class should be suffixed by
"socket" and doesn't contain more than one substr of "socket".

Signed-off-by: Harry Ciao <qingtao.cao@windriver.com>
Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
scripts/selinux/genheaders/genheaders.c
security/selinux/include/classmap.h

index 58a12c27870638d522cca54bef07e5f176b38748..539855ff31f977f32a1afbc16b35c9bfc2df6387 100644 (file)
@@ -43,6 +43,8 @@ int main(int argc, char *argv[])
        int i, j, k;
        int isids_len;
        FILE *fout;
+       const char *needle = "SOCKET";
+       char *substr;
 
        progname = argv[0];
 
@@ -88,6 +90,24 @@ int main(int argc, char *argv[])
                fprintf(fout, "%2d\n", i);
        }
        fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1);
+       fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n");
+       fprintf(fout, "{\n");
+       fprintf(fout, "\tbool sock = false;\n\n");
+       fprintf(fout, "\tswitch (kern_tclass) {\n");
+       for (i = 0; secclass_map[i].name; i++) {
+               struct security_class_mapping *map = &secclass_map[i];
+               substr = strstr(map->name, needle);
+               if (substr && strcmp(substr, needle) == 0)
+                       fprintf(fout, "\tcase SECCLASS_%s:\n", map->name);
+       }
+       fprintf(fout, "\t\tsock = true;\n");
+       fprintf(fout, "\t\tbreak;\n");
+       fprintf(fout, "\tdefault:\n");
+       fprintf(fout, "\t\tbreak;\n");
+       fprintf(fout, "\t}\n\n");
+       fprintf(fout, "\treturn sock;\n");
+       fprintf(fout, "}\n");
+
        fprintf(fout, "\n#endif\n");
        fclose(fout);
 
index 4227e5fa7861bf2a350efca9ea352e12ccf61636..b8c53723e09bfe7d6c211bc05df35793ae9ac8b2 100644 (file)
 #define COMMON_IPC_PERMS "create", "destroy", "getattr", "setattr", "read", \
            "write", "associate", "unix_read", "unix_write"
 
+/*
+ * Note: The name for any socket class should be suffixed by "socket",
+ *      and doesn't contain more than one substr of "socket".
+ */
 struct security_class_mapping secclass_map[] = {
        { "security",
          { "compute_av", "compute_create", "compute_member",