<commit_before>/*
 * viraudit.c: auditing support
 *
 * Copyright (C) 2010-2011 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

#include <config.h>

#ifdef WITH_AUDIT
# include <libaudit.h>
#endif
#include <unistd.h>

#include "virerror.h"
#include "virlog.h"
#include "viraudit.h"
#include "virfile.h"
#include "viralloc.h"
#include "virstring.h"

VIR_LOG_INIT("util.audit");

/* Provide the macros in case the header file is old.
   FIXME: should be removed. */
#ifndef AUDIT_VIRT_CONTROL
# define AUDIT_VIRT_CONTROL              2500 /* Start, Pause, Stop VM */
#endif
#ifndef AUDIT_VIRT_RESOURCE
# define AUDIT_VIRT_RESOURCE             2501 /* Resource assignment */
#endif
#ifndef AUDIT_VIRT_MACHINE_ID
# define AUDIT_VIRT_MACHINE_ID           2502 /* Binding of label to VM */
#endif

#define VIR_FROM_THIS VIR_FROM_AUDIT

#if WITH_AUDIT
static int auditfd = -1;
#endif
static bool auditlog;

int virAuditOpen(unsigned int audit_level G_GNUC_UNUSED)
{
#if WITH_AUDIT
    if ((auditfd = audit_open()) < 0) {
        /* You get these error codes only when the kernel does not
         * have audit compiled in or it's disabled (e.g. by the kernel
         * cmdline) */
        if (errno == EINVAL || errno == EPROTONOSUPPORT ||
            errno == EAFNOSUPPORT) {
            if (audit_level < 2)
                VIR_INFO("Audit is not supported by the kernel");
            else
                virReportError(VIR_FROM_THIS, "%s", _("Audit is not supported by the kernel"));
        } else {
            virReportSystemError(errno, "%s", _("Unable to initialize audit layer"));
        }

        return -1;
    }

    return 0;<commit_msg>util: audit: drop support for old libaudit<commit_after>/*
 * viraudit.c: auditing support
 *
 * Copyright (C) 2010-2011 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 */

#include <config.h>

#ifdef WITH_AUDIT
# include <libaudit.h>
#endif
#include <unistd.h>

#include "virerror.h"
#include "virlog.h"
#include "viraudit.h"
#include "virfile.h"
#include "viralloc.h"
#include "virstring.h"

VIR_LOG_INIT("util.audit");

#define VIR_FROM_THIS VIR_FROM_AUDIT

#if WITH_AUDIT
static int auditfd = -1;
#endif
static bool auditlog;

int virAuditOpen(unsigned int audit_level G_GNUC_UNUSED)
{
#if WITH_AUDIT
    if ((auditfd = audit_open()) < 0) {
        /* You get these error codes only when the kernel does not
         * have audit compiled in or it's disabled (e.g. by the kernel
         * cmdline) */
        if (errno == EINVAL || errno == EPROTONOSUPPORT ||
            errno == EAFNOSUPPORT) {
            if (audit_level < 2)
                VIR_INFO("Audit is not supported by the kernel");
            else
                virReportError(VIR_FROM_THIS, "%s", _("Audit is not supported by the kernel"));
        } else {
            virReportSystemError(errno, "%s", _("Unable to initialize audit layer"));
        }

        return -1;
    }

    return 0;
{'fraction_non_alphanumeric': 0.09455927773818008, 'fraction_numerical': 0.009978617248752673, 'mean_word_length': 2.9867424242424243, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '767000', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1283, 'n_words': 488}