diff options
-rw-r--r-- | source3/smbd/globals.h | 4 | ||||
-rw-r--r-- | source3/smbd/smbXsrv_open.c | 73 |
2 files changed, 77 insertions, 0 deletions
diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h index 6ead9626a5..90e9ab4dd7 100644 --- a/source3/smbd/globals.h +++ b/source3/smbd/globals.h @@ -457,6 +457,10 @@ NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn, struct GUID create_guid, NTTIME now, struct smbXsrv_open **_open); +struct smbXsrv_open_global0; +NTSTATUS smbXsrv_open_global_traverse( + int (*fn)(struct smbXsrv_open_global0 *, void *), + void *private_data); struct smbd_smb2_request { struct smbd_smb2_request *prev, *next; diff --git a/source3/smbd/smbXsrv_open.c b/source3/smbd/smbXsrv_open.c index be39cbc397..2c2798b5c8 100644 --- a/source3/smbd/smbXsrv_open.c +++ b/source3/smbd/smbXsrv_open.c @@ -1277,3 +1277,76 @@ NTSTATUS smb2srv_open_recreate(struct smbXsrv_connection *conn, *_open = op; return NT_STATUS_OK; } + + +struct smbXsrv_open_global_traverse_state { + int (*fn)(struct smbXsrv_open_global0 *, void *); + void *private_data; +}; + +static int smbXsrv_open_global_traverse_fn(struct db_record *rec, void *data) +{ + int ret = -1; + struct smbXsrv_open_global_traverse_state *state = + (struct smbXsrv_open_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_open_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_open_globalB); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + DEBUG(1,("Invalid record in smbXsrv_open_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_open_global.tdb:" + "key '%s' unsuported version - %d\n", + hex_encode_talloc(frame, key.dptr, key.dsize), + (int)global_blob.version)); + goto done; + } + + global_blob.info.info0->db_rec = rec; + ret = state->fn(global_blob.info.info0, state->private_data); +done: + TALLOC_FREE(frame); + return ret; +} + +NTSTATUS smbXsrv_open_global_traverse( + int (*fn)(struct smbXsrv_open_global0 *, void *), + void *private_data) +{ + + NTSTATUS status; + int count = 0; + struct smbXsrv_open_global_traverse_state state = { + .fn = fn, + .private_data = private_data, + }; + + become_root(); + status = smbXsrv_open_global_init(); + if (!NT_STATUS_IS_OK(status)) { + unbecome_root(); + DEBUG(0, ("Failed to initialize open_global: %s\n", + nt_errstr(status))); + return status; + } + + status = dbwrap_traverse_read(smbXsrv_open_global_db_ctx, + smbXsrv_open_global_traverse_fn, + &state, + &count); + unbecome_root(); + + return status; +} |