Example #1
0
} END_TEST

START_TEST (test_create_mailbox) {
	char *data;
	uint32_t *data_int;
	uint64_t fid = 14989949884725985281ul;

	retval = openchangedb_create_mailbox(g_oc_ctx, "chuck", "First Organization",
					     "First Administrative Group", fid,
					     "OpenChange Mailbox: chuck");
	CHECK_SUCCESS;

	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, "chuck",
						  PidTagDisplayName, fid,
						  (void **)&data);
	CHECK_SUCCESS;
	ck_assert_str_eq("OpenChange Mailbox: chuck", (char *)data);

	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, "chuck",
						  PidTagAccess, fid,
						  (void **)&data_int);
	CHECK_SUCCESS;
	ck_assert_int_eq(63, *data_int);

	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, "chuck",
						  PidTagRights, fid,
						  (void **)&data_int);
	CHECK_SUCCESS;
	ck_assert_int_eq(2043, *data_int);
} END_TEST
Example #2
0
} END_TEST

START_TEST (test_set_folder_properties_on_mailbox) {
	uint64_t fid;
	uint32_t proptag;
	struct SRow *row = talloc_zero(g_mem_ctx, struct SRow);
	struct Binary_r *s1, *s2;

	fid = 18303473310563827713ul;
	proptag = PidTagIpmTaskEntryId;

	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag,
						  fid, (void **)&s1);
	CHECK_SUCCESS;
	row->cValues = 1;
	row->lpProps = talloc_zero(g_mem_ctx, struct SPropValue);
	row->lpProps[0].ulPropTag = proptag;
	row->lpProps[0].value.bin.lpb = (uint8_t *)talloc_strdup(g_mem_ctx, "foo");
	row->lpProps[0].value.bin.cb = 3;
	retval = openchangedb_set_folder_properties(g_oc_ctx, USER1, fid, row);
	CHECK_SUCCESS;

	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag,
						  fid, (void **)&s2);
	CHECK_SUCCESS;
	ck_assert_int_eq(s2->cb, 3);
	ck_assert_str_eq((char *)s2->lpb, "foo");
} END_TEST
Example #3
0
} END_TEST

START_TEST (test_set_folder_properties) {
	uint64_t fid;
	uint32_t proptag;
	struct FILETIME *last_modification, *last_modification_after;
	uint64_t change_number, change_number_after;
	struct SRow *row = talloc_zero(g_mem_ctx, struct SRow);
	char *display_name;

	// We have to check that last_modification_time and change_number have
	// changed (besides the property we are setting)
	fid = 14124414331340718081ul;
	proptag = PidTagLastModificationTime;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag,
						  fid, (void **)&last_modification);
	CHECK_SUCCESS;

	proptag = PidTagChangeNumber;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag,
						  fid, (void **)&change_number);
	CHECK_SUCCESS;

	proptag = PidTagDisplayName;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag,
						  fid, (void **)&display_name);
	CHECK_SUCCESS;
	ck_assert_str_eq(display_name, "A3");

	row->cValues = 1;
	row->lpProps = talloc_zero(g_mem_ctx, struct SPropValue);
	row->lpProps[0].ulPropTag = PidTagDisplayName;
	row->lpProps[0].value.lpszW = talloc_strdup(g_mem_ctx, "foo");
	retval = openchangedb_set_folder_properties(g_oc_ctx, USER1, fid, row);
	CHECK_SUCCESS;

	proptag = PidTagLastModificationTime;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag,
						  fid, (void **)&last_modification_after);
	CHECK_SUCCESS;

	proptag = PidTagChangeNumber;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag,
						  fid, (void **)&change_number_after);
	CHECK_SUCCESS;

	ck_assert(change_number != change_number_after);
	ck_assert(last_modification->dwHighDateTime != last_modification_after->dwHighDateTime);
	ck_assert(last_modification->dwLowDateTime != last_modification_after->dwLowDateTime);

	proptag = PidTagDisplayName;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag,
						  fid, (void **)&display_name);
	CHECK_SUCCESS;
	ck_assert_str_eq(display_name, "foo");
} END_TEST
Example #4
0
} END_TEST

