1#!/usr/perl5/bin/perl -w 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22# 23# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26 27# audit_record_xml [-d] <xml input file> 28 29# audit_record_xml takes the audit record description (.xml file) and 30# generates adt_ part of audit_record_attr on stdout. 31 32use auditxml; 33use Getopt::Std; 34use vars qw($opt_d); 35use strict; 36 37 38our $debug = 0; # normal use is to set via the file being parsed. 39 # <debug set="on"/> or <debug set="off"/> or <debug/> 40 # if the set attribute is omitted, debug state is toggled 41 # Override with appDebug, but toggle won't do what you 42 # want. 43my $appDebug = 0; # used after return from "new auditxml"; 44 45my $prog = $0; $prog =~ s|.*/||g; 46my $usage = "usage: $prog [-d] file.xml\n"; 47 48getopts('d'); 49 50$appDebug = $opt_d; 51 52die $usage if ($#ARGV < 0); 53 54my $doc = new auditxml ($ARGV[0]); # input XML file 55 56$debug = $appDebug; 57 58foreach my $eventId ($doc->getEventIds) { 59 my $event = $doc->getEvent($eventId); 60 next if ($event->getOmit eq 'always'); 61 print "label=$eventId\n"; 62 my $title = $event->getTitle; 63 print " title=$title\n" if (defined $title && length($title)); 64 my $program = $event->getProgram; 65 if (defined $program && scalar @$program) { 66 print " program="; 67 print join(";", @$program); 68 print "\n"; 69 } 70 my $see = $event->getSee; 71 if (defined $see && scalar @$see) { 72 print " see="; 73 print join(";", @$see); 74 print "\n"; 75 } 76 my $format = []; 77 my $comments = []; 78 my $idx = 0; 79 my $superClass = $event->getSuperClass; 80 $event = $superClass if (defined $superClass && ref($superClass)); 81 foreach my $entryId ($event->getExternal->getEntryIds) { 82 next if $entryId eq 'subject'; 83 next if $entryId eq 'return'; 84 my @entry = $event->getExternal->getEntry($entryId); 85 my $token = $entry[2]; 86 my $comment = $entry[4]; 87 my $opt = $entry[0]->getAttr('opt'); 88 $token = "[$token]" if ($opt eq 'optional'); 89 if (defined $comment && ($comment ne '')) { 90 $idx++; 91 $token .= $idx; 92 push @$comments, $comment; 93 } 94 push @$format, $token; 95 } 96 if (scalar @$format) { 97 print " format=".join(":", @$format)."\n"; 98 } else { 99 print " format=user\n"; 100 } 101 my $commentStr = ''; 102 foreach (@$comments) { 103 $commentStr .= " comment=$_:\n"; 104 } 105 $commentStr =~ s/:\n$/\n/s; 106 print $commentStr; 107 print "\n"; 108} 109 110exit (0); 111 112