s3-printing: Added automatic migration of printing tdbs.
authorAndreas Schneider <asn@samba.org>
Tue, 15 Jun 2010 11:37:44 +0000 (13:37 +0200)
committerSimo Sorce <idra@samba.org>
Tue, 27 Jul 2010 14:27:15 +0000 (10:27 -0400)
Signed-off-by: Jim McDonough <jmcd@samba.org>
source3/include/nt_printing.h
source3/printing/nt_printing.c
source3/printing/nt_printing_migrate.c
source3/printing/printing.c
source3/rpc_server/srv_spoolss_nt.c
source3/smbd/process.c

index 830afb480471125015525cefbb4e570d705df230..199236bd5e3fe7f7f4e951844ad741910c92ca4e 100644 (file)
@@ -229,12 +229,6 @@ WERROR spoolss_create_default_devmode(TALLOC_CTX *mem_ctx,
                                      const char *devicename,
                                      struct spoolss_DeviceMode **devmode);
 
-int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8 *buf, int buflen);
-
-int unpack_devicemode(TALLOC_CTX *mem_ctx,
-                     const uint8 *buf, int buflen,
-                     struct spoolss_DeviceMode **devmode);
-
 WERROR spoolss_create_default_secdesc(TALLOC_CTX *mem_ctx,
                                      struct spoolss_security_descriptor **secdesc);
 
index 8a06ef11c6860806405289b853742cb0cf91c373..1186c6710cfd267ca1c4ce7f4fc4324bd7071c9f 100644 (file)
@@ -82,10 +82,6 @@ bool nt_printing_init(struct messaging_context *msg_ctx)
                return false;
        }
 
-       if (!nt_printing_tdb_migrate()) {
-               return false;
-       }
-
        /*
         * register callback to handle updating printers as new
         * drivers are installed
@@ -1144,87 +1140,6 @@ WERROR move_driver_to_download_area(struct pipes_struct *p,
        return (*perr);
 }
 
-/****************************************************************************
-****************************************************************************/
-int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8 *buf, int buflen)
-{
-       enum ndr_err_code ndr_err;
-       DATA_BLOB blob;
-       int len = 0;
-
-       if (devmode) {
-               ndr_err = ndr_push_struct_blob(&blob, talloc_tos(),
-                                              devmode,
-                                              (ndr_push_flags_fn_t)
-                                              ndr_push_spoolss_DeviceMode);
-               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-                       DEBUG(10, ("pack_devicemode: "
-                                  "error encoding spoolss_DeviceMode\n"));
-                       goto done;
-               }
-       } else {
-               ZERO_STRUCT(blob);
-       }
-
-       len = tdb_pack(buf, buflen, "B", blob.length, blob.data);
-
-       if (devmode) {
-               DEBUG(8, ("Packed devicemode [%s]\n", devmode->formname));
-       }
-
-done:
-       return len;
-}
-
-/****************************************************************************
-****************************************************************************/
-int unpack_devicemode(TALLOC_CTX *mem_ctx,
-                     const uint8 *buf, int buflen,
-                     struct spoolss_DeviceMode **devmode)
-{
-       struct spoolss_DeviceMode *dm;
-       enum ndr_err_code ndr_err;
-       char *data = NULL;
-       int data_len = 0;
-       DATA_BLOB blob;
-       int len = 0;
-
-       *devmode = NULL;
-
-       len = tdb_unpack(buf, buflen, "B", &data_len, &data);
-       if (!data) {
-               return len;
-       }
-
-       dm = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
-       if (!dm) {
-               goto done;
-       }
-
-       blob = data_blob_const(data, data_len);
-
-       ndr_err = ndr_pull_struct_blob(&blob, dm, dm,
-                       (ndr_pull_flags_fn_t)ndr_pull_spoolss_DeviceMode);
-       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
-               DEBUG(10, ("unpack_devicemode: "
-                          "error parsing spoolss_DeviceMode\n"));
-               goto done;
-       }
-
-       DEBUG(8, ("Unpacked devicemode [%s](%s)\n",
-                 dm->devicename, dm->formname));
-       if (dm->driverextra_data.data) {
-               DEBUG(8, ("with a private section of %d bytes\n",
-                         dm->__driverextra_length));
-       }
-
-       *devmode = dm;
-
-done:
-       SAFE_FREE(data);
-       return len;
-}
-
 /****************************************************************************
  Create and allocate a default devicemode.
 ****************************************************************************/
