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