14176Stz204579#!/usr/perl5/bin/perl -w 24176Stz204579# 34176Stz204579# CDDL HEADER START 44176Stz204579# 54176Stz204579# The contents of this file are subject to the terms of the 64176Stz204579# Common Development and Distribution License (the "License"). 74176Stz204579# You may not use this file except in compliance with the License. 84176Stz204579# 94176Stz204579# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 104176Stz204579# or http://www.opensolaris.org/os/licensing. 114176Stz204579# See the License for the specific language governing permissions 124176Stz204579# and limitations under the License. 134176Stz204579# 144176Stz204579# When distributing Covered Code, include this CDDL HEADER in each 154176Stz204579# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 164176Stz204579# If applicable, add the following below this CDDL HEADER, with the 174176Stz204579# fields enclosed by brackets "[]" replaced with your own identifying 184176Stz204579# information: Portions Copyright [yyyy] [name of copyright owner] 194176Stz204579# 204176Stz204579# CDDL HEADER END 214176Stz204579# 224176Stz204579# 234176Stz204579# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 244176Stz204579# Use is subject to license terms. 254176Stz204579# 264176Stz204579# ident "%Z%%M% %I% %E% SMI" 274176Stz204579# 284176Stz204579 294176Stz204579# auditxml [-d] <xml input file> 304176Stz204579 314176Stz204579# auditxml takes the audit record description (.xml file) and 324176Stz204579# generates the files needed for the C audit api. 334176Stz204579 344176Stz204579use auditxml; 354176Stz204579use Getopt::Std; 364176Stz204579use vars qw($opt_d); 374176Stz204579use strict; 384176Stz204579 394176Stz204579 404176Stz204579our $debug = 0; # normal use is to set via the file being parsed. 414176Stz204579 # <debug set="on"/> or <debug set="off"/> or <debug/> 424176Stz204579 # if the set attribute is omitted, debug state is toggled 434176Stz204579 # Override with appDebug, but toggle won't do what you 444176Stz204579 # want. 454176Stz204579my $appDebug = 0; # used after return from "new auditxml"; 464176Stz204579 474176Stz204579my $genNotice = " 484176Stz204579DO NOT EDIT. This file is auto generated by the Solaris Audit 494176Stz204579system from adt.xml. 504176Stz204579 514176Stz204579See http://opensolaris.org/os/project/audit/ 524176Stz204579"; 534176Stz204579 544176Stz204579# trim leading/trailing newlines 554176Stz204579$genNotice =~ s/^\n//s; 564176Stz204579$genNotice =~ s/\n$//s; 574176Stz204579my $prog = $0; $prog =~ s|.*/||g; 584176Stz204579my $usage = "usage: $prog [-d] file.xml\n"; 594176Stz204579 604176Stz204579getopts('d'); 614176Stz204579 624176Stz204579$appDebug = $opt_d; 634176Stz204579 644176Stz204579my $uniLabel = "adr"; 654176Stz204579my $xlateUniLabelInc = 0; 664176Stz204579 674176Stz204579die $usage if ($#ARGV < 0); 684176Stz204579 694176Stz204579# where everything comes from and where it goes: 704176Stz204579 714176Stz204579my $bsmBuildPath = "./common"; 724176Stz204579my $xlateFile = "$bsmBuildPath/adt_xlate.c"; 734176Stz204579my $headerFile = "$bsmBuildPath/adt_event_N.h"; 744176Stz204579 754176Stz204579my $doc = new auditxml ($ARGV[0]); # input XML file 764176Stz204579 774176Stz204579$debug = $appDebug; 784176Stz204579 794176Stz204579my %xlateEventTable = (); 804176Stz204579my @xlateTypeList = (); 814176Stz204579my %xlateTypeList = (); 824176Stz204579my %eventAPI = (); 834176Stz204579my %eventExtra = (); 844176Stz204579my %headers = (); 854176Stz204579my %externalIdNo = (); 864176Stz204579my @outputState = (); 874176Stz204579my %nameTranslation = (); 884176Stz204579my @xlateDefaults = (); 894176Stz204579my %xlateDefault = (); 904176Stz204579my %msg_list = (); 914176Stz204579 924176Stz204579my $event; 934176Stz204579while ($event = $doc->getNextEvent()) { 944176Stz204579 my $eventId = $event->getId(); 954176Stz204579 my $eventHeader = $event->getHeader(); 964176Stz204579 my $idNo = $event->getIdNo(); 974176Stz204579 $externalIdNo{$eventId} = $idNo; 984176Stz204579 addHeader($eventHeader) if defined ($eventHeader); 994176Stz204579 my $super; 1004176Stz204579 my $omit = $event->getOmit(); 1014176Stz204579 my $eventType = ''; 1024176Stz204579 if ($super = $event->getSuperClass()) { 1034176Stz204579 $event = $super; 1044176Stz204579 $eventType = 'instance'; 1054176Stz204579 } else { 1064176Stz204579 $eventType = $event->getType(); 1074176Stz204579 } 1084176Stz204579 1094176Stz204579 # header file for API use 1104176Stz204579 generateAPIFile($event, $eventId, $eventType, $eventHeader, $idNo) 1114176Stz204579 unless $omit eq 'always'; 1124176Stz204579 1134176Stz204579 # c file table for translation 1144176Stz204579 generateTableC($event, $eventId, $eventType, $eventHeader, $omit); 1154176Stz204579} 1164176Stz204579 1174176Stz204579my $textList; 1184176Stz204579while ($textList = $doc->getNextMsgId()) { 1194176Stz204579 generateMsgLists($textList); # enum -> text mappings 1204176Stz204579} 1214176Stz204579 1224176Stz204579printTableC($xlateFile); 1234176Stz204579printAPIFile($headerFile, $doc); 1244176Stz204579 1254176Stz204579exit 0; 1264176Stz204579 1274176Stz204579 1284176Stz204579sub printTableC { 1294176Stz204579 my $file = shift; 1304176Stz204579 1314176Stz204579 unless (open(Cfile, ">$file")) { 1324176Stz204579 print STDERR "can't open output file ($file): $!\n"; 1334176Stz204579 return; 1344176Stz204579 } 1354176Stz204579 1364176Stz204579 my $notice = $genNotice; 1374176Stz204579 $notice =~ s/\n/\n * /gs; 1384176Stz204579 $notice =~ s/\s+\n/\n/gs; 1394176Stz204579 print Cfile <<EOF; 1404176Stz204579/* 1414176Stz204579 * $notice 1424176Stz204579 */ 1434176Stz204579 1444176Stz204579#include <bsm/libbsm.h> 1454176Stz204579#include <adt_xlate.h> 1464176Stz204579#include <libintl.h> 1474176Stz204579 1484176Stz204579EOF 1494176Stz204579 print Cfile "#ifndef _PRAUDIT\n"; 1504176Stz204579 print Cfile "/* Internal data type definitions */\n\n"; 1514176Stz204579 my $extDef; 1524176Stz204579 foreach $extDef (@xlateTypeList) { 1534176Stz204579 print Cfile "static $extDef\n"; 1544176Stz204579 } 1554176Stz204579 @xlateTypeList = (); 1564176Stz204579 1574176Stz204579 print Cfile "\n/* External event structure to internal event structure */\n\n"; 1584176Stz204579 1594176Stz204579 my @pointers = (); 1604176Stz204579 1614176Stz204579 foreach my $eventId (sort keys %xlateEventTable) { 1624176Stz204579 if ($xlateEventTable{$eventId}) { 1634176Stz204579 my ($ref1, $eventType, $firstToken, $eventHeader) = 1644176Stz204579 @{$xlateEventTable{$eventId}}; 1654176Stz204579 my @entries = @$ref1; 1664176Stz204579 my $entry; 1674176Stz204579 my $entries = $#entries; 1684176Stz204579 my $count = $entries + 1; 1694176Stz204579 my $externalName = $nameTranslation{$eventId}; 1704176Stz204579 my $externalRoot = $externalName; 1714176Stz204579 $externalRoot =~ s/AUE_//; 1724176Stz204579 my $structName = "XX_$externalRoot"; 1734176Stz204579 my $root = $eventId; 1744176Stz204579 $root =~ s/AUE_//; 1754176Stz204579 my $externalId = $eventId; 1764176Stz204579 $externalId =~ s/AUE_/ADT_/; 1774176Stz204579 1784176Stz204579 unless ($eventType eq 'generic') { 1794176Stz204579 print Cfile "static struct entry $structName\[$count\] = {\n"; 1804176Stz204579 foreach $entry (@entries) { 1814176Stz204579 if ($entries--) { 1824176Stz204579 $entry =~ s/EOL/,/; 1834176Stz204579 } 1844176Stz204579 else { 1854176Stz204579 $entry =~ s/EOL//; 1864176Stz204579 } 1874176Stz204579 $entry =~ s/selfReference/$structName/; 1884176Stz204579 print Cfile "\t$entry\n"; 1894176Stz204579 } 1904176Stz204579 print Cfile "};\n"; 1914176Stz204579 1924176Stz204579 print Cfile "static struct translation X_$externalRoot = {\n"; 1934176Stz204579 push (@pointers, "X_$externalRoot"); 1944176Stz204579 1954176Stz204579 print Cfile "\t0,\n"; # tx_offsetsCalculated = 0 1964176Stz204579 print Cfile "\t$externalId,\n"; 1974176Stz204579 print Cfile "\t$externalName,\n"; 1984176Stz204579 1994176Stz204579 print Cfile "\t$count,\n"; 2004176Stz204579 print Cfile "\t&XX_$externalRoot\[$firstToken\],\n"; 2014176Stz204579 print Cfile "\t&XX_$externalRoot\[0\]\n};\n"; 2024176Stz204579 } 2034176Stz204579 } else { 2044176Stz204579 print STDERR "expected entry for $eventId but none found\n"; 2054176Stz204579 } 2064176Stz204579 } 2074176Stz204579 2084176Stz204579 my $count = $#pointers + 2; 2094176Stz204579 print Cfile "struct translation *xlate_table[$count] = {\n"; 2104176Stz204579 2114176Stz204579 my $firstEvent = 1; 2124176Stz204579 foreach my $eventId (@pointers) { 2134176Stz204579 if ($firstEvent) { 2144176Stz204579 $firstEvent = 0; 2154176Stz204579 } 2164176Stz204579 else { 2174176Stz204579 print Cfile ",\n"; 2184176Stz204579 } 2194176Stz204579 print Cfile "\t&$eventId"; 2204176Stz204579 } 2214176Stz204579 print Cfile ",\n\tNULL\n};\n"; 2224176Stz204579 2234176Stz204579 # generate the adt_preload() function 2244176Stz204579 2254176Stz204579 print Cfile <<EOF; 2264176Stz204579 2274176Stz204579void 2284176Stz204579adt_preload(au_event_t event_id, adt_event_data_t *event_data) 2294176Stz204579{ 2304176Stz204579 switch (event_id) { 2314176Stz204579EOF 2324176Stz204579 2334176Stz204579 foreach my $id (@xlateDefaults) { 2344176Stz204579 my $adtID = $id; 2354176Stz204579 $adtID =~ s/AUE/ADT/; 2364176Stz204579 2374176Stz204579 print Cfile <<EOF; 2384176Stz204579 case $adtID: 2394176Stz204579EOF 2404176Stz204579 my @preloads = @{$xlateDefault{$id}}; 2414176Stz204579 while (@preloads) { 2424176Stz204579 my $fieldName = shift @preloads; 2434176Stz204579 my $default = shift @preloads; 2444176Stz204579 my $lcid = lc $id; 2454176Stz204579 $lcid =~ s/aue_/adt_/; 2464176Stz204579 2474176Stz204579 print Cfile <<EOF; 2484176Stz204579 event_data->$lcid.$fieldName = $default; 2494176Stz204579EOF 2504176Stz204579 } 2514176Stz204579 2524176Stz204579 print Cfile <<EOF; 2534176Stz204579 break; 2544176Stz204579EOF 2554176Stz204579 } 2564176Stz204579 2574176Stz204579 print Cfile <<EOF; 2584176Stz204579 default: 2594176Stz204579 break; 2604176Stz204579 } 2614176Stz204579} 2624176Stz204579#endif 2634176Stz204579 2644176Stz204579/* message lists */ 2654176Stz204579 2664176Stz204579EOF 2674176Stz204579 my $listName; 2684176Stz204579 my @listName; 2694176Stz204579 foreach $listName (sort keys %msg_list) { 2704176Stz204579 my ($listRef, $headref) = @{$msg_list{$listName}}; 2714176Stz204579 my ($header, $start, $public, $deprecated) = @$headref; 2724176Stz204579 2734176Stz204579 my @listValue = @$listRef; 2744176Stz204579 my $listValue; 2754176Stz204579 my $listLength = $#listValue + 1; 2764176Stz204579 2774176Stz204579 $listName = 'NULL' if ($#listValue < 0); 2784176Stz204579 2794176Stz204579 push (@listName, [$listName, $listLength - 1, $start, $public]); 2804176Stz204579 2814176Stz204579 next if ($#listValue < 0); 2824176Stz204579 2834176Stz204579 print Cfile "/* Deprecated message list */\n" if ($deprecated); 2844176Stz204579 print Cfile "static char *msg_$listName\[$listLength] = {\n"; 2854176Stz204579 2864176Stz204579 my $ffirst = 1; 2874176Stz204579 foreach $listValue (@listValue) { 2884176Stz204579 print Cfile ",\n" unless $ffirst; 2894176Stz204579 $ffirst = 0; 2904176Stz204579 my ($id, $text) = split(/\s*::\s*/, $listValue); 2914176Stz204579 if ($text) { 2924176Stz204579 print Cfile "\t\"$text\""; 2934176Stz204579 } 2944176Stz204579 else { 2954176Stz204579 print Cfile "\tNULL"; 2964176Stz204579 } 2974176Stz204579 } 2984176Stz204579 print Cfile "\n};\n"; 2994176Stz204579 } 3004176Stz204579 print Cfile "\nstruct msg_text adt_msg_text[", $#listName + 1, 3014176Stz204579 "] = {\n"; 3024176Stz204579 my $ffirst = 1; 3034176Stz204579 foreach $listName (@listName) { 3044176Stz204579 my ($name, $max, $start) = @$listName; 3054176Stz204579 $start = -$start if $start; 3064176Stz204579 print Cfile ",\n" unless $ffirst; 3074176Stz204579 $ffirst = 0; 3084176Stz204579 $name = "msg_$name" if ($name ne 'NULL'); 3094176Stz204579 print Cfile "\t{0, $max, $name, $start}"; 3104176Stz204579 } 3114176Stz204579 print Cfile "\n};\n"; 3124176Stz204579 3134176Stz204579 close Cfile; 3144176Stz204579} 3154176Stz204579 3164176Stz204579sub printAPIFile { 3174176Stz204579 my $file = shift; 3184176Stz204579 my $xmlDoc = shift; 3194176Stz204579 3204176Stz204579 my @Hfile; 3214176Stz204579 @Hfile = openHeaderFiles($file); 3224176Stz204579 3234176Stz204579 my $notice = $genNotice; 3244176Stz204579 $notice =~ s/\n/\n * /gs; 3254176Stz204579 $notice =~ s/\s+\n/\n/gs; 3264176Stz204579 3274176Stz204579 foreach my $header (keys %headers) { 3284176Stz204579 next unless $Hfile[$header]; 3294176Stz204579 *Hfile = $Hfile[$header]; 3304176Stz204579 my $include = "adt.h"; 3314176Stz204579 my $adt_event_n = "_ADT_EVENT_H"; 3324176Stz204579 if ($header > 0) { 3334176Stz204579 $include = "adt_event.h"; 3344176Stz204579 $adt_event_n = "_ADT_EVENT_".$header."_H"; 3354176Stz204579 } 3364176Stz204579 print Hfile <<EOF; 3374176Stz204579/* 3384176Stz204579 * $notice 3394176Stz204579 */ 3404176Stz204579 3414176Stz204579#ifndef $adt_event_n 3424176Stz204579#define $adt_event_n 3434176Stz204579 3444176Stz204579#include <bsm/$include> 3454176Stz204579 3464176Stz204579#ifdef __cplusplus 3474176Stz204579extern "C" { 3484176Stz204579#endif 3494176Stz204579 3504176Stz204579/* 3514176Stz204579 * adt_put_event() status values. Positive values are for kernel-generated 3524176Stz204579 * failure, -1 for user-space. For ADT_SUCCESS, the adt_put_event() return_val 3534176Stz204579 * is not used; the convention is to set it to ADT_SUCCESS. 3544176Stz204579 */ 3554176Stz204579#define ADT_SUCCESS 0 3564176Stz204579#define ADT_FAILURE -1 3574176Stz204579 3584176Stz204579EOF 3594176Stz204579 } 3604176Stz204579 3614176Stz204579 foreach my $listName (sort keys %msg_list) { 3624176Stz204579 my $shortName = uc $listName; 3634176Stz204579 $shortName =~ s/_TEXT//; 3644176Stz204579 3654176Stz204579 my ($listRef, $headref) = @{$msg_list{$listName}}; 3664176Stz204579 my ($header, $start, $public, $deprecated) = @$headref; 3674176Stz204579 next unless $Hfile[$header]; 3684176Stz204579 *Hfile = $Hfile[$header]; 3694176Stz204579 3704176Stz204579 print Hfile "/* Deprecated message list */\n" if $deprecated; 3714176Stz204579 print Hfile "#define\tADT_$shortName\t$start\n" if $start; 3724176Stz204579 3734176Stz204579 my @listValue = @$listRef; 3744176Stz204579 next unless ($#listValue >= 0); 3754176Stz204579 print Hfile "enum\tadt_$listName", " {\n"; 3764176Stz204579 3774176Stz204579 my $listValue; 3784176Stz204579 my $i = 0; 3794176Stz204579 my $j = $#listValue; 3804176Stz204579 my $comma = ','; 3814176Stz204579 foreach $listValue (@listValue) { 3824176Stz204579 my ($id, $text) = split(/\s*::\s*/, $listValue); 3834176Stz204579 $comma = '' if $i++ == $j; 3844176Stz204579 if ($start) { 3854176Stz204579 $start = " = $start$comma"; 3864176Stz204579 } else { 3874176Stz204579 $start = "$comma\t"; 3884176Stz204579 } 3894176Stz204579 $text = "(no token will be generated)" unless $text; 3905319Stz204579 my $line = "\tADT_$shortName"."_$id$start\t/* "; 3915319Stz204579 # ensure whole line does not exceed 80 chars 3925319Stz204579 my $eline = $line.$text; 3935319Stz204579 #expand tabs 3945319Stz204579 1 while $eline =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e; 3955319Stz204579 if ((length($eline) > 77) && ($line =~ /\t\t/)) { 3965319Stz204579 # 77 = 80 - length(" */") 3975319Stz204579 # strip off double tab so that comment can be longer 3985319Stz204579 $line =~ s/\t\t/\t/; 3995319Stz204579 # shorten eline; don't mind where the spaces are removed, it is 4005319Stz204579 # only $eline length which matters 4015319Stz204579 $eline =~ s/ {8}//; 4025319Stz204579 } 4035319Stz204579 if (length($eline) > 77) { # 80 - length(" */") 4045319Stz204579 # here we use negative length in substr to leave off from the 4055319Stz204579 # right side; 74 = 77 - length("...") 4065319Stz204579 $line .= substr($text, 0, 74 - length($eline)); 4075319Stz204579 # strip off part of last word (already cut) 4085319Stz204579 $line =~ s/\s(\S+)$/ /; 4095319Stz204579 $line .= "..."; 4105319Stz204579 } else { 4115319Stz204579 $line .= $text; 4125319Stz204579 } 4135319Stz204579 print Hfile "$line */\n"; 4144176Stz204579 $start = ''; 4154176Stz204579 } 4164176Stz204579 print Hfile "};\n"; 4174176Stz204579 } 4184176Stz204579 4194176Stz204579 # generate defines for ADT_* external event names 4204176Stz204579 4214176Stz204579 foreach my $eventId (sort keys %eventAPI) { 4224176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 4234176Stz204579 unless (defined ($header)) { 4244176Stz204579 print STDERR "missing header selection for $eventId\n"; 4254176Stz204579 next; 4264176Stz204579 } 4274176Stz204579 *Hfile = $Hfile[$header]; 4284176Stz204579 next unless $Hfile[$header]; 4294176Stz204579 4304176Stz204579 my $l = length($eventId) + 8; # label plus preceding #define\t 4314176Stz204579 $l = 5 - int(($l + 8)/8); 4324176Stz204579 $l = 1 if $l < 1; 4334176Stz204579 my $tab = "\t" x $l; 4344176Stz204579 4354176Stz204579 print STDERR "missing id number for $eventId\n" unless $idNo; 4364176Stz204579 4374176Stz204579 $eventId =~ s/AUE_/ADT_/; 4384176Stz204579 print Hfile "#define\t$eventId$tab$idNo\n"; 4394176Stz204579 } 4404176Stz204579 4414176Stz204579 4424176Stz204579 # generate per-event structures 4434176Stz204579 4444176Stz204579 foreach my $eventId (sort keys %eventAPI) { 4454176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 4464176Stz204579 my $dataId = $eventId; 4474176Stz204579 $dataId =~ s/^AUE_/adt_/; 4484176Stz204579 unless(defined ($header)) { 4494176Stz204579 print STDERR "$eventId is missing the header assignment\n"; 4504176Stz204579 next; 4514176Stz204579 } 4524176Stz204579 *Hfile = $Hfile[$header]; 4534176Stz204579 next unless $Hfile[$header]; 4544176Stz204579 4554176Stz204579 my $externalId = $eventId; 4564176Stz204579 $externalId =~ s/AUE_/ADT_/; 4574176Stz204579 4584176Stz204579 print Hfile "\nstruct $dataId {\t/* $externalId */\n"; 4594176Stz204579 4604176Stz204579 my @entries = @{$eventAPI{$eventId}}; 4614176Stz204579 my $entry; 4624176Stz204579 if ($#entries < 0) { 4634176Stz204579 print Hfile "\tint\tdummy;\t/* not used */\n"; 4644176Stz204579 } else { 4654176Stz204579 foreach $entry (@entries) { 4664176Stz204579 $entry =~ s/termid/adt_termid_t/; 4674176Stz204579 print Hfile "\t$entry\n"; 4684176Stz204579 } 4694176Stz204579 } 4704176Stz204579 print Hfile "};\n"; 4714176Stz204579 $eventId =~ s/^AUE_/adt_/; 4724176Stz204579 print Hfile "typedef struct $dataId $eventId","_t;\n"; 4734176Stz204579 } 4744176Stz204579 4754176Stz204579 foreach my $header (sort keys %headers) { 4764176Stz204579 $outputState[$header] = 0; 4774176Stz204579 } 4784176Stz204579 4794176Stz204579 foreach my $eventId (sort keys %eventAPI) { 4804176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 4814176Stz204579 unless(defined ($header)) { 4824176Stz204579 # don't print duplicate error message 4834176Stz204579 next; 4844176Stz204579 } 4854176Stz204579 *Hfile = $Hfile[$header]; 4864176Stz204579 next unless $Hfile[$header]; 4874176Stz204579 if ($outputState[$header] == 0) { 4884176Stz204579 $outputState[$header] = 1; 4894176Stz204579 my $suffix = ''; 4904176Stz204579 $suffix = "_$header" if $header; 4914176Stz204579 print Hfile "\nunion adt_event_data$suffix {\n"; 4924176Stz204579 } 4934176Stz204579 my $elementName = $eventId; 4944176Stz204579 $elementName =~ s/^AUE_/adt_/; 4954176Stz204579 $eventId =~ s/^AUE_/adt_/; 4964176Stz204579 $elementName =~ s/_t$//; 4974176Stz204579 4984176Stz204579 print Hfile "\t\t$eventId","_t\t$elementName;\n"; 4994176Stz204579 } 5004176Stz204579 foreach my $header (sort keys %headers) { 5014176Stz204579 if ($outputState[$header]) { 5024176Stz204579 *Hfile = $Hfile[$header]; 5034176Stz204579 next unless $Hfile[$header]; 5044176Stz204579 print Hfile "};\n"; 5054176Stz204579 } 5064176Stz204579 } 5074176Stz204579 foreach my $header (keys %headers) { 5084176Stz204579 next unless $Hfile[$header]; 5094176Stz204579 *Hfile = $Hfile[$header]; 5104176Stz204579 my $adt_event_n = "_ADT_EVENT_H"; 5114176Stz204579 if ($header > 0) { 5124176Stz204579 $adt_event_n = "_ADT_EVENT_".$header."_H"; 5134176Stz204579 } 5144176Stz204579 print Hfile <<EOF; 5154176Stz204579 5164176Stz204579 5174176Stz204579#ifndef ADT_PRIVATE 5184176Stz204579#define ADT_PRIVATE 5194176Stz204579 5204176Stz204579/* 5214176Stz204579 * These interfaces are project private and will change without 5224176Stz204579 * notice as needed for the BSM API project. 5234176Stz204579 */ 5244176Stz204579 5254176Stz204579extern void adt_get_auid(const adt_session_data_t *, au_id_t *); 5264176Stz204579extern void adt_set_auid(const adt_session_data_t *, const au_id_t); 5274176Stz204579 5284176Stz204579extern void adt_get_mask(const adt_session_data_t *, au_mask_t *); 5294176Stz204579extern void adt_set_mask(const adt_session_data_t *, const au_mask_t *); 5304176Stz204579 5314176Stz204579extern void adt_get_termid(const adt_session_data_t *, au_tid_addr_t *); 5324176Stz204579extern void adt_set_termid(const adt_session_data_t *, 5334176Stz204579 const au_tid_addr_t *); 5344176Stz204579 5354176Stz204579extern void adt_get_asid(const adt_session_data_t *, au_asid_t *); 5364176Stz204579extern void adt_set_asid(const adt_session_data_t *, const au_asid_t); 5374176Stz204579 5384176Stz204579#endif 5394176Stz204579 5404176Stz204579#ifdef __cplusplus 5414176Stz204579} 5424176Stz204579#endif 5434176Stz204579 5444176Stz204579#endif /* $adt_event_n */ 5454176Stz204579EOF 5464176Stz204579 } 5474176Stz204579 closeHeaderFiles(@Hfile); 5484176Stz204579} 5494176Stz204579 5504176Stz204579sub generateTableC { 5514176Stz204579 my $event = shift; 5524176Stz204579 my $eventId = shift; 5534176Stz204579 my $eventType = shift; 5544176Stz204579 my $eventHeader = shift; 5554176Stz204579 my $omit = shift; 5564176Stz204579 5574176Stz204579 my %tokenType = ( 558*5537Sgww # 559*5537Sgww # tokenTypes are the ones that are actually defined 560*5537Sgww # for use in adt.xml audit records 561*5537Sgww # 562*5537Sgww 563*5537Sgww # 'acl' => 'AUT_ACL', # not defined 564*5537Sgww # 'arbitrary' => 'AUT_ARBITRARY', # not defined 565*5537Sgww # 'arg' => 'AUT_ARG', # not defined 566*5537Sgww # 'attr' => 'AUT_ATTR', 5674176Stz204579 'command' => 'AUT_CMD', 5684176Stz204579 'command_1' => 'ADT_CMD_ALT', # dummy token id 569*5537Sgww # 'date' => 'AUT_TEXT', # not used 570*5537Sgww # 'exec_args' => 'AUT_EXEC_ARGS', # not defined 571*5537Sgww # 'exec_env' => 'AUT_EXEC_ENV', # not defined 572*5537Sgww # 'exit' => 'AUT_EXIT', # not defined 5734176Stz204579 'fmri' => 'AUT_FMRI', 574*5537Sgww # 'groups' => 'AUT_GROUPS', # not defined 575*5537Sgww # 'header' => 'AUT_HEADER', # not defined 576*5537Sgww 'in_peer' => 'ADT_IN_PEER', # dummy token id 5774176Stz204579 'tid' => 'AUT_TID', 578*5537Sgww # 'ipc' => 'AUT_IPC', # not defined 579*5537Sgww # 'ipc_perm' => 'AUT_IPC_PERM', # not defined 580*5537Sgww # 'iport' => 'AUT_IPORT', # not defined 5814176Stz204579 'label' => 'AUT_LABEL', 5824176Stz204579 'newgroups' => 'AUT_NEWGROUPS', 583*5537Sgww # 'opaque' => 'AUT_OPAQUE', # not defined 5844176Stz204579 'path' => 'AUT_PATH', 5854176Stz204579 'path_list' => '-AUT_PATH', # dummy token id 5864176Stz204579 'process' => 'AUT_PROCESS', 5874176Stz204579 'priv_effective' => 'ADT_AUT_PRIV_E', # dummy token id 5884176Stz204579 'priv_limit' => 'ADT_AUT_PRIV_L', # dummy token id 5894176Stz204579 'priv_inherit' => 'ADT_AUT_PRIV_I', # dummy token id 5904176Stz204579 'return' => 'AUT_RETURN', 591*5537Sgww # 'seq' => 'AUT_SEQ', # not defined 592*5537Sgww # 'socket' => 'AUT_SOCKET', # not defined 593*5537Sgww # 'socket-inet' => 'AUT_SOCKET_INET', 5944176Stz204579 'subject' => 'AUT_SUBJECT', 5954176Stz204579 'text' => 'AUT_TEXT', 596*5537Sgww # 'trailer' => 'AUT_TRAILER', # not defined 5974176Stz204579 'uauth' => 'AUT_UAUTH', 5984176Stz204579 'zonename' => 'AUT_ZONENAME' 5994176Stz204579 ); 6004176Stz204579 6014176Stz204579 my @xlateEntryList = (); 6024176Stz204579 6034176Stz204579 my $external = $event->getExternal(); 6044176Stz204579 my $internal = $event->getInternal(); 6054176Stz204579 6064176Stz204579 unless ($external) { 6074176Stz204579 print STDERR "No external object captured for event $eventId\n"; 6084176Stz204579 return; 6094176Stz204579 } 6104176Stz204579 if ($eventType) { 6114176Stz204579 $nameTranslation{$eventId} = $eventId; 6124176Stz204579 } else { 6134176Stz204579 $nameTranslation{$eventId} = $external->getInternalName(); 6144176Stz204579 } 6154176Stz204579 unless ($internal) { 6164176Stz204579 print STDERR "No internal object captured for event $eventId\n"; 6174176Stz204579 return; 6184176Stz204579 } 6194176Stz204579 my @entryRef = $internal->getEntries(); 6204176Stz204579 my $entryRef; 6214176Stz204579 my @tokenOrder = (); 6224176Stz204579 my $firstTokenIndex = 0; # djdj not used yet, djdj BUG! 6234176Stz204579 # needs to be used by translate table 6244176Stz204579 6254176Stz204579 if ($internal->isReorder()) { # prescan the entry list to get the token order 6264176Stz204579 my @inputOrder; 6274176Stz204579 foreach $entryRef (@entryRef) { 6284176Stz204579 my ($intEntry, $entry) = @$entryRef; 6294176Stz204579 push (@inputOrder, $intEntry->getAttr('order')); 6304176Stz204579 } 6314176Stz204579 6324176Stz204579 my $i; # walk down the inputOrder list once 6334176Stz204579 my $k = 1; # discover next in line 6344176Stz204579 my $l = 0; # who should point to next in line 6354176Stz204579 for ($i = 0; $i <= $#inputOrder; $i++) { 6364176Stz204579 my $j; 6374176Stz204579 for ($j = 0; $j <= $#inputOrder; $j++) { 6384176Stz204579 if ($k == $inputOrder[$j]) { 6394176Stz204579 if ($k == 1) { 6404176Stz204579 $firstTokenIndex = $j; 6414176Stz204579 } else { 6424176Stz204579 $tokenOrder[$l] = "&(selfReference[$j])"; 6434176Stz204579 } 6444176Stz204579 $l = $j; 6454176Stz204579 last; 6464176Stz204579 } 6474176Stz204579 } 6484176Stz204579 $k++; 6494176Stz204579 } 6504176Stz204579 $tokenOrder[$l] = 'NULL'; 6514176Stz204579 } 6524176Stz204579 else { # default order -- input order same as output 6534176Stz204579 my $i; 6544176Stz204579 my $j; 6554176Stz204579 for ($i = 0; $i < $#entryRef; $i++) { 6564176Stz204579 my $j = $i + 1; 6574176Stz204579 $tokenOrder[$i] = "&(selfReference[$j])"; 6584176Stz204579 } 6594176Stz204579 $tokenOrder[$#entryRef] = 'NULL'; 6604176Stz204579 } 6614176Stz204579 6624176Stz204579 my $sequence = 0; 6634176Stz204579 foreach $entryRef (@entryRef) { 6644176Stz204579 my ($intEntry, $entry) = @$entryRef; 6654176Stz204579 my $entryId = $entry->getAttr('id'); 6664176Stz204579 6674176Stz204579 my ($extEntry, $unusedEntry, $tokenId) = 6684176Stz204579 $external->getEntry($entryId); 6694176Stz204579 my $opt = $extEntry->getAttr('opt'); 6704176Stz204579 6714176Stz204579 if ($opt eq 'none') { 6724176Stz204579 if (defined ($doc->getToken($tokenId))) { 6734176Stz204579 if (defined ($tokenType{$tokenId})) { 6744176Stz204579 $tokenId = $tokenType{$tokenId}; 6754176Stz204579 } 6764176Stz204579 else { 6774176Stz204579 print STDERR "token id $tokenId not implemented\n"; 6784176Stz204579 } 6794176Stz204579 } 6804176Stz204579 else { 6814176Stz204579 print STDERR "token = $tokenId is undefined\n"; 6824176Stz204579 $tokenId = 'error'; 6834176Stz204579 } 6844176Stz204579 my ($xlate, $jni) = 6855300Sgww formatTableEntry ('', $tokenId, $eventId, '', 0, 0, 6865300Sgww $tokenOrder[$sequence], 'NULL', $omit); 6874176Stz204579 push (@xlateEntryList, $xlate); 6884176Stz204579 } 6894176Stz204579 else { 6904176Stz204579 my $dataType = $extEntry->getAttr('type'); 6914176Stz204579 $dataType =~ s/\s+//g; # remove blanks (char * => char*) 6924176Stz204579 6934176Stz204579 my $enumGroup = ''; 6944176Stz204579 if ($dataType =~ /^msg/i) { 6954176Stz204579 $enumGroup = $dataType; 6964176Stz204579 $enumGroup =~ s/^msg\s*//i; 6974176Stz204579 $enumGroup = 'adt_' . $enumGroup; 6984176Stz204579 } 6994176Stz204579 my $required = ($opt eq 'required') ? 1 : 0; 7004176Stz204579 my $tsol = 0; 7014176Stz204579 my $tokenId = $intEntry->getAttr('token'); 7024176Stz204579 my $token; 7034176Stz204579 my $tokenName; 7044176Stz204579 my $tokenFormat = $intEntry->getAttr('format'); 7054176Stz204579 if (defined ($tokenFormat)) { 7064176Stz204579 $tokenFormat = "\"$tokenFormat\""; 7074176Stz204579 } 7084176Stz204579 else { 7094176Stz204579 $tokenFormat = 'NULL'; 7104176Stz204579 } 7114176Stz204579 7124176Stz204579 if (defined ($token = $doc->getToken($tokenId))) { 7134176Stz204579 $tsol = (lc $token->getUsage() eq 'tsol') ? 1 : 0; 7144176Stz204579 if (defined ($tokenType{$tokenId})) { 7154176Stz204579 $tokenName = $tokenType{$tokenId}; 7164176Stz204579 } 7174176Stz204579 else { 7184176Stz204579 print STDERR "token id $tokenId not implemented\n"; 7194176Stz204579 } 7204176Stz204579 } 7214176Stz204579 else { 7224176Stz204579 print STDERR 7234176Stz204579 "$tokenId is an unimplemented token ($entryId in $eventId)\n"; 7244176Stz204579 $tokenName = 'AUT_TEXT'; 7254176Stz204579 } 7264176Stz204579 my ($xlate, $jni) = 7274176Stz204579 formatTableEntry($entryId, $tokenName, $eventId, $dataType, $required, 7284176Stz204579 $tsol, $tokenOrder[$sequence], $tokenFormat, 7295300Sgww $enumGroup, $omit); 7304176Stz204579 push (@xlateEntryList, $xlate); 7314176Stz204579 } 7324176Stz204579 $sequence++; 7334176Stz204579 } 7344176Stz204579 $xlateEventTable{$eventId} = [\@xlateEntryList, $eventType, $firstTokenIndex, 7354176Stz204579 $eventHeader]; 7364176Stz204579} 7374176Stz204579 7384176Stz204579sub formatTableEntry { 7395300Sgww my ($id, $token, $eventId, $type, $required, $tsol, $sequence, $format, 7405300Sgww $enumGroup, $omitEntry) = @_; 7414176Stz204579 7424176Stz204579 7434176Stz204579 # does this map belong in the xml source? (at least the defaults?) 7444176Stz204579 # fill in the default value only if it is other than zero. 7454176Stz204579 # base type adt name, default value 7464176Stz204579 my %entryDef = ( 'au_asid_t' => ['ADT_UINT32', ''], 7474176Stz204579 'uint_t' => ['ADT_UINT32', ''], 7484176Stz204579 'int' => ['ADT_INT', ''], 7494176Stz204579 'int32_t' => ['ADT_INT32', ''], 7504176Stz204579 'uid_t' => ['ADT_UID', 'AU_NOAUDITID'], 7514176Stz204579 'gid_t' => ['ADT_GID', 'AU_NOAUDITID'], 7524176Stz204579 'uid_t*' => ['ADT_UIDSTAR', ''], 7534176Stz204579 'gid_t*' => ['ADT_GIDSTAR', ''], 7544176Stz204579 'char' => ['ADT_CHAR', ''], 7554176Stz204579 'char*' => ['ADT_CHARSTAR', ''], 7564176Stz204579 'char**' => ['ADT_CHAR2STAR', ''], 7574176Stz204579 'long' => ['ADT_LONG', ''], 7584176Stz204579 'pid_t' => ['ADT_PID', ''], 7594176Stz204579 'priv_set_t*' => ['ADT_PRIVSTAR', ''], 7604176Stz204579 'ulong_t' => ['ADT_ULONG', ''], 7614176Stz204579 'uint16_t', => ['ADT_UINT16', ''], 7624176Stz204579 'uint32_t' => ['ADT_UINT32', ''], 7634176Stz204579 'uint32_t*' => ['ADT_UINT32STAR', ''], 7644176Stz204579 'uint32_t[]' => ['ADT_UINT32ARRAY', ''], 7654176Stz204579 'uint64_t' => ['ADT_UINT64', ''], 7664176Stz204579 'uint64_t*' => ['ADT_UINT64STAR', ''], 7674176Stz204579 'm_label_t*' => ['ADT_MLABELSTAR', ''], 7684176Stz204579 ); 7694176Stz204579 my $xlateLabel = $uniLabel.$xlateUniLabelInc; 7704176Stz204579 my $xlateLabelInc = 0; 7714176Stz204579 my $xlateLine = ''; 7724176Stz204579 my @jniLine = (); 7734176Stz204579 7744176Stz204579 # the list handling should be a simple loop with a loop of one 7754176Stz204579 # falling out naturally. 7764176Stz204579 7774176Stz204579 unless ($type =~ /,/) { # if list, then generate sequence of entries 7784176Stz204579 my $dataType; 7794176Stz204579 my $dataSize; 7804176Stz204579 my $xlateLabelRef = ''; 7814176Stz204579 7824176Stz204579 my $arraySize = ''; 7834176Stz204579 $arraySize = $1 if ($type =~ s/\[(\d+)\]/[]/); 7844176Stz204579 7854176Stz204579 my $entryType = ${$entryDef{$type}}[0]; 7864176Stz204579 7874176Stz204579 my @xlateType = (); # for adt_xlate.c 7884176Stz204579 my $typeCount = 1; 7894176Stz204579 7904176Stz204579 if ($entryType) { 7914176Stz204579 $dataType = $entryType; 7924176Stz204579 $type =~ s/([^*]+)\s*(\*+)/$1 $2/; 7934176Stz204579 $type =~ s/\[\]//; 7944176Stz204579 $dataSize = "sizeof ($type)"; 7954176Stz204579 if ($arraySize) { 7964176Stz204579 $dataSize = "$arraySize * " . $dataSize; 7974176Stz204579 } 7984176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 7994176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 8004176Stz204579 } elsif ($type eq '') { 8014176Stz204579 $xlateLabelRef = 'NULL'; 8024176Stz204579 } elsif ($type =~ /^msg/i) { 8034176Stz204579 $type =~ s/^msg//i; 8044176Stz204579 $dataType = 'ADT_MSG'; 8054176Stz204579 my $dataEnum = 'ADT_LIST_' . uc $type; 8064176Stz204579 $xlateLine = "{{$dataType, $dataEnum}}"; 8074176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 8084176Stz204579 } elsif ($type =~ /time_t/i) { 8094176Stz204579 $dataType = 'ADT_DATE'; 8104176Stz204579 $dataSize = "sizeof (time_t)"; 8114176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 8124176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 8134176Stz204579 } elsif ($type =~ /termid/i) { 8144176Stz204579 $dataType = 'ADT_TERMIDSTAR'; 8154176Stz204579 $dataSize = "sizeof (au_tid_addr_t *)"; 8164176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 8174176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 8185300Sgww } elsif (uc $omitEntry eq 'JNI') { 8194176Stz204579 $xlateLabelRef = 'NULL'; 8204176Stz204579 } else { 8214176Stz204579 print STDERR "$type is not an implemented data type\n"; 8224176Stz204579 $xlateLabelRef = 'NULL'; 8234176Stz204579 } 8244176Stz204579 if ($xlateLine && !($xlateTypeList{$xlateLine})) { 8254176Stz204579 $xlateTypeList{$xlateLine} = $xlateLabel; 8264176Stz204579 push (@xlateTypeList, "datadef\t$xlateLabel\[1\] =\t$xlateLine;"); 8274176Stz204579 $xlateLabelInc = 1; 8284176Stz204579 } else { 8294176Stz204579 $xlateLabel = $xlateTypeList{$xlateLine}; 8304176Stz204579 } 8314176Stz204579 $xlateLabelRef = '&' . $xlateLabel . '[0]' 8324176Stz204579 unless $xlateLabelRef eq 'NULL'; 8334176Stz204579 8344176Stz204579 # "EOL" is where a comma should go unless end of list 8354176Stz204579 $xlateLine = "{$token,\t1,\t$xlateLabelRef,\t$sequence,\n" . 8364176Stz204579 "\t\t0,\t$required,\t$tsol,\t$format}EOL"; 8374176Stz204579 8385300Sgww if (uc $omitEntry ne 'ALWAYS' && ${$entryDef{$type}}[1]) { 8394176Stz204579 my @list = (); 8404176Stz204579 if ($xlateDefault{$eventId}) { 8414176Stz204579 @list = @{$xlateDefault{$eventId}}; 8424176Stz204579 } else { 8434176Stz204579 push (@xlateDefaults, $eventId); 8444176Stz204579 } 8454176Stz204579 push (@list, $id, ${$entryDef{$type}}[1]); 8464176Stz204579 $xlateDefault{$eventId} = \@list; 8474176Stz204579 } 8484176Stz204579 } else { # is a list 8494176Stz204579 my @type = split(/,/, $type); 8504176Stz204579 my @arraySize = (); 8514176Stz204579 my @id = split(/,/, $id); 8524176Stz204579 my @jniId = @id; 8534176Stz204579 my $dataType; 8544176Stz204579 my $typeCount = ($#type + 1); 8554176Stz204579 my @xlateType = (); 8564176Stz204579 my @default = (); 8574176Stz204579 8584176Stz204579 foreach my $dtype (@type) { 8594176Stz204579 my $jniId = shift @jniId; 8604176Stz204579 my $id = shift @id; 8614176Stz204579 my $arraySize = ''; 8624176Stz204579 $arraySize = $1 if ($dtype =~ s/\[(\d+)\]/[]/); 8634176Stz204579 8644176Stz204579 my $entryType = ${$entryDef{$dtype}}[0]; 8654176Stz204579 if ($entryType) { 8664176Stz204579 my $type = $dtype; 8674176Stz204579 $type =~ s/([^*]+)\s*(\*+)/$1 $2/; 8684176Stz204579 $type =~ s/\[\]//; 8694176Stz204579 8704176Stz204579 my $sizeString = "sizeof"; 8714176Stz204579 $sizeString = "$arraySize * " . $sizeString if $arraySize; 8724176Stz204579 push (@xlateType, "\{$entryType, $sizeString ($type)\}"); 8734176Stz204579 push (@jniLine, [$jniId, $entryType, $format, $enumGroup, $required]); 8744176Stz204579 } elsif ($type =~ /^msg/i) { 8754176Stz204579 $type =~ s/^msg//i; 8764176Stz204579 $dataType = 'ADT_MSG'; 8774176Stz204579 my $dataEnum = 'ADT_LIST_' . uc $type; 8784176Stz204579 push (@xlateType, "\{$dataType, $dataEnum\}};"); 8794176Stz204579 push (@jniLine, [$jniId, $dataType, $format, $enumGroup, $required]); 8804176Stz204579 } elsif ($type =~ /time_t/i) { 8814176Stz204579 $dataType = 'ADT_DATE'; 8824176Stz204579 push (@xlateType, "\{$entryType, sizeof ($type)\}"); 8834176Stz204579 push (@jniLine, [$jniId, $entryType, $format, $enumGroup, $required]); 8844176Stz204579 } elsif ($type =~ /termid/i) { 8854176Stz204579 $dataType = 'ADT_TERMIDSTAR'; 8864176Stz204579 push (@xlateType, "\{$dataType, sizeof (au_tid_addr_t *)\}"); 8874176Stz204579 push (@jniLine, [$jniId, $dataType, $format, $enumGroup, $required]); 8885300Sgww } elsif (uc $omitEntry eq 'JNI') { 8894176Stz204579 # nothing to do. 8904176Stz204579 } else { 8914176Stz204579 print STDERR "$dtype is not an implemented data type\n"; 8924176Stz204579 } 8935300Sgww if (uc $omitEntry ne 'ALWAYS' && ${$entryDef{$dtype}}[1]) { 8944176Stz204579 push (@default, $id, ${$entryDef{$dtype}}[1]); 8954176Stz204579 } 8964176Stz204579 } 8974176Stz204579 my $xlateArray = "\[$typeCount\] =\t{" . join(",\n\t\t\t\t", @xlateType) . "};"; 8984176Stz204579 8994176Stz204579 unless ($xlateTypeList{$xlateArray}) { 9004176Stz204579 $xlateTypeList{$xlateArray} = $xlateLabel; 9014176Stz204579 $xlateArray = "datadef\t$xlateLabel" . $xlateArray; 9024176Stz204579 push (@xlateTypeList, $xlateArray); 9034176Stz204579 $xlateLabelInc = 1; 9044176Stz204579 } else { 9054176Stz204579 $xlateLabel = $xlateTypeList{$xlateArray}; 9064176Stz204579 } 9074176Stz204579 $xlateLine = 9084176Stz204579 "{$token,\t$typeCount,\t&$xlateLabel\[0\],\t$sequence,\n" . 9094176Stz204579 "\t\t0,\t$required,\t$tsol,\t$format}EOL"; 9104176Stz204579 if (@default) { 9114176Stz204579 my @list = (); 9124176Stz204579 if ($xlateDefault{$eventId}) { 9134176Stz204579 @list = @{$xlateDefault{$eventId}}; 9144176Stz204579 } else { 9154176Stz204579 push (@xlateDefaults, $eventId); 9164176Stz204579 } 9174176Stz204579 push (@list, @default); 9184176Stz204579 $xlateDefault{$eventId} = \@list; 9194176Stz204579 } 9204176Stz204579 } 9214176Stz204579 $xlateUniLabelInc++ if $xlateLabelInc; 9224176Stz204579 return ($xlateLine, \@jniLine); 9234176Stz204579} 9244176Stz204579 9254176Stz204579sub generateAPIFile { 9264176Stz204579 my $event = shift; 9274176Stz204579 my $eventId = shift; 9284176Stz204579 my $eventType = shift; 9294176Stz204579 my $eventHeader = shift; 9304176Stz204579 my $idNo = shift; 9314176Stz204579 9324176Stz204579 my @entryList = (); 9334176Stz204579 9344176Stz204579 my $external = $event->getExternal(); 9354176Stz204579 9364176Stz204579 if ($eventType && $debug) { 9374176Stz204579 print STDERR "event $eventId is of type $eventType\n"; 9384176Stz204579 } 9394176Stz204579 9404176Stz204579 return unless $external; 9414176Stz204579 9424176Stz204579 my ($extEntry, $entry, $tokenId, $format); 9434176Stz204579 while (($extEntry, $entry, $tokenId, $format) = $external->getNextEntry()) { 9444176Stz204579 last unless $entry; 9454176Stz204579 my $entryId = $entry->getAttr('id'); 9464176Stz204579 9474176Stz204579 unless (defined $entryId) { 9484176Stz204579 print STDERR "undefined entry id for external $eventId\n"; 9494176Stz204579 next; 9504176Stz204579 } 9514176Stz204579 my $option = $extEntry->getAttr('opt'); 9524176Stz204579 next if ($option eq 'none'); 9534176Stz204579 9544176Stz204579 if (defined (my $token = $doc->getToken($tokenId))) { 9554176Stz204579 $option = 'Trusted Solaris only' 9564176Stz204579 if (lc $token->getUsage() eq 'tsol') ? 1 : 0; 9574176Stz204579 } 9584176Stz204579 $option .= " (format: $format)" if $format; 9594176Stz204579 9604176Stz204579 my $dataType = $extEntry->getAttr('type'); 9614176Stz204579 unless (defined $dataType) { 9624176Stz204579 print STDERR "no type defined for external tag for $eventId\n"; 9634176Stz204579 $dataType = "error"; 9644176Stz204579 } 9654176Stz204579 9664176Stz204579 my $comment = $entry->getContent(); 9674176Stz204579 9684176Stz204579 if (($dataType =~ /,/) || ($entryId =~ /,/)) { 9694176Stz204579 my @type = split(/\s*,\s*/, $dataType); 9704176Stz204579 my @id = split(/\s*,\s*/, $entryId); 9714176Stz204579 if ($#type != $#id) { 9724176Stz204579 print STDERR 9734176Stz204579 "number of data types ($dataType) does not match number of ids ($entryId)", 9744176Stz204579 " for event $eventId\n"; 9754176Stz204579 if ($#type < $#id) { 9764176Stz204579 $#id = $#type; 9774176Stz204579 } 9784176Stz204579 else { 9794176Stz204579 $#type = $#id; 9804176Stz204579 } 9814176Stz204579 } 9824176Stz204579 9834176Stz204579 my $i; 9844176Stz204579 my $line = ''; 9854176Stz204579 $line = "/* $comment */\n\t" if defined $comment; 9864176Stz204579 for ($i = 0; $i <= $#type; $i++) { 9874176Stz204579 my ($primitive, $dereference) = 9884176Stz204579 ($type[$i] =~ /([^\*]+)\s*(\**)/); 9894176Stz204579 $id[$i] .= $1 if ($primitive =~ s/(\[\d+\])//); 9904176Stz204579 $line .= "$primitive\t$dereference$id[$i];\t/* $option */"; 9914176Stz204579 push (@entryList, $line); 9924176Stz204579 $line = ''; 9934176Stz204579 } 9944176Stz204579 } 9954176Stz204579 else { 9964176Stz204579 my $line = ''; 9974176Stz204579 $line = "/* $comment */\n\t" if defined $comment; 9984176Stz204579 if ($dataType =~ /^msg/i) { 9994176Stz204579 $dataType =~ s/^msg\s*//i; 10004176Stz204579 $line .= "enum adt_$dataType" . "\t$entryId;\t/* $option */"; 10014176Stz204579 } 10024176Stz204579 elsif ($dataType =~ /time_t/i) { 10034176Stz204579 $line .= "time_t\t$entryId;\t/* $option */"; 10044176Stz204579 } 10054176Stz204579 else { 10064176Stz204579 my ($primitive, $dereference) = 10074176Stz204579 ($dataType =~ /([^\*]+)\s*(\**)/); 10084176Stz204579 $entryId .= $1 if ($primitive =~ s/(\[\d+\])//); 10094176Stz204579 $line .= "$primitive\t$dereference$entryId;\t/* $option */"; 10104176Stz204579 } 10114176Stz204579 push (@entryList, $line); 10124176Stz204579 } 10134176Stz204579 } 10144176Stz204579 $eventExtra{$eventId} = [$eventHeader, $idNo]; 10154176Stz204579 $eventAPI{$eventId} = \@entryList; 10164176Stz204579} 10174176Stz204579 10184176Stz204579sub generateMsgLists { 10194176Stz204579 my $textList = shift; 10204176Stz204579 10214176Stz204579 my $textName = $textList->getId(); 10224176Stz204579 my $header = $textList->getHeader(); 10234176Stz204579 my $start = $textList->getMsgStart(); 10244176Stz204579 my $public = $textList->getMsgPublic(); 10254176Stz204579 my $deprecated = $textList->getDeprecated(); 10264176Stz204579 10274176Stz204579 addHeader($header); 10284176Stz204579 print "$textName starts at $start\n" if $debug; 10294176Stz204579 10304176Stz204579 my $entry; 10314176Stz204579 my @entry; 10324176Stz204579 while ($entry = $textList->getNextMsg()) { 10334176Stz204579 if ($debug) { 10344176Stz204579 my ($id, $text) = split(/\s*::\s*/, $entry); 10354176Stz204579 print " $id = $text\n"; 10364176Stz204579 } 10374176Stz204579 unshift (@entry, $entry); 10384176Stz204579 } 10394176Stz204579 $msg_list{$textName} = 10404176Stz204579 [\@entry, [$header, $start, $public, $deprecated]]; 10414176Stz204579} 10424176Stz204579 10434176Stz204579sub addHeader { 10444176Stz204579 my $header_index = shift; 10454176Stz204579 10464176Stz204579 die "invalid adt_event_N.h index: $header_index\n" 10474176Stz204579 unless ($header_index =~ /^\d+$/); 10484176Stz204579 10494176Stz204579 $headers{$header_index} = $header_index; 10504176Stz204579} 10514176Stz204579 10524176Stz204579# $header = 0 is a special case; it is for adt_event.h 10534176Stz204579# $header > 0 creates adt_event_N.h, where N = $header 10544176Stz204579 10554176Stz204579sub openHeaderFiles { 10564176Stz204579 my $outfile = shift; # path to an adt_event_N.h file 10574176Stz204579 10584176Stz204579 my $header; 10594176Stz204579 my @Hfile = (); # potentially sparse array of file handles 10604176Stz204579 my @HfileName = (); # parallel array to Hfile, file name (not path) 10614176Stz204579 foreach $header (sort keys %headers) { 10624176Stz204579 my $file = $outfile; 10634176Stz204579 if ($header > 0) { 10644176Stz204579 $file =~ s/_N/_$header/; 10654176Stz204579 } else { 10664176Stz204579 $file =~ s/_N//; 10674176Stz204579 } 10684176Stz204579 unless (open($Hfile[$header], ">$file")) { 10694176Stz204579 print STDERR "can't open output ($file): $!\n"; 10704176Stz204579 $HfileName[$header] = ''; 10714176Stz204579 $Hfile[$header] = ''; 10724176Stz204579 } else { 10734176Stz204579 my @tmp = split(/\//, $file); 10744176Stz204579 $HfileName[$header] = $tmp[$#tmp]; 10754176Stz204579 } 10764176Stz204579 } 10774176Stz204579 return (@Hfile); 10784176Stz204579} 10794176Stz204579 10804176Stz204579sub closeHeaderFiles { 10814176Stz204579 my @Hfile = @_; 10824176Stz204579 10834176Stz204579 my $header; 10844176Stz204579 foreach $header (sort keys %headers) { 10854176Stz204579 close $Hfile[$header] if $Hfile[$header]; 10864176Stz204579 } 10874176Stz204579} 1088