Added locking
authorJamie Cameron <jcameron@webmin.com>
Mon, 4 Feb 2008 05:41:28 +0000 (05:41 +0000)
committerJamie Cameron <jcameron@webmin.com>
Mon, 4 Feb 2008 05:41:28 +0000 (05:41 +0000)
ldap-useradmin/CHANGELOG
ldap-useradmin/batch_exec.cgi
ldap-useradmin/ldap-useradmin-lib.pl
ldap-useradmin/save_group.cgi
ldap-useradmin/save_user.cgi

index f610968..08b7d38 100644 (file)
@@ -53,3 +53,5 @@ UID and GID allocation is now done by querying the LDAP server for specific IDs,
 All Samba attributes are removed when Samba access is disabled for a user.
 ---- Changes since 1.380 ----
 Added access control options to prevent use of the same UID or GID.
+---- Changes since 1.390 ----
+Added locking to prevent concurrent writes to the LDAP database, to prevent UID collisions.
index f0ef275..7b7bc7c 100755 (executable)
@@ -31,6 +31,7 @@ elsif ($in{'source'} == 2) {
 $ldap = &ldap_connect();
 $schema = $ldap->schema();
 $pft = $schema->attribute("shadowLastChange") ? 2 : 0;
+&lock_user_files();
 
 # Work out a good base UID for new users
 $newuid = $mconfig{'base_uid'};
@@ -532,6 +533,7 @@ LINE: foreach $line (split(/[\r\n]+/, $data)) {
                }
        }
 print "</pre>\n";
+&unlock_user_files();
 &webmin_log("batch", undef, $in{'source'} == 1 ? $in{'local'} : undef,
            { 'created' => $created, 'modified' => $modified,
              'deleted' => $deleted, 'lnum' => $lnum } );
index 5129044..96ab5fd 100644 (file)
@@ -532,11 +532,16 @@ sub set_group_envs
 return &useradmin::set_group_envs(@_);
 }
 
-# Does nothing, because no LDAP locking is needed
-sub lock_user_files { }
+# Locks a dummy file, to indicate that the DB is in use
+sub lock_user_files
+{
+&lock_file("$module_config_directory/ldapdb");
+}
 
-# Does nothing, because no LDAP locking is needed
-sub unlock_user_files { }
+sub unlock_user_files
+{
+&unlock_file("$module_config_directory/ldapdb");
+}
 
 # split_props(text, &user)
 sub split_props
index bc5f9e8..0a6256e 100755 (executable)
@@ -7,6 +7,7 @@ require './ldap-useradmin-lib.pl';
 &ReadParse();
 $ldap = &ldap_connect();
 $schema = $ldap->schema();
+&lock_user_files();
 
 if (!$in{'new'}) {
        # Get existing group
@@ -309,6 +310,7 @@ if ($in{'others'}) {
 delete($in{'pass'});
 delete($in{'encpass'});
 $ldap->unbind();
+&unlock_user_files();
 &webmin_log(!$in{'new'} ? 'modify' : 'create', 'group', $group, \%in);
 
 # Bounce back to the list
index 8f660ea..2b9df24 100755 (executable)
@@ -7,6 +7,7 @@ use Time::Local;
 &ReadParse();
 $ldap = &ldap_connect();
 $schema = $ldap->schema();
+&lock_user_files();
 if (!$in{'new'}) {
        # Get existing user
        $rv = $ldap->search(base => $in{'dn'},
@@ -682,6 +683,7 @@ else {
 $ldap->unbind();
 delete($in{'pass'});
 delete($in{'passmode'});
+&unlock_user_files();
 &webmin_log(!$in{'new'} ? 'modify' : 'create', 'user', $user, \%in);
 &redirect($in{'return'} || "");