~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to mapiproxy/servers/default/emsmdb/dcesrv_exchange_emsmdb.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
   \brief OpenChange EMSMDB Server implementation
26
26
 */
27
27
 
 
28
#include <sys/time.h>
 
29
 
28
30
#include "mapiproxy/dcesrv_mapiproxy.h"
 
31
#include "mapiproxy/libmapiserver/libmapiserver.h"
29
32
#include "dcesrv_exchange_emsmdb.h"
30
33
 
31
34
struct exchange_emsmdb_session          *emsmdb_session = NULL;
32
35
void                                    *openchange_ldb_ctx = NULL;
33
36
 
 
37
static struct exchange_emsmdb_session *dcesrv_find_emsmdb_session(struct GUID *uuid)
 
38
{
 
39
        struct exchange_emsmdb_session  *session, *found_session = NULL;
 
40
 
 
41
        for (session = emsmdb_session; !found_session && session; session = session->next) {
 
42
                if (GUID_equal(uuid, &session->uuid)) {
 
43
                        found_session = session;
 
44
                }
 
45
        }
 
46
 
 
47
        return found_session;
 
48
}
 
49
 
 
50
/* FIXME: See _unbind below */
 
51
/* static struct exchange_emsmdb_session *dcesrv_find_emsmdb_session_by_server_id(const struct server_id *server_id, uint32_t context_id) */
 
52
/* { */
 
53
/*      struct exchange_emsmdb_session  *session; */
 
54
 
 
55
/*      for (session = emsmdb_session; session; session = session->next) { */
 
56
/*              if (session->session */
 
57
/*                  && session->session->server_id.id == server_id->id && session->session->server_id.id2 == server_id->id2 && session->session->server_id.node == server_id->node */
 
58
/*                  && session->session->context_id == context_id) { */
 
59
/*                      return session; */
 
60
/*              } */
 
61
/*      } */
 
62
 
 
63
/*      return NULL; */
 
64
/* } */
 
65
 
34
66
/**
35
67
   \details exchange_emsmdb EcDoConnect (0x0) function
36
68
 
54
86
        const char                      *cn;
55
87
        const char                      *userDN;
56
88
        char                            *dnprefix;
57
 
        bool                            found = false;
58
89
 
59
90
        DEBUG(3, ("exchange_emsmdb: EcDoConnect (0x0)\n"));
60
91
 
75
106
                *r->out.pcmsPollsMax = 0;
76
107
                *r->out.pcRetry = 0;
77
108
                *r->out.pcmsRetryDelay = 0;
78
 
                r->out.szDisplayName = NULL;
79
 
                r->out.szDNPrefix = NULL;
 
109
                *r->out.szDisplayName = NULL;
 
110
                *r->out.szDNPrefix = NULL;
80
111
                r->out.rgwServerVersion[0] = 0;
81
112
                r->out.rgwServerVersion[1] = 0;
82
113
                r->out.rgwServerVersion[2] = 0;
89
120
                return MAPI_E_LOGON_FAILED;
90
121
        }
91
122
 
92
 
        /* !!! WARNING: MAPISTORE_v2 asks you to change emsmdbp_ctx and deal properly with login_user and username !!!*/
93
 
 
94
123
        /* Step 1. Initialize the emsmdbp context */
