From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 4C84ED381 for ; Wed, 30 Nov 2022 14:22:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1FEDE1E027 for ; Wed, 30 Nov 2022 14:21:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 30 Nov 2022 14:21:39 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 430A443690 for ; Wed, 30 Nov 2022 14:21:39 +0100 (CET) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Wed, 30 Nov 2022 14:21:29 +0100 Message-Id: <20221130132129.66108-1-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.162 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pmg-devel] [PATCH pmg-api] pmgdb dump: encode ruledata before printing X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Nov 2022 13:22:10 -0000 was overlooked with the utf-8 support for rules and objects this patch prevents a "Wide character in print at .." when dumping the ruledata Reported-by: Dominik Csapak Signed-off-by: Stoiko Ivanov --- src/PMG/CLI/pmgdb.pm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/PMG/CLI/pmgdb.pm b/src/PMG/CLI/pmgdb.pm index 417e008..8368af8 100644 --- a/src/PMG/CLI/pmgdb.pm +++ b/src/PMG/CLI/pmgdb.pm @@ -3,6 +3,7 @@ package PMG::CLI::pmgdb; use strict; use warnings; use Data::Dumper; +use Encode qw(encode); use PVE::SafeSyslog; use PVE::Tools qw(extract_param); @@ -31,7 +32,7 @@ sub print_objects { my $objects = $ruledb->load_group_objects ($og->{id}); foreach my $obj (@$objects) { - my $desc = $obj->short_desc (); + my $desc = encode('UTF-8', $obj->short_desc()); print " OBJECT $obj->{id}: $desc\n"; } } @@ -46,31 +47,34 @@ sub print_rule { }; my $active = $rule->{active} ? 'active' : 'inactive'; my $dir = $direction->{$rule->{direction}}; + my $rulename = encode('UTF-8', $rule->{name}); - print "Found RULE $rule->{id} (prio: $rule->{priority}, $dir, $active): $rule->{name}\n"; + print "Found RULE $rule->{id} (prio: $rule->{priority}, $dir, $active): $rulename\n"; + + my $print_group = sub { + my ($type, $og) = @_; + my $oname = encode('UTF-8', $og->{name}); + print " FOUND $type GROUP $og->{id}: $oname\n"; + print_objects($ruledb, $og); + }; my ($from, $to, $when, $what, $action) = $ruledb->load_groups($rule); foreach my $og (@$from) { - print " FOUND FROM GROUP $og->{id}: $og->{name}\n"; - print_objects($ruledb, $og); + $print_group->("FROM", $og); } foreach my $og (@$to) { - print " FOUND TO GROUP $og->{id}: $og->{name}\n"; - print_objects($ruledb, $og); + $print_group->("TO", $og); } foreach my $og (@$when) { - print " FOUND WHEN GROUP $og->{id}: $og->{name}\n"; - print_objects($ruledb, $og); + $print_group->("WHEN", $og); } foreach my $og (@$what) { - print " FOUND WHAT GROUP $og->{id}: $og->{name}\n"; - print_objects($ruledb, $og); + $print_group->("WHAT", $og); } foreach my $og (@$action) { - print " FOUND ACTION GROUP $og->{id}: $og->{name}\n"; - print_objects($ruledb, $og); + $print_group->("ACTION", $og); } } -- 2.30.2