+/* GNU provides this but we can't rely on that so let's make our own version */
+static void
+updwtmpx (const gchar *wtmp_file, struct utmpx *ut)
+{
+ struct utmp u;
+
+ memset (&u, 0, sizeof (u));
+ u.ut_type = ut->ut_type;
+ u.ut_pid = ut->ut_pid;
+ if (ut->ut_line)
+ strncpy (u.ut_line, ut->ut_line, sizeof (u.ut_line));
+ if (ut->ut_id)
+ strncpy (u.ut_id, ut->ut_id, sizeof (u.ut_id));
+ if (ut->ut_user)
+ strncpy (u.ut_user, ut->ut_user, sizeof (u.ut_user));
+ if (ut->ut_host)
+ strncpy (u.ut_host, ut->ut_host, sizeof (u.ut_host));
+ u.ut_tv.tv_sec = ut->ut_tv.tv_sec;
+ u.ut_tv.tv_usec = ut->ut_tv.tv_usec;
+
+ updwtmp (wtmp_file, &u);
+}
+
+#if HAVE_LIBAUDIT
+static void
+audit_event (int type, const gchar *username, uid_t uid, const gchar *remote_host_name, const gchar *tty, gboolean success)
+{
+ int auditfd, result;
+ const char *op = NULL;
+
+ auditfd = audit_open ();
+ if (auditfd < 0) {
+ g_printerr ("Error opening audit socket: %s\n", strerror (errno));
+ return;
+ }
+
+ if (type == AUDIT_USER_LOGIN)
+ op = "login";
+ else if (type == AUDIT_USER_LOGOUT)
+ op = "logout";
+ result = success == TRUE ? 1 : 0;
+
+ if (audit_log_acct_message (auditfd, type, NULL, op, username, uid, remote_host_name, NULL, tty, result) <= 0)
+ g_printerr ("Error writing audit message: %s\n", strerror (errno));
+
+ close (auditfd);
+}
+#endif
+