START_TEST (test_get_public_folder_property) {
	void *data;
	uint32_t proptag;
	uint64_t fid;

	fid = 216172782113783809ul;
	proptag = PidTagAttributeReadOnly;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	CHECK_SUCCESS;
	ck_assert_int_eq(0, *(int *)data);

	proptag = PidTagDisplayName;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	CHECK_SUCCESS;
	ck_assert_str_eq("NON_IPM_SUBTREE", (char *)data);

	proptag = PidTagCreationTime;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	CHECK_SUCCESS;
	ck_assert_int_eq(130264095410000000 >> 32, ((struct FILETIME *)data)->dwHighDateTime);
	ck_assert_int_eq(130264095410000000 & 0xffffffff, ((struct FILETIME *)data)->dwLowDateTime);
} END_TEST
Example #5
0
} END_TEST

START_TEST (test_create_folder_change_number) {
	uint64_t pfid, fid, changenumber;
	uint32_t proptag;
	uint64_t *cn;

	pfid = 18231415716525899777ul;
	fid = 10741085111278632961ul;
	changenumber = 1;
	retval = openchangedb_create_folder(g_oc_ctx, USER1, pfid, fid, changenumber,
					    "sogo://paco@mail/folderFoo", -1);
	CHECK_SUCCESS;

	proptag = PidTagChangeNumber;
	cn = talloc_zero(g_mem_ctx, uint64_t);
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1,
						  proptag, fid, (void **)&cn);
	CHECK_SUCCESS;
	ck_assert_int_eq(*cn, changenumber);
} END_TEST
Example #6
0
} END_TEST

START_TEST (test_get_folder_property) {
	void *data;
	uint64_t fid;
	uint32_t proptag;

	// PT_LONG
	proptag = PidTagAccess;
	fid = 17871127746336260097ul;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	CHECK_SUCCESS;
	ck_assert_int_eq(63, *(int *)data);

	// PT_UNICODE
	proptag = PidTagDisplayName;
	fid = 14124414331340718081ul;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	CHECK_SUCCESS;
	ck_assert_str_eq("A3", (char *)data);
	proptag = PidTagRights;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	CHECK_SUCCESS;
	ck_assert_int_eq(2043, *(int *)data);

	// PT_SYSTIME
	proptag = PidTagLastModificationTime;
	fid = 17438782182108692481ul;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	CHECK_SUCCESS;
	ck_assert_int_eq(130268260180000000 >> 32, ((struct FILETIME *)data)->dwHighDateTime);
	ck_assert_int_eq(130268260180000000 & 0xffffffff, ((struct FILETIME *)data)->dwLowDateTime);

	// Mailbox display name
	proptag = PidTagDisplayName;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	CHECK_SUCCESS;
	ck_assert_str_eq("OpenChange Mailbox: paco", (char *)data);

	// PT_BINARY
	proptag = PidTagIpmDraftsEntryId;
	retval = openchangedb_get_folder_property(g_mem_ctx, g_oc_ctx, USER1, proptag, fid, &data);
	ck_assert_int_eq(46, ((struct Binary_r *)data)->cb);
} END_TEST
Example #7
0
/**
   \details Check if a fid is an special following [MS-OXOSFLD] Section 2.2.2 rules.

   \param emsmdbp_ctx pointer to the emsmdb provider context
   \param fid the folder identifier to check

   \return true on success, otherwise false

   \note An error on any call is interpreted as false
 */
