s3:libsmb: get rid of cli_state_remote_name
[samba.git] / source3 / utils / net_rpc_printer.c
index ef84d9eec0b854c23839f981e90da7976215f759..0ab08efcc0a1981e575c3d4ea1aab684eb11f5ac 100644 (file)
 #include "rpc_client/cli_spoolss.h"
 #include "rpc_client/init_spoolss.h"
 #include "nt_printing.h"
-#include "registry/reg_objects.h"
+#include "registry.h"
 #include "../libcli/security/security.h"
 #include "../libcli/registry/util_reg.h"
 #include "libsmb/libsmb.h"
+#include "../libcli/smb/smbXcli_base.h"
 
 /* support itanium as well */
 static const struct print_architecture_table_node archi_table[]= {
@@ -80,44 +81,45 @@ static void display_print_driver3(struct spoolss_DriverInfo3 *r)
        printf(_("\tDefaultdatatype: [%s]\n\n"), r->default_datatype);
 }
 
-static void display_reg_value(const char *subkey, struct regval_blob *value)
+static void display_reg_value(const char *subkey, const char *name, struct registry_value *value)
 {
        const char *text;
-       DATA_BLOB blob;
 
-       switch(regval_type(value)) {
+       switch(value->type) {
        case REG_DWORD:
-               d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey,
-                       regval_name(value), *((uint32_t *) regval_data_p(value)));
+               if (value->data.length == sizeof(uint32)) {
+                       d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey,
+                                name, IVAL(value->data.data,0));
+               } else {
+                       d_printf(_("\t[%s:%s]: REG_DWORD: <invalid>\n"), subkey,
+                                name);
+               }
                break;
 
        case REG_SZ:
-               blob = data_blob_const(regval_data_p(value), regval_size(value));
-               pull_reg_sz(talloc_tos(), &blob, &text);
+               pull_reg_sz(talloc_tos(), &value->data, &text);
                if (!text) {
                        break;
                }
-               d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, regval_name(value),
-                        text);
+               d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, name, text);
                break;
 
        case REG_BINARY:
                d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not "
                           "displayed\n"),
-                        subkey, regval_name(value));
+                        subkey, name);
                break;
 
        case REG_MULTI_SZ: {
                uint32_t i;
                const char **values;
-               blob = data_blob_const(regval_data_p(value), regval_size(value));
 
-               if (!pull_reg_multi_sz(NULL, &blob, &values)) {
+               if (!pull_reg_multi_sz(NULL, &value->data, &values)) {
                        d_printf("pull_reg_multi_sz failed\n");
                        break;
                }
 
-               printf("%s: REG_MULTI_SZ: \n", regval_name(value));
+               printf("%s: REG_MULTI_SZ: \n", name);
                for (i=0; values[i] != NULL; i++) {
                        d_printf("%s\n", values[i]);
                }
@@ -126,8 +128,7 @@ static void display_reg_value(const char *subkey, struct regval_blob *value)
        }
 
        default:
-               d_printf(_("\t%s: unknown type %d\n"), regval_name(value),
-                        regval_type(value));
+               d_printf(_("\t%s: unknown type %d\n"), name, value->type);
        }
 
 }
