s3-printing: open up a winreg pipe handle for the migration code.
authorGünther Deschner <gd@samba.org>
Fri, 1 Jul 2011 13:39:11 +0000 (15:39 +0200)
committerGünther Deschner <gd@samba.org>
Mon, 4 Jul 2011 13:06:41 +0000 (15:06 +0200)
Guenther

Autobuild-User: Günther Deschner <gd@samba.org>
Autobuild-Date: Mon Jul  4 15:06:41 CEST 2011 on sn-devel-104

source3/printing/nt_printing_migrate.c
source3/printing/nt_printing_migrate.h
source3/printing/nt_printing_migrate_internal.c
source3/utils/net_printing.c

index dc3f3694b709f1007c9b6eb5004c109375605320..7e9d6ca56543e7c8dd671e56fd7307a9ff623441 100644 (file)
@@ -28,6 +28,7 @@
 
 NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx,
                                   struct rpc_pipe_client *pipe_hnd,
+                                  struct rpc_pipe_client *winreg_pipe,
                                   const char *key_name,
                                   unsigned char *data,
                                   size_t length)
@@ -126,6 +127,7 @@ NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx,
 
 NTSTATUS printing_tdb_migrate_driver(TALLOC_CTX *mem_ctx,
                                     struct rpc_pipe_client *pipe_hnd,
+                                    struct rpc_pipe_client *winreg_pipe,
                                     const char *key_name,
                                     unsigned char *data,
                                     size_t length)
