[omd-commits] OMD Git: omd: omd: cp/mv use chown instead of seteuid

git version control git at mathias-kettner.de
Thu May 12 11:34:18 CEST 2011


Module:   omd
Branch:   master
Commit:   33a105bdae95d7b9a16776bc1ae32604b1da0824
URL:      http://omdistro.org/projects/omd/repository/revisions/33a105bdae95d7b9a16776bc1ae32604b1da0824

Author:   Mathias Kettner <mk at mathias-kettner.de>
Date:     Thu May 12 11:34:13 2011 +0200
Commiter: Mathias Kettner <mk at mathias-kettner.de>
Date:     Thu May 12 11:34:13 2011 +0200

omd: cp/mv use chown instead of seteuid

---

 packages/omd/omd |   32 ++++++++++++++++++++------------
 1 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/packages/omd/omd b/packages/omd/omd
index c4ba046..7c28140 100644
--- a/packages/omd/omd
+++ b/packages/omd/omd
@@ -691,11 +691,6 @@ def stop_site(sitename):
 # Change site specific information in files originally create from
 # skeleton files. Skip files below tmp/
 def patch_skeleton_files(old, new):
-    # Temporarily change to the new site user/group so that
-    # files created will be owned by the new user and not
-    # by root
-    switch_temp_to_user(new)
-
     skelroot = "/omd/versions/%s/skel" % OMD_VERSION
     os.chdir(skelroot)  # make relative paths
     for dirpath, dirnames, filenames in os.walk("."):
@@ -715,10 +710,6 @@ def patch_skeleton_files(old, new):
                     sys.stderr.write("Error patching template file '%s': %s\n" %
                             (dst, e))
 
-    # Become root again
-    switch_back_to_root()
-
-
 
 def chown_tree(dir, user):
     uid = pwd.getpwnam(user).pw_uid
@@ -729,6 +720,17 @@ def chown_tree(dir, user):
             os.lchown(dirpath + "/" + entry, uid, gid)
 
 
+def try_chown(filename, user):
+    if os.path.exists(filename):
+        try:
+            uid = pwd.getpwnam(user).pw_uid
+            gid = pwd.getpwnam(user).pw_gid
+            os.chown(filename, uid, gid)
+        except Exception, e:
+            sys.stderr.write("Cannot chown %s to %s: %s\n" % (filename, user, e))
+            pass
+
+
 def instantiate_skel(path):
     try:
         t = file(path).read()
@@ -749,7 +751,9 @@ def patch_template_file(src, dst, old, new):
             "###SITE###" : site,
             "###ROOT###" : site_dir(site),
         }
-        file("%s.skel.%s" % (dst, site), "w").write(replace_tags(content, replacements))
+        filename = "%s.skel.%s" % (dst, site)
+        file(filename, "w").write(replace_tags(content, replacements))
+        try_chown(filename, new)
 
     # If old and new skeleton file are identical, then do nothing
     old_orig_path = "%s.skel.%s" % (dst, old) 
@@ -762,8 +766,12 @@ def patch_template_file(src, dst, old, new):
     # Now create a patch from old to new and immediately apply on
     # existing - possibly user modified - file.
     
-    if 0 == os.system("diff -u %s %s | %s/bin/patch --force --backup --forward --silent %s" %
-            (old_orig_path, new_orig_path, site_dir(new), dst)):
+    result = os.system("diff -u %s %s | %s/bin/patch --force --backup --forward --silent %s" %
+            (old_orig_path, new_orig_path, site_dir(new), dst))
+    try_chown(dst, new)
+    try_chown(dst + ".rej", new) 
+    try_chown(dst + ".orig", new)
+    if result == 0:
         sys.stdout.write(good + " Converted      %s\n" % src)
     else:
         # Make conflict resolution interactive - similar to omd update



More information about the omd-commits mailing list