Module: check_mk
Branch: master
Commit: 62a45888464b1c2b5740aab8d241b6f5c174f116
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=62a45888464b1c…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Dec 5 17:18:25 2014 +0100
#1706 FIX Fix file permissions when installing MKPs to 0644 or 0755
When installing MKP packages that contain files with invalid permissions
then fix these when installing the packages.
---
.bugs/763 | 6 ++++--
.bugs/784 | 6 ++++--
.werks/1706 | 10 ++++++++++
ChangeLog | 1 +
modules/packaging.py | 51 +++++++++++++++++++++++++++++---------------------
5 files changed, 49 insertions(+), 25 deletions(-)
diff --git a/.bugs/763 b/.bugs/763
index 5186307..1881842 100644
--- a/.bugs/763
+++ b/.bugs/763
@@ -1,9 +1,9 @@
Title: Duplicate Check on Cisco 4500
Component: checks
-State: open
+Class: nastiness
+State: done
Date: 2012-06-04 12:20:55
Targetversion: 1.4.0
-Class: nastiness
Generating Nagios configuration...Configuration Error: ERROR:
Duplicate service description 'Temperature Chassis Temperature Sensor'
@@ -29,3 +29,5 @@ Precedence should be:
We could do: the cmk -I outputs a warning on duplicate (automatically
ignored) services. WATO introduces a new section: "Duplicate Services"
that simply displays the ignored services.
+
+2014-12-05 17:01:29: changed state open -> done
diff --git a/.bugs/784 b/.bugs/784
index 08d50dc..55f9ee5 100644
--- a/.bugs/784
+++ b/.bugs/784
@@ -1,9 +1,9 @@
Title: mkp install should fix file permissions
Component: core
-State: open
+Class: nastiness
+State: done
Date: 2012-07-25 17:42:13
Targetversion: future
-Class: nastiness
When installing the cmc_lcp checks from Bastian from the Exchange into
GIT, then all files are not group/world readable. The MKP installer should
@@ -11,3 +11,5 @@ automatically fix file permissions.
Resolution: add a new column to packages_parts in packaging.py with the
correct target permission for that folder.
+
+2014-12-05 17:17:35: changed state open -> done
diff --git a/.werks/1706 b/.werks/1706
new file mode 100644
index 0000000..0ea1d98
--- /dev/null
+++ b/.werks/1706
@@ -0,0 +1,10 @@
+Title: Fix file permissions when installing MKPs to 0644 or 0755
+Level: 1
+Component: core
+Compatible: compat
+Version: 1.2.5i7
+Date: 1417796257
+Class: fix
+
+When installing MKP packages that contain files with invalid permissions
+then fix these when installing the packages.
diff --git a/ChangeLog b/ChangeLog
index ed7ab9d..cc45988 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
* 1624 FIX: Remove illegal characters from service descriptions of active checks...
* 1628 FIX: Remove trailing backslashes from service descriptions...
* 1649 FIX: Check_MK inventory service has been renamed to Check_MK Discovery...
+ * 1706 FIX: Fix file permissions when installing MKPs to 0644 or 0755...
Checks & Agents:
* 1197 climaveneta_temp: New check for temperature sensors on Climaveneta clima
devices
diff --git a/modules/packaging.py b/modules/packaging.py
index 8a7f115..6808a43 100644
--- a/modules/packaging.py
+++ b/modules/packaging.py
@@ -44,15 +44,15 @@ except:
pass
# in case of local directories (OMD) use those instead
-package_parts = [ (part, title, ldir and ldir or dir) for part, title, dir, ldir in [
- ( "checks", "Checks", checks_dir,
local_checks_dir ),
- ( "notifications", "Notification scripts", notifications_dir,
local_notifications_dir ),
- ( "inventory", "Inventory plugins", inventory_dir,
local_inventory_dir ),
- ( "checkman", "Checks' man pages",
check_manpages_dir, local_check_manpages_dir ),
- ( "agents", "Agents", agents_dir,
local_agents_dir ),
- ( "web", "Multisite extensions", web_dir,
local_web_dir ),
- ( "pnp-templates", "PNP4Nagios templates", pnp_templates_dir,
local_pnp_templates_dir ),
- ( "doc", "Documentation files", doc_dir,
local_doc_dir ),
+package_parts = [ (part, title, perm, ldir and ldir or dir) for part, title, perm, dir,
ldir in [
+ ( "checks", "Checks", 0644, checks_dir,
local_checks_dir ),
+ ( "notifications", "Notification scripts", 0755,
notifications_dir, local_notifications_dir ),
+ ( "inventory", "Inventory plugins", 0644,
inventory_dir, local_inventory_dir ),
+ ( "checkman", "Checks' man pages", 0644,
check_manpages_dir, local_check_manpages_dir ),
+ ( "agents", "Agents", 0755, agents_dir,
local_agents_dir ),
+ ( "web", "Multisite extensions", 0644, web_dir,
local_web_dir ),
+ ( "pnp-templates", "PNP4Nagios templates", 0644,
pnp_templates_dir, local_pnp_templates_dir ),
+ ( "doc", "Documentation files", 0644, doc_dir,
local_doc_dir ),
]]
def packaging_usage():
@@ -166,14 +166,14 @@ def show_package(name, show_info = False):
else:
if opt_verbose:
sys.stdout.write("Files in package %s:\n" % name)
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
files = package["files"].get(part, [])
if len(files) > 0:
sys.stdout.write(" %s%s%s:\n" % (tty_bold, title,
tty_normal))
for f in files:
sys.stdout.write(" %s\n" % f)
else:
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
for fn in package["files"].get(part, []):
sys.stdout.write(dir + "/" + fn + "\n")
@@ -200,7 +200,7 @@ def package_create(args):
"files" : filelists
}
num_files = 0
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
files = unpackaged_files_in_dir(part, dir)
filelists[part] = files
num_files += len(files)
@@ -216,7 +216,7 @@ def package_create(args):
def package_find(_no_args):
first = True
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
files = unpackaged_files_in_dir(part, dir)
if len(files) > 0:
if first:
@@ -243,7 +243,7 @@ def package_release(args):
os.unlink(pacpath)
verbose("Releasing files of package %s into freedom...\n" % pacname)
if opt_verbose:
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
filenames = package["files"].get(part, [])
if len(filenames) > 0:
verbose(" %s%s%s:\n" % (tty_bold, title, tty_normal))
@@ -256,7 +256,7 @@ def package_pack(args):
# Make sure, user is not in data directories of Check_MK
p = os.path.abspath(os.curdir)
- for dir in [var_dir] + [ dir for x,y,dir in package_parts ]:
+ for dir in [var_dir] + [ dir for x,y,perm,dir in package_parts ]:
if p == dir or p.startswith(dir + "/"):
raise PackageException("You are in %s!\n"
"Please leave the directories of Check_MK before
creating\n"
@@ -287,7 +287,7 @@ def package_pack(args):
tar.addfile(info, info_file)
# Now pack the actual files into sub tars
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
filenames = package["files"].get(part, [])
if len(filenames) > 0:
verbose(" %s%s%s:\n" % (tty_bold, title, tty_normal))
@@ -310,7 +310,7 @@ def package_remove(args):
raise PackageException("No such package %s." % pacname)
verbose("Removing package %s...\n" % pacname)
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
filenames = package["files"].get(part, [])
if len(filenames) > 0:
verbose(" %s%s%s\n" % (tty_bold, title, tty_normal))
@@ -345,7 +345,7 @@ def package_install(args):
# Before installing check for conflicts
keep_files = {}
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
packaged = packaged_files_in_dir(part)
keep = []
keep_files[part] = keep
@@ -361,7 +361,7 @@ def package_install(args):
raise PackageException("File conflict: %s already existing." %
path)
# Now install files, but only unpack files explicitely listed
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
filenames = package["files"].get(part, [])
if len(filenames) > 0:
verbose(" %s%s%s:\n" % (tty_bold, title, tty_normal))
@@ -380,9 +380,18 @@ def package_install(args):
break
tardest.write(data)
+ # Fix permissions of extracted files
+ for filename in filenames:
+ path = dir + "/" + filename
+ has_perm = os.stat(path).st_mode & 07777
+ if has_perm != perm:
+ verbose(" Fixing permissions of %s: %04o -> %04o\n" %
(path, has_perm, perm))
+ os.chmod(path, perm)
+
+
# In case of an update remove files from old_package not present in new one
if update:
- for part, title, dir in package_parts:
+ for part, title, perm, dir in package_parts:
filenames = old_package["files"].get(part, [])
keep = keep_files.get(part, [])
for fn in filenames:
@@ -403,7 +412,7 @@ def files_in_dir(part, dir, prefix = ""):
return []
# Handle case where one part-dir lies below another
- taboo_dirs = [ d for p, t, d in package_parts if p != part ]
+ taboo_dirs = [ d for p, t, perm, d in package_parts if p != part ]
if dir in taboo_dirs:
return []