Added EnumPrinterDriver, GetPrinterDriver (still in progress)
authorTim Potter <tpot@samba.org>
Sun, 30 Nov 2003 11:57:40 +0000 (11:57 +0000)
committerTim Potter <tpot@samba.org>
Sun, 30 Nov 2003 11:57:40 +0000 (11:57 +0000)
(This used to be commit a818439b5915fd70b8aa3d3045f658b3f59a6bea)

source4/librpc/idl/spoolss.idl
source4/librpc/ndr/ndr_spoolss_buf.c
source4/torture/rpc/spoolss.c

index 69d929561bf498c92954653e7a8bbec53f0425c3..efec217fab70ee76d0ef0d28714b65575475cc8b 100644 (file)
 
        /******************/
        /* Function: 0x05 */
-       WERROR spoolss_05(
+       WERROR spoolss_AddPrinter(
+               /* This function is not implemented in Samba 3 as no
+                  clients have been observed using it. */
        );
 
        /******************/
        WERROR spoolss_09(
        );
 
+       typedef struct {
+               [relative] nstring *driver_name;
+       } spoolss_DriverInfo1;
+
+       typedef struct {
+               uint32 version;
+               [relative] nstring *driver_name;
+               [relative] nstring *architecture;
+               [relative] nstring *driver_path;
+               [relative] nstring *data_file;
+               [relative] nstring *config_file;
+       } spoolss_DriverInfo2;
+
+       typedef struct {
+               uint32 version;
+               [relative] nstring *driver_name;
+               [relative] nstring *architecture;
+               [relative] nstring *driver_path;
+               [relative] nstring *data_file;
+               [relative] nstring *config_file;
+               [relative] nstring *help_file;
+               [relative] nstring *dependent_files; /* array */
+               [relative] nstring *monitor_name;
+               [relative] nstring *default_datatype;
+       } spoolss_DriverInfo3;
+
+       typedef [nodiscriminant,public] union {
+               [case(1)] spoolss_DriverInfo1 info1;
+               [case(2)] spoolss_DriverInfo2 info2;
+               [case(3)] spoolss_DriverInfo3 info3;
+       } spoolss_DriverInfo;
+
        /******************/
        /* Function: 0x0a */
-       WERROR spoolss_0a(
+       WERROR spoolss_EnumPrinterDrivers(
+               [in] unistr *server,
+               [in] unistr *environment,
+               [in] uint32 level,
+               [in,out] DATA_BLOB *buffer,
+               [in,out,ref] uint32 *buf_size,
+               [out] uint32 count
        );
 
        /******************/
 
        /******************/
        /* Function: 0x0d */
-       WERROR spoolss_0d(
+       WERROR spoolss_DeletePrinterDriver(
+               [in,ref] policy_handle *handle,
+               [in] unistr *server,
+               [in] unistr architecture,
+               [in] unistr driver
        );
 
        /******************/
 
        /******************/
        /* Function: 0x35 */
-       WERROR spoolss_35(
+       WERROR spoolss_GetPrinterDriver2(
+               [in,ref] policy_handle *handle,
+               [in] unistr *architecture,
+               [in] uint32 level,
+               [in,out] DATA_BLOB *buffer,
+               [in,out,ref] uint32 *buf_size,
+               [in] uint32 client_major_version,
+               [in] uint32 client_minor_version,
+               [out] uint32 server_major_version,
+               [out] uint32 server_minor_version
        );
 
        /******************/
 
        /******************/
        /* Function: 0x46 */
-       WERROR spoolss_46(
+       WERROR spoolss_AddPrinterEx(
+               [in] unistr *server,
+               [in] uint32 level,
+               [in,switch_is(level)] spoolss_PrinterInfo *info,
+               [in] spoolss_DevmodeContainer devmode_ctr,
+               [in] security_descriptor *secdesc,
+               [in] uint32 ulevel,
+               [in,switch_is(ulevel)] spoolss_UserLevel userlevel
        );
 
        /******************/
index cd251112c0ce98364458c988555064c11c2bd4a3..d8a3f6a07e3dd58ee40c109ebbcb51ad66acfa5d 100644 (file)
@@ -74,3 +74,20 @@ NTSTATUS pull_spoolss_JobInfoArray(DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
        }
        return NT_STATUS_OK;
 }
+
+NTSTATUS pull_spoolss_DriverInfoArray(DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
+                                     uint32 level, uint32 count,
+                                     union spoolss_DriverInfo **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_DriverInfo(ndr, NDR_SCALARS|NDR_BUFFERS, level, &(*info)[i]));
+       }
+       return NT_STATUS_OK;
+}
index 802671c8e87b4e0c4a8a4fc70344e537d9e5c09d..2be1ddc0a28e38bb74e14ae5afeef37f259557df 100644 (file)
@@ -612,23 +612,26 @@ static BOOL test_OpenPrinter(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        return ret;
 }
 
-static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
-                              const char *name)
+static BOOL call_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+                              const char *name, struct policy_handle *handle)
 {
-       struct policy_handle handle;
        struct spoolss_OpenPrinterEx r;
        struct spoolss_UserLevel1 userlevel1;
        NTSTATUS status;
-       BOOL ret = True;
 
-       r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s", 
-                                          dcerpc_server_name(p), name);
+       if (name && name[0])
+               r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s", 
+                                                  dcerpc_server_name(p), name);
+       else
+               r.in.printername = talloc_asprintf(mem_ctx, "\\\\%s", 
+                                                  dcerpc_server_name(p));
+
        r.in.datatype = NULL;
        r.in.devmode_ctr.size = 0;
        r.in.devmode_ctr.devmode = NULL;
        r.in.access_required = 0x02000000;
        r.in.level = 1;
