17c478bd9Sstevel@tonic-gate#!/usr/perl5/bin/perl -w 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 6*cf9691b9Sgww# Common Development and Distribution License (the "License"). 7*cf9691b9Sgww# You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate# and limitations under the License. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate# 207c478bd9Sstevel@tonic-gate# CDDL HEADER END 217c478bd9Sstevel@tonic-gate# 227c478bd9Sstevel@tonic-gate# 23*cf9691b9Sgww# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*cf9691b9Sgww# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate# 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate# mkmsg.pl -- generate message file content for strings that 287c478bd9Sstevel@tonic-gate# originate in audit_record_attr and audit_event 297c478bd9Sstevel@tonic-gate# 307c478bd9Sstevel@tonic-gate# mkmsg.pl domain po_file_name 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gaterequire 5.005; 337c478bd9Sstevel@tonic-gateuse strict; 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gateuse vars qw( 367c478bd9Sstevel@tonic-gate $parse %translateText 377c478bd9Sstevel@tonic-gate $debug 387c478bd9Sstevel@tonic-gate %attr %event %class %skipClass %token %noteAlias); 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gateuse locale; 417c478bd9Sstevel@tonic-gateuse POSIX qw(locale_h); 427c478bd9Sstevel@tonic-gateuse Sun::Solaris::Utils qw(gettext textdomain); 437c478bd9Sstevel@tonic-gateuse Sun::Solaris::BSM::_BSMparse; 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gateunless ($#ARGV == 1) { 467c478bd9Sstevel@tonic-gate print STDERR "usage: $0 domain_name file_name\n"; 477c478bd9Sstevel@tonic-gate exit (1); 487c478bd9Sstevel@tonic-gate} 497c478bd9Sstevel@tonic-gatemy $textDomain = $ARGV[0]; 507c478bd9Sstevel@tonic-gatemy $poFile = $ARGV[1]; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate# Set message locale 537c478bd9Sstevel@tonic-gatesetlocale(LC_ALL, ""); 547c478bd9Sstevel@tonic-gatetextdomain($textDomain); 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gatemy %options; 577c478bd9Sstevel@tonic-gate$options{'classFilter'} = ''; # don''t filter 587c478bd9Sstevel@tonic-gate$debug = 0; # debug mode on 597c478bd9Sstevel@tonic-gate$options{'eventFilter'} = ''; # don''t filter 607c478bd9Sstevel@tonic-gate$options{'idFilter'} = ''; # don''t filter 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate$parse = new Sun::Solaris::BSM::_BSMparse($debug, \%options, './', 637c478bd9Sstevel@tonic-gate '../../lib/libbsm', '.txt'); 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gatemy ($attr, $token, $skipClass, $noteAlias) = $parse->readAttr(); 667c478bd9Sstevel@tonic-gate%class = %{$parse->readClass()}; 677c478bd9Sstevel@tonic-gate%event = %{$parse->readEvent()}; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate%attr = %$attr; 707c478bd9Sstevel@tonic-gate%token = %$token; 717c478bd9Sstevel@tonic-gate%noteAlias = %$noteAlias; 727c478bd9Sstevel@tonic-gate%skipClass = %$skipClass; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gatemy $label; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gatemy $errString; 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gateforeach $label (sort keys %event) { 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate my ($id, $class, $eventDescription) = ('', '', ''); 817c478bd9Sstevel@tonic-gate if (defined($event{$label})) { 827c478bd9Sstevel@tonic-gate ($id, $class, $eventDescription) = @{$event{$label}}; 837c478bd9Sstevel@tonic-gate $eventDescription =~ s/\(\w+\)//; 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate my ($name, $description, $title, $skip, @case) = ('', '', '', '', ()); 877c478bd9Sstevel@tonic-gate if (defined($attr{$label})) { 887c478bd9Sstevel@tonic-gate ($name, $description, $title, $skip, @case) = @{$attr{$label}}; 897c478bd9Sstevel@tonic-gate $description = '' if ($description eq 'none'); 907c478bd9Sstevel@tonic-gate $name = '' if ($name eq 'none'); 917c478bd9Sstevel@tonic-gate $title = $name if (($title eq 'none') || (!defined($title))); 927c478bd9Sstevel@tonic-gate } 937c478bd9Sstevel@tonic-gate 94*cf9691b9Sgww# in auditrecord.pl, _either_ $description _or_ $eventDescription 957c478bd9Sstevel@tonic-gate# is used. Both are put into the message file so that this script 96*cf9691b9Sgww# doesn't have logic dependent on auditrecord.pl 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate addToMsgFile($title); 997c478bd9Sstevel@tonic-gate addToMsgFile($eventDescription); 1007c478bd9Sstevel@tonic-gate addToMsgFile($description); 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate my $case; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate foreach $case (@case) { 1057c478bd9Sstevel@tonic-gate addToMsgFile(${$case}[0]); # description 1067c478bd9Sstevel@tonic-gate # [1] # token id (a name list) 1077c478bd9Sstevel@tonic-gate my @comment = split(/\s*:\s*/, ${$case}[2]); 1087c478bd9Sstevel@tonic-gate my $note = ${$case}[3]; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate my $comment; 1117c478bd9Sstevel@tonic-gate foreach $comment (@comment) { 1127c478bd9Sstevel@tonic-gate addToMsgFile($comment); 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate if ($noteAlias{$note}) { 1157c478bd9Sstevel@tonic-gate addToMsgFile($noteAlias{$note}); 1167c478bd9Sstevel@tonic-gate } else { 1177c478bd9Sstevel@tonic-gate addToMsgFile($note); 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate } 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate} 1227c478bd9Sstevel@tonic-gatewriteMsgFile($textDomain, $poFile); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gateexit (0); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gatesub addToMsgFile { 1277c478bd9Sstevel@tonic-gate my @text = @_; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate my $text; 1307c478bd9Sstevel@tonic-gate foreach $text (@text) { 1317c478bd9Sstevel@tonic-gate next if ($text =~ /^$/); 1327c478bd9Sstevel@tonic-gate $text =~ s/:/:/g; 1337c478bd9Sstevel@tonic-gate $translateText{$text} = 1; 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate} 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate# ids in the .po file must be quoted; since the messages themselves 1387c478bd9Sstevel@tonic-gate# contain quotes, quotes must be escaped 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gatesub writeMsgFile { 1417c478bd9Sstevel@tonic-gate my $domain = shift; 1427c478bd9Sstevel@tonic-gate my $file = shift; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate my $text; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate open(Message, ">$file") or 1477c478bd9Sstevel@tonic-gate die "Failed to open $file: $!\n"; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate print Message "# File:audit_record_attr: textdomain(\"$domain\")\n"; 1507c478bd9Sstevel@tonic-gate foreach $text (sort keys %translateText) { 1517c478bd9Sstevel@tonic-gate $text =~ s/"/\\"/g; 1527c478bd9Sstevel@tonic-gate print Message "msgid \"$text\"\nmsgstr\n"; 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate close Message; 1557c478bd9Sstevel@tonic-gate} 156