summaryrefslogtreecommitdiff
path: root/source4/librpc/ndr/ndr_basic.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/librpc/ndr/ndr_basic.c')
-rw-r--r--source4/librpc/ndr/ndr_basic.c71
1 files changed, 71 insertions, 0 deletions
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);
+}