| 1 |
.TH "selabel_lookup_best_match" "3" "05 May 2015" "Security Enhanced Linux" "SELinux API documentation" |
| 2 |
|
| 3 |
.SH "NAME" |
| 4 |
selabel_lookup_best_match \- obtain a best match SELinux security |
| 5 |
context \- Only supported on file backend. |
| 6 |
. |
| 7 |
.SH "SYNOPSIS" |
| 8 |
.B #include <selinux/selinux.h> |
| 9 |
.br |
| 10 |
.B #include <selinux/label.h> |
| 11 |
.sp |
| 12 |
.BI "int selabel_lookup_best_match(struct selabel_handle *" hnd , |
| 13 |
.in +\w'int selabel_lookup_best_match('u |
| 14 |
.BI "char **" context , |
| 15 |
.br |
| 16 |
.BI "const char *" key , |
| 17 |
.br |
| 18 |
.BI "const char **" links , |
| 19 |
.br |
| 20 |
.BI "int " type ");" |
| 21 |
.in |
| 22 |
.sp |
| 23 |
.BI "int selabel_lookup_best_match_raw(struct selabel_handle *" hnd , |
| 24 |
.in +\w'int selabel_lookup_best_match_raw('u |
| 25 |
.BI "char **" context , |
| 26 |
.br |
| 27 |
.BI "const char *" key , |
| 28 |
.br |
| 29 |
.BI "const char **" links , |
| 30 |
.br |
| 31 |
.BI "int " type ");" |
| 32 |
.in |
| 33 |
. |
| 34 |
.SH "DESCRIPTION" |
| 35 |
.BR selabel_lookup_best_match () |
| 36 |
performs a best match lookup operation on the handle |
| 37 |
.IR hnd , |
| 38 |
returning the result in the memory pointed to by |
| 39 |
.IR context , |
| 40 |
which must be freed by the caller using |
| 41 |
.BR freecon (3). |
| 42 |
The \fIkey\fR parameter is a file path to check for best match using zero or |
| 43 |
more \fIlink\fR (aliases) parameters. The order of precedence for best match is: |
| 44 |
.RS |
| 45 |
.IP "1." 4 |
| 46 |
An exact match for the real path (\fIkey\fR) or |
| 47 |
.IP "2." 4 |
| 48 |
An exact match for any of the \fIlink\fRs (aliases), or |
| 49 |
.IP "3." 4 |
| 50 |
The longest fixed prefix match. |
| 51 |
.RE |
| 52 |
.sp |
| 53 |
The \fItype\fR parameter is an optional file \fImode\fR argument that should |
| 54 |
be set to the mode bits of the file, as determined by \fBlstat\fR(2). |
| 55 |
\fImode\fR may be zero, however full matching may not occur. |
| 56 |
|
| 57 |
.BR selabel_lookup_best_match_raw () |
| 58 |
behaves identically to |
| 59 |
.BR selabel_lookup_best_match () |
| 60 |
but does not perform context translation. |
| 61 |
. |
| 62 |
.SH "RETURN VALUE" |
| 63 |
On success, zero is returned. On error, \-1 is returned and |
| 64 |
.I errno |
| 65 |
is set appropriately. |
| 66 |
. |
| 67 |
.SH "ERRORS" |
| 68 |
.TP |
| 69 |
.B ENOENT |
| 70 |
No context corresponding to the input |
| 71 |
.I key |
| 72 |
and |
| 73 |
.I type |
| 74 |
was found. |
| 75 |
.TP |
| 76 |
.B EINVAL |
| 77 |
The |
| 78 |
.I key |
| 79 |
and/or |
| 80 |
.I type |
| 81 |
inputs are invalid, or the context being returned failed validation. |
| 82 |
.TP |
| 83 |
.B ENOMEM |
| 84 |
An attempt to allocate memory failed. |
| 85 |
.sp |
| 86 |
.SH "NOTES" |
| 87 |
Example usage - When a service creates a device node, it may also create one |
| 88 |
or more symlinks to the device node. These symlinks may be the only stable |
| 89 |
name for the device, e.g. if the partition is dynamically assigned. |
| 90 |
The file label backend supports this by looking up the "best match" |
| 91 |
for a device node based on its real path (\fIkey\fR) and any \fIlink\fRs to it |
| 92 |
(aliases). The order of precedence for best match is described above. |
| 93 |
.sp |
| 94 |
.SH "SEE ALSO" |
| 95 |
.BR selabel_open (3), |
| 96 |
.BR selabel_stats (3), |
| 97 |
.BR selinux_set_callback (3), |
| 98 |
.BR selinux (8), |
| 99 |
.BR lstat (2), |
| 100 |
.BR selabel_file (5) |