Implemented EnumForms and GetForm.
authorTim Potter <tpot@samba.org>
Wed, 26 Nov 2003 06:26:18 +0000 (06:26 +0000)
committerTim Potter <tpot@samba.org>
Wed, 26 Nov 2003 06:26:18 +0000 (06:26 +0000)
source/librpc/idl/spoolss.idl
source/librpc/ndr/ndr_spoolss_buf.c
source/torture/rpc/spoolss.c

index 14cb3ed441f2715282754f9184a01a7ce8d2773b..2c318ce4a15673042cde61e1c9e32bf1294442c2 100644 (file)
                [relative] nstring *comment;
        } spoolss_PrinterInfo1;
 
+       typedef struct {
+               uint32 flags;
+               [relative] nstring *name;
+               uint32 width;
+               uint32 length;
+               uint32 left;
+               uint32 top;
+               uint32 right;
+               uint32 bottom;
+       } spoolss_FormInfo1;
+
        typedef struct {
                [relative] nstring *servername;
                [relative] nstring *printername;
                [in,ref] policy_handle *handle,
                [in] unistr formname,
                [in] uint32 level,
-               [out,subcontext(4),switch_is(level)] spoolss_PrinterInfo *info,
+               [in] DATA_BLOB *buffer,
+               [out,subcontext(4),switch_is(level)] spoolss_FormInfo *info,
                [in,out,ref] uint32 *buf_size
        );
 
        WERROR spoolss_21(
        );
 
+       typedef [nodiscriminant,public] union {
+               [case(1)] spoolss_FormInfo1 info1;
+       } spoolss_FormInfo;
+
        /******************/
        /* Function: 0x22 */
        WERROR spoolss_EnumForms(
                [in,ref] policy_handle *handle,
                [in] uint32 level,
-               [in]         DATA_BLOB *buffer,
-               [out,subcontext(4),switch_is(level)] spoolss_PrinterInfo *info,
-               [in,out,ref] uint32 *buf_size
+               [in,out] DATA_BLOB *buffer,
+               [in,out,ref] uint32 *buf_size,
+               [out] uint32 count
        );
 
        /******************/
index 381093a58f08d644668cb85820a5857b5810faca..6c12ab2ae572b7fb4c4362d1af1b6e663ec64e86 100644 (file)
@@ -40,3 +40,20 @@ NTSTATUS pull_spoolss_PrinterInfoArray(DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
        }
        return NT_STATUS_OK;
 }
+
+NTSTATUS pull_spoolss_FormInfoArray(DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
+                                   uint32 level, uint32 count,
+                                   union spoolss_FormInfo **info)
+{
+       int i;
+       struct ndr_pull *ndr;
+       ndr = ndr_pull_init_blob(blob, mem_ctx);
+       if (!ndr) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       NDR_ALLOC_N(ndr, *info, count);
+       for (i=0;i<count;i++) {
+               NDR_CHECK(ndr_pull_spoolss_FormInfo(ndr, NDR_SCALARS|NDR_BUFFERS, level, &(*info)[i]));
+       }
+       return NT_STATUS_OK;
+}
index 166be85d57009ec40320885a1a7afb0f2e584a39..6913290d1aa8cc8df084d3744958c5134526dc72 100644 (file)
@@ -87,6 +87,108 @@ BOOL test_ClosePrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        return True;
 }
 
+BOOL test_GetForm(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+                 struct policy_handle *handle, char *formname)
+{
+       NTSTATUS status;
+       struct spoolss_GetForm r;
+       uint32 buf_size;
+
+       r.in.handle = handle;
+       r.in.formname = formname;
+       r.in.level = 1;
+       r.in.buffer = NULL;
+       buf_size = 0;
+       r.in.buf_size = r.out.buf_size = &buf_size;
+
+       printf("Testing GetForm\n");
+
+       status = dcerpc_spoolss_GetForm(p, mem_ctx, &r);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("GetForm failed - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
+               DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
+
+               data_blob_clear(&blob);
+               r.in.buffer = &blob;
+
+               status = dcerpc_spoolss_GetForm(p, mem_ctx, &r);
+
+               if (!r.out.info) {
+                       printf("No form info returned");
+                       return False;
+               }
+       }
+
+       return True;
+}
+
+BOOL test_EnumForms(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+                   struct policy_handle *handle)
+{
+       NTSTATUS status;
+       struct spoolss_EnumForms r;
+       uint32 buf_size;
+
+       r.in.handle = handle;
+       r.in.level = 1;
+       r.in.buffer = NULL;
+       buf_size = 0;
+       r.in.buf_size = &buf_size;
+       r.out.buf_size = &buf_size;
+
+       printf("Testing EnumForms\n");
+
+       status = dcerpc_spoolss_EnumForms(p, mem_ctx, &r);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("EnumForms failed - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
+               DATA_BLOB blob = data_blob_talloc(mem_ctx, NULL, buf_size);
+               union spoolss_FormInfo *info;
+               int j;
+
+               data_blob_clear(&blob);
+               r.in.buffer = &blob;
+
+               status = dcerpc_spoolss_EnumForms(p, mem_ctx, &r);
+
+               if (!r.out.buffer) {
+                       printf("No forms returned");
+                       return False;
+               }
+
+               status = pull_spoolss_FormInfoArray(r.out.buffer, mem_ctx, r.in.level, r.out.count, &info);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("EnumFormsArray parse failed - %s\n", nt_errstr(status));
+                       return False;
+               }
+
+               for (j=0;j<r.out.count;j++) {
+                       printf("Form %d\n", j);
+                       NDR_PRINT_UNION_DEBUG(spoolss_FormInfo, r.in.level, &info[j]);
+               }
+
+               for (j = 0; j < r.out.count; j++)
+                       test_GetForm(p, mem_ctx, handle, info[j].info1.name);
+       }
+
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
+               printf("EnumForms failed - %s/%s\n", 
+                      nt_errstr(status), win_errstr(r.out.result));
+               return False;
+       }
+
+       return True;
+}
+
 BOOL test_EnumPrinterData(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                          struct policy_handle *handle)
 {
@@ -212,6 +314,10 @@ static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                ret = False;
        }
 
+       if (!test_EnumForms(p, mem_ctx, &handle)) {
+               ret = False;
+       }
+
        if (!test_EnumPrinterData(p, mem_ctx, &handle)) {
                ret = False;
        }