s3: fix the fix for bug #6195 - dont let smbd child processes panic
authorMichael Adam <obnox@samba.org>
Wed, 1 Apr 2009 10:23:07 +0000 (12:23 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 1 Apr 2009 10:26:36 +0000 (12:26 +0200)
This patch makes sure the original and temporary TDBs are closed
_before_ the rename. Originally, the open TDB was renamed, and so
the name passdb.tdb.tmp stayed around in the db context. Hence
upon client connect, the smbd children died because reinit_after_fork()
calling tdb_reopen_all() would try to reopen passdb.tdb.tmp which
existed no longer...

Michael

source3/passdb/pdb_tdb.c

index 1060733df494bca98fb51f263b3e0c0d390d0f98..6c49eb1dc28bd2b2985dfe99e69e23f03c284bcf 100644 (file)
@@ -250,6 +250,11 @@ static bool tdbsam_convert_backup(const char *dbname, struct db_context **pp_db)
                smb_panic("tdbsam_convert_backup: orig commit failed\n");
        }
 
+       /* be sure to close the DBs _before_ renaming the file */
+
+       TALLOC_FREE(orig_db);
+       TALLOC_FREE(tmp_db);
+
        /* This is safe from other users as we know we're
         * under a mutex here. */
 
@@ -262,13 +267,22 @@ static bool tdbsam_convert_backup(const char *dbname, struct db_context **pp_db)
        }
 
        TALLOC_FREE(frame);
-       TALLOC_FREE(orig_db);
+
+       /* re-open the converted TDB */
+
+       orig_db = db_open(NULL, dbname, 0,
+                         TDB_DEFAULT, O_CREAT|O_RDWR, 0600);
+       if (orig_db == NULL) {
+               DEBUG(0, ("tdbsam_convert_backup: Failed to re-open "
+                         "converted passdb TDB [%s]\n", dbname));
+               return false;
+       }
 
        DEBUG(1, ("tdbsam_convert_backup: updated %s file.\n",
                dbname ));
 
        /* Replace the global db pointer. */
-       *pp_db = tmp_db;
+       *pp_db = orig_db;
        return true;
 
   cancel: