From 95b0563817c20bd7d7d82719d8baf8eac2bc9098 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 10 Feb 2011 22:13:42 -0500 Subject: Ensure that file ownership doesn't change when config is updated. Out of the blue update_file() and set_directive() changed file ownership to root:root when it updated some files. This was causing dogtag to break. So grab the owner before opening the file and reset it after closing. ticket 928 --- ipaserver/install/installutils.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ipaserver/install/installutils.py') diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py index 314c26c7..99d1582e 100644 --- a/ipaserver/install/installutils.py +++ b/ipaserver/install/installutils.py @@ -282,6 +282,7 @@ def read_password(user, confirm=True, validate=True): def update_file(filename, orig, subst): if os.path.exists(filename): + st = os.stat(filename) pattern = "%s" % re.escape(orig) p = re.compile(pattern) for line in fileinput.input(filename, inplace=1): @@ -290,6 +291,7 @@ def update_file(filename, orig, subst): else: sys.stdout.write(p.sub(subst, line)) fileinput.close() + os.chown(filename, st.st_uid, st.st_gid) # reset perms return 0 else: print "File %s doesn't exist." % filename @@ -301,6 +303,7 @@ def set_directive(filename, directive, value, quotes=True, separator=' '): This has only been tested with nss.conf """ valueset = False + st = os.stat(filename) fd = open(filename) newfile = [] for line in fd: @@ -322,6 +325,7 @@ def set_directive(filename, directive, value, quotes=True, separator=' '): fd = open(filename, "w") fd.write("".join(newfile)) fd.close() + os.chown(filename, st.st_uid, st.st_gid) # reset perms def get_directive(filename, directive, separator=' '): """ -- cgit