1
/* gdm-session-linux-auditor.c - Object for Linux auditing of session login/logout
3
* Copyright (C) 2004, 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2005, 2008 Red Hat, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
* Written by: Brian A. Cameron <Brian.Cameron@sun.com>
22
* Gary Winiger <Gary.Winiger@sun.com>
23
* Ray Strode <rstrode@redhat.com>
24
* Steve Grubb <sgrubb@redhat.com>
27
#include "gdm-session-linux-auditor.h"
38
struct _GdmSessionLinuxAuditorPrivate
43
static void gdm_session_linux_auditor_finalize (GObject *object);
45
G_DEFINE_TYPE (GdmSessionLinuxAuditor, gdm_session_linux_auditor, GDM_TYPE_SESSION_AUDITOR)
48
log_user_message (GdmSessionAuditor *auditor,
52
GdmSessionLinuxAuditor *linux_auditor;
59
linux_auditor = GDM_SESSION_LINUX_AUDITOR (auditor);
61
g_object_get (G_OBJECT (auditor), "username", &username, NULL);
62
g_object_get (G_OBJECT (auditor), "hostname", &hostname, NULL);
63
g_object_get (G_OBJECT (auditor), "display-device", &display_device, NULL);
65
if (username != NULL) {
66
pw = getpwnam (username);
68
username = g_strdup ("unknown");
73
g_snprintf (buf, sizeof (buf), "uid=%d", pw->pw_uid);
74
audit_log_user_message (linux_auditor->priv->audit_fd, type,
75
buf, hostname, NULL, display_device,
78
g_snprintf (buf, sizeof (buf), "acct=%s", username);
79
audit_log_user_message (linux_auditor->priv->audit_fd, type,
80
buf, hostname, NULL, display_device,
86
g_free (display_device);
90
gdm_session_linux_auditor_report_login (GdmSessionAuditor *auditor)
92
log_user_message (auditor, AUDIT_USER_LOGIN, 1);
96
gdm_session_linux_auditor_report_login_failure (GdmSessionAuditor *auditor,
98
const char *pam_error_string)
100
log_user_message (auditor, AUDIT_USER_LOGIN, 0);
104
gdm_session_linux_auditor_report_logout (GdmSessionAuditor *auditor)
106
log_user_message (auditor, AUDIT_USER_LOGOUT, 1);
110
gdm_session_linux_auditor_class_init (GdmSessionLinuxAuditorClass *klass)
112
GObjectClass *object_class;
113
GdmSessionAuditorClass *auditor_class;
115
object_class = G_OBJECT_CLASS (klass);
116
auditor_class = GDM_SESSION_AUDITOR_CLASS (klass);
118
object_class->finalize = gdm_session_linux_auditor_finalize;
120
auditor_class->report_login = gdm_session_linux_auditor_report_login;
121
auditor_class->report_login_failure = gdm_session_linux_auditor_report_login_failure;
122
auditor_class->report_logout = gdm_session_linux_auditor_report_logout;
124
g_type_class_add_private (auditor_class, sizeof (GdmSessionLinuxAuditorPrivate));
128
gdm_session_linux_auditor_init (GdmSessionLinuxAuditor *auditor)
130
auditor->priv = G_TYPE_INSTANCE_GET_PRIVATE (auditor,
131
GDM_TYPE_SESSION_LINUX_AUDITOR,
132
GdmSessionLinuxAuditorPrivate);
134
auditor->priv->audit_fd = audit_open ();
138
gdm_session_linux_auditor_finalize (GObject *object)
140
GdmSessionLinuxAuditor *linux_auditor;
141
GObjectClass *parent_class;
143
linux_auditor = GDM_SESSION_LINUX_AUDITOR (object);
145
close (linux_auditor->priv->audit_fd);
147
parent_class = G_OBJECT_CLASS (gdm_session_linux_auditor_parent_class);
148
if (parent_class->finalize != NULL) {
149
parent_class->finalize (object);
155
gdm_session_linux_auditor_new (const char *hostname,
156
const char *display_device)
160
auditor = g_object_new (GDM_TYPE_SESSION_LINUX_AUDITOR,
161
"hostname", hostname,
162
"display-device", display_device,
165
return GDM_SESSION_AUDITOR (auditor);