OpenCoverage

getfilecon.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/getfilecon.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* wrap getfilecon, lgetfilecon, and fgetfilecon-
2 Copyright (C) 2009-2018 Free Software Foundation, Inc.-
3-
4 This program is free software; you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation; either version 3, or (at your option)-
7 any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program; if not, see <https://www.gnu.org/licenses/>. */-
16-
17/* written by Jim Meyering */-
18-
19#include <config.h>-
20-
21#include <selinux/selinux.h>-
22-
23#include <sys/types.h>-
24#include <errno.h>-
25#include <string.h>-
26-
27/* FIXME: remove this once there is an errno-gnu module-
28 that guarantees the definition of ENODATA. */-
29#ifndef ENODATA-
30# define ENODATA ENOTSUP-
31#endif-
32-
33#undef getfilecon-
34#undef lgetfilecon-
35#undef fgetfilecon-
36int getfilecon (char const *file, security_context_t *con);-
37int lgetfilecon (char const *file, security_context_t *con);-
38int fgetfilecon (int fd, security_context_t *con);-
39-
40/* getfilecon, lgetfilecon, and fgetfilecon can all misbehave, be it-
41 via an old version of libselinux where these would return 0 and set the-
42 result context to NULL, or via a modern kernel+lib operating on a file-
43 from a disk whose attributes were set by a kernel from around 2006.-
44 In that latter case, the functions return a length of 10 for the-
45 "unlabeled" context. Map both failures to a return value of -1, and-
46 set errno to ENOTSUP in the first case, and ENODATA in the latter. */-
47-
48static int-
49map_to_failure (int ret, security_context_t *con)-
50{-
51 if (ret == 0)
ret == 0Description
TRUEnever evaluated
FALSEevaluated 160 times by 2 tests
Evaluated by:
  • ls
  • vdir
0-160
52 {-
53 errno = ENOTSUP;-
54 return -1;
never executed: return -1;
0
55 }-
56-
57 if (ret == 10 && strcmp (*con, "unlabeled") == 0)
never executed: __result = (((const unsigned char *) (const char *) ( *con ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( "unlabeled" ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
ret == 10Description
TRUEnever evaluated
FALSEevaluated 160 times by 2 tests
Evaluated by:
  • ls
  • vdir
__extension__ ... )))); }) == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-160
58 {-
59 freecon (*con);-
60 *con = NULL;-
61 errno = ENODATA;-
62 return -1;
never executed: return -1;
0
63 }-
64-
65 return ret;
executed 160 times by 2 tests: return ret;
Executed by:
  • ls
  • vdir
160
66}-
67-
68int-
69rpl_getfilecon (char const *file, security_context_t *con)-
70{-
71 int ret = getfilecon (file, con);-
72 return map_to_failure (ret, con);
never executed: return map_to_failure (ret, con);
0
73}-
74-
75int-
76rpl_lgetfilecon (char const *file, security_context_t *con)-
77{-
78 int ret = lgetfilecon (file, con);-
79 return map_to_failure (ret, con);
executed 160 times by 2 tests: return map_to_failure (ret, con);
Executed by:
  • ls
  • vdir
160
80}-
81-
82int-
83rpl_fgetfilecon (int fd, security_context_t *con)-
84{-
85 int ret = fgetfilecon (fd, con);-
86 return map_to_failure (ret, con);
never executed: return map_to_failure (ret, con);
0
87}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2