95
124
        emsmdbp_ctx = emsmdbp_init(dce_call->conn->dce_ctx->lp_ctx, 
96
125
                                   dcesrv_call_account_name(dce_call),
122
151
        /* Step 5. Retrieve the dinstinguished name of the server */
123
152
        cn = ldb_msg_find_attr_as_string(msg, "cn", NULL);
124
153
        userDN = ldb_msg_find_attr_as_string(msg, "legacyExchangeDN", NULL);
125
 
        dnprefix = (char *)strstr(userDN, cn);
 
154
        dnprefix = strstr(userDN, cn);
126
155
        if (!dnprefix) {
127
156
                talloc_free(emsmdbp_ctx);
128
157
                goto failure;
172
201
        r->out.result = MAPI_E_SUCCESS;
173
202
 
174
203
        /* Search for an existing session and increment ref_count, otherwise create it */
175
 
        for (session = emsmdb_session; session; session = session->next) {
176
 
                if ((mpm_session_cmp(session->session, dce_call) == true)) {
177
 
                        DEBUG(0, ("[exchange_emsmdb]: Increment session ref count for %d\n", 
178
 
                                  session->session->context_id));
179
 
                        mpm_session_increment_ref_count(session->session);
180
 
                        found = true;
181
 
                        break;
182
 
                }
183
 
        }
184
 
 
185
 
        if (found == false) {
 
204
        session = dcesrv_find_emsmdb_session(&handle->wire_handle.uuid);
 
205
        if (session) {
 
206
                DEBUG(0, ("[exchange_emsmdb]: Increment session ref count for %d\n", 
 
207
                          session->session->context_id));
 
208
                mpm_session_increment_ref_count(session->session);
 
209
        }
 
210
        else {
186
211
                /* Step 7. Associate this emsmdbp context to the session */
187
212
                session = talloc((TALLOC_CTX *)emsmdb_session, struct exchange_emsmdb_session);
188
213
                OPENCHANGE_RETVAL_IF(!session, MAPI_E_NOT_ENOUGH_RESOURCES, emsmdbp_ctx);
191
216
                session->session = mpm_session_init((TALLOC_CTX *)emsmdb_session, dce_call);
192
217
                OPENCHANGE_RETVAL_IF(!session->session, MAPI_E_NOT_ENOUGH_RESOURCES, emsmdbp_ctx);
193
218
 
 
219
                session->uuid = handle->wire_handle.uuid;
 
220
 
194
221
                mpm_session_set_private_data(session->session, (void *) emsmdbp_ctx);
195
222
                mpm_session_set_destructor(session->session, emsmdbp_destructor);
196
223
 
231
258
        /* Step 1. Retrieve handle and free if emsmdbp context and session are available */
232
259
        h = dcesrv_handle_fetch(dce_call->context, r->in.handle, DCESRV_HANDLE_ANY);
233
260
        if (h) {
234
 
                for (session = emsmdb_session; session; session = session->next) {
235
 
                        if ((mpm_session_cmp(session->session, dce_call) == true)) {
236
 
                                ret = mpm_session_release(session->session);
237
 
                                if (ret == true) {
238
 
                                        DLIST_REMOVE(emsmdb_session, session);
239
 
                                        DEBUG(5, ("[%s:%d]: Session found and released\n", 
240
 
                                                  __FUNCTION__, __LINE__));
241
 
                                        talloc_free(session);
242
 
                                } else {
243
 
                                        DEBUG(5, ("[%s:%d]: Session found and ref_count decreased\n",
244
 
                                                  __FUNCTION__, __LINE__));
245
 
                                }
246
 
                                break;
247
 
                        }
 
261
                session = dcesrv_find_emsmdb_session(&r->in.handle->uuid);
 
262
                if (session) {
 
263
                        ret = mpm_session_release(session->session);
 
264
                        if (ret == true) {
 
265
                                DLIST_REMOVE(emsmdb_session, session);
 
266
                                DEBUG(5, ("[%s:%d]: Session found and released\n", 
 
267
                                          __FUNCTION__, __LINE__));
 
268
                        } else {
 
269
                                DEBUG(5, ("[%s:%d]: Session found and ref_count decreased\n",
 
270
                                          __FUNCTION__, __LINE__));
 
271
                        }
248
272
                }
 
273
                else {
 
274
                        DEBUG(5, ("  emsmdb_session NOT found\n"));
 
275
                }
249
276
        }
250
277
 
251
278
        r->out.handle->handle_type = 0;
256
283
        return MAPI_E_SUCCESS;
257
284
}
258
285
 
 
286
static bool emsmdbp_fill_notification(TALLOC_CTX *mem_ctx, 
 
287
                                      struct emsmdbp_context *emsmdbp_ctx,
 
288
                                      struct EcDoRpc_MAPI_REPL *mapi_repl,
 
289
                                      struct mapistore_subscription *subscription,
 
290
                                      struct mapistore_notification *notification,
 
291
                                      uint16_t *sizep)
 
292
{
 
293
        bool                    success = true; 
 
294
        struct Notify_repl      *reply;
 
295
        struct emsmdbp_object   *handle_object;
 
296
        struct emsmdbp_object_table *table;
 
297
        struct mapi_handles     *handle_object_handle;
 
298
        enum MAPISTATUS         retval;
 
299
        void                    **data_pointers;
 
300
        DATA_BLOB               *table_row;
 
301
        enum MAPISTATUS         *retvals;
 
302
        uint32_t                contextID, saved_prop_count, prev_instance;
 
303
        enum MAPITAGS           *saved_properties, *previous_row_properties;
 
304
        uint64_t                prev_fid, prev_mid;
 
305
 
 
306
        mapi_repl->opnum = op_MAPI_Notify;
 
307
        reply = &mapi_repl->u.mapi_Notify;
 
308
        reply->LogonId = 0; /* TODO: seems to be always 0 ? */
 
309
 
 
310
        retval = mapi_handles_search(emsmdbp_ctx->handles_ctx, subscription->handle, &handle_object_handle);
 
311
        if (retval) {
 
312
                reply->NotificationType = fnevCriticalError;
 
313
                DEBUG(5, ("notification handle not found\n"));
 
314
                goto end;
 
315
        }
 
316
        retval = mapi_handles_get_private_data(handle_object_handle, (void **) &handle_object);
 
317
        if (retval) {
 
318
                reply->NotificationType = fnevCriticalError;
 
319
                DEBUG(5, ("object not found for notification handle\n"));
 
320
                goto end;
 
321
        }
 
322
 
 
323
        reply->NotificationHandle = subscription->handle;
 
324
        switch (notification->object_type) {
 
325
        case MAPISTORE_MESSAGE:
 
326
                reply->NotificationType = fnevMbit;
 
327
                break;
 
328
        case MAPISTORE_FOLDER:
 
329
                if (notification->parameters.object_parameters.new_message_count) {
 
330
                  reply->NotificationType = fnevTbit;
 
331
                }
 
332
                else {
 
333
                  reply->NotificationType = 0; // FIXME - THIS IS WRONG - IT'S AN INVALID NOTIFICATION TYPE
 
334
                }
 
335
                break;
 
336
        case MAPISTORE_TABLE:
 
337
                reply->NotificationType = fnevTableModified;
 
338
                if (notification->parameters.table_parameters.table_type != MAPISTORE_FOLDER_TABLE) {
 
339
                        reply->NotificationType |= (fnevMbit | fnevSbit);
 
340
                }
 
341
                break;
 
342
        default:
 
343
                reply->NotificationType = fnevCriticalError;
 
344
                DEBUG(5, ("unknown value for notification object type: %d\n", notification->object_type));
 
345
                goto end;
 
346
        }
 
347
 
 
348
        if (notification->object_type == MAPISTORE_TABLE) {
 
349
                table = handle_object->object.table;
 
350
 
 
351
                /* FIXME: here is a hack to update table counters and which would not be needed if the backend had access to the table structure... */
 
352
                if (notification->event == MAPISTORE_OBJECT_CREATED) {
 
353
                        table->denominator++;
 
354
                }
 
355
                else if (notification->event == MAPISTORE_OBJECT_DELETED) {
 
356
                        table->denominator--;
 
357
                        if (table->numerator >= table->denominator) {
 
358
                                table->numerator = table->denominator;
 
359
                        }
 
360
                }
 
361
 
 
362
                if (notification->parameters.table_parameters.table_type == MAPISTORE_FOLDER_TABLE) {
 
363
                        if (notification->event == MAPISTORE_OBJECT_CREATED || notification->event == MAPISTORE_OBJECT_MODIFIED) {
 
364
                                if (notification->parameters.table_parameters.row_id > 0) {
 
365
                                        /* FIXME: this hack enables the fetching of some properties from the previous row */
 
366
                                        saved_prop_count = table->prop_count;
 
367
                                        saved_properties = table->properties;
 
368
                                        previous_row_properties = talloc_array(NULL, enum MAPITAGS, 1);
 
369
                                        previous_row_properties[0] = PR_FID;
 
370
                                        table->properties = previous_row_properties;
 
371
                                        table->prop_count = 1;
 
372
                                        contextID = emsmdbp_get_contextID(handle_object);
 
373
                                        mapistore_table_set_columns(emsmdbp_ctx->mstore_ctx, contextID, handle_object->backend_object, table->prop_count, (enum MAPITAGS *) table->properties);
 
374
                                        data_pointers = emsmdbp_object_table_get_row_props(mem_ctx, emsmdbp_ctx, handle_object,
 
375
                                                                                           notification->parameters.table_parameters.row_id - 1, MAPISTORE_PREFILTERED_QUERY,
 
376
                                                                                           &retvals);
 
377
                                        if (data_pointers) {
 
378
                                                prev_fid = *(uint32_t *) data_pointers[0];
 
379
                                                talloc_free(data_pointers);
 
380
                                        }
 
381
                                        else {
 
382
                                                prev_fid = -1;
 
383
                                        }
 
384
 
 
385
                                        table->prop_count = saved_prop_count;
 
386
                                        table->properties = saved_properties;
 
387
                                        talloc_free(previous_row_properties);
 
388
                                        mapistore_table_set_columns(emsmdbp_ctx->mstore_ctx, contextID, handle_object->backend_object, table->prop_count, (enum MAPITAGS *) table->properties);
 
389
                                }
 
390
                                else {
 
391
                                        prev_fid = 0;
 
392
                                }
 
393
 
 
394
                                table_row = talloc_zero(mem_ctx, DATA_BLOB);
 
395
                                data_pointers = emsmdbp_object_table_get_row_props(mem_ctx, emsmdbp_ctx, handle_object,
 
396
                                                                                   notification->parameters.table_parameters.row_id, MAPISTORE_PREFILTERED_QUERY,
 
397
                                                                                   &retvals);
 
398
                                if (data_pointers) {
 
399
                                        emsmdbp_fill_table_row_blob(mem_ctx, emsmdbp_ctx, table_row, table->prop_count, (enum MAPITAGS *) table->properties, data_pointers, retvals);
 
400
                                        talloc_free(data_pointers);
 
401
                                        talloc_free(retvals);
 
402
                                }
 
403
                                else {
 
404
                                        success = false;
 
405
                                        DEBUG(5, (__location__": no data returned for row, notification ignored\n"));
 
406
                                }
 
407
                        }
 
408
 
 
409
                        /* FIXME: for some reason, TABLE_ROW_MODIFIED and TABLE_ROW_DELETED do not work... */
 
410
                        reply->NotificationData.SearchTableChange.TableEvent = TABLE_CHANGED;
 
411
                        switch (notification->event) {
 
412
                        case MAPISTORE_OBJECT_CREATED:
 
413
                                /* case MAPISTORE_OBJECT_MODIFIED: */
 
414
                                reply->NotificationData.HierarchyTableChange.TableEvent = (notification->event == MAPISTORE_OBJECT_CREATED ? TABLE_ROW_ADDED : TABLE_ROW_MODIFIED);
 
415
                                reply->NotificationData.HierarchyTableChange.HierarchyTableChangeUnion.HierarchyRowAddedNotification.FID = notification->parameters.table_parameters.object_id;
 
416
                                reply->NotificationData.HierarchyTableChange.HierarchyTableChangeUnion.HierarchyRowAddedNotification.InsertAfterFID = prev_fid;
 
417
                                reply->NotificationData.HierarchyTableChange.HierarchyTableChangeUnion.HierarchyRowAddedNotification.Columns = *table_row;
 
418
                                break;
 
419
                        case MAPISTORE_OBJECT_MODIFIED:
 
420
                        case MAPISTORE_OBJECT_DELETED:
 
421
                        case MAPISTORE_OBJECT_COPIED:
 
422
                        case MAPISTORE_OBJECT_MOVED:
 
423
                        case MAPISTORE_OBJECT_NEWMAIL:
 
424
                                break;
 
425
                        /* case MAPISTORE_OBJECT_DELETED: */
 
426
                        /*         reply->NotificationData.HierarchyTableChange.TableEvent = TABLE_ROW_DELETED; */
 
427
                        /*         reply->NotificationData.HierarchyTableChange.HierarchyTableChangeUnion.HierarchyRowDeletedNotification.FID = notification->parameters.table_parameters.object_id; */
 
428
                        /*         break; */
 
429
                        /* default: */
 
430
                        /*         reply->NotificationType = fnevCriticalError; */
 
431
                        /*         DEBUG(5, ("unknown value for notification event: %d\n", notification->event)); */
 
432
                        /*         goto end; */
 
433
                        }
 
434
                }
 
435
                else {
 
436
                        if (notification->event == MAPISTORE_OBJECT_CREATED || notification->event == MAPISTORE_OBJECT_MODIFIED) {
 
437
                                if (notification->parameters.table_parameters.row_id > 0) {
 
438
                                        /* FIXME: this hack enables the fetching of some properties from the previous row */
 
439
                                        saved_prop_count = table->prop_count;
 
440
                                        saved_properties = table->properties;
 
441
                                        previous_row_properties = talloc_array(NULL, enum MAPITAGS, 3);
 
442
                                        previous_row_properties[0] = PR_FID;
 
443
                                        previous_row_properties[1] = PR_MID;
 
444
                                        previous_row_properties[2] = PR_INSTANCE_NUM;
 
445
                                        table->properties = previous_row_properties;
 
446
                                        table->prop_count = 3;
 
447
                                        contextID = emsmdbp_get_contextID(handle_object);
 
448
                                        mapistore_table_set_columns(emsmdbp_ctx->mstore_ctx, contextID, handle_object->backend_object, table->prop_count, (enum MAPITAGS *) table->properties);
 
449
                                        data_pointers = emsmdbp_object_table_get_row_props(mem_ctx, emsmdbp_ctx, handle_object, notification->parameters.table_parameters.row_id - 1, MAPISTORE_PREFILTERED_QUERY, NULL);
 
450
                                        if (data_pointers) {
 
451
                                                prev_fid = *(uint64_t *) data_pointers[0];
 
452
                                                prev_mid = *(uint64_t *) data_pointers[1];
 
453
                                                prev_instance = *(uint32_t *) data_pointers[2];
 
454
                                                talloc_free(data_pointers);
 
455
                                        }
 
456
                                        else {
 
457
                                                prev_fid = -1;
 
458
                                                prev_mid = -1;
 
459
                                                prev_instance = -1;
 
460
                                        }
 
461
 
 
462
                                        table->prop_count = saved_prop_count;
 
463
                                        table->properties = saved_properties;
 
464
                                        talloc_free(previous_row_properties);
 
465
                                        mapistore_table_set_columns(emsmdbp_ctx->mstore_ctx, contextID, handle_object->backend_object, table->prop_count, (enum MAPITAGS *) table->properties);
 
466
                                }
 
467
                                else {
 
468
                                        prev_fid = 0;
 
469
                                        prev_mid = 0;
 
470
                                        prev_instance = 0;
 
471
                                }
 
472
 
 
473
                                table_row = talloc_zero(mem_ctx, DATA_BLOB);
 
474
                                data_pointers = emsmdbp_object_table_get_row_props(mem_ctx, emsmdbp_ctx, handle_object,
 
475
                                                                                   notification->parameters.table_parameters.row_id, MAPISTORE_PREFILTERED_QUERY,
 
476
                                                                                   &retvals);
 
477
                                if (data_pointers) {
 
478
                                        emsmdbp_fill_table_row_blob(mem_ctx, emsmdbp_ctx, table_row, table->prop_count, (enum MAPITAGS *) table->properties, data_pointers, retvals);
 
479
                                        talloc_free(data_pointers);
 
480
                                        talloc_free(retvals);
 
481
                                }
 
482
                                else {
 
483
                                        success = false;
 
484
                                        DEBUG(5, (__location__": no data returned for row, notification ignored\n"));
 
485
                                }
 
486
                        }
 
487
 
 
488
                        /* FIXME: for some reason, TABLE_ROW_MODIFIED and TABLE_ROW_DELETED do not work... */
 
489
                        reply->NotificationData.SearchTableChange.TableEvent = TABLE_CHANGED;
 
490
                        switch (notification->event) {
 
491
                        case MAPISTORE_OBJECT_CREATED:
 
492
                        /* case MAPISTORE_OBJECT_MODIFIED: */
 
493
                                reply->NotificationData.SearchTableChange.TableEvent = (notification->event == MAPISTORE_OBJECT_CREATED ? TABLE_ROW_ADDED : TABLE_ROW_MODIFIED);
 
494
                                reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowAddedNotification.FID = notification->parameters.table_parameters.folder_id;
 
495
                                reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowAddedNotification.MID = notification->parameters.table_parameters.object_id;
 
496
                                reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowAddedNotification.Instance = notification->parameters.table_parameters.instance_id;
 
497
                                reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowAddedNotification.InsertAfterFID = prev_fid;
 
498
                                reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowAddedNotification.InsertAfterMID = prev_mid;
 
499
                                reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowAddedNotification.InsertAfterInstance = prev_instance;
 
500
                                reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowAddedNotification.Columns = *table_row;
 
501
                                break;
 
502
                        /* case MAPISTORE_OBJECT_DELETED: */
 
503
                        /*         reply->NotificationData.SearchTableChange.TableEvent = TABLE_ROW_DELETED; */
 
504
                        /*         reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowDeletedNotification.FID = notification->parameters.table_parameters.folder_id; */
 
505
                        /*         reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowDeletedNotification.MID = notification->parameters.table_parameters.object_id; */
 
506
                        /*         reply->NotificationData.SearchTableChange.ContentsTableChangeUnion.ContentsRowDeletedNotification.Instance = notification->parameters.table_parameters.instance_id; */
 
507
                        /*         break; */
 
508
                        /* default: */
 
509
                        /*         reply->NotificationType = fnevCriticalError; */
 
510
                        /*         DEBUG(5, ("unknown value for notification event: %d\n", notification->event)); */
 
511
                        /*         goto end; */
 
512
                        case MAPISTORE_OBJECT_MODIFIED:
 
513
                        case MAPISTORE_OBJECT_DELETED:
 
514
                        case MAPISTORE_OBJECT_COPIED:
 
515
                        case MAPISTORE_OBJECT_MOVED:
 
516
                        case MAPISTORE_OBJECT_NEWMAIL:
 
517
                                break;
 
518
                        }
 
519
                }
 
520
        }
 
521
        else {
 
522
                switch (notification->event) {
 
523
                case MAPISTORE_OBJECT_NEWMAIL:
 
524
                        reply->NotificationType |= fnevNewMail;
 
525
                        break;
 
526
                case MAPISTORE_OBJECT_CREATED:
 
527
                        reply->NotificationType |= fnevObjectCreated;
 
528
                        break;
 
529
                case MAPISTORE_OBJECT_DELETED:
 
530
                        reply->NotificationType |= fnevObjectDeleted;
 
531
                        break;
 
532
                case MAPISTORE_OBJECT_MODIFIED:
 
533
                        reply->NotificationType |= fnevObjectModified;
 
534
                        break;
 
535
                case MAPISTORE_OBJECT_COPIED:
 
536
                        reply->NotificationType |= fnevObjectCopied;
 
537
                        break;
 
538
                case MAPISTORE_OBJECT_MOVED:
 
539
                        reply->NotificationType |= fnevObjectMoved;
 
540
                        break;
 
541
                default:
 
542
                        reply->NotificationType = fnevCriticalError;
 
543
                        DEBUG(5, ("unknown value for notification event: %d\n", notification->event));
 
544
                        goto end;
 
545
                }
 
546
                if (notification->object_type == MAPISTORE_MESSAGE) {
 
547
                        switch (notification->event) {
 
548
                        case MAPISTORE_OBJECT_NEWMAIL:
 
549
                                reply->NotificationData.NewMailNotification.FID = notification->parameters.object_parameters.folder_id;
 
550
                                reply->NotificationData.NewMailNotification.MID = notification->parameters.object_parameters.object_id;
 
551
                                /* Hack for now */
 
552
                                reply->NotificationData.NewMailNotification.MessageFlags = 0x4;
 
553
                                reply->NotificationData.NewMailNotification.UnicodeFlag = true;
 
554
                                reply->NotificationData.NewMailNotification.MessageClass.lpszW = "IPF.Note";
 
555
                                break;
 
556
                        case MAPISTORE_OBJECT_CREATED:
 
557
                                reply->NotificationData.MessageCreatedNotification.FID = notification->parameters.object_parameters.folder_id;
 
558
                                reply->NotificationData.MessageCreatedNotification.MID = notification->parameters.object_parameters.object_id;
 
559
                                reply->NotificationData.MessageCreatedNotification.TagCount = notification->parameters.object_parameters.tag_count;
 
560
                                if (notification->parameters.object_parameters.tag_count
 
561
                                    && notification->parameters.object_parameters.tag_count != 0xffff) {
 
562
                                        reply->NotificationData.MessageCreatedNotification.NotificationTags.Tags = talloc_memdup(mem_ctx, notification->parameters.object_parameters.tags, notification->parameters.object_parameters.tag_count * sizeof(enum MAPITAGS));
 
563
                                }
 
564
                                else {
 
565
                                        reply->NotificationData.MessageCreatedNotification.NotificationTags.Tags = NULL;
 
566
                                }
 
567
                                break;
 
568
                        case MAPISTORE_OBJECT_MODIFIED:
 
569
                                reply->NotificationData.MessageModifiedNotification.FID = notification->parameters.object_parameters.folder_id;
 
570
                                reply->NotificationData.MessageModifiedNotification.MID = notification->parameters.object_parameters.object_id;
 
571
                                reply->NotificationData.MessageModifiedNotification.TagCount = notification->parameters.object_parameters.tag_count;
 
572
                                if (notification->parameters.object_parameters.tag_count
 
573
                                    && notification->parameters.object_parameters.tag_count != 0xffff) {
 
574
                                        reply->NotificationData.MessageModifiedNotification.NotificationTags.Tags = talloc_memdup(mem_ctx, notification->parameters.object_parameters.tags, notification->parameters.object_parameters.tag_count * sizeof(enum MAPITAGS));
 
575
                                }
 
576
                                else {
 
577
                                        reply->NotificationData.MessageModifiedNotification.NotificationTags.Tags = NULL;
 
578
                                }
 
579
                                break;
 
580
                        case MAPISTORE_OBJECT_COPIED:
 
581
                        case MAPISTORE_OBJECT_MOVED:
 
582
                                reply->NotificationData.MessageMoveNotification.FID = notification->parameters.object_parameters.folder_id;
 
583
                                reply->NotificationData.MessageMoveNotification.MID = notification->parameters.object_parameters.object_id;
 
584
                                reply->NotificationData.MessageMoveNotification.OldFID = notification->parameters.object_parameters.old_folder_id;
 
585
                                reply->NotificationData.MessageMoveNotification.OldMID = notification->parameters.object_parameters.old_object_id;
 
586
                                break;
 
587
                                
 
588
                        default: /* MAPISTORE_OBJECT_DELETED */
 
589
                                reply->NotificationData.MessageDeletedNotification.FID = notification->parameters.object_parameters.folder_id;
 
590
                                reply->NotificationData.MessageDeletedNotification.MID = notification->parameters.object_parameters.object_id;
 
591
                        }
 
592
                }
 
593
                else { /* MAPISTORE_FOLDER */
 
594
                        switch (notification->event) {
 
595
                        case MAPISTORE_OBJECT_NEWMAIL:
 
596
                                reply->NotificationData.NewMailNotification.FID = notification->parameters.object_parameters.folder_id;
 
597
                                reply->NotificationData.NewMailNotification.MID = notification->parameters.object_parameters.object_id;
 
598
                                /* Hack for now */
 
599
                                reply->NotificationData.NewMailNotification.MessageFlags = 0x4;
 
600
                                reply->NotificationData.NewMailNotification.UnicodeFlag = true;
 
601
                                reply->NotificationData.NewMailNotification.MessageClass.lpszW = "IPF.Note";
 
602
                                break;
 
603
                        case MAPISTORE_OBJECT_CREATED:
 
604
                                reply->NotificationData.FolderCreatedNotification.ParentFID = notification->parameters.object_parameters.folder_id;
 
605
                                reply->NotificationData.FolderCreatedNotification.FID = notification->parameters.object_parameters.object_id;
 
606
                                reply->NotificationData.FolderCreatedNotification.TagCount = notification->parameters.object_parameters.tag_count;
 
607
                                if (notification->parameters.object_parameters.tag_count
 
608
                                    && notification->parameters.object_parameters.tag_count != 0xffff) {
 
609
                                        reply->NotificationData.FolderCreatedNotification.NotificationTags.Tags = talloc_memdup(mem_ctx, notification->parameters.object_parameters.tags, notification->parameters.object_parameters.tag_count * sizeof(enum MAPITAGS));
 
610
                                }
 
611
                                else {
 
612
                                        reply->NotificationData.FolderCreatedNotification.NotificationTags.Tags = NULL;
 
613
                                }
 
614
                                break;
 
615
                        case MAPISTORE_OBJECT_MODIFIED:
 
616
                                reply->NotificationData.FolderModifiedNotification_10.FID = notification->parameters.object_parameters.object_id;
 
617
                                reply->NotificationData.FolderModifiedNotification_10.TagCount = notification->parameters.object_parameters.tag_count;
 
618
                                if (notification->parameters.object_parameters.tag_count
 
619
                                    && notification->parameters.object_parameters.tag_count != 0xffff) {
 
620
                                        reply->NotificationData.FolderModifiedNotification_10.NotificationTags.Tags = talloc_memdup(mem_ctx, notification->parameters.object_parameters.tags, notification->parameters.object_parameters.tag_count * sizeof(enum MAPITAGS));
 
621
                                }
 
622
                                else {
 
623
                                        reply->NotificationData.FolderModifiedNotification_10.NotificationTags.Tags = NULL;
 
624
                                }
 
625
 
 
626
                                if (notification->parameters.object_parameters.new_message_count) {
 
627
                                        reply->NotificationData.FolderModifiedNotification_1010.TotalMessageCount = notification->parameters.object_parameters.message_count;
 
628
                                }
 
629
 
 
630
                                break;
 
631
                        default: /* MAPISTORE_OBJECT_DELETED */
 
632
                                reply->NotificationData.FolderDeletedNotification.ParentFID = notification->parameters.object_parameters.folder_id;
 
633
                                reply->NotificationData.FolderDeletedNotification.FID = notification->parameters.object_parameters.object_id;
 
634
                        }
 
635
                }
 
636
        }
 
637
 
 
638
end:
 
639
        *sizep += libmapiserver_RopNotify_size(mapi_repl);
 
640
 
 
641
        return success;
 
642
}
259
643
 
260
644
static struct mapi_response *EcDoRpc_process_transaction(TALLOC_CTX *mem_ctx, 
261
645
                                                         struct emsmdbp_context *emsmdbp_ctx,
262
646
                                                         struct mapi_request *mapi_request)
263
647
{
264
 
        enum MAPISTATUS         retval;
265
 
        struct mapi_response    *mapi_response;
 
648
        enum MAPISTATUS                         retval;
 
649
        struct mapi_response                    *mapi_response;
 
650
        struct mapistore_notification_list      *notification_holder;
 
651
        struct mapistore_notification_list      *nlist;
 
652
        struct mapistore_notification_list      *el;
 
653
        struct mapistore_subscription_list      *sel;
 
654
        struct mapistore_subscription_list      *subscription_list;
 
655
        struct mapistore_subscription_list      *subscription_holder;
266
656
        uint32_t                handles_length;
267
657
        uint16_t                size = 0;
268
658
        uint32_t                i;
269
659
        uint32_t                idx;
 
660
        bool                    needs_realloc = true;
270
661
 
271
662
        /* Sanity checks */
272
663
        if (!emsmdbp_ctx) return NULL;
279
670
        /* Step 1. Handle Idle requests case */
280
671
        if (mapi_request->mapi_len <= 2) {
281
672
                mapi_response->mapi_len = 2;
282
 
                return mapi_response;
 
673
                idx = 0;
 
674
                goto notif;
283
675
        }
284
 
        
 
676
 
285
677
        /* Step 2. Process serialized MAPI requests */
286
678
        mapi_response->mapi_repl = talloc_zero(mem_ctx, struct EcDoRpc_MAPI_REPL);
287
679
        for (i = 0, idx = 0, size = 0; mapi_request->mapi_req[i].opnum != 0; i++) {
334
726
                                                                  &(mapi_response->mapi_repl[idx]),
335
727
                                                                  mapi_response->handles, &size);
336
728
                        break;
337
 
                /* op_MAPI_GetPropsAll: 0x8 */
338
 
                /* op_MAPI_GetPropList: 0x9 */
339
 
                case op_MAPI_SetProps: /* 0x09 */
 
729
                case op_MAPI_GetPropsAll: /* 0x8 */
 
730
                        retval = EcDoRpc_RopGetPropertiesAll(mem_ctx, emsmdbp_ctx,
 
731
                                                             &(mapi_request->mapi_req[i]),
 
732
                                                             &(mapi_response->mapi_repl[idx]),
 
733
                                                             mapi_response->handles, &size);
 
734
                        break;
 
735
                case op_MAPI_GetPropList: /* 0x9 */
 
736
                        retval = EcDoRpc_RopGetPropertiesList(mem_ctx, emsmdbp_ctx,
 
737
                                                              &(mapi_request->mapi_req[i]),
 
738
                                                              &(mapi_response->mapi_repl[idx]), 
 
739
                                                              mapi_response->handles, &size);
 
740
                        break;
 
741
                case op_MAPI_SetProps: /* 0x0a */
340
742
                        retval = EcDoRpc_RopSetProperties(mem_ctx, emsmdbp_ctx,
341
743
                                                          &(mapi_request->mapi_req[i]),
342
744
                                                          &(mapi_response->mapi_repl[idx]),
350
752
                        break;
351
753
                case op_MAPI_SaveChangesMessage: /* 0x0c */
352
754
                        retval = EcDoRpc_RopSaveChangesMessage(mem_ctx, emsmdbp_ctx,
353
 
                                                          &(mapi_request->mapi_req[i]),
354
 
                                                          &(mapi_response->mapi_repl[idx]),
355
 
                                                          mapi_response->handles, &size);
356
 
                        break;
357
 
                /* op_MAPI_SaveChangesMessage: 0xc */
358
 
                /* op_MAPI_RemoveAllRecipients: 0xd */
 
755
                                                               &(mapi_request->mapi_req[i]),
 
756
                                                               &(mapi_response->mapi_repl[idx]),
 
757
                                                               mapi_response->handles, &size);
 
758
                        break;
 
759
                case op_MAPI_RemoveAllRecipients: /* 0xd */
 
760
                        retval = EcDoRpc_RopRemoveAllRecipients(mem_ctx, emsmdbp_ctx,
 
761
                                                                &(mapi_request->mapi_req[i]),
 
762
                                                                &(mapi_response->mapi_repl[idx]),
 
763
                                                                mapi_response->handles, &size);
 
764
                        break;
359
765
                case op_MAPI_ModifyRecipients: /* 0xe */
360
766
                        retval = EcDoRpc_RopModifyRecipients(mem_ctx, emsmdbp_ctx,
361
767
                                                             &(mapi_request->mapi_req[i]),
442
848
                                                               &(mapi_response->mapi_repl[idx]),
443
849
                                                               mapi_response->handles, &size);
444
850
                        break;
445
 
                /* op_MAPI_OpenAttach: 0x22 */
446
 
                /* op_MAPI_CreateAttach: 0x23 */
 
851
                case op_MAPI_OpenAttach: /* 0x22 */
 
852
                        retval = EcDoRpc_RopOpenAttach(mem_ctx, emsmdbp_ctx,
 
853
                                                       &(mapi_request->mapi_req[i]),
 
854
                                                       &(mapi_response->mapi_repl[idx]),
 
855
                                                       mapi_response->handles, &size);
 
856
                        break;
 
857
                case op_MAPI_CreateAttach: /* 0x23 */
 
858
                        retval = EcDoRpc_RopCreateAttach(mem_ctx, emsmdbp_ctx,
 
859
                                                         &(mapi_request->mapi_req[i]),
 
860
                                                         &(mapi_response->mapi_repl[idx]),
 
861
                                                         mapi_response->handles, &size);
 
862
                        break;
447
863
                /* op_MAPI_DeleteAttach: 0x24 */
448
 
                /* op_MAPI_SaveChangesAttachment: 0x25 */
 
864
                case op_MAPI_SaveChangesAttachment: /* 0x25 */
 
865
                        retval = EcDoRpc_RopSaveChangesAttachment(mem_ctx, emsmdbp_ctx,
 
866
                                                                  &(mapi_request->mapi_req[i]),
 
867
                                                                  &(mapi_response->mapi_repl[idx]),
 
868
                                                                  mapi_response->handles, &size);
 
869
                        break;
449
870
                case op_MAPI_SetReceiveFolder: /* 0x26 */
450
871
                        retval = EcDoRpc_RopSetReceiveFolder(mem_ctx, emsmdbp_ctx,
451
872
                                                             &(mapi_request->mapi_req[i]),
483
904
                                                        &(mapi_response->mapi_repl[idx]),
484
905
                                                        mapi_response->handles, &size);
485
906
                        break;
486
 
                /* op_MAPI_SeekStream: 0x2e */
487
 
                /* op_MAPI_SetStreamSize: 0x2f */
 
907
                case op_MAPI_SeekStream: /* 0x2e */
 
908
                        retval = EcDoRpc_RopSeekStream(mem_ctx, emsmdbp_ctx,
 
909
                                                       &(mapi_request->mapi_req[i]),
 
910
                                                       &(mapi_response->mapi_repl[idx]),
 
911
                                                       mapi_response->handles, &size);
 
912
                        break;
 
913
                case op_MAPI_SetStreamSize: /* 0x2f */
 
914
                        retval = EcDoRpc_RopSetStreamSize(mem_ctx, emsmdbp_ctx,
 
915
                                                          &(mapi_request->mapi_req[i]),
 
916
                                                          &(mapi_response->mapi_repl[idx]),
 
917
                                                          mapi_response->handles, &size);
 
918
                        break;
488
919
                case op_MAPI_SetSearchCriteria: /* 0x30 */
489
920
                        retval = EcDoRpc_RopSetSearchCriteria(mem_ctx, emsmdbp_ctx,
490
921
                                                              &(mapi_request->mapi_req[i]),
503
934
                                                          &(mapi_response->mapi_repl[idx]),
504
935
                                                          mapi_response->handles, &size);
505
936
                        break;
506
 
                /* op_MAPI_MoveCopyMessages: 0x33 */
 
937
                case op_MAPI_MoveCopyMessages: /* 0x33 */
 
938
                        retval = EcDoRpc_RopMoveCopyMessages(mem_ctx, emsmdbp_ctx,
 
939
                                                            &(mapi_request->mapi_req[i]),
 
940
                                                            &(mapi_response->mapi_repl[idx]),
 
941
                                                            mapi_response->handles, &size);
 
942
                        break;
507
943
                /* op_MAPI_AbortSubmit: 0x34 */
508
944
                /* op_MAPI_MoveFolder: 0x35 */
509
945
                /* op_MAPI_CopyFolder: 0x36 */
510
946
                /* op_MAPI_QueryColumnsAll: 0x37 */
511
947
                /* op_MAPI_Abort: 0x38 */
512
 
                /* op_MAPI_CopyTo: 0x39 */
 
948
                case op_MAPI_CopyTo: /* 0x39 */
 
949
                        retval = EcDoRpc_RopCopyTo(mem_ctx, emsmdbp_ctx,
 
950
                                                   &(mapi_request->mapi_req[i]),
 
951
                                                   &(mapi_response->mapi_repl[idx]),
 
952
                                                   mapi_response->handles, &size);
 
953
                        break;
513
954
                /* op_MAPI_CopyToStream: 0x3a */
514
955
                /* op_MAPI_CloneStream: 0x3b */
515
956
                case op_MAPI_GetPermissionsTable: /* 0x3e */
524
965
                                                          &(mapi_response->mapi_repl[idx]),
525
966
                                                          mapi_response->handles, &size);
526
967
                        break;
527
 
                /* op_MAPI_ModifyPermissions: 0x40 */
 
968
                case op_MAPI_ModifyPermissions: /* 0x40 */
 
969
                        retval = EcDoRpc_RopModifyPermissions(mem_ctx, emsmdbp_ctx,
 
970
                                                              &(mapi_request->mapi_req[i]),
 
971
                                                              &(mapi_response->mapi_repl[idx]),
 
972
                                                              mapi_response->handles, &size);
 
973
                        break;
528
974
                case op_MAPI_ModifyRules: /* 0x41 */
529
975
                        retval = EcDoRpc_RopModifyRules(mem_ctx, emsmdbp_ctx,
530
976
                                                        &(mapi_request->mapi_req[i]),
532
978
                                                        mapi_response->handles, &size);
533
979
                        break;
534
980
                /* op_MAPI_GetOwningServers: 0x42 */
535
 
                /* op_MAPI_LongTermIdFromId: 0x43 */
536
 
                /* op_MAPI_IdFromLongTermId: 0x44 */
 
981
                case op_MAPI_LongTermIdFromId: /* 0x43 */
 
982
                        retval = EcDoRpc_RopLongTermIdFromId(mem_ctx, emsmdbp_ctx,
 
983
                                                             &(mapi_request->mapi_req[i]),
 
984
                                                             &(mapi_response->mapi_repl[idx]),
 
985
                                                             mapi_response->handles, &size);
 
986
                        break;
 
987
                case op_MAPI_IdFromLongTermId: /* 0x44 */
 
988
                        retval = EcDoRpc_RopIdFromLongTermId(mem_ctx, emsmdbp_ctx,
 
989
                                                             &(mapi_request->mapi_req[i]),
 
990
                                                             &(mapi_response->mapi_repl[idx]),
 
991
                                                             mapi_response->handles, &size);
 
992
                        break;
537
993
                /* op_MAPI_PublicFolderIsGhosted: 0x45 */
538
 
                /* op_MAPI_OpenEmbeddedMessage: 0x46 */
 
994
                case op_MAPI_OpenEmbeddedMessage: /* 0x46 */
 
995
                        retval = EcDoRpc_RopOpenEmbeddedMessage(mem_ctx, emsmdbp_ctx,
 
996
                                                                &(mapi_request->mapi_req[i]),
 
997
                                                                &(mapi_response->mapi_repl[idx]),
 
998
                                                                mapi_response->handles, &size);
 
999
                        break;
539
1000
                case op_MAPI_SetSpooler: /* 0x47 */
540
1001
                        retval = EcDoRpc_RopSetSpooler(mem_ctx, emsmdbp_ctx,
541
1002
                                                       &(mapi_request->mapi_req[i]),
549
1010
                                                            &(mapi_response->mapi_repl[idx]),
550
1011
                                                            mapi_response->handles, &size);
551
1012
                        break;
552
 
                /* op_MAPI_TransportSend: 0x4a */
553
 
                /* op_MAPI_FastTransferSourceGetBuffer: 0x4e */
 
1013
                case op_MAPI_TransportSend: /* 0x4a */
 
1014
                        retval = EcDoRpc_RopTransportSend(mem_ctx, emsmdbp_ctx,
 
1015
                                                          &(mapi_request->mapi_req[i]),
 
1016
                                                          &(mapi_response->mapi_repl[idx]),
 
1017
                                                          mapi_response->handles, &size);
 
1018
                        break;
 
1019
                /* op_MAPI_FastTransferSourceCopyMessages: 0x4b */
 
1020
                /* op_MAPI_FastTransferSourceCopyFolder: 0x4c */
 
1021
                case op_MAPI_FastTransferSourceCopyTo: /* 0x4d */
 
1022
                        retval = EcDoRpc_RopFastTransferSourceCopyTo(mem_ctx, emsmdbp_ctx, 
 
1023
                                                                     &(mapi_request->mapi_req[i]),
 
1024
                                                                     &(mapi_response->mapi_repl[idx]),
 
1025
                                                                     mapi_response->handles, &size);
 
1026
                        break;
 
1027
                case op_MAPI_FastTransferSourceGetBuffer: /* 0x4e */
 
1028
                        retval = EcDoRpc_RopFastTransferSourceGetBuffer(mem_ctx, emsmdbp_ctx, 
 
1029
                                                                        &(mapi_request->mapi_req[i]),
 
1030
                                                                        &(mapi_response->mapi_repl[idx]),
 
1031
                                                                        mapi_response->handles, &size);
 
1032
                        break;
554
1033
                case op_MAPI_FindRow: /* 0x4f */
555
1034
                        retval = EcDoRpc_RopFindRow(mem_ctx, emsmdbp_ctx, 
556
1035
                                                    &(mapi_request->mapi_req[i]),
560
1039
                /* op_MAPI_Progress: 0x50 */
561
1040
                /* op_MAPI_TransportNewMail: 0x51 */
562
1041
                /* op_MAPI_GetValidAttachments: 0x52 */
563
 
                /* op_MAPI_GetNamesFromIDs: 0x55 */
 
1042
                case op_MAPI_GetNamesFromIDs: /* 0x55 */
 
1043
                        retval = EcDoRpc_RopGetNamesFromIDs(mem_ctx, emsmdbp_ctx,
 
1044
                                                            &(mapi_request->mapi_req[i]),
 
1045
                                                            &(mapi_response->mapi_repl[idx]),
 
1046
                                                            mapi_response->handles, &size);
 
1047
                        break;
564
1048
                case op_MAPI_GetIDsFromNames: /* 0x56 */
565
1049
                        retval = EcDoRpc_RopGetPropertyIdsFromNames(mem_ctx, emsmdbp_ctx,
566
1050
                                                                    &(mapi_request->mapi_req[i]),
578
1062
                /* op_MAPI_CollapseRow: 0x5a */
579
1063
                /* op_MAPI_LockRegionStream: 0x5b */
580
1064
                /* op_MAPI_UnlockRegionStream: 0x5c */
581
 
                /* op_MAPI_CommitStream: 0x5d */
582
 
                /* op_MAPI_GetStreamSize: 0x5e */
 
1065
                case op_MAPI_CommitStream: /* 0x5d */
 
1066
                        retval = EcDoRpc_RopCommitStream(mem_ctx, emsmdbp_ctx,
 
1067
                                                         &(mapi_request->mapi_req[i]),
 
1068
                                                         &(mapi_response->mapi_repl[idx]),
 
1069
                                                         mapi_response->handles, &size);
 
1070
                        break;
 
1071
                case op_MAPI_GetStreamSize: /* 0x5e */
 
1072
                        retval = EcDoRpc_RopGetStreamSize(mem_ctx, emsmdbp_ctx,
 
1073
                                                          &(mapi_request->mapi_req[i]),
 
1074
                                                          &(mapi_response->mapi_repl[idx]),
 
1075
                                                          mapi_response->handles, &size);
 
1076
                        break;
583
1077
                /* op_MAPI_QueryNamedProperties: 0x5f */
584
1078
                case op_MAPI_GetPerUserLongTermIds: /* 0x60 */
585
1079
                        retval = EcDoRpc_RopGetPerUserLongTermIds(mem_ctx, emsmdbp_ctx,
618
1112
                                                        &(mapi_response->mapi_repl[idx]),
619
1113
                                                        mapi_response->handles, &size);
620
1114
                        break;
621
 
                /* op_MAPI_SyncConfigure: 0x70 */
622
 
                /* op_MAPI_SyncImportMessageChange: 0x72 */
623
 
                /* op_MAPI_SyncImportHierarchyChange: 0x73 */
624
 
                /* op_MAPI_SyncImportDeletes: 0x74 */
625
 
                /* op_MAPI_SyncUploadStateStreamBegin: 0x75 */
626
 
                /* op_MAPI_SyncUploadStateStreamContinue: 0x76 */
627
 
                /* op_MAPI_SyncUploadStateStreamEnd: 0x77 */
628
 
                /* op_MAPI_SyncImportMessageMove: 0x78 */
 
1115
                case op_MAPI_SyncConfigure: /* 0x70 */
 
1116
                        retval = EcDoRpc_RopSyncConfigure(mem_ctx, emsmdbp_ctx,
 
1117
                                                          &(mapi_request->mapi_req[i]),
 
1118
                                                          &(mapi_response->mapi_repl[idx]),
 
1119
                                                          mapi_response->handles, &size);
 
1120
                        break;
 
1121
                case op_MAPI_SyncImportMessageChange: /* 0x72 */
 
1122
                        retval = EcDoRpc_RopSyncImportMessageChange(mem_ctx, emsmdbp_ctx,
 
1123
                                                                    &(mapi_request->mapi_req[i]),
 
1124
                                                                    &(mapi_response->mapi_repl[idx]),
 
1125
                                                                    mapi_response->handles, &size);
 
1126
                        break;
 
1127
                case op_MAPI_SyncImportHierarchyChange: /* 0x73 */
 
1128
                        retval = EcDoRpc_RopSyncImportHierarchyChange(mem_ctx, emsmdbp_ctx,
 
1129
                                                                      &(mapi_request->mapi_req[i]),
 
1130
                                                                      &(mapi_response->mapi_repl[idx]),
 
1131
                                                                      mapi_response->handles, &size);
 
1132
                        break;
 
1133
                case op_MAPI_SyncImportDeletes: /* 0x74 */
 
1134
                        retval = EcDoRpc_RopSyncImportDeletes(mem_ctx, emsmdbp_ctx,
 
1135
                                                              &(mapi_request->mapi_req[i]),
 
1136
                                                              &(mapi_response->mapi_repl[idx]),
 
1137
                                                              mapi_response->handles, &size);
 
1138
                        break;
 
1139
                case op_MAPI_SyncUploadStateStreamBegin: /* 0x75 */
 
1140
                        retval = EcDoRpc_RopSyncUploadStateStreamBegin(mem_ctx, emsmdbp_ctx,
 
1141
                                                                       &(mapi_request->mapi_req[i]),
 
1142
                                                                       &(mapi_response->mapi_repl[idx]),
 
1143
                                                                       mapi_response->handles, &size);
 
1144
                        break;
 
1145
                case op_MAPI_SyncUploadStateStreamContinue: /* 0x76 */
 
1146
                        retval = EcDoRpc_RopSyncUploadStateStreamContinue(mem_ctx, emsmdbp_ctx,
 
1147
                                                                          &(mapi_request->mapi_req[i]),
 
1148
                                                                          &(mapi_response->mapi_repl[idx]),
 
1149
                                                                          mapi_response->handles, &size);
 
1150
                        break;
 
1151
                case op_MAPI_SyncUploadStateStreamEnd: /* 0x77 */
 
1152
                        retval = EcDoRpc_RopSyncUploadStateStreamEnd(mem_ctx, emsmdbp_ctx,
 
1153
                                                                     &(mapi_request->mapi_req[i]),
 
1154
                                                                     &(mapi_response->mapi_repl[idx]),
 
1155
                                                                     mapi_response->handles, &size);
 
1156
                        break;
 
1157
                case op_MAPI_SyncImportMessageMove: /* 0x78 */
 
1158
                        retval = EcDoRpc_RopSyncImportMessageMove(mem_ctx, emsmdbp_ctx,
 
1159
                                                                  &(mapi_request->mapi_req[i]),
 
1160
                                                                  &(mapi_response->mapi_repl[idx]),
 
1161
                                                                  mapi_response->handles, &size);
 
1162
                        break;
629
1163
                /* op_MAPI_SetPropertiesNoReplicate: 0x79 */
630
 
                /* op_MAPI_DeletePropertiesNoReplicate: 0x7a */
631
 
                /* op_MAPI_GetStoreState: 0x7b */
632
 
                /* op_MAPI_SyncOpenCollector: 0x7e */
633
 
                /* op_MAPI_GetLocalReplicaIds: 0x7f */
634
 
                /* op_MAPI_SyncImportReadStateChanges: 0x80 */
635
 
                /* op_MAPI_ResetTable: 0x81 */
636
 
                /* op_MAPI_SyncGetTransferState: 0x82 */
 
1164
                case op_MAPI_DeletePropertiesNoReplicate: /* 0x7a */
 
1165
                        retval = EcDoRpc_RopDeletePropertiesNoReplicate(mem_ctx, emsmdbp_ctx,
 
1166
                                                                        &(mapi_request->mapi_req[i]),
 
1167
                                                                        &(mapi_response->mapi_repl[idx]),
 
1168
                                                                        mapi_response->handles, &size);
 
1169
                        break;
 
1170
                case op_MAPI_GetStoreState: /* 0x7b */
 
1171
                        retval = EcDoRpc_RopGetStoreState(mem_ctx, emsmdbp_ctx,
 
1172
                                                          &(mapi_request->mapi_req[i]),
 
1173
                                                          &(mapi_response->mapi_repl[idx]),
 
1174
                                                          mapi_response->handles, &size);
 
1175
                        break;
 
1176
                case op_MAPI_SyncOpenCollector: /* 0x7e */
 
1177
                        retval = EcDoRpc_RopSyncOpenCollector(mem_ctx, emsmdbp_ctx,
 
1178
                                                              &(mapi_request->mapi_req[i]),
 
1179
                                                              &(mapi_response->mapi_repl[idx]),
 
1180
                                                              mapi_response->handles, &size);
 
1181
                        break;
 
1182
                case op_MAPI_GetLocalReplicaIds: /* 0x7f */
 
1183
                        retval = EcDoRpc_RopGetLocalReplicaIds(mem_ctx, emsmdbp_ctx,
 
1184
                                                               &(mapi_request->mapi_req[i]),
 
1185
                                                               &(mapi_response->mapi_repl[idx]),
 
1186
                                                               mapi_response->handles, &size);
 
1187
                        break;
 
1188
                case op_MAPI_SyncImportReadStateChanges: /* 0x80 */
 
1189
                        retval = EcDoRpc_RopSyncImportReadStateChanges(mem_ctx, emsmdbp_ctx,
 
1190
                                                                       &(mapi_request->mapi_req[i]),
 
1191
                                                                       &(mapi_response->mapi_repl[idx]),
 
1192
                                                                       mapi_response->handles, &size);
 
1193
                        break;
 
1194
                case op_MAPI_ResetTable: /* 0x81 */
 
1195
                        retval = EcDoRpc_RopResetTable(mem_ctx, emsmdbp_ctx,
 
1196
                                                       &(mapi_request->mapi_req[i]),
 
1197
                                                       &(mapi_response->mapi_repl[idx]),
 
1198
                                                       mapi_response->handles, &size);
 
1199
                        break;
 
1200
                case op_MAPI_SyncGetTransferState: /* 0x82 */
 
1201
                        retval = EcDoRpc_RopSyncGetTransferState(mem_ctx, emsmdbp_ctx,
 
1202
                                                                 &(mapi_request->mapi_req[i]),
 
1203
                                                                 &(mapi_response->mapi_repl[idx]),
 
1204
                                                                 mapi_response->handles, &size);
 
1205
                        break;
637
1206
                /* op_MAPI_OpenPublicFolderByName: 0x87 */
638
1207
                /* op_MAPI_SetSyncNotificationGuid: 0x88 */
639
1208
                /* op_MAPI_FreeBookmark: 0x89 */
640
1209
                /* op_MAPI_WriteAndCommitStream: 0x90 */
641
1210
                /* op_MAPI_HardDeleteMessages: 0x91 */
642
1211
                /* op_MAPI_HardDeleteMessagesAndSubfolders: 0x92 */
 
1212
                case op_MAPI_SetLocalReplicaMidsetDeleted: /* 0x93 */
 
1213
                        retval = EcDoRpc_RopSetLocalReplicaMidsetDeleted(mem_ctx, emsmdbp_ctx,
 
1214
                                                                         &(mapi_request->mapi_req[i]),
 
1215
                                                                         &(mapi_response->mapi_repl[idx]),
 
1216
                                                                         mapi_response->handles, &size);
 
1217
                        break;
643
1218
                case op_MAPI_Logon: /* 0xfe */
644
1219
                        retval = EcDoRpc_RopLogon(mem_ctx, emsmdbp_ctx,
645
1220
                                                  &(mapi_request->mapi_req[i]),
654
1229
                if (mapi_request->mapi_req[i].opnum != op_MAPI_Release) {
655
1230
                        idx++;
656
1231
                }
657
 
 
658
1232
        }
659
1233
 
 
1234
notif:
660
1235
        /* Step 3. Notifications/Pending calls should be processed here */
661
 
        mapi_response->mapi_repl[idx].opnum = 0;
 
1236
        /* Note: GetProps and GetRows are filled with flag NDR_REMAINING, which may hide the content of the following replies. */
 
1237
        while ((notification_holder = emsmdbp_ctx->mstore_ctx->notifications)) {
 
1238
                subscription_list = mapistore_find_matching_subscriptions(emsmdbp_ctx->mstore_ctx, notification_holder->notification);
 
1239
                while ((subscription_holder = subscription_list)) {
 
1240
                        if (needs_realloc) {
 
1241
                                mapi_response->mapi_repl = talloc_realloc(mem_ctx, mapi_response->mapi_repl, struct EcDoRpc_MAPI_REPL, idx + 2);
 
1242
                        }
 
1243
                        needs_realloc = emsmdbp_fill_notification(mapi_response->mapi_repl, emsmdbp_ctx, &(mapi_response->mapi_repl[idx]), subscription_holder->subscription, notification_holder->notification, &size);
 
1244
                        DLIST_REMOVE(subscription_list, subscription_holder);
 
1245
                        talloc_free(subscription_holder);
 
1246
                        idx++;
 
1247
                }
 
1248
                
 
1249
                DLIST_REMOVE(emsmdbp_ctx->mstore_ctx->notifications, notification_holder);
 
1250
                talloc_free(notification_holder);
 
1251
        }
 
1252
        
 
1253
        DEBUG(0, ("subscriptions: %p\n", emsmdbp_ctx->mstore_ctx->subscriptions));
 
1254
        /* Process notifications available on subscriptions queues */
 
1255
        for (sel = emsmdbp_ctx->mstore_ctx->subscriptions; sel; sel = sel->next) {
 
1256
                DEBUG(0, ("subscription = %p\n", sel->subscription));
 
1257
                if (sel->subscription) {
 
1258
                        DEBUG(0, ("subscription: handle = 0x%x\n", sel->subscription->handle));
 
1259
                        DEBUG(0, ("subscription: types = 0x%x\n", sel->subscription->notification_types));
 
1260
                        DEBUG(0, ("subscription: mqueue = %d\n", sel->subscription->mqueue));
 
1261
                        DEBUG(0, ("subscription: mqueue name = %s\n", sel->subscription->mqueue_name));
 
1262
                }
 
1263
                retval = mapistore_get_queued_notifications(emsmdbp_ctx->mstore_ctx, sel->subscription, &nlist);
 
1264
                if (retval == MAPI_E_SUCCESS) {
 
1265
                        for (el = nlist; el->notification; el = el->next) {
 
1266
                                if (needs_realloc) {
 
1267
                                        mapi_response->mapi_repl = talloc_realloc(mem_ctx, mapi_response->mapi_repl, 
 
1268
                                                                                  struct EcDoRpc_MAPI_REPL, idx + 2);
 
1269
                                }
 
1270
                                needs_realloc = emsmdbp_fill_notification(mapi_response->mapi_repl, emsmdbp_ctx, 
 
1271
                                                                          &(mapi_response->mapi_repl[idx]),
 
1272
                                                                          sel->subscription, el->notification, &size);
 
1273
                                idx++;
 
1274
                        }
 
1275
                        talloc_free(nlist);
 
1276
                }
 
1277
        }
662
1278
 
 
1279
        if (mapi_response->mapi_repl) {
 
1280
                mapi_response->mapi_repl[idx].opnum = 0;
 
1281
        }
 
1282
        
663
1283
        /* Step 4. Fill mapi_response structure */
664
1284
        handles_length = mapi_request->mapi_len - mapi_request->length;
665
1285
        mapi_response->length = size + sizeof (mapi_response->length);
668
1288
        return mapi_response;
669
1289
}
670
1290
 
671
 
 
672
1291
/**
673
1292
   \details exchange_emsmdb EcDoRpc (0x2) function
674
1293
 
686
1305
        struct emsmdbp_context          *emsmdbp_ctx = NULL;
687
1306
        struct mapi_request             *mapi_request;
688
1307
        struct mapi_response            *mapi_response;
689
 
        bool                            found = false;
690
1308
 
691
1309
        DEBUG(3, ("exchange_emsmdb: EcDoRpc (0x2)\n"));
692
1310
 
693
1311
        /* Step 0. Ensure incoming user is authenticated */
694
1312
        if (!dcesrv_call_authenticated(dce_call)) {
695
1313
                DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
 
1314
                r->out.handle->handle_type = 0;
 
1315
                r->out.handle->uuid = GUID_zero();
 
1316
                r->out.result = DCERPC_FAULT_CONTEXT_MISMATCH;
696
1317
                return MAPI_E_LOGON_FAILED;
697
1318
        }
698
1319
 
699
1320
        /* Retrieve the emsmdbp_context from the session management system */
700
 
        for (session = emsmdb_session; session; session = session->next) {
701
 
                if ((mpm_session_cmp(session->session, dce_call)) == true) {
702
 
                        emsmdbp_ctx = (struct emsmdbp_context *)session->session->private_data;
703
 
                        found = true;
704
 
                }
705
 
        }
706
 
        OPENCHANGE_RETVAL_IF(found == false, MAPI_E_LOGON_FAILED, NULL);
 
1321
        session = dcesrv_find_emsmdb_session(&r->in.handle->uuid);
 
1322
        if (session) {
 
1323
                emsmdbp_ctx = (struct emsmdbp_context *)session->session->private_data;
 
1324
        }
 
1325
        else {
 
1326
                r->out.handle->handle_type = 0;
 
1327
                r->out.handle->uuid = GUID_zero();
 
1328
                r->out.result = DCERPC_FAULT_CONTEXT_MISMATCH;
 
1329
                return MAPI_E_LOGON_FAILED;
 
1330
        }
707
1331
 
708
1332
        /* Step 1. Process EcDoRpc requests */
709
1333
        mapi_request = r->in.mapi_request;
754
1378
                                                          TALLOC_CTX *mem_ctx,
755
1379
                                                          struct EcRRegisterPushNotification *r)
756
1380
{
757
 
        DEBUG(3, ("exchange_emsmdb: EcRRegisterPushNotification (0x4) not implemented\n"));
758
 
        DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
 
1381
        int                             retval;
 
1382
        struct exchange_emsmdb_session  *session;
 
1383
        struct emsmdbp_context          *emsmdbp_ctx = NULL;
 
1384
 
 
1385
        DEBUG(3, ("exchange_emsmdb: EcRRegisterPushNotification (0x4)\n"));
 
1386
 
 
1387
        if (!dcesrv_call_authenticated(dce_call)) {
 
1388
                DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
 
1389
                r->out.handle->handle_type = 0;
 
1390
                r->out.handle->uuid = GUID_zero();
 
1391
                r->out.result = DCERPC_FAULT_CONTEXT_MISMATCH;
 
1392
                return MAPI_E_LOGON_FAILED;
 
1393
        }
 
1394
 
 
1395
        /* Retrieve the emsmdbp_context from the session management system */
 
1396
        session = dcesrv_find_emsmdb_session(&r->in.handle->uuid);
 
1397
        if (session) {
 
1398
                emsmdbp_ctx = (struct emsmdbp_context *)session->session->private_data;
 
1399
        } else {
 
1400
                r->out.handle->handle_type = 0;
 
1401
                r->out.handle->uuid = GUID_zero();
 
1402
                r->out.result = DCERPC_FAULT_CONTEXT_MISMATCH;
 
1403
                return MAPI_E_LOGON_FAILED;
 
1404
        }
 
1405
 
 
1406
        retval = mapistore_mgmt_interface_register_bind(emsmdbp_ctx->mstore_ctx->conn_info,
 
1407
                                                        r->in.cbContext, r->in.rgbContext,
 
1408
                                                        r->in.cbCallbackAddress, r->in.rgbCallbackAddress);
 
1409
        DEBUG(0, ("[%s:%d]: retval = 0x%x\n", __FUNCTION__, __LINE__, retval));
 
1410
        if (retval == MAPI_E_SUCCESS) {
 
1411
                r->out.handle = r->in.handle;
 
1412
                /* FIXME: Create a notification object and return associated handle */
 
1413
                *r->out.hNotification = 244;
 
1414
        } 
 
1415
 
 
1416
        return MAPI_E_SUCCESS;
759
1417
}
760
1418
 
761
1419
 
840
1498
 
841
1499
   \return MAPI_E_SUCCESS on success
842
1500
 */
843
 
static void dcesrv_EcDoRpcExt(struct dcesrv_call_state *dce_call,
844
 
                              TALLOC_CTX *mem_ctx,
845
 
                              struct EcDoRpcExt *r)
 
1501
static enum MAPISTATUS dcesrv_EcDoRpcExt(struct dcesrv_call_state *dce_call,
 
1502
                                         TALLOC_CTX *mem_ctx,
 
1503
                                         struct EcDoRpcExt *r)
846
1504
{
847
1505
        DEBUG(3, ("exchange_emsmdb: EcDoRpcExt (0x9) not implemented\n"));
848
 
        DCESRV_FAULT_VOID(DCERPC_FAULT_OP_RNG_ERROR);
 
1506
        DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
849
1507
}
850
1508
 
851
1509
/* check if a client version is too low to use */
880
1538
        const char                      *cn;
881
1539
        const char                      *userDN;
882
1540
        char                            *dnprefix;
883
 
        bool                            found = false;
884
1541
 
885
1542
        DEBUG(3, ("exchange_emsmdb: EcDoConnectEx (0xA)\n"));
886
1543
 
891
1548
                wire_handle.handle_type = EXCHANGE_HANDLE_EMSMDB;
892
1549
                wire_handle.uuid = GUID_zero();
893
1550
                *r->out.handle = wire_handle;
894
 
 
895
 
                r->out.pcmsPollsMax = talloc_zero(mem_ctx, uint32_t);
896
 
                r->out.pcRetry = talloc_zero(mem_ctx, uint32_t);
897
 
                r->out.pcmsRetryDelay = talloc_zero(mem_ctx, uint32_t);
898
 
                r->out.picxr = talloc_zero(mem_ctx, uint32_t);
899
 
                r->out.pulTimeStamp = talloc_zero(mem_ctx, uint32_t);
900
 
                r->out.pcbAuxOut = talloc_zero(mem_ctx, uint32_t);
901
 
 
902
1551
                *r->out.pcmsPollsMax = 0;
903
1552
                *r->out.pcRetry = 0;
904
1553
                *r->out.pcmsRetryDelay = 0;
914
1563
                *r->out.pulTimeStamp = 0;
915
1564
                r->out.rgbAuxOut = NULL;
916
1565
                *r->out.pcbAuxOut = 0;
917
 
 
918
1566
                r->out.result = MAPI_E_LOGON_FAILED;
919
1567
                return MAPI_E_LOGON_FAILED;
920
1568
        }
950
1598
        /* Step 5. Retrieve the distinguished name of the server */
951
1599
        cn = ldb_msg_find_attr_as_string(msg, "cn", NULL);
952
1600
        userDN = ldb_msg_find_attr_as_string(msg, "legacyExchangeDN", NULL);
953
 
        dnprefix = (char *) strstr(userDN, cn);
 
1601
        dnprefix = strstr(userDN, cn);
954
1602
        if (!dnprefix) {
955
1603
                talloc_free(emsmdbp_ctx);
956
1604
                goto failure;
966
1614
        handle->data = (void *) emsmdbp_ctx;
967
1615
        *r->out.handle = handle->wire_handle;
968
1616
 
969
 
        r->out.pcmsPollsMax = talloc_zero(mem_ctx, uint32_t);
970
1617
        *r->out.pcmsPollsMax = EMSMDB_PCMSPOLLMAX;
971
 
 
972
 
        r->out.pcRetry = talloc_zero(mem_ctx, uint32_t);
973
1618
        *r->out.pcRetry = EMSMDB_PCRETRY;
974
 
 
975
 
        r->out.pcmsRetryDelay = talloc_zero(mem_ctx, uint32_t);
976
1619
        *r->out.pcmsRetryDelay = EMSMDB_PCRETRYDELAY;
977
 
 
978
 
        r->out.picxr = talloc_zero(mem_ctx, uint32_t);
979
1620
        *r->out.picxr = 0;
980
1621
 
981
1622
        r->out.rgwServerVersion[0] = 0x8;
985
1626
        r->out.pulTimeStamp = talloc_zero(mem_ctx, uint32_t);
986
1627
        *r->out.pulTimeStamp = time(NULL);
987
1628
 
988
 
        r->out.pcbAuxOut = talloc_zero(mem_ctx, uint32_t);
989
1629
        *r->out.pcbAuxOut = 0;
990
1630
 
991
1631
        r->out.rgbAuxOut = NULL;
992
1632
 
 
1633
        r->out.result = MAPI_E_SUCCESS;
 
1634
 
993
1635
        if (clientVersionIsTooLow(r->in.rgwClientVersion)) {
994
1636
                r->out.rgwBestVersion[0] = 0x000B;
995
1637
                r->out.rgwBestVersion[1] = 0x8000;
1003
1645
 
1004
1646
                r->out.result = MAPI_E_SUCCESS;
1005
1647
        }
 
1648
 
1006
1649
        /* Search for an existing session and increment ref_count, otherwise create it */
1007
 
        for (session = emsmdb_session; session; session = session->next) {
1008
 
                if ((mpm_session_cmp(session->session, dce_call)) == true) {
1009
 
                        DEBUG(0, ("[exchange_emsmdb]: Increment session ref count for %d\n",
1010
 
                                  session->session->context_id));
1011
 
                        mpm_session_increment_ref_count(session->session);
1012
 
                        found = true;
1013
 
                        break;
1014
 
                }
1015
 
        }
1016
 
 
1017
 
        if (found == false) {
 
1650
        session = dcesrv_find_emsmdb_session(&handle->wire_handle.uuid);
 
1651
        if (session) {
 
1652
                DEBUG(0, ("[exchange_emsmdb]: Increment session ref count for %d\n", 
 
1653
                          session->session->context_id));
 
1654
                mpm_session_increment_ref_count(session->session);
 
1655
        }
 
1656
        else {
1018
1657
                /* Step 7. Associate this emsmdbp context to the session */
1019
1658
                session = talloc((TALLOC_CTX *)emsmdb_session, struct exchange_emsmdb_session);
1020
1659
                OPENCHANGE_RETVAL_IF(!session, MAPI_E_NOT_ENOUGH_RESOURCES, emsmdbp_ctx);
1023
1662
                session->session = mpm_session_init((TALLOC_CTX *)emsmdb_session, dce_call);
1024
1663
                OPENCHANGE_RETVAL_IF(!session->session, MAPI_E_NOT_ENOUGH_RESOURCES, emsmdbp_ctx);
1025
1664
                
 
1665
                session->uuid = handle->wire_handle.uuid;
 
1666
 
1026
1667
                mpm_session_set_private_data(session->session, (void *) emsmdbp_ctx);
1027
1668
                mpm_session_set_destructor(session->session, emsmdbp_destructor);
1028
1669
 
1059
1700
        uint32_t                        pulFlags = 0x0;
1060
1701
        uint32_t                        pulTransTime = 0;
1061
1702
        DATA_BLOB                       rgbIn;
1062
 
        bool                            found = false;
1063
1703
 
1064
1704
        DEBUG(3, ("exchange_emsmdb: EcDoRpcExt2 (0xB)\n"));
1065
1705
 
 
1706
        r->out.rgbOut = NULL;
 
1707
        *r->out.pcbOut = 0;
 
1708
        r->out.rgbAuxOut = NULL;
 
1709
        *r->out.pcbAuxOut = 0;
 
1710
 
1066
1711
        /* Step 0. Ensure incoming user is authenticated */
1067
1712
        if (!dcesrv_call_authenticated(dce_call)) {
1068
1713
                DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
 
1714
                r->out.handle->handle_type = 0;
 
1715
                r->out.handle->uuid = GUID_zero();
 
1716
                r->out.result = DCERPC_FAULT_CONTEXT_MISMATCH;
1069
1717
                return MAPI_E_LOGON_FAILED;
1070
1718
        }
1071
1719
 
1072
1720
        /* Retrieve the emsmdbp_context from the session management system */
1073
 
        for (session = emsmdb_session; session; session = session->next) {
1074
 
                if ((mpm_session_cmp(session->session, dce_call)) == true) {
1075
 
                        emsmdbp_ctx = (struct emsmdbp_context *)session->session->private_data;
1076
 
                        found = true;
1077
 
                }
 
1721
        session = dcesrv_find_emsmdb_session(&r->in.handle->uuid);
 
1722
        if (!session) {
 
1723
                r->out.handle->handle_type = 0;
 
1724
                r->out.handle->uuid = GUID_zero();
 
1725
                r->out.result = DCERPC_FAULT_CONTEXT_MISMATCH;
 
1726
                return MAPI_E_LOGON_FAILED;
1078
1727
        }
1079
 
        OPENCHANGE_RETVAL_IF(found == false, MAPI_E_LOGON_FAILED, NULL);
 
1728
        emsmdbp_ctx = (struct emsmdbp_context *)session->session->private_data;
1080
1729
 
1081
1730
        /* Extract mapi_request from rgbIn */
1082
1731
        rgbIn.data = r->in.rgbIn;
1091
1740
 
1092
1741
        /* Fill EcDoRpcExt2 reply */
1093
1742
        r->out.handle = r->in.handle;
1094
 
        r->out.pulFlags = &pulFlags;
 
1743
        *r->out.pulFlags = pulFlags;
1095
1744
 
1096
1745
        /* Push MAPI response into a DATA blob */
1097
1746
        ndr_uncomp_rgbOut = ndr_push_init_ctx(mem_ctx);
1122
1771
 
1123
1772
        /* Push MAPI response into a DATA blob */
1124
1773
        r->out.rgbOut = ndr_rgbOut->data;
1125
 
        r->out.pcbOut = &ndr_rgbOut->offset;
 
1774
        *r->out.pcbOut = ndr_rgbOut->offset;
1126
1775
 
1127
 
        r->out.rgbAuxOut = NULL;
1128
 
        *r->out.pcbAuxOut = 0;
1129
 
        r->out.pulTransTime = &pulTransTime;
 
1776
        *r->out.pulTransTime = pulTransTime;
1130
1777
 
1131
1778
        return MAPI_E_SUCCESS;
1132
1779
}
1181
1828
                                                 struct EcDoAsyncConnectEx *r)
1182
1829
{
1183
1830
        DEBUG(3, ("exchange_emsmdb: EcDoAsyncConnectEx (0xe) not implemented\n"));
 
1831
        r->out.result = ecRejected;
1184
1832
        DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1185
1833
 
1186
1834
        return MAPI_E_SUCCESS;
1203
1851
                                                TALLOC_CTX *mem_ctx,
1204
1852
                                                void *r, struct mapiproxy *mapiproxy)
1205
1853
{
1206
 
        enum MAPISTATUS                         retval;
1207
1854
        const struct ndr_interface_table        *table;
1208
1855
        uint16_t                                opnum;
1209
1856
 
1216
1863
 
1217
1864
        switch (opnum) {
1218
1865
        case NDR_ECDOCONNECT:
1219
 
                retval = dcesrv_EcDoConnect(dce_call, mem_ctx, (struct EcDoConnect *)r);
 
1866
                dcesrv_EcDoConnect(dce_call, mem_ctx, (struct EcDoConnect *)r);
1220
1867
                break;
1221
1868
        case NDR_ECDODISCONNECT:
1222
 
                retval = dcesrv_EcDoDisconnect(dce_call, mem_ctx, (struct EcDoDisconnect *)r);
 
1869
                dcesrv_EcDoDisconnect(dce_call, mem_ctx, (struct EcDoDisconnect *)r);
1223
1870
                break;
1224
1871
        case NDR_ECDORPC:
1225
 
                retval = dcesrv_EcDoRpc(dce_call, mem_ctx, (struct EcDoRpc *)r);
 
1872
                dcesrv_EcDoRpc(dce_call, mem_ctx, (struct EcDoRpc *)r);
1226
1873
                break;
1227
1874
        case NDR_ECGETMORERPC:
1228
1875
                dcesrv_EcGetMoreRpc(dce_call, mem_ctx, (struct EcGetMoreRpc *)r);
1229
1876
                break;
1230
1877
        case NDR_ECRREGISTERPUSHNOTIFICATION:
1231
 
                retval = dcesrv_EcRRegisterPushNotification(dce_call, mem_ctx, (struct EcRRegisterPushNotification *)r);
 
1878
                dcesrv_EcRRegisterPushNotification(dce_call, mem_ctx, (struct EcRRegisterPushNotification *)r);
1232
1879
                break;
1233
1880
        case NDR_ECRUNREGISTERPUSHNOTIFICATION:
1234
 
                retval = dcesrv_EcRUnregisterPushNotification(dce_call, mem_ctx, (struct EcRUnregisterPushNotification *)r);
 
1881
                dcesrv_EcRUnregisterPushNotification(dce_call, mem_ctx, (struct EcRUnregisterPushNotification *)r);
1235
1882
                break;
1236
1883
        case NDR_ECDUMMYRPC:
1237
1884
                dcesrv_EcDummyRpc(dce_call, mem_ctx, (struct EcDummyRpc *)r);
1246
1893
                dcesrv_EcDoRpcExt(dce_call, mem_ctx, (struct EcDoRpcExt *)r);
1247
1894
                break;
1248
1895
        case NDR_ECDOCONNECTEX:
1249
 
                retval = dcesrv_EcDoConnectEx(dce_call, mem_ctx, (struct EcDoConnectEx *)r);
 
1896
                dcesrv_EcDoConnectEx(dce_call, mem_ctx, (struct EcDoConnectEx *)r);
1250
1897
                break;
1251
1898
        case NDR_ECDORPCEXT2:
1252
 
                retval = dcesrv_EcDoRpcExt2(dce_call, mem_ctx, (struct EcDoRpcExt2 *)r);
 
1899
                dcesrv_EcDoRpcExt2(dce_call, mem_ctx, (struct EcDoRpcExt2 *)r);
1253
1900
                break;
1254
1901
        case NDR_ECUNKNOWN0XC:
1255
1902
                dcesrv_EcUnknown0xC(dce_call, mem_ctx, (struct EcUnknown0xC *)r);
1300
1947
 
1301
1948
   \return NT_STATUS_OK on success
1302
1949
 */
 
1950
 
 
1951
/* FIXME: code temporarily disabled as we don't master the logic behind session handles yet... */
1303
1952
static NTSTATUS dcesrv_exchange_emsmdb_unbind(struct server_id server_id, uint32_t context_id)
1304
1953
{
1305
 
        struct exchange_emsmdb_session  *session;
1306
 
 
1307
 
        for (session = emsmdb_session; session; session = session->next) {
1308
 
                if ((mpm_session_cmp_sub(session->session, server_id, context_id) == true)) {
1309
 
                        mpm_session_release(session->session);
1310
 
                        DLIST_REMOVE(emsmdb_session, session);
1311
 
                        DEBUG(6, ("[%s:%d]: Session found and released\n", __FUNCTION__, __LINE__));
1312
 
                        return NT_STATUS_OK;
1313
 
                }
1314
 
        }
 
1954
        /* struct exchange_emsmdb_session       *session; */
 
1955
        /* bool ret; */
 
1956
 
 
1957
        DEBUG (0, ("dcesrv_exchange_emsmdb_unbind\n"));
 
1958
 
 
1959
        /* session = dcesrv_find_emsmdb_session_by_server_id(&server_id, context_id); */
 
1960
        /* if (session) { */
 
1961
        /*      ret = mpm_session_release(session->session); */
 
1962
        /*      if (ret == true) { */
 
1963
        /*              DLIST_REMOVE(emsmdb_session, session); */
 
1964
        /*              DEBUG(5, ("[%s:%d]: Session found and released\n",  */
 
1965
        /*                        __FUNCTION__, __LINE__)); */
 
1966
        /*      } else { */
 
1967
        /*              DEBUG(5, ("[%s:%d]: Session found and ref_count decreased\n", */
 
1968
        /*                        __FUNCTION__, __LINE__)); */
 
1969
        /*      } */
 
1970
        /* } */
1315
1971
 
1316
1972
        return NT_STATUS_OK;
1317
1973
}