Пример #1
0
static bool wrap_ndr_inout_pull_test(struct torture_context *tctx,
				     struct torture_tcase *tcase,
				     struct torture_test *test)
{
	bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
	const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
	void *ds = talloc_zero_size(tctx, data->struct_size);
	struct ndr_pull *ndr;
	uint32_t highest_ofs;

	/* handle NDR_IN context */

	ndr = ndr_pull_init_blob(&(data->data_context), tctx);
	torture_assert(tctx, ndr, "ndr init failed");

	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;

	torture_assert_ndr_success(tctx,
		data->pull_fn(ndr, NDR_IN, ds),
		"ndr pull of context failed");

	if (ndr->offset > ndr->relative_highest_offset) {
		highest_ofs = ndr->offset;
	} else {
		highest_ofs = ndr->relative_highest_offset;
	}

	torture_assert(tctx, highest_ofs == ndr->data_size,
		talloc_asprintf(tctx, "%d unread bytes", ndr->data_size - highest_ofs));

	talloc_free(ndr);

	/* handle NDR_OUT */

	ndr = ndr_pull_init_blob(&(data->data), tctx);
	torture_assert(tctx, ndr, "ndr init failed");

	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;

	torture_assert_ndr_success(tctx,
		data->pull_fn(ndr, NDR_OUT, ds),
		"ndr pull failed");

	if (ndr->offset > ndr->relative_highest_offset) {
		highest_ofs = ndr->offset;
	} else {
		highest_ofs = ndr->relative_highest_offset;
	}

	torture_assert(tctx, highest_ofs == ndr->data_size,
		talloc_asprintf(tctx, "%d unread bytes", ndr->data_size - highest_ofs));

	talloc_free(ndr);

	if (check_fn) {
		return check_fn(tctx, ds);
	} else {
		return true;
	}
}
Пример #2
0
static bool test_check_string_terminator(struct torture_context *tctx)
{
	struct ndr_pull *ndr;
	DATA_BLOB blob;
	TALLOC_CTX *mem_ctx = tctx;

	/* Simple test */
	blob = strhex_to_data_blob(tctx, "0000");

	ndr = ndr_pull_init_blob(&blob, mem_ctx);

	torture_assert_ndr_success(tctx, ndr_check_string_terminator(ndr, 1, 2),
				   "simple check_string_terminator test failed");

	torture_assert(tctx, ndr->offset == 0,
		"check_string_terminator did not reset offset");

	if (NDR_ERR_CODE_IS_SUCCESS(ndr_check_string_terminator(ndr, 1, 3))) {
		torture_fail(tctx, "check_string_terminator checked beyond string boundaries");
	}

	torture_assert(tctx, ndr->offset == 0,
		"check_string_terminator did not reset offset");

	talloc_free(ndr);

	blob = strhex_to_data_blob(tctx, "11220000");
	ndr = ndr_pull_init_blob(&blob, mem_ctx);

	torture_assert_ndr_success(tctx,
		ndr_check_string_terminator(ndr, 4, 1),
		"check_string_terminator failed to recognize terminator");

	torture_assert_ndr_success(tctx,
		ndr_check_string_terminator(ndr, 3, 1),
		"check_string_terminator failed to recognize terminator");

	if (NDR_ERR_CODE_IS_SUCCESS(ndr_check_string_terminator(ndr, 2, 1))) {
		torture_fail(tctx, "check_string_terminator erroneously reported terminator");
	}

	torture_assert(tctx, ndr->offset == 0,
		"check_string_terminator did not reset offset");
	return true;
}
Пример #3
0
static bool wrap_ndr_pullpush_test(struct torture_context *tctx,
				   struct torture_tcase *tcase,
				   struct torture_test *test)
{
	bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
	const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
	struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx);
	void *ds = talloc_zero_size(ndr, data->struct_size);
	bool ret;
	uint32_t highest_ofs;

	ndr->flags |= data->flags;

	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;

	torture_assert_ndr_success(tctx, data->pull_fn(ndr, data->ndr_flags, ds),
				   "pulling");

	if (ndr->offset > ndr->relative_highest_offset) {
		highest_ofs = ndr->offset;
	} else {
		highest_ofs = ndr->relative_highest_offset;
	}

	torture_assert(tctx, highest_ofs == ndr->data_size,
				   talloc_asprintf(tctx,
					   "%d unread bytes", ndr->data_size - highest_ofs));

	if (check_fn != NULL) {
		ret = check_fn(tctx, ds);
	} else {
		ret = true;
	}

	if (data->push_fn != NULL) {
		DATA_BLOB outblob;
		torture_assert_ndr_success(tctx, ndr_push_struct_blob(&outblob, ndr, ds, data->push_fn), "pushing");
		torture_assert_data_blob_equal(tctx, outblob, data->data, "ndr push compare");
	}

	talloc_free(ndr);
	return ret;
}
Пример #4
0
static bool ntprinting_printer_latin1_check(struct torture_context *tctx)
{
	enum ndr_err_code ndr_err;
	struct ntprinting_printer r;
	DATA_BLOB blob;
	bool ok;

	ok = lpcfg_do_global_parameter(tctx->lp_ctx, "dos charset", "CP1252");
	if (!ok) {
		torture_comment(tctx, "Could not set 'dos charset' option.\n");
		return false;
	}
	reload_charcnv(tctx->lp_ctx);

	ZERO_STRUCT(r);
	r.info.string_flags = LIBNDR_FLAG_STR_ASCII;

	blob = data_blob_const(ntprinting_printer_data_latin1,
			       sizeof(ntprinting_printer_data_latin1));

	ndr_err = ndr_pull_struct_blob(&blob, tctx, &r,
		   (ndr_pull_flags_fn_t)ndr_pull_ntprinting_printer);

	torture_assert_ndr_success(tctx,
				   ndr_err,
				   "ndr_pull_ntprinting_printer");
#if 0
	ndr_print_debug((ndr_print_fn_t) ndr_print_ntprinting_printer,
			"ntprinter",
			&r);
#endif
	torture_assert_str_equal(tctx,
				 r.info.printername,
				 "S0BC",
				 "printername");
	/* latin1 encoding check */
	torture_assert_str_equal(tctx,
				 r.info.comment,
				 "\" SALA DA RECEPÇÃO DA CONSTRUÇÃO - RAND0 LOCATIO",
				 "comment");
	torture_assert_str_equal(tctx,
				 r.info.location,
				 "UTGCA ",
				 "location");

	return true;
}
Пример #5
0
Файл: ndr.c Проект: endisd/samba
static bool wrap_ndr_pull_test(struct torture_context *tctx,
							   struct torture_tcase *tcase,
							   struct torture_test *test)
{
	bool (*check_fn) (struct torture_context *ctx, void *data) = test->fn;
	const struct ndr_pull_test_data *data = (const struct ndr_pull_test_data *)test->data;
	void *ds = talloc_zero_size(tctx, data->struct_size);
	struct ndr_pull *ndr = ndr_pull_init_blob(&(data->data), tctx, lp_iconv_convenience(tctx->lp_ctx));

	ndr->flags |= LIBNDR_FLAG_REF_ALLOC;

	torture_assert_ndr_success(tctx, data->pull_fn(ndr, data->ndr_flags, ds),
				   "pulling");

	torture_assert(tctx, ndr->offset == ndr->data_size, 
				   talloc_asprintf(tctx, 
					   "%d unread bytes", ndr->data_size - ndr->offset));

	if (check_fn != NULL) 
		return check_fn(tctx, ds);
	else
		return true;
}