TODO later? smbXsrv_open_close_all
authorStefan Metzmacher <metze@samba.org>
Mon, 18 Jun 2012 11:27:19 +0000 (13:27 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 15 Oct 2019 07:36:38 +0000 (09:36 +0200)
source3/smbd/smbXsrv_open.c

index 2be1d54d6ce441505c59482e6ed865b6eea6cea2..d3864962554df4e001b680853a9183c9cb25f713 100644 (file)
@@ -1168,6 +1168,87 @@ NTSTATUS smbXsrv_open_close(struct smbXsrv_open *op, NTTIME now)
        return error;
 }
 
+struct smbXsrv_open_close_all_state {
+       NTTIME now;
+       NTSTATUS first_status;
+       int errors;
+};
+
+static int smbXsrv_open_close_all_callback(struct db_record *local_rec,
+                                          void *private_data);
+
+static NTSTATUS smbXsrv_open_close_all(struct smbXsrv_open_table *table,
+                                      NTTIME now)
+{
+       struct smbXsrv_open_close_all_state state;
+       NTSTATUS status;
+       int count = 0;
+
+       ZERO_STRUCT(state);
+
+       if (table == NULL) {
+               return NT_STATUS_OK;
+       }
+
+       state.now = now;
+
+       status = dbwrap_traverse(table->local.db_ctx,
+                                smbXsrv_open_close_all_callback,
+                                &state, &count);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("smbXsrv_open_close_all: "
+                         "dbwrap_traverse() failed: %s\n",
+                         nt_errstr(status)));
+               return status;
+       }
+
+       if (!NT_STATUS_IS_OK(state.first_status)) {
+               DEBUG(0, ("smbXsrv_open_close_all: "
+                         "count[%d] errors[%d] first[%s]\n",
+                         count, state.errors,
+                         nt_errstr(state.first_status)));
+               return state.first_status;
+       }
+
+       return NT_STATUS_OK;
+}
+
+static int smbXsrv_open_close_all_callback(struct db_record *local_rec,
+                                          void *private_data)
+{
+       struct smbXsrv_open_close_all_state *state =
+               (struct smbXsrv_open_close_all_state *)private_data;
+       TDB_DATA val;
+       void *ptr = NULL;
+       struct smbXsrv_open *op = NULL;
+       NTSTATUS status;
+
+       val = dbwrap_record_get_value(local_rec);
+       if (val.dsize != sizeof(ptr)) {
+               status = NT_STATUS_INTERNAL_ERROR;
+               if (NT_STATUS_IS_OK(state->first_status)) {
+                       state->first_status = status;
+               }
+               state->errors++;
+               return 0;
+       }
+
+       memcpy(&ptr, val.dptr, val.dsize);
+       op = talloc_get_type_abort(ptr, struct smbXsrv_open);
+
+       op->db_rec = local_rec;
+       status = smbXsrv_open_close(op, state->now);
+       if (!NT_STATUS_IS_OK(status)) {
+               if (NT_STATUS_IS_OK(state->first_status)) {
+                       state->first_status = status;
+               }
+               state->errors++;
+               return 0;
+       }
+
+       return 0;
+}
+
 NTSTATUS smb1srv_open_table_init(struct smbXsrv_connection *conn)
 {
        uint32_t max_opens;