1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

gconftool2: improvements (#4647) (#4666)

* gconftool2: improvements

* added changelog fragment

* typo

* Update changelogs/fragments/4647-gconftool2-command-arg.yaml

Per recommendation from Felix. Danke!

(cherry picked from commit fbff98c5f2)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2022-05-12 12:48:33 +02:00 committed by GitHub
parent a4d8929a7e
commit 2947acb77c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 18 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- gconftool2 - properly escape values when passing them to ``gconftool-2`` (https://github.com/ansible-collections/community.general/pull/4647).

View file

@ -99,45 +99,41 @@ class GConf2Preference(object):
def call(self, call_type, fail_onerr=True):
""" Helper function to perform gconftool-2 operations """
config_source = ''
direct = ''
config_source = []
direct = []
changed = False
out = ''
# If the configuration source is different from the default, create
# the argument
if self.config_source is not None and len(self.config_source) > 0:
config_source = "--config-source " + self.config_source
config_source = ["--config-source", self.config_source]
# If direct is true, create the argument
if self.direct:
direct = "--direct"
direct = ["--direct"]
# Execute the call
cmd = "gconftool-2 "
cmd = ["gconftool-2"]
try:
# If the call is "get", then we don't need as many parameters and
# we can ignore some
if call_type == 'get':
cmd += "--get {0}".format(self.key)
cmd.extend(["--get", self.key])
# Otherwise, we will use all relevant parameters
elif call_type == 'set':
cmd += "{0} {1} --type {2} --{3} {4} \"{5}\"".format(direct,
config_source,
self.value_type,
call_type,
self.key,
self.value)
cmd.extend(direct)
cmd.extend(config_source)
cmd.extend(["--type", self.value_type, "--{3}".format(call_type), self.key, self.value])
elif call_type == 'unset':
cmd += "--unset {0}".format(self.key)
cmd.extend(["--unset", self.key])
# Start external command
rc, out, err = self.ansible.run_command(cmd, use_unsafe_shell=True)
rc, out, err = self.ansible.run_command(cmd)
if len(err) > 0:
if fail_onerr:
self.ansible.fail_json(msg='gconftool-2 failed with '
'error: %s' % (str(err)))
if err and fail_onerr:
self.ansible.fail_json(msg='gconftool-2 failed with '
'error: %s' % (str(err)))
else:
changed = True