s3:printing: use dcerpc_spoolss_X() functions
authorStefan Metzmacher <metze@samba.org>
Sat, 15 Jan 2011 11:06:09 +0000 (12:06 +0100)
committerAndreas Schneider <asn@samba.org>
Fri, 21 Jan 2011 12:14:49 +0000 (13:14 +0100)
metze

Signed-off-by: Andreas Schneider <asn@samba.org>
Autobuild-User: Andreas Schneider <asn@samba.org>
Autobuild-Date: Fri Jan 21 13:14:49 CET 2011 on sn-devel-104

source3/printing/nt_printing_migrate.c
source3/printing/printspoolss.c

index c6466767e58335560d1df08d17cd9d9221433aae..61fb9a602ba44bd6093c6609d69777f4eea20327 100644 (file)
@@ -22,7 +22,7 @@
 #include "printing/nt_printing_migrate.h"
 
 #include "librpc/gen_ndr/ndr_ntprinting.h"
 #include "printing/nt_printing_migrate.h"
 
 #include "librpc/gen_ndr/ndr_ntprinting.h"
-#include "librpc/gen_ndr/cli_spoolss.h"
+#include "librpc/gen_ndr/ndr_spoolss_c.h"
 #include "rpc_client/cli_spoolss.h"
 #include "librpc/gen_ndr/ndr_security.h"
 #include "rpc_server/rpc_ncacn_np.h"
 #include "rpc_client/cli_spoolss.h"
 #include "librpc/gen_ndr/ndr_security.h"
 #include "rpc_server/rpc_ncacn_np.h"
@@ -38,6 +38,7 @@ static NTSTATUS migrate_form(TALLOC_CTX *mem_ctx,
                         unsigned char *data,
                         size_t length)
 {
                         unsigned char *data,
                         size_t length)
 {
+       struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
        struct spoolss_DevmodeContainer devmode_ctr;
        struct policy_handle hnd;
        enum ndr_err_code ndr_err;
        struct spoolss_DevmodeContainer devmode_ctr;
        struct policy_handle hnd;
        enum ndr_err_code ndr_err;
@@ -76,7 +77,7 @@ static NTSTATUS migrate_form(TALLOC_CTX *mem_ctx,
 
        ZERO_STRUCT(devmode_ctr);
 
 
        ZERO_STRUCT(devmode_ctr);
 
-       status = rpccli_spoolss_OpenPrinter(pipe_hnd,
+       status = dcerpc_spoolss_OpenPrinter(b,
                                            mem_ctx,
                                            srv_name_slash,
                                            NULL,
                                            mem_ctx,
                                            srv_name_slash,
                                            NULL,
@@ -85,13 +86,16 @@ static NTSTATUS migrate_form(TALLOC_CTX *mem_ctx,
                                            &hnd,
                                            &result);
        if (!NT_STATUS_IS_OK(status)) {
                                            &hnd,
                                            &result);
        if (!NT_STATUS_IS_OK(status)) {
-               if (!W_ERROR_IS_OK(result)) {
-                       status = werror_to_ntstatus(result);
-               }
-               DEBUG(2, ("OpenPrinter(%s) failed: %s\n",
+               DEBUG(2, ("dcerpc_spoolss_OpenPrinter(%s) failed: %s\n",
                          srv_name_slash, nt_errstr(status)));
                return status;
        }
                          srv_name_slash, nt_errstr(status)));
                return status;
        }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(2, ("OpenPrinter(%s) failed: %s\n",
+                         srv_name_slash, win_errstr(result)));
+               status = werror_to_ntstatus(result);
+               return status;
+       }
 
        f1.form_name = key_name;
        f1.flags = r.flag;
 
        f1.form_name = key_name;
        f1.flags = r.flag;
@@ -106,18 +110,22 @@ static NTSTATUS migrate_form(TALLOC_CTX *mem_ctx,
 
        f.info1 = &f1;
 
 
        f.info1 = &f1;
 
-       status = rpccli_spoolss_AddForm(pipe_hnd,
+       status = dcerpc_spoolss_AddForm(b,
                                        mem_ctx,
                                        &hnd,
                                        1,
                                        f,
                                        &result);
        if (!NT_STATUS_IS_OK(status)) {
                                        mem_ctx,
                                        &hnd,
                                        1,
                                        f,
                                        &result);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(2, ("AddForm(%s) refused -- %s.\n",
+               DEBUG(2, ("dcerpc_spoolss_AddForm(%s) refused -- %s.\n",
                          f.info1->form_name, nt_errstr(status)));
                          f.info1->form_name, nt_errstr(status)));
+       } else if (!W_ERROR_IS_OK(result)) {
+               DEBUG(2, ("AddForm(%s) refused -- %s.\n",
+                         f.info1->form_name, win_errstr(result)));
+               status = werror_to_ntstatus(result);
        }
 
        }
 
-       rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
+       dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &result);
 
        return status;
 }
 
        return status;
 }
