summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/smbd/globals.h4
-rw-r--r--source3/smbd/smbXsrv_session.c71
2 files changed, 75 insertions, 0 deletions
diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h
index 107d338337..6509dda37c 100644
--- a/source3/smbd/globals.h
+++ b/source3/smbd/globals.h
@@ -396,6 +396,10 @@ NTSTATUS smb2srv_session_table_init(struct smbXsrv_connection *conn);
NTSTATUS smb2srv_session_lookup(struct smbXsrv_connection *conn,
uint64_t session_id, NTTIME now,
struct smbXsrv_session **session);
+struct smbXsrv_session_global0;
+NTSTATUS smbXsrv_session_global_traverse(
+ int (*fn)(struct smbXsrv_session_global0 *, void *),
+ void *private_data);
struct tevent_req *smb2srv_session_close_previous_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct smbXsrv_connection *conn,
diff --git a/source3/smbd/smbXsrv_session.c b/source3/smbd/smbXsrv_session.c
index f31d85b6a5..f3072ee91b 100644
--- a/source3/smbd/smbXsrv_session.c
+++ b/source3/smbd/smbXsrv_session.c
@@ -1524,3 +1524,74 @@ NTSTATUS smb2srv_session_lookup(struct smbXsrv_connection *conn,
return smbXsrv_session_local_lookup(table, local_id, now, session);
}
+
+struct smbXsrv_session_global_traverse_state {
+ int (*fn)(struct smbXsrv_session_global0 *, void *);
+ void *private_data;
+};
+
+static int smbXsrv_session_global_traverse_fn(struct db_record *rec, void *data)
+{
+ int ret = -1;
+ struct smbXsrv_session_global_traverse_state *state =
+ (struct smbXsrv_session_global_traverse_state*)data;
+ TDB_DATA key = dbwrap_record_get_key(rec);
+ TDB_DATA val = dbwrap_record_get_value(rec);
+ DATA_BLOB blob = data_blob_const(val.dptr, val.dsize);
+ struct smbXsrv_session_globalB global_blob;
+ enum ndr_err_code ndr_err;
+ TALLOC_CTX *frame = talloc_stackframe();
+
+ ndr_err = ndr_pull_struct_blob(&blob, frame, &global_blob,
+ (ndr_pull_flags_fn_t)ndr_pull_smbXsrv_session_globalB);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ DEBUG(1,("Invalid record in smbXsrv_session_global.tdb:"
+ "key '%s' ndr_pull_struct_blob - %s\n",
+ hex_encode_talloc(frame, key.dptr, key.dsize),
+ ndr_errstr(ndr_err)));
+ goto done;
+ }
+
+ if (global_blob.version != SMBXSRV_VERSION_0) {
+ DEBUG(1,("Invalid record in smbXsrv_session_global.tdb:"
+ "key '%s' unsuported version - %d\n",
+ hex_encode_talloc(frame, key.dptr, key.dsize),
+ (int)global_blob.version));
+ goto done;
+ }
+
+ ret = state->fn(global_blob.info.info0, state->private_data);
+done:
+ TALLOC_FREE(frame);
+ return ret;
+}
+
+NTSTATUS smbXsrv_session_global_traverse(
+ int (*fn)(struct smbXsrv_session_global0 *, void *),
+ void *private_data)
+{
+
+ NTSTATUS status;
+ int count = 0;
+ struct smbXsrv_session_global_traverse_state state = {
+ .fn = fn,
+ .private_data = private_data,
+ };
+
+ become_root();
+ status = smbXsrv_session_global_init();
+ if (!NT_STATUS_IS_OK(status)) {
+ unbecome_root();
+ DEBUG(0, ("Failed to initialize session_global: %s\n",
+ nt_errstr(status)));
+ return status;
+ }
+
+ status = dbwrap_traverse_read(smbXsrv_session_global_db_ctx,
+ smbXsrv_session_global_traverse_fn,
+ &state,
+ &count);
+ unbecome_root();
+
+ return status;
+}