| 1 |
.TH "matchpathcon" "3" "21 November 2009" "[email protected]" "SELinux API documentation" |
| 2 |
.SH "NAME" |
| 3 |
matchpathcon, matchpathcon_index \- get the default SELinux security context for the specified path from the file contexts configuration |
| 4 |
. |
| 5 |
.SH "SYNOPSIS" |
| 6 |
.B #include <selinux/selinux.h> |
| 7 |
.sp |
| 8 |
.BI "int matchpathcon_init(const char *" path ");" |
| 9 |
.sp |
| 10 |
.BI "int matchpathcon_init_prefix(const char *" path ", const char *" prefix ");" |
| 11 |
.sp |
| 12 |
.BI "int matchpathcon_fini(void);" |
| 13 |
.sp |
| 14 |
.BI "int matchpathcon(const char *" path ", mode_t " mode ", char **" con "); |
| 15 |
.sp |
| 16 |
.BI "int matchpathcon_index(const char *" name ", mode_t " mode ", char **" con ");" |
| 17 |
. |
| 18 |
.SH "DESCRIPTION" |
| 19 |
|
| 20 |
This family of functions is deprecated. For new code, please use |
| 21 |
.BR selabel_open (3) |
| 22 |
with the |
| 23 |
.B SELABEL_CTX_FILE |
| 24 |
backend in place of |
| 25 |
.BR matchpathcon_init (), |
| 26 |
use |
| 27 |
.BR selabel_close (3) |
| 28 |
in place of |
| 29 |
.BR matchpathcon_fini (), |
| 30 |
and use |
| 31 |
.BR selabel_lookup (3) |
| 32 |
in place of |
| 33 |
.BR matchpathcon (). |
| 34 |
|
| 35 |
The remaining description below is for the legacy interface. |
| 36 |
|
| 37 |
.BR matchpathcon_init () |
| 38 |
loads the file contexts configuration specified by |
| 39 |
.I path |
| 40 |
into memory for use by subsequent |
| 41 |
.BR matchpathcon () |
| 42 |
calls. If |
| 43 |
.I path |
| 44 |
is NULL, then the active file contexts configuration is loaded by default, |
| 45 |
i.e. the path returned by |
| 46 |
.BR selinux_file_context_path (3). |
| 47 |
Unless the |
| 48 |
.B MATCHPATHCON_BASEONLY |
| 49 |
flag has been set via |
| 50 |
.BR \%set_matchpathcon_flags (3), |
| 51 |
files with the same path prefix but a |
| 52 |
.B \%.homedirs |
| 53 |
and |
| 54 |
.B .local |
| 55 |
suffix are also looked up and loaded if present. These files provide |
| 56 |
dynamically generated entries for user home directories and for local |
| 57 |
customizations. |
| 58 |
|
| 59 |
.BR matchpathcon_init_prefix () |
| 60 |
is the same as |
| 61 |
.BR matchpathcon_init () |
| 62 |
but only loads entries with regular expressions whose first pathname |
| 63 |
component is a prefix of |
| 64 |
.I \%prefix |
| 65 |
, e.g. pass "/dev" if you only intend to call |
| 66 |
.BR matchpathcon () |
| 67 |
with pathnames beginning with /dev. |
| 68 |
However, this optimization is no longer necessary due to the use of |
| 69 |
.I file_contexts.bin |
| 70 |
files with precompiled regular expressions, so use of this interface |
| 71 |
is deprecated. |
| 72 |
|
| 73 |
.BR matchpathcon_fini () |
| 74 |
frees the memory allocated by a prior call to |
| 75 |
.BR matchpathcon_init. () |
| 76 |
This function can be used to free and reset the internal state between multiple |
| 77 |
.BR matchpathcon_init () |
| 78 |
calls, or to free memory when finished using |
| 79 |
.BR matchpathcon (). |
| 80 |
|
| 81 |
.BR matchpathcon () |
| 82 |
matches the specified |
| 83 |
.I pathname, |
| 84 |
after transformation via |
| 85 |
.BR realpath (3) |
| 86 |
excepting any final symbolic link component if S_IFLNK was |
| 87 |
specified as the |
| 88 |
.I mode, |
| 89 |
and |
| 90 |
.I mode |
| 91 |
against the |
| 92 |
.I file contexts |
| 93 |
configuration and sets the security context |
| 94 |
.I con |
| 95 |
to refer to the |
| 96 |
resulting context. The caller must free the returned security context |
| 97 |
.I con |
| 98 |
using |
| 99 |
.BR freecon (3) |
| 100 |
when finished using it. |
| 101 |
.I mode |
| 102 |
can be 0 to disable mode matching, but |
| 103 |
should be provided whenever possible, as it may affect the matching. |
| 104 |
Only the file format bits (i.e. the file type) of the |
| 105 |
.I mode |
| 106 |
are used. |
| 107 |
If |
| 108 |
.BR matchpathcon_init () |
| 109 |
has not already been called, then this function will call it upon |
| 110 |
its first invocation with a NULL |
| 111 |
.I path, |
| 112 |
defaulting to the active file contexts configuration. |
| 113 |
|
| 114 |
.BR matchpathcon_index () |
| 115 |
is the same as |
| 116 |
.BR matchpathcon () |
| 117 |
but returns a specification index that can later be used in a |
| 118 |
.BR matchpathcon_filespec_add (3) |
| 119 |
call. |
| 120 |
. |
| 121 |
.SH "RETURN VALUE" |
| 122 |
Returns zero on success or \-1 otherwise. |
| 123 |
. |
| 124 |
.SH "SEE ALSO" |
| 125 |
.ad l |
| 126 |
.nh |
| 127 |
.BR selinux "(8), " set_matchpathcon_flags "(3), " set_matchpathcon_invalidcon "(3), " set_matchpathcon_printf "(3), " matchpathcon_filespec_add "(3), " matchpathcon_checkmatches "(3), " freecon "(3), " setfilecon "(3), " setfscreatecon "(3)" |