Function naughtyfy::api::fanotify_init
source · Expand description
Initializes a new fanotify group and returns a file descriptor for the event queue associated with the group.
The file descriptor is used in calls to fanotify_mark() to
specify the files, directories, mounts, or filesystems for which
fanotify events shall be created. These events are received by
reading from the file descriptor. Some events are only
informative, indicating that a file has been accessed. Other
events can be used to determine whether another application is
permitted to access a file or directory. Permission to access
filesystem objects is granted by writing to the file descriptor.
Multiple programs may be using the fanotify interface at the same time to monitor the same files.
In the current implementation, the number of fanotify groups per user is limited to 128. This limit cannot be overridden.
Calling fanotify_init() requires the CAP_SYS_ADMIN capability.
This constraint might be relaxed in future versions of the API.
Therefore, certain additional capability checks have been
implemented as indicated below.
The flags argument contains a multi-bit field defining the notification class of the listening application and further single bit fields specifying the behavior of the file descriptor.
If multiple listeners for permission events exist, the notification class is used to establish the sequence in which the listeners receive the events.
Arguments
-
flags- Sets the notification group, can be mask ofThe following bits can additionally be set in
flags: -
event_f_flags- Defines the file status flags that will be set on the open file descriptions that are created for fanotify events. For details of these flags, see the description of the flags values in open(2).event_f_flagsincludes a multi- bit field for the access mode. This field can take the following values:Additional bits can be set in
event_f_flags.
Example
This example will panic due to absence of CAP_SYS_ADMIN capabilitity
let fd = fanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK, O_RDONLY);