@@ -128,6 +136,7 @@ static NTSTATUS migrate_driver(TALLOC_CTX *mem_ctx,
                               unsigned char *data,
                               size_t length)
 {
                               unsigned char *data,
                               size_t length)
 {
+       struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
        const char *srv_name_slash;
        enum ndr_err_code ndr_err;
        struct ntprinting_driver r;
        const char *srv_name_slash;
        enum ndr_err_code ndr_err;
        struct ntprinting_driver r;
@@ -176,17 +185,18 @@ static NTSTATUS migrate_driver(TALLOC_CTX *mem_ctx,
        d.level = 3;
        d.info.info3 = &d3;
 
        d.level = 3;
        d.info.info3 = &d3;
 
-       status = rpccli_spoolss_AddPrinterDriver(pipe_hnd,
+       status = dcerpc_spoolss_AddPrinterDriver(b,
                                                 mem_ctx,
                                                 srv_name_slash,
                                                 &d,
                                                 &result);
        if (!NT_STATUS_IS_OK(status)) {
                                                 mem_ctx,
                                                 srv_name_slash,
                                                 &d,
                                                 &result);
        if (!NT_STATUS_IS_OK(status)) {
-               if (!W_ERROR_IS_OK(result)) {
-                       status = werror_to_ntstatus(result);
-               }
-               DEBUG(2, ("AddPrinterDriver(%s) refused -- %s.\n",
+               DEBUG(2, ("dcerpc_spoolss_AddPrinterDriver(%s) refused -- %s.\n",
                          d3.driver_name, nt_errstr(status)));
                          d3.driver_name, nt_errstr(status)));
+       } else if (!W_ERROR_IS_OK(result)) {
+               DEBUG(2, ("AddPrinterDriver(%s) refused -- %s.\n",
+                         d3.driver_name, win_errstr(result)));
+               status = werror_to_ntstatus(result);
        }
 
        return status;
        }
 
        return status;
@@ -198,6 +208,7 @@ static NTSTATUS migrate_printer(TALLOC_CTX *mem_ctx,
                                unsigned char *data,
                                size_t length)
 {
                                unsigned char *data,
                                size_t length)
 {
+       struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
        struct policy_handle hnd;
        enum ndr_err_code ndr_err;
        struct ntprinting_printer r;
        struct policy_handle hnd;
        enum ndr_err_code ndr_err;
        struct ntprinting_printer r;
@@ -231,7 +242,7 @@ static NTSTATUS migrate_printer(TALLOC_CTX *mem_ctx,
 
        ZERO_STRUCT(devmode_ctr);
 
 
        ZERO_STRUCT(devmode_ctr);
 
-       status = rpccli_spoolss_OpenPrinter(pipe_hnd,
+       status = dcerpc_spoolss_OpenPrinter(b,
                                            mem_ctx,
                                            key_name,
                                            NULL,
                                            mem_ctx,
                                            key_name,
                                            NULL,
@@ -240,11 +251,14 @@ static NTSTATUS migrate_printer(TALLOC_CTX *mem_ctx,
                                            &hnd,
                                            &result);
        if (!NT_STATUS_IS_OK(status)) {
                                            &hnd,
                                            &result);
        if (!NT_STATUS_IS_OK(status)) {
-               if (!W_ERROR_IS_OK(result)) {
-                       status = werror_to_ntstatus(result);
-               }
+               DEBUG(2, ("dcerpc_spoolss_OpenPrinter(%s) failed: %s\n",
+                         key_name, nt_errstr(status)));
+               return status;
+       }
+       if (!W_ERROR_IS_OK(result)) {
                DEBUG(2, ("OpenPrinter(%s) failed: %s\n",
                          key_name, win_errstr(result)));
                DEBUG(2, ("OpenPrinter(%s) failed: %s\n",
                          key_name, win_errstr(result)));
+               status = werror_to_ntstatus(result);
                return status;
        }
 
                return status;
        }
 
@@ -320,7 +334,7 @@ static NTSTATUS migrate_printer(TALLOC_CTX *mem_ctx,
        info_ctr.info.info2 = &info2;
        info_ctr.level = 2;
 
        info_ctr.info.info2 = &info2;
        info_ctr.level = 2;
 
-       status = rpccli_spoolss_SetPrinter(pipe_hnd,
+       status = dcerpc_spoolss_SetPrinter(b,
                                           mem_ctx,
                                           &hnd,
                                           &info_ctr,
                                           mem_ctx,
                                           &hnd,
                                           &info_ctr,
@@ -329,10 +343,16 @@ static NTSTATUS migrate_printer(TALLOC_CTX *mem_ctx,
                                           0, /* command */
                                           &result);
        if (!NT_STATUS_IS_OK(status)) {
                                           0, /* command */
                                           &result);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(2, ("SetPrinter(%s) level 2 refused -- %s.\n",
+               DEBUG(2, ("dcerpc_spoolss_SetPrinter(%s) level 2 refused -- %s.\n",
                          key_name, nt_errstr(status)));
                goto done;
        }
                          key_name, nt_errstr(status)));
                goto done;
        }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(2, ("SetPrinter(%s) level 2 refused -- %s.\n",
+                         key_name, win_errstr(result)));
+               status = werror_to_ntstatus(result);
+               goto done;
+       }
 
        /* migrate printerdata */
        for (j = 0; j < r.count; j++) {
 
        /* migrate printerdata */
        for (j = 0; j < r.count; j++) {
@@ -352,7 +372,7 @@ static NTSTATUS migrate_printer(TALLOC_CTX *mem_ctx,
                        valuename++;
                }
 
                        valuename++;
                }
 
-               status = rpccli_spoolss_SetPrinterDataEx(pipe_hnd,
+               status = dcerpc_spoolss_SetPrinterDataEx(b,
                                                         mem_ctx,
                                                         &hnd,
                                                         keyname,
                                                         mem_ctx,
                                                         &hnd,
                                                         keyname,
@@ -362,16 +382,25 @@ static NTSTATUS migrate_printer(TALLOC_CTX *mem_ctx,
                                                         r.printer_data[j].data.length,
                                                         &result);
                if (!NT_STATUS_IS_OK(status)) {
                                                         r.printer_data[j].data.length,
                                                         &result);
                if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(2, ("SetPrinterDataEx: printer [%s], keyname [%s], "
+                       DEBUG(2, ("dcerpc_spoolss_SetPrinterDataEx: "
+                                 "printer [%s], keyname [%s], "
                                  "valuename [%s] refused -- %s.\n",
                                  key_name, keyname, valuename,
                                  nt_errstr(status)));
                        break;
                }
                                  "valuename [%s] refused -- %s.\n",
                                  key_name, keyname, valuename,
                                  nt_errstr(status)));
                        break;
                }
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(2, ("SetPrinterDataEx: printer [%s], keyname [%s], "
+                                 "valuename [%s] refused -- %s.\n",
+                                 key_name, keyname, valuename,
+                                 win_errstr(result)));
+                       status = werror_to_ntstatus(result);
+                       break;
+               }
        }
 
  done:
        }
 
  done:
-       rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
+       dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &result);
 
        return status;
 }
 
        return status;
 }
