Coverage Report

Created: 2025-11-11 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/selinux/libselinux/src/lsetfilecon.c
Line
Count
Source
1
#include <unistd.h>
2
#include <fcntl.h>
3
#include <string.h>
4
#include <stdlib.h>
5
#include <errno.h>
6
#include <sys/xattr.h>
7
#include "selinux_internal.h"
8
#include "policy.h"
9
10
int lsetfilecon_raw(const char *path, const char * context)
11
0
{
12
0
  int rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
13
0
       0);
14
0
  if (rc < 0 && errno == ENOTSUP) {
15
0
    char * ccontext = NULL;
16
0
    int err = errno;
17
0
    if ((lgetfilecon_raw(path, &ccontext) >= 0) &&
18
0
        (strcmp(context,ccontext) == 0)) {
19
0
      rc = 0;
20
0
    } else {
21
0
      errno = err;
22
0
    }
23
0
    freecon(ccontext);
24
0
  }
25
0
  return rc;
26
0
}
27
28
29
int lsetfilecon(const char *path, const char *context)
30
0
{
31
0
  int ret;
32
0
  char * rcontext;
33
34
0
  if (selinux_trans_to_raw_context(context, &rcontext))
35
0
    return -1;
36
37
0
  ret = lsetfilecon_raw(path, rcontext);
38
39
0
  freecon(rcontext);
40
41
0
  return ret;
42
0
}