index 94f8d873973b35053a38001dc7c263388a277f37..624d24539db5b2f87bfb3b43d8e7c9abb4d2bbc7 100644 (file)
@@ -602,7 +602,6 @@ bool nt_printing_tdb_migrate(void)
 
        status = rpc_pipe_open_internal(tmp_ctx,
                                        &ndr_table_spoolss.syntax_id,
-                                       rpc_spoolss_dispatch,
                                        server_info,
                                        &spoolss_pipe);
        if (!NT_STATUS_IS_OK(status)) {
index b620db03d5623f2a9a9d256d156e5d45c6d78824..3635e59c34d54211cefb6b1512f4308abea28384 100644 (file)
@@ -275,6 +275,89 @@ static TDB_DATA print_key(uint32 jobid, uint32 *tmp)
        return ret;
 }
 
+/****************************************************************************
+ Pack the devicemode to store it in a tdb.
+****************************************************************************/
+static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8 *buf, int buflen)
+{
+       enum ndr_err_code ndr_err;
+       DATA_BLOB blob;
+       int len = 0;
+
+       if (devmode) {
+               ndr_err = ndr_push_struct_blob(&blob, talloc_tos(),
+                                              devmode,
+                                              (ndr_push_flags_fn_t)
+                                              ndr_push_spoolss_DeviceMode);
+               if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+                       DEBUG(10, ("pack_devicemode: "
+                                  "error encoding spoolss_DeviceMode\n"));
+                       goto done;
+               }
+       } else {
+               ZERO_STRUCT(blob);
+       }
+
+       len = tdb_pack(buf, buflen, "B", blob.length, blob.data);
+
+       if (devmode) {
+               DEBUG(8, ("Packed devicemode [%s]\n", devmode->formname));
+       }
+
+done:
+       return len;
+}
+
+/****************************************************************************
+ Unpack the devicemode to store it in a tdb.
+****************************************************************************/
+static int unpack_devicemode(TALLOC_CTX *mem_ctx,
+                     const uint8 *buf, int buflen,
+                     struct spoolss_DeviceMode **devmode)
+{
+       struct spoolss_DeviceMode *dm;
+       enum ndr_err_code ndr_err;
+       char *data = NULL;
+       int data_len = 0;
+       DATA_BLOB blob;
+       int len = 0;
+
+       *devmode = NULL;
+
+       len = tdb_unpack(buf, buflen, "B", &data_len, &data);
+       if (!data) {
+               return len;
+       }
+
+       dm = talloc_zero(mem_ctx, struct spoolss_DeviceMode);
+       if (!dm) {
+               goto done;
+       }
+
+       blob = data_blob_const(data, data_len);
+
+       ndr_err = ndr_pull_struct_blob(&blob, dm, dm,
+                       (ndr_pull_flags_fn_t)ndr_pull_spoolss_DeviceMode);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               DEBUG(10, ("unpack_devicemode: "
+                          "error parsing spoolss_DeviceMode\n"));
+               goto done;
+       }
+
+       DEBUG(8, ("Unpacked devicemode [%s](%s)\n",
+                 dm->devicename, dm->formname));
+       if (dm->driverextra_data.data) {
+               DEBUG(8, ("with a private section of %d bytes\n",
+                         dm->__driverextra_length));
+       }
+
+       *devmode = dm;
+
+done:
+       SAFE_FREE(data);
+       return len;
+}
+
 /***********************************************************************
  unpack a pjob from a tdb buffer
 ***********************************************************************/
