merge lchown variants
[trinity.git] / taint.c
blob9c2eca706d7affbbfdff1a3d09e5e24de53c4c64
1 #include <stdlib.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include "log.h"
8 #include "params.h"
9 #include "types.h"
10 #include "taint.h"
12 int kernel_taint_initial = 0;
14 int check_tainted(void)
16 int fd;
17 unsigned int ret;
18 char buffer[11];
20 buffer[10] = 0; //make sure that we can fit the whole int.
22 fd = open("/proc/sys/kernel/tainted", O_RDONLY);
23 if (fd < 0)
24 return -1;
25 ret = read(fd, buffer, 10);
26 close(fd);
28 if (ret > 0)
29 ret = atoi(buffer);
30 else {
31 /* We should never fail, but if we do, assume untainted. */
32 ret = 0;
35 return ret;
38 static void toggle_taint_flag(int bit)
40 kernel_taint_mask |= (1 << bit);
43 static void toggle_taint_flag_by_name(char *beg, char *end)
45 char flagname[TAINT_NAME_LEN];
46 char *name;
48 if (end == NULL) {
49 name = beg;
50 } else {
51 int maxlen;
53 name = flagname;
54 maxlen = end - beg;
55 if (maxlen > (TAINT_NAME_LEN - 1))
56 maxlen = TAINT_NAME_LEN - 1;
57 strncpy(flagname, beg, maxlen);
58 flagname[maxlen] = 0;
61 if (strcmp(name,"PROPRIETARY_MODULE") == 0)
62 toggle_taint_flag(TAINT_PROPRIETARY_MODULE);
63 else if (strcmp(name,"FORCED_MODULE") == 0)
64 toggle_taint_flag(TAINT_FORCED_MODULE);
65 else if (strcmp(name,"UNSAFE_SMP") == 0)
66 toggle_taint_flag(TAINT_UNSAFE_SMP);
67 else if (strcmp(name,"FORCED_RMMOD") == 0)
68 toggle_taint_flag(TAINT_FORCED_RMMOD);
69 else if (strcmp(name,"MACHINE_CHECK") == 0)
70 toggle_taint_flag(TAINT_MACHINE_CHECK);
71 else if (strcmp(name,"BAD_PAGE") == 0)
72 toggle_taint_flag(TAINT_BAD_PAGE);
73 else if (strcmp(name,"USER") == 0)
74 toggle_taint_flag(TAINT_USER);
75 else if (strcmp(name,"DIE") == 0)
76 toggle_taint_flag(TAINT_DIE);
77 else if (strcmp(name,"OVERRIDDEN_ACPI_TABLE") == 0)
78 toggle_taint_flag(TAINT_OVERRIDDEN_ACPI_TABLE);
79 else if (strcmp(name,"WARN") == 0)
80 toggle_taint_flag(TAINT_WARN);
81 else if (strcmp(name,"CRAP") == 0)
82 toggle_taint_flag(TAINT_CRAP);
83 else if (strcmp(name,"FIRMWARE_WORKAROUND") == 0)
84 toggle_taint_flag(TAINT_FIRMWARE_WORKAROUND);
85 else if (strcmp(name,"OOT_MODULE") == 0)
86 toggle_taint_flag(TAINT_OOT_MODULE);
87 else {
88 outputerr("Unrecognizable kernel taint flag \"%s\".\n", name);
89 exit(EXIT_FAILURE);
93 void process_taint_arg(char *taintarg)
95 char *beg, *end;
97 if (kernel_taint_param_occured == FALSE) {
98 kernel_taint_param_occured = TRUE;
99 kernel_taint_mask = 0; //We now only care about flags that user specified.
102 beg = taintarg;
103 end = strchr(beg, ',');
104 while(end != NULL) {
105 toggle_taint_flag_by_name(beg,end);
106 beg = end + 1;
107 end = strchr(beg, ',');
109 toggle_taint_flag_by_name(beg,end);