MAPIProxy 2.0 API Documentation

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

Functions
mpm_cache.c File Reference

Cache messages and attachments so we can reduce WAN traffic. More...

`#include "libmapi/libmapi.h"`
`#include "libmapi/libmapi_private.h"`
`#include "mapiproxy/dcesrv_mapiproxy.h"`
`#include "mapiproxy/libmapiproxy/libmapiproxy.h"`
`#include "mapiproxy/modules/mpm_cache.h"`

## Functions
static NTSTATUS | cache_dispatch (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r, struct mapiproxy *mapiproxy)
static void | cache_dump_stream_stat (struct mpm_stream *stream)
static NTSTATUS | cache_exec_sync_cmd (struct mpm_stream *stream)
static uint32_t | cache_find_call_request_index (uint8_t opnum, struct EcDoRpc_MAPI_REQ *mapi_req)
static NTSTATUS | cache_init (struct dcesrv_context *dce_ctx)
static NTSTATUS | cache_pull (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
static NTSTATUS | cache_pull_OpenAttach (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct EcDoRpc_MAPI_REQ mapi_req, struct EcDoRpc *EcDoRpc)
static NTSTATUS | cache_pull_OpenMessage (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct OpenMessage_req request)
static NTSTATUS | cache_pull_OpenStream (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct EcDoRpc_MAPI_REQ mapi_req, struct EcDoRpc *EcDoRpc)
static NTSTATUS | cache_pull_Release (struct dcesrv_call_state *dce_call, struct EcDoRpc *EcDoRpc, uint32_t handle_idx)
static NTSTATUS | cache_push (struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, void *r)
static NTSTATUS | cache_push_OpenAttach (struct dcesrv_call_state *dce_call, struct EcDoRpc_MAPI_REQ mapi_req, struct EcDoRpc_MAPI_REPL mapi_repl, struct EcDoRpc *EcDoRpc)
static NTSTATUS | cache_push_OpenMessage (struct dcesrv_call_state *dce_call, struct EcDoRpc_MAPI_REQ mapi_req, struct EcDoRpc_MAPI_REPL mapi_repl, struct EcDoRpc *EcDoRpc)
static NTSTATUS | cache_push_OpenStream (struct dcesrv_call_state *dce_call, struct EcDoRpc_MAPI_REQ mapi_req, struct EcDoRpc_MAPI_REPL mapi_repl, struct EcDoRpc *EcDoRpc)
static NTSTATUS | cache_push_ReadStream (struct dcesrv_call_state *dce_call, struct EcDoRpc_MAPI_REQ mapi_req, struct EcDoRpc_MAPI_REPL mapi_repl, struct EcDoRpc *EcDoRpc)
NTSTATUS | samba_init_module (void)

## Detailed Description

Cache messages and attachments so we can reduce WAN traffic.

## Function Documentation

static NTSTATUS cache_dispatch | ( | struct dcesrv_call_state * | dce_call,
|  | TALLOC_CTX * | mem_ctx,
|  | void * | r,
|  | struct mapiproxy * | mapiproxy
| ) |  |
| static

Dispatch function.

This function avoids calling dcerpc_ndr_request - understand forwarding client request to remove server - when the client is reading a message/attachment stream available in the cache.

This function can also be used to loop over dcerpc_ndr_request and perform a read-ahead operation.

Parameters

  dce_call | the session context
  mem_ctx | the memory context
  r | pointer on EcDoRpc operation
  mapiproxy | pointer to a mapiproxy structure controlling mapiproxy behavior.

Returns
  NT_STATUS_OK

References cache_dump_stream_stat(), mpm_cache_stream_read(), mpm_cache_stream_reset(), mpm_cache_stream_write(), and mpm_session_cmp().

Referenced by samba_init_module().

static void cache_dump_stream_stat | ( | struct mpm_stream * | stream | ) |
| static

Dump time statistic between OpenStream and Release

This function monitors the effective time required to open, read and close a stream.

Parameters

  stream | the mpm_stream entry

Referenced by cache_dispatch(), and cache_push_ReadStream().

static NTSTATUS cache_exec_sync_cmd | ( | struct mpm_stream * | stream | ) |
| static

1. close the existing FILE *
2. build complete file path
3. replace FILE arguments with complete file path
4. call execve
5. stat the sync'd file
6. open the stream again
7. mark the file as cached

Parameters

  stream | pointer on the mpm_stream entry

References mpm_cache_stream_close(), and mpm_cache_stream_open().

Referenced by cache_push_ReadStream().

static uint32_t cache_find_call_request_index | ( | uint8_t | opnum,
|  | struct EcDoRpc_MAPI_REQ * | mapi_req
| ) |  |
| static

Find the position of the given MAPI call in a serialized MAPI request.

If the request includes a Release call, then request and replies indexes for other calls will mismatch.

Parameters

  opnum | The MAPI opnum to seek
  mapi_req | Pointer to the MAPI request calls array

Returns
  On success, returns the call position, otherwise -1.

Referenced by cache_push().

static NTSTATUS cache_init | ( | struct dcesrv_context * | dce_ctx | ) |
| static

Initialize the cache module and retrieve configuration from smb.conf

Possible smb.conf parameters: mpm_cache:database

Parameters

  dce_ctx | the session context

Returns
  NT_STATUS_OK on success otherwise NT_STATUS_INVALID_PARAMETER, NT_STATUS_NO_MEMORY

References mpm_cache_ldb_createdb().

Referenced by samba_init_module().

static NTSTATUS cache_pull | ( | struct dcesrv_call_state * | dce_call,
|  | TALLOC_CTX * | mem_ctx,
|  | void * | r
| ) |  |
| static

Analyze EcDoRpc MAPI requests

This function loops over EcDoRpc MAPI calls and search for the opnums required by the cache module to monitor Stream traffic properly.

Parameters

  dce_call | the session context
  mem_ctx | the memory context
  r | generic pointer on EcDoRpc operation

Returns
  NT_STATUS_OK

References cache_pull_OpenAttach(), cache_pull_OpenMessage(), cache_pull_OpenStream(), and cache_pull_Release().

Referenced by samba_init_module().

static NTSTATUS cache_pull_OpenAttach | ( | struct dcesrv_call_state * | dce_call,
|  | TALLOC_CTX * | mem_ctx,
|  | struct EcDoRpc_MAPI_REQ | mapi_req,
|  | struct EcDoRpc * | EcDoRpc
| ) |  |
| static

Monitor OpenAttach requests and register an attachment in the mpm_messages list.

This is the first step for attachment registration. This function first ensures the attachment is not already registered, otherwise delete it. It next creates the attachment entry in the global mpm_message structure.

Parameters

  dce_call | pointer to the session context
  mem_ctx | the memory context
  mapi_req | reference to the OpenAttach EcDoRpc_MAPI_REQ entry
  EcDoRpc | pointer to the EcDoRpc operation

Returns
  NT_STATUS_OK on success, otherwise NT_STATUS_NO_MEMORY

References mpm_session_cmp(), and mpm_session_init().

Referenced by cache_pull().

static NTSTATUS cache_pull_OpenMessage | ( | struct dcesrv_call_state * | dce_call,
|  | TALLOC_CTX * | mem_ctx,
|  | struct OpenMessage_req | request
| ) |  |
| static

Monitor OpenMessage requests and register a message in the mpm_messages list.

This is the first step for message registration: set Folder ID and Message ID set the handle to 0xFFFFFFFF Insert the message to the list

Parameters

  dce_call | pointer to the session context
  mem_ctx | the memory context
  request | reference to the OpenMessage request

Returns
  NT_STATUS_OK on success

References mpm_session_cmp(), and mpm_session_init().

Referenced by cache_pull().

static NTSTATUS cache_pull_OpenStream | ( | struct dcesrv_call_state * | dce_call,
|  | TALLOC_CTX * | mem_ctx,
|  | struct EcDoRpc_MAPI_REQ | mapi_req,
|  | struct EcDoRpc * | EcDoRpc
| ) |  |
| static

Monitor OpenStream requests and register a stream in the mpm_streams list.

We are only interested in monitoring streams related to attachments or messages. This is the first step for stream registration:

Look whether this stream inherits from a message or attachment Fill the stream element according to previous statement Add it to the mpm_stream list

Parameters

  dce_call | pointer to the session context
  mem_ctx | the memory context
  mapi_req | reference to the OpenStream MAPI request
  EcDoRpc | pointer to the current EcDoRpc operation

Returns
  NT_STATUS_OK on success, otherwise NT_STATUS_NO_MEMORY

References mpm_session_cmp(), and mpm_session_init().

Referenced by cache_pull().

static NTSTATUS cache_pull_Release | ( | struct dcesrv_call_state * | dce_call,
|  | struct EcDoRpc * | EcDoRpc,
|  | uint32_t | handle_idx
| ) |  |
| static

Track down Release calls and update the mpm_cache global list - removing associated entries.

This function recursively remove child entries whenever necessary.

Parameters

  dce_call | pointer to the session context
  EcDoRpc | pointer to the EcDoRpc operation
  handle_idx | the handle to track down

Returns
  NT_STATUS_OK

References mpm_cache_stream_close(), mpm_session_cmp(), and mpm_session_release().

Referenced by cache_pull().

static NTSTATUS cache_push | ( | struct dcesrv_call_state * | dce_call,
|  | TALLOC_CTX * | mem_ctx,
|  | void * | r
| ) |  |
| static

Analyze EcDoRpc MAPI responses

This function loops over EcDoRpc MAPI calls and search for the opnums required by the cache module to monitor Stream traffic properly.

Parameters

  dce_call | pointer to the session context
  mem_ctx | the memory context
  r | generic pointer on EcDoRpc operation

Returns
  NT_STATUS_OK

References cache_find_call_request_index(), cache_push_OpenAttach(), cache_push_OpenMessage(), cache_push_OpenStream(), and cache_push_ReadStream().

Referenced by samba_init_module().

static NTSTATUS cache_push_OpenAttach | ( | struct dcesrv_call_state * | dce_call,
|  | struct EcDoRpc_MAPI_REQ | mapi_req,
|  | struct EcDoRpc_MAPI_REPL | mapi_repl,
|  | struct EcDoRpc * | EcDoRpc
| ) |  |
| static

Monitor OpenAttach replies and store OpenAttach MAPI handle.

This is the second step for attachment registration:

Seek for a given parent_handle/attachmentID in the mpm_attachments list.

if a match is found (expected) and MAPI retval is set to MAPI_E_SUCCESS, update the handle parameter for the element and commit this attachment in the tdb store.

If retval is different from MAPI_E_SUCCESS, then delete the element.

Parameters

  dce_call | pointer to the session context
  mapi_req | reference to the OpenAttach request entry
  mapi_repl | reference to the OpenAttach MAPI response entry
  EcDoRpc | pointer to the current EcDoRpc operation

Returns
  NT_STATUS_OK

References mpm_cache_ldb_add_attachment(), and mpm_session_cmp().

Referenced by cache_push().

static NTSTATUS cache_push_OpenMessage | ( | struct dcesrv_call_state * | dce_call,
|  | struct EcDoRpc_MAPI_REQ | mapi_req,
|  | struct EcDoRpc_MAPI_REPL | mapi_repl,
|  | struct EcDoRpc * | EcDoRpc
| ) |  |
| static

Monitor OpenMessage replies and store OpenMessage MAPI handle.

This is the second step for message registration:

Seek for a given FolderId/MessageId in the mpm_message list

If a match is found (expected) and MAPI retval is set to MAPI_E_SUCCESS, update the handle field for the element and commit this message in the tdb store.

If retval is different from MAPI_E_SUCCESS, then delete the record

Parameters

  dce_call | pointer to the session context
  mapi_req | reference to the OpenMessage MAPI request entry
  mapi_repl | reference to the OpenMessage MAPI response entry
  EcDoRpc | pointer to the current EcDoRpc operation

Returns
  NT_STATUS_OK

References mpm_cache_ldb_add_message(), and mpm_session_cmp().

Referenced by cache_push().

static NTSTATUS cache_push_OpenStream | ( | struct dcesrv_call_state * | dce_call,
|  | struct EcDoRpc_MAPI_REQ | mapi_req,
|  | struct EcDoRpc_MAPI_REPL | mapi_repl,
|  | struct EcDoRpc * | EcDoRpc
| ) |  |
| static

Monitor OpenStream replies and store the OpenStream MAPI handle.

This is the second step for stream registration:

Seek the parent_handle/PropertyTag couple in the mpm_streams list.

If a match is found (expected) and MAPI retval is set to MAPI_E_SUCCESS, update the handle field and StreamSize parameters for the element and commit this stream in the tdb store.

If retval is different from MAPI_E_SUCCESS, then delete the element.

Parameters

  dce_call | pointer to the session context
  mapi_req | reference to the OpenStream MAPI request entry
  mapi_repl | reference to the OpenStream MAPI response entry
  EcDoRpc | pointer to the current EcDoRpc operation

Returns
  NT_STATUS_OK

References mpm_cache_ldb_add_stream(), and mpm_session_cmp().

Referenced by cache_push().

static NTSTATUS cache_push_ReadStream | ( | struct dcesrv_call_state * | dce_call,
|  | struct EcDoRpc_MAPI_REQ | mapi_req,
|  | struct EcDoRpc_MAPI_REPL | mapi_repl,
|  | struct EcDoRpc * | EcDoRpc
| ) |  |
| static

Monitor ReadStream replies.

This function writes ReadStream data received from remote server and associated to messages or attachments to the opened associated file. This function only writes data if the file is not already cached, otherwise it just returns.

Parameters

  dce_call | pointer to the session context
  mapi_req | reference to the ReadStream MAPI request
  mapi_repl | reference to the ReadStream MAPI reply
  EcDoRpc | pointer to the current EcDoRpc operation

Returns
  NT_STATUS_OK

See Also
  cache_dispatch

References cache_dump_stream_stat(), cache_exec_sync_cmd(), mpm_cache_stream_write(), and mpm_session_cmp().

Referenced by cache_push().

NTSTATUS samba_init_module | ( | void |  | ) |

Entry point for the cache mapiproxy module

Returns
  NT_STATUS_OK on success, otherwise NTSTATUS error

References cache_dispatch(), cache_init(), cache_pull(), and cache_push().

| This content is licensed under the Creative Commons Attribution ShareAlike License v. 3.0: http://creativecommons.org/licenses/by-sa/3.0/