mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-12 16:32:01 -05: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:
1 parent
cdd2e9caff
commit
0880d030ae
1 file changed
+2
-2
@@ -331,7 +331,7 @@ def set_directive(filename, directive, value, quotes=True, separator=' '):
|
||||
fd = open(filename)
|
||||
newfile = []
|
||||
for line in fd:
|
||||
if directive in line:
|
||||
if line.lstrip().startswith(directive):
|
||||
valueset = True
|
||||
if value is not None:
|
||||
if quotes:
|
||||
@@ -359,7 +359,7 @@ def get_directive(filename, directive, separator=' '):
|
||||
"""
|
||||
fd = open(filename, "r")
|
||||
for line in fd:
|
||||
if directive in line:
|
||||
if line.lstrip().startswith(directive):
|
||||
line = line.strip()
|
||||
result = line.split(separator, 1)[1]
|
||||
result = result.strip('"')
|
||||
|
||||
Reference in new issue
Block a user