| $ git diff libselinux/src/selinux_check_securetty_context.c
|
| diff --git a/libselinux/src/selinux_check_securetty_context.c b/libselinux/src/selinux_check_securetty_context.c
|
| index 7609752e..5d8590a5 100644
|
| --- a/libselinux/src/selinux_check_securetty_context.c
|
| +++ b/libselinux/src/selinux_check_securetty_context.c
|
| @@ -1,3 +1,4 @@
|
| +#include <fcntl.h>
|
| #include <unistd.h>
|
| #include <stdlib.h>
|
| #include <string.h>
|
| @@ -8,45 +9,55 @@
|
|
|
| int selinux_check_securetty_context(const char * tty_context)
|
| {
|
| + context_t con = context_new(tty_context);
|
| + if (!con) {
|
| + return -1;
|
| + }
|
| +
|
| + FILE *fp = fopen(selinux_securetty_types_path(), "re");
|
| + if (!fp) {
|
| + return -1;
|
| + }
|
| +
|
| + const char *type = context_type_get(con);
|
| +
|
| char *line = NULL;
|
| - char *start, *end = NULL;
|
| + char *start = NULL;
|
| + char *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((unsigned char)*start))
|
| - start++;
|
| - if (!(*start))
|
| - continue;
|
| -
|
| - end = start;
|
| - while (*end && !isspace((unsigned char)*end))
|
| - end++;
|
| - if (*end)
|
| - *end++ = 0;
|
| - if (!strcmp(type, start)) {
|
| - found = 0;
|
| - break;
|
| - }
|
| - }
|
| - free(line);
|
| - context_free(con);
|
| + ssize_t len;
|
| + 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((unsigned char)*start)) {
|
| + start++;
|
| + }
|
| + if (!(*start)) {
|
| + continue;
|
| + }
|
| +
|
| + end = start;
|
| + while (*end && !isspace((unsigned char)*end)) {
|
| + end++;
|
| + }
|
| + if (*end) {
|
| + *end++ = 0;
|
| + }
|
| + if (!strcmp(type, start)) {
|
| + found = 0;
|
| + break;
|
| }
|
| - fclose(fp);
|
| }
|
|
|
| + free(line);
|
| + context_free(con);
|
| + fclose(fp);
|
| +
|
| return found;
|
| }
|
| -
|