Module: check_mk
Branch: master
Commit: 09ab950226c905bd4ace5a69432c7c8ee53f7506
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=09ab950226c905…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Dec 11 09:20:16 2013 +0100
FIX Trying to prevent read/write conflicts with a large user base
When having a large amount of users, it might happen, that the user
configuration files are read while they are written e.g. by an automated
LDAP sync or some other modification to the user database. With bad
timing, the file could be read while being incomplete which might result
in syntax errors or similar unexpected situations. This changes the way
the files are being written to a more save way.
---
.werks/309 | 13 +++++++++++++
ChangeLog | 1 +
web/htdocs/userdb.py | 9 ++++++---
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/.werks/309 b/.werks/309
new file mode 100644
index 0000000..6803741
--- /dev/null
+++ b/.werks/309
@@ -0,0 +1,13 @@
+Title: Trying to prevent read/write conflicts with a large user base
+Level: 1
+Component: wato
+Version: 1.2.3i8
+Date: 1386749884
+Class: fix
+
+When having a large amount of users, it might happen, that the user
+configuration files are read while they are written e.g. by an automated
+LDAP sync or some other modification to the user database. With bad
+timing, the file could be read while being incomplete which might result
+in syntax errors or similar unexpected situations. This changes the way
+the files are being written to a more save way.
diff --git a/ChangeLog b/ChangeLog
index a8429ce..d23dc38 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,7 @@
* 0057 FIX: Fix exception in WATO host editor on custom tag without topic...
* 0241 FIX: Improved sorting of WATO folders in dropdown menu...
* 0019 FIX: Fixed wording in WATO rule for MSSQL check
+ * 0309 FIX: Trying to prevent read/write conflicts with a large user base...
Reporting & Availability:
* 0018 New option for displaying a legend for the colors used in the timeline...
diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index 43ad80b..55905d1 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -392,27 +392,29 @@ def save_users(profiles):
for p, val in profile.items()
if p in multisite_keys +
multisite_attributes(profile.get('connector'))])
- filename = root_dir + "contacts.mk"
+ filename = root_dir + "contacts.mk.new"
# Check_MK's monitoring contacts
out = create_user_file(filename, "w")
out.write("# Written by Multisite UserDB\n# encoding: utf-8\n\n")
out.write("contacts.update(\n%s\n)\n" % pprint.pformat(contacts))
out.close()
+ os.rename(filename, filename[:-4])
# Users with passwords for Multisite
make_nagios_directory(multisite_dir)
- filename = multisite_dir + "users.mk"
+ filename = multisite_dir + "users.mk.new"
out = create_user_file(filename, "w")
out.write("# Written by Multisite UserDB\n# encoding: utf-8\n\n")
out.write("multisite_users = \\\n%s\n" % pprint.pformat(users))
out.close()
+ os.rename(filename, filename[:-4])
# Execute user connector save hooks
hook_save(profiles)
# Write out the users serials
- serials_file = '%s/auth.serials' % os.path.dirname(defaults.htpasswd_file)
+ serials_file = '%s/auth.serials.new' %
os.path.dirname(defaults.htpasswd_file)
out = create_user_file(serials_file, "w")
def encode_utf8(value):
if type(value) == unicode:
@@ -422,6 +424,7 @@ def save_users(profiles):
for user_id, user in profiles.items():
out.write('%s:%d\n' % (encode_utf8(user_id), user.get('serial',
0)))
out.close()
+ os.rename(serials_file, serials_file[:-4])
# Write user specific files
for id, user in profiles.items():