2020-12-23 22:21:36 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2015 Red Hat, Inc.
|
2015-07-20 18:33:35 +02:00
|
|
|
*/
|
|
|
|
|
|
2021-02-04 18:04:13 +01:00
|
|
|
#include "src/core/nm-default-daemon.h"
|
2016-02-19 14:57:48 +01:00
|
|
|
|
2016-02-12 14:44:52 +01:00
|
|
|
#include "nm-audit-manager.h"
|
|
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
#if HAVE_LIBAUDIT
|
2021-07-09 08:48:48 +02:00
|
|
|
#include <libaudit.h>
|
2015-07-20 18:33:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
#define NM_VALUE_TYPE_DEFINE_FUNCTIONS
|
|
|
|
|
|
2021-02-12 15:01:09 +01:00
|
|
|
#include "libnm-core-aux-intern/nm-auth-subject.h"
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
#include "libnm-glib-aux/nm-str-buf.h"
|
|
|
|
|
#include "libnm-glib-aux/nm-value-type.h"
|
2015-07-20 18:33:35 +02:00
|
|
|
#include "nm-config.h"
|
2019-12-19 11:30:38 +01:00
|
|
|
#include "nm-dbus-manager.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "settings/nm-settings-connection.h"
|
2015-07-20 18:33:35 +02:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2016-03-03 09:20:23 +01:00
|
|
|
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
typedef enum _nm_packed {
|
2016-09-29 13:49:01 +02:00
|
|
|
BACKEND_LOG = (1 << 0),
|
|
|
|
|
BACKEND_AUDITD = (1 << 1),
|
|
|
|
|
_BACKEND_LAST,
|
|
|
|
|
BACKEND_ALL = ((_BACKEND_LAST - 1) << 1) - 1,
|
2015-07-20 18:33:35 +02:00
|
|
|
} AuditBackend;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
const char * name;
|
|
|
|
|
AuditBackend backends;
|
|
|
|
|
bool need_encoding;
|
|
|
|
|
NMValueType value_type;
|
|
|
|
|
NMValueTypUnion value;
|
2015-07-20 18:33:35 +02:00
|
|
|
} AuditField;
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-08-07 16:43:11 -04:00
|
|
|
typedef struct {
|
2015-07-20 18:33:35 +02:00
|
|
|
NMConfig *config;
|
|
|
|
|
int auditd_fd;
|
|
|
|
|
} NMAuditManagerPrivate;
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
struct _NMAuditManager {
|
|
|
|
|
GObject parent;
|
|
|
|
|
#if HAVE_LIBAUDIT
|
|
|
|
|
NMAuditManagerPrivate _priv;
|
2015-08-07 16:43:11 -04:00
|
|
|
#endif
|
2016-09-29 13:49:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _NMAuditManagerClass {
|
|
|
|
|
GObjectClass parent;
|
|
|
|
|
};
|
2015-07-20 18:33:35 +02:00
|
|
|
|
|
|
|
|
G_DEFINE_TYPE(NMAuditManager, nm_audit_manager, G_TYPE_OBJECT)
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
#define NM_AUDIT_MANAGER_GET_PRIVATE(self) \
|
|
|
|
|
_NM_GET_PRIVATE(self, NMAuditManager, NM_IS_AUDIT_MANAGER)
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define AUDIT_LOG_LEVEL LOGL_INFO
|
|
|
|
|
|
|
|
|
|
#define _NMLOG_PREFIX_NAME "audit"
|
|
|
|
|
#define _NMLOG(level, domain, ...) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
2017-03-01 10:20:01 +00:00
|
|
|
nm_log((level), \
|
|
|
|
|
(domain), \
|
|
|
|
|
NULL, \
|
|
|
|
|
NULL, \
|
2016-09-29 13:49:01 +02:00
|
|
|
"%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
|
|
|
|
_NMLOG_PREFIX_NAME ": " _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
NM_DEFINE_SINGLETON_GETTER(NMAuditManager, nm_audit_manager_get, NM_TYPE_AUDIT_MANAGER);
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
static void
|
|
|
|
|
_audit_field_init_string(AuditField * field,
|
|
|
|
|
const char * name,
|
|
|
|
|
const char * str,
|
|
|
|
|
gboolean need_encoding,
|
|
|
|
|
AuditBackend backends)
|
|
|
|
|
{
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
*field = (AuditField){
|
|
|
|
|
.name = name,
|
|
|
|
|
.need_encoding = need_encoding,
|
|
|
|
|
.backends = backends,
|
|
|
|
|
.value_type = NM_VALUE_TYPE_STRING,
|
|
|
|
|
.value.v_string = str,
|
|
|
|
|
};
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
_audit_field_init_uint64(AuditField *field, const char *name, guint64 val, AuditBackend backends)
|
2015-07-20 18:33:35 +02:00
|
|
|
{
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
*field = (AuditField){
|
|
|
|
|
.name = name,
|
|
|
|
|
.backends = backends,
|
|
|
|
|
.value_type = NM_VALUE_TYPE_UINT64,
|
|
|
|
|
.value.v_uint64 = val,
|
|
|
|
|
};
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-09 16:54:05 +02:00
|
|
|
static const char *
|
|
|
|
|
build_message(NMStrBuf *strbuf, AuditBackend backend, GPtrArray *fields)
|
2015-07-20 18:33:35 +02:00
|
|
|
{
|
2021-04-09 16:54:05 +02:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
if (strbuf->len == 0) {
|
|
|
|
|
/* preallocate a large buffer... */
|
|
|
|
|
nm_str_buf_maybe_expand(strbuf, NM_UTILS_GET_NEXT_REALLOC_SIZE_232, FALSE);
|
|
|
|
|
} else
|
|
|
|
|
nm_str_buf_reset(strbuf);
|
2015-07-20 18:33:35 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < fields->len; i++) {
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
const AuditField *field = fields->pdata[i];
|
2015-07-20 18:33:35 +02:00
|
|
|
|
2017-12-11 16:38:42 +01:00
|
|
|
if (!NM_FLAGS_ANY(field->backends, backend))
|
2015-07-20 18:33:35 +02:00
|
|
|
continue;
|
|
|
|
|
|
2021-04-09 16:54:05 +02:00
|
|
|
nm_str_buf_append_required_delimiter(strbuf, ' ');
|
2015-07-20 18:33:35 +02:00
|
|
|
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
if (field->value_type == NM_VALUE_TYPE_STRING) {
|
|
|
|
|
const char *str = field->value.v_string;
|
2015-07-20 18:33:35 +02:00
|
|
|
|
|
|
|
|
#if HAVE_LIBAUDIT
|
|
|
|
|
if (backend == BACKEND_AUDITD) {
|
|
|
|
|
if (field->need_encoding) {
|
2021-04-09 13:44:49 +02:00
|
|
|
gs_free char *value = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
value = audit_encode_nv_string(field->name, str, 0);
|
2021-04-09 16:54:05 +02:00
|
|
|
nm_str_buf_append(strbuf, value);
|
2015-07-20 18:33:35 +02:00
|
|
|
} else
|
2021-04-09 16:54:05 +02:00
|
|
|
nm_str_buf_append_printf(strbuf, "%s=%s", field->name, str);
|
2015-07-20 18:33:35 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_LIBAUDIT */
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
|
2021-04-09 16:54:05 +02:00
|
|
|
nm_str_buf_append_printf(strbuf, "%s=\"%s\"", field->name, str);
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (field->value_type == NM_VALUE_TYPE_UINT64) {
|
2021-04-09 16:54:05 +02:00
|
|
|
nm_str_buf_append_printf(strbuf,
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
"%s=%" G_GUINT64_FORMAT,
|
2021-04-09 13:44:49 +02:00
|
|
|
field->name,
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
field->value.v_uint64);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_return_val_if_reached(NULL);
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
|
2021-04-09 16:54:05 +02:00
|
|
|
return nm_str_buf_get_str(strbuf);
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_audit_log(NMAuditManager *self,
|
|
|
|
|
GPtrArray * fields,
|
|
|
|
|
const char * file,
|
|
|
|
|
guint line,
|
|
|
|
|
const char * func,
|
|
|
|
|
gboolean success)
|
|
|
|
|
{
|
2021-04-09 16:54:05 +02:00
|
|
|
nm_auto_str_buf NMStrBuf strbuf = NM_STR_BUF_INIT(0, FALSE);
|
2015-08-07 16:43:11 -04:00
|
|
|
#if HAVE_LIBAUDIT
|
2015-07-20 18:33:35 +02:00
|
|
|
NMAuditManagerPrivate *priv;
|
2015-08-07 16:43:11 -04:00
|
|
|
#endif
|
2015-07-20 18:33:35 +02:00
|
|
|
|
|
|
|
|
g_return_if_fail(NM_IS_AUDIT_MANAGER(self));
|
|
|
|
|
|
|
|
|
|
#if HAVE_LIBAUDIT
|
2015-08-07 16:43:11 -04:00
|
|
|
priv = NM_AUDIT_MANAGER_GET_PRIVATE(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
if (priv->auditd_fd >= 0) {
|
2021-04-09 16:54:05 +02:00
|
|
|
audit_log_user_message(priv->auditd_fd,
|
|
|
|
|
AUDIT_USYS_CONFIG,
|
|
|
|
|
build_message(&strbuf, BACKEND_AUDITD, fields),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
success);
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (nm_logging_enabled(AUDIT_LOG_LEVEL, LOGD_AUDIT)) {
|
2021-04-09 13:05:07 +02:00
|
|
|
_nm_log_full(file,
|
|
|
|
|
line,
|
|
|
|
|
func,
|
|
|
|
|
!(NM_THREAD_SAFE_ON_MAIN_THREAD),
|
|
|
|
|
AUDIT_LOG_LEVEL,
|
|
|
|
|
LOGD_AUDIT,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
"%s%s",
|
|
|
|
|
_NMLOG_PREFIX_NAME ": ",
|
2021-04-09 16:54:05 +02:00
|
|
|
build_message(&strbuf, BACKEND_LOG, fields));
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-07-15 09:56:44 +02:00
|
|
|
_audit_log_helper(NMAuditManager *self,
|
|
|
|
|
GPtrArray * fields,
|
|
|
|
|
const char * file,
|
|
|
|
|
guint line,
|
|
|
|
|
const char * func,
|
|
|
|
|
const char * op,
|
|
|
|
|
gboolean result,
|
|
|
|
|
gpointer subject_context,
|
|
|
|
|
const char * reason)
|
2015-07-20 18:33:35 +02:00
|
|
|
{
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
AuditField op_field;
|
|
|
|
|
AuditField pid_field;
|
|
|
|
|
AuditField uid_field;
|
|
|
|
|
AuditField result_field;
|
|
|
|
|
AuditField reason_field;
|
|
|
|
|
gulong pid;
|
|
|
|
|
gulong uid;
|
2016-01-07 16:31:19 +01:00
|
|
|
NMAuthSubject * subject = NULL;
|
|
|
|
|
gs_unref_object NMAuthSubject *subject_free = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
_audit_field_init_string(&op_field, "op", op, FALSE, BACKEND_ALL);
|
|
|
|
|
g_ptr_array_insert(fields, 0, &op_field);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-01-07 16:31:19 +01:00
|
|
|
if (subject_context) {
|
|
|
|
|
if (NM_IS_AUTH_SUBJECT(subject_context))
|
|
|
|
|
subject = subject_context;
|
|
|
|
|
else if (G_IS_DBUS_METHOD_INVOCATION(subject_context)) {
|
|
|
|
|
GDBusMethodInvocation *context = subject_context;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-12-19 11:30:38 +01:00
|
|
|
subject = subject_free = nm_dbus_manager_new_auth_subject_from_context(context);
|
2016-01-07 16:31:19 +01:00
|
|
|
} else
|
|
|
|
|
g_warn_if_reached();
|
|
|
|
|
}
|
2019-12-17 20:36:18 +01:00
|
|
|
if (subject && nm_auth_subject_get_subject_type(subject) == NM_AUTH_SUBJECT_TYPE_UNIX_PROCESS) {
|
2015-07-20 18:33:35 +02:00
|
|
|
pid = nm_auth_subject_get_unix_process_pid(subject);
|
|
|
|
|
uid = nm_auth_subject_get_unix_process_uid(subject);
|
|
|
|
|
if (pid != G_MAXULONG) {
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
_audit_field_init_uint64(&pid_field, "pid", pid, BACKEND_ALL);
|
2015-07-20 18:33:35 +02:00
|
|
|
g_ptr_array_add(fields, &pid_field);
|
|
|
|
|
}
|
|
|
|
|
if (uid != G_MAXULONG) {
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
_audit_field_init_uint64(&uid_field, "uid", uid, BACKEND_ALL);
|
2015-07-20 18:33:35 +02:00
|
|
|
g_ptr_array_add(fields, &uid_field);
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
_audit_field_init_string(&result_field,
|
|
|
|
|
"result",
|
|
|
|
|
result ? "success" : "fail",
|
|
|
|
|
FALSE,
|
|
|
|
|
BACKEND_ALL);
|
|
|
|
|
g_ptr_array_add(fields, &result_field);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
if (reason) {
|
|
|
|
|
_audit_field_init_string(&reason_field, "reason", reason, FALSE, BACKEND_LOG);
|
|
|
|
|
g_ptr_array_add(fields, &reason_field);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
nm_audit_log(self, fields, file, line, func, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
nm_audit_manager_audit_enabled(NMAuditManager *self)
|
|
|
|
|
{
|
|
|
|
|
#if HAVE_LIBAUDIT
|
|
|
|
|
NMAuditManagerPrivate *priv = NM_AUDIT_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
if (priv->auditd_fd >= 0)
|
|
|
|
|
return TRUE;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return nm_logging_enabled(AUDIT_LOG_LEVEL, LOGD_AUDIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2019-07-15 09:56:44 +02:00
|
|
|
_nm_audit_manager_log_connection_op(NMAuditManager * self,
|
|
|
|
|
const char * file,
|
|
|
|
|
guint line,
|
|
|
|
|
const char * func,
|
|
|
|
|
const char * op,
|
|
|
|
|
NMSettingsConnection *connection,
|
|
|
|
|
gboolean result,
|
|
|
|
|
const char * args,
|
|
|
|
|
gpointer subject_context,
|
|
|
|
|
const char * reason)
|
2015-07-20 18:33:35 +02:00
|
|
|
{
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
gs_unref_ptrarray GPtrArray *fields = NULL;
|
|
|
|
|
AuditField uuid_field;
|
|
|
|
|
AuditField name_field;
|
|
|
|
|
AuditField args_field;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
g_return_if_fail(op);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
fields = g_ptr_array_new();
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
if (connection) {
|
2015-07-14 16:53:24 +02:00
|
|
|
_audit_field_init_string(&uuid_field,
|
|
|
|
|
"uuid",
|
|
|
|
|
nm_settings_connection_get_uuid(connection),
|
2015-07-20 18:33:35 +02:00
|
|
|
FALSE,
|
|
|
|
|
BACKEND_ALL);
|
|
|
|
|
g_ptr_array_add(fields, &uuid_field);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-14 16:53:24 +02:00
|
|
|
_audit_field_init_string(&name_field,
|
|
|
|
|
"name",
|
|
|
|
|
nm_settings_connection_get_id(connection),
|
2015-07-20 18:33:35 +02:00
|
|
|
TRUE,
|
|
|
|
|
BACKEND_ALL);
|
|
|
|
|
g_ptr_array_add(fields, &name_field);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-04-20 12:10:55 +02:00
|
|
|
if (args) {
|
|
|
|
|
_audit_field_init_string(&args_field, "args", args, FALSE, BACKEND_ALL);
|
|
|
|
|
g_ptr_array_add(fields, &args_field);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-01-07 16:31:19 +01:00
|
|
|
_audit_log_helper(self, fields, file, line, func, op, result, subject_context, reason);
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2016-08-01 17:19:14 +02:00
|
|
|
_nm_audit_manager_log_generic_op(NMAuditManager *self,
|
|
|
|
|
const char * file,
|
|
|
|
|
guint line,
|
2015-07-20 18:33:35 +02:00
|
|
|
const char * func,
|
|
|
|
|
const char * op,
|
|
|
|
|
const char * arg,
|
2016-01-07 16:31:19 +01:00
|
|
|
gboolean result,
|
|
|
|
|
gpointer subject_context,
|
2015-07-20 18:33:35 +02:00
|
|
|
const char * reason)
|
|
|
|
|
{
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
gs_unref_ptrarray GPtrArray *fields = NULL;
|
|
|
|
|
AuditField arg_field;
|
2015-07-20 18:33:35 +02:00
|
|
|
|
|
|
|
|
g_return_if_fail(op);
|
|
|
|
|
g_return_if_fail(arg);
|
|
|
|
|
|
|
|
|
|
fields = g_ptr_array_new();
|
|
|
|
|
|
|
|
|
|
_audit_field_init_string(&arg_field, "arg", arg, TRUE, BACKEND_ALL);
|
|
|
|
|
g_ptr_array_add(fields, &arg_field);
|
|
|
|
|
|
2016-01-07 16:31:19 +01:00
|
|
|
_audit_log_helper(self, fields, file, line, func, op, result, subject_context, reason);
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_nm_audit_manager_log_device_op(NMAuditManager *self,
|
|
|
|
|
const char * file,
|
|
|
|
|
guint line,
|
|
|
|
|
const char * func,
|
|
|
|
|
const char * op,
|
|
|
|
|
NMDevice * device,
|
2017-03-04 00:06:59 +01:00
|
|
|
gboolean result,
|
|
|
|
|
const char * args,
|
|
|
|
|
gpointer subject_context,
|
2015-07-20 18:33:35 +02:00
|
|
|
const char * reason)
|
|
|
|
|
{
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
gs_unref_ptrarray GPtrArray *fields = NULL;
|
|
|
|
|
AuditField interface_field;
|
|
|
|
|
AuditField ifindex_field;
|
|
|
|
|
AuditField args_field;
|
2015-07-20 18:33:35 +02:00
|
|
|
int ifindex;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
g_return_if_fail(op);
|
|
|
|
|
g_return_if_fail(device);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
fields = g_ptr_array_new();
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
_audit_field_init_string(&interface_field,
|
|
|
|
|
"interface",
|
|
|
|
|
nm_device_get_ip_iface(device),
|
|
|
|
|
TRUE,
|
|
|
|
|
BACKEND_ALL);
|
|
|
|
|
g_ptr_array_add(fields, &interface_field);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
ifindex = nm_device_get_ip_ifindex(device);
|
|
|
|
|
if (ifindex > 0) {
|
audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.
But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.
The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.
If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-09 14:08:00 +02:00
|
|
|
_audit_field_init_uint64(&ifindex_field, "ifindex", ifindex, BACKEND_ALL);
|
2015-07-20 18:33:35 +02:00
|
|
|
g_ptr_array_add(fields, &ifindex_field);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-03-04 00:06:59 +01:00
|
|
|
if (args) {
|
|
|
|
|
_audit_field_init_string(&args_field, "args", args, FALSE, BACKEND_ALL);
|
|
|
|
|
g_ptr_array_add(fields, &args_field);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-01-07 16:31:19 +01:00
|
|
|
_audit_log_helper(self, fields, file, line, func, op, result, subject_context, reason);
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if HAVE_LIBAUDIT
|
|
|
|
|
static void
|
|
|
|
|
init_auditd(NMAuditManager *self)
|
|
|
|
|
{
|
|
|
|
|
NMAuditManagerPrivate *priv = NM_AUDIT_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
NMConfigData * data = nm_config_get_data(priv->config);
|
2019-01-31 13:29:21 +01:00
|
|
|
int errsv;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
if (nm_config_data_get_value_boolean(data,
|
|
|
|
|
NM_CONFIG_KEYFILE_GROUP_LOGGING,
|
2018-11-09 18:05:04 +01:00
|
|
|
NM_CONFIG_KEYFILE_KEY_LOGGING_AUDIT,
|
2016-10-06 22:14:01 +02:00
|
|
|
NM_CONFIG_DEFAULT_LOGGING_AUDIT_BOOL)) {
|
2015-07-20 18:33:35 +02:00
|
|
|
if (priv->auditd_fd < 0) {
|
|
|
|
|
priv->auditd_fd = audit_open();
|
2019-01-31 13:29:21 +01:00
|
|
|
if (priv->auditd_fd < 0) {
|
|
|
|
|
errsv = errno;
|
2019-01-31 17:22:18 +01:00
|
|
|
_LOGE(LOGD_CORE, "failed to open auditd socket: %s", nm_strerror_native(errsv));
|
2019-01-31 13:29:21 +01:00
|
|
|
} else
|
2016-03-03 09:20:23 +01:00
|
|
|
_LOGD(LOGD_CORE, "socket created");
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (priv->auditd_fd >= 0) {
|
|
|
|
|
audit_close(priv->auditd_fd);
|
|
|
|
|
priv->auditd_fd = -1;
|
2016-03-03 09:20:23 +01:00
|
|
|
_LOGD(LOGD_CORE, "socket closed");
|
2015-07-20 18:33:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
config_changed_cb(NMConfig * config,
|
|
|
|
|
NMConfigData * config_data,
|
|
|
|
|
NMConfigChangeFlags changes,
|
|
|
|
|
NMConfigData * old_data,
|
|
|
|
|
NMAuditManager * self)
|
|
|
|
|
{
|
|
|
|
|
if (NM_FLAGS_HAS(changes, NM_CONFIG_CHANGE_VALUES))
|
|
|
|
|
init_auditd(self);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
static void
|
|
|
|
|
nm_audit_manager_init(NMAuditManager *self)
|
|
|
|
|
{
|
|
|
|
|
#if HAVE_LIBAUDIT
|
|
|
|
|
NMAuditManagerPrivate *priv = NM_AUDIT_MANAGER_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
priv->config = g_object_ref(nm_config_get());
|
|
|
|
|
g_signal_connect(G_OBJECT(priv->config),
|
|
|
|
|
NM_CONFIG_SIGNAL_CONFIG_CHANGED,
|
|
|
|
|
G_CALLBACK(config_changed_cb),
|
|
|
|
|
self);
|
|
|
|
|
priv->auditd_fd = -1;
|
|
|
|
|
|
|
|
|
|
init_auditd(self);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dispose(GObject *object)
|
|
|
|
|
{
|
|
|
|
|
#if HAVE_LIBAUDIT
|
|
|
|
|
NMAuditManager * self = NM_AUDIT_MANAGER(object);
|
|
|
|
|
NMAuditManagerPrivate *priv = NM_AUDIT_MANAGER_GET_PRIVATE(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
if (priv->config) {
|
|
|
|
|
g_signal_handlers_disconnect_by_func(priv->config, config_changed_cb, self);
|
|
|
|
|
g_clear_object(&priv->config);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-07-20 18:33:35 +02:00
|
|
|
if (priv->auditd_fd >= 0) {
|
|
|
|
|
audit_close(priv->auditd_fd);
|
|
|
|
|
priv->auditd_fd = -1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(nm_audit_manager_parent_class)->dispose(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_audit_manager_class_init(NMAuditManagerClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS(klass);
|
|
|
|
|
|
|
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
}
|