mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Make set_directive and get_directive more strict
When set_directive was used for directive "foo" and the word "foo" was detected anywhere on the line (e.g. in a comment, or in an example), it was overwritten which may potentially lead to wrong line being overwritten. Only match the directives on the beginning of the lines, it is safer. https://fedorahosted.org/freeipa/ticket/3974
This commit is contained in:
committed by
Petr Viktorin
parent
cdd2e9caff
commit
0880d030ae
@@ -331,7 +331,7 @@ def set_directive(filename, directive, value, quotes=True, separator=' '):
|
|||||||
fd = open(filename)
|
fd = open(filename)
|
||||||
newfile = []
|
newfile = []
|
||||||
for line in fd:
|
for line in fd:
|
||||||
if directive in line:
|
if line.lstrip().startswith(directive):
|
||||||
valueset = True
|
valueset = True
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if quotes:
|
if quotes:
|
||||||
@@ -359,7 +359,7 @@ def get_directive(filename, directive, separator=' '):
|
|||||||
"""
|
"""
|
||||||
fd = open(filename, "r")
|
fd = open(filename, "r")
|
||||||
for line in fd:
|
for line in fd:
|
||||||
if directive in line:
|
if line.lstrip().startswith(directive):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
result = line.split(separator, 1)[1]
|
result = line.split(separator, 1)[1]
|
||||||
result = result.strip('"')
|
result = result.strip('"')
|
||||||
|
|||||||
Reference in New Issue
Block a user