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# 235777Stw21770# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 244176Stz204579# Use is subject to license terms. 254176Stz204579# 264176Stz204579# 274176Stz204579 284176Stz204579# auditxml [-d] <xml input file> 294176Stz204579 304176Stz204579# auditxml takes the audit record description (.xml file) and 314176Stz204579# generates the files needed for the C audit api. 324176Stz204579 334176Stz204579use auditxml; 344176Stz204579use Getopt::Std; 354176Stz204579use vars qw($opt_d); 364176Stz204579use strict; 374176Stz204579 384176Stz204579 394176Stz204579our $debug = 0; # normal use is to set via the file being parsed. 404176Stz204579 # <debug set="on"/> or <debug set="off"/> or <debug/> 414176Stz204579 # if the set attribute is omitted, debug state is toggled 424176Stz204579 # Override with appDebug, but toggle won't do what you 434176Stz204579 # want. 444176Stz204579my $appDebug = 0; # used after return from "new auditxml"; 454176Stz204579 464176Stz204579my $genNotice = " 474176Stz204579DO NOT EDIT. This file is auto generated by the Solaris Audit 484176Stz204579system from adt.xml. 494176Stz204579 504176Stz204579See http://opensolaris.org/os/project/audit/ 514176Stz204579"; 524176Stz204579 534176Stz204579# trim leading/trailing newlines 544176Stz204579$genNotice =~ s/^\n//s; 554176Stz204579$genNotice =~ s/\n$//s; 564176Stz204579my $prog = $0; $prog =~ s|.*/||g; 574176Stz204579my $usage = "usage: $prog [-d] file.xml\n"; 584176Stz204579 594176Stz204579getopts('d'); 604176Stz204579 614176Stz204579$appDebug = $opt_d; 624176Stz204579 634176Stz204579my $uniLabel = "adr"; 644176Stz204579my $xlateUniLabelInc = 0; 654176Stz204579 664176Stz204579die $usage if ($#ARGV < 0); 674176Stz204579 684176Stz204579# where everything comes from and where it goes: 694176Stz204579 704176Stz204579my $bsmBuildPath = "./common"; 714176Stz204579my $xlateFile = "$bsmBuildPath/adt_xlate.c"; 724176Stz204579my $headerFile = "$bsmBuildPath/adt_event_N.h"; 734176Stz204579 744176Stz204579my $doc = new auditxml ($ARGV[0]); # input XML file 754176Stz204579 764176Stz204579$debug = $appDebug; 774176Stz204579 784176Stz204579my %xlateEventTable = (); 794176Stz204579my @xlateTypeList = (); 804176Stz204579my %xlateTypeList = (); 814176Stz204579my %eventAPI = (); 824176Stz204579my %eventExtra = (); 834176Stz204579my %headers = (); 844176Stz204579my %externalIdNo = (); 854176Stz204579my @outputState = (); 864176Stz204579my %nameTranslation = (); 874176Stz204579my @xlateDefaults = (); 884176Stz204579my %xlateDefault = (); 894176Stz204579my %msg_list = (); 904176Stz204579 914176Stz204579my $event; 924176Stz204579while ($event = $doc->getNextEvent()) { 934176Stz204579 my $eventId = $event->getId(); 944176Stz204579 my $eventHeader = $event->getHeader(); 954176Stz204579 my $idNo = $event->getIdNo(); 964176Stz204579 $externalIdNo{$eventId} = $idNo; 974176Stz204579 addHeader($eventHeader) if defined ($eventHeader); 984176Stz204579 my $super; 994176Stz204579 my $omit = $event->getOmit(); 1004176Stz204579 my $eventType = ''; 1014176Stz204579 if ($super = $event->getSuperClass()) { 1024176Stz204579 $event = $super; 1034176Stz204579 $eventType = 'instance'; 1044176Stz204579 } else { 1054176Stz204579 $eventType = $event->getType(); 1064176Stz204579 } 1074176Stz204579 1084176Stz204579 # header file for API use 1094176Stz204579 generateAPIFile($event, $eventId, $eventType, $eventHeader, $idNo) 1104176Stz204579 unless $omit eq 'always'; 1114176Stz204579 1124176Stz204579 # c file table for translation 1134176Stz204579 generateTableC($event, $eventId, $eventType, $eventHeader, $omit); 1144176Stz204579} 1154176Stz204579 1164176Stz204579my $textList; 1174176Stz204579while ($textList = $doc->getNextMsgId()) { 1184176Stz204579 generateMsgLists($textList); # enum -> text mappings 1194176Stz204579} 1204176Stz204579 1214176Stz204579printTableC($xlateFile); 1224176Stz204579printAPIFile($headerFile, $doc); 1234176Stz204579 1244176Stz204579exit 0; 1254176Stz204579 1264176Stz204579 1274176Stz204579sub printTableC { 1284176Stz204579 my $file = shift; 1294176Stz204579 1304176Stz204579 unless (open(Cfile, ">$file")) { 1314176Stz204579 print STDERR "can't open output file ($file): $!\n"; 1324176Stz204579 return; 1334176Stz204579 } 1344176Stz204579 1354176Stz204579 my $notice = $genNotice; 1364176Stz204579 $notice =~ s/\n/\n * /gs; 1374176Stz204579 $notice =~ s/\s+\n/\n/gs; 1384176Stz204579 print Cfile <<EOF; 1394176Stz204579/* 1404176Stz204579 * $notice 1414176Stz204579 */ 1424176Stz204579 1434176Stz204579#include <bsm/libbsm.h> 1444176Stz204579#include <adt_xlate.h> 1454176Stz204579#include <libintl.h> 1464176Stz204579 1474176Stz204579EOF 1484176Stz204579 print Cfile "#ifndef _PRAUDIT\n"; 1494176Stz204579 print Cfile "/* Internal data type definitions */\n\n"; 1504176Stz204579 my $extDef; 1514176Stz204579 foreach $extDef (@xlateTypeList) { 1524176Stz204579 print Cfile "static $extDef\n"; 1534176Stz204579 } 1544176Stz204579 @xlateTypeList = (); 1554176Stz204579 1564176Stz204579 print Cfile "\n/* External event structure to internal event structure */\n\n"; 1574176Stz204579 1584176Stz204579 my @pointers = (); 1594176Stz204579 1604176Stz204579 foreach my $eventId (sort keys %xlateEventTable) { 1614176Stz204579 if ($xlateEventTable{$eventId}) { 1624176Stz204579 my ($ref1, $eventType, $firstToken, $eventHeader) = 1634176Stz204579 @{$xlateEventTable{$eventId}}; 1644176Stz204579 my @entries = @$ref1; 1654176Stz204579 my $entry; 1664176Stz204579 my $entries = $#entries; 1674176Stz204579 my $count = $entries + 1; 1684176Stz204579 my $externalName = $nameTranslation{$eventId}; 1694176Stz204579 my $externalRoot = $externalName; 1704176Stz204579 $externalRoot =~ s/AUE_//; 1714176Stz204579 my $structName = "XX_$externalRoot"; 1724176Stz204579 my $root = $eventId; 1734176Stz204579 $root =~ s/AUE_//; 1744176Stz204579 my $externalId = $eventId; 1754176Stz204579 $externalId =~ s/AUE_/ADT_/; 1764176Stz204579 1774176Stz204579 unless ($eventType eq 'generic') { 1784176Stz204579 print Cfile "static struct entry $structName\[$count\] = {\n"; 1794176Stz204579 foreach $entry (@entries) { 1804176Stz204579 if ($entries--) { 1814176Stz204579 $entry =~ s/EOL/,/; 1824176Stz204579 } 1834176Stz204579 else { 1844176Stz204579 $entry =~ s/EOL//; 1854176Stz204579 } 1864176Stz204579 $entry =~ s/selfReference/$structName/; 1874176Stz204579 print Cfile "\t$entry\n"; 1884176Stz204579 } 1894176Stz204579 print Cfile "};\n"; 1904176Stz204579 1914176Stz204579 print Cfile "static struct translation X_$externalRoot = {\n"; 1924176Stz204579 push (@pointers, "X_$externalRoot"); 1934176Stz204579 1944176Stz204579 print Cfile "\t0,\n"; # tx_offsetsCalculated = 0 1954176Stz204579 print Cfile "\t$externalId,\n"; 1964176Stz204579 print Cfile "\t$externalName,\n"; 1974176Stz204579 1984176Stz204579 print Cfile "\t$count,\n"; 1994176Stz204579 print Cfile "\t&XX_$externalRoot\[$firstToken\],\n"; 2004176Stz204579 print Cfile "\t&XX_$externalRoot\[0\]\n};\n"; 2014176Stz204579 } 2024176Stz204579 } else { 2034176Stz204579 print STDERR "expected entry for $eventId but none found\n"; 2044176Stz204579 } 2054176Stz204579 } 2064176Stz204579 2074176Stz204579 my $count = $#pointers + 2; 2084176Stz204579 print Cfile "struct translation *xlate_table[$count] = {\n"; 2094176Stz204579 2104176Stz204579 my $firstEvent = 1; 2114176Stz204579 foreach my $eventId (@pointers) { 2124176Stz204579 if ($firstEvent) { 2134176Stz204579 $firstEvent = 0; 2144176Stz204579 } 2154176Stz204579 else { 2164176Stz204579 print Cfile ",\n"; 2174176Stz204579 } 2184176Stz204579 print Cfile "\t&$eventId"; 2194176Stz204579 } 2204176Stz204579 print Cfile ",\n\tNULL\n};\n"; 2214176Stz204579 2224176Stz204579 # generate the adt_preload() function 2234176Stz204579 2244176Stz204579 print Cfile <<EOF; 2254176Stz204579 2264176Stz204579void 2274176Stz204579adt_preload(au_event_t event_id, adt_event_data_t *event_data) 2284176Stz204579{ 2294176Stz204579 switch (event_id) { 2304176Stz204579EOF 2314176Stz204579 2324176Stz204579 foreach my $id (@xlateDefaults) { 2334176Stz204579 my $adtID = $id; 2344176Stz204579 $adtID =~ s/AUE/ADT/; 2354176Stz204579 2364176Stz204579 print Cfile <<EOF; 2374176Stz204579 case $adtID: 2384176Stz204579EOF 2394176Stz204579 my @preloads = @{$xlateDefault{$id}}; 2404176Stz204579 while (@preloads) { 2414176Stz204579 my $fieldName = shift @preloads; 2424176Stz204579 my $default = shift @preloads; 2434176Stz204579 my $lcid = lc $id; 2444176Stz204579 $lcid =~ s/aue_/adt_/; 2454176Stz204579 2464176Stz204579 print Cfile <<EOF; 2474176Stz204579 event_data->$lcid.$fieldName = $default; 2484176Stz204579EOF 2494176Stz204579 } 2504176Stz204579 2514176Stz204579 print Cfile <<EOF; 2524176Stz204579 break; 2534176Stz204579EOF 2544176Stz204579 } 2554176Stz204579 2564176Stz204579 print Cfile <<EOF; 2574176Stz204579 default: 2584176Stz204579 break; 2594176Stz204579 } 2604176Stz204579} 2614176Stz204579#endif 2624176Stz204579 2634176Stz204579/* message lists */ 2644176Stz204579 2654176Stz204579EOF 2664176Stz204579 my $listName; 2674176Stz204579 my @listName; 2684176Stz204579 foreach $listName (sort keys %msg_list) { 2694176Stz204579 my ($listRef, $headref) = @{$msg_list{$listName}}; 2704176Stz204579 my ($header, $start, $public, $deprecated) = @$headref; 2714176Stz204579 2724176Stz204579 my @listValue = @$listRef; 2734176Stz204579 my $listValue; 2744176Stz204579 my $listLength = $#listValue + 1; 2754176Stz204579 2764176Stz204579 $listName = 'NULL' if ($#listValue < 0); 2774176Stz204579 2784176Stz204579 push (@listName, [$listName, $listLength - 1, $start, $public]); 2794176Stz204579 2804176Stz204579 next if ($#listValue < 0); 2814176Stz204579 2824176Stz204579 print Cfile "/* Deprecated message list */\n" if ($deprecated); 2834176Stz204579 print Cfile "static char *msg_$listName\[$listLength] = {\n"; 2844176Stz204579 2854176Stz204579 my $ffirst = 1; 2864176Stz204579 foreach $listValue (@listValue) { 2874176Stz204579 print Cfile ",\n" unless $ffirst; 2884176Stz204579 $ffirst = 0; 2894176Stz204579 my ($id, $text) = split(/\s*::\s*/, $listValue); 2904176Stz204579 if ($text) { 2914176Stz204579 print Cfile "\t\"$text\""; 2924176Stz204579 } 2934176Stz204579 else { 2944176Stz204579 print Cfile "\tNULL"; 2954176Stz204579 } 2964176Stz204579 } 2974176Stz204579 print Cfile "\n};\n"; 2984176Stz204579 } 2994176Stz204579 print Cfile "\nstruct msg_text adt_msg_text[", $#listName + 1, 3004176Stz204579 "] = {\n"; 3014176Stz204579 my $ffirst = 1; 3024176Stz204579 foreach $listName (@listName) { 3034176Stz204579 my ($name, $max, $start) = @$listName; 3044176Stz204579 $start = -$start if $start; 3054176Stz204579 print Cfile ",\n" unless $ffirst; 3064176Stz204579 $ffirst = 0; 3074176Stz204579 $name = "msg_$name" if ($name ne 'NULL'); 3084176Stz204579 print Cfile "\t{0, $max, $name, $start}"; 3094176Stz204579 } 3104176Stz204579 print Cfile "\n};\n"; 3114176Stz204579 3124176Stz204579 close Cfile; 3134176Stz204579} 3144176Stz204579 3154176Stz204579sub printAPIFile { 3164176Stz204579 my $file = shift; 3174176Stz204579 my $xmlDoc = shift; 3184176Stz204579 3194176Stz204579 my @Hfile; 3204176Stz204579 @Hfile = openHeaderFiles($file); 3214176Stz204579 3224176Stz204579 my $notice = $genNotice; 3234176Stz204579 $notice =~ s/\n/\n * /gs; 3244176Stz204579 $notice =~ s/\s+\n/\n/gs; 3254176Stz204579 3264176Stz204579 foreach my $header (keys %headers) { 3274176Stz204579 next unless $Hfile[$header]; 3284176Stz204579 *Hfile = $Hfile[$header]; 3294176Stz204579 my $include = "adt.h"; 3304176Stz204579 my $adt_event_n = "_ADT_EVENT_H"; 3314176Stz204579 if ($header > 0) { 3324176Stz204579 $include = "adt_event.h"; 3334176Stz204579 $adt_event_n = "_ADT_EVENT_".$header."_H"; 3344176Stz204579 } 3354176Stz204579 print Hfile <<EOF; 3364176Stz204579/* 3374176Stz204579 * $notice 3384176Stz204579 */ 3394176Stz204579 3404176Stz204579#ifndef $adt_event_n 3414176Stz204579#define $adt_event_n 3424176Stz204579 3434176Stz204579#include <bsm/$include> 3444176Stz204579 3454176Stz204579#ifdef __cplusplus 3464176Stz204579extern "C" { 3474176Stz204579#endif 3484176Stz204579 3494176Stz204579/* 3504176Stz204579 * adt_put_event() status values. Positive values are for kernel-generated 3514176Stz204579 * failure, -1 for user-space. For ADT_SUCCESS, the adt_put_event() return_val 3524176Stz204579 * is not used; the convention is to set it to ADT_SUCCESS. 3534176Stz204579 */ 3544176Stz204579#define ADT_SUCCESS 0 3554176Stz204579#define ADT_FAILURE -1 3564176Stz204579 3574176Stz204579EOF 3584176Stz204579 } 3594176Stz204579 3604176Stz204579 foreach my $listName (sort keys %msg_list) { 3614176Stz204579 my $shortName = uc $listName; 3624176Stz204579 $shortName =~ s/_TEXT//; 3634176Stz204579 3644176Stz204579 my ($listRef, $headref) = @{$msg_list{$listName}}; 3654176Stz204579 my ($header, $start, $public, $deprecated) = @$headref; 3664176Stz204579 next unless $Hfile[$header]; 3674176Stz204579 *Hfile = $Hfile[$header]; 3684176Stz204579 3694176Stz204579 print Hfile "/* Deprecated message list */\n" if $deprecated; 3704176Stz204579 print Hfile "#define\tADT_$shortName\t$start\n" if $start; 3714176Stz204579 3724176Stz204579 my @listValue = @$listRef; 3734176Stz204579 next unless ($#listValue >= 0); 3744176Stz204579 print Hfile "enum\tadt_$listName", " {\n"; 3754176Stz204579 3764176Stz204579 my $listValue; 3774176Stz204579 my $i = 0; 3784176Stz204579 my $j = $#listValue; 3794176Stz204579 my $comma = ','; 3804176Stz204579 foreach $listValue (@listValue) { 3814176Stz204579 my ($id, $text) = split(/\s*::\s*/, $listValue); 3824176Stz204579 $comma = '' if $i++ == $j; 3834176Stz204579 if ($start) { 3844176Stz204579 $start = " = $start$comma"; 3854176Stz204579 } else { 3864176Stz204579 $start = "$comma\t"; 3874176Stz204579 } 3884176Stz204579 $text = "(no token will be generated)" unless $text; 3895319Stz204579 my $line = "\tADT_$shortName"."_$id$start\t/* "; 3905319Stz204579 # ensure whole line does not exceed 80 chars 3915319Stz204579 my $eline = $line.$text; 3925319Stz204579 #expand tabs 3935319Stz204579 1 while $eline =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e; 3945319Stz204579 if ((length($eline) > 77) && ($line =~ /\t\t/)) { 3955319Stz204579 # 77 = 80 - length(" */") 3965319Stz204579 # strip off double tab so that comment can be longer 3975319Stz204579 $line =~ s/\t\t/\t/; 3985319Stz204579 # shorten eline; don't mind where the spaces are removed, it is 3995319Stz204579 # only $eline length which matters 4005319Stz204579 $eline =~ s/ {8}//; 4015319Stz204579 } 4025319Stz204579 if (length($eline) > 77) { # 80 - length(" */") 4035319Stz204579 # here we use negative length in substr to leave off from the 4045319Stz204579 # right side; 74 = 77 - length("...") 4055319Stz204579 $line .= substr($text, 0, 74 - length($eline)); 4065319Stz204579 # strip off part of last word (already cut) 4075319Stz204579 $line =~ s/\s(\S+)$/ /; 4085319Stz204579 $line .= "..."; 4095319Stz204579 } else { 4105319Stz204579 $line .= $text; 4115319Stz204579 } 4125319Stz204579 print Hfile "$line */\n"; 4134176Stz204579 $start = ''; 4144176Stz204579 } 4154176Stz204579 print Hfile "};\n"; 4164176Stz204579 } 4174176Stz204579 4184176Stz204579 # generate defines for ADT_* external event names 4194176Stz204579 4204176Stz204579 foreach my $eventId (sort keys %eventAPI) { 4214176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 4224176Stz204579 unless (defined ($header)) { 4234176Stz204579 print STDERR "missing header selection for $eventId\n"; 4244176Stz204579 next; 4254176Stz204579 } 4264176Stz204579 *Hfile = $Hfile[$header]; 4274176Stz204579 next unless $Hfile[$header]; 4284176Stz204579 4294176Stz204579 my $l = length($eventId) + 8; # label plus preceding #define\t 4304176Stz204579 $l = 5 - int(($l + 8)/8); 4314176Stz204579 $l = 1 if $l < 1; 4324176Stz204579 my $tab = "\t" x $l; 4334176Stz204579 4344176Stz204579 print STDERR "missing id number for $eventId\n" unless $idNo; 4354176Stz204579 4364176Stz204579 $eventId =~ s/AUE_/ADT_/; 4374176Stz204579 print Hfile "#define\t$eventId$tab$idNo\n"; 4384176Stz204579 } 4394176Stz204579 4404176Stz204579 4414176Stz204579 # generate per-event structures 4424176Stz204579 4434176Stz204579 foreach my $eventId (sort keys %eventAPI) { 4444176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 4454176Stz204579 my $dataId = $eventId; 4464176Stz204579 $dataId =~ s/^AUE_/adt_/; 4474176Stz204579 unless(defined ($header)) { 4484176Stz204579 print STDERR "$eventId is missing the header assignment\n"; 4494176Stz204579 next; 4504176Stz204579 } 4514176Stz204579 *Hfile = $Hfile[$header]; 4524176Stz204579 next unless $Hfile[$header]; 4534176Stz204579 4544176Stz204579 my $externalId = $eventId; 4554176Stz204579 $externalId =~ s/AUE_/ADT_/; 4564176Stz204579 4574176Stz204579 print Hfile "\nstruct $dataId {\t/* $externalId */\n"; 4584176Stz204579 4594176Stz204579 my @entries = @{$eventAPI{$eventId}}; 4604176Stz204579 my $entry; 4614176Stz204579 if ($#entries < 0) { 4624176Stz204579 print Hfile "\tint\tdummy;\t/* not used */\n"; 4634176Stz204579 } else { 4644176Stz204579 foreach $entry (@entries) { 4654176Stz204579 $entry =~ s/termid/adt_termid_t/; 4664176Stz204579 print Hfile "\t$entry\n"; 4674176Stz204579 } 4684176Stz204579 } 4694176Stz204579 print Hfile "};\n"; 4704176Stz204579 $eventId =~ s/^AUE_/adt_/; 4714176Stz204579 print Hfile "typedef struct $dataId $eventId","_t;\n"; 4724176Stz204579 } 4734176Stz204579 4744176Stz204579 foreach my $header (sort keys %headers) { 4754176Stz204579 $outputState[$header] = 0; 4764176Stz204579 } 4774176Stz204579 4784176Stz204579 foreach my $eventId (sort keys %eventAPI) { 4794176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 4804176Stz204579 unless(defined ($header)) { 4814176Stz204579 # don't print duplicate error message 4824176Stz204579 next; 4834176Stz204579 } 4844176Stz204579 *Hfile = $Hfile[$header]; 4854176Stz204579 next unless $Hfile[$header]; 4864176Stz204579 if ($outputState[$header] == 0) { 4874176Stz204579 $outputState[$header] = 1; 4884176Stz204579 my $suffix = ''; 4894176Stz204579 $suffix = "_$header" if $header; 4904176Stz204579 print Hfile "\nunion adt_event_data$suffix {\n"; 4914176Stz204579 } 4924176Stz204579 my $elementName = $eventId; 4934176Stz204579 $elementName =~ s/^AUE_/adt_/; 4944176Stz204579 $eventId =~ s/^AUE_/adt_/; 4954176Stz204579 $elementName =~ s/_t$//; 4964176Stz204579 4974176Stz204579 print Hfile "\t\t$eventId","_t\t$elementName;\n"; 4984176Stz204579 } 4994176Stz204579 foreach my $header (sort keys %headers) { 5004176Stz204579 if ($outputState[$header]) { 5014176Stz204579 *Hfile = $Hfile[$header]; 5024176Stz204579 next unless $Hfile[$header]; 5034176Stz204579 print Hfile "};\n"; 5044176Stz204579 } 5054176Stz204579 } 5064176Stz204579 foreach my $header (keys %headers) { 5074176Stz204579 next unless $Hfile[$header]; 5084176Stz204579 *Hfile = $Hfile[$header]; 5094176Stz204579 my $adt_event_n = "_ADT_EVENT_H"; 5104176Stz204579 if ($header > 0) { 5114176Stz204579 $adt_event_n = "_ADT_EVENT_".$header."_H"; 5124176Stz204579 } 5134176Stz204579 print Hfile <<EOF; 5144176Stz204579 5154176Stz204579 5164176Stz204579#ifndef ADT_PRIVATE 5174176Stz204579#define ADT_PRIVATE 5184176Stz204579 5194176Stz204579/* 5204176Stz204579 * These interfaces are project private and will change without 5214176Stz204579 * notice as needed for the BSM API project. 5224176Stz204579 */ 5234176Stz204579 5244176Stz204579extern void adt_get_auid(const adt_session_data_t *, au_id_t *); 5254176Stz204579extern void adt_set_auid(const adt_session_data_t *, const au_id_t); 5264176Stz204579 5274176Stz204579extern void adt_get_mask(const adt_session_data_t *, au_mask_t *); 5284176Stz204579extern void adt_set_mask(const adt_session_data_t *, const au_mask_t *); 5294176Stz204579 5304176Stz204579extern void adt_get_termid(const adt_session_data_t *, au_tid_addr_t *); 5314176Stz204579extern void adt_set_termid(const adt_session_data_t *, 5324176Stz204579 const au_tid_addr_t *); 5334176Stz204579 5344176Stz204579extern void adt_get_asid(const adt_session_data_t *, au_asid_t *); 5354176Stz204579extern void adt_set_asid(const adt_session_data_t *, const au_asid_t); 5365777Stw21770extern au_id_t adt_get_unique_id(au_id_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 = ( 5585537Sgww # 5595537Sgww # tokenTypes are the ones that are actually defined 5605537Sgww # for use in adt.xml audit records 5615537Sgww # 5625537Sgww 5635537Sgww # 'acl' => 'AUT_ACL', # not defined 5645537Sgww # 'arbitrary' => 'AUT_ARBITRARY', # not defined 5655537Sgww # 'arg' => 'AUT_ARG', # not defined 5665537Sgww # 'attr' => 'AUT_ATTR', 5674176Stz204579 'command' => 'AUT_CMD', 568*7427SJan.Friedel@Sun.COM 'command_alt' => 'ADT_CMD_ALT', # dummy token id 5695537Sgww # 'date' => 'AUT_TEXT', # not used 5705537Sgww # 'exec_args' => 'AUT_EXEC_ARGS', # not defined 5715537Sgww # 'exec_env' => 'AUT_EXEC_ENV', # not defined 5725537Sgww # 'exit' => 'AUT_EXIT', # not defined 5734176Stz204579 'fmri' => 'AUT_FMRI', 5745537Sgww # 'groups' => 'AUT_GROUPS', # not defined 5755537Sgww # 'header' => 'AUT_HEADER', # not defined 5765537Sgww 'in_peer' => 'ADT_IN_PEER', # dummy token id 5774176Stz204579 'tid' => 'AUT_TID', 5785537Sgww # 'ipc' => 'AUT_IPC', # not defined 5795537Sgww # 'ipc_perm' => 'AUT_IPC_PERM', # not defined 5805537Sgww # 'iport' => 'AUT_IPORT', # not defined 5814176Stz204579 'label' => 'AUT_LABEL', 5824176Stz204579 'newgroups' => 'AUT_NEWGROUPS', 5835537Sgww # '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', 5915537Sgww # 'seq' => 'AUT_SEQ', # not defined 5925537Sgww # 'socket' => 'AUT_SOCKET', # not defined 5935537Sgww # 'socket-inet' => 'AUT_SOCKET_INET', 5944176Stz204579 'subject' => 'AUT_SUBJECT', 5954176Stz204579 'text' => 'AUT_TEXT', 5965537Sgww # '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', ''], 7685622Ssabdar 'fd_t' => ['ADT_FD', '-1'], 7694176Stz204579 ); 7704176Stz204579 my $xlateLabel = $uniLabel.$xlateUniLabelInc; 7714176Stz204579 my $xlateLabelInc = 0; 7724176Stz204579 my $xlateLine = ''; 7734176Stz204579 my @jniLine = (); 7744176Stz204579 7754176Stz204579 # the list handling should be a simple loop with a loop of one 7764176Stz204579 # falling out naturally. 7774176Stz204579 7784176Stz204579 unless ($type =~ /,/) { # if list, then generate sequence of entries 7794176Stz204579 my $dataType; 7804176Stz204579 my $dataSize; 7814176Stz204579 my $xlateLabelRef = ''; 7824176Stz204579 7834176Stz204579 my $arraySize = ''; 7844176Stz204579 $arraySize = $1 if ($type =~ s/\[(\d+)\]/[]/); 7854176Stz204579 7864176Stz204579 my $entryType = ${$entryDef{$type}}[0]; 7874176Stz204579 7884176Stz204579 my @xlateType = (); # for adt_xlate.c 7894176Stz204579 my $typeCount = 1; 7904176Stz204579 7914176Stz204579 if ($entryType) { 7924176Stz204579 $dataType = $entryType; 7934176Stz204579 $type =~ s/([^*]+)\s*(\*+)/$1 $2/; 7944176Stz204579 $type =~ s/\[\]//; 7954176Stz204579 $dataSize = "sizeof ($type)"; 7964176Stz204579 if ($arraySize) { 7974176Stz204579 $dataSize = "$arraySize * " . $dataSize; 7984176Stz204579 } 7994176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 8004176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 8014176Stz204579 } elsif ($type eq '') { 8024176Stz204579 $xlateLabelRef = 'NULL'; 8034176Stz204579 } elsif ($type =~ /^msg/i) { 8044176Stz204579 $type =~ s/^msg//i; 8054176Stz204579 $dataType = 'ADT_MSG'; 8064176Stz204579 my $dataEnum = 'ADT_LIST_' . uc $type; 8074176Stz204579 $xlateLine = "{{$dataType, $dataEnum}}"; 8084176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 8094176Stz204579 } elsif ($type =~ /time_t/i) { 8104176Stz204579 $dataType = 'ADT_DATE'; 8114176Stz204579 $dataSize = "sizeof (time_t)"; 8124176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 8134176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 8144176Stz204579 } elsif ($type =~ /termid/i) { 8154176Stz204579 $dataType = 'ADT_TERMIDSTAR'; 8164176Stz204579 $dataSize = "sizeof (au_tid_addr_t *)"; 8174176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 8184176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 8195300Sgww } elsif (uc $omitEntry eq 'JNI') { 8204176Stz204579 $xlateLabelRef = 'NULL'; 8214176Stz204579 } else { 8224176Stz204579 print STDERR "$type is not an implemented data type\n"; 8234176Stz204579 $xlateLabelRef = 'NULL'; 8244176Stz204579 } 8254176Stz204579 if ($xlateLine && !($xlateTypeList{$xlateLine})) { 8264176Stz204579 $xlateTypeList{$xlateLine} = $xlateLabel; 8274176Stz204579 push (@xlateTypeList, "datadef\t$xlateLabel\[1\] =\t$xlateLine;"); 8284176Stz204579 $xlateLabelInc = 1; 8294176Stz204579 } else { 8304176Stz204579 $xlateLabel = $xlateTypeList{$xlateLine}; 8314176Stz204579 } 8324176Stz204579 $xlateLabelRef = '&' . $xlateLabel . '[0]' 8334176Stz204579 unless $xlateLabelRef eq 'NULL'; 8344176Stz204579 8354176Stz204579 # "EOL" is where a comma should go unless end of list 8364176Stz204579 $xlateLine = "{$token,\t1,\t$xlateLabelRef,\t$sequence,\n" . 8374176Stz204579 "\t\t0,\t$required,\t$tsol,\t$format}EOL"; 8384176Stz204579 8395300Sgww if (uc $omitEntry ne 'ALWAYS' && ${$entryDef{$type}}[1]) { 8404176Stz204579 my @list = (); 8414176Stz204579 if ($xlateDefault{$eventId}) { 8424176Stz204579 @list = @{$xlateDefault{$eventId}}; 8434176Stz204579 } else { 8444176Stz204579 push (@xlateDefaults, $eventId); 8454176Stz204579 } 8464176Stz204579 push (@list, $id, ${$entryDef{$type}}[1]); 8474176Stz204579 $xlateDefault{$eventId} = \@list; 8484176Stz204579 } 8494176Stz204579 } else { # is a list 8504176Stz204579 my @type = split(/,/, $type); 8514176Stz204579 my @arraySize = (); 8524176Stz204579 my @id = split(/,/, $id); 8534176Stz204579 my @jniId = @id; 8544176Stz204579 my $dataType; 8554176Stz204579 my $typeCount = ($#type + 1); 8564176Stz204579 my @xlateType = (); 8574176Stz204579 my @default = (); 8584176Stz204579 8594176Stz204579 foreach my $dtype (@type) { 8604176Stz204579 my $jniId = shift @jniId; 8614176Stz204579 my $id = shift @id; 8624176Stz204579 my $arraySize = ''; 8634176Stz204579 $arraySize = $1 if ($dtype =~ s/\[(\d+)\]/[]/); 8644176Stz204579 8654176Stz204579 my $entryType = ${$entryDef{$dtype}}[0]; 8664176Stz204579 if ($entryType) { 8674176Stz204579 my $type = $dtype; 8684176Stz204579 $type =~ s/([^*]+)\s*(\*+)/$1 $2/; 8694176Stz204579 $type =~ s/\[\]//; 8704176Stz204579 8714176Stz204579 my $sizeString = "sizeof"; 8724176Stz204579 $sizeString = "$arraySize * " . $sizeString if $arraySize; 8734176Stz204579 push (@xlateType, "\{$entryType, $sizeString ($type)\}"); 8744176Stz204579 push (@jniLine, [$jniId, $entryType, $format, $enumGroup, $required]); 8754176Stz204579 } elsif ($type =~ /^msg/i) { 8764176Stz204579 $type =~ s/^msg//i; 8774176Stz204579 $dataType = 'ADT_MSG'; 8784176Stz204579 my $dataEnum = 'ADT_LIST_' . uc $type; 8794176Stz204579 push (@xlateType, "\{$dataType, $dataEnum\}};"); 8804176Stz204579 push (@jniLine, [$jniId, $dataType, $format, $enumGroup, $required]); 8814176Stz204579 } elsif ($type =~ /time_t/i) { 8824176Stz204579 $dataType = 'ADT_DATE'; 8834176Stz204579 push (@xlateType, "\{$entryType, sizeof ($type)\}"); 8844176Stz204579 push (@jniLine, [$jniId, $entryType, $format, $enumGroup, $required]); 8854176Stz204579 } elsif ($type =~ /termid/i) { 8864176Stz204579 $dataType = 'ADT_TERMIDSTAR'; 8874176Stz204579 push (@xlateType, "\{$dataType, sizeof (au_tid_addr_t *)\}"); 8884176Stz204579 push (@jniLine, [$jniId, $dataType, $format, $enumGroup, $required]); 8895300Sgww } elsif (uc $omitEntry eq 'JNI') { 8904176Stz204579 # nothing to do. 8914176Stz204579 } else { 8924176Stz204579 print STDERR "$dtype is not an implemented data type\n"; 8934176Stz204579 } 8945300Sgww if (uc $omitEntry ne 'ALWAYS' && ${$entryDef{$dtype}}[1]) { 8954176Stz204579 push (@default, $id, ${$entryDef{$dtype}}[1]); 8964176Stz204579 } 8974176Stz204579 } 8984176Stz204579 my $xlateArray = "\[$typeCount\] =\t{" . join(",\n\t\t\t\t", @xlateType) . "};"; 8994176Stz204579 9004176Stz204579 unless ($xlateTypeList{$xlateArray}) { 9014176Stz204579 $xlateTypeList{$xlateArray} = $xlateLabel; 9024176Stz204579 $xlateArray = "datadef\t$xlateLabel" . $xlateArray; 9034176Stz204579 push (@xlateTypeList, $xlateArray); 9044176Stz204579 $xlateLabelInc = 1; 9054176Stz204579 } else { 9064176Stz204579 $xlateLabel = $xlateTypeList{$xlateArray}; 9074176Stz204579 } 9084176Stz204579 $xlateLine = 9094176Stz204579 "{$token,\t$typeCount,\t&$xlateLabel\[0\],\t$sequence,\n" . 9104176Stz204579 "\t\t0,\t$required,\t$tsol,\t$format}EOL"; 9114176Stz204579 if (@default) { 9124176Stz204579 my @list = (); 9134176Stz204579 if ($xlateDefault{$eventId}) { 9144176Stz204579 @list = @{$xlateDefault{$eventId}}; 9154176Stz204579 } else { 9164176Stz204579 push (@xlateDefaults, $eventId); 9174176Stz204579 } 9184176Stz204579 push (@list, @default); 9194176Stz204579 $xlateDefault{$eventId} = \@list; 9204176Stz204579 } 9214176Stz204579 } 9224176Stz204579 $xlateUniLabelInc++ if $xlateLabelInc; 9234176Stz204579 return ($xlateLine, \@jniLine); 9244176Stz204579} 9254176Stz204579 9264176Stz204579sub generateAPIFile { 9274176Stz204579 my $event = shift; 9284176Stz204579 my $eventId = shift; 9294176Stz204579 my $eventType = shift; 9304176Stz204579 my $eventHeader = shift; 9314176Stz204579 my $idNo = shift; 9324176Stz204579 9334176Stz204579 my @entryList = (); 9344176Stz204579 9354176Stz204579 my $external = $event->getExternal(); 9364176Stz204579 9374176Stz204579 if ($eventType && $debug) { 9384176Stz204579 print STDERR "event $eventId is of type $eventType\n"; 9394176Stz204579 } 9404176Stz204579 9414176Stz204579 return unless $external; 9424176Stz204579 9434176Stz204579 my ($extEntry, $entry, $tokenId, $format); 9444176Stz204579 while (($extEntry, $entry, $tokenId, $format) = $external->getNextEntry()) { 9454176Stz204579 last unless $entry; 9464176Stz204579 my $entryId = $entry->getAttr('id'); 9474176Stz204579 9484176Stz204579 unless (defined $entryId) { 9494176Stz204579 print STDERR "undefined entry id for external $eventId\n"; 9504176Stz204579 next; 9514176Stz204579 } 9524176Stz204579 my $option = $extEntry->getAttr('opt'); 9534176Stz204579 next if ($option eq 'none'); 9544176Stz204579 9554176Stz204579 if (defined (my $token = $doc->getToken($tokenId))) { 9564176Stz204579 $option = 'Trusted Solaris only' 9574176Stz204579 if (lc $token->getUsage() eq 'tsol') ? 1 : 0; 9584176Stz204579 } 9594176Stz204579 $option .= " (format: $format)" if $format; 9604176Stz204579 9614176Stz204579 my $dataType = $extEntry->getAttr('type'); 9624176Stz204579 unless (defined $dataType) { 9634176Stz204579 print STDERR "no type defined for external tag for $eventId\n"; 9644176Stz204579 $dataType = "error"; 9654176Stz204579 } 9664176Stz204579 9674176Stz204579 my $comment = $entry->getContent(); 9684176Stz204579 9694176Stz204579 if (($dataType =~ /,/) || ($entryId =~ /,/)) { 9704176Stz204579 my @type = split(/\s*,\s*/, $dataType); 9714176Stz204579 my @id = split(/\s*,\s*/, $entryId); 9724176Stz204579 if ($#type != $#id) { 9734176Stz204579 print STDERR 9744176Stz204579 "number of data types ($dataType) does not match number of ids ($entryId)", 9754176Stz204579 " for event $eventId\n"; 9764176Stz204579 if ($#type < $#id) { 9774176Stz204579 $#id = $#type; 9784176Stz204579 } 9794176Stz204579 else { 9804176Stz204579 $#type = $#id; 9814176Stz204579 } 9824176Stz204579 } 9834176Stz204579 9844176Stz204579 my $i; 9854176Stz204579 my $line = ''; 9864176Stz204579 $line = "/* $comment */\n\t" if defined $comment; 9874176Stz204579 for ($i = 0; $i <= $#type; $i++) { 9884176Stz204579 my ($primitive, $dereference) = 9894176Stz204579 ($type[$i] =~ /([^\*]+)\s*(\**)/); 9904176Stz204579 $id[$i] .= $1 if ($primitive =~ s/(\[\d+\])//); 9914176Stz204579 $line .= "$primitive\t$dereference$id[$i];\t/* $option */"; 9924176Stz204579 push (@entryList, $line); 9934176Stz204579 $line = ''; 9944176Stz204579 } 9954176Stz204579 } 9964176Stz204579 else { 9974176Stz204579 my $line = ''; 9984176Stz204579 $line = "/* $comment */\n\t" if defined $comment; 9994176Stz204579 if ($dataType =~ /^msg/i) { 10004176Stz204579 $dataType =~ s/^msg\s*//i; 10014176Stz204579 $line .= "enum adt_$dataType" . "\t$entryId;\t/* $option */"; 10024176Stz204579 } 10034176Stz204579 elsif ($dataType =~ /time_t/i) { 10044176Stz204579 $line .= "time_t\t$entryId;\t/* $option */"; 10054176Stz204579 } 10064176Stz204579 else { 10074176Stz204579 my ($primitive, $dereference) = 10084176Stz204579 ($dataType =~ /([^\*]+)\s*(\**)/); 10094176Stz204579 $entryId .= $1 if ($primitive =~ s/(\[\d+\])//); 10104176Stz204579 $line .= "$primitive\t$dereference$entryId;\t/* $option */"; 10114176Stz204579 } 10124176Stz204579 push (@entryList, $line); 10134176Stz204579 } 10144176Stz204579 } 10154176Stz204579 $eventExtra{$eventId} = [$eventHeader, $idNo]; 10164176Stz204579 $eventAPI{$eventId} = \@entryList; 10174176Stz204579} 10184176Stz204579 10194176Stz204579sub generateMsgLists { 10204176Stz204579 my $textList = shift; 10214176Stz204579 10224176Stz204579 my $textName = $textList->getId(); 10234176Stz204579 my $header = $textList->getHeader(); 10244176Stz204579 my $start = $textList->getMsgStart(); 10254176Stz204579 my $public = $textList->getMsgPublic(); 10264176Stz204579 my $deprecated = $textList->getDeprecated(); 10274176Stz204579 10284176Stz204579 addHeader($header); 10294176Stz204579 print "$textName starts at $start\n" if $debug; 10304176Stz204579 10314176Stz204579 my $entry; 10324176Stz204579 my @entry; 10334176Stz204579 while ($entry = $textList->getNextMsg()) { 10344176Stz204579 if ($debug) { 10354176Stz204579 my ($id, $text) = split(/\s*::\s*/, $entry); 10364176Stz204579 print " $id = $text\n"; 10374176Stz204579 } 10384176Stz204579 unshift (@entry, $entry); 10394176Stz204579 } 10404176Stz204579 $msg_list{$textName} = 10414176Stz204579 [\@entry, [$header, $start, $public, $deprecated]]; 10424176Stz204579} 10434176Stz204579 10444176Stz204579sub addHeader { 10454176Stz204579 my $header_index = shift; 10464176Stz204579 10474176Stz204579 die "invalid adt_event_N.h index: $header_index\n" 10484176Stz204579 unless ($header_index =~ /^\d+$/); 10494176Stz204579 10504176Stz204579 $headers{$header_index} = $header_index; 10514176Stz204579} 10524176Stz204579 10534176Stz204579# $header = 0 is a special case; it is for adt_event.h 10544176Stz204579# $header > 0 creates adt_event_N.h, where N = $header 10554176Stz204579 10564176Stz204579sub openHeaderFiles { 10574176Stz204579 my $outfile = shift; # path to an adt_event_N.h file 10584176Stz204579 10594176Stz204579 my $header; 10604176Stz204579 my @Hfile = (); # potentially sparse array of file handles 10614176Stz204579 my @HfileName = (); # parallel array to Hfile, file name (not path) 10624176Stz204579 foreach $header (sort keys %headers) { 10634176Stz204579 my $file = $outfile; 10644176Stz204579 if ($header > 0) { 10654176Stz204579 $file =~ s/_N/_$header/; 10664176Stz204579 } else { 10674176Stz204579 $file =~ s/_N//; 10684176Stz204579 } 10694176Stz204579 unless (open($Hfile[$header], ">$file")) { 10704176Stz204579 print STDERR "can't open output ($file): $!\n"; 10714176Stz204579 $HfileName[$header] = ''; 10724176Stz204579 $Hfile[$header] = ''; 10734176Stz204579 } else { 10744176Stz204579 my @tmp = split(/\//, $file); 10754176Stz204579 $HfileName[$header] = $tmp[$#tmp]; 10764176Stz204579 } 10774176Stz204579 } 10784176Stz204579 return (@Hfile); 10794176Stz204579} 10804176Stz204579 10814176Stz204579sub closeHeaderFiles { 10824176Stz204579 my @Hfile = @_; 10834176Stz204579 10844176Stz204579 my $header; 10854176Stz204579 foreach $header (sort keys %headers) { 10864176Stz204579 close $Hfile[$header] if $Hfile[$header]; 10874176Stz204579 } 10884176Stz204579} 1089