1*4176Stz204579#!/usr/perl5/bin/perl -w 2*4176Stz204579# 3*4176Stz204579# CDDL HEADER START 4*4176Stz204579# 5*4176Stz204579# The contents of this file are subject to the terms of the 6*4176Stz204579# Common Development and Distribution License (the "License"). 7*4176Stz204579# You may not use this file except in compliance with the License. 8*4176Stz204579# 9*4176Stz204579# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*4176Stz204579# or http://www.opensolaris.org/os/licensing. 11*4176Stz204579# See the License for the specific language governing permissions 12*4176Stz204579# and limitations under the License. 13*4176Stz204579# 14*4176Stz204579# When distributing Covered Code, include this CDDL HEADER in each 15*4176Stz204579# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*4176Stz204579# If applicable, add the following below this CDDL HEADER, with the 17*4176Stz204579# fields enclosed by brackets "[]" replaced with your own identifying 18*4176Stz204579# information: Portions Copyright [yyyy] [name of copyright owner] 19*4176Stz204579# 20*4176Stz204579# CDDL HEADER END 21*4176Stz204579# 22*4176Stz204579# 23*4176Stz204579# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24*4176Stz204579# Use is subject to license terms. 25*4176Stz204579# 26*4176Stz204579# ident "%Z%%M% %I% %E% SMI" 27*4176Stz204579# 28*4176Stz204579 29*4176Stz204579# auditxml [-d] <xml input file> 30*4176Stz204579 31*4176Stz204579# auditxml takes the audit record description (.xml file) and 32*4176Stz204579# generates the files needed for the C audit api. 33*4176Stz204579 34*4176Stz204579use auditxml; 35*4176Stz204579use Getopt::Std; 36*4176Stz204579use vars qw($opt_d); 37*4176Stz204579use strict; 38*4176Stz204579 39*4176Stz204579 40*4176Stz204579our $debug = 0; # normal use is to set via the file being parsed. 41*4176Stz204579 # <debug set="on"/> or <debug set="off"/> or <debug/> 42*4176Stz204579 # if the set attribute is omitted, debug state is toggled 43*4176Stz204579 # Override with appDebug, but toggle won't do what you 44*4176Stz204579 # want. 45*4176Stz204579my $appDebug = 0; # used after return from "new auditxml"; 46*4176Stz204579 47*4176Stz204579my $genNotice = " 48*4176Stz204579DO NOT EDIT. This file is auto generated by the Solaris Audit 49*4176Stz204579system from adt.xml. 50*4176Stz204579 51*4176Stz204579See http://opensolaris.org/os/project/audit/ 52*4176Stz204579"; 53*4176Stz204579 54*4176Stz204579# trim leading/trailing newlines 55*4176Stz204579$genNotice =~ s/^\n//s; 56*4176Stz204579$genNotice =~ s/\n$//s; 57*4176Stz204579my $prog = $0; $prog =~ s|.*/||g; 58*4176Stz204579my $usage = "usage: $prog [-d] file.xml\n"; 59*4176Stz204579 60*4176Stz204579getopts('d'); 61*4176Stz204579 62*4176Stz204579$appDebug = $opt_d; 63*4176Stz204579 64*4176Stz204579my $uniLabel = "adr"; 65*4176Stz204579my $xlateUniLabelInc = 0; 66*4176Stz204579 67*4176Stz204579die $usage if ($#ARGV < 0); 68*4176Stz204579 69*4176Stz204579# where everything comes from and where it goes: 70*4176Stz204579 71*4176Stz204579my $bsmBuildPath = "./common"; 72*4176Stz204579my $xlateFile = "$bsmBuildPath/adt_xlate.c"; 73*4176Stz204579my $headerFile = "$bsmBuildPath/adt_event_N.h"; 74*4176Stz204579 75*4176Stz204579my $doc = new auditxml ($ARGV[0]); # input XML file 76*4176Stz204579 77*4176Stz204579$debug = $appDebug; 78*4176Stz204579 79*4176Stz204579my %xlateEventTable = (); 80*4176Stz204579my @xlateTypeList = (); 81*4176Stz204579my %xlateTypeList = (); 82*4176Stz204579my %eventAPI = (); 83*4176Stz204579my %eventExtra = (); 84*4176Stz204579my %headers = (); 85*4176Stz204579my %externalIdNo = (); 86*4176Stz204579my @outputState = (); 87*4176Stz204579my %nameTranslation = (); 88*4176Stz204579my @xlateDefaults = (); 89*4176Stz204579my %xlateDefault = (); 90*4176Stz204579my %msg_list = (); 91*4176Stz204579 92*4176Stz204579my $event; 93*4176Stz204579while ($event = $doc->getNextEvent()) { 94*4176Stz204579 my $eventId = $event->getId(); 95*4176Stz204579 my $eventHeader = $event->getHeader(); 96*4176Stz204579 my $idNo = $event->getIdNo(); 97*4176Stz204579 $externalIdNo{$eventId} = $idNo; 98*4176Stz204579 addHeader($eventHeader) if defined ($eventHeader); 99*4176Stz204579 my $super; 100*4176Stz204579 my $omit = $event->getOmit(); 101*4176Stz204579 my $eventType = ''; 102*4176Stz204579 if ($super = $event->getSuperClass()) { 103*4176Stz204579 $event = $super; 104*4176Stz204579 $eventType = 'instance'; 105*4176Stz204579 } else { 106*4176Stz204579 $eventType = $event->getType(); 107*4176Stz204579 } 108*4176Stz204579 109*4176Stz204579 # header file for API use 110*4176Stz204579 generateAPIFile($event, $eventId, $eventType, $eventHeader, $idNo) 111*4176Stz204579 unless $omit eq 'always'; 112*4176Stz204579 113*4176Stz204579 # c file table for translation 114*4176Stz204579 generateTableC($event, $eventId, $eventType, $eventHeader, $omit); 115*4176Stz204579} 116*4176Stz204579 117*4176Stz204579my $textList; 118*4176Stz204579while ($textList = $doc->getNextMsgId()) { 119*4176Stz204579 generateMsgLists($textList); # enum -> text mappings 120*4176Stz204579} 121*4176Stz204579 122*4176Stz204579printTableC($xlateFile); 123*4176Stz204579printAPIFile($headerFile, $doc); 124*4176Stz204579 125*4176Stz204579exit 0; 126*4176Stz204579 127*4176Stz204579 128*4176Stz204579sub printTableC { 129*4176Stz204579 my $file = shift; 130*4176Stz204579 131*4176Stz204579 unless (open(Cfile, ">$file")) { 132*4176Stz204579 print STDERR "can't open output file ($file): $!\n"; 133*4176Stz204579 return; 134*4176Stz204579 } 135*4176Stz204579 136*4176Stz204579 my $notice = $genNotice; 137*4176Stz204579 $notice =~ s/\n/\n * /gs; 138*4176Stz204579 $notice =~ s/\s+\n/\n/gs; 139*4176Stz204579 print Cfile <<EOF; 140*4176Stz204579/* 141*4176Stz204579 * $notice 142*4176Stz204579 */ 143*4176Stz204579 144*4176Stz204579#include <bsm/libbsm.h> 145*4176Stz204579#include <adt_xlate.h> 146*4176Stz204579#include <libintl.h> 147*4176Stz204579 148*4176Stz204579EOF 149*4176Stz204579 print Cfile "#ifndef _PRAUDIT\n"; 150*4176Stz204579 print Cfile "/* Internal data type definitions */\n\n"; 151*4176Stz204579 my $extDef; 152*4176Stz204579 foreach $extDef (@xlateTypeList) { 153*4176Stz204579 print Cfile "static $extDef\n"; 154*4176Stz204579 } 155*4176Stz204579 @xlateTypeList = (); 156*4176Stz204579 157*4176Stz204579 print Cfile "\n/* External event structure to internal event structure */\n\n"; 158*4176Stz204579 159*4176Stz204579 my @pointers = (); 160*4176Stz204579 161*4176Stz204579 foreach my $eventId (sort keys %xlateEventTable) { 162*4176Stz204579 if ($xlateEventTable{$eventId}) { 163*4176Stz204579 my ($ref1, $eventType, $firstToken, $eventHeader) = 164*4176Stz204579 @{$xlateEventTable{$eventId}}; 165*4176Stz204579 my @entries = @$ref1; 166*4176Stz204579 my $entry; 167*4176Stz204579 my $entries = $#entries; 168*4176Stz204579 my $count = $entries + 1; 169*4176Stz204579 my $externalName = $nameTranslation{$eventId}; 170*4176Stz204579 my $externalRoot = $externalName; 171*4176Stz204579 $externalRoot =~ s/AUE_//; 172*4176Stz204579 my $structName = "XX_$externalRoot"; 173*4176Stz204579 my $root = $eventId; 174*4176Stz204579 $root =~ s/AUE_//; 175*4176Stz204579 my $externalId = $eventId; 176*4176Stz204579 $externalId =~ s/AUE_/ADT_/; 177*4176Stz204579 178*4176Stz204579 unless ($eventType eq 'generic') { 179*4176Stz204579 print Cfile "static struct entry $structName\[$count\] = {\n"; 180*4176Stz204579 foreach $entry (@entries) { 181*4176Stz204579 if ($entries--) { 182*4176Stz204579 $entry =~ s/EOL/,/; 183*4176Stz204579 } 184*4176Stz204579 else { 185*4176Stz204579 $entry =~ s/EOL//; 186*4176Stz204579 } 187*4176Stz204579 $entry =~ s/selfReference/$structName/; 188*4176Stz204579 print Cfile "\t$entry\n"; 189*4176Stz204579 } 190*4176Stz204579 print Cfile "};\n"; 191*4176Stz204579 192*4176Stz204579 print Cfile "static struct translation X_$externalRoot = {\n"; 193*4176Stz204579 push (@pointers, "X_$externalRoot"); 194*4176Stz204579 195*4176Stz204579 print Cfile "\t0,\n"; # tx_offsetsCalculated = 0 196*4176Stz204579 print Cfile "\t$externalId,\n"; 197*4176Stz204579 print Cfile "\t$externalName,\n"; 198*4176Stz204579 199*4176Stz204579 print Cfile "\t$count,\n"; 200*4176Stz204579 print Cfile "\t&XX_$externalRoot\[$firstToken\],\n"; 201*4176Stz204579 print Cfile "\t&XX_$externalRoot\[0\]\n};\n"; 202*4176Stz204579 } 203*4176Stz204579 } else { 204*4176Stz204579 print STDERR "expected entry for $eventId but none found\n"; 205*4176Stz204579 } 206*4176Stz204579 } 207*4176Stz204579 208*4176Stz204579 my $count = $#pointers + 2; 209*4176Stz204579 print Cfile "struct translation *xlate_table[$count] = {\n"; 210*4176Stz204579 211*4176Stz204579 my $firstEvent = 1; 212*4176Stz204579 foreach my $eventId (@pointers) { 213*4176Stz204579 if ($firstEvent) { 214*4176Stz204579 $firstEvent = 0; 215*4176Stz204579 } 216*4176Stz204579 else { 217*4176Stz204579 print Cfile ",\n"; 218*4176Stz204579 } 219*4176Stz204579 print Cfile "\t&$eventId"; 220*4176Stz204579 } 221*4176Stz204579 print Cfile ",\n\tNULL\n};\n"; 222*4176Stz204579 223*4176Stz204579 # generate the adt_preload() function 224*4176Stz204579 225*4176Stz204579 print Cfile <<EOF; 226*4176Stz204579 227*4176Stz204579void 228*4176Stz204579adt_preload(au_event_t event_id, adt_event_data_t *event_data) 229*4176Stz204579{ 230*4176Stz204579 switch (event_id) { 231*4176Stz204579EOF 232*4176Stz204579 233*4176Stz204579 foreach my $id (@xlateDefaults) { 234*4176Stz204579 my $adtID = $id; 235*4176Stz204579 $adtID =~ s/AUE/ADT/; 236*4176Stz204579 237*4176Stz204579 print Cfile <<EOF; 238*4176Stz204579 case $adtID: 239*4176Stz204579EOF 240*4176Stz204579 my @preloads = @{$xlateDefault{$id}}; 241*4176Stz204579 while (@preloads) { 242*4176Stz204579 my $fieldName = shift @preloads; 243*4176Stz204579 my $default = shift @preloads; 244*4176Stz204579 my $lcid = lc $id; 245*4176Stz204579 $lcid =~ s/aue_/adt_/; 246*4176Stz204579 247*4176Stz204579 print Cfile <<EOF; 248*4176Stz204579 event_data->$lcid.$fieldName = $default; 249*4176Stz204579EOF 250*4176Stz204579 } 251*4176Stz204579 252*4176Stz204579 print Cfile <<EOF; 253*4176Stz204579 break; 254*4176Stz204579EOF 255*4176Stz204579 } 256*4176Stz204579 257*4176Stz204579 print Cfile <<EOF; 258*4176Stz204579 default: 259*4176Stz204579 break; 260*4176Stz204579 } 261*4176Stz204579} 262*4176Stz204579#endif 263*4176Stz204579 264*4176Stz204579/* message lists */ 265*4176Stz204579 266*4176Stz204579EOF 267*4176Stz204579 my $listName; 268*4176Stz204579 my @listName; 269*4176Stz204579 foreach $listName (sort keys %msg_list) { 270*4176Stz204579 my ($listRef, $headref) = @{$msg_list{$listName}}; 271*4176Stz204579 my ($header, $start, $public, $deprecated) = @$headref; 272*4176Stz204579 273*4176Stz204579 my @listValue = @$listRef; 274*4176Stz204579 my $listValue; 275*4176Stz204579 my $listLength = $#listValue + 1; 276*4176Stz204579 277*4176Stz204579 $listName = 'NULL' if ($#listValue < 0); 278*4176Stz204579 279*4176Stz204579 push (@listName, [$listName, $listLength - 1, $start, $public]); 280*4176Stz204579 281*4176Stz204579 next if ($#listValue < 0); 282*4176Stz204579 283*4176Stz204579 print Cfile "/* Deprecated message list */\n" if ($deprecated); 284*4176Stz204579 print Cfile "static char *msg_$listName\[$listLength] = {\n"; 285*4176Stz204579 286*4176Stz204579 my $ffirst = 1; 287*4176Stz204579 foreach $listValue (@listValue) { 288*4176Stz204579 print Cfile ",\n" unless $ffirst; 289*4176Stz204579 $ffirst = 0; 290*4176Stz204579 my ($id, $text) = split(/\s*::\s*/, $listValue); 291*4176Stz204579 if ($text) { 292*4176Stz204579 print Cfile "\t\"$text\""; 293*4176Stz204579 } 294*4176Stz204579 else { 295*4176Stz204579 print Cfile "\tNULL"; 296*4176Stz204579 } 297*4176Stz204579 } 298*4176Stz204579 print Cfile "\n};\n"; 299*4176Stz204579 } 300*4176Stz204579 print Cfile "\nstruct msg_text adt_msg_text[", $#listName + 1, 301*4176Stz204579 "] = {\n"; 302*4176Stz204579 my $ffirst = 1; 303*4176Stz204579 foreach $listName (@listName) { 304*4176Stz204579 my ($name, $max, $start) = @$listName; 305*4176Stz204579 $start = -$start if $start; 306*4176Stz204579 print Cfile ",\n" unless $ffirst; 307*4176Stz204579 $ffirst = 0; 308*4176Stz204579 $name = "msg_$name" if ($name ne 'NULL'); 309*4176Stz204579 print Cfile "\t{0, $max, $name, $start}"; 310*4176Stz204579 } 311*4176Stz204579 print Cfile "\n};\n"; 312*4176Stz204579 313*4176Stz204579 close Cfile; 314*4176Stz204579} 315*4176Stz204579 316*4176Stz204579sub printAPIFile { 317*4176Stz204579 my $file = shift; 318*4176Stz204579 my $xmlDoc = shift; 319*4176Stz204579 320*4176Stz204579 my @Hfile; 321*4176Stz204579 @Hfile = openHeaderFiles($file); 322*4176Stz204579 323*4176Stz204579 my $notice = $genNotice; 324*4176Stz204579 $notice =~ s/\n/\n * /gs; 325*4176Stz204579 $notice =~ s/\s+\n/\n/gs; 326*4176Stz204579 327*4176Stz204579 foreach my $header (keys %headers) { 328*4176Stz204579 next unless $Hfile[$header]; 329*4176Stz204579 *Hfile = $Hfile[$header]; 330*4176Stz204579 my $include = "adt.h"; 331*4176Stz204579 my $adt_event_n = "_ADT_EVENT_H"; 332*4176Stz204579 if ($header > 0) { 333*4176Stz204579 $include = "adt_event.h"; 334*4176Stz204579 $adt_event_n = "_ADT_EVENT_".$header."_H"; 335*4176Stz204579 } 336*4176Stz204579 print Hfile <<EOF; 337*4176Stz204579/* 338*4176Stz204579 * $notice 339*4176Stz204579 */ 340*4176Stz204579 341*4176Stz204579#ifndef $adt_event_n 342*4176Stz204579#define $adt_event_n 343*4176Stz204579 344*4176Stz204579#include <bsm/$include> 345*4176Stz204579 346*4176Stz204579#ifdef __cplusplus 347*4176Stz204579extern "C" { 348*4176Stz204579#endif 349*4176Stz204579 350*4176Stz204579/* 351*4176Stz204579 * adt_put_event() status values. Positive values are for kernel-generated 352*4176Stz204579 * failure, -1 for user-space. For ADT_SUCCESS, the adt_put_event() return_val 353*4176Stz204579 * is not used; the convention is to set it to ADT_SUCCESS. 354*4176Stz204579 */ 355*4176Stz204579#define ADT_SUCCESS 0 356*4176Stz204579#define ADT_FAILURE -1 357*4176Stz204579 358*4176Stz204579EOF 359*4176Stz204579 } 360*4176Stz204579 361*4176Stz204579 foreach my $listName (sort keys %msg_list) { 362*4176Stz204579 my $shortName = uc $listName; 363*4176Stz204579 $shortName =~ s/_TEXT//; 364*4176Stz204579 365*4176Stz204579 my ($listRef, $headref) = @{$msg_list{$listName}}; 366*4176Stz204579 my ($header, $start, $public, $deprecated) = @$headref; 367*4176Stz204579 next unless $Hfile[$header]; 368*4176Stz204579 *Hfile = $Hfile[$header]; 369*4176Stz204579 370*4176Stz204579 print Hfile "/* Deprecated message list */\n" if $deprecated; 371*4176Stz204579 print Hfile "#define\tADT_$shortName\t$start\n" if $start; 372*4176Stz204579 373*4176Stz204579 my @listValue = @$listRef; 374*4176Stz204579 next unless ($#listValue >= 0); 375*4176Stz204579 print Hfile "enum\tadt_$listName", " {\n"; 376*4176Stz204579 377*4176Stz204579 my $listValue; 378*4176Stz204579 my $i = 0; 379*4176Stz204579 my $j = $#listValue; 380*4176Stz204579 my $comma = ','; 381*4176Stz204579 foreach $listValue (@listValue) { 382*4176Stz204579 my ($id, $text) = split(/\s*::\s*/, $listValue); 383*4176Stz204579 $comma = '' if $i++ == $j; 384*4176Stz204579 if ($start) { 385*4176Stz204579 $start = " = $start$comma"; 386*4176Stz204579 } else { 387*4176Stz204579 $start = "$comma\t"; 388*4176Stz204579 } 389*4176Stz204579 $text = "(no token will be generated)" unless $text; 390*4176Stz204579 print Hfile "\tADT_$shortName", "_$id$start\t/* $text */\n"; 391*4176Stz204579 $start = ''; 392*4176Stz204579 } 393*4176Stz204579 print Hfile "};\n"; 394*4176Stz204579 } 395*4176Stz204579 396*4176Stz204579 # generate defines for ADT_* external event names 397*4176Stz204579 398*4176Stz204579 foreach my $eventId (sort keys %eventAPI) { 399*4176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 400*4176Stz204579 unless (defined ($header)) { 401*4176Stz204579 print STDERR "missing header selection for $eventId\n"; 402*4176Stz204579 next; 403*4176Stz204579 } 404*4176Stz204579 *Hfile = $Hfile[$header]; 405*4176Stz204579 next unless $Hfile[$header]; 406*4176Stz204579 407*4176Stz204579 my $l = length($eventId) + 8; # label plus preceding #define\t 408*4176Stz204579 $l = 5 - int(($l + 8)/8); 409*4176Stz204579 $l = 1 if $l < 1; 410*4176Stz204579 my $tab = "\t" x $l; 411*4176Stz204579 412*4176Stz204579 print STDERR "missing id number for $eventId\n" unless $idNo; 413*4176Stz204579 414*4176Stz204579 $eventId =~ s/AUE_/ADT_/; 415*4176Stz204579 print Hfile "#define\t$eventId$tab$idNo\n"; 416*4176Stz204579 } 417*4176Stz204579 418*4176Stz204579 419*4176Stz204579 # generate per-event structures 420*4176Stz204579 421*4176Stz204579 foreach my $eventId (sort keys %eventAPI) { 422*4176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 423*4176Stz204579 my $dataId = $eventId; 424*4176Stz204579 $dataId =~ s/^AUE_/adt_/; 425*4176Stz204579 unless(defined ($header)) { 426*4176Stz204579 print STDERR "$eventId is missing the header assignment\n"; 427*4176Stz204579 next; 428*4176Stz204579 } 429*4176Stz204579 *Hfile = $Hfile[$header]; 430*4176Stz204579 next unless $Hfile[$header]; 431*4176Stz204579 432*4176Stz204579 my $externalId = $eventId; 433*4176Stz204579 $externalId =~ s/AUE_/ADT_/; 434*4176Stz204579 435*4176Stz204579 print Hfile "\nstruct $dataId {\t/* $externalId */\n"; 436*4176Stz204579 437*4176Stz204579 my @entries = @{$eventAPI{$eventId}}; 438*4176Stz204579 my $entry; 439*4176Stz204579 if ($#entries < 0) { 440*4176Stz204579 print Hfile "\tint\tdummy;\t/* not used */\n"; 441*4176Stz204579 } else { 442*4176Stz204579 foreach $entry (@entries) { 443*4176Stz204579 $entry =~ s/termid/adt_termid_t/; 444*4176Stz204579 print Hfile "\t$entry\n"; 445*4176Stz204579 } 446*4176Stz204579 } 447*4176Stz204579 print Hfile "};\n"; 448*4176Stz204579 $eventId =~ s/^AUE_/adt_/; 449*4176Stz204579 print Hfile "typedef struct $dataId $eventId","_t;\n"; 450*4176Stz204579 } 451*4176Stz204579 452*4176Stz204579 foreach my $header (sort keys %headers) { 453*4176Stz204579 $outputState[$header] = 0; 454*4176Stz204579 } 455*4176Stz204579 456*4176Stz204579 foreach my $eventId (sort keys %eventAPI) { 457*4176Stz204579 my ($header, $idNo) = @{$eventExtra{$eventId}}; 458*4176Stz204579 unless(defined ($header)) { 459*4176Stz204579 # don't print duplicate error message 460*4176Stz204579 next; 461*4176Stz204579 } 462*4176Stz204579 *Hfile = $Hfile[$header]; 463*4176Stz204579 next unless $Hfile[$header]; 464*4176Stz204579 if ($outputState[$header] == 0) { 465*4176Stz204579 $outputState[$header] = 1; 466*4176Stz204579 my $suffix = ''; 467*4176Stz204579 $suffix = "_$header" if $header; 468*4176Stz204579 print Hfile "\nunion adt_event_data$suffix {\n"; 469*4176Stz204579 } 470*4176Stz204579 my $elementName = $eventId; 471*4176Stz204579 $elementName =~ s/^AUE_/adt_/; 472*4176Stz204579 $eventId =~ s/^AUE_/adt_/; 473*4176Stz204579 $elementName =~ s/_t$//; 474*4176Stz204579 475*4176Stz204579 print Hfile "\t\t$eventId","_t\t$elementName;\n"; 476*4176Stz204579 } 477*4176Stz204579 foreach my $header (sort keys %headers) { 478*4176Stz204579 if ($outputState[$header]) { 479*4176Stz204579 *Hfile = $Hfile[$header]; 480*4176Stz204579 next unless $Hfile[$header]; 481*4176Stz204579 print Hfile "};\n"; 482*4176Stz204579 } 483*4176Stz204579 } 484*4176Stz204579 foreach my $header (keys %headers) { 485*4176Stz204579 next unless $Hfile[$header]; 486*4176Stz204579 *Hfile = $Hfile[$header]; 487*4176Stz204579 my $adt_event_n = "_ADT_EVENT_H"; 488*4176Stz204579 if ($header > 0) { 489*4176Stz204579 $adt_event_n = "_ADT_EVENT_".$header."_H"; 490*4176Stz204579 } 491*4176Stz204579 print Hfile <<EOF; 492*4176Stz204579 493*4176Stz204579 494*4176Stz204579#ifndef ADT_PRIVATE 495*4176Stz204579#define ADT_PRIVATE 496*4176Stz204579 497*4176Stz204579/* 498*4176Stz204579 * These interfaces are project private and will change without 499*4176Stz204579 * notice as needed for the BSM API project. 500*4176Stz204579 */ 501*4176Stz204579 502*4176Stz204579extern void adt_get_auid(const adt_session_data_t *, au_id_t *); 503*4176Stz204579extern void adt_set_auid(const adt_session_data_t *, const au_id_t); 504*4176Stz204579 505*4176Stz204579extern void adt_get_mask(const adt_session_data_t *, au_mask_t *); 506*4176Stz204579extern void adt_set_mask(const adt_session_data_t *, const au_mask_t *); 507*4176Stz204579 508*4176Stz204579extern void adt_get_termid(const adt_session_data_t *, au_tid_addr_t *); 509*4176Stz204579extern void adt_set_termid(const adt_session_data_t *, 510*4176Stz204579 const au_tid_addr_t *); 511*4176Stz204579 512*4176Stz204579extern void adt_get_asid(const adt_session_data_t *, au_asid_t *); 513*4176Stz204579extern void adt_set_asid(const adt_session_data_t *, const au_asid_t); 514*4176Stz204579 515*4176Stz204579#endif 516*4176Stz204579 517*4176Stz204579#ifdef __cplusplus 518*4176Stz204579} 519*4176Stz204579#endif 520*4176Stz204579 521*4176Stz204579#endif /* $adt_event_n */ 522*4176Stz204579EOF 523*4176Stz204579 } 524*4176Stz204579 closeHeaderFiles(@Hfile); 525*4176Stz204579} 526*4176Stz204579 527*4176Stz204579sub generateTableC { 528*4176Stz204579 my $event = shift; 529*4176Stz204579 my $eventId = shift; 530*4176Stz204579 my $eventType = shift; 531*4176Stz204579 my $eventHeader = shift; 532*4176Stz204579 my $omit = shift; 533*4176Stz204579 534*4176Stz204579 my %tokenType = ( 535*4176Stz204579 'acl' => 'AUT_ACL', 536*4176Stz204579 'arbitrary' => 'AUT_ARBITRARY', 537*4176Stz204579 'arg' => 'AUT_ARG', 538*4176Stz204579 'attr' => 'AUT_ATTR', 539*4176Stz204579 'command' => 'AUT_CMD', 540*4176Stz204579 'command_1' => 'ADT_CMD_ALT', # dummy token id 541*4176Stz204579 'date' => 'AUT_TEXT', 542*4176Stz204579 'exec_args' => 'AUT_EXEC_ARGS', 543*4176Stz204579 'exec_env' => 'AUT_EXEC_ENV', 544*4176Stz204579 'exit' => 'AUT_EXIT', 545*4176Stz204579 'file' => 'AUT_FILE', 546*4176Stz204579 'fmri' => 'AUT_FMRI', 547*4176Stz204579 'groups' => 'AUT_GROUPS', 548*4176Stz204579 # 'header' => 'AUT_HEADER', # not used 549*4176Stz204579 'in_addr' => 'AUT_IN_ADDR', 550*4176Stz204579 'tid' => 'AUT_TID', 551*4176Stz204579 'ipc' => 'AUT_IPC', 552*4176Stz204579 'ipc_perm' => 'AUT_IPC_PERM', 553*4176Stz204579 'iport' => 'AUT_IPORT', 554*4176Stz204579 'label' => 'AUT_LABEL', 555*4176Stz204579 'newgroups' => 'AUT_NEWGROUPS', 556*4176Stz204579 'opaque' => 'AUT_OPAQUE', 557*4176Stz204579 'path' => 'AUT_PATH', 558*4176Stz204579 'path_list' => '-AUT_PATH', # dummy token id 559*4176Stz204579 'process' => 'AUT_PROCESS', 560*4176Stz204579 'priv_effective' => 'ADT_AUT_PRIV_E', # dummy token id 561*4176Stz204579 'priv_limit' => 'ADT_AUT_PRIV_L', # dummy token id 562*4176Stz204579 'priv_inherit' => 'ADT_AUT_PRIV_I', # dummy token id 563*4176Stz204579 'return' => 'AUT_RETURN', 564*4176Stz204579 'seq' => 'AUT_SEQ', 565*4176Stz204579 'socket' => 'AUT_SOCKET', 566*4176Stz204579 'socket-inet' => 'AUT_SOCKET_INET', 567*4176Stz204579 'subject' => 'AUT_SUBJECT', 568*4176Stz204579 'text' => 'AUT_TEXT', 569*4176Stz204579 # 'trailer' => 'AUT_TRAILER', # not used 570*4176Stz204579 'uauth' => 'AUT_UAUTH', 571*4176Stz204579 'zonename' => 'AUT_ZONENAME' 572*4176Stz204579 ); 573*4176Stz204579 574*4176Stz204579 my @xlateEntryList = (); 575*4176Stz204579 576*4176Stz204579 my $external = $event->getExternal(); 577*4176Stz204579 my $internal = $event->getInternal(); 578*4176Stz204579 579*4176Stz204579 unless ($external) { 580*4176Stz204579 print STDERR "No external object captured for event $eventId\n"; 581*4176Stz204579 return; 582*4176Stz204579 } 583*4176Stz204579 if ($eventType) { 584*4176Stz204579 $nameTranslation{$eventId} = $eventId; 585*4176Stz204579 } else { 586*4176Stz204579 $nameTranslation{$eventId} = $external->getInternalName(); 587*4176Stz204579 } 588*4176Stz204579 unless ($internal) { 589*4176Stz204579 print STDERR "No internal object captured for event $eventId\n"; 590*4176Stz204579 return; 591*4176Stz204579 } 592*4176Stz204579 my @entryRef = $internal->getEntries(); 593*4176Stz204579 my $entryRef; 594*4176Stz204579 my @tokenOrder = (); 595*4176Stz204579 my $firstTokenIndex = 0; # djdj not used yet, djdj BUG! 596*4176Stz204579 # needs to be used by translate table 597*4176Stz204579 598*4176Stz204579 if ($internal->isReorder()) { # prescan the entry list to get the token order 599*4176Stz204579 my @inputOrder; 600*4176Stz204579 foreach $entryRef (@entryRef) { 601*4176Stz204579 my ($intEntry, $entry) = @$entryRef; 602*4176Stz204579 push (@inputOrder, $intEntry->getAttr('order')); 603*4176Stz204579 } 604*4176Stz204579 605*4176Stz204579 my $i; # walk down the inputOrder list once 606*4176Stz204579 my $k = 1; # discover next in line 607*4176Stz204579 my $l = 0; # who should point to next in line 608*4176Stz204579 for ($i = 0; $i <= $#inputOrder; $i++) { 609*4176Stz204579 my $j; 610*4176Stz204579 for ($j = 0; $j <= $#inputOrder; $j++) { 611*4176Stz204579 if ($k == $inputOrder[$j]) { 612*4176Stz204579 if ($k == 1) { 613*4176Stz204579 $firstTokenIndex = $j; 614*4176Stz204579 } else { 615*4176Stz204579 $tokenOrder[$l] = "&(selfReference[$j])"; 616*4176Stz204579 } 617*4176Stz204579 $l = $j; 618*4176Stz204579 last; 619*4176Stz204579 } 620*4176Stz204579 } 621*4176Stz204579 $k++; 622*4176Stz204579 } 623*4176Stz204579 $tokenOrder[$l] = 'NULL'; 624*4176Stz204579 } 625*4176Stz204579 else { # default order -- input order same as output 626*4176Stz204579 my $i; 627*4176Stz204579 my $j; 628*4176Stz204579 for ($i = 0; $i < $#entryRef; $i++) { 629*4176Stz204579 my $j = $i + 1; 630*4176Stz204579 $tokenOrder[$i] = "&(selfReference[$j])"; 631*4176Stz204579 } 632*4176Stz204579 $tokenOrder[$#entryRef] = 'NULL'; 633*4176Stz204579 } 634*4176Stz204579 635*4176Stz204579 my $sequence = 0; 636*4176Stz204579 foreach $entryRef (@entryRef) { 637*4176Stz204579 my ($intEntry, $entry) = @$entryRef; 638*4176Stz204579 my $entryId = $entry->getAttr('id'); 639*4176Stz204579 640*4176Stz204579 my ($extEntry, $unusedEntry, $tokenId) = 641*4176Stz204579 $external->getEntry($entryId); 642*4176Stz204579 my $opt = $extEntry->getAttr('opt'); 643*4176Stz204579 644*4176Stz204579 if ($opt eq 'none') { 645*4176Stz204579 if (defined ($doc->getToken($tokenId))) { 646*4176Stz204579 if (defined ($tokenType{$tokenId})) { 647*4176Stz204579 $tokenId = $tokenType{$tokenId}; 648*4176Stz204579 } 649*4176Stz204579 else { 650*4176Stz204579 print STDERR "token id $tokenId not implemented\n"; 651*4176Stz204579 } 652*4176Stz204579 } 653*4176Stz204579 else { 654*4176Stz204579 print STDERR "token = $tokenId is undefined\n"; 655*4176Stz204579 $tokenId = 'error'; 656*4176Stz204579 } 657*4176Stz204579 my ($xlate, $jni) = 658*4176Stz204579 formatTableEntry ('', $tokenId, $eventId, '', 0, 0, $tokenOrder[$sequence], 659*4176Stz204579 'NULL', ''); 660*4176Stz204579 push (@xlateEntryList, $xlate); 661*4176Stz204579 } 662*4176Stz204579 else { 663*4176Stz204579 my $dataType = $extEntry->getAttr('type'); 664*4176Stz204579 $dataType =~ s/\s+//g; # remove blanks (char * => char*) 665*4176Stz204579 666*4176Stz204579 my $enumGroup = ''; 667*4176Stz204579 if ($dataType =~ /^msg/i) { 668*4176Stz204579 $enumGroup = $dataType; 669*4176Stz204579 $enumGroup =~ s/^msg\s*//i; 670*4176Stz204579 $enumGroup = 'adt_' . $enumGroup; 671*4176Stz204579 } 672*4176Stz204579 my $required = ($opt eq 'required') ? 1 : 0; 673*4176Stz204579 my $tsol = 0; 674*4176Stz204579 my $tokenId = $intEntry->getAttr('token'); 675*4176Stz204579 my $token; 676*4176Stz204579 my $tokenName; 677*4176Stz204579 my $tokenFormat = $intEntry->getAttr('format'); 678*4176Stz204579 if (defined ($tokenFormat)) { 679*4176Stz204579 $tokenFormat = "\"$tokenFormat\""; 680*4176Stz204579 } 681*4176Stz204579 else { 682*4176Stz204579 $tokenFormat = 'NULL'; 683*4176Stz204579 } 684*4176Stz204579 685*4176Stz204579 if (defined ($token = $doc->getToken($tokenId))) { 686*4176Stz204579 $tsol = (lc $token->getUsage() eq 'tsol') ? 1 : 0; 687*4176Stz204579 if (defined ($tokenType{$tokenId})) { 688*4176Stz204579 $tokenName = $tokenType{$tokenId}; 689*4176Stz204579 } 690*4176Stz204579 else { 691*4176Stz204579 print STDERR "token id $tokenId not implemented\n"; 692*4176Stz204579 } 693*4176Stz204579 } 694*4176Stz204579 else { 695*4176Stz204579 print STDERR 696*4176Stz204579 "$tokenId is an unimplemented token ($entryId in $eventId)\n"; 697*4176Stz204579 $tokenName = 'AUT_TEXT'; 698*4176Stz204579 } 699*4176Stz204579 my ($xlate, $jni) = 700*4176Stz204579 formatTableEntry($entryId, $tokenName, $eventId, $dataType, $required, 701*4176Stz204579 $tsol, $tokenOrder[$sequence], $tokenFormat, 702*4176Stz204579 $enumGroup, (uc $omit eq 'JNI')); 703*4176Stz204579 push (@xlateEntryList, $xlate); 704*4176Stz204579 } 705*4176Stz204579 $sequence++; 706*4176Stz204579 } 707*4176Stz204579 $xlateEventTable{$eventId} = [\@xlateEntryList, $eventType, $firstTokenIndex, 708*4176Stz204579 $eventHeader]; 709*4176Stz204579} 710*4176Stz204579 711*4176Stz204579sub formatTableEntry { 712*4176Stz204579 my ($id, $token, $eventId, $type, $required, $tsol, $sequence, $format, $enumGroup, 713*4176Stz204579 $omitJNI) = @_; 714*4176Stz204579 715*4176Stz204579 716*4176Stz204579 # does this map belong in the xml source? (at least the defaults?) 717*4176Stz204579 # fill in the default value only if it is other than zero. 718*4176Stz204579 # base type adt name, default value 719*4176Stz204579 my %entryDef = ( 'au_asid_t' => ['ADT_UINT32', ''], 720*4176Stz204579 'uint_t' => ['ADT_UINT32', ''], 721*4176Stz204579 'int' => ['ADT_INT', ''], 722*4176Stz204579 'int32_t' => ['ADT_INT32', ''], 723*4176Stz204579 'uid_t' => ['ADT_UID', 'AU_NOAUDITID'], 724*4176Stz204579 'gid_t' => ['ADT_GID', 'AU_NOAUDITID'], 725*4176Stz204579 'uid_t*' => ['ADT_UIDSTAR', ''], 726*4176Stz204579 'gid_t*' => ['ADT_GIDSTAR', ''], 727*4176Stz204579 'char' => ['ADT_CHAR', ''], 728*4176Stz204579 'char*' => ['ADT_CHARSTAR', ''], 729*4176Stz204579 'char**' => ['ADT_CHAR2STAR', ''], 730*4176Stz204579 'long' => ['ADT_LONG', ''], 731*4176Stz204579 'pid_t' => ['ADT_PID', ''], 732*4176Stz204579 'priv_set_t*' => ['ADT_PRIVSTAR', ''], 733*4176Stz204579 'ulong_t' => ['ADT_ULONG', ''], 734*4176Stz204579 'uint16_t', => ['ADT_UINT16', ''], 735*4176Stz204579 'uint32_t' => ['ADT_UINT32', ''], 736*4176Stz204579 'uint32_t*' => ['ADT_UINT32STAR', ''], 737*4176Stz204579 'uint32_t[]' => ['ADT_UINT32ARRAY', ''], 738*4176Stz204579 'uint64_t' => ['ADT_UINT64', ''], 739*4176Stz204579 'uint64_t*' => ['ADT_UINT64STAR', ''], 740*4176Stz204579 'm_label_t*' => ['ADT_MLABELSTAR', ''], 741*4176Stz204579 ); 742*4176Stz204579 my $xlateLabel = $uniLabel.$xlateUniLabelInc; 743*4176Stz204579 my $xlateLabelInc = 0; 744*4176Stz204579 my $xlateLine = ''; 745*4176Stz204579 my @jniLine = (); 746*4176Stz204579 747*4176Stz204579 # the list handling should be a simple loop with a loop of one 748*4176Stz204579 # falling out naturally. 749*4176Stz204579 750*4176Stz204579 unless ($type =~ /,/) { # if list, then generate sequence of entries 751*4176Stz204579 my $dataType; 752*4176Stz204579 my $dataSize; 753*4176Stz204579 my $xlateLabelRef = ''; 754*4176Stz204579 755*4176Stz204579 my $arraySize = ''; 756*4176Stz204579 $arraySize = $1 if ($type =~ s/\[(\d+)\]/[]/); 757*4176Stz204579 758*4176Stz204579 my $entryType = ${$entryDef{$type}}[0]; 759*4176Stz204579 760*4176Stz204579 my @xlateType = (); # for adt_xlate.c 761*4176Stz204579 my $typeCount = 1; 762*4176Stz204579 763*4176Stz204579 if ($entryType) { 764*4176Stz204579 $dataType = $entryType; 765*4176Stz204579 $type =~ s/([^*]+)\s*(\*+)/$1 $2/; 766*4176Stz204579 $type =~ s/\[\]//; 767*4176Stz204579 $dataSize = "sizeof ($type)"; 768*4176Stz204579 if ($arraySize) { 769*4176Stz204579 $dataSize = "$arraySize * " . $dataSize; 770*4176Stz204579 } 771*4176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 772*4176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 773*4176Stz204579 } elsif ($type eq '') { 774*4176Stz204579 $xlateLabelRef = 'NULL'; 775*4176Stz204579 } elsif ($type =~ /^msg/i) { 776*4176Stz204579 $type =~ s/^msg//i; 777*4176Stz204579 $dataType = 'ADT_MSG'; 778*4176Stz204579 my $dataEnum = 'ADT_LIST_' . uc $type; 779*4176Stz204579 $xlateLine = "{{$dataType, $dataEnum}}"; 780*4176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 781*4176Stz204579 } elsif ($type =~ /time_t/i) { 782*4176Stz204579 $dataType = 'ADT_DATE'; 783*4176Stz204579 $dataSize = "sizeof (time_t)"; 784*4176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 785*4176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 786*4176Stz204579 } elsif ($type =~ /termid/i) { 787*4176Stz204579 $dataType = 'ADT_TERMIDSTAR'; 788*4176Stz204579 $dataSize = "sizeof (au_tid_addr_t *)"; 789*4176Stz204579 $xlateLine = "{{$dataType, $dataSize}}"; 790*4176Stz204579 push (@jniLine, [$id, $dataType, $format, $enumGroup, $required]); 791*4176Stz204579 } elsif ($omitJNI) { 792*4176Stz204579 $xlateLabelRef = 'NULL'; 793*4176Stz204579 } else { 794*4176Stz204579 print STDERR "$type is not an implemented data type\n"; 795*4176Stz204579 $xlateLabelRef = 'NULL'; 796*4176Stz204579 } 797*4176Stz204579 if ($xlateLine && !($xlateTypeList{$xlateLine})) { 798*4176Stz204579 $xlateTypeList{$xlateLine} = $xlateLabel; 799*4176Stz204579 push (@xlateTypeList, "datadef\t$xlateLabel\[1\] =\t$xlateLine;"); 800*4176Stz204579 $xlateLabelInc = 1; 801*4176Stz204579 } else { 802*4176Stz204579 $xlateLabel = $xlateTypeList{$xlateLine}; 803*4176Stz204579 } 804*4176Stz204579 $xlateLabelRef = '&' . $xlateLabel . '[0]' 805*4176Stz204579 unless $xlateLabelRef eq 'NULL'; 806*4176Stz204579 807*4176Stz204579 # "EOL" is where a comma should go unless end of list 808*4176Stz204579 $xlateLine = "{$token,\t1,\t$xlateLabelRef,\t$sequence,\n" . 809*4176Stz204579 "\t\t0,\t$required,\t$tsol,\t$format}EOL"; 810*4176Stz204579 811*4176Stz204579 if (${$entryDef{$type}}[1]) { 812*4176Stz204579 my @list = (); 813*4176Stz204579 if ($xlateDefault{$eventId}) { 814*4176Stz204579 @list = @{$xlateDefault{$eventId}}; 815*4176Stz204579 } else { 816*4176Stz204579 push (@xlateDefaults, $eventId); 817*4176Stz204579 } 818*4176Stz204579 push (@list, $id, ${$entryDef{$type}}[1]); 819*4176Stz204579 $xlateDefault{$eventId} = \@list; 820*4176Stz204579 } 821*4176Stz204579 } else { # is a list 822*4176Stz204579 my @type = split(/,/, $type); 823*4176Stz204579 my @arraySize = (); 824*4176Stz204579 my @id = split(/,/, $id); 825*4176Stz204579 my @jniId = @id; 826*4176Stz204579 my $dataType; 827*4176Stz204579 my $typeCount = ($#type + 1); 828*4176Stz204579 my @xlateType = (); 829*4176Stz204579 my @default = (); 830*4176Stz204579 831*4176Stz204579 foreach my $dtype (@type) { 832*4176Stz204579 my $jniId = shift @jniId; 833*4176Stz204579 my $id = shift @id; 834*4176Stz204579 my $arraySize = ''; 835*4176Stz204579 $arraySize = $1 if ($dtype =~ s/\[(\d+)\]/[]/); 836*4176Stz204579 837*4176Stz204579 my $entryType = ${$entryDef{$dtype}}[0]; 838*4176Stz204579 if ($entryType) { 839*4176Stz204579 my $type = $dtype; 840*4176Stz204579 $type =~ s/([^*]+)\s*(\*+)/$1 $2/; 841*4176Stz204579 $type =~ s/\[\]//; 842*4176Stz204579 843*4176Stz204579 my $sizeString = "sizeof"; 844*4176Stz204579 $sizeString = "$arraySize * " . $sizeString if $arraySize; 845*4176Stz204579 push (@xlateType, "\{$entryType, $sizeString ($type)\}"); 846*4176Stz204579 push (@jniLine, [$jniId, $entryType, $format, $enumGroup, $required]); 847*4176Stz204579 } elsif ($type =~ /^msg/i) { 848*4176Stz204579 $type =~ s/^msg//i; 849*4176Stz204579 $dataType = 'ADT_MSG'; 850*4176Stz204579 my $dataEnum = 'ADT_LIST_' . uc $type; 851*4176Stz204579 push (@xlateType, "\{$dataType, $dataEnum\}};"); 852*4176Stz204579 push (@jniLine, [$jniId, $dataType, $format, $enumGroup, $required]); 853*4176Stz204579 } elsif ($type =~ /time_t/i) { 854*4176Stz204579 $dataType = 'ADT_DATE'; 855*4176Stz204579 push (@xlateType, "\{$entryType, sizeof ($type)\}"); 856*4176Stz204579 push (@jniLine, [$jniId, $entryType, $format, $enumGroup, $required]); 857*4176Stz204579 } elsif ($type =~ /termid/i) { 858*4176Stz204579 $dataType = 'ADT_TERMIDSTAR'; 859*4176Stz204579 push (@xlateType, "\{$dataType, sizeof (au_tid_addr_t *)\}"); 860*4176Stz204579 push (@jniLine, [$jniId, $dataType, $format, $enumGroup, $required]); 861*4176Stz204579 } elsif ($omitJNI) { 862*4176Stz204579 # nothing to do. 863*4176Stz204579 } else { 864*4176Stz204579 print STDERR "$dtype is not an implemented data type\n"; 865*4176Stz204579 } 866*4176Stz204579 if (${$entryDef{$dtype}}[1]) { 867*4176Stz204579 push (@default, $id, ${$entryDef{$dtype}}[1]); 868*4176Stz204579 } 869*4176Stz204579 } 870*4176Stz204579 my $xlateArray = "\[$typeCount\] =\t{" . join(",\n\t\t\t\t", @xlateType) . "};"; 871*4176Stz204579 872*4176Stz204579 unless ($xlateTypeList{$xlateArray}) { 873*4176Stz204579 $xlateTypeList{$xlateArray} = $xlateLabel; 874*4176Stz204579 $xlateArray = "datadef\t$xlateLabel" . $xlateArray; 875*4176Stz204579 push (@xlateTypeList, $xlateArray); 876*4176Stz204579 $xlateLabelInc = 1; 877*4176Stz204579 } else { 878*4176Stz204579 $xlateLabel = $xlateTypeList{$xlateArray}; 879*4176Stz204579 } 880*4176Stz204579 $xlateLine = 881*4176Stz204579 "{$token,\t$typeCount,\t&$xlateLabel\[0\],\t$sequence,\n" . 882*4176Stz204579 "\t\t0,\t$required,\t$tsol,\t$format}EOL"; 883*4176Stz204579 if (@default) { 884*4176Stz204579 my @list = (); 885*4176Stz204579 if ($xlateDefault{$eventId}) { 886*4176Stz204579 @list = @{$xlateDefault{$eventId}}; 887*4176Stz204579 } else { 888*4176Stz204579 push (@xlateDefaults, $eventId); 889*4176Stz204579 } 890*4176Stz204579 push (@list, @default); 891*4176Stz204579 $xlateDefault{$eventId} = \@list; 892*4176Stz204579 } 893*4176Stz204579 } 894*4176Stz204579 $xlateUniLabelInc++ if $xlateLabelInc; 895*4176Stz204579 return ($xlateLine, \@jniLine); 896*4176Stz204579} 897*4176Stz204579 898*4176Stz204579sub generateAPIFile { 899*4176Stz204579 my $event = shift; 900*4176Stz204579 my $eventId = shift; 901*4176Stz204579 my $eventType = shift; 902*4176Stz204579 my $eventHeader = shift; 903*4176Stz204579 my $idNo = shift; 904*4176Stz204579 905*4176Stz204579 my @entryList = (); 906*4176Stz204579 907*4176Stz204579 my $external = $event->getExternal(); 908*4176Stz204579 909*4176Stz204579 if ($eventType && $debug) { 910*4176Stz204579 print STDERR "event $eventId is of type $eventType\n"; 911*4176Stz204579 } 912*4176Stz204579 913*4176Stz204579 return unless $external; 914*4176Stz204579 915*4176Stz204579 my ($extEntry, $entry, $tokenId, $format); 916*4176Stz204579 while (($extEntry, $entry, $tokenId, $format) = $external->getNextEntry()) { 917*4176Stz204579 last unless $entry; 918*4176Stz204579 my $entryId = $entry->getAttr('id'); 919*4176Stz204579 920*4176Stz204579 unless (defined $entryId) { 921*4176Stz204579 print STDERR "undefined entry id for external $eventId\n"; 922*4176Stz204579 next; 923*4176Stz204579 } 924*4176Stz204579 my $option = $extEntry->getAttr('opt'); 925*4176Stz204579 next if ($option eq 'none'); 926*4176Stz204579 927*4176Stz204579 if (defined (my $token = $doc->getToken($tokenId))) { 928*4176Stz204579 $option = 'Trusted Solaris only' 929*4176Stz204579 if (lc $token->getUsage() eq 'tsol') ? 1 : 0; 930*4176Stz204579 } 931*4176Stz204579 $option .= " (format: $format)" if $format; 932*4176Stz204579 933*4176Stz204579 my $dataType = $extEntry->getAttr('type'); 934*4176Stz204579 unless (defined $dataType) { 935*4176Stz204579 print STDERR "no type defined for external tag for $eventId\n"; 936*4176Stz204579 $dataType = "error"; 937*4176Stz204579 } 938*4176Stz204579 939*4176Stz204579 my $comment = $entry->getContent(); 940*4176Stz204579 941*4176Stz204579 if (($dataType =~ /,/) || ($entryId =~ /,/)) { 942*4176Stz204579 my @type = split(/\s*,\s*/, $dataType); 943*4176Stz204579 my @id = split(/\s*,\s*/, $entryId); 944*4176Stz204579 if ($#type != $#id) { 945*4176Stz204579 print STDERR 946*4176Stz204579 "number of data types ($dataType) does not match number of ids ($entryId)", 947*4176Stz204579 " for event $eventId\n"; 948*4176Stz204579 if ($#type < $#id) { 949*4176Stz204579 $#id = $#type; 950*4176Stz204579 } 951*4176Stz204579 else { 952*4176Stz204579 $#type = $#id; 953*4176Stz204579 } 954*4176Stz204579 } 955*4176Stz204579 956*4176Stz204579 my $i; 957*4176Stz204579 my $line = ''; 958*4176Stz204579 $line = "/* $comment */\n\t" if defined $comment; 959*4176Stz204579 for ($i = 0; $i <= $#type; $i++) { 960*4176Stz204579 my ($primitive, $dereference) = 961*4176Stz204579 ($type[$i] =~ /([^\*]+)\s*(\**)/); 962*4176Stz204579 $id[$i] .= $1 if ($primitive =~ s/(\[\d+\])//); 963*4176Stz204579 $line .= "$primitive\t$dereference$id[$i];\t/* $option */"; 964*4176Stz204579 push (@entryList, $line); 965*4176Stz204579 $line = ''; 966*4176Stz204579 } 967*4176Stz204579 } 968*4176Stz204579 else { 969*4176Stz204579 my $line = ''; 970*4176Stz204579 $line = "/* $comment */\n\t" if defined $comment; 971*4176Stz204579 if ($dataType =~ /^msg/i) { 972*4176Stz204579 $dataType =~ s/^msg\s*//i; 973*4176Stz204579 $line .= "enum adt_$dataType" . "\t$entryId;\t/* $option */"; 974*4176Stz204579 } 975*4176Stz204579 elsif ($dataType =~ /time_t/i) { 976*4176Stz204579 $line .= "time_t\t$entryId;\t/* $option */"; 977*4176Stz204579 } 978*4176Stz204579 else { 979*4176Stz204579 my ($primitive, $dereference) = 980*4176Stz204579 ($dataType =~ /([^\*]+)\s*(\**)/); 981*4176Stz204579 $entryId .= $1 if ($primitive =~ s/(\[\d+\])//); 982*4176Stz204579 $line .= "$primitive\t$dereference$entryId;\t/* $option */"; 983*4176Stz204579 } 984*4176Stz204579 push (@entryList, $line); 985*4176Stz204579 } 986*4176Stz204579 } 987*4176Stz204579 $eventExtra{$eventId} = [$eventHeader, $idNo]; 988*4176Stz204579 $eventAPI{$eventId} = \@entryList; 989*4176Stz204579} 990*4176Stz204579 991*4176Stz204579sub generateMsgLists { 992*4176Stz204579 my $textList = shift; 993*4176Stz204579 994*4176Stz204579 my $textName = $textList->getId(); 995*4176Stz204579 my $header = $textList->getHeader(); 996*4176Stz204579 my $start = $textList->getMsgStart(); 997*4176Stz204579 my $public = $textList->getMsgPublic(); 998*4176Stz204579 my $deprecated = $textList->getDeprecated(); 999*4176Stz204579 1000*4176Stz204579 addHeader($header); 1001*4176Stz204579 print "$textName starts at $start\n" if $debug; 1002*4176Stz204579 1003*4176Stz204579 my $entry; 1004*4176Stz204579 my @entry; 1005*4176Stz204579 while ($entry = $textList->getNextMsg()) { 1006*4176Stz204579 if ($debug) { 1007*4176Stz204579 my ($id, $text) = split(/\s*::\s*/, $entry); 1008*4176Stz204579 print " $id = $text\n"; 1009*4176Stz204579 } 1010*4176Stz204579 unshift (@entry, $entry); 1011*4176Stz204579 } 1012*4176Stz204579 $msg_list{$textName} = 1013*4176Stz204579 [\@entry, [$header, $start, $public, $deprecated]]; 1014*4176Stz204579} 1015*4176Stz204579 1016*4176Stz204579sub addHeader { 1017*4176Stz204579 my $header_index = shift; 1018*4176Stz204579 1019*4176Stz204579 die "invalid adt_event_N.h index: $header_index\n" 1020*4176Stz204579 unless ($header_index =~ /^\d+$/); 1021*4176Stz204579 1022*4176Stz204579 $headers{$header_index} = $header_index; 1023*4176Stz204579} 1024*4176Stz204579 1025*4176Stz204579# $header = 0 is a special case; it is for adt_event.h 1026*4176Stz204579# $header > 0 creates adt_event_N.h, where N = $header 1027*4176Stz204579 1028*4176Stz204579sub openHeaderFiles { 1029*4176Stz204579 my $outfile = shift; # path to an adt_event_N.h file 1030*4176Stz204579 1031*4176Stz204579 my $header; 1032*4176Stz204579 my @Hfile = (); # potentially sparse array of file handles 1033*4176Stz204579 my @HfileName = (); # parallel array to Hfile, file name (not path) 1034*4176Stz204579 foreach $header (sort keys %headers) { 1035*4176Stz204579 my $file = $outfile; 1036*4176Stz204579 if ($header > 0) { 1037*4176Stz204579 $file =~ s/_N/_$header/; 1038*4176Stz204579 } else { 1039*4176Stz204579 $file =~ s/_N//; 1040*4176Stz204579 } 1041*4176Stz204579 unless (open($Hfile[$header], ">$file")) { 1042*4176Stz204579 print STDERR "can't open output ($file): $!\n"; 1043*4176Stz204579 $HfileName[$header] = ''; 1044*4176Stz204579 $Hfile[$header] = ''; 1045*4176Stz204579 } else { 1046*4176Stz204579 my @tmp = split(/\//, $file); 1047*4176Stz204579 $HfileName[$header] = $tmp[$#tmp]; 1048*4176Stz204579 } 1049*4176Stz204579 } 1050*4176Stz204579 return (@Hfile); 1051*4176Stz204579} 1052*4176Stz204579 1053*4176Stz204579sub closeHeaderFiles { 1054*4176Stz204579 my @Hfile = @_; 1055*4176Stz204579 1056*4176Stz204579 my $header; 1057*4176Stz204579 foreach $header (sort keys %headers) { 1058*4176Stz204579 close $Hfile[$header] if $Hfile[$header]; 1059*4176Stz204579 } 1060*4176Stz204579} 1061