s3: Lift the server_messaging_context from construct_printer_info2
[amitay/samba.git] / source3 / rpc_server / srv_spoolss_nt.c
index 89b9e7acd148cf32dd0773853b8da01f3833ea9d..733307df56b4cc3a69ca30333bf387fa46a9f01f 100644 (file)
@@ -159,7 +159,9 @@ static int nt_printq_status(int v)
  Disconnect from the client
 ****************************************************************************/
 
-static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
+static void srv_spoolss_replycloseprinter(
+       int snum, struct policy_handle *handle,
+       struct messaging_context *msg_ctx)
 {
        WERROR result;
        NTSTATUS status;
@@ -172,7 +174,7 @@ static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle
        if (!print_notify_deregister_pid(snum))
                DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
 
-       /* weird if the test succeds !!! */
+       /* weird if the test succeeds !!! */
        if (smb_connections==0) {
                DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
                return;
@@ -189,17 +191,24 @@ static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle
        if (smb_connections==1) {
 
                cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
-               notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
+               /*
+                * The above call shuts down the pipe also.
+                */
+               notify_cli_pipe = NULL;
 
-               messaging_deregister(smbd_messaging_context(),
-                                    MSG_PRINTER_NOTIFY2, NULL);
+               if (msg_ctx != NULL) {
+                       messaging_deregister(msg_ctx, MSG_PRINTER_NOTIFY2,
+                                            NULL);
 
-               /* Tell the connections db we're no longer interested in
-                * printer notify messages. */
+                       /*
+                        * Tell the serverid.tdb we're no longer
+                        * interested in printer notify messages.
+                        */
 
-               serverid_register_msg_flags(
-                       messaging_server_id(smbd_messaging_context()),
-                       false, FLAG_MSG_PRINT_NOTIFY);
+                       serverid_register_msg_flags(
+                               messaging_server_id(msg_ctx),
+                               false, FLAG_MSG_PRINT_NOTIFY);
+               }
        }
 
        smb_connections--;
@@ -216,12 +225,15 @@ static int printer_entry_destructor(Printer_entry *Printer)
 
                if ( Printer->printer_type == SPLHND_SERVER) {
                        snum = -1;
-                       srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
+                       srv_spoolss_replycloseprinter(
+                               snum, &Printer->notify.client_hnd,
+                               Printer->notify.msg_ctx);
                } else if (Printer->printer_type == SPLHND_PRINTER) {
                        snum = print_queue_snum(Printer->sharename);
                        if (snum != -1)
-                               srv_spoolss_replycloseprinter(snum,
-                                               &Printer->notify.client_hnd);
+                               srv_spoolss_replycloseprinter(
+                                       snum, &Printer->notify.client_hnd,
+                                       Printer->notify.msg_ctx);
                }
        }
 
@@ -329,7 +341,7 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
 
        /* go ahead and re-read the services immediately */
        become_root();
-       reload_services(false);
+       reload_services(msg_ctx, false);
        unbecome_root();
 
        if ( lp_servicenumber( sharename )  > 0 )
@@ -369,7 +381,7 @@ static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle
           done on the handle already */
 
        result = winreg_delete_printer_key(p->mem_ctx, p->server_info,
-                                          Printer->sharename, "");
+                                          p->msg_ctx, Printer->sharename, "");
        if (!W_ERROR_IS_OK(result)) {
                DEBUG(3,("Error deleting printer %s\n", Printer->sharename));
                return WERR_BADFID;
@@ -443,6 +455,7 @@ static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *hand
 
 static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
                                 struct auth_serversupplied_info *server_info,
+                                struct messaging_context *msg_ctx,
                                 Printer_entry *Printer,
                                 const char *handlename)
 {
@@ -527,6 +540,7 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
 
                result = winreg_get_printer(mem_ctx,
                                            server_info,
+                                           msg_ctx,
                                            servername,
                                            sname,
                                            &info2);
@@ -597,7 +611,8 @@ static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
                return false;
        }
 
-       if (!set_printer_hnd_name(p->mem_ctx, p->server_info, new_printer, name)) {
+       if (!set_printer_hnd_name(p->mem_ctx, p->server_info, p->msg_ctx,
+                                 new_printer, name)) {
                close_printer_handle(p, hnd);
                return false;
        }
@@ -1333,7 +1348,8 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
                        continue;
                }
 
