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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id DC22B9376D for ; Fri, 7 Apr 2023 15:43:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4D7FD1A788 for ; Fri, 7 Apr 2023 15:43:09 +0200 (CEST) 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 ; Fri, 7 Apr 2023 15:43:07 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3D1E746451 for ; Fri, 7 Apr 2023 15:43:07 +0200 (CEST) From: Leo Nunner To: pmg-devel@lists.proxmox.com Date: Fri, 7 Apr 2023 15:42:52 +0200 Message-Id: <20230407134258.199691-7-l.nunner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230407134258.199691-1-l.nunner@proxmox.com> References: <20230407134258.199691-1-l.nunner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.126 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 6/8] feature: match groups: parse field into objects 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: Fri, 07 Apr 2023 13:43:39 -0000 Parse the MatchGroup value from the databsae into the 'and' property of our abstraction objects. We are skipping this step for 'action' objects. A function was added to update the MatchGroup value for a specific object-rule relation. Signed-off-by: Leo Nunner --- src/PMG/API2/ObjectGroupHelpers.pm | 1 + src/PMG/RuleCache.pm | 4 +++- src/PMG/RuleDB.pm | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/PMG/API2/ObjectGroupHelpers.pm b/src/PMG/API2/ObjectGroupHelpers.pm index c3e6448..9bedce2 100644 --- a/src/PMG/API2/ObjectGroupHelpers.pm +++ b/src/PMG/API2/ObjectGroupHelpers.pm @@ -51,6 +51,7 @@ sub format_object_group { name => $og->{name}, info => $og->{info}, negate => $og->{negate}, + 'and' => $og->{and}, }; } return $res; diff --git a/src/PMG/RuleCache.pm b/src/PMG/RuleCache.pm index 04e35da..9a531ef 100644 --- a/src/PMG/RuleCache.pm +++ b/src/PMG/RuleCache.pm @@ -56,7 +56,7 @@ sub new { my ($from, $to, $when, $what, $action); my $sth1 = $dbh->prepare( - "SELECT Objectgroup_ID, Grouptype, Negate FROM RuleGroup " . + "SELECT Objectgroup_ID, Grouptype, Negate, MatchGroup FROM RuleGroup " . "where RuleGroup.Rule_ID = '$ruleid' " . "ORDER BY Grouptype, Objectgroup_ID"); @@ -65,6 +65,7 @@ sub new { my $gtype = $ref1->{grouptype}; my $groupid = $ref1->{objectgroup_id}; my $negate = $ref1->{negate}; + my $and = $ref1->{matchgroup}; # emtyp groups differ from non-existent groups! @@ -93,6 +94,7 @@ sub new { if ($gtype != 4) { # it doesn't make any sense to negate actions $obj->{negate} = $negate; + $obj->{and} = $and; } if ($gtype == 0) { #from diff --git a/src/PMG/RuleDB.pm b/src/PMG/RuleDB.pm index 98beda3..dc2be20 100644 --- a/src/PMG/RuleDB.pm +++ b/src/PMG/RuleDB.pm @@ -107,7 +107,7 @@ sub load_groups { my $sth = $self->{dbh}->prepare( "SELECT RuleGroup.Grouptype, Objectgroup.ID, " . - "Objectgroup.Name, Objectgroup.Info, Negate " . + "Objectgroup.Name, Objectgroup.Info, Negate, MatchGroup " . "FROM Rulegroup, Objectgroup " . "WHERE Rulegroup.Rule_ID = ? and " . "Rulegroup.Objectgroup_ID = Objectgroup.ID " . @@ -125,6 +125,7 @@ sub load_groups { if ($ref->{'grouptype'} != 4) { # this doesn't make any sense for actions $og->{negate} = $ref->{negate}; + $og->{and} = $ref->{matchgroup}; } if ($ref->{'grouptype'} == 0) { #from @@ -797,6 +798,24 @@ sub rule_set_group_setting_negate { return 1; } +sub rule_set_group_setting_matchgroup { + my ($self, $value, $ruleid, $groupid, $gtype_str) = @_; + + my $gtype = $grouptype_hash->{$gtype_str} // + die "unknown group type '$gtype_str'\n"; + + defined($ruleid) || die "undefined rule id: ERROR"; + defined($groupid) || die "undefined group id: ERROR"; + defined($gtype) || die "undefined group type: ERROR"; + + my $sth = $self->{dbh}->prepare("UPDATE RuleGroup SET MatchGroup = ? " . + "WHERE Objectgroup_ID = ? and Rule_ID = ? and Grouptype = ?"); + + $sth->execute($value, $groupid, $ruleid, $gtype); + + return 1; +} + sub load_rule { my ($self, $id) = @_; -- 2.30.2