liyujie
2025-08-28 786ff4f4ca2374bdd9177f2e24b503d43e7a3b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "selinux_internal.h"
#include "context_internal.h"
 
int selinux_check_securetty_context(const char * tty_context)
{
   char *line = NULL;
   char *start, *end = NULL;
   size_t line_len = 0;
   ssize_t len;
   int found = -1;
   FILE *fp;
   fp = fopen(selinux_securetty_types_path(), "re");
   if (fp) {
       context_t con = context_new(tty_context);
       if (con) {
           const char *type = context_type_get(con);
           while ((len = getline(&line, &line_len, fp)) != -1) {
 
               if (line[len - 1] == '\n')
                   line[len - 1] = 0;
 
               /* Skip leading whitespace. */
               start = line;
               while (*start && isspace(*start))
                   start++;
               if (!(*start))
                   continue;
 
               end = start;
               while (*end && !isspace(*end))
                   end++;
               if (*end)
                   *end++ = 0;
               if (!strcmp(type, start)) {
                   found = 0;
                   break;
               }
           }
           free(line);
           context_free(con);
       }
       fclose(fp);
   }
 
   return found;
}
 
hidden_def(selinux_check_securetty_context)