@@ -382,6 +411,7 @@ static NTSTATUS migrate_secdesc(TALLOC_CTX *mem_ctx,
                                unsigned char *data,
                                size_t length)
 {
                                unsigned char *data,
                                size_t length)
 {
+       struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
        struct policy_handle hnd;
        enum ndr_err_code ndr_err;
        struct sec_desc_buf secdesc_ctr;
        struct policy_handle hnd;
        enum ndr_err_code ndr_err;
        struct sec_desc_buf secdesc_ctr;
@@ -412,7 +442,7 @@ static NTSTATUS migrate_secdesc(TALLOC_CTX *mem_ctx,
 
        ZERO_STRUCT(devmode_ctr);
 
 
        ZERO_STRUCT(devmode_ctr);
 
-       status = rpccli_spoolss_OpenPrinter(pipe_hnd,
+       status = dcerpc_spoolss_OpenPrinter(b,
                                            mem_ctx,
                                            key_name,
                                            NULL,
                                            mem_ctx,
                                            key_name,
                                            NULL,
@@ -421,17 +451,20 @@ static NTSTATUS migrate_secdesc(TALLOC_CTX *mem_ctx,
                                            &hnd,
                                            &result);
        if (!NT_STATUS_IS_OK(status)) {
                                            &hnd,
                                            &result);
        if (!NT_STATUS_IS_OK(status)) {
-               if (W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME, result)) {
-                       DEBUG(3, ("Ignoring missing printer %s\n", key_name));
-                       return NT_STATUS_OK;
-               }
-               if (!W_ERROR_IS_OK(result)) {
-                       status = werror_to_ntstatus(result);
-               }
-               DEBUG(2, ("OpenPrinter(%s) failed: %s\n",
+               DEBUG(2, ("dcerpc_spoolss_OpenPrinter(%s) failed: %s\n",
                          key_name, nt_errstr(status)));
                return status;
        }
                          key_name, nt_errstr(status)));
                return status;
        }
+       if (W_ERROR_EQUAL(WERR_INVALID_PRINTER_NAME, result)) {
+               DEBUG(3, ("Ignoring missing printer %s\n", key_name));
+               return NT_STATUS_OK;
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(2, ("OpenPrinter(%s) failed: %s\n",
+                         key_name, win_errstr(result)));
+               status = werror_to_ntstatus(result);
+               return status;
+       }
 
        ZERO_STRUCT(devmode_ctr);
 
 
        ZERO_STRUCT(devmode_ctr);
 
@@ -440,7 +473,7 @@ static NTSTATUS migrate_secdesc(TALLOC_CTX *mem_ctx,
        info_ctr.info.info3 = &info3;
        info_ctr.level = 3;
 
        info_ctr.info.info3 = &info3;
        info_ctr.level = 3;
 
-       status = rpccli_spoolss_SetPrinter(pipe_hnd,
+       status = dcerpc_spoolss_SetPrinter(b,
                                           mem_ctx,
                                           &hnd,
                                           &info_ctr,
                                           mem_ctx,
                                           &hnd,
                                           &info_ctr,
@@ -449,11 +482,15 @@ static NTSTATUS migrate_secdesc(TALLOC_CTX *mem_ctx,
                                           0, /* command */
                                           &result);
        if (!NT_STATUS_IS_OK(status)) {
                                           0, /* command */
                                           &result);
        if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(2, ("SetPrinter(%s) level 3 refused -- %s.\n",
+               DEBUG(2, ("dcerpc_spoolss_SetPrinter(%s) level 3 refused -- %s.\n",
                          key_name, nt_errstr(status)));
                          key_name, nt_errstr(status)));
+       } else if (!W_ERROR_IS_OK(result)) {
+               DEBUG(2, ("SetPrinter(%s) level 3 refused -- %s.\n",
+                         key_name, win_errstr(result)));
+               status = werror_to_ntstatus(result);
        }
 
        }
 
-       rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
+       dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &result);
 
        return status;
 }
 
        return status;
 }
