c0c79a3f09914f35651895ffc111883455b7f62dtz# CDDL HEADER START
c0c79a3f09914f35651895ffc111883455b7f62dtz# The contents of this file are subject to the terms of the
c0c79a3f09914f35651895ffc111883455b7f62dtz# Common Development and Distribution License (the "License").
c0c79a3f09914f35651895ffc111883455b7f62dtz# You may not use this file except in compliance with the License.
c0c79a3f09914f35651895ffc111883455b7f62dtz# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c0c79a3f09914f35651895ffc111883455b7f62dtz# See the License for the specific language governing permissions
c0c79a3f09914f35651895ffc111883455b7f62dtz# and limitations under the License.
c0c79a3f09914f35651895ffc111883455b7f62dtz# When distributing Covered Code, include this CDDL HEADER in each
c0c79a3f09914f35651895ffc111883455b7f62dtz# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c0c79a3f09914f35651895ffc111883455b7f62dtz# If applicable, add the following below this CDDL HEADER, with the
c0c79a3f09914f35651895ffc111883455b7f62dtz# fields enclosed by brackets "[]" replaced with your own identifying
c0c79a3f09914f35651895ffc111883455b7f62dtz# information: Portions Copyright [yyyy] [name of copyright owner]
c0c79a3f09914f35651895ffc111883455b7f62dtz# CDDL HEADER END
047f6e6f42a3d50d3e38a05c00bf7dd3fafac726gww# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
c0c79a3f09914f35651895ffc111883455b7f62dtz# Use is subject to license terms.
c0c79a3f09914f35651895ffc111883455b7f62dtz# auditxml takes the audit record description (.xml file) and
c0c79a3f09914f35651895ffc111883455b7f62dtz# generates the files needed for the C audit api.
0ad2061eab39cb8631cb8f2e91ce483699f50425gwwUsage: $prog [options] <xml-input-file>
0ad2061eab39cb8631cb8f2e91ce483699f50425gww -d Enable debug output
0ad2061eab39cb8631cb8f2e91ce483699f50425gww -e pfx Internal event prefix (default: AUE)
0ad2061eab39cb8631cb8f2e91ce483699f50425gww -i pfx Interface prefix (default: adt)
0ad2061eab39cb8631cb8f2e91ce483699f50425gww External event prefix is uppercase version of this string.
0ad2061eab39cb8631cb8f2e91ce483699f50425gww -o dir Output directory (default: current dir)
c0c79a3f09914f35651895ffc111883455b7f62dtzour $debug = 0; # normal use is to set via the file being parsed.
c0c79a3f09914f35651895ffc111883455b7f62dtz # <debug set="on"/> or <debug set="off"/> or <debug/>
c0c79a3f09914f35651895ffc111883455b7f62dtz # if the set attribute is omitted, debug state is toggled
c0c79a3f09914f35651895ffc111883455b7f62dtz # Override with appDebug, but toggle won't do what you
c0c79a3f09914f35651895ffc111883455b7f62dtzmy $appDebug = 0; # used after return from "new auditxml";
0ad2061eab39cb8631cb8f2e91ce483699f50425gww# Process command-line options
c0c79a3f09914f35651895ffc111883455b7f62dtz# where everything comes from and where it goes:
0ad2061eab39cb8631cb8f2e91ce483699f50425gww$filename =~ s|.*/||g;
0ad2061eab39cb8631cb8f2e91ce483699f50425gwwDO NOT EDIT. This file is auto generated by the Solaris Audit
0ad2061eab39cb8631cb8f2e91ce483699f50425gwwsystem from $filename.
0ad2061eab39cb8631cb8f2e91ce483699f50425gww# trim leading/trailing newlines
c0c79a3f09914f35651895ffc111883455b7f62dtz generateAPIFile($event, $eventId, $eventType, $eventHeader, $idNo)
c0c79a3f09914f35651895ffc111883455b7f62dtz generateTableC($event, $eventId, $eventType, $eventHeader, $omit);
c0c79a3f09914f35651895ffc111883455b7f62dtz my $file = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz $notice =~ s/\n/\n * /gs;
c0c79a3f09914f35651895ffc111883455b7f62dtz $notice =~ s/\s+\n/\n/gs;
c0c79a3f09914f35651895ffc111883455b7f62dtz#include <bsm/libbsm.h>
c0c79a3f09914f35651895ffc111883455b7f62dtz#include <adt_xlate.h>
c0c79a3f09914f35651895ffc111883455b7f62dtz#include <libintl.h>
c0c79a3f09914f35651895ffc111883455b7f62dtz print Cfile "\n/* External event structure to internal event structure */\n\n";
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $root =~ s/${pfx_AUE}_//;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $externalId =~ s/${pfx_AUE}_/${pfx_ADT}_/;
c0c79a3f09914f35651895ffc111883455b7f62dtz print Cfile "static struct entry $structName\[$count\] = {\n";
c0c79a3f09914f35651895ffc111883455b7f62dtz print Cfile "static struct translation X_$externalRoot = {\n";
c0c79a3f09914f35651895ffc111883455b7f62dtz print STDERR "expected entry for $eventId but none found\n";
c0c79a3f09914f35651895ffc111883455b7f62dtz my $count = $#pointers + 2;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww print Cfile "adt_translation_t *${pfx_adt}_xlate_table[$count] = {\n";
0ad2061eab39cb8631cb8f2e91ce483699f50425gww${pfx_adt}_preload(au_event_t event_id, adt_event_data_t *event_data)
c0c79a3f09914f35651895ffc111883455b7f62dtz switch (event_id) {
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $adtID =~ s/${pfx_AUE}/${pfx_ADT}/;
c0c79a3f09914f35651895ffc111883455b7f62dtz case $adtID:
c0c79a3f09914f35651895ffc111883455b7f62dtz my $fieldName = shift @preloads;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $default = shift @preloads;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $id =~ s/${pfx_AUE}_/${pfx_adt}_/;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww event_data->$id.$fieldName = $default;
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@listName, [$listName, $listLength - 1, $start, $public]);
c0c79a3f09914f35651895ffc111883455b7f62dtz print Cfile "/* Deprecated message list */\n" if ($deprecated);
c0c79a3f09914f35651895ffc111883455b7f62dtz print Cfile "static char *msg_$listName\[$listLength] = {\n";
0ad2061eab39cb8631cb8f2e91ce483699f50425gww print Cfile "\nstruct msg_text ${pfx_adt}_msg_text[", $#listName + 1,
c0c79a3f09914f35651895ffc111883455b7f62dtz my $file = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $xmlDoc = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz $notice =~ s/\n/\n * /gs;
c0c79a3f09914f35651895ffc111883455b7f62dtz $notice =~ s/\s+\n/\n/gs;
c0c79a3f09914f35651895ffc111883455b7f62dtz#ifndef $adt_event_n
c0c79a3f09914f35651895ffc111883455b7f62dtz#define $adt_event_n
c0c79a3f09914f35651895ffc111883455b7f62dtz#include <bsm/$include>
c0c79a3f09914f35651895ffc111883455b7f62dtz#ifdef __cplusplus
c0c79a3f09914f35651895ffc111883455b7f62dtzextern "C" {
c0c79a3f09914f35651895ffc111883455b7f62dtz * adt_put_event() status values. Positive values are for kernel-generated
c0c79a3f09914f35651895ffc111883455b7f62dtz * failure, -1 for user-space. For ADT_SUCCESS, the adt_put_event() return_val
c0c79a3f09914f35651895ffc111883455b7f62dtz * is not used; the convention is to set it to ADT_SUCCESS.
c0c79a3f09914f35651895ffc111883455b7f62dtz#define ADT_SUCCESS 0
c0c79a3f09914f35651895ffc111883455b7f62dtz#define ADT_FAILURE -1
c0c79a3f09914f35651895ffc111883455b7f62dtz print Hfile "/* Deprecated message list */\n" if $deprecated;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww print Hfile "#define\t${pfx_ADT}_$shortName\t$start\n" if $start;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $i = 0;
6a3b10db10504576d94f22ea0d7aaf12b96b0bbetz 1 while $eline =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
6a3b10db10504576d94f22ea0d7aaf12b96b0bbetz $line =~ s/\t\t/\t/;
6a3b10db10504576d94f22ea0d7aaf12b96b0bbetz # shorten eline; don't mind where the spaces are removed, it is
6a3b10db10504576d94f22ea0d7aaf12b96b0bbetz $eline =~ s/ {8}//;
6a3b10db10504576d94f22ea0d7aaf12b96b0bbetz # here we use negative length in substr to leave off from the
c0c79a3f09914f35651895ffc111883455b7f62dtz my $l = length($eventId) + 8; # label plus preceding #define\t
c0c79a3f09914f35651895ffc111883455b7f62dtz $l = 1 if $l < 1;
c0c79a3f09914f35651895ffc111883455b7f62dtz print STDERR "missing id number for $eventId\n" unless $idNo;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $eventId =~ s/${pfx_AUE}_/${pfx_ADT}_/;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $dataId =~ s/^${pfx_AUE}_/${pfx_adt}_/;
c0c79a3f09914f35651895ffc111883455b7f62dtz print STDERR "$eventId is missing the header assignment\n";
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $externalId =~ s/${pfx_AUE}_/${pfx_ADT}_/;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $eventId =~ s/^${pfx_AUE}_/${pfx_adt}_/;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $elementName =~ s/^${pfx_AUE}_/${pfx_adt}_/;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $eventId =~ s/^${pfx_AUE}_/${pfx_adt}_/;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww#ifndef ${pfx_ADT}_PRIVATE
0ad2061eab39cb8631cb8f2e91ce483699f50425gww#define ${pfx_ADT}_PRIVATE
c0c79a3f09914f35651895ffc111883455b7f62dtz * These interfaces are project private and will change without
0ad2061eab39cb8631cb8f2e91ce483699f50425gww * notice as needed for the Solaris Audit project.
c0c79a3f09914f35651895ffc111883455b7f62dtzextern void adt_get_auid(const adt_session_data_t *, au_id_t *);
c0c79a3f09914f35651895ffc111883455b7f62dtzextern void adt_set_auid(const adt_session_data_t *, const au_id_t);
c0c79a3f09914f35651895ffc111883455b7f62dtzextern void adt_get_mask(const adt_session_data_t *, au_mask_t *);
c0c79a3f09914f35651895ffc111883455b7f62dtzextern void adt_set_mask(const adt_session_data_t *, const au_mask_t *);
c0c79a3f09914f35651895ffc111883455b7f62dtzextern void adt_get_termid(const adt_session_data_t *, au_tid_addr_t *);
c0c79a3f09914f35651895ffc111883455b7f62dtzextern void adt_set_termid(const adt_session_data_t *,
c0c79a3f09914f35651895ffc111883455b7f62dtz const au_tid_addr_t *);
c0c79a3f09914f35651895ffc111883455b7f62dtzextern void adt_get_asid(const adt_session_data_t *, au_asid_t *);
c0c79a3f09914f35651895ffc111883455b7f62dtzextern void adt_set_asid(const adt_session_data_t *, const au_asid_t);
85e8d33eda72d79b047f9f6d1d38e71c94352fdbgwwextern au_asid_t adt_get_unique_id(au_id_t);
0ad2061eab39cb8631cb8f2e91ce483699f50425gwwextern void adt_load_table(const adt_session_data_t *, adt_translation_t **,
0ad2061eab39cb8631cb8f2e91ce483699f50425gww void (*preload)(au_event_t, adt_event_data_t *));
0ad2061eab39cb8631cb8f2e91ce483699f50425gwwextern void ${pfx_adt}_preload(au_event_t, adt_event_data_t *);
0ad2061eab39cb8631cb8f2e91ce483699f50425gwwextern adt_translation_t *${pfx_adt}_xlate_table[];
c0c79a3f09914f35651895ffc111883455b7f62dtz#ifdef __cplusplus
c0c79a3f09914f35651895ffc111883455b7f62dtz#endif /* $adt_event_n */
c0c79a3f09914f35651895ffc111883455b7f62dtz my $event = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $eventId = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $eventType = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $omit = shift;
3cccda98b87857542deb064ace0cec9c785dbeb9Jan Friedel 'command_alt' => 'ADT_CMD_ALT', # dummy token id
c0c79a3f09914f35651895ffc111883455b7f62dtz print STDERR "No external object captured for event $eventId\n";
c0c79a3f09914f35651895ffc111883455b7f62dtz $nameTranslation{$eventId} = $external->getInternalName();
c0c79a3f09914f35651895ffc111883455b7f62dtz print STDERR "No internal object captured for event $eventId\n";
c0c79a3f09914f35651895ffc111883455b7f62dtz if ($internal->isReorder()) { # prescan the entry list to get the token order
c0c79a3f09914f35651895ffc111883455b7f62dtz my $j = $i + 1;
c0c79a3f09914f35651895ffc111883455b7f62dtz $enumGroup =~ s/^msg\s*//i;
c0c79a3f09914f35651895ffc111883455b7f62dtz "$tokenId is an unimplemented token ($entryId in $eventId)\n";
c0c79a3f09914f35651895ffc111883455b7f62dtz formatTableEntry($entryId, $tokenName, $eventId, $dataType, $required,
c0c79a3f09914f35651895ffc111883455b7f62dtz $xlateEventTable{$eventId} = [\@xlateEntryList, $eventType, $firstTokenIndex,
5114d1ad03211a84d5722382609b1c7f8552e216gww my ($id, $token, $eventId, $type, $required, $tsol, $sequence, $format,
c0c79a3f09914f35651895ffc111883455b7f62dtz # does this map belong in the xml source? (at least the defaults?)
c0c79a3f09914f35651895ffc111883455b7f62dtz # fill in the default value only if it is other than zero.
c0c79a3f09914f35651895ffc111883455b7f62dtz # the list handling should be a simple loop with a loop of one
c0c79a3f09914f35651895ffc111883455b7f62dtz unless ($type =~ /,/) { # if list, then generate sequence of entries
c0c79a3f09914f35651895ffc111883455b7f62dtz $type =~ s/\[\]//;
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]);
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]);
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]);
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]);
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@xlateTypeList, "datadef\t$xlateLabel\[1\] =\t$xlateLine;");
c0c79a3f09914f35651895ffc111883455b7f62dtz $xlateLine = "{$token,\t1,\t$xlateLabelRef,\t$sequence,\n" .
5114d1ad03211a84d5722382609b1c7f8552e216gww if (uc $omitEntry ne 'ALWAYS' && ${$entryDef{$type}}[1]) {
c0c79a3f09914f35651895ffc111883455b7f62dtz my $jniId = shift @jniId;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $id = shift @id;
c0c79a3f09914f35651895ffc111883455b7f62dtz $type =~ s/\[\]//;
c0c79a3f09914f35651895ffc111883455b7f62dtz $sizeString = "$arraySize * " . $sizeString if $arraySize;
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@xlateType, "\{$entryType, $sizeString ($type)\}");
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@jniLine, [$jniId, $entryType, $format, $enumGroup, $required]);
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@jniLine, [$jniId, $dataType, $format, $enumGroup, $required]);
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@jniLine, [$jniId, $entryType, $format, $enumGroup, $required]);
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@xlateType, "\{$dataType, sizeof (au_tid_addr_t *)\}");
c0c79a3f09914f35651895ffc111883455b7f62dtz push (@jniLine, [$jniId, $dataType, $format, $enumGroup, $required]);
5114d1ad03211a84d5722382609b1c7f8552e216gww if (uc $omitEntry ne 'ALWAYS' && ${$entryDef{$dtype}}[1]) {
c0c79a3f09914f35651895ffc111883455b7f62dtz my $xlateArray = "\[$typeCount\] =\t{" . join(",\n\t\t\t\t", @xlateType) . "};";
c0c79a3f09914f35651895ffc111883455b7f62dtz "{$token,\t$typeCount,\t&$xlateLabel\[0\],\t$sequence,\n" .
c0c79a3f09914f35651895ffc111883455b7f62dtz my $event = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $eventId = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $eventType = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz my $idNo = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz while (($extEntry, $entry, $tokenId, $format) = $external->getNextEntry()) {
c0c79a3f09914f35651895ffc111883455b7f62dtz print STDERR "undefined entry id for external $eventId\n";
c0c79a3f09914f35651895ffc111883455b7f62dtz print STDERR "no type defined for external tag for $eventId\n";
c0c79a3f09914f35651895ffc111883455b7f62dtz "number of data types ($dataType) does not match number of ids ($entryId)",
c0c79a3f09914f35651895ffc111883455b7f62dtz $#id = $#type;
c0c79a3f09914f35651895ffc111883455b7f62dtz $#type = $#id;
c0c79a3f09914f35651895ffc111883455b7f62dtz $line .= "$primitive\t$dereference$id[$i];\t/* $option */";
c0c79a3f09914f35651895ffc111883455b7f62dtz $dataType =~ s/^msg\s*//i;
0ad2061eab39cb8631cb8f2e91ce483699f50425gww $line .= "enum ${pfx_adt}_$dataType" . "\t$entryId;\t/* $option */";
c0c79a3f09914f35651895ffc111883455b7f62dtz $line .= "$primitive\t$dereference$entryId;\t/* $option */";
c0c79a3f09914f35651895ffc111883455b7f62dtz my $textList = shift;
c0c79a3f09914f35651895ffc111883455b7f62dtz# $header = 0 is a special case; it is for adt_event.h
c0c79a3f09914f35651895ffc111883455b7f62dtz# $header > 0 creates adt_event_N.h, where N = $header
c0c79a3f09914f35651895ffc111883455b7f62dtz my @Hfile = (); # potentially sparse array of file handles
c0c79a3f09914f35651895ffc111883455b7f62dtz my @HfileName = (); # parallel array to Hfile, file name (not path)