/** \details EcDoRpc ModifyPermissions (0x40) Rop. This operation gets the GUID of a public folder's per-user information. \param mem_ctx pointer to the memory context \param emsmdbp_ctx pointer to the emsmdb provider context \param mapi_req pointer to the GetPerUserLongTermIds EcDoRpc_MAPI_REQ \param mapi_repl pointer to the GetPerUserLongTermIds EcDoRpc_MAPI_REPL \param handles pointer to the MAPI handles array \param size pointer to the mapi_response size to update \return MAPI_E_SUCCESS on success, otherwise MAPI error */ _PUBLIC_ enum MAPISTATUS EcDoRpc_RopModifyPermissions(TALLOC_CTX *mem_ctx, struct emsmdbp_context *emsmdbp_ctx, struct EcDoRpc_MAPI_REQ *mapi_req, struct EcDoRpc_MAPI_REPL *mapi_repl, uint32_t *handles, uint16_t *size) { enum MAPISTATUS retval; enum mapistore_error mretval; struct mapi_handles *folder; struct emsmdbp_object *folder_object; void *data = NULL; uint32_t handle; struct ModifyPermissions_req *request; OC_DEBUG(4, "exchange_emsmdb: [OXCSTOR] ModifyPermissions (0x40)\n"); /* Sanity checks */ OPENCHANGE_RETVAL_IF(!emsmdbp_ctx, MAPI_E_NOT_INITIALIZED, NULL); OPENCHANGE_RETVAL_IF(!mapi_req, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!mapi_repl, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!handles, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!size, MAPI_E_INVALID_PARAMETER, NULL); mapi_repl->opnum = mapi_req->opnum; mapi_repl->handle_idx = mapi_req->handle_idx; mapi_repl->error_code = MAPI_E_SUCCESS; /* Ensure handle references a folder object */ handle = handles[mapi_req->handle_idx]; retval = mapi_handles_search(emsmdbp_ctx->handles_ctx, handle, &folder); if (retval) { mapi_repl->error_code = MAPI_E_INVALID_OBJECT; OC_DEBUG(5, " handle (%x) not found: %x\n", handle, mapi_req->handle_idx); goto end; } retval = mapi_handles_get_private_data(folder, &data); if (retval || !data) { mapi_repl->error_code = MAPI_E_INVALID_OBJECT; OC_DEBUG(5, " handle data not found, idx = %x\n", mapi_req->handle_idx); goto end; } folder_object = (struct emsmdbp_object *) data; if (folder_object->type != EMSMDBP_OBJECT_FOLDER) { mapi_repl->error_code = MAPI_E_INVALID_OBJECT; OC_DEBUG(5, " unhandled object type: %d\n", folder_object->type); goto end; } request = &mapi_req->u.mapi_ModifyPermissions; if (emsmdbp_is_mapistore(folder_object)) { mretval = mapistore_folder_modify_permissions(emsmdbp_ctx->mstore_ctx, emsmdbp_get_contextID(folder_object), folder_object->backend_object, request->rowList.ModifyFlags, request->rowList.ModifyCount, request->rowList.PermissionsData); if (mretval != MAPISTORE_SUCCESS) { OC_DEBUG(5, "mapistore_folder_modify_permissions: %s\n", mapistore_errstr(mretval)); mapi_repl->error_code = mapistore_error_to_mapi(mretval); } } else { mapi_repl->error_code = MAPI_E_NOT_FOUND; } end: *size += libmapiserver_RopModifyPermissions_size(mapi_repl); return MAPI_E_SUCCESS; }
/** \details EcDoRpc EmptyFolder (0x58) Rop. This operation removes the sub-folders and messages from a given parent folder. \param mem_ctx pointer to the memory context \param emsmdbp_ctx pointer to the emsmdb provider context \param mapi_req pointer to the EmptyFolder EcDoRpc_MAPI_REQ structure \param mapi_repl pointer to the EmptyFolder EcDoRpc_MAPI_REPL structure \param handles pointer to the MAPI handles array \param size pointer to the mapi_response size to update \return MAPI_E_SUCCESS on success, otherwise MAPI error */ enum MAPISTATUS EcDoRpc_RopCopyFolder(TALLOC_CTX *mem_ctx, struct emsmdbp_context *emsmdbp_ctx, struct EcDoRpc_MAPI_REQ *mapi_req, struct EcDoRpc_MAPI_REPL *mapi_repl, uint32_t *handles, uint16_t *size) { enum MAPISTATUS retval; enum mapistore_error ret; uint32_t handle; struct mapi_handles *handle_object; void *private_data; struct CopyFolder_req *request; struct CopyFolder_repl *response; struct emsmdbp_object *source_parent; struct emsmdbp_object *copy_folder; struct emsmdbp_object *target_folder; uint32_t contextID; OC_DEBUG(4, "exchange_emsmdb: [OXCFOLD] CopyFolder (0x36)\n"); /* Sanity checks */ OPENCHANGE_RETVAL_IF(!emsmdbp_ctx, MAPI_E_NOT_INITIALIZED, NULL); OPENCHANGE_RETVAL_IF(!mapi_req, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!mapi_repl, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!handles, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!size, MAPI_E_INVALID_PARAMETER, NULL); mapi_repl->opnum = mapi_req->opnum; mapi_repl->handle_idx = mapi_req->handle_idx; mapi_repl->error_code = MAPI_E_SUCCESS; request = &mapi_req->u.mapi_CopyFolder; response = &mapi_repl->u.mapi_CopyFolder; /* Retrieve the source parent handle in the hierarchy */ handle = handles[mapi_req->handle_idx]; retval = mapi_handles_search(emsmdbp_ctx->handles_ctx, handle, &handle_object); if (retval) { OC_DEBUG(5, " handle (%x) not found: %x\n", handle, mapi_req->handle_idx); mapi_repl->error_code = MAPI_E_INVALID_OBJECT; goto end; } mapi_handles_get_private_data(handle_object, &private_data); source_parent = private_data; if (!source_parent || source_parent->type != EMSMDBP_OBJECT_FOLDER) { OC_DEBUG(5, " invalid handle (%x): %x\n", handle, mapi_req->handle_idx); mapi_repl->error_code = MAPI_E_INVALID_OBJECT; goto end; } /* Open the folder being copied as it will be the actor object in this process */ ret = emsmdbp_object_open_folder(mem_ctx, emsmdbp_ctx, source_parent, request->FolderId, ©_folder); if (ret != MAPISTORE_SUCCESS) { mapi_repl->error_code = mapistore_error_to_mapi(ret); goto end; } /* TODO: we should provide the ability to perform this operation between non-mapistore objects or between mapistore and non-mapistore objects */ if (!emsmdbp_is_mapistore(copy_folder)) { mapi_repl->error_code = MAPI_E_NO_ACCESS; goto end; } /* Retrieve the destination parent handle in the hierarchy */ handle = handles[request->handle_idx]; retval = mapi_handles_search(emsmdbp_ctx->handles_ctx, handle, &handle_object); if (retval) { OC_DEBUG(5, " handle (%x) not found: %x\n", handle, mapi_req->handle_idx); mapi_repl->error_code = MAPI_E_INVALID_OBJECT; goto end; } mapi_handles_get_private_data(handle_object, &private_data); target_folder = private_data; if (!target_folder || target_folder->type != EMSMDBP_OBJECT_FOLDER) { OC_DEBUG(5, " invalid handle (%x): %x\n", handle, mapi_req->handle_idx); mapi_repl->error_code = MAPI_E_INVALID_OBJECT; goto end; } if (!emsmdbp_is_mapistore(target_folder)) { mapi_repl->error_code = MAPI_E_NO_ACCESS; goto end; } contextID = emsmdbp_get_contextID(copy_folder); ret = mapistore_folder_copy_folder(emsmdbp_ctx->mstore_ctx, contextID, copy_folder->backend_object, target_folder->backend_object, mem_ctx, request->WantRecursive, request->NewFolderName.lpszW); mapi_repl->error_code = mapistore_error_to_mapi(ret); response->PartialCompletion = false; end: *size += libmapiserver_RopCopyFolder_size(mapi_repl); handles[mapi_repl->handle_idx] = handles[mapi_req->handle_idx]; return MAPI_E_SUCCESS; }
/** \details EcDoRpc CreateFolder (0x1c) Rop. This operation creates a folder on the remote server. \param mem_ctx pointer to the memory context \param emsmdbp_ctx pointer to the emsmdb provider context \param mapi_req pointer to the CreateFolder EcDoRpc_MAPI_REQ structure \param mapi_repl pointer to the CreateFolder EcDoRpc_MAPI_REPL structure \param handles pointer to the MAPI handles array \param size pointer to the mapi_response size to update \return MAPI_E_SUCCESS on success, otherwise MAPI error \note We do not provide support for GhostInfo */ _PUBLIC_ enum MAPISTATUS EcDoRpc_RopCreateFolder(TALLOC_CTX *mem_ctx, struct emsmdbp_context *emsmdbp_ctx, struct EcDoRpc_MAPI_REQ *mapi_req, struct EcDoRpc_MAPI_REPL *mapi_repl, uint32_t *handles, uint16_t *size) { enum MAPISTATUS retval; enum mapistore_error ret; struct mapi_handles *parent = NULL; uint32_t handle; uint64_t parent_fid, fid, cn; struct SPropValue cnValue; struct emsmdbp_object *parent_object = NULL; struct emsmdbp_object *object = NULL; struct CreateFolder_req *request; struct CreateFolder_repl *response; struct SRow *aRow = NULL; void *data; struct mapi_handles *rec = NULL; OC_DEBUG(4, "exchange_emsmdb: [OXCFOLD] CreateFolder (0x1c)\n"); /* Sanity checks */ OPENCHANGE_RETVAL_IF(!emsmdbp_ctx, MAPI_E_NOT_INITIALIZED, NULL); OPENCHANGE_RETVAL_IF(!mapi_req, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!mapi_repl, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!handles, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!size, MAPI_E_INVALID_PARAMETER, NULL); /* Set up sensible values for the reply */ mapi_repl->opnum = mapi_req->opnum; mapi_repl->error_code = MAPI_E_SUCCESS; mapi_repl->handle_idx = mapi_req->u.mapi_CreateFolder.handle_idx; if (!mapi_req->u.mapi_CreateFolder.ulFolderType || mapi_req->u.mapi_CreateFolder.ulFolderType > 0x2) { mapi_repl->error_code = MAPI_E_INVALID_PARAMETER; goto end; } /* Step 1. Retrieve parent handle in the hierarchy */ handle = handles[mapi_req->handle_idx]; retval = mapi_handles_search(emsmdbp_ctx->handles_ctx, handle, &parent); OPENCHANGE_RETVAL_IF(retval, retval, NULL); /* With CreateFolder, the parent object really IS the parent object */ mapi_handles_get_private_data(parent, &data); parent_object = (struct emsmdbp_object *)data; if (!parent_object) { OC_DEBUG(4, "exchange_emsmdb: [OXCFOLD] CreateFolder null object\n"); mapi_repl->error_code = MAPI_E_NO_SUPPORT; goto end; } if (parent_object->type == EMSMDBP_OBJECT_MAILBOX) { mapi_repl->error_code = MAPI_E_NO_SUPPORT; goto end; } if (parent_object->type != EMSMDBP_OBJECT_FOLDER && parent_object->type != EMSMDBP_OBJECT_MAILBOX) { OC_DEBUG(4, "exchange_emsmdb: [OXCFOLD] CreateFolder wrong object type: 0x%x\n", parent_object->type); mapi_repl->error_code = MAPI_E_NO_SUPPORT; goto end; } request = &mapi_req->u.mapi_CreateFolder; response = &mapi_repl->u.mapi_CreateFolder; /* OC_DEBUG(4, ("exchange_emsmdb: [OXCFOLD] CreateFolder parent: 0x%.16"PRIx64"\n", parent_fid)); */ /* OC_DEBUG(4, ("exchange_emsmdb: [OXCFOLD] Creating %s\n", request->FolderName.lpszW)); */ /* if (request->ulFolderType != FOLDER_GENERIC) { */ /* OC_DEBUG(4, ("exchange_emsmdb: [OXCFOLD] Unexpected folder type 0x%x\n", request->ulType)); */ /* mapi_repl->error_code = MAPI_E_NO_SUPPORT; */ /* goto end; */ /* } */ response->IsExistingFolder = false; ret = emsmdbp_object_get_fid_by_name(emsmdbp_ctx, parent_object, request->FolderName.lpszW, &fid); if (ret == MAPISTORE_SUCCESS) { if (oxosfld_is_special_folder(emsmdbp_ctx, fid) || request->ulFlags == OPEN_IF_EXISTS) { response->IsExistingFolder = true; } else { if (emsmdbp_is_mapistore(parent_object)) { OC_DEBUG(5, "Folder %s exists in MAPIStore", request->FolderName.lpszW); } else { OC_DEBUG(5, "Folder %s exists in OpenChangeDB", request->FolderName.lpszW); } mapi_repl->error_code = MAPI_E_COLLISION; goto end; } } mapi_handles_add(emsmdbp_ctx->handles_ctx, 0, &rec); if (response->IsExistingFolder) { retval = emsmdbp_object_open_folder_by_fid(rec, emsmdbp_ctx, parent_object, fid, &object); if (retval != MAPI_E_SUCCESS) { OC_DEBUG(4, "exchange_emsmdb: [OXCFOLD] Failure opening existing folder: %s\n", mapi_get_errstr(retval)); mapi_handles_delete(emsmdbp_ctx->handles_ctx, rec->handle); mapi_repl->error_code = retval; goto end; } } else { /* Step 3. Turn CreateFolder parameters into MAPI property array */ parent_fid = parent_object->object.folder->folderID; if (openchangedb_is_public_folder_id(emsmdbp_ctx->oc_ctx, parent_fid)) { retval = openchangedb_get_new_public_folderID(emsmdbp_ctx->oc_ctx, emsmdbp_ctx->username, &fid); } else { retval = mapistore_error_to_mapi(mapistore_indexing_get_new_folderID(emsmdbp_ctx->mstore_ctx, &fid)); } if (retval != MAPI_E_SUCCESS) { OC_DEBUG(4, "exchange_emsmdb: [OXCFOLD] Could not obtain a new folder id\n"); mapi_repl->error_code = MAPI_E_NO_SUPPORT; goto end; } retval = openchangedb_get_new_changeNumber(emsmdbp_ctx->oc_ctx, emsmdbp_ctx->username, &cn); if (retval != MAPI_E_SUCCESS) { OC_DEBUG(4, "exchange_emsmdb: [OXCFOLD] Could not obtain a new folder cn\n"); mapi_repl->error_code = MAPI_E_NO_SUPPORT; goto end; } aRow = libmapiserver_ROP_request_to_properties(mem_ctx, (void *)&mapi_req->u.mapi_CreateFolder, op_MAPI_CreateFolder); aRow->lpProps = add_SPropValue(mem_ctx, aRow->lpProps, &(aRow->cValues), PR_PARENT_FID, (void *)(&parent_fid)); cnValue.ulPropTag = PidTagChangeNumber; cnValue.value.d = cn; SRow_addprop(aRow, cnValue); retval = emsmdbp_object_create_folder(emsmdbp_ctx, parent_object, rec, fid, aRow, true, &object); if (retval != MAPI_E_SUCCESS) { OC_DEBUG(5, "folder creation failed\n"); mapi_handles_delete(emsmdbp_ctx->handles_ctx, rec->handle); mapi_repl->error_code = retval; goto end; } } handles[mapi_repl->handle_idx] = rec->handle; mapi_handles_set_private_data(rec, object); response->folder_id = fid; if (response->IsExistingFolder == true) { response->GhostUnion.GhostInfo.HasRules = false; response->GhostUnion.GhostInfo.IsGhosted = false; } end: *size += libmapiserver_RopCreateFolder_size(mapi_repl); if (aRow) { talloc_free(aRow); } return MAPI_E_SUCCESS; }
/** \details EcDoRpc EmptyFolder (0x58) Rop. This operation removes the sub-folders and messages from a given parent folder. \param mem_ctx pointer to the memory context \param emsmdbp_ctx pointer to the emsmdb provider context \param mapi_req pointer to the EmptyFolder EcDoRpc_MAPI_REQ structure \param mapi_repl pointer to the EmptyFolder EcDoRpc_MAPI_REPL structure \param handles pointer to the MAPI handles array \param size pointer to the mapi_response size to update \return MAPI_E_SUCCESS on success, otherwise MAPI error */ enum MAPISTATUS EcDoRpc_RopMoveFolder(TALLOC_CTX *mem_ctx, struct emsmdbp_context *emsmdbp_ctx, struct EcDoRpc_MAPI_REQ *mapi_req, struct EcDoRpc_MAPI_REPL *mapi_repl, uint32_t *handles, uint16_t *size) { enum MAPISTATUS retval; enum mapistore_error ret; uint32_t handle; struct mapi_handles *handle_object; void *private_data; struct MoveFolder_req *request; struct MoveFolder_repl *response; struct emsmdbp_object *source_parent; struct emsmdbp_object *move_folder; struct emsmdbp_object *target_folder; DEBUG(4, ("exchange_emsmdb: [OXCFOLD] MoveFolder (0x35)\n")); /* Sanity checks */ OPENCHANGE_RETVAL_IF(!emsmdbp_ctx, MAPI_E_NOT_INITIALIZED, NULL); OPENCHANGE_RETVAL_IF(!mapi_req, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!mapi_repl, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!handles, MAPI_E_INVALID_PARAMETER, NULL); OPENCHANGE_RETVAL_IF(!size, MAPI_E_INVALID_PARAMETER, NULL); mapi_repl->opnum = mapi_req->opnum; mapi_repl->handle_idx = mapi_req->handle_idx; mapi_repl->error_code = MAPI_E_SUCCESS; request = &mapi_req->u.mapi_MoveFolder; response = &mapi_repl->u.mapi_MoveFolder; /* Retrieve the source parent handle in the hierarchy */ handle = handles[mapi_req->handle_idx]; retval = mapi_handles_search(emsmdbp_ctx->handles_ctx, handle, &handle_object); if (retval) { DEBUG(5, (" handle (%x) not found: %x\n", handle, mapi_req->handle_idx)); mapi_repl->error_code = MAPI_E_INVALID_OBJECT; goto end; } mapi_handles_get_private_data(handle_object, &private_data); source_parent = private_data; if (!source_parent || source_parent->type != EMSMDBP_OBJECT_FOLDER) { DEBUG(5, (" invalid handle (%x): %x\n", handle, mapi_req->handle_idx)); mapi_repl->error_code = MAPI_E_INVALID_OBJECT; goto end; } /* Open the folder being moved as it will be the actor object in this process */ ret = emsmdbp_object_open_folder(mem_ctx, emsmdbp_ctx, source_parent, request->FolderId, &move_folder); if (ret != MAPISTORE_SUCCESS) { mapi_repl->error_code = mapistore_error_to_mapi(ret); goto end; } /* Retrieve the destination parent handle in the hierarchy */ handle = handles[request->handle_idx]; retval = mapi_handles_search(emsmdbp_ctx->handles_ctx, handle, &handle_object); if (retval) { DEBUG(5, (" handle (%x) not found: %x\n", handle, mapi_req->handle_idx)); mapi_repl->error_code = MAPI_E_INVALID_OBJECT; goto end; } mapi_handles_get_private_data(handle_object, &private_data); target_folder = private_data; if (!target_folder || target_folder->type != EMSMDBP_OBJECT_FOLDER) { DEBUG(5, (" invalid handle (%x): %x\n", handle, mapi_req->handle_idx)); mapi_repl->error_code = MAPI_E_INVALID_OBJECT; goto end; } ret = emsmdbp_folder_move_folder(emsmdbp_ctx, move_folder, target_folder, mem_ctx, request->NewFolderName.lpszW); mapi_repl->error_code = mapistore_error_to_mapi(ret); response->PartialCompletion = false; end: *size += libmapiserver_RopMoveFolder_size(mapi_repl); handles[mapi_repl->handle_idx] = handles[mapi_req->handle_idx]; return MAPI_E_SUCCESS; }