audit_plugin.c revision e4163c9bf1c1d30987c9216473236d730dc3c3a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* private interfaces for auditd plugins and auditd.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <bsm/audit_record.h>
#include <bsm/audit_uevents.h>
#include <errno.h>
#include <fcntl.h>
#include <libintl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <wait.h>
#include "audit_plugin.h"
static char auditwarn[] = "/etc/security/audit_warn";
static pthread_mutex_t syslog_lock;
static void
{
}
/*
* audit_syslog() -- generate syslog messages from threads that use
* different severity, facility code, and application names.
*
* syslog(3C) is thread safe, but the set openlog() / syslog() /
* closelog() is not.
*
* Assumption: the app_name and facility code are paired, i.e.,
* if the facility code for this call is the same as for the
* the previous, the app_name hasn't changed.
*/
void
const char *app_name,
int flags,
int facility,
int severity,
const char *message)
{
static int logopen = 0;
static int prev_facility = -1;
(void) pthread_mutex_lock(&syslog_lock);
if (prev_facility != facility) {
if (logopen)
closelog();
(void) pthread_mutex_unlock(&syslog_lock);
} else {
(void) pthread_mutex_unlock(&syslog_lock);
}
}
/*
* __audit_dowarn - invoke the shell script auditwarn to notify the
* adminstrator about a given problem.
* parameters -
* option - what the problem is
* text - when used with options soft and hard: which file was being
* used when the filesystem filled up
* when used with the plugin option: error detail
* count - used with various options: how many times auditwarn has
* been called for this problem since it was last cleared.
*/
void
{
int st;
char countstr[5];
char warnstring[80];
return;
}
if (pid != 0) {
return;
}
else
/*
* (execl failed)
*/
(void) sprintf(warnstring,
(void) sprintf(warnstring,
(void) sprintf(warnstring,
gettext("All audit filesystems are full.\n"));
(void) sprintf(warnstring,
gettext("audit_control minfree error.\n"));
(void) sprintf(warnstring,
gettext("audit_control directory error.\n"));
else
(void) sprintf(warnstring,
LOG_ALERT, (const char *)warnstring);
exit(1);
}
/*
* __audit_dowarn2 - invoke the shell script auditwarn to notify the
* adminstrator about a given problem.
* parameters -
* option - what the problem is
* name - entity reporting the problem (ie, plugin name)
* error - error string
* text - when used with options soft and hard: which file was being
* used when the filesystem filled up
* when used with the plugin option: error detail
* count - used with various options: how many times auditwarn has
* been called for this problem since it was last cleared.
*/
void
{
int st;
char countstr[5];
char warnstring[80];
return;
}
if (pid != 0) {
return;
}
countstr, 0);
/*
* (execl failed)
*/
(void) sprintf(warnstring,
LOG_ALERT, (const char *)warnstring);
exit(1);
}
/*
* logpost - post the new audit log file name to audit_data.
*
* This is not re-entrant code; it is called from auditd.c when
* audit_binfile.so is not running and from binfile after auditd
* is done.
*/
int
{
char buffer[MAXPATHLEN];
char empty[] = "";
static int first = 1;
static char auditdata[] = AUDITDATAFILE;
static int audit_data_fd; /* file descriptor of audit_data */
if (first) {
first = 0;
/*
* Open the audit_data file. Use O_APPEND so that the contents
* are not destroyed if there is another auditd running.
*/
return (1);
}
}
(void) fsync(audit_data_fd);
return (0);
}
/*
* debug use - open a file for auditd and its plugins for debug
*/
FILE *
return (fp);
return (fp);
}