NTSTATUS samdb_result_parameters(TALLOC_CTX *mem_ctx,
				 struct ldb_message *msg,
				 const char *attr,
				 struct lsa_BinaryString *s)
{
	int i;
	const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr);

	ZERO_STRUCTP(s);

	if (!val) {
		return NT_STATUS_OK;
	}

	if ((val->length % 2) != 0) {
		/*
		 * If the on-disk data is not even in length, we know
		 * it is corrupt, and can not be safely pushed.  We
		 * would either truncate, send either a un-initilaised
		 * byte or send a forced zero byte
		 */
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	s->array = talloc_array(mem_ctx, uint16_t, val->length/2);
	if (!s->array) {
		return NT_STATUS_NO_MEMORY;
	}
	s->length = s->size = val->length;

	/* The on-disk format is the 'network' format, being UTF16LE (sort of) */
	for (i = 0; i < s->length / 2; i++) {
		s->array[i] = SVAL(val->data, i * 2);
	}

	return NT_STATUS_OK;
}
NTSTATUS samdb_result_parameters(TALLOC_CTX *mem_ctx,
				 struct ldb_message *msg,
				 const char *attr,
				 struct lsa_BinaryString *s)
{
	int i;
	const struct ldb_val *val = ldb_msg_find_ldb_val(msg, attr);

	ZERO_STRUCTP(s);

	if (!val) {
		return NT_STATUS_OK;
	}

	if ((val->length % 2) != 0) {
		 
		return NT_STATUS_INTERNAL_DB_CORRUPTION;
	}

	s->array = talloc_array(mem_ctx, uint16_t, val->length/2);
	if (!s->array) {
		return NT_STATUS_NO_MEMORY;
	}
	s->length = s->size = val->length;

	 
	for (i = 0; i < s->length / 2; i++) {
		s->array[i] = SVAL(val->data, i * 2);
	}

	return NT_STATUS_OK;
}