smbd: Factor out remove_stale_share_mode_entries
[mat/samba.git] / source3 / locking / share_mode_lock.c
index d45b450d94860dd8e72c179dfb9b88ea09833722..5d7a08ca4bf018232aba3a6f41dcc08967afd0f1 100644 (file)
@@ -46,6 +46,7 @@
 #include "messages.h"
 #include "util_tdb.h"
 #include "../librpc/gen_ndr/ndr_open_files.h"
+#include "source3/lib/dbwrap/dbwrap_watch.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_LOCKING
@@ -76,6 +77,8 @@ static bool locking_init_internal(bool read_only)
        if (!posix_locking_init(read_only))
                return False;
 
+       dbwrap_watch_db(lock_db, server_messaging_context());
+
        return True;
 }
 
@@ -118,6 +121,7 @@ static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
 {
        struct share_mode_data *d;
        enum ndr_err_code ndr_err;
+       uint32_t i;
        DATA_BLOB blob;
 
        d = talloc(mem_ctx, struct share_mode_data);
@@ -137,6 +141,14 @@ static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
                goto fail;
        }
 
+       /*
+        * Initialize the values that are [skip] in the idl. The NDR code does
+        * not initialize them.
+        */
+
+       for (i=0; i<d->num_share_modes; i++) {
+               d->share_modes[i].stale = false;
+       }
        d->modified = false;
        d->fresh = false;
 
@@ -165,6 +177,8 @@ static TDB_DATA unparse_share_modes(struct share_mode_data *d)
                NDR_PRINT_DEBUG(share_mode_data, d);
        }
 
+       remove_stale_share_mode_entries(d);
+
        if (d->num_share_modes == 0) {
                DEBUG(10, ("No used share mode found\n"));
                return make_tdb_data(NULL, 0);