index ea3f3207fc98e1208be0c57e7257a85a2301180c..d781e2c95095f64c018b8b0794057a86272f385b 100644 (file)
@@ -85,7 +85,7 @@ const struct standard_mapping printer_std_mapping = {
 
 /* Map generic permissions to print server object specific permissions */
 
-const struct generic_mapping printserver_std_mapping = {
+const struct standard_mapping printserver_std_mapping = {
        SERVER_READ,
        SERVER_WRITE,
        SERVER_EXECUTE,
@@ -3213,7 +3213,7 @@ static WERROR printserver_notify_info(pipes_struct *p,
                                continue; /* skip */
                        }
 
-                       /* FIXME: should we use a SYSTEM server_info here? */
+                       /* Maybe we should use the SYSTEM server_info here... */
                        result = winreg_get_printer(mem_ctx, p->server_info,
                                                    Printer->servername,
                                                    lp_servicename(snum),
@@ -3296,7 +3296,7 @@ static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
 
        get_printer_snum(p, hnd, &snum, NULL);
 
-       /* FIXME: should we use a SYSTEM server_info here ? */
+       /* Maybe we should use the SYSTEM server_info here... */
        result = winreg_get_printer(mem_ctx, p->server_info,
                                    Printer->servername,
                                    lp_servicename(snum), &pinfo2);
@@ -5392,7 +5392,7 @@ static WERROR update_printer_sec(struct policy_handle *handle,
                struct security_acl *the_acl;
                int i;
 
-               the_acl = secdesc_ctr->sd->dacl;
+               the_acl = old_secdesc->dacl;
                DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
                           printer, the_acl->num_aces));
 
index 13fec92ea5621bcda978bc70bbc3d5f8176a2f30..d91c07e169f9c18f4b5c88985932876258f9ea39 100644 (file)
@@ -35,6 +35,7 @@
 #include "../librpc/gen_ndr/srv_winreg.h"
 #include "../librpc/gen_ndr/srv_wkssvc.h"
 #include "librpc/gen_ndr/messaging.h"
+#include "printing/nt_printing_migrate.h"
 
 extern bool global_machine_password_needs_changing;
 
@@ -2856,6 +2857,11 @@ fail:
        return false;
 }
 
+static bool spoolss_init_cb(void)
+{
+       return nt_printing_tdb_migrate();
+}
+
 /****************************************************************************
  Process commands from the client
 ****************************************************************************/
@@ -2870,6 +2876,7 @@ void smbd_process(void)
        struct tsocket_address *remote_address = NULL;
        const char *remaddr = NULL;
        int ret;
+       struct rpc_srv_callbacks spoolss_cb;
 
        if (lp_maxprotocol() == PROTOCOL_SMB2 &&
            lp_security() != SEC_SHARE &&
@@ -2969,8 +2976,6 @@ void smbd_process(void)
                   tsocket_address_string(remote_address, talloc_tos()),
                   tsocket_address_string(local_address, talloc_tos())));
 
-       static_init_rpc;
-
        init_modules();
 
        smb_perfcount_init();
@@ -3108,6 +3113,25 @@ void smbd_process(void)
                exit_server("failed to create smbd_server_connection fde");
        }
 
+       /*
+        * Initialize spoolss with an init function to convert printers first.
+        * static_init_rpc will try to initialize the spoolss server too but you
+        * can't register it twice.
+        */
+       spoolss_cb.init = spoolss_init_cb;
+       spoolss_cb.shutdown = NULL;
+
+
+       if (!NT_STATUS_IS_OK(rpc_winreg_init(NULL))) {
+               exit(1);
+       }
+
+       if (!NT_STATUS_IS_OK(rpc_spoolss_init(&spoolss_cb))) {
+               exit(1);
+       }
+
+       static_init_rpc;
+
        TALLOC_FREE(frame);
 
        while (True) {