_PUBLIC_ bool oxosfld_is_special_folder(struct emsmdbp_context *emsmdbp_ctx, uint64_t fid)
{
        bool                    ret = false;
        struct Binary_r         *entry_id;
        struct BinaryArray_r    *entries_ids;
        struct FolderEntryId    folder_entry_id;
        int                     i, system_idx;
        enum MAPISTATUS         retval;
        TALLOC_CTX              *local_mem_ctx;
        const uint32_t          identification_properties[] = { PidTagIpmAppointmentEntryId, PidTagIpmContactEntryId,
                                                                PidTagIpmJournalEntryId, PidTagIpmNoteEntryId,
                                                                PidTagIpmTaskEntryId, PidTagRemindersOnlineEntryId,
                                                                PidTagIpmDraftsEntryId };
        const uint32_t          IDENTIFICATION_PROP_COUNT = sizeof(identification_properties)/sizeof(uint32_t);
        const uint32_t          ADDITIONAL_REN_ENTRY_IDS_COUNT = 5, FREEBUSY_DATA_ENTRYID_IDX = 3;
        uint64_t                inbox_fid, mailbox_fid;

        /* Sanity checks */
        if (!emsmdbp_ctx) return false;

        /* 1. The fids returned in RopLogon are special folders, as they are set with SystemIdx
           higher than -1. See emsmdbp_provisioning.c for details */
        retval = openchangedb_get_system_idx(emsmdbp_ctx->oc_ctx, emsmdbp_ctx->username, fid,
                                             &system_idx);
        if (retval == MAPI_E_SUCCESS && system_idx > -1) {
                OC_DEBUG(5, "Fid 0x%"PRIx64 " is a system special folder whose system_idx is %d", fid, system_idx);
                return true;
        }

        retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, emsmdbp_ctx->username,
                                                 EMSMDBP_MAILBOX_ROOT, &mailbox_fid);
        if (retval == MAPI_E_SUCCESS && mailbox_fid == fid) {
                OC_DEBUG(5, "Fid 0x%"PRIx64 " is the mailbox ID", fid);
                return true;
        }

        /* 2. Set of binary properties on the root folder or inbox folder */
        /* TODO: work in Delegate mode */
        retval = openchangedb_get_SystemFolderID(emsmdbp_ctx->oc_ctx, emsmdbp_ctx->username,
                                                 EMSMDBP_INBOX, &inbox_fid);
        if (retval != MAPI_E_SUCCESS) {
                return false;
        }

        memset(&folder_entry_id, 0, sizeof(struct FolderEntryId));
        retval = openchangedb_get_MailboxGuid(emsmdbp_ctx->oc_ctx, emsmdbp_ctx->username,
                                              &folder_entry_id.ProviderUID);

        if (retval != MAPI_E_SUCCESS) {
                return false;
        }
        retval = openchangedb_get_MailboxReplica(emsmdbp_ctx->oc_ctx, emsmdbp_ctx->username,
                                                 NULL, &folder_entry_id.FolderDatabaseGuid);
        if (retval != MAPI_E_SUCCESS) {
                return false;
        }

        local_mem_ctx = talloc_new(NULL);
        if (!local_mem_ctx) return false;

        for (i = 0; i < IDENTIFICATION_PROP_COUNT; i++) {
                retval = openchangedb_get_folder_property(local_mem_ctx, emsmdbp_ctx->oc_ctx,
                                                          emsmdbp_ctx->username, identification_properties[i],
                                                          inbox_fid, (void **) &entry_id);
                if (retval == MAPI_E_SUCCESS
                    && fid_in_entry_id(entry_id, inbox_fid, &folder_entry_id, fid)) {
                        OC_DEBUG(5, "The fid 0x%"PRIx64 " found in %s property", fid, get_proptag_name(identification_properties[i]));
                        ret = true;
                        goto end;
                }
        }

        /* 3. The PidTagAdditionalRenEntryIds contains an array of entry IDs with special folders */
        retval = openchangedb_get_folder_property(local_mem_ctx, emsmdbp_ctx->oc_ctx,
                                                  emsmdbp_ctx->username, PidTagAdditionalRenEntryIds,
                                                  inbox_fid, (void **) &entries_ids);
        if (retval == MAPI_E_SUCCESS && entries_ids
            && entries_ids->cValues >= ADDITIONAL_REN_ENTRY_IDS_COUNT) {
                for (i = 0; i < ADDITIONAL_REN_ENTRY_IDS_COUNT; i++) {
                        if (fid_in_entry_id((entries_ids->lpbin + i), inbox_fid, &folder_entry_id, fid)) {
                                OC_DEBUG(5, "The fid 0x%"PRIx64 " found as %d index in PidTagAdditionalRenEntryIds", fid, i);
                                ret = true;
                                goto end;
                        }
                }
        }

        /* 4. The PidTagAdditionalRenEntryIdsEx on the store object */
        retval = openchangedb_get_folder_property(local_mem_ctx, emsmdbp_ctx->oc_ctx,
                                                  emsmdbp_ctx->username, PidTagAdditionalRenEntryIdsEx,
                                                  inbox_fid, (void **) &entry_id);
        if (retval == MAPI_E_SUCCESS) {
                int j, k;
                struct PersistDataArray *persist_data_array;

                persist_data_array = get_PersistDataArray(local_mem_ctx, entry_id);
                if (persist_data_array && persist_data_array->cValues > 0) {
                        struct Binary_r               checked_entry_id;
                        DATA_BLOB                     checked_folder_entry_id;
                        struct PersistData            persist_data;
                        struct PersistElement         persist_element;
                        struct PersistElementArray    persist_element_array;

                        for (j = 0; j < persist_data_array->cValues; j++) {
                                persist_data = persist_data_array->lpPersistData[j];
                                if (persist_data.PersistID == PERSIST_SENTINEL) {
                                        /* This is the last PersistData */
                                        break;
                                }
                                persist_element_array = persist_data.DataElements;
                                for (k = 0; k < persist_element_array.cValues; k++) {
                                        persist_element = persist_element_array.lpPersistElement[k];
                                        if (persist_element.ElementID == PERSIST_SENTINEL) {
                                                /* This is the last PersistElement */
                                                break;
                                        }
                                        if (persist_element.ElementID == RSF_ELID_ENTRYID) {
                                                checked_folder_entry_id = persist_element.ElementData.rsf_elid_entryid;
                                                checked_entry_id.cb = checked_folder_entry_id.length;
                                                checked_entry_id.lpb = checked_folder_entry_id.data;
                                                if (fid_in_entry_id(&checked_entry_id, inbox_fid, &folder_entry_id, fid)) {
                                                        OC_DEBUG(5, "The fid 0x%"PRIx64 " found as %d entry in PidTagAdditionalRenEntryIdsEx", fid, persist_data.PersistID);
                                                        ret = true;
                                                        goto end;
                                                }
                                        }
                                }
                        }
                } else {
                        OC_DEBUG(5, "Cannot parse PersistDataArray");
                }
        }


        /* 5. The entry ID indexed by 3 in PidTagFreeBusyEntryIds on the root folder stores
           the Freebusy data folder */
        retval = openchangedb_get_folder_property(local_mem_ctx, emsmdbp_ctx->oc_ctx,
                                                  emsmdbp_ctx->username, PidTagFreeBusyEntryIds,
                                                  inbox_fid, (void **) &entries_ids);
        if (retval == MAPI_E_SUCCESS && entries_ids
            && entries_ids->cValues >= FREEBUSY_DATA_ENTRYID_IDX
            && fid_in_entry_id((entries_ids->lpbin + FREEBUSY_DATA_ENTRYID_IDX),
                               mailbox_fid, &folder_entry_id, fid)) {
                OC_DEBUG(5, "The fid 0x%"PRIx64 " found as Freebusy Data\n", fid);
                ret = true;
                goto end;
        }

        /* 6. The FID returned by RopGetReceiveFolder */
        /* According to [MS-OXOSFLD] Section 2.2.7, we should search
           for the default Receive folder for the Store object. And
           according to [MS-OXCSTOR] Section 3.2.5.2, it should be the
           user's inbox folder and it is already checked above. */

end:
        talloc_free(local_mem_ctx);

        return ret;
}