File 0002-Improve-ACL-rule-quoting-bsc-1042963.patch of Package hawk.5195
From 61ea57f07b07f8f66cb6c0b9f191b2022dc27278 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20Gr=C3=B6nlund?= <krig@koru.se>
Date: Thu, 22 Jun 2017 18:30:36 +0200
Subject: [PATCH] Improve ACL rule quoting (bsc#1042963)
---
hawk/app/models/cib_object.rb | 13 +++++++++++++
hawk/app/models/location.rb | 15 ---------------
hawk/app/models/role.rb | 20 ++++++++++----------
3 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/hawk/app/models/cib_object.rb b/hawk/app/models/cib_object.rb
index 90d5ef5d..66fc141f 100644
--- a/hawk/app/models/cib_object.rb
+++ b/hawk/app/models/cib_object.rb
@@ -69,6 +69,19 @@ class CibObject
create_or_update
end
+ # TODO(should): Don't add quotes if unnecessary (e.g. no whitespace in val)
+ def crm_quote(str)
+ if str.index("'")
+ "\"#{str}\""
+ else
+ "'#{str}'"
+ end
+ end
+
+ def unquotable?(str)
+ str.index("'") && str.index('"')
+ end
+
class << self
# Check whether anything with the given ID exists, or for a specific
diff --git a/hawk/app/models/location.rb b/hawk/app/models/location.rb
index b7f7dd77..65804ae3 100644
--- a/hawk/app/models/location.rb
+++ b/hawk/app/models/location.rb
@@ -192,21 +192,6 @@ class Location < Constraint
private
- # TODO(must): Move this somewhere else and reuse in other models
- # TODO(should): Don't add quotes if unnecessary (e.g. no whitespace in val)
- def crm_quote(str)
- if str.index("'")
- "\"#{str}\""
- else
- "'#{str}'"
- end
- end
-
- # TODO(must): As above, move this elsewhere for reuse
- def unquotable?(str)
- str.index("'") && str.index('"')
- end
-
# Note: caller must ensure valid rule before calling this
def shell_syntax
cmd = "location #{@id} "
diff --git a/hawk/app/models/role.rb b/hawk/app/models/role.rb
index c0eb7230..43a598a7 100644
--- a/hawk/app/models/role.rb
+++ b/hawk/app/models/role.rb
@@ -106,16 +106,16 @@ class Role < CibObject
private
def shell_syntax
- cmd = "role #{@id}"
- @rules.each do |rule|
- cmd += " #{rule[:right]} "
- cmd += " tag:#{rule[:tag]}" if rule[:tag] && !rule[:tag].empty?
- cmd += " ref:#{rule[:ref]}" if rule[:ref] && !rule[:ref].empty?
- cmd += " xpath:#{rule[:xpath]}" if rule[:xpath] && !rule[:xpath].empty?
- cmd += " attribute:#{rule[:attribute]}" if rule[:attribute] && !rule[:attribute].empty?
- end
- Rails.logger.debug(cmd)
- cmd
+ [].tap do |cmd|
+ cmd.push "role #{@id}"
+ @rules.each do |rule|
+ cmd.push rule[:right]
+ cmd.push crm_quote("tag:#{rule[:tag]}") unless rule[:tag].blank?
+ cmd.push crm_quote("ref:#{rule[:ref]}") unless rule[:ref].blank?
+ cmd.push crm_quote("xpath:#{rule[:xpath]}") unless rule[:xpath].blank?
+ cmd.push crm_quote("attribute:#{rule[:attribute]}") unless rule[:attribute].blank?
+ end
+ end.join(' ')
end
end
--
2.13.1