1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* wrap getfilecon, lgetfilecon, and fgetfilecon
4 Copyright (C) 2009-2014 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>. */
19 /* written by Jim Meyering */
23 #include <selinux/selinux.h>
25 #include <sys/types.h>
29 /* FIXME: remove this once there is an errno-gnu module
30 that guarantees the definition of ENODATA. */
32 # define ENODATA ENOTSUP
38 int getfilecon (char const *file, security_context_t *con);
39 int lgetfilecon (char const *file, security_context_t *con);
40 int fgetfilecon (int fd, security_context_t *con);
42 /* getfilecon, lgetfilecon, and fgetfilecon can all misbehave, be it
43 via an old version of libselinux where these would return 0 and set the
44 result context to NULL, or via a modern kernel+lib operating on a file
45 from a disk whose attributes were set by a kernel from around 2006.
46 In that latter case, the functions return a length of 10 for the
47 "unlabeled" context. Map both failures to a return value of -1, and
48 set errno to ENOTSUP in the first case, and ENODATA in the latter. */
51 map_to_failure (int ret, security_context_t *con)
59 if (ret == 10 && strcmp (*con, "unlabeled") == 0)
70 rpl_getfilecon (char const *file, security_context_t *con)
72 int ret = getfilecon (file, con);
73 return map_to_failure (ret, con);
77 rpl_lgetfilecon (char const *file, security_context_t *con)
79 int ret = lgetfilecon (file, con);
80 return map_to_failure (ret, con);
84 rpl_fgetfilecon (int fd, security_context_t *con)
86 int ret = fgetfilecon (fd, con);
87 return map_to_failure (ret, con);