Exemple #1
0
_PUBLIC_ void mapidump_SRow(struct SRow *aRow, const char *sep)
{
	uint32_t		i;

	for (i = 0; i < aRow->cValues; i++) {
		mapidump_SPropValue(aRow->lpProps[i], sep);
	}
}
Exemple #2
0
static int process_response(TALLOC_CTX *mem_ctx,
			    const struct ndr_interface_call *f,
			    const char *filename,
			    struct SPropTagArray *SPropTagArray,
			    uint8_t opnum, int index)
{
	struct SPropValue	*lpProps = NULL;
	void			*st;
	uint8_t			*data;
	size_t			size = 0;
	DATA_BLOB		blob;
	enum ndr_err_code	ndr_err;
	struct ndr_pull		*ndr_pull;
	struct ndr_pull		*sndr_pull;
	struct EcDoRpcExt2	*r;
	struct mapi2k7_response	mapi2k7_response;
	struct mapi_response	*mapi_response;
	DATA_BLOB		rgbOut;
	int			index_out = -1;
	int			i, j;

	st = talloc_zero_size(mem_ctx, f->struct_size);
	if (!st) {
		DEBUG(0, ("Unable to allocate %d bytes\n", (int)f->struct_size));
		return -1;
	}

	data = (uint8_t *) file_load(filename, &size, 0, mem_ctx);
	if (!data) {
		perror(filename);
		return -1;
	}

	blob.data = data;
	blob.length = size;

	ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
	if (ndr_pull == NULL) {
		perror("ndr_pull_init_blob");
		return -1;
	}
	ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
	ndr_err = f->ndr_pull(ndr_pull, NDR_OUT, st);
	if (ndr_err) {
		DEBUG(0, ("Unable to pull response, ndr_err = 0x%x\n", ndr_err));
		return -1;
	}

	r = (struct EcDoRpcExt2 *) st;
	rgbOut.data = r->out.rgbOut;
	rgbOut.length = *r->out.pcbOut;

	sndr_pull = ndr_pull_init_blob(&rgbOut, mem_ctx);
	if (sndr_pull == NULL) {
		perror("ndr_pull_init_blob");
		return -1;
	}
	ndr_set_flags(&sndr_pull->flags, LIBNDR_FLAG_NOALIGN|LIBNDR_FLAG_REF_ALLOC);
	ndr_err = ndr_pull_mapi2k7_response(sndr_pull, NDR_SCALARS|NDR_BUFFERS, &mapi2k7_response);
	talloc_free(ndr_pull);
	if (ndr_err) {
		DEBUG(0, ("Unable to pull response, ndr_err = 0x%x\n", ndr_err));
		talloc_free(sndr_pull);
		return -1;
	}

	mapi_response = mapi2k7_response.mapi_response;

	switch (opnum) {
	case op_MAPI_GetProps:
	case op_MAPI_ModifyRecipients:
		if (mapi_response->mapi_repl[index].opnum != opnum) {
			DEBUG(0, ("Mismatching request vs reply\n"));
			talloc_free(sndr_pull);
			return -1;
		}
		break;
	case op_MAPI_SetColumns:
		for (i = 0; mapi_response->mapi_repl[i].opnum; i++) {
			if ((mapi_response->mapi_repl[i].opnum == op_MAPI_QueryRows) ||
			    (mapi_response->mapi_repl[i].opnum == op_MAPI_FindRow) ||
			    (mapi_response->mapi_repl[i].opnum == op_MAPI_ExpandRow)) {
				opnum = mapi_response->mapi_repl[i].opnum;
				index_out = i;
				break;
			}
		}
		if (index_out == -1) {
			DEBUG(0, ("Unable to find ROP QueryRows, FindRow or ExpandRow in the reply\n"));
			talloc_free(sndr_pull);
			return -1;
		}
		break;
	}

	switch (opnum) {
	case op_MAPI_GetProps:
	{
		struct GetProps_repl	*g;
		uint32_t		cn_propvals;

		g = &(mapi_response->mapi_repl[index].u.mapi_GetProps);
		emsmdb_get_SPropValue(mem_ctx, &g->prop_data, SPropTagArray,
				      &lpProps, &cn_propvals, g->layout);
		for (j = 0; j < SPropTagArray->cValues; j++) {
			mapidump_SPropValue(lpProps[j], "\t");
		}
	}
	break;
	case op_MAPI_ModifyRecipients:
	case op_MAPI_ExpandRow:
		DEBUG(0, ("Not implemented!\n"));
		return -1;
		break;
	case op_MAPI_FindRow:
	{
		uint32_t		offset = 0;
		uint32_t		cn_propvals;
		struct FindRow_repl	*repl;

		repl = &(mapi_response->mapi_repl[index_out].u.mapi_FindRow);
		if (!emsmdb_get_SPropValue_offset(mem_ctx, &repl->row,
						  SPropTagArray, &lpProps,
						  &cn_propvals, &offset)) {
			for (j = 0; j < SPropTagArray->cValues; j++) {
				mapidump_SPropValue(lpProps[j], "\t");
			}
			talloc_free(lpProps);
		}
	}
	break;
	case op_MAPI_QueryRows:
	{
		uint32_t		offset = 0;
		uint32_t		cn_propvals;
		struct QueryRows_repl	*repl;

		repl = &(mapi_response->mapi_repl[index_out].u.mapi_QueryRows);
		for (i = 0; i < repl->RowCount; i++) {
			if (!emsmdb_get_SPropValue_offset(mem_ctx, &repl->RowData, SPropTagArray,
							  &lpProps, &cn_propvals, &offset)) {
				DEBUG(0, ("\nrow %d:\n", i));
				for (j = 0; j < SPropTagArray->cValues; j++) {
					mapidump_SPropValue(lpProps[j], "\t");
				}
				talloc_free(lpProps);
			}
		}
	}
	break;
	}

	talloc_free(sndr_pull);
	return 0;
}
/**
   \details Test dump using mapidump_SPropValue

   This function:
   -# Tests the mapidump_SPropValue() function 

   \param mt pointer to the top-level mapitest structure

   \return true on success, otherwise false
   
   \note This currently doesn't check the results are sane, so manual inspection is required
*/ 
_PUBLIC_ bool mapitest_mapidump_spropvalue(struct mapitest *mt)
{
	struct SPropValue propvalue;
	struct FILETIME ft;
	struct Binary_r bin;
	struct StringArray_r mvstr;
	uint32_t i;

	propvalue.ulPropTag = PR_GENDER; /* enum MAPITAGS */
	propvalue.dwAlignPad = 0;
	propvalue.value.i = 3; /* union SPropValue_CTR */
	mapidump_SPropValue(propvalue, "[sep]");

	propvalue.ulPropTag = PR_SENSITIVITY; /* enum MAPITAGS */
	propvalue.dwAlignPad = 0;
	propvalue.value.l = 68000; /* union SPropValue_CTR */
	mapidump_SPropValue(propvalue, "[sep]");

	propvalue.ulPropTag = PR_REPLY_REQUESTED; /* enum MAPITAGS */
	propvalue.dwAlignPad = 0;
	propvalue.value.b = 1; /* union SPropValue_CTR */
	mapidump_SPropValue(propvalue, "[sep]");

	propvalue.ulPropTag = PidTagMemberId; /* enum MAPITAGS */
	propvalue.dwAlignPad = 0;
	propvalue.value.d = 0x3DEADBEEFCAFE124LL; /* union SPropValue_CTR */
	mapidump_SPropValue(propvalue, "[sep]");

	propvalue.ulPropTag = PR_SENDER_NAME; /* enum MAPITAGS */
	propvalue.dwAlignPad = 0;
	propvalue.value.lpszA = "Mr. The Sender"; /* union SPropValue_CTR */
	mapidump_SPropValue(propvalue, "[sep]");

	propvalue.ulPropTag = PR_REPORT_TAG; /* enum MAPITAGS */
	propvalue.dwAlignPad = 0;
	bin.cb = 12;
	bin.lpb = talloc_array(mt->mem_ctx, uint8_t, bin.cb);
	for (i = 0; i < bin.cb; ++i) {
		bin.lpb[i] = 0xF0 + i;
	}
	propvalue.value.bin = bin; /* union SPropValue_CTR */
	mapidump_SPropValue(propvalue, "[sep]");

	propvalue.ulPropTag = PidTagOriginalDeliveryTime ; /* enum MAPITAGS */
	propvalue.dwAlignPad = 0;
	ft.dwLowDateTime = 0x12345678;
	ft.dwHighDateTime = 0x01CA6AE4;
	propvalue.value.ft = ft; /* union SPropValue_CTR */
	mapidump_SPropValue(propvalue, "[sep]");

	propvalue.ulPropTag = PR_REPLY_TIME_ERROR; /* enum MAPITAGS */
	propvalue.dwAlignPad = 0;
	propvalue.value.err = MAPI_E_UNKNOWN_CPID; /* union SPropValue_CTR */
	mapidump_SPropValue(propvalue, "[sep]");

	propvalue.ulPropTag = PidTagScheduleInfoDelegateNames;
	propvalue.dwAlignPad = 0;
	mvstr.cValues = 3;
	mvstr.lppszA = talloc_array(mt->mem_ctx, const char *, mvstr.cValues);
	mvstr.lppszA[0] = talloc_strdup(mt->mem_ctx, "Foo");
	mvstr.lppszA[1] = talloc_strdup(mt->mem_ctx, "A longer string");
	mvstr.lppszA[2] = talloc_strdup(mt->mem_ctx, "All strung out on bugs");

	propvalue.value.MVszA = mvstr;
	mapidump_SPropValue(propvalue, "[sep]");

#if 0
	/* Types TODO */
	// int64_t dbl;/* [case(0x0005)] */
	// const char *lpszW;/* [unique,charset(UTF16),case(0x001f)] */
	// struct FlatUID_r *lpguid;/* [unique,case(0x0048)] */
	// struct ShortArray_r MVi;/* [case(0x1002)] */
	// struct LongArray_r MVl;/* [case(0x1003)] */
	// struct BinaryArray_r MVbin;/* [case(0x1102)] */
	// struct FlatUIDArray_r MVguid;/* [case(0x1048)] */
	// struct StringArrayW_r MVszW;/* [case(0x101f)] */
	// struct DateTimeArray_r MVft;/* [case(0x1040)] */
	// uint32_t object;/* [case(0x000d)] */
#endif

	propvalue.ulPropTag = 0xDDDD << 16 | PT_LONG; /* This isn't a real tag, just a test case */
	propvalue.dwAlignPad = 0;
	propvalue.value.l = 68020;
	mapidump_SPropValue(propvalue, "[sep]");

	return true;
}