@@ -368,9 +369,9 @@ NTSTATUS net_copy_file(struct net_context *c,
 
                d_printf(_("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
                           "%s ACLs and %s DOS Attributes %s\n"),
-                       cli_state_remote_name(cli_share_src),
+                       smbXcli_conn_remote_name(cli_share_src->conn),
                        cli_share_src->share, src_name,
-                       cli_state_remote_name(cli_share_dst),
+                       smbXcli_conn_remote_name(cli_share_dst->conn),
                        cli_share_dst->share, dst_name,
                        copy_acls ?  _("with") : _("without"),
                        copy_attrs ? _("with") : _("without"),
@@ -388,7 +389,7 @@ NTSTATUS net_copy_file(struct net_context *c,
                if (!NT_STATUS_IS_OK(nt_status)) {
                        d_fprintf(stderr,
                                  _("Error reading file [\\\\%s\\%s%s]: %s\n"),
-                                 cli_state_remote_name(cli_share_src),
+                                 smbXcli_conn_remote_name(cli_share_src->conn),
                                  cli_share_src->share,
                                  src_name, nt_errstr(nt_status));
                        goto out;
@@ -403,7 +404,7 @@ NTSTATUS net_copy_file(struct net_context *c,
                if (!NT_STATUS_IS_OK(nt_status)) {
                        d_fprintf(stderr,
                                  _("Error writing file: [\\\\%s\\%s%s]: %s\n"),
-                                 cli_state_remote_name(cli_share_dst),
+                                 smbXcli_conn_remote_name(cli_share_dst->conn),
                                  cli_share_dst->share,
                                  dst_name, nt_errstr(nt_status));
                        goto out;
@@ -933,10 +934,11 @@ static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd,
 
 
 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd,
-                                       TALLOC_CTX *mem_ctx,
-                                       struct policy_handle *hnd,
-                                       const char *keyname,
-                                       struct regval_blob *value)
+                                        TALLOC_CTX *mem_ctx,
+                                        struct policy_handle *hnd,
+                                        const char *keyname,
+                                        const char *name,
+                                        struct registry_value *value)
 {
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
        WERROR result;
@@ -946,10 +948,10 @@ static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd,
        status = dcerpc_spoolss_SetPrinterDataEx(b, mem_ctx,
                                                 hnd,
                                                 keyname,
-                                                regval_name(value),
-                                                regval_type(value),
-                                                regval_data_p(value),
-                                                regval_size(value),
+                                                name,
+                                                value->type,
+                                                value->data.data,
+                                                value->data.length,
                                                 &result);
        if (!NT_STATUS_IS_OK(status)) {
                printf(_("could not set printerdataex: %s\n"),
@@ -1913,8 +1915,8 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
 
        /* open print$-share on the src server */
        nt_status = connect_to_service(c, &cli_share_src,
-                                      cli_state_remote_sockaddr(cli),
-                                      cli_state_remote_name(cli),
+                                      smbXcli_conn_remote_sockaddr(cli->conn),
+                                      smbXcli_conn_remote_name(cli->conn),
                                       "print$", "A:");
        if (!NT_STATUS_IS_OK(nt_status))
                goto done;
@@ -1924,8 +1926,8 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
 
        /* open print$-share on the dst server */
        nt_status = connect_to_service(c, &cli_share_dst,
-                                      cli_state_remote_sockaddr(cli_dst),
-                                      cli_state_remote_name(cli_dst),
+                                      smbXcli_conn_remote_sockaddr(cli_dst->conn),
+                                      smbXcli_conn_remote_name(cli_dst->conn),
                                       "print$", "A:");
        if (!NT_STATUS_IS_OK(nt_status))
                return nt_status;
@@ -2289,7 +2291,6 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
        union spoolss_PrinterInfo info_dst_publish;
        union spoolss_PrinterInfo info_dst;
        struct cli_state *cli_dst = NULL;
-       char *devicename = NULL, *unc_name = NULL, *url = NULL;
        const char *longname;
        const char **keylist = NULL;
 
@@ -2454,20 +2455,13 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
 
                                /* display_value */
                                if (c->opt_verbose) {
-                                       struct regval_blob *v;
-
-                                       v = regval_compose(talloc_tos(),
-                                                          r.out.value_name,
-                                                          *r.out.type,
-                                                          r.out.data,
-                                                          r.in.data_offered);
-                                       if (v == NULL) {
-                                               nt_status = NT_STATUS_NO_MEMORY;
-                                               goto done;
-                                       }
+                                       struct registry_value v;
+                                       v.type = *r.out.type;
+                                       v.data = data_blob_const(
+                                               r.out.data, r.in.data_offered);
 
-                                       display_reg_value(SPOOL_PRINTERDATA_KEY, v);
-                                       talloc_free(v);
+                                       display_reg_value(SPOOL_PRINTERDATA_KEY,
+                                                         r.out.value_name, &v);
                                }
 
                                /* set_value */
@@ -2516,107 +2510,58 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
 
                        for (j=0; j < count; j++) {
 
-                               struct regval_blob *value;
-                               DATA_BLOB blob;
-
-                               ZERO_STRUCT(blob);
+                               struct registry_value value;
+                               const char *value_name = info[j].value_name;
+                               value.type = REG_SZ;
 
                                /* although samba replies with sane data in most cases we
                                   should try to avoid writing wrong registry data */
 
-                               if (strequal(info[j].value_name, SPOOL_REG_PORTNAME) ||
-                                   strequal(info[j].value_name, SPOOL_REG_UNCNAME) ||
-                                   strequal(info[j].value_name, SPOOL_REG_URL) ||
-                                   strequal(info[j].value_name, SPOOL_REG_SHORTSERVERNAME) ||
-                                   strequal(info[j].value_name, SPOOL_REG_SERVERNAME)) {
-
-                                       if (strequal(info[j].value_name, SPOOL_REG_PORTNAME)) {
-
-                                               /* although windows uses a multi-sz, we use a sz */
-                                               push_reg_sz(mem_ctx, &blob, SAMBA_PRINTER_PORT_NAME);
-                                       }
-
-                                       if (strequal(info[j].value_name, SPOOL_REG_UNCNAME)) {
-
-                                               if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
-                                                       nt_status = NT_STATUS_NO_MEMORY;
-                                                       goto done;
-                                               }
-                                               push_reg_sz(mem_ctx, &blob, unc_name);
-                                       }
-
-                                       if (strequal(info[j].value_name, SPOOL_REG_URL)) {
-
-                                               continue;
-
-#if 0
-                                               /* FIXME: should we really do that ??? */
-                                               if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) {
-                                                       nt_status = NT_STATUS_NO_MEMORY;
-                                                       goto done;
-                                               }
-                                               push_reg_sz(mem_ctx, NULL, &blob, url);
-                                               fstrcpy(value.valuename, SPOOL_REG_URL);
-#endif
-                                       }
-
-                                       if (strequal(info[j].value_name, SPOOL_REG_SERVERNAME)) {
-
-                                               push_reg_sz(mem_ctx, &blob, longname);
-                                       }
-
-                                       if (strequal(info[j].value_name, SPOOL_REG_SHORTSERVERNAME)) {
-
-                                               push_reg_sz(mem_ctx, &blob, lp_netbios_name());
-                                       }
-
-                                       value = regval_compose(talloc_tos(),
-                                                              info[j].value_name,
-                                                              REG_SZ,
-                                                              blob.length == 0 ? NULL : blob.data,
-                                                              blob.length);
-                                       if (value == NULL) {
+                               if (strequal(value_name, SPOOL_REG_PORTNAME)) {
+                                       /* although windows uses a multi-sz, we use a sz */
+                                       push_reg_sz(mem_ctx, &value.data, SAMBA_PRINTER_PORT_NAME);
+                               }
+                               else if (strequal(value_name, SPOOL_REG_UNCNAME)) {
+                                       char *unc_name;
+                                       if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
                                                nt_status = NT_STATUS_NO_MEMORY;
                                                goto done;
                                        }
-
-                                       if (c->opt_verbose)
-                                               display_reg_value(subkey, value);
-
-                                       /* here we have to set all subkeys on the dst server */
-                                       if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
-                                                       subkey, value))
-                                       {
-                                               talloc_free(value);
-                                               goto done;
-                                       }
-
-                                       talloc_free(value);
-                               } else {
-
-                                       struct regval_blob *v;
-
-                                       v = regval_compose(talloc_tos(),
-                                                          info[j].value_name,
-                                                          info[j].type,
-                                                          info[j].data->data,
-                                                          info[j].data->length);
-                                       if (v == NULL) {
+                                       push_reg_sz(mem_ctx, &value.data, unc_name);
+                                       free(unc_name);
+                               }
+                               else if (strequal(value_name, SPOOL_REG_URL)) {
+                                       continue;
+#if 0
+                                       /* FIXME: should we really do that ??? */
+                                       if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) {
                                                nt_status = NT_STATUS_NO_MEMORY;
                                                goto done;
                                        }
+                                       push_reg_sz(mem_ctx, NULL, &value.data, url);
+                                       free(url);
+#endif
+                               }
+                               else if (strequal(value_name, SPOOL_REG_SERVERNAME)) {
+                                       push_reg_sz(mem_ctx, &value.data, longname);
+                               }
+                               else if (strequal(value_name, SPOOL_REG_SHORTSERVERNAME)) {
+                                       push_reg_sz(mem_ctx, &value.data, lp_netbios_name());
+                               }
+                               else {
+                                       value.type = info[j].type;
+                                       value.data = *info[j].data;
+                               }
 
-                                       if (c->opt_verbose) {
-                                               display_reg_value(subkey, v);
-                                       }
-
-                                       /* here we have to set all subkeys on the dst server */
-                                       if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
-                                                       subkey, v)) {
-                                               goto done;
-                                       }
+                               if (c->opt_verbose) {
+                                       display_reg_value(subkey, value_name, &value);
+                               }
 
-                                       talloc_free(v);
+                               /* here we have to set all subkeys on the dst server */
+                               if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
+                                                                 subkey, value_name, &value))
+                               {
+                                       goto done;
                                }
 
                                DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
@@ -2640,10 +2585,6 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
        nt_status = NT_STATUS_OK;
 
 done:
-       SAFE_FREE(devicename);
-       SAFE_FREE(url);
-       SAFE_FREE(unc_name);
-
        if (is_valid_policy_hnd(&hnd_src)) {
                dcerpc_spoolss_ClosePrinter(b_src, mem_ctx, &hnd_src, &result);
        }