-               result = winreg_get_printer(tmp_ctx, server_info, NULL,
+               result = winreg_get_printer(tmp_ctx, server_info, msg,
+                                           NULL,
                                            lp_const_servicename(snum),
                                            &pinfo2);
 
@@ -1354,6 +1370,7 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
                /* all we care about currently is the change_id */
                result = winreg_printer_update_changeid(tmp_ctx,
                                                        server_info,
+                                                       msg,
                                                        pinfo2->printername);
 
                if (!W_ERROR_IS_OK(result)) {
@@ -1373,7 +1390,7 @@ done:
  connection
  ********************************************************************/
 
-void update_monitored_printq_cache( void )
+void update_monitored_printq_cache(struct messaging_context *msg_ctx)
 {
        Printer_entry *printer = printers_list;
        int snum;
@@ -1386,7 +1403,7 @@ void update_monitored_printq_cache( void )
                        && printer->notify.client_connected )
                {
                        snum = print_queue_snum(printer->sharename);
-                       print_queue_status( snum, NULL, NULL );
+                       print_queue_status(msg_ctx, snum, NULL, NULL );
                }
 
                printer = printer->next;
@@ -1633,7 +1650,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
                if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
                                   p->server_info->ptok, snum) ||
-                   !print_access_check(p->server_info, snum,
+                   !print_access_check(p->server_info, p->msg_ctx, snum,
                                        r->in.access_mask)) {
                        DEBUG(3, ("access DENIED for printer open\n"));
                        close_printer_handle(p, r->out.handle);
@@ -1658,6 +1675,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
                winreg_create_printer(p->mem_ctx,
                                      p->server_info,
+                                     p->msg_ctx,
                                      Printer->servername,
                                      lp_const_servicename(snum));
 
@@ -1749,6 +1767,7 @@ WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
        if (get_printer_snum(p, r->in.handle, &snum, NULL)) {
                winreg_delete_printer_key(p->mem_ctx,
                                          p->server_info,
+                                         p->msg_ctx,
                                          lp_const_servicename(snum),
                                          "");
        }
@@ -1822,7 +1841,7 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
        if ((version = get_version_id(r->in.architecture)) == -1)
                return WERR_INVALID_ENVIRONMENT;
 
-       status = winreg_get_driver(p->mem_ctx, p->server_info,
+       status = winreg_get_driver(p->mem_ctx, p->server_info, p->msg_ctx,
                                   r->in.architecture, r->in.driver,
                                   version, &info);
        if (!W_ERROR_IS_OK(status)) {
@@ -1832,6 +1851,7 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
                        version = 3;
 
                        status = winreg_get_driver(p->mem_ctx, p->server_info,
+                                                  p->msg_ctx,
                                                   r->in.architecture,
                                                   r->in.driver,
                                                   version, &info);
@@ -1848,13 +1868,15 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
 
        }
 
-       if (printer_driver_in_use(p->mem_ctx, p->server_info, info)) {
+       if (printer_driver_in_use(p->mem_ctx, p->server_info, p->msg_ctx,
+                                 info)) {
                status = WERR_PRINTER_DRIVER_IN_USE;
                goto done;
        }
 
        if (version == 2) {
                status = winreg_get_driver(p->mem_ctx, p->server_info,
+                                          p->msg_ctx,
                                           r->in.architecture,
                                           r->in.driver, 3, &info_win2k);
                if (W_ERROR_IS_OK(status)) {
@@ -1863,6 +1885,7 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
 
                        status = winreg_del_driver(p->mem_ctx,
                                                   p->server_info,
+                                                  p->msg_ctx,
                                                   info_win2k, 3);
                        talloc_free(info_win2k);
 
@@ -1873,7 +1896,8 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
                }
        }
 
-       status = winreg_del_driver(p->mem_ctx, p->server_info, info, version);
+       status = winreg_del_driver(p->mem_ctx, p->server_info, p->msg_ctx,
+                                  info, version);
 
 done:
        talloc_free(info);
@@ -1919,8 +1943,8 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                version = r->in.version;
 
        status = winreg_get_driver(p->mem_ctx, p->server_info,
-                                  r->in.architecture, r->in.driver,
-                                  version, &info);
+                                  p->msg_ctx, r->in.architecture,
+                                  r->in.driver, version, &info);
        if (!W_ERROR_IS_OK(status)) {
                status = WERR_UNKNOWN_PRINTER_DRIVER;
 
@@ -1936,7 +1960,7 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                /* try for Win2k driver if "Windows NT x86" */
 
                version = 3;
-               status = winreg_get_driver(info, p->server_info,
+               status = winreg_get_driver(info, p->server_info, p->msg_ctx,
                                           r->in.architecture,
                                           r->in.driver,
                                           version, &info);
@@ -1946,7 +1970,7 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                }
        }
 
-       if (printer_driver_in_use(info, p->server_info, info)) {
+       if (printer_driver_in_use(info, p->server_info, p->msg_ctx, info)) {
                status = WERR_PRINTER_DRIVER_IN_USE;
                goto done;
        }
@@ -1969,7 +1993,8 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
 
        if (delete_files &&
            (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
-           printer_driver_files_in_use(info, p->server_info, info)) {
+           printer_driver_files_in_use(info, p->server_info, p->msg_ctx,
+                                       info)) {
                /* no idea of the correct error here */
                status = WERR_ACCESS_DENIED;
                goto done;
@@ -1979,7 +2004,7 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
        /* also check for W32X86/3 if necessary; maybe we already have? */
 
        if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION)  ) {
-               status = winreg_get_driver(info, p->server_info,
+               status = winreg_get_driver(info, p->server_info, p->msg_ctx,
                                           r->in.architecture,
                                           r->in.driver, 3, &info_win2k);
                if (W_ERROR_IS_OK(status)) {
@@ -1987,6 +2012,7 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                        if (delete_files &&
                            (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
                            printer_driver_files_in_use(info, p->server_info,
+                                                       p->msg_ctx,
                                                        info_win2k)) {
                                /* no idea of the correct error here */
                                talloc_free(info_win2k);
@@ -1998,7 +2024,7 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                        /* remove the Win2k driver first*/
 
                        status = winreg_del_driver(info, p->server_info,
-                                                  info_win2k, 3);
+                                                  p->msg_ctx, info_win2k, 3);
 
                        /* this should not have failed---if it did, report to client */
 
@@ -2018,7 +2044,8 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                }
        }
 
-       status = winreg_del_driver(info, p->server_info, info, version);
+       status = winreg_del_driver(info, p->server_info, p->msg_ctx, info,
+                                  version);
        if (!W_ERROR_IS_OK(status)) {
                goto done;
        }
@@ -2225,7 +2252,7 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
                        addr));
        }
 
-       if (ismyaddr((struct sockaddr *)&rm_addr)) {
+       if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
                DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
                        addr));
                return false;
@@ -2407,6 +2434,7 @@ WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
        Printer->notify.flags           = r->in.flags;
        Printer->notify.options         = r->in.options;
        Printer->notify.printerlocal    = r->in.printer_local;
+       Printer->notify.msg_ctx         = p->msg_ctx;
 
        TALLOC_FREE(Printer->notify.option);
        Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
@@ -2444,7 +2472,8 @@ WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
  * fill a notify_info_data with the servername
  ********************************************************************/
 
-static void spoolss_notify_server_name(int snum,
+static void spoolss_notify_server_name(struct messaging_context *msg_ctx,
+                                      int snum,
                                       struct spoolss_Notify *data,
                                       print_queue_struct *queue,
                                       struct spoolss_PrinterInfo2 *pinfo2,
@@ -2457,7 +2486,8 @@ static void spoolss_notify_server_name(int snum,
  * fill a notify_info_data with the printername (not including the servername).
  ********************************************************************/
 
-static void spoolss_notify_printer_name(int snum,
+static void spoolss_notify_printer_name(struct messaging_context *msg_ctx,
+                                       int snum,
                                        struct spoolss_Notify *data,
                                        print_queue_struct *queue,
                                        struct spoolss_PrinterInfo2 *pinfo2,
@@ -2479,7 +2509,8 @@ static void spoolss_notify_printer_name(int snum,
  * fill a notify_info_data with the servicename
  ********************************************************************/
 
-static void spoolss_notify_share_name(int snum,
+static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
+                                     int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
                                      struct spoolss_PrinterInfo2 *pinfo2,
@@ -2492,7 +2523,8 @@ static void spoolss_notify_share_name(int snum,
  * fill a notify_info_data with the port name
  ********************************************************************/
 
-static void spoolss_notify_port_name(int snum,
+static void spoolss_notify_port_name(struct messaging_context *msg_ctx,
+                                    int snum,
                                     struct spoolss_Notify *data,
                                     print_queue_struct *queue,
                                     struct spoolss_PrinterInfo2 *pinfo2,
@@ -2506,7 +2538,8 @@ static void spoolss_notify_port_name(int snum,
  * but it doesn't exist, have to see what to do
  ********************************************************************/
 
-static void spoolss_notify_driver_name(int snum,
+static void spoolss_notify_driver_name(struct messaging_context *msg_ctx,
+                                      int snum,
                                       struct spoolss_Notify *data,
                                       print_queue_struct *queue,
                                       struct spoolss_PrinterInfo2 *pinfo2,
@@ -2519,7 +2552,8 @@ static void spoolss_notify_driver_name(int snum,
  * fill a notify_info_data with the comment
  ********************************************************************/
 
-static void spoolss_notify_comment(int snum,
+static void spoolss_notify_comment(struct messaging_context *msg_ctx,
+                                  int snum,
                                   struct spoolss_Notify *data,
                                   print_queue_struct *queue,
                                   struct spoolss_PrinterInfo2 *pinfo2,
@@ -2541,7 +2575,8 @@ static void spoolss_notify_comment(int snum,
  * location = "Room 1, floor 2, building 3"
  ********************************************************************/
 
-static void spoolss_notify_location(int snum,
+static void spoolss_notify_location(struct messaging_context *msg_ctx,
+                                   int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
                                    struct spoolss_PrinterInfo2 *pinfo2,
@@ -2555,7 +2590,8 @@ static void spoolss_notify_location(int snum,
  * jfm:xxxx don't to it for know but that's a real problem !!!
  ********************************************************************/
 
-static void spoolss_notify_devmode(int snum,
+static void spoolss_notify_devmode(struct messaging_context *msg_ctx,
+                                  int snum,
                                   struct spoolss_Notify *data,
                                   print_queue_struct *queue,
                                   struct spoolss_PrinterInfo2 *pinfo2,
@@ -2569,7 +2605,8 @@ static void spoolss_notify_devmode(int snum,
  * fill a notify_info_data with the separator file name
  ********************************************************************/
 
-static void spoolss_notify_sepfile(int snum,
+static void spoolss_notify_sepfile(struct messaging_context *msg_ctx,
+                                  int snum,
                                   struct spoolss_Notify *data,
                                   print_queue_struct *queue,
                                   struct spoolss_PrinterInfo2 *pinfo2,
@@ -2583,7 +2620,8 @@ static void spoolss_notify_sepfile(int snum,
  * jfm:xxxx return always winprint to indicate we don't do anything to it
  ********************************************************************/
 
-static void spoolss_notify_print_processor(int snum,
+static void spoolss_notify_print_processor(struct messaging_context *msg_ctx,
+                                          int snum,
                                           struct spoolss_Notify *data,
                                           print_queue_struct *queue,
                                           struct spoolss_PrinterInfo2 *pinfo2,
@@ -2597,7 +2635,8 @@ static void spoolss_notify_print_processor(int snum,
  * jfm:xxxx send an empty string
  ********************************************************************/
 
-static void spoolss_notify_parameters(int snum,
+static void spoolss_notify_parameters(struct messaging_context *msg_ctx,
+                                     int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
                                      struct spoolss_PrinterInfo2 *pinfo2,
@@ -2611,7 +2650,8 @@ static void spoolss_notify_parameters(int snum,
  * jfm:xxxx always send RAW as data type
  ********************************************************************/
 
-static void spoolss_notify_datatype(int snum,
+static void spoolss_notify_datatype(struct messaging_context *msg_ctx,
+                                   int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
                                    struct spoolss_PrinterInfo2 *pinfo2,
@@ -2626,7 +2666,8 @@ static void spoolss_notify_datatype(int snum,
  * have to implement security before !
  ********************************************************************/
 
-static void spoolss_notify_security_desc(int snum,
+static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
+                                        int snum,
                                         struct spoolss_Notify *data,
                                         print_queue_struct *queue,
                                         struct spoolss_PrinterInfo2 *pinfo2,
@@ -2640,7 +2681,8 @@ static void spoolss_notify_security_desc(int snum,
  * jfm:xxxx a samba printer is always shared
  ********************************************************************/
 
-static void spoolss_notify_attributes(int snum,
+static void spoolss_notify_attributes(struct messaging_context *msg_ctx,
+                                     int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
                                      struct spoolss_PrinterInfo2 *pinfo2,
@@ -2653,7 +2695,8 @@ static void spoolss_notify_attributes(int snum,
  * fill a notify_info_data with the priority
  ********************************************************************/
 
-static void spoolss_notify_priority(int snum,
+static void spoolss_notify_priority(struct messaging_context *msg_ctx,
+                                   int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
                                    struct spoolss_PrinterInfo2 *pinfo2,
@@ -2666,7 +2709,8 @@ static void spoolss_notify_priority(int snum,
  * fill a notify_info_data with the default priority
  ********************************************************************/
 
-static void spoolss_notify_default_priority(int snum,
+static void spoolss_notify_default_priority(struct messaging_context *msg_ctx,
+                                           int snum,
                                            struct spoolss_Notify *data,
                                            print_queue_struct *queue,
                                            struct spoolss_PrinterInfo2 *pinfo2,
@@ -2679,7 +2723,8 @@ static void spoolss_notify_default_priority(int snum,
  * fill a notify_info_data with the start time
  ********************************************************************/
 
-static void spoolss_notify_start_time(int snum,
+static void spoolss_notify_start_time(struct messaging_context *msg_ctx,
+                                     int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
                                      struct spoolss_PrinterInfo2 *pinfo2,
@@ -2692,7 +2737,8 @@ static void spoolss_notify_start_time(int snum,
  * fill a notify_info_data with the until time
  ********************************************************************/
 
-static void spoolss_notify_until_time(int snum,
+static void spoolss_notify_until_time(struct messaging_context *msg_ctx,
+                                     int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
                                      struct spoolss_PrinterInfo2 *pinfo2,
@@ -2705,7 +2751,8 @@ static void spoolss_notify_until_time(int snum,
  * fill a notify_info_data with the status
  ********************************************************************/
 
-static void spoolss_notify_status(int snum,
+static void spoolss_notify_status(struct messaging_context *msg_ctx,
+                                 int snum,
                                  struct spoolss_Notify *data,
                                  print_queue_struct *queue,
                                  struct spoolss_PrinterInfo2 *pinfo2,
@@ -2713,7 +2760,7 @@ static void spoolss_notify_status(int snum,
 {
        print_status_struct status;
 
-       print_queue_length(snum, &status);
+       print_queue_length(msg_ctx, snum, &status);
        SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, status.status);
 }
 
@@ -2721,20 +2768,23 @@ static void spoolss_notify_status(int snum,
  * fill a notify_info_data with the number of jobs queued
  ********************************************************************/
 
-static void spoolss_notify_cjobs(int snum,
+static void spoolss_notify_cjobs(struct messaging_context *msg_ctx,
+                                int snum,
                                 struct spoolss_Notify *data,
                                 print_queue_struct *queue,
                                 struct spoolss_PrinterInfo2 *pinfo2,
                                 TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
+       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(
+               data, print_queue_length(msg_ctx, snum, NULL));
 }
 
 /*******************************************************************
  * fill a notify_info_data with the average ppm
  ********************************************************************/
 
-static void spoolss_notify_average_ppm(int snum,
+static void spoolss_notify_average_ppm(struct messaging_context *msg_ctx,
+                                      int snum,
                                       struct spoolss_Notify *data,
                                       print_queue_struct *queue,
                                       struct spoolss_PrinterInfo2 *pinfo2,
@@ -2749,7 +2799,8 @@ static void spoolss_notify_average_ppm(int snum,
  * fill a notify_info_data with username
  ********************************************************************/
 
-static void spoolss_notify_username(int snum,
+static void spoolss_notify_username(struct messaging_context *msg_ctx,
+                                   int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
                                    struct spoolss_PrinterInfo2 *pinfo2,
@@ -2762,7 +2813,8 @@ static void spoolss_notify_username(int snum,
  * fill a notify_info_data with job status
  ********************************************************************/
 
-static void spoolss_notify_job_status(int snum,
+static void spoolss_notify_job_status(struct messaging_context *msg_ctx,
+                                     int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
                                      struct spoolss_PrinterInfo2 *pinfo2,
@@ -2775,7 +2827,8 @@ static void spoolss_notify_job_status(int snum,
  * fill a notify_info_data with job name
  ********************************************************************/
 
-static void spoolss_notify_job_name(int snum,
+static void spoolss_notify_job_name(struct messaging_context *msg_ctx,
+                                   int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
                                    struct spoolss_PrinterInfo2 *pinfo2,
@@ -2788,7 +2841,8 @@ static void spoolss_notify_job_name(int snum,
  * fill a notify_info_data with job status
  ********************************************************************/
 
-static void spoolss_notify_job_status_string(int snum,
+static void spoolss_notify_job_status_string(struct messaging_context *msg_ctx,
+                                            int snum,
                                             struct spoolss_Notify *data,
                                             print_queue_struct *queue,
                                             struct spoolss_PrinterInfo2 *pinfo2,
@@ -2826,7 +2880,8 @@ static void spoolss_notify_job_status_string(int snum,
  * fill a notify_info_data with job time
  ********************************************************************/
 
-static void spoolss_notify_job_time(int snum,
+static void spoolss_notify_job_time(struct messaging_context *msg_ctx,
+                                   int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
                                    struct spoolss_PrinterInfo2 *pinfo2,
@@ -2839,7 +2894,8 @@ static void spoolss_notify_job_time(int snum,
  * fill a notify_info_data with job size
  ********************************************************************/
 
-static void spoolss_notify_job_size(int snum,
+static void spoolss_notify_job_size(struct messaging_context *msg_ctx,
+                                   int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
                                    struct spoolss_PrinterInfo2 *pinfo2,
@@ -2851,7 +2907,8 @@ static void spoolss_notify_job_size(int snum,
 /*******************************************************************
  * fill a notify_info_data with page info
  ********************************************************************/
-static void spoolss_notify_total_pages(int snum,
+static void spoolss_notify_total_pages(struct messaging_context *msg_ctx,
+                                      int snum,
                                struct spoolss_Notify *data,
                                print_queue_struct *queue,
                                struct spoolss_PrinterInfo2 *pinfo2,
@@ -2863,7 +2920,8 @@ static void spoolss_notify_total_pages(int snum,
 /*******************************************************************
  * fill a notify_info_data with pages printed info.
  ********************************************************************/
-static void spoolss_notify_pages_printed(int snum,
+static void spoolss_notify_pages_printed(struct messaging_context *msg_ctx,
+                                        int snum,
                                struct spoolss_Notify *data,
                                print_queue_struct *queue,
                                struct spoolss_PrinterInfo2 *pinfo2,
@@ -2877,7 +2935,8 @@ static void spoolss_notify_pages_printed(int snum,
  Fill a notify_info_data with job position.
  ********************************************************************/
 
-static void spoolss_notify_job_position(int snum,
+static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
+                                       int snum,
                                        struct spoolss_Notify *data,
                                        print_queue_struct *queue,
                                        struct spoolss_PrinterInfo2 *pinfo2,
@@ -2890,7 +2949,8 @@ static void spoolss_notify_job_position(int snum,
  Fill a notify_info_data with submitted time.
  ********************************************************************/
 
-static void spoolss_notify_submitted_time(int snum,
+static void spoolss_notify_submitted_time(struct messaging_context *msg_ctx,
+                                         int snum,
                                          struct spoolss_Notify *data,
                                          print_queue_struct *queue,
                                          struct spoolss_PrinterInfo2 *pinfo2,
@@ -2911,7 +2971,8 @@ struct s_notify_info_data_table
        uint16_t field;
        const char *name;
        enum spoolss_NotifyTable variable_type;
-       void (*fn) (int snum, struct spoolss_Notify *data,
+       void (*fn) (struct messaging_context *msg_ctx,
+                   int snum, struct spoolss_Notify *data,
                    print_queue_struct *queue,
                    struct spoolss_PrinterInfo2 *pinfo2,
                    TALLOC_CTX *mem_ctx);
@@ -3035,7 +3096,8 @@ static void construct_info_data(struct spoolss_Notify *info_data,
  *
  ********************************************************************/
 
-static bool construct_notify_printer_info(Printer_entry *print_hnd,
+static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
+                                         Printer_entry *print_hnd,
                                          struct spoolss_NotifyInfo *info,
                                          struct spoolss_PrinterInfo2 *pinfo2,
                                          int snum,
@@ -3081,8 +3143,8 @@ static bool construct_notify_printer_info(Printer_entry *print_hnd,
                           notify_info_data_table[j].name, snum,
                           pinfo2->printername));
 
-               notify_info_data_table[j].fn(snum, current_data, queue,
-                                            pinfo2, mem_ctx);
+               notify_info_data_table[j].fn(msg_ctx, snum, current_data,
+                                            queue, pinfo2, mem_ctx);
 
                info->count++;
        }
@@ -3096,7 +3158,8 @@ static bool construct_notify_printer_info(Printer_entry *print_hnd,
  *
  ********************************************************************/
 
-static bool construct_notify_jobs_info(print_queue_struct *queue,
+static bool construct_notify_jobs_info(struct messaging_context *msg_ctx,
+                                      print_queue_struct *queue,
                                       struct spoolss_NotifyInfo *info,
                                       struct spoolss_PrinterInfo2 *pinfo2,
                                       int snum,
@@ -3134,8 +3197,8 @@ static bool construct_notify_jobs_info(print_queue_struct *queue,
                current_data=&(info->notifies[info->count]);
 
                construct_info_data(current_data, type, field, id);
-               notify_info_data_table[j].fn(snum, current_data, queue,
-                                            pinfo2, mem_ctx);
+               notify_info_data_table[j].fn(msg_ctx, snum, current_data,
+                                            queue, pinfo2, mem_ctx);
                info->count++;
        }
 
@@ -3218,6 +3281,7 @@ static WERROR printserver_notify_info(struct pipes_struct *p,
 
                        /* Maybe we should use the SYSTEM server_info here... */
                        result = winreg_get_printer(mem_ctx, p->server_info,
+                                                   p->msg_ctx,
                                                    Printer->servername,
                                                    lp_servicename(snum),
                                                    &pinfo2);
@@ -3229,7 +3293,8 @@ static WERROR printserver_notify_info(struct pipes_struct *p,
                        }
 
 
-                       construct_notify_printer_info(Printer, info,
+                       construct_notify_printer_info(p->msg_ctx,
+                                                     Printer, info,
                                                      pinfo2, snum,
                                                      &option_type, snum,
                                                      mem_ctx);
@@ -3301,7 +3366,7 @@ static WERROR printer_notify_info(struct pipes_struct *p,
        get_printer_snum(p, hnd, &snum, NULL);
 
        /* Maybe we should use the SYSTEM server_info here... */
-       result = winreg_get_printer(mem_ctx, p->server_info,
+       result = winreg_get_printer(mem_ctx, p->server_info, p->msg_ctx,
                                    Printer->servername,
                                    lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
@@ -3313,7 +3378,8 @@ static WERROR printer_notify_info(struct pipes_struct *p,
 
                switch (option_type.type) {
                case PRINTER_NOTIFY_TYPE:
-                       if (construct_notify_printer_info(Printer, info,
+                       if (construct_notify_printer_info(p->msg_ctx,
+                                                         Printer, info,
                                                          pinfo2, snum,
                                                          &option_type, id,
                                                          mem_ctx)) {
@@ -3323,10 +3389,12 @@ static WERROR printer_notify_info(struct pipes_struct *p,
 
                case JOB_NOTIFY_TYPE:
 
-                       count = print_queue_status(snum, &queue, &status);
+                       count = print_queue_status(p->msg_ctx, snum, &queue,
+                                                  &status);
 
                        for (j=0; j<count; j++) {
-                               construct_notify_jobs_info(&queue[j], info,
+                               construct_notify_jobs_info(p->msg_ctx,
+                                                          &queue[j], info,
                                                           pinfo2, snum,
                                                           &option_type,
                                                           queue[j].job,
@@ -3433,6 +3501,7 @@ done:
 
 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
                                      struct auth_serversupplied_info *server_info,
+                                     struct messaging_context *msg_ctx,
                                      struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_PrinterInfo0 *r,
                                      int snum)
@@ -3448,7 +3517,7 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
        r->servername           = talloc_strdup(mem_ctx, info2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->servername);
 
-       count = print_queue_length(snum, &status);
+       count = print_queue_length(msg_ctx, snum, &status);
 
        /* check if we already have a counter for this printer */
        for (session_counter = counter_list; session_counter; session_counter = session_counter->next) {
@@ -3495,7 +3564,11 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
        r->number_of_processors         = 0x1;
        r->processor_type               = PROCESSOR_INTEL_PENTIUM; /* 586 Pentium ? */
        r->high_part_total_bytes        = 0x0;
-       winreg_printer_get_changeid(mem_ctx, server_info, info2->sharename, &r->change_id); /* ChangeID in milliseconds*/
+
+       /* ChangeID in milliseconds*/
+       winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
+                                   info2->sharename, &r->change_id);
+
        r->last_error                   = WERR_OK;
        r->status                       = nt_printq_status(status.status);
        r->enumerate_network_printers   = 0x0;
@@ -3548,6 +3621,7 @@ static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
 ********************************************************************/
 
 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
+                                     struct messaging_context *msg_ctx,
                                      const struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_PrinterInfo2 *r,
                                      int snum)
@@ -3555,7 +3629,7 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
        int count;
        print_status_struct status;
 
-       count = print_queue_length(snum, &status);
+       count = print_queue_length(msg_ctx, snum, &status);
 
        r->servername           = talloc_strdup(mem_ctx, info2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->servername);
@@ -3693,7 +3767,7 @@ static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
        int count;
        print_status_struct status;
 
-       count = print_queue_length(snum, &status);
+       count = print_queue_length(server_messaging_context(), snum, &status);
 
        r->status = nt_printq_status(status.status);
 
@@ -3706,6 +3780,7 @@ static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
+                                     struct messaging_context *msg_ctx,
                                      Printer_entry *print_hnd,
                                      struct spoolss_PrinterInfo7 *r,
                                      int snum)
@@ -3721,7 +3796,8 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
                return WERR_NOMEM;
        }
 
-       if (is_printer_published(mem_ctx, server_info, print_hnd->servername,
+       if (is_printer_published(mem_ctx, server_info, msg_ctx,
+                                print_hnd->servername,
                                 lp_servicename(snum), &guid, NULL)) {
                r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
                r->action = DSPRINT_PUBLISH;
@@ -3768,6 +3844,7 @@ static bool snum_is_shared_printer(int snum)
 
 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                                           struct auth_serversupplied_info *server_info,
+                                          struct messaging_context *msg_ctx,
                                           uint32_t level,
                                           uint32_t flags,
                                           union spoolss_PrinterInfo **info_p,
@@ -3798,6 +3875,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
 
                result = winreg_create_printer(mem_ctx,
                                               server_info,
+                                              msg_ctx,
                                               NULL,
                                               printer);
                if (!W_ERROR_IS_OK(result)) {
@@ -3812,7 +3890,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                        goto out;
                }
 
-               result = winreg_get_printer(mem_ctx, server_info,
+               result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
                                            NULL, printer, &info2);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
@@ -3820,7 +3898,8 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
 
                switch (level) {
                case 0:
-                       result = construct_printer_info0(info, server_info, info2,
+                       result = construct_printer_info0(info, server_info,
+                                                        msg_ctx, info2,
                                                         &info[count].info0, snum);
                        break;
                case 1:
@@ -3828,7 +3907,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                                                         &info[count].info1, snum);
                        break;
                case 2:
-                       result = construct_printer_info2(info, info2,
+                       result = construct_printer_info2(info, msg_ctx, info2,
                                                         &info[count].info2, snum);
                        break;
                case 4:
@@ -3872,6 +3951,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
 
 static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
                                  struct auth_serversupplied_info *server_info,
+                                 struct messaging_context *msg_ctx,
                                  uint32_t flags,
                                  const char *servername,
                                  union spoolss_PrinterInfo **info,
@@ -3879,7 +3959,8 @@ static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
 {
        DEBUG(4,("enum_all_printers_info_0\n"));
 
-       return enum_all_printers_info_level(mem_ctx, server_info, 0, flags, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
+                                           0, flags, info, count);
 }
 
 
@@ -3888,13 +3969,15 @@ static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
 
 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
                                       struct auth_serversupplied_info *server_info,
+                                      struct messaging_context *msg_ctx,
                                       uint32_t flags,
                                       union spoolss_PrinterInfo **info,
                                       uint32_t *count)
 {
        DEBUG(4,("enum_all_printers_info_1\n"));
 
-       return enum_all_printers_info_level(mem_ctx, server_info, 1, flags, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
+                                           1, flags, info, count);
 }
 
 /********************************************************************
@@ -3903,12 +3986,14 @@ static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
 
 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
                                             struct auth_serversupplied_info *server_info,
+                                            struct messaging_context *msg_ctx,
                                             union spoolss_PrinterInfo **info,
                                             uint32_t *count)
 {
        DEBUG(4,("enum_all_printers_info_1_local\n"));
 
-       return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
+       return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
+                                       PRINTER_ENUM_ICON8, info, count);
 }
 
 /********************************************************************
@@ -3917,6 +4002,7 @@ static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
 
 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
                                            struct auth_serversupplied_info *server_info,
+                                           struct messaging_context *msg_ctx,
                                            const char *name,
                                            union spoolss_PrinterInfo **info,
                                            uint32_t *count)
@@ -3933,7 +4019,8 @@ static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
                return WERR_INVALID_NAME;
        }
 
-       return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
+       return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
+                                       PRINTER_ENUM_ICON8, info, count);
 }
 
 /********************************************************************
@@ -3942,6 +4029,7 @@ static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
 
 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
                                               struct auth_serversupplied_info *server_info,
+                                              struct messaging_context *msg_ctx,
                                               const char *name,
                                               union spoolss_PrinterInfo **info,
                                               uint32_t *count)
@@ -3966,7 +4054,8 @@ static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
                 return WERR_CAN_NOT_COMPLETE;
        }
 
-       return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_NAME, info, count);
+       return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
+                                       PRINTER_ENUM_NAME, info, count);
 }
 
 /********************************************************************
@@ -3977,12 +4066,14 @@ static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
 
 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
                                       struct auth_serversupplied_info *server_info,
+                                      struct messaging_context *msg_ctx,
                                       union spoolss_PrinterInfo **info,
                                       uint32_t *count)
 {
        DEBUG(4,("enum_all_printers_info_2\n"));
 
-       return enum_all_printers_info_level(mem_ctx, server_info, 2, 0, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
+                                           2, 0, info, count);
 }
 
 /********************************************************************
@@ -3991,6 +4082,7 @@ static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
 
 static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
                                  struct auth_serversupplied_info *server_info,
+                                 struct messaging_context *msg_ctx,
                                  uint32_t flags,
                                  const char *name,
                                  union spoolss_PrinterInfo **info,
@@ -3999,15 +4091,20 @@ static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
        /* Not all the flags are equals */
 
        if (flags & PRINTER_ENUM_LOCAL) {
-               return enum_all_printers_info_1_local(mem_ctx, server_info, info, count);
+               return enum_all_printers_info_1_local(mem_ctx, server_info,
+                                                     msg_ctx, info, count);
        }
 
        if (flags & PRINTER_ENUM_NAME) {
-               return enum_all_printers_info_1_name(mem_ctx, server_info, name, info, count);
+               return enum_all_printers_info_1_name(mem_ctx, server_info,
+                                                    msg_ctx, name, info,
+                                                    count);
        }
 
        if (flags & PRINTER_ENUM_NETWORK) {
-               return enum_all_printers_info_1_network(mem_ctx, server_info, name, info, count);
+               return enum_all_printers_info_1_network(mem_ctx, server_info,
+                                                       msg_ctx, name, info,
+                                                       count);
        }
 
        return WERR_OK; /* NT4sp5 does that */
@@ -4019,13 +4116,15 @@ static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
 
 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
                                  struct auth_serversupplied_info *server_info,
+                                 struct messaging_context *msg_ctx,
                                  uint32_t flags,
                                  const char *servername,
                                  union spoolss_PrinterInfo **info,
                                  uint32_t *count)
 {
        if (flags & PRINTER_ENUM_LOCAL) {
-               return enum_all_printers_info_2(mem_ctx, server_info, info, count);
+               return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
+                                               info, count);
        }
 
        if (flags & PRINTER_ENUM_NAME) {
@@ -4033,7 +4132,8 @@ static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
                        return WERR_INVALID_NAME;
                }
 
-               return enum_all_printers_info_2(mem_ctx, server_info, info, count);
+               return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
+                                               info, count);
        }
 
        if (flags & PRINTER_ENUM_REMOTE) {
@@ -4049,6 +4149,7 @@ static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
 
 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
                                  struct auth_serversupplied_info *server_info,
+                                 struct messaging_context *msg_ctx,
                                  uint32_t flags,
                                  const char *servername,
                                  union spoolss_PrinterInfo **info,
@@ -4056,7 +4157,8 @@ static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
 {
        DEBUG(4,("enum_all_printers_info_4\n"));
 
-       return enum_all_printers_info_level(mem_ctx, server_info, 4, flags, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
+                                           4, flags, info, count);
 }
 
 
@@ -4066,6 +4168,7 @@ static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
 
 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
                                  struct auth_serversupplied_info *server_info,
+                                 struct messaging_context *msg_ctx,
                                  uint32_t flags,
                                  const char *servername,
                                  union spoolss_PrinterInfo **info,
@@ -4073,7 +4176,8 @@ static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
 {
        DEBUG(4,("enum_all_printers_info_5\n"));
 
-       return enum_all_printers_info_level(mem_ctx, server_info, 5, flags, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
+                                           5, flags, info, count);
 }
 
 /****************************************************************
@@ -4119,27 +4223,27 @@ WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
        switch (r->in.level) {
        case 0:
                result = enumprinters_level0(p->mem_ctx, p->server_info,
-                                            r->in.flags, name,
+                                            p->msg_ctx, r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        case 1:
                result = enumprinters_level1(p->mem_ctx, p->server_info,
-                                            r->in.flags, name,
+                                            p->msg_ctx, r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        case 2:
                result = enumprinters_level2(p->mem_ctx, p->server_info,
-                                            r->in.flags, name,
+                                            p->msg_ctx, r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        case 4:
                result = enumprinters_level4(p->mem_ctx, p->server_info,
-                                            r->in.flags, name,
+                                            p->msg_ctx, r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        case 5:
                result = enumprinters_level5(p->mem_ctx, p->server_info,
-                                            r->in.flags, name,
+                                            p->msg_ctx, r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        default:
@@ -4191,6 +4295,7 @@ WERROR _spoolss_GetPrinter(struct pipes_struct *p,
 
        result = winreg_get_printer(p->mem_ctx,
                                    p->server_info,
+                                   p->msg_ctx,
                                    servername,
                                    lp_const_servicename(snum),
                                    &info2);
@@ -4201,7 +4306,7 @@ WERROR _spoolss_GetPrinter(struct pipes_struct *p,
        switch (r->in.level) {
        case 0:
                result = construct_printer_info0(p->mem_ctx, p->server_info,
-                                                info2,
+                                                p->msg_ctx, info2,
                                                 &r->out.info->info0, snum);
                break;
        case 1:
@@ -4210,7 +4315,7 @@ WERROR _spoolss_GetPrinter(struct pipes_struct *p,
                                                 &r->out.info->info1, snum);
                break;
        case 2:
-               result = construct_printer_info2(p->mem_ctx, info2,
+               result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
                                                 &r->out.info->info2, snum);
                break;
        case 3:
@@ -4230,7 +4335,8 @@ WERROR _spoolss_GetPrinter(struct pipes_struct *p,
                                                 &r->out.info->info6, snum);
                break;
        case 7:
-               result = construct_printer_info7(p->mem_ctx, Printer,
+               result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
+                                                Printer,
                                                 &r->out.info->info7, snum);
                break;
        case 8:
@@ -4938,6 +5044,7 @@ static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
 
 static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
                                                  struct auth_serversupplied_info *server_info,
+                                                 struct messaging_context *msg_ctx,
                                                  uint32_t level,
                                                  union spoolss_DriverInfo *r,
                                                  int snum,
@@ -4951,6 +5058,7 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
 
        result = winreg_get_printer(mem_ctx,
                                    server_info,
+                                   msg_ctx,
                                    servername,
                                    lp_const_servicename(snum),
                                    &pinfo2);
@@ -4962,7 +5070,8 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
                return WERR_INVALID_PRINTER_NAME;
        }
 
-       result = winreg_get_driver(mem_ctx, server_info, architecture,
+       result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
+                                  architecture,
                                   pinfo2->drivername, version, &driver);
 
        DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
@@ -4980,7 +5089,8 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
 
                /* Yes - try again with a WinNT driver. */
                version = 2;
-               result = winreg_get_driver(mem_ctx, server_info, architecture,
+               result = winreg_get_driver(mem_ctx, server_info, msg_ctx,
+                                          architecture,
                                           pinfo2->drivername,
                                           version, &driver);
                DEBUG(8,("construct_printer_driver_level: status: %s\n",
@@ -5062,7 +5172,9 @@ WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = construct_printer_driver_info_level(p->mem_ctx, p->server_info,
+       result = construct_printer_driver_info_level(p->mem_ctx,
+                                                    p->server_info,
+                                                    p->msg_ctx,
                                                     r->in.level, r->out.info,
                                                     snum, printer->servername,
                                                     r->in.architecture,
@@ -5120,7 +5232,7 @@ WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
                return WERR_BADFID;
 
        Printer->page_started = false;
-       print_job_endpage(snum, Printer->jobid);
+       print_job_endpage(p->msg_ctx, snum, Printer->jobid);
 
        return WERR_OK;
 }
@@ -5177,7 +5289,7 @@ WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
                return WERR_BADFID;
        }
 
-       werr = print_job_start(p->server_info, snum,
+       werr = print_job_start(p->server_info, p->msg_ctx, snum,
                                info_1->document_name, info_1->output_file,
                                Printer->devmode, &Printer->jobid);
 
@@ -5216,7 +5328,7 @@ WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
        }
 
        Printer->document_started = false;
-       status = print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
+       status = print_job_end(p->msg_ctx, snum, Printer->jobid, NORMAL_CLOSE);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(2, ("_spoolss_EndDocPrinter: "
                          "print_job_end failed [%s]\n",
@@ -5249,7 +5361,8 @@ WERROR _spoolss_WritePrinter(struct pipes_struct *p,
                return WERR_BADFID;
 
        /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
-       buffer_written = print_job_write(snum, Printer->jobid,
+       buffer_written = print_job_write(server_event_context(),p->msg_ctx,
+                                                  snum, Printer->jobid,
                                                   (const char *)r->in.data.data,
                                                   (SMB_OFF_T)-1,
                                                   (size_t)r->in._data_size);
@@ -5290,14 +5403,14 @@ static WERROR control_printer(struct policy_handle *handle, uint32_t command,
 
        switch (command) {
        case SPOOLSS_PRINTER_CONTROL_PAUSE:
-               errcode = print_queue_pause(p->server_info, snum);
+               errcode = print_queue_pause(p->server_info, p->msg_ctx, snum);
                break;
        case SPOOLSS_PRINTER_CONTROL_RESUME:
        case SPOOLSS_PRINTER_CONTROL_UNPAUSE:
-               errcode = print_queue_resume(p->server_info, snum);
+               errcode = print_queue_resume(p->server_info, p->msg_ctx, snum);
                break;
        case SPOOLSS_PRINTER_CONTROL_PURGE:
-               errcode = print_queue_purge(p->server_info, snum);
+               errcode = print_queue_purge(p->server_info, p->msg_ctx, snum);
                break;
        default:
                return WERR_UNKNOWN_LEVEL;
@@ -5333,7 +5446,8 @@ WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
                return WERR_SPL_NO_STARTDOC;
        }
 
-       errcode = print_job_delete(p->server_info, snum, Printer->jobid);
+       errcode = print_job_delete(p->server_info, p->msg_ctx, snum,
+                                  Printer->jobid);
 
        return errcode;
 }
@@ -5385,6 +5499,7 @@ static WERROR update_printer_sec(struct policy_handle *handle,
           nothing may have actually changed. */
        result = winreg_get_printer_secdesc(p->mem_ctx,
                                            p->server_info,
+                                           p->msg_ctx,
                                            printer,
                                            &old_secdesc);
        if (!W_ERROR_IS_OK(result)) {
@@ -5436,6 +5551,7 @@ static WERROR update_printer_sec(struct policy_handle *handle,
 
        result = winreg_set_printer_secdesc(p->mem_ctx,
                                            p->server_info,
+                                           p->msg_ctx,
                                            printer,
                                            new_secdesc);
 
@@ -5607,7 +5723,7 @@ static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
 
        /* reload our services immediately */
        become_root();
-       reload_services(false);
+       reload_services(msg_ctx, false);
        unbecome_root();
 
        numlines = 0;
@@ -5631,6 +5747,7 @@ static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
 
 static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                               struct auth_serversupplied_info *server_info,
+                              struct messaging_context *msg_ctx,
                               int snum,
                               struct spoolss_SetPrinterInfo2 *printer,
                               struct spoolss_PrinterInfo2 *old_printer)
@@ -5647,6 +5764,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->drivername);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_DRIVERNAME,
@@ -5658,7 +5776,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                        DEBUG(10,("update_printer: changing driver [%s]!  Sending event!\n",
                                printer->drivername));
 
-                       notify_printer_driver(snum, printer->drivername);
+                       notify_printer_driver(server_event_context(), msg_ctx,
+                                             snum, printer->drivername);
                }
        }
 
@@ -5666,6 +5785,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->comment);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_DESCRIPTION,
@@ -5674,7 +5794,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                          buffer.length);
 
                if (!force_update) {
-                       notify_printer_comment(snum, printer->comment);
+                       notify_printer_comment(server_event_context(), msg_ctx,
+                                              snum, printer->comment);
                }
        }
 
@@ -5682,6 +5803,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->sharename);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSHARENAME,
@@ -5690,7 +5812,9 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                          buffer.length);
 
                if (!force_update) {
-                       notify_printer_sharename(snum, printer->sharename);
+                       notify_printer_sharename(server_event_context(),
+                                                msg_ctx,
+                                                snum, printer->sharename);
                }
        }
 
@@ -5707,6 +5831,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, p);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTERNAME,
@@ -5715,7 +5840,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                          buffer.length);
 
                if (!force_update) {
-                       notify_printer_printername(snum, p);
+                       notify_printer_printername(server_event_context(),
+                                                  msg_ctx, snum, p);
                }
        }
 
@@ -5723,6 +5849,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->portname);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PORTNAME,
@@ -5731,7 +5858,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                          buffer.length);
 
                if (!force_update) {
-                       notify_printer_port(snum, printer->portname);
+                       notify_printer_port(server_event_context(),
+                                           msg_ctx, snum, printer->portname);
                }
        }
 
@@ -5739,6 +5867,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->location);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_LOCATION,
@@ -5747,7 +5876,9 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                          buffer.length);
 
                if (!force_update) {
-                       notify_printer_location(snum, printer->location);
+                       notify_printer_location(server_event_context(),
+                                               msg_ctx, snum,
+                                               printer->location);
                }
        }
 
@@ -5755,6 +5886,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->sepfile);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSEPARATORFILE,
@@ -5763,7 +5895,9 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                          buffer.length);
 
                if (!force_update) {
-                       notify_printer_location(snum, printer->location);
+                       notify_printer_location(server_event_context(),
+                                               msg_ctx, snum,
+                                               printer->location);
                }
        }
 
@@ -5772,6 +5906,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                SIVAL(buffer.data, 0, printer->starttime);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSTARTTIME,
@@ -5785,6 +5920,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                SIVAL(buffer.data, 0, printer->untiltime);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTENDTIME,
@@ -5798,6 +5934,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                SIVAL(buffer.data, 0, printer->priority);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRIORITY,
@@ -5812,6 +5949,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                       PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTKEEPPRINTEDJOBS,
@@ -5835,6 +5973,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, spooling);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSPOOLING,
@@ -5846,6 +5985,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
        push_reg_sz(mem_ctx, &buffer, global_myname());
        winreg_set_printer_dataex(mem_ctx,
                                  server_info,
+                                 msg_ctx,
                                  printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
                                  SPOOL_REG_SHORTSERVERNAME,
@@ -5867,6 +6007,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
        push_reg_sz(mem_ctx, &buffer, longname);
        winreg_set_printer_dataex(mem_ctx,
                                  server_info,
+                                 msg_ctx,
                                  printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
                                  SPOOL_REG_SERVERNAME,
@@ -5879,6 +6020,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
        push_reg_sz(mem_ctx, &buffer, uncname);
        winreg_set_printer_dataex(mem_ctx,
                                  server_info,
+                                 msg_ctx,
                                  printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
                                  SPOOL_REG_UNCNAME,
@@ -5932,6 +6074,7 @@ static WERROR update_printer(struct pipes_struct *p,
 
        result = winreg_get_printer(tmp_ctx,
                                    p->server_info,
+                                   p->msg_ctx,
                                    servername,
                                    lp_const_servicename(snum),
                                    &old_printer);
@@ -5976,6 +6119,7 @@ static WERROR update_printer(struct pipes_struct *p,
 
        update_dsspooler(tmp_ctx,
                         p->server_info,
+                        p->msg_ctx,
                         snum,
                         printer,
                         old_printer);
@@ -5987,6 +6131,7 @@ static WERROR update_printer(struct pipes_struct *p,
        }
        result = winreg_update_printer(tmp_ctx,
                                       p->server_info,
+                                      p->msg_ctx,
                                       printer->sharename,
                                       printer_mask,
                                       printer,
@@ -6025,14 +6170,15 @@ static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
        if (!get_printer_snum(p, handle, &snum, NULL))
                return WERR_BADFID;
 
-       result = winreg_get_printer(p->mem_ctx, p->server_info,
+       result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
                                    Printer->servername,
                                    lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                return WERR_BADFID;
        }
 
-       nt_printer_publish(pinfo2, p->server_info, pinfo2, info7->action);
+       nt_printer_publish(pinfo2, p->server_info, p->msg_ctx, pinfo2,
+                          info7->action);
 
        TALLOC_FREE(pinfo2);
        return WERR_OK;
@@ -6070,6 +6216,7 @@ static WERROR update_printer_devmode(struct pipes_struct *p,
 
        return winreg_update_printer(p->mem_ctx,
                                     p->server_info,
+                                    p->msg_ctx,
                                     lp_const_servicename(snum),
                                     info2_mask,
                                     NULL,
@@ -6147,7 +6294,8 @@ WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
                                !get_printer_snum(p, r->in.handle, &snum, NULL) )
                        return WERR_BADFID;
 
-               srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
+               srv_spoolss_replycloseprinter(
+                       snum, &Printer->notify.client_hnd, p->msg_ctx);
        }
 
        Printer->notify.flags=0;
@@ -6481,13 +6629,13 @@ WERROR _spoolss_EnumJobs(struct pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
-                                   lp_servicename(snum), &pinfo2);
+       result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
+                                   NULL, lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                return result;
        }
 
-       count = print_queue_status(snum, &queue, &prt_status);
+       count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
        DEBUGADD(4,("count:[%d], status:[%d], [%s]\n",
                count, prt_status.status, prt_status.message));
 
@@ -6560,7 +6708,9 @@ static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
                return WERR_OK;
        }
 
-       if (!print_job_set_name(printer_name, job_id, r->document_name)) {
+       if (!print_job_set_name(server_event_context(),
+                               server_messaging_context(),
+                               printer_name, job_id, r->document_name)) {
                return WERR_BADFID;
        }
 
@@ -6588,20 +6738,22 @@ WERROR _spoolss_SetJob(struct pipes_struct *p,
        switch (r->in.command) {
        case SPOOLSS_JOB_CONTROL_CANCEL:
        case SPOOLSS_JOB_CONTROL_DELETE:
-               errcode = print_job_delete(p->server_info,
+               errcode = print_job_delete(p->server_info, p->msg_ctx,
                                           snum, r->in.job_id);
                if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
                        errcode = WERR_OK;
                }
                break;
        case SPOOLSS_JOB_CONTROL_PAUSE:
-               if (print_job_pause(p->server_info, snum, r->in.job_id, &errcode)) {
+               if (print_job_pause(p->server_info, p->msg_ctx,
+                                   snum, r->in.job_id, &errcode)) {
                        errcode = WERR_OK;
                }
                break;
        case SPOOLSS_JOB_CONTROL_RESTART:
        case SPOOLSS_JOB_CONTROL_RESUME:
-               if (print_job_resume(p->server_info, snum, r->in.job_id, &errcode)) {
+               if (print_job_resume(p->server_info, p->msg_ctx,
+                                    snum, r->in.job_id, &errcode)) {
                        errcode = WERR_OK;
                }
                break;
@@ -6642,6 +6794,7 @@ WERROR _spoolss_SetJob(struct pipes_struct *p,
 
 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
                                                       struct auth_serversupplied_info *server_info,
+                                                      struct messaging_context *msg_ctx,
                                                       const char *servername,
                                                       const char *architecture,
                                                       uint32_t level,
@@ -6661,7 +6814,7 @@ static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
        *info_p = NULL;
 
        for (version=0; version<DRIVER_MAX_VERSION; version++) {
-               result = winreg_get_driver_list(mem_ctx, server_info,
+               result = winreg_get_driver_list(mem_ctx, server_info, msg_ctx,
                                                architecture, version,
                                                &num_drivers, &drivers);
                if (!W_ERROR_IS_OK(result)) {
@@ -6687,6 +6840,7 @@ static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
                        DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
 
                        result = winreg_get_driver(mem_ctx, server_info,
+                                                  msg_ctx,
                                                   architecture, drivers[i],
                                                   version, &driver);
                        if (!W_ERROR_IS_OK(result)) {
@@ -6758,6 +6912,7 @@ static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
 
 static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
                                       struct auth_serversupplied_info *server_info,
+                                      struct messaging_context *msg_ctx,
                                       const char *servername,
                                       const char *architecture,
                                       uint32_t level,
@@ -6776,6 +6931,7 @@ static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
 
                        result = enumprinterdrivers_level_by_architecture(mem_ctx,
                                                                          server_info,
+                                                                         msg_ctx,
                                                                          servername,
                                                                          archi_table[a].long_archi,
                                                                          level,
@@ -6796,6 +6952,7 @@ static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
 
        return enumprinterdrivers_level_by_architecture(mem_ctx,
                                                        server_info,
+                                                       msg_ctx,
                                                        servername,
                                                        architecture,
                                                        level,
@@ -6833,6 +6990,7 @@ WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
 
        result = enumprinterdrivers_level(p->mem_ctx,
                                          p->server_info,
+                                         p->msg_ctx,
                                          cservername,
                                          r->in.environment,
                                          r->in.level,
@@ -6879,6 +7037,7 @@ WERROR _spoolss_EnumForms(struct pipes_struct *p,
        case 1:
                result = winreg_printer_enumforms1(p->mem_ctx,
                                                   p->server_info,
+                                                  p->msg_ctx,
                                                   r->out.count,
                                                   r->out.info);
                break;
@@ -6928,6 +7087,7 @@ WERROR _spoolss_GetForm(struct pipes_struct *p,
        case 1:
                result = winreg_printer_getform1(p->mem_ctx,
                                                 p->server_info,
+                                                p->msg_ctx,
                                                 r->in.form_name,
                                                 &r->out.info->info1);
                break;
@@ -7274,7 +7434,8 @@ static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
        }
 
        /* you must be a printer admin to add a new printer */
-       if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
+       if (!print_access_check(p->server_info, p->msg_ctx, snum,
+                               PRINTER_ACCESS_ADMINISTER)) {
                return WERR_ACCESS_DENIED;
        }
 
@@ -7292,12 +7453,14 @@ static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
 
        update_dsspooler(p->mem_ctx,
                         p->server_info,
+                        p->msg_ctx,
                         0,
                         info2,
                         NULL);
 
        err = winreg_update_printer(p->mem_ctx,
                                    p->server_info,
+                                   p->msg_ctx,
                                    info2->sharename,
                                    info2_mask,
                                    info2,
@@ -7421,7 +7584,7 @@ WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
                goto done;
        }
 
-       err = winreg_add_driver(p->mem_ctx, p->server_info,
+       err = winreg_add_driver(p->mem_ctx, p->server_info, p->msg_ctx,
                                 r->in.info_ctr, &driver_name, &version);
        if (!W_ERROR_IS_OK(err)) {
                goto done;
@@ -7859,7 +8022,8 @@ WERROR _spoolss_AddForm(struct pipes_struct *p,
                return WERR_INVALID_PARAM;
        }
 
-       status = winreg_printer_addform1(p->mem_ctx, p->server_info, form);
+       status = winreg_printer_addform1(p->mem_ctx, p->server_info,
+                                        p->msg_ctx, form);
        if (!W_ERROR_IS_OK(status)) {
                return status;
        }
@@ -7874,6 +8038,7 @@ WERROR _spoolss_AddForm(struct pipes_struct *p,
 
                status = winreg_printer_update_changeid(p->mem_ctx,
                                                        p->server_info,
+                                                       p->msg_ctx,
                                                        lp_const_servicename(snum));
                if (!W_ERROR_IS_OK(status)) {
                        return status;
@@ -7917,6 +8082,7 @@ WERROR _spoolss_DeleteForm(struct pipes_struct *p,
 
        status = winreg_printer_deleteform1(p->mem_ctx,
                                            p->server_info,
+                                           p->msg_ctx,
                                            form_name);
        if (!W_ERROR_IS_OK(status)) {
                return status;
@@ -7932,6 +8098,7 @@ WERROR _spoolss_DeleteForm(struct pipes_struct *p,
 
                status = winreg_printer_update_changeid(p->mem_ctx,
                                                        p->server_info,
+                                                       p->msg_ctx,
                                                        lp_const_servicename(snum));
                if (!W_ERROR_IS_OK(status)) {
                        return status;
@@ -7980,6 +8147,7 @@ WERROR _spoolss_SetForm(struct pipes_struct *p,
 
        status = winreg_printer_setform1(p->mem_ctx,
                                         p->server_info,
+                                        p->msg_ctx,
                                         form_name,
                                         form);
        if (!W_ERROR_IS_OK(status)) {
@@ -7996,6 +8164,7 @@ WERROR _spoolss_SetForm(struct pipes_struct *p,
 
                status = winreg_printer_update_changeid(p->mem_ctx,
                                                        p->server_info,
+                                                       p->msg_ctx,
                                                        lp_const_servicename(snum));
                if (!W_ERROR_IS_OK(status)) {
                        return status;
@@ -8478,13 +8647,13 @@ WERROR _spoolss_GetJob(struct pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
-                                   lp_servicename(snum), &pinfo2);
+       result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
+                                   NULL, lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                return result;
        }
 
-       count = print_queue_status(snum, &queue, &prt_status);
+       count = print_queue_status(p->msg_ctx, snum, &queue, &prt_status);
 
        DEBUGADD(4,("count:[%d], prt_status:[%d], [%s]\n",
                     count, prt_status.status, prt_status.message));
@@ -8604,6 +8773,7 @@ WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
 
                        result = winreg_printer_get_changeid(p->mem_ctx,
                                                             p->server_info,
+                                                            p->msg_ctx,
                                                             printer,
                                                             &changeid);
                        if (!W_ERROR_IS_OK(result)) {
@@ -8618,6 +8788,7 @@ WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
 
        result = winreg_get_printer_dataex(p->mem_ctx,
                                           p->server_info,
+                                          p->msg_ctx,
                                           printer,
                                           r->in.key_name,
                                           r->in.value_name,
@@ -8690,7 +8861,7 @@ WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
                return WERR_ACCESS_DENIED;
        }
 
-       result = winreg_get_printer(Printer, p->server_info,
+       result = winreg_get_printer(Printer, p->server_info, p->msg_ctx,
                                    Printer->servername,
                                    lp_servicename(snum),
                                    &pinfo2);
@@ -8710,6 +8881,7 @@ WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
 
        result = winreg_set_printer_dataex(p->mem_ctx,
                                           p->server_info,
+                                          p->msg_ctx,
                                           pinfo2->sharename,
                                           r->in.key_name,
                                           r->in.value_name,
@@ -8735,6 +8907,7 @@ WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
                         */
                        winreg_set_printer_dataex(p->mem_ctx,
                                                  p->server_info,
+                                                 p->msg_ctx,
                                                  pinfo2->sharename,
                                                  str,
                                                  r->in.value_name,
@@ -8745,6 +8918,7 @@ WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
 
                result = winreg_printer_update_changeid(p->mem_ctx,
                                                        p->server_info,
+                                                       p->msg_ctx,
                                                        lp_const_servicename(snum));
 
        }
@@ -8792,12 +8966,14 @@ WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
 
        status = winreg_delete_printer_dataex(p->mem_ctx,
                                              p->server_info,
+                                             p->msg_ctx,
                                              printer,
                                              r->in.key_name,
                                              r->in.value_name);
        if (W_ERROR_IS_OK(status)) {
                status = winreg_printer_update_changeid(p->mem_ctx,
                                                        p->server_info,
+                                                       p->msg_ctx,
                                                        printer);
        }
 
@@ -8832,6 +9008,7 @@ WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
 
        result = winreg_enum_printer_key(p->mem_ctx,
                                         p->server_info,
+                                        p->msg_ctx,
                                         lp_const_servicename(snum),
                                         r->in.key_name,
                                         &num_keys,
@@ -8905,11 +9082,13 @@ WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
        /* delete the key and all subkeys */
        status = winreg_delete_printer_key(p->mem_ctx,
                                           p->server_info,
+                                          p->msg_ctx,
                                           printer,
                                           r->in.key_name);
        if (W_ERROR_IS_OK(status)) {
                status = winreg_printer_update_changeid(p->mem_ctx,
                                                        p->server_info,
+                                                       p->msg_ctx,
                                                        printer);
        }
 
@@ -8960,6 +9139,7 @@ WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
        /* now look for a match on the key name */
        result = winreg_enum_printer_dataex(p->mem_ctx,
                                            p->server_info,
+                                           p->msg_ctx,
                                            lp_const_servicename(snum),
                                            r->in.key_name,
                                            &count,