@@ -198,6 +200,7 @@ NTSTATUS printing_tdb_migrate_driver(TALLOC_CTX *mem_ctx,
 
 NTSTATUS printing_tdb_migrate_printer(TALLOC_CTX *mem_ctx,
                                      struct rpc_pipe_client *pipe_hnd,
+                                     struct rpc_pipe_client *winreg_pipe,
                                      const char *key_name,
                                      unsigned char *data,
                                      size_t length)
@@ -402,6 +405,7 @@ NTSTATUS printing_tdb_migrate_printer(TALLOC_CTX *mem_ctx,
 
 NTSTATUS printing_tdb_migrate_secdesc(TALLOC_CTX *mem_ctx,
                                      struct rpc_pipe_client *pipe_hnd,
+                                     struct rpc_pipe_client *winreg_pipe,
                                      const char *key_name,
                                      unsigned char *data,
                                      size_t length)
index 4991d06bd3e9588b5fc964b52f22c9bb470da45d..707ddc9714f71c9d42014583356348f708148afd 100644 (file)
 
 NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx,
                                   struct rpc_pipe_client *pipe_hnd,
+                                  struct rpc_pipe_client *winreg_pipe,
                                   const char *key_name,
                                   unsigned char *data,
                                   size_t length);
 NTSTATUS printing_tdb_migrate_driver(TALLOC_CTX *mem_ctx,
                                     struct rpc_pipe_client *pipe_hnd,
+                                    struct rpc_pipe_client *winreg_pipe,
                                     const char *key_name,
                                     unsigned char *data,
                                     size_t length);
 NTSTATUS printing_tdb_migrate_printer(TALLOC_CTX *mem_ctx,
                                      struct rpc_pipe_client *pipe_hnd,
+                                     struct rpc_pipe_client *winreg_pipe,
                                      const char *key_name,
                                      unsigned char *data,
                                      size_t length);
 NTSTATUS printing_tdb_migrate_secdesc(TALLOC_CTX *mem_ctx,
                                      struct rpc_pipe_client *pipe_hnd,
+                                     struct rpc_pipe_client *winreg_pipe,
                                      const char *key_name,
                                      unsigned char *data,
                                      size_t length);
index 59f6d33a76e38077dce5eb8e9a039fdcb49e878d..214ea8977d09046497ebff8e2a0335d7f56e983c 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "rpc_client/rpc_client.h"
 #include "librpc/gen_ndr/ndr_spoolss_c.h"
+#include "librpc/gen_ndr/ndr_winreg.h"
 #include "rpc_server/rpc_ncacn_np.h"
 #include "auth.h"
 #include "util_tdb.h"
@@ -65,7 +66,8 @@ static int rename_file_with_suffix(TALLOC_CTX *mem_ctx,
 
 static NTSTATUS migrate_internal(TALLOC_CTX *mem_ctx,
                                 const char *tdb_path,
-                                struct rpc_pipe_client *pipe_hnd)
+                                struct rpc_pipe_client *pipe_hnd,
+                                struct rpc_pipe_client *winreg_pipe)
 {
        const char *backup_suffix = ".bak";
        TDB_DATA kbuf, dbuf;
@@ -97,6 +99,7 @@ static NTSTATUS migrate_internal(TALLOC_CTX *mem_ctx,
                if (strncmp((const char *) kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) == 0) {
                        status = printing_tdb_migrate_form(mem_ctx,
                                              pipe_hnd,
+                                             winreg_pipe,
                                              (const char *) kbuf.dptr + strlen(FORMS_PREFIX),
                                              dbuf.dptr,
                                              dbuf.dsize);
@@ -111,6 +114,7 @@ static NTSTATUS migrate_internal(TALLOC_CTX *mem_ctx,
                if (strncmp((const char *) kbuf.dptr, DRIVERS_PREFIX, strlen(DRIVERS_PREFIX)) == 0) {
                        status = printing_tdb_migrate_driver(mem_ctx,
                                                pipe_hnd,
+                                               winreg_pipe,
                                                (const char *) kbuf.dptr + strlen(DRIVERS_PREFIX),
                                                dbuf.dptr,
                                                dbuf.dsize);
@@ -127,6 +131,7 @@ static NTSTATUS migrate_internal(TALLOC_CTX *mem_ctx,
                                                    + strlen(PRINTERS_PREFIX));
                        status = printing_tdb_migrate_printer(mem_ctx,
                                                 pipe_hnd,
+                                                winreg_pipe,
                                                 printer_name,
                                                 dbuf.dptr,
                                                 dbuf.dsize);
@@ -148,6 +153,7 @@ static NTSTATUS migrate_internal(TALLOC_CTX *mem_ctx,
                                                    + strlen(SECDESC_PREFIX));
                        status = printing_tdb_migrate_secdesc(mem_ctx,
                                                 pipe_hnd,
+                                                winreg_pipe,
                                                 secdesc_name,
                                                 dbuf.dptr,
                                                 dbuf.dsize);
@@ -186,6 +192,7 @@ bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
        bool forms_exists = file_exist(forms_path);
        struct auth_serversupplied_info *session_info;
        struct rpc_pipe_client *spoolss_pipe = NULL;
+       struct rpc_pipe_client *winreg_pipe = NULL;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
        NTSTATUS status;
 
@@ -214,8 +221,21 @@ bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
                return false;
        }
 
+       status = rpc_pipe_open_interface(tmp_ctx,
+                                       &ndr_table_winreg.syntax_id,
+                                       session_info,
+                                       NULL,
+                                       msg_ctx,
+                                       &winreg_pipe);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("Couldn't open internal winreg pipe: %s\n",
+                         nt_errstr(status)));
+               talloc_free(tmp_ctx);
+               return false;
+       }
+
        if (drivers_exists) {
-               status = migrate_internal(tmp_ctx, drivers_path, spoolss_pipe);
+               status = migrate_internal(tmp_ctx, drivers_path, spoolss_pipe, winreg_pipe);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("Couldn't migrate drivers tdb file: %s\n",
                          nt_errstr(status)));
@@ -225,7 +245,7 @@ bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
        }
 
        if (printers_exists) {
-               status = migrate_internal(tmp_ctx, printers_path, spoolss_pipe);
+               status = migrate_internal(tmp_ctx, printers_path, spoolss_pipe, winreg_pipe);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("Couldn't migrate printers tdb file: %s\n",
                                  nt_errstr(status)));
@@ -235,7 +255,7 @@ bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
        }
 
        if (forms_exists) {
-               status = migrate_internal(tmp_ctx, forms_path, spoolss_pipe);
+               status = migrate_internal(tmp_ctx, forms_path, spoolss_pipe, winreg_pipe);
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(0, ("Couldn't migrate forms tdb file: %s\n",
                                  nt_errstr(status)));
index c919d3775e2ff665e12012b5e8b0a250ce28ed95..9c2f70082d7da81f3d3628afb72bf0b7ed585cc1 100644 (file)
 #include "system/filesys.h"
 #include "utils/net.h"
 #include "rpc_client/rpc_client.h"
+#include "rpc_client/cli_pipe.h"
 #include "librpc/gen_ndr/ndr_ntprinting.h"
 #include "librpc/gen_ndr/ndr_spoolss.h"
 #include "../libcli/security/security.h"
 #include "../librpc/gen_ndr/ndr_security.h"
+#include "../librpc/gen_ndr/ndr_winreg.h"
 #include "util_tdb.h"
 #include "printing/nt_printing_migrate.h"
 
@@ -231,12 +233,22 @@ static NTSTATUS printing_migrate_internal(struct net_context *c,
        TDB_CONTEXT *tdb;
        TDB_DATA kbuf, dbuf;
        NTSTATUS status;
+       struct rpc_pipe_client *winreg_pipe = NULL;
 
        tmp_ctx = talloc_new(mem_ctx);
        if (tmp_ctx == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
 
+       status = cli_rpc_pipe_open_noauth(rpc_pipe_np_smb_conn(pipe_hnd),
+                                         &ndr_table_winreg.syntax_id,
+                                         &winreg_pipe);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, _("failed to open winreg pipe: %s\n"),
+                       nt_errstr(status));
+               goto done;
+       }
+
        tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0600);
        if (tdb == NULL) {
                d_fprintf(stderr, _("failed to open tdb file: %s\n"), argv[0]);
@@ -256,6 +268,7 @@ static NTSTATUS printing_migrate_internal(struct net_context *c,
                if (strncmp((const char *) kbuf.dptr, FORMS_PREFIX, strlen(FORMS_PREFIX)) == 0) {
                        printing_tdb_migrate_form(tmp_ctx,
                                     pipe_hnd,
+                                    winreg_pipe,
                                     (const char *) kbuf.dptr + strlen(FORMS_PREFIX),
                                     dbuf.dptr,
                                     dbuf.dsize);
@@ -266,6 +279,7 @@ static NTSTATUS printing_migrate_internal(struct net_context *c,
                if (strncmp((const char *) kbuf.dptr, DRIVERS_PREFIX, strlen(DRIVERS_PREFIX)) == 0) {
                        printing_tdb_migrate_driver(tmp_ctx,
                                       pipe_hnd,
+                                      winreg_pipe,
                                       (const char *) kbuf.dptr + strlen(DRIVERS_PREFIX),
                                       dbuf.dptr,
                                       dbuf.dsize);
@@ -276,6 +290,7 @@ static NTSTATUS printing_migrate_internal(struct net_context *c,
                if (strncmp((const char *) kbuf.dptr, PRINTERS_PREFIX, strlen(PRINTERS_PREFIX)) == 0) {
                        printing_tdb_migrate_printer(tmp_ctx,
                                        pipe_hnd,
+                                       winreg_pipe,
                                        (const char *) kbuf.dptr + strlen(PRINTERS_PREFIX),
                                        dbuf.dptr,
                                        dbuf.dsize);
@@ -286,6 +301,7 @@ static NTSTATUS printing_migrate_internal(struct net_context *c,
                if (strncmp((const char *) kbuf.dptr, SECDESC_PREFIX, strlen(SECDESC_PREFIX)) == 0) {
                        printing_tdb_migrate_secdesc(tmp_ctx,
                                        pipe_hnd,
+                                       winreg_pipe,
                                        (const char *) kbuf.dptr + strlen(SECDESC_PREFIX),
                                        dbuf.dptr,
                                        dbuf.dsize);