viraudit.h 1.8 KB
Newer Older
1
/*
2
 * viraudit.h: auditing support
3
 *
E
Eric Blake 已提交
4
 * Copyright (C) 2010-2011, 2014 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21
 *
 */

22
#pragma once
23

24 25
#include "internal.h"
#include "virlog.h"
26

27
typedef enum {
28 29 30
    VIR_AUDIT_RECORD_MACHINE_CONTROL,
    VIR_AUDIT_RECORD_MACHINE_ID,
    VIR_AUDIT_RECORD_RESOURCE,
31
} virAuditRecordType;
32

33
int virAuditOpen(unsigned int audit_level);
34

E
Eric Blake 已提交
35
void virAuditLog(bool enabled);
36

37 38
void virAuditSend(virLogSourcePtr source,
                  const char *filename, size_t linenr, const char *funcname,
39
                  const char *clienttty, const char *clientaddr,
40
                  virAuditRecordType type, bool success,
41
                  const char *fmt, ...)
42
    ATTRIBUTE_FMT_PRINTF(9, 10);
43

44 45
char *virAuditEncode(const char *key, const char *value);

46 47
void virAuditClose(void);

48
#define VIR_AUDIT(type, success, ...) \
49
    virAuditSend(&virLogSelf, __FILE__, __LINE__, __func__, \
50 51
                 NULL, NULL, type, success, __VA_ARGS__);

52
#define VIR_AUDIT_USER(type, success, clienttty, clientaddr, ...) \
53
    virAuditSend(&virLogSelf, __FILE__, __LINE__, __func__, \
54 55
                 clienttty, clientaddr, type, success, __VA_ARGS__);

56
#define VIR_AUDIT_STR(str) \
57
    ((str) ? (str) : "?")