Commit a40612ef authored by Al Viro's avatar Al Viro

genheaders: %-<width>s had been there since v6; %-*s - since v7

Please, use at least K&R C; printf had been able to left-adjust
a field for as long as stdio existed and use of '*' for variable
width had been there since v7.  Yes, the first edition of K&R
didn't cover the latter feature (it slightly predates v7), but
you are using a much later feature of the language than that -
in K&R C
static char *stoupperx(const char *s)
{
...
}
would've been spelled as
static char *stoupperx(s)
char *s;
{
...
}

While we are at it, the use of strstr() is bogus - it finds the
_first_ instance of substring, so it's a lousy fit for checking
if a string ends with given suffix...
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 65102238
...@@ -19,8 +19,6 @@ struct security_class_mapping { ...@@ -19,8 +19,6 @@ struct security_class_mapping {
#include "classmap.h" #include "classmap.h"
#include "initial_sid_to_string.h" #include "initial_sid_to_string.h"
#define max(x, y) (((int)(x) > (int)(y)) ? x : y)
const char *progname; const char *progname;
static void usage(void) static void usage(void)
...@@ -46,11 +44,9 @@ static char *stoupperx(const char *s) ...@@ -46,11 +44,9 @@ static char *stoupperx(const char *s)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i, j, k; int i, j;
int isids_len; int isids_len;
FILE *fout; FILE *fout;
const char *needle = "SOCKET";
char *substr;
progname = argv[0]; progname = argv[0];
...@@ -80,20 +76,14 @@ int main(int argc, char *argv[]) ...@@ -80,20 +76,14 @@ int main(int argc, char *argv[])
for (i = 0; secclass_map[i].name; i++) { for (i = 0; secclass_map[i].name; i++) {
struct security_class_mapping *map = &secclass_map[i]; struct security_class_mapping *map = &secclass_map[i];
fprintf(fout, "#define SECCLASS_%s", map->name); fprintf(fout, "#define SECCLASS_%-39s %2d\n", map->name, i+1);
for (j = 0; j < max(1, 40 - strlen(map->name)); j++)
fprintf(fout, " ");
fprintf(fout, "%2d\n", i+1);
} }
fprintf(fout, "\n"); fprintf(fout, "\n");
for (i = 1; i < isids_len; i++) { for (i = 1; i < isids_len; i++) {
const char *s = initial_sid_to_string[i]; const char *s = initial_sid_to_string[i];
fprintf(fout, "#define SECINITSID_%s", s); fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i);
for (j = 0; j < max(1, 40 - strlen(s)); j++)
fprintf(fout, " ");
fprintf(fout, "%2d\n", i);
} }
fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); 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, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n");
...@@ -101,9 +91,10 @@ int main(int argc, char *argv[]) ...@@ -101,9 +91,10 @@ int main(int argc, char *argv[])
fprintf(fout, "\tbool sock = false;\n\n"); fprintf(fout, "\tbool sock = false;\n\n");
fprintf(fout, "\tswitch (kern_tclass) {\n"); fprintf(fout, "\tswitch (kern_tclass) {\n");
for (i = 0; secclass_map[i].name; i++) { for (i = 0; secclass_map[i].name; i++) {
static char s[] = "SOCKET";
struct security_class_mapping *map = &secclass_map[i]; struct security_class_mapping *map = &secclass_map[i];
substr = strstr(map->name, needle); int len = strlen(map->name), l = sizeof(s) - 1;
if (substr && strcmp(substr, needle) == 0) if (len >= l && memcmp(map->name + len - l, s, l) == 0)
fprintf(fout, "\tcase SECCLASS_%s:\n", map->name); fprintf(fout, "\tcase SECCLASS_%s:\n", map->name);
} }
fprintf(fout, "\t\tsock = true;\n"); fprintf(fout, "\t\tsock = true;\n");
...@@ -129,17 +120,15 @@ int main(int argc, char *argv[]) ...@@ -129,17 +120,15 @@ int main(int argc, char *argv[])
for (i = 0; secclass_map[i].name; i++) { for (i = 0; secclass_map[i].name; i++) {
struct security_class_mapping *map = &secclass_map[i]; struct security_class_mapping *map = &secclass_map[i];
int len = strlen(map->name);
for (j = 0; map->perms[j]; j++) { for (j = 0; map->perms[j]; j++) {
if (j >= 32) { if (j >= 32) {
fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n", fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n",
map->name, map->perms[j]); map->name, map->perms[j]);
exit(5); exit(5);
} }
fprintf(fout, "#define %s__%s", map->name, fprintf(fout, "#define %s__%-*s 0x%08xU\n", map->name,
map->perms[j]); 39-len, map->perms[j], 1U<<j);
for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++)
fprintf(fout, " ");
fprintf(fout, "0x%08xU\n", (1<<j));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment