LCOV - code coverage report
Current view: top level - core - audit-fd.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 0 19 0.0 %
Date: 2019-08-22 15:41:25 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : 
       3             : #include <errno.h>
       4             : 
       5             : #include "audit-fd.h"
       6             : 
       7             : #if HAVE_AUDIT
       8             : 
       9             : #include <libaudit.h>
      10             : #include <stdbool.h>
      11             : 
      12             : #include "capability-util.h"
      13             : #include "fd-util.h"
      14             : #include "log.h"
      15             : #include "util.h"
      16             : 
      17             : static bool initialized = false;
      18             : static int audit_fd;
      19             : 
      20           0 : int get_audit_fd(void) {
      21             : 
      22           0 :         if (!initialized) {
      23           0 :                 if (have_effective_cap(CAP_AUDIT_WRITE) == 0) {
      24           0 :                         audit_fd = -EPERM;
      25           0 :                         initialized = true;
      26             : 
      27           0 :                         return audit_fd;
      28             :                 }
      29             : 
      30           0 :                 audit_fd = audit_open();
      31             : 
      32           0 :                 if (audit_fd < 0) {
      33           0 :                         if (!IN_SET(errno, EAFNOSUPPORT, EPROTONOSUPPORT))
      34           0 :                                 log_error_errno(errno, "Failed to connect to audit log: %m");
      35             : 
      36           0 :                         audit_fd = errno ? -errno : -EINVAL;
      37             :                 }
      38             : 
      39           0 :                 initialized = true;
      40             :         }
      41             : 
      42           0 :         return audit_fd;
      43             : }
      44             : 
      45           0 : void close_audit_fd(void) {
      46             : 
      47           0 :         if (initialized && audit_fd >= 0)
      48           0 :                 safe_close(audit_fd);
      49             : 
      50           0 :         initialized = true;
      51           0 :         audit_fd = -ECONNRESET;
      52           0 : }
      53             : 
      54             : #else
      55             : 
      56             : int get_audit_fd(void) {
      57             :         return -EAFNOSUPPORT;
      58             : }
      59             : 
      60             : void close_audit_fd(void) {
      61             : }
      62             : 
      63             : #endif

Generated by: LCOV version 1.14