/** \details Test #1863 NspiQueryRows and try to build PR_ENTRYID for AD user which is not part of OpenChange. \param mt pointer to the top level mapitest structure \return true on success, otherwise false */ _PUBLIC_ bool mapitest_zentyal_1863(struct mapitest *mt) { TALLOC_CTX *mem_ctx; enum MAPISTATUS retval; struct nspi_context *nspi_ctx; struct PropertyTagArray_r *MIds; struct PropertyRowSet_r *RowSet; struct SPropTagArray *SPropTagArray; struct PropertyValue_r *lpProp; struct Restriction_r Filter; mem_ctx = talloc_named(NULL, 0, "mapitest_zentyal_1863"); nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx; /* Build the array of columns we want to retrieve */ SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, PR_DISPLAY_NAME, PR_DISPLAY_TYPE); /* Build the restriction we want for NspiGetMatches on * existing AD user but not OpenChange one */ lpProp = talloc_zero(mem_ctx, struct PropertyValue_r); lpProp->ulPropTag = PR_ACCOUNT; lpProp->dwAlignPad = 0; lpProp->value.lpszA = talloc_strdup(lpProp, mt->profile->username); Filter.rt = RES_PROPERTY; Filter.res.resProperty.relop = RES_PROPERTY; Filter.res.resProperty.ulPropTag = PR_ACCOUNT; Filter.res.resProperty.lpProp = lpProp; RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r); MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r); retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds); MAPIFreeBuffer(lpProp); MAPIFreeBuffer(RowSet); MAPIFreeBuffer(SPropTagArray); mapitest_print_retval_clean(mt, "NspiGetMatches", retval); if (retval != MAPI_E_SUCCESS) { talloc_free(mem_ctx); return false; } /* Query the rows */ SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_ENTRYID); RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r); retval = nspi_QueryRows(nspi_ctx, mem_ctx, SPropTagArray, MIds, 1, &RowSet); MAPIFreeBuffer(SPropTagArray); MAPIFreeBuffer(RowSet); mapitest_print_retval_clean(mt, "NspiQueryRows", retval); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(MIds); talloc_free(mem_ctx); return false; } talloc_free(mem_ctx); return true; }
/** \details Test the NspiGetPropList RPC operation (0x08) \param mt pointer on the top-level mapitest structure \return true on success, otherwise false */ _PUBLIC_ bool mapitest_nspi_GetPropList(struct mapitest *mt) { TALLOC_CTX *mem_ctx; enum MAPISTATUS retval; struct nspi_context *nspi_ctx; struct SPropTagArray *pPropTags = 0; struct PropertyTagArray_r *MIds; struct PropertyValue_r *lpProp; struct Restriction_r Filter; struct SPropTagArray *SPropTagArray; struct PropertyRowSet_r *RowSet; mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_GetPropList"); nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx; /* Step 1. Query for current profile username */ SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_DISPLAY_NAME); lpProp = talloc_zero(mem_ctx, struct PropertyValue_r); lpProp->ulPropTag = PR_ANR_UNICODE; lpProp->dwAlignPad = 0; lpProp->value.lpszW = mt->mapi_ctx->session->profile->username; Filter.rt = RES_PROPERTY; Filter.res.resProperty.relop = RES_PROPERTY; Filter.res.resProperty.ulPropTag = PR_ANR_UNICODE; Filter.res.resProperty.lpProp = lpProp; RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r); MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r); retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds); MAPIFreeBuffer(SPropTagArray); MAPIFreeBuffer(lpProp); MAPIFreeBuffer(RowSet); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(MIds); talloc_free(mem_ctx); return retval; } /* Step 2. Call NspiGetPropList using the MId returned by NspiGetMatches */ pPropTags = talloc_zero(mt->mem_ctx, struct SPropTagArray); retval = nspi_GetPropList(nspi_ctx, mem_ctx, 0, MIds->aulPropTag[0], &pPropTags); MAPIFreeBuffer(MIds); mapitest_print_retval(mt, "NspiGetPropList"); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(pPropTags); talloc_free(mem_ctx); return false; } if (pPropTags) { mapitest_print(mt, "* %-35s: %d\n", "Properties number", pPropTags->cValues); MAPIFreeBuffer(pPropTags); } talloc_free(mem_ctx); return true; }
/** \details Test the NspiModProps RPC operation (0xb) \param mt pointer on the top-level mapitest structure \return true on success, otherwise false */ _PUBLIC_ bool mapitest_nspi_ModProps(struct mapitest *mt) { TALLOC_CTX *mem_ctx; enum MAPISTATUS retval; struct nspi_context *nspi_ctx; struct PropertyRow_r *pRow; struct SPropTagArray *pPropTags; struct PropertyValue_r modProp; struct PropertyTagArray_r *MIds; struct PropertyRowSet_r *RowSet; struct SPropTagArray *SPropTagArray; struct PropertyValue_r *lpProp; struct Restriction_r Filter; const char *original_office_location; bool ret = true; mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_ModProps"); nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx; /* Build the array of columns we want to retrieve */ SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, PR_DISPLAY_NAME, PR_DISPLAY_TYPE); /* Build the restriction we want for NspiGetMatches */ lpProp = talloc_zero(mem_ctx, struct PropertyValue_r); lpProp->ulPropTag = PR_ACCOUNT; lpProp->dwAlignPad = 0; lpProp->value.lpszA = mt->mapi_ctx->session->profile->username; Filter.rt = RES_PROPERTY; Filter.res.resProperty.relop = RES_PROPERTY; Filter.res.resProperty.ulPropTag = PR_ACCOUNT; Filter.res.resProperty.lpProp = lpProp; RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r); MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r); retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds); MAPIFreeBuffer(lpProp); MAPIFreeBuffer(RowSet); MAPIFreeBuffer(SPropTagArray); mapitest_print_retval_clean(mt, "nspi_GetMatches", retval); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(MIds); talloc_free(mem_ctx); return false; } /* Query the rows */ RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r); retval = nspi_QueryRows(nspi_ctx, mem_ctx, NULL, MIds, 1, &RowSet); mapitest_print_retval_clean(mt, "nspi_QueryRows", retval); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(MIds); MAPIFreeBuffer(RowSet); talloc_free(mem_ctx); return false; } if (RowSet->cRows != 1) { mapitest_print(mem_ctx, "unexpected number of rows: %i\n", RowSet->cRows); MAPIFreeBuffer(MIds); MAPIFreeBuffer(RowSet); talloc_free(mem_ctx); return false; } original_office_location = (const char *)find_PropertyValue_data(&(RowSet->aRow[0]), PR_OFFICE_LOCATION); mapitest_print(mt, "original PR_OFFICE_LOCATION value: %s\n", original_office_location); /* Build the SRow and SPropTagArray for NspiModProps */ pRow = talloc_zero(mem_ctx, struct PropertyRow_r); modProp.ulPropTag = PR_OFFICE_LOCATION; modProp.value.lpszA = "MT office location"; PropertyRow_addprop(pRow, modProp); pPropTags = set_SPropTagArray(mem_ctx, 0x1, PR_OFFICE_LOCATION); retval = nspi_ModProps(nspi_ctx, mem_ctx, MIds->aulPropTag[0], pPropTags, pRow); mapitest_print_retval_clean(mt, "nspi_ModProps", retval); MAPIFreeBuffer(pRow); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(MIds); MAPIFreeBuffer(pPropTags); talloc_free(mem_ctx); return false; } /* Check that the property was set correctly */ RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r); retval = nspi_QueryRows(nspi_ctx, mem_ctx, NULL, MIds, 1, &RowSet); mapitest_print_retval_clean(mt, "nspi_QueryRows", retval); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(MIds); MAPIFreeBuffer(RowSet); talloc_free(mem_ctx); return false; } if (RowSet->cRows != 1) { mapitest_print(mem_ctx, "unexpected number of rows: %i\n", RowSet->cRows); MAPIFreeBuffer(MIds); MAPIFreeBuffer(RowSet); talloc_free(mem_ctx); return false; } if (strcmp((const char *)find_PropertyValue_data(&(RowSet->aRow[0]), PR_OFFICE_LOCATION), "MT office location") != 0) { mapitest_print(mt, "PR_OFFICE_LOCATION string value mismatch: %s", (const char *)find_PropertyValue_data(&(RowSet->aRow[0]), PR_OFFICE_LOCATION)); ret = false; } else { mapitest_print(mt, "correctly set PR_OFFICE_LOCATION\n"); } /* try to reset the office location back to the original value */ pRow = talloc_zero(mem_ctx, struct PropertyRow_r); modProp.ulPropTag = PR_OFFICE_LOCATION; modProp.value.lpszA = original_office_location; PropertyRow_addprop(pRow, modProp); retval = nspi_ModProps(nspi_ctx, mem_ctx, MIds->aulPropTag[0], pPropTags, pRow); mapitest_print_retval_clean(mt, "nspi_ModProps (reset original value)", retval); if (retval != MAPI_E_SUCCESS) { ret = false; } MAPIFreeBuffer(MIds); MAPIFreeBuffer(pPropTags); MAPIFreeBuffer(pRow); talloc_free(mem_ctx); return ret; }
/** \details Test the NspiCompareMIds RPC operation (0x0a) \param mt pointer to the top-level mapitest structure \return true on success, otherwise false */ _PUBLIC_ bool mapitest_nspi_CompareMIds(struct mapitest *mt) { TALLOC_CTX *mem_ctx; enum MAPISTATUS retval; struct nspi_context *nspi_ctx; uint32_t plResult; struct PropertyTagArray_r *MIds; struct PropertyRowSet_r *RowSet; struct SPropTagArray *SPropTagArray; struct PropertyValue_r *lpProp; struct Restriction_r Filter; mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_CompareMIds"); nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx; /* Build the array of columns we want to retrieve */ SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_DISPLAY_NAME); /* Build the restriction we want for NspiGetMatches */ lpProp = talloc_zero(mem_ctx, struct PropertyValue_r); lpProp->ulPropTag = PR_OBJECT_TYPE; lpProp->dwAlignPad = 0; lpProp->value.l = 6; Filter.rt = RES_PROPERTY; Filter.res.resProperty.relop = RES_PROPERTY; Filter.res.resProperty.ulPropTag = PR_OBJECT_TYPE; Filter.res.resProperty.lpProp = lpProp; RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r); MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r); retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds); MAPIFreeBuffer(lpProp); MAPIFreeBuffer(SPropTagArray); MAPIFreeBuffer(RowSet); mapitest_print_retval_clean(mt, "NspiGetMatches", retval); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(MIds); talloc_free(mem_ctx); return false; } /* Ensure we have at least two result to compare */ if (MIds->cValues < 2) { mapitest_print(mt, "* Only one result found, can't compare\n"); MAPIFreeBuffer(MIds); talloc_free(mem_ctx); return false; } retval = nspi_CompareMIds(nspi_ctx, mem_ctx, MIds->aulPropTag[0], MIds->aulPropTag[1], &plResult); mapitest_print_retval_clean(mt, "NspiCompareMIds", retval); MAPIFreeBuffer(MIds); if (retval != MAPI_E_SUCCESS) { talloc_free(mem_ctx); return false; } mapitest_print(mt, "* %-35s: %d\n", "value of the comparison", plResult); talloc_free(mem_ctx); return true; }
/** \details Test the NspiResortRestriction RPC operation (0x6) \param mt pointer on the top-level mapitest structure \return true on success, otherwise false */ _PUBLIC_ bool mapitest_nspi_ResortRestriction(struct mapitest *mt) { TALLOC_CTX *mem_ctx; enum MAPISTATUS retval; struct nspi_context *nspi_ctx; struct Restriction_r Filter; struct PropertyRowSet_r *RowSet = NULL; struct SPropTagArray *SPropTagArray = NULL; struct PropertyValue_r *lpProp = NULL; struct PropertyTagArray_r *MIds = NULL; struct PropertyTagArray_r *ppMIds = NULL; bool ret = true; mem_ctx = talloc_named(NULL, 0, "mapitest_nspi_ResortRestriction"); nspi_ctx = (struct nspi_context *) mt->session->nspi->ctx; /* Build the array of columns we want to retrieve */ SPropTagArray = set_SPropTagArray(mem_ctx, 0xb, PR_DISPLAY_NAME, PR_OFFICE_TELEPHONE_NUMBER, PR_OFFICE_LOCATION, PR_TITLE, PR_COMPANY_NAME, PR_ACCOUNT, PR_ADDRTYPE, PR_ENTRYID, PR_DISPLAY_TYPE, PR_INSTANCE_KEY, PR_EMAIL_ADDRESS ); /* Build the restriction we want for NspiGetMatches */ lpProp = talloc_zero(mem_ctx, struct PropertyValue_r); lpProp->ulPropTag = PR_OBJECT_TYPE; lpProp->dwAlignPad = 0; lpProp->value.l = 6; Filter.rt = RES_PROPERTY; Filter.res.resProperty.relop = RES_PROPERTY; Filter.res.resProperty.ulPropTag = PR_OBJECT_TYPE; Filter.res.resProperty.lpProp = lpProp; RowSet = talloc_zero(mem_ctx, struct PropertyRowSet_r); MIds = talloc_zero(mem_ctx, struct PropertyTagArray_r); retval = nspi_GetMatches(nspi_ctx, mem_ctx, SPropTagArray, &Filter, 5000, &RowSet, &MIds); MAPIFreeBuffer(lpProp); MAPIFreeBuffer(SPropTagArray); MAPIFreeBuffer(RowSet); mapitest_print_retval_clean(mt, "NspiGetMatches", retval); if (retval != MAPI_E_SUCCESS) { MAPIFreeBuffer(MIds); talloc_free(mem_ctx); return false; } ppMIds = talloc_zero(mem_ctx, struct PropertyTagArray_r); retval = nspi_ResortRestriction(nspi_ctx, mem_ctx, SortTypeDisplayName, MIds, &ppMIds); mapitest_print_retval_clean(mt, "NspiResortRestriction", retval); if (retval != MAPI_E_SUCCESS) { ret = false; } MAPIFreeBuffer(MIds); MAPIFreeBuffer(ppMIds); talloc_free(mem_ctx); return ret; }