Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast a warning if a system halt is possible #435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <utmpx.h>
#include <fcntl.h>

/*
* This function returns 1 if it is the last record in an event.
Expand Down Expand Up @@ -75,4 +77,36 @@ int write_to_console(const char *fmt, ...)
close(fd);

return res;
}

void wall_message(const char* format, ...)
{
struct utmpx* entry;
char message[512];
va_list args;
int fd;

// Format the message
va_start(args, format);
vsnprintf(message, sizeof(message), format, args);
va_end(args);

setutxent();

// Send the message to all active users
while ((entry = getutxent())) {
// Only active users have a valid terminal
if (entry->ut_type == USER_PROCESS) {
char tty_path[128];
snprintf(tty_path, sizeof(tty_path), "/dev/%s", entry->ut_line);

fd = open(tty_path, O_WRONLY | O_NOCTTY);
if (fd != -1) {
dprintf(fd, "\nBroadcast message from audit daemon:\n%s\n", message);
close(fd);
}
}
}

endutxent();
}
7 changes: 7 additions & 0 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ int write_to_console(const char *fmt, ...)
;
#endif

void wall_message(const char *fmt, ...)
#ifdef __GNUC__
__attribute__((format(printf, 1, 2)));
#else
;
#endif

AUDIT_HIDDEN_END
#endif

7 changes: 7 additions & 0 deletions src/auditd-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,13 @@ static void do_space_left_action(int admin)
}
next_actions = buffer;

// If space_left is reached and FA_HALT is set in any of these fields
// we need to inform logged in users.
if (config->admin_space_left_action == FA_HALT ||
config->disk_full_action == FA_HALT) {
wall_message("Audit daemon is low on disk space for logging. %s", next_actions);
}

switch (action)
{
case FA_IGNORE:
Expand Down