libcli/security Provide a common, top level libcli/security/security.h
[sfrench/samba-autobuild/.git] / source3 / utils / net_rpc_printer.c
index 7d8c67fb4da625b42e23510795fd0e5c81880c27..1e218049ede0506b2da721e7cac560ced8544365 100644 (file)
 #include "utils/net.h"
 #include "../librpc/gen_ndr/cli_spoolss.h"
 #include "rpc_client/cli_spoolss.h"
+#include "rpc_client/init_spoolss.h"
+#include "nt_printing.h"
 #include "registry.h"
 #include "registry/reg_objects.h"
+#include "../libcli/security/security.h"
 
 /* support itanium as well */
 static const struct print_architecture_table_node archi_table[]= {
@@ -489,12 +492,11 @@ static NTSTATUS net_copy_driverfile(struct net_context *c,
                                    struct cli_state *cli_share_dst,
                                    const char *file, const char *short_archi) {
 
-       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        const char *p;
        char *src_name;
        char *dst_name;
-       char *version;
-       char *filename;
+       char *version = NULL;
+       char *filename = NULL;
        char *tok;
 
        if (!file) {
@@ -511,29 +513,27 @@ static NTSTATUS net_copy_driverfile(struct net_context *c,
                }
        }
 
+       if (version == NULL || filename == NULL) {
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
        /* build source file name */
-       if (asprintf(&src_name, "\\%s\\%s\\%s", short_archi, version, filename) < 0 )
+       src_name = talloc_asprintf(mem_ctx, "\\%s\\%s\\%s",
+                                  short_archi, version, filename);
+       if (src_name == NULL) {
                return NT_STATUS_NO_MEMORY;
-
+       }
 
        /* create destination file name */
-       if (asprintf(&dst_name, "\\%s\\%s", short_archi, filename) < 0 )
-                return NT_STATUS_NO_MEMORY;
+       dst_name = talloc_asprintf(mem_ctx, "\\%s\\%s", short_archi, filename);
+       if (dst_name == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
 
        /* finally copy the file */
-       nt_status = net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst,
-                                 src_name, dst_name, false, false, false, true);
-       if (!NT_STATUS_IS_OK(nt_status))
-               goto out;
-
-       nt_status = NT_STATUS_OK;
-
-out:
-       SAFE_FREE(src_name);
-       SAFE_FREE(dst_name);
-
-       return nt_status;
+       return net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst,
+                            src_name, dst_name, false, false, false, true);
 }
 
 /**
@@ -757,6 +757,7 @@ static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd,
        WERROR result;
        NTSTATUS status;
        struct spoolss_SetPrinterInfoCtr info_ctr;
+       struct spoolss_SetPrinterInfo2 info2;
        struct spoolss_DevmodeContainer devmode_ctr;
        struct sec_desc_buf secdesc_ctr;
 
@@ -776,8 +777,8 @@ static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd,
                        (void *)&info->info1;
                break;
        case 2:
-               info_ctr.info.info2 = (struct spoolss_SetPrinterInfo2 *)
-                       (void *)&info->info2;
+               spoolss_printerinfo2_to_setprinterinfo2(&info->info2, &info2);
+               info_ctr.info.info2 = &info2;
                break;
        case 3:
                info_ctr.info.info3 = (struct spoolss_SetPrinterInfo3 *)
@@ -1093,6 +1094,11 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
                                         &hnd))
                return false;
 
+       *info_p = talloc_zero(mem_ctx, union spoolss_PrinterInfo);
+       if (*info_p == NULL) {
+               return false;
+       }
+
        if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, *info_p)) {
                rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
                return false;
@@ -1317,9 +1323,13 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_
                                                      0, /* command */
                                                      &result);
 
-               if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) {
-                       printf(_("cannot set printer-info: %s\n"),
-                              win_errstr(result));
+               if (!W_ERROR_IS_OK(result) && !W_ERROR_EQUAL(result, WERR_IO_PENDING)) {
+                       if ((action == DSPRINT_UPDATE) && W_ERROR_EQUAL(result, W_ERROR(0x80070002))) {
+                               printf(_("printer not published yet\n"));
+                       } else {
+                               printf(_("cannot set printer-info: %s\n"),
+                                      win_errstr(result));
+                       }
                        goto done;
                }
 
@@ -2047,6 +2057,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
        /* do something for all printers */
        for (i = 0; i < num_printers; i++) {
 
+               struct spoolss_SetPrinterInfo2 info2;
+
                /* do some initialization */
                printername = info_enum[i].info2.printername;
                sharename = info_enum[i].info2.sharename;
@@ -2098,8 +2110,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
                d_printf(_("creating printer: %s\n"), printername);
 
                info_ctr.level = level;
-               info_ctr.info.info2 = (struct spoolss_SetPrinterInfo2 *)
-                       (void *)&info_src.info2;
+               spoolss_printerinfo2_to_setprinterinfo2(&info_src.info2, &info2);
+               info_ctr.info.info2 = &info2;
 
                result = rpccli_spoolss_addprinterex(pipe_hnd_dst,
                                                     mem_ctx,
@@ -2420,6 +2432,8 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
                                struct regval_blob *value;
                                DATA_BLOB blob;
 
+                               ZERO_STRUCT(blob);
+
                                /* although samba replies with sane data in most cases we
                                   should try to avoid writing wrong registry data */