index 8effb6ec482eb59d872bf923fd602d54f41f4445..9b06ece307e35be3a336224cee9688f33d02fbeb 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "includes.h"
 #include "printing.h"
 
 #include "includes.h"
 #include "printing.h"
-#include "../librpc/gen_ndr/cli_spoolss.h"
+#include "../librpc/gen_ndr/ndr_spoolss_c.h"
 #include "rpc_server/rpc_ncacn_np.h"
 #include "smbd/globals.h"
 #include "../libcli/security/security.h"
 #include "rpc_server/rpc_ncacn_np.h"
 #include "smbd/globals.h"
 #include "../libcli/security/security.h"
@@ -43,7 +43,7 @@ NTSTATUS print_spool_open(files_struct *fsp,
        NTSTATUS status;
        TALLOC_CTX *tmp_ctx;
        struct print_file_data *pf;
        NTSTATUS status;
        TALLOC_CTX *tmp_ctx;
        struct print_file_data *pf;
-       struct rpc_pipe_client *cli;
+       struct dcerpc_binding_handle *b = NULL;
        struct spoolss_DevmodeContainer devmode_ctr;
        union spoolss_DocumentInfo info;
        int fd = -1;
        struct spoolss_DevmodeContainer devmode_ctr;
        union spoolss_DocumentInfo info;
        int fd = -1;
@@ -132,11 +132,11 @@ NTSTATUS print_spool_open(files_struct *fsp,
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
-       cli = fsp->conn->spoolss_pipe;
+       b = fsp->conn->spoolss_pipe->binding_handle;
 
        ZERO_STRUCT(devmode_ctr);
 
 
        ZERO_STRUCT(devmode_ctr);
 
-       status = rpccli_spoolss_OpenPrinter(cli, pf, pf->svcname,
+       status = dcerpc_spoolss_OpenPrinter(b, pf, pf->svcname,
                                            "RAW", devmode_ctr,
                                            SEC_FLAG_MAXIMUM_ALLOWED,
                                            &pf->handle, &werr);
                                            "RAW", devmode_ctr,
                                            SEC_FLAG_MAXIMUM_ALLOWED,
                                            &pf->handle, &werr);
@@ -157,7 +157,7 @@ NTSTATUS print_spool_open(files_struct *fsp,
        info.info1->output_file = pf->filename;
        info.info1->datatype = "RAW";
 
        info.info1->output_file = pf->filename;
        info.info1->datatype = "RAW";
 
-       status = rpccli_spoolss_StartDocPrinter(cli, tmp_ctx, &pf->handle,
+       status = dcerpc_spoolss_StartDocPrinter(b, tmp_ctx, &pf->handle,
                                                1, info, &pf->jobid, &werr);
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
                                                1, info, &pf->jobid, &werr);
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
@@ -272,9 +272,9 @@ int print_spool_write(files_struct *fsp,
 
 void print_spool_end(files_struct *fsp, enum file_close_type close_type)
 {
 
 void print_spool_end(files_struct *fsp, enum file_close_type close_type)
 {
-       struct rpc_pipe_client *cli;
        NTSTATUS status;
        WERROR werr;
        NTSTATUS status;
        WERROR werr;
+       struct dcerpc_binding_handle *b = NULL;
 
        status = rpc_pipe_open_interface(fsp->conn,
                                         &ndr_table_spoolss.syntax_id,
 
        status = rpc_pipe_open_interface(fsp->conn,
                                         &ndr_table_spoolss.syntax_id,
@@ -288,13 +288,13 @@ void print_spool_end(files_struct *fsp, enum file_close_type close_type)
                          nt_errstr(status)));
                return;
        }
                          nt_errstr(status)));
                return;
        }
-       cli = fsp->conn->spoolss_pipe;
+       b = fsp->conn->spoolss_pipe->binding_handle;
 
        switch (close_type) {
        case NORMAL_CLOSE:
        case SHUTDOWN_CLOSE:
                /* this also automatically calls spoolss_EndDocPrinter */
 
        switch (close_type) {
        case NORMAL_CLOSE:
        case SHUTDOWN_CLOSE:
                /* this also automatically calls spoolss_EndDocPrinter */
-               status = rpccli_spoolss_ClosePrinter(cli, fsp->print_file,
+               status = dcerpc_spoolss_ClosePrinter(b, fsp->print_file,
                                                &fsp->print_file->handle,
                                                &werr);
                if (!NT_STATUS_IS_OK(status) ||
                                                &fsp->print_file->handle,
                                                &werr);
                if (!NT_STATUS_IS_OK(status) ||
@@ -313,9 +313,9 @@ void print_spool_end(files_struct *fsp, enum file_close_type close_type)
 void print_spool_terminate(struct connection_struct *conn,
                           struct print_file_data *print_file)
 {
 void print_spool_terminate(struct connection_struct *conn,
                           struct print_file_data *print_file)
 {
-       struct rpc_pipe_client *cli;
        NTSTATUS status;
        WERROR werr;
        NTSTATUS status;
        WERROR werr;
+       struct dcerpc_binding_handle *b = NULL;
 
        rap_jobid_delete(print_file->svcname, print_file->jobid);
 
 
        rap_jobid_delete(print_file->svcname, print_file->jobid);
 
@@ -331,9 +331,9 @@ void print_spool_terminate(struct connection_struct *conn,
                          nt_errstr(status)));
                return;
        }
                          nt_errstr(status)));
                return;
        }
-       cli = conn->spoolss_pipe;
+       b = conn->spoolss_pipe->binding_handle;
 
 
-       status = rpccli_spoolss_SetJob(cli, print_file,
+       status = dcerpc_spoolss_SetJob(b, print_file,
                                        &print_file->handle,
                                        print_file->jobid,
                                        NULL, SPOOLSS_JOB_CONTROL_DELETE,
                                        &print_file->handle,
                                        print_file->jobid,
                                        NULL, SPOOLSS_JOB_CONTROL_DELETE,
@@ -344,7 +344,7 @@ void print_spool_terminate(struct connection_struct *conn,
                          print_file->jobid, nt_errstr(status)));
                return;
        }
                          print_file->jobid, nt_errstr(status)));
                return;
        }
-       status = rpccli_spoolss_ClosePrinter(cli, print_file,
+       status = dcerpc_spoolss_ClosePrinter(b, print_file,
                                             &print_file->handle,
                                             &werr);
        if (!NT_STATUS_IS_OK(status) ||
                                             &print_file->handle,
                                             &werr);
        if (!NT_STATUS_IS_OK(status) ||