-       r.out.handle = &handle;
+       r.out.handle = handle;
 
        userlevel1.size = 1234;
        userlevel1.client = "hello";
@@ -647,12 +650,25 @@ static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
                printf("OpenPrinterEx failed - %s\n", nt_errstr(status));
                return False;
        }
-
+       
        if (!W_ERROR_IS_OK(r.out.result)) {
                printf("OpenPrinterEx failed - %s\n", win_errstr(r.out.result));
                return False;
        }
 
+       return True;
+}
+
+static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+                              const char *name)
+{
+       struct policy_handle handle;
+       BOOL ret = True;
+
+       if (!call_OpenPrinterEx(p, mem_ctx, name, &handle)) {
+               return False;
+       }
+
        if (!test_GetPrinter(p, mem_ctx, &handle)) {
                ret = False;
        }
@@ -680,11 +696,10 @@ static BOOL test_OpenPrinterEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
        if (!test_ClosePrinter(p, mem_ctx, &handle)) {
                ret = False;
        }
-
+       
        return ret;
 }
 
-
 static BOOL test_EnumPrinters(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
 {
        struct spoolss_EnumPrinters r;
@@ -763,6 +778,136 @@ static BOOL test_EnumPrinters(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
        return ret;
 }
 
+static BOOL test_GetPrinterDriver2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+                                  struct policy_handle *handle, char *driver_name)
+{
+       NTSTATUS status;
+       struct spoolss_GetPrinterDriver2 r;
+       uint32 buf_size;
+
+       r.in.handle = handle;
+       r.in.architecture = "W32X86";
+       r.in.level = 1;
+       buf_size = 0;
+       r.in.buf_size = r.out.buf_size = &buf_size;
+       r.in.client_major_version = 0;
+       r.in.client_minor_version = 0;
+
+       printf("Testing GetPrinterDriver2\n");
+
+       status = dcerpc_spoolss_GetPrinterDriver2(p, mem_ctx, &r);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("GetPrinterDriver2 failed - %s\n", nt_errstr(status));
+               return False;
+       }
+
+       if (W_ERROR_EQUAL(r.out.result, WERR_INSUFFICIENT_BUFFER)) {
+               status = dcerpc_spoolss_GetPrinterDriver2(p, mem_ctx, &r);
+       }
+               
+       if (!NT_STATUS_IS_OK(status) ||
+           !W_ERROR_IS_OK(r.out.result)) {
+               printf("GetPrinterDriver2 failed - %s/%s\n", 
+                      nt_errstr(status), win_errstr(r.out.result));
+               return False;
+       }
+
+       return True;
+}
+       
+static BOOL test_EnumPrinterDrivers(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
+{
+       struct spoolss_EnumPrinterDrivers r;
+       NTSTATUS status;
+       uint16 levels[] = {1, 2, 3};
+       int i;
+       BOOL ret = True;
+
+       for (i=0;i<ARRAY_SIZE(levels);i++) {
+               uint32 buf_size;
+               char *server;
+               union spoolss_DriverInfo *info;
+               uint32 j;
+
+               asprintf(&server, "\\\\%s", dcerpc_server_name(p));
+               r.in.server = server;
+               r.in.environment = "Windows NT x86";
+               r.in.level = levels[i];
+               r.in.buffer = NULL;
+               buf_size = 0;
+               r.in.buf_size = &buf_size;
+               r.out.buf_size = &buf_size;
+
+               printf("\nTesting EnumPrinterDrivers level %u\n", r.in.level);
+
+               status = dcerpc_spoolss_EnumPrinterDrivers(p, mem_ctx, &r);
+
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("EnumPrinterDrivers failed - %s\n", 
+                              nt_errstr(status));
+                       ret = False;
+                       continue;
+               }
+               
+               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_EnumPrinterDrivers(
+                               p, mem_ctx, &r);
+               }
+               
+               if (!NT_STATUS_IS_OK(status) ||
+                   !W_ERROR_IS_OK(r.out.result)) {
+                       printf("EnumPrinterDrivers failed - %s/%s\n", 
+                              nt_errstr(status), win_errstr(r.out.result));
+                       goto done;
+               }
+
+               if (!r.out.buffer) {
+                       printf("No printer drivers returned");
+                       goto done;
+               }
+
+               status = pull_spoolss_DriverInfoArray(
+                       r.out.buffer, mem_ctx, r.in.level, r.out.count, &info);
+
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("EnumPrinterDriverArray parse failed - %s\n", 
+                              nt_errstr(status));
+                       continue;
+               }
+
+               for (j=0;j<r.out.count;j++) {
+                       printf("Printer driver %d\n", j);
+                       NDR_PRINT_UNION_DEBUG(
+                               spoolss_DriverInfo, r.in.level, 
+                               &info[j]);
+
+                       if (r.in.level == 1) {
+                               struct policy_handle handle;
+
+                               if (!call_OpenPrinterEx(
+                                           p, mem_ctx, "",
+                                           &handle))
+                                       continue;
+
+                               test_GetPrinterDriver2(
+                                       p, mem_ctx, &handle, 
+                                       info[j].info1.driver_name);
+                       }
+               }
+
+       done:
+               free(server);
+       }
+       
+       return ret;
+}
+
 BOOL torture_rpc_spoolss(int dummy)
 {
         NTSTATUS status;
@@ -786,6 +931,10 @@ BOOL torture_rpc_spoolss(int dummy)
                ret = False;
        }
 
+       if (!test_EnumPrinterDrivers(p, mem_ctx)) {
+               ret = False;
+       }
+
        talloc_destroy(mem_ctx);
 
         torture_rpc_close(p);