From ea266c0625e04a2dc10d25c2fee7b685965fcd3e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Nov 2003 11:36:59 +0000 Subject: added support for level1 of EnumPrinters in spoolss. This uses a number of "magic" add-ons to IDL to make it less painful, hopefully this will make IDL generation useful for horrible systems like spoolss (This used to be commit e18dba7d5a957ef82e8f91733a0bf95d579dcd7a) --- source4/librpc/ndr/ndr_basic.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'source4/librpc/ndr/ndr_basic.c') diff --git a/source4/librpc/ndr/ndr_basic.c b/source4/librpc/ndr/ndr_basic.c index 31e16b6812..ece496ebde 100644 --- a/source4/librpc/ndr/ndr_basic.c +++ b/source4/librpc/ndr/ndr_basic.c @@ -512,3 +512,74 @@ void ndr_print_GUID(struct ndr_print *ndr, const char *name, struct GUID *guid) } +/* + pull a spoolss style "relative string" +*/ +NTSTATUS ndr_pull_relstr(struct ndr_pull *ndr, int ndr_flags, const char **s) +{ + uint32 ofs; + int ret; + struct ndr_pull_save save; + + if (!(ndr_flags & NDR_SCALARS)) { + return NT_STATUS_OK; + } + + NDR_CHECK(ndr_pull_uint32(ndr, &ofs)); + ndr_pull_save(ndr, &save); + NDR_CHECK(ndr_pull_set_offset(ndr, ofs)); + ret = convert_string_talloc(ndr->mem_ctx, CH_UCS2, CH_UNIX, + ndr->data+ndr->offset, + ndr->data_size - ndr->offset, + (const void **)s); + if (ret == -1) { + return ndr_pull_error(ndr, NDR_ERR_RELSTR, "Bad relative string"); + } + ndr_pull_restore(ndr, &save); + return NT_STATUS_OK; +} + +/* + push a spoolss style "relative string" +*/ +NTSTATUS ndr_push_relstr(struct ndr_push *ndr, int ndr_flags, const char **s) +{ + struct ndr_push_save *save; + if (ndr_flags & NDR_SCALARS) { + save = talloc(ndr->mem_ctx, sizeof(*save)); + if (!save) return NT_STATUS_NO_MEMORY; + NDR_CHECK(ndr_push_align(ndr, 4)); + ndr_push_save(ndr, save); + NDR_CHECK(ndr_push_uint32(ndr, 0xFFFFFFFF)); + save->next = ndr->relstr_list; + ndr->relstr_list = save; + } + if (ndr_flags & NDR_BUFFERS) { + struct ndr_push_save save2; + uint32 len; + int ret; + save = ndr->relstr_list; + if (!save) { + return ndr_push_error(ndr, NDR_ERR_RELSTR, "Empty relstr stack"); + } + ndr->relstr_list = save->next; + NDR_CHECK(ndr_push_align(ndr, 2)); + ndr_push_save(ndr, &save2); + ndr_push_restore(ndr, save); + NDR_CHECK(ndr_push_uint32(ndr, save2.offset)); + ndr_push_restore(ndr, &save2); + len = 2*(strlen_m(*s)+1); + NDR_PUSH_NEED_BYTES(ndr, len); + ret = push_ucs2(NULL, ndr->data + ndr->offset, *s, len, STR_TERMINATE); + if (ret == -1) { + return ndr_push_error(ndr, NDR_ERR_CHARCNV, "Bad string conversion"); + } + ndr->offset += len; + } + return NT_STATUS_OK; +} + +void ndr_print_relstr(struct ndr_print *ndr, const char *name, const char **s) +{ + ndr_print_unistr(ndr, name, *s); +} -- cgit