xref: /illumos-gate/usr/src/cmd/auditrecord/mkmsg.pl (revision 6bb6b5762ca4b17cd5fb3c6c123f17489d5635aa)
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# mkmsg.pl -- generate message file content for strings that
28# originate in audit_record_attr and audit_event
29#
30# mkmsg.pl domain po_file_name
31
32require 5.005;
33use strict;
34
35use vars qw(
36    $parse %translateText
37    $debug
38    %attr %event %class %skipClass %token %noteAlias);
39
40use locale;
41use POSIX qw(locale_h);
42use Sun::Solaris::Utils qw(gettext textdomain);
43use Sun::Solaris::BSM::_BSMparse;
44
45unless ($#ARGV == 1) {
46	print STDERR "usage: $0 domain_name file_name\n";
47	exit (1);
48}
49my $textDomain = $ARGV[0];
50my $poFile = $ARGV[1];
51
52# Set message locale
53setlocale(LC_ALL, "");
54textdomain($textDomain);
55
56my %options;
57$options{'classFilter'} = '';		# don''t filter
58$debug			= 0;		# debug mode on
59$options{'eventFilter'} = '';   	# don''t filter
60$options{'idFilter'}	= '';		# don''t filter
61
62$parse = new Sun::Solaris::BSM::_BSMparse($debug, \%options, './',
63    '../../lib/libbsm', '.txt');
64
65my ($attr, $token, $skipClass, $noteAlias) = $parse->readAttr();
66%class = %{$parse->readClass()};
67%event = %{$parse->readEvent()};
68
69%attr  = %$attr;
70%token = %$token;
71%noteAlias = %$noteAlias;
72%skipClass = %$skipClass;
73
74my $label;
75
76my $errString;
77
78foreach $label (sort keys %event) {
79
80	my ($id, $class, $eventDescription) = ('', '', '');
81	if (defined($event{$label})) {
82		($id, $class, $eventDescription) = @{$event{$label}};
83		$eventDescription =~ s/\(\w+\)//;
84	}
85
86	my ($name, $description, $title, $skip, @case) = ('', '', '', '', ());
87	if (defined($attr{$label})) {
88		($name, $description, $title, $skip, @case) = @{$attr{$label}};
89		$description = '' if ($description eq 'none');
90		$name = '' if ($name eq 'none');
91		$title = $name if (($title eq 'none') || (!defined($title)));
92	}
93
94# in auditrecord.pl, _either_ $description _or_ $eventDescription
95# is used.  Both are put into the message file so that this script
96# doesn't have logic dependent on auditrecord.pl
97
98	addToMsgFile($title);
99	addToMsgFile($eventDescription);
100	addToMsgFile($description);
101
102	my $case;
103
104	foreach $case (@case) {
105		addToMsgFile(${$case}[0]);	# description
106		#		[1]		# token id (a name list)
107		my @comment = split(/\s*:\s*/, ${$case}[2]);
108		my $note = ${$case}[3];
109
110		my $comment;
111		foreach $comment (@comment) {
112			addToMsgFile($comment);
113		}
114		if ($noteAlias{$note}) {
115			addToMsgFile($noteAlias{$note});
116		} else {
117			addToMsgFile($note);
118		}
119	}
120
121}
122writeMsgFile($textDomain, $poFile);
123
124exit (0);
125
126sub addToMsgFile {
127	my @text = @_;
128
129	my $text;
130	foreach $text (@text) {
131		next if ($text =~ /^$/);
132		$text =~ s/:/:/g;
133		$translateText{$text} = 1;
134	}
135}
136
137# ids in the .po file must be quoted; since the messages themselves
138# contain quotes, quotes must be escaped
139
140sub writeMsgFile {
141	my $domain = shift;
142	my $file = shift;
143
144	my $text;
145
146	open(Message, ">$file") or
147		die "Failed to open $file: $!\n";
148
149	print Message "# File:audit_record_attr: textdomain(\"$domain\")\n";
150	foreach $text (sort keys %translateText) {
151		$text =~ s/"/\\"/g;
152		print Message "msgid \"$text\"\nmsgstr\n";
153	}
154	close Message;
155}
156