xref: /titanic_44/usr/src/cmd/auditrecord/mkmsg.pl (revision cf9691b98ccefac465372c1b1b779ed4834d8020)
1*cf9691b9Sgww#!/usr/perl5/bin/perl -w
2*cf9691b9Sgww#
3*cf9691b9Sgww# CDDL HEADER START
4*cf9691b9Sgww#
5*cf9691b9Sgww# 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.
8*cf9691b9Sgww#
9*cf9691b9Sgww# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*cf9691b9Sgww# or http://www.opensolaris.org/os/licensing.
11*cf9691b9Sgww# See the License for the specific language governing permissions
12*cf9691b9Sgww# and limitations under the License.
13*cf9691b9Sgww#
14*cf9691b9Sgww# When distributing Covered Code, include this CDDL HEADER in each
15*cf9691b9Sgww# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*cf9691b9Sgww# If applicable, add the following below this CDDL HEADER, with the
17*cf9691b9Sgww# fields enclosed by brackets "[]" replaced with your own identifying
18*cf9691b9Sgww# information: Portions Copyright [yyyy] [name of copyright owner]
19*cf9691b9Sgww#
20*cf9691b9Sgww# CDDL HEADER END
21*cf9691b9Sgww#
22*cf9691b9Sgww#
23*cf9691b9Sgww# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*cf9691b9Sgww# Use is subject to license terms.
25*cf9691b9Sgww#
26*cf9691b9Sgww
27*cf9691b9Sgww# mkmsg.pl -- generate message file content for strings that
28*cf9691b9Sgww# originate in audit_record_attr and audit_event
29*cf9691b9Sgww#
30*cf9691b9Sgww# mkmsg.pl domain po_file_name
31*cf9691b9Sgww
32*cf9691b9Sgwwrequire 5.005;
33*cf9691b9Sgwwuse strict;
34*cf9691b9Sgww
35*cf9691b9Sgwwuse vars qw(
36*cf9691b9Sgww    $parse %translateText
37*cf9691b9Sgww    $debug
38*cf9691b9Sgww    %attr %event %class %skipClass %token %noteAlias);
39*cf9691b9Sgww
40*cf9691b9Sgwwuse locale;
41*cf9691b9Sgwwuse POSIX qw(locale_h);
42*cf9691b9Sgwwuse Sun::Solaris::Utils qw(gettext textdomain);
43*cf9691b9Sgwwuse Sun::Solaris::BSM::_BSMparse;
44*cf9691b9Sgww
45*cf9691b9Sgwwunless ($#ARGV == 1) {
46*cf9691b9Sgww	print STDERR "usage: $0 domain_name file_name\n";
47*cf9691b9Sgww	exit (1);
48*cf9691b9Sgww}
49*cf9691b9Sgwwmy $textDomain = $ARGV[0];
50*cf9691b9Sgwwmy $poFile = $ARGV[1];
51*cf9691b9Sgww
52*cf9691b9Sgww# Set message locale
53*cf9691b9Sgwwsetlocale(LC_ALL, "");
54*cf9691b9Sgwwtextdomain($textDomain);
55*cf9691b9Sgww
56*cf9691b9Sgwwmy %options;
57*cf9691b9Sgww$options{'classFilter'} = '';		# don''t filter
58*cf9691b9Sgww$debug			= 0;		# debug mode on
59*cf9691b9Sgww$options{'eventFilter'} = '';   	# don''t filter
60*cf9691b9Sgww$options{'idFilter'}	= '';		# don''t filter
61*cf9691b9Sgww
62*cf9691b9Sgww$parse = new Sun::Solaris::BSM::_BSMparse($debug, \%options, './',
63*cf9691b9Sgww    '../../lib/libbsm', '.txt');
64*cf9691b9Sgww
65*cf9691b9Sgwwmy ($attr, $token, $skipClass, $noteAlias) = $parse->readAttr();
66*cf9691b9Sgww%class = %{$parse->readClass()};
67*cf9691b9Sgww%event = %{$parse->readEvent()};
68*cf9691b9Sgww
69*cf9691b9Sgww%attr  = %$attr;
70*cf9691b9Sgww%token = %$token;
71*cf9691b9Sgww%noteAlias = %$noteAlias;
72*cf9691b9Sgww%skipClass = %$skipClass;
73*cf9691b9Sgww
74*cf9691b9Sgwwmy $label;
75*cf9691b9Sgww
76*cf9691b9Sgwwmy $errString;
77*cf9691b9Sgww
78*cf9691b9Sgwwforeach $label (sort keys %event) {
79*cf9691b9Sgww
80*cf9691b9Sgww	my ($id, $class, $eventDescription) = ('', '', '');
81*cf9691b9Sgww	if (defined($event{$label})) {
82*cf9691b9Sgww		($id, $class, $eventDescription) = @{$event{$label}};
83*cf9691b9Sgww		$eventDescription =~ s/\(\w+\)//;
84*cf9691b9Sgww	}
85*cf9691b9Sgww
86*cf9691b9Sgww	my ($name, $description, $title, $skip, @case) = ('', '', '', '', ());
87*cf9691b9Sgww	if (defined($attr{$label})) {
88*cf9691b9Sgww		($name, $description, $title, $skip, @case) = @{$attr{$label}};
89*cf9691b9Sgww		$description = '' if ($description eq 'none');
90*cf9691b9Sgww		$name = '' if ($name eq 'none');
91*cf9691b9Sgww		$title = $name if (($title eq 'none') || (!defined($title)));
92*cf9691b9Sgww	}
93*cf9691b9Sgww
94*cf9691b9Sgww# in auditrecord.pl, _either_ $description _or_ $eventDescription
95*cf9691b9Sgww# is used.  Both are put into the message file so that this script
96*cf9691b9Sgww# doesn't have logic dependent on auditrecord.pl
97*cf9691b9Sgww
98*cf9691b9Sgww	addToMsgFile($title);
99*cf9691b9Sgww	addToMsgFile($eventDescription);
100*cf9691b9Sgww	addToMsgFile($description);
101*cf9691b9Sgww
102*cf9691b9Sgww	my $case;
103*cf9691b9Sgww
104*cf9691b9Sgww	foreach $case (@case) {
105*cf9691b9Sgww		addToMsgFile(${$case}[0]);	# description
106*cf9691b9Sgww		#		[1]		# token id (a name list)
107*cf9691b9Sgww		my @comment = split(/\s*:\s*/, ${$case}[2]);
108*cf9691b9Sgww		my $note = ${$case}[3];
109*cf9691b9Sgww
110*cf9691b9Sgww		my $comment;
111*cf9691b9Sgww		foreach $comment (@comment) {
112*cf9691b9Sgww			addToMsgFile($comment);
113*cf9691b9Sgww		}
114*cf9691b9Sgww		if ($noteAlias{$note}) {
115*cf9691b9Sgww			addToMsgFile($noteAlias{$note});
116*cf9691b9Sgww		} else {
117*cf9691b9Sgww			addToMsgFile($note);
118*cf9691b9Sgww		}
119*cf9691b9Sgww	}
120*cf9691b9Sgww
121*cf9691b9Sgww}
122*cf9691b9SgwwwriteMsgFile($textDomain, $poFile);
123*cf9691b9Sgww
124*cf9691b9Sgwwexit (0);
125*cf9691b9Sgww
126*cf9691b9Sgwwsub addToMsgFile {
127*cf9691b9Sgww	my @text = @_;
128*cf9691b9Sgww
129*cf9691b9Sgww	my $text;
130*cf9691b9Sgww	foreach $text (@text) {
131*cf9691b9Sgww		next if ($text =~ /^$/);
132*cf9691b9Sgww		$text =~ s/:/:/g;
133*cf9691b9Sgww		$translateText{$text} = 1;
134*cf9691b9Sgww	}
135*cf9691b9Sgww}
136*cf9691b9Sgww
137*cf9691b9Sgww# ids in the .po file must be quoted; since the messages themselves
138*cf9691b9Sgww# contain quotes, quotes must be escaped
139*cf9691b9Sgww
140*cf9691b9Sgwwsub writeMsgFile {
141*cf9691b9Sgww	my $domain = shift;
142*cf9691b9Sgww	my $file = shift;
143*cf9691b9Sgww
144*cf9691b9Sgww	my $text;
145*cf9691b9Sgww
146*cf9691b9Sgww	open(Message, ">$file") or
147*cf9691b9Sgww		die "Failed to open $file: $!\n";
148*cf9691b9Sgww
149*cf9691b9Sgww	print Message "# File:audit_record_attr: textdomain(\"$domain\")\n";
150*cf9691b9Sgww	foreach $text (sort keys %translateText) {
151*cf9691b9Sgww		$text =~ s/"/\\"/g;
152*cf9691b9Sgww		print Message "msgid \"$text\"\nmsgstr\n";
153*cf9691b9Sgww	}
154*cf9691b9Sgww	close Message;
155*cf9691b9Sgww}
156