s3: Lift the server_messaging_context from construct_notify_jobs_info
[amitay/samba.git] / source3 / rpc_server / srv_spoolss_nt.c
index 2a95ba94c69ab52e489039b0bfc3c5d38bf43670..94c3249f77aa13e7620fc3a01812ea625961bba5 100644 (file)
@@ -341,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 )
@@ -455,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)
 {
@@ -539,7 +540,7 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
 
                result = winreg_get_printer(mem_ctx,
                                            server_info,
-                                           smbd_messaging_context(),
+                                           msg_ctx,
                                            servername,
                                            sname,
                                            &info2);
@@ -610,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;
        }
@@ -1388,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;
@@ -1401,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;
@@ -1648,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);
@@ -1839,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)) {
@@ -1849,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);
@@ -1865,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)) {
@@ -1880,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);
 
@@ -1890,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);
@@ -1936,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;
 
@@ -1953,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);
@@ -1963,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;
        }
@@ -1986,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;
@@ -1996,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)) {
@@ -2004,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);
@@ -2015,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 */
 
@@ -2035,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;
        }
@@ -2462,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,
@@ -2475,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,
@@ -2497,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,
@@ -2510,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,
@@ -2524,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,
@@ -2537,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,
@@ -2559,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,
@@ -2573,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,
@@ -2587,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,
@@ -2601,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,
@@ -2615,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,
@@ -2629,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,
@@ -2644,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,
@@ -2658,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,
@@ -2671,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,
@@ -2684,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,
@@ -2697,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,
@@ -2710,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,
@@ -2723,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,
@@ -2731,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);
 }
 
@@ -2739,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,
@@ -2767,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,
@@ -2780,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,
@@ -2793,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,
@@ -2806,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,
@@ -2844,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,
@@ -2857,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,
@@ -2869,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,
@@ -2881,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,
@@ -2895,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,
@@ -2908,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,
@@ -2929,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);
@@ -3053,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,
@@ -3099,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++;
        }
@@ -3114,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,
@@ -3152,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++;
        }
 
@@ -3248,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);
@@ -3332,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)) {
@@ -3342,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,
@@ -3452,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)
@@ -3467,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) {
@@ -3516,8 +3566,7 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
        r->high_part_total_bytes        = 0x0;
 
        /* ChangeID in milliseconds*/
-       winreg_printer_get_changeid(mem_ctx, server_info,
-                                   smbd_messaging_context(),
+       winreg_printer_get_changeid(mem_ctx, server_info, msg_ctx,
                                    info2->sharename, &r->change_id);
 
        r->last_error                   = WERR_OK;
@@ -3579,7 +3628,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(server_messaging_context(), snum, &status);
 
        r->servername           = talloc_strdup(mem_ctx, info2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->servername);
@@ -3717,7 +3766,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);
 
@@ -3730,6 +3779,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)
@@ -3745,7 +3795,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;
@@ -3792,6 +3843,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,
@@ -3822,7 +3874,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
 
                result = winreg_create_printer(mem_ctx,
                                               server_info,
-                                              smbd_messaging_context(),
+                                              msg_ctx,
                                               NULL,
                                               printer);
                if (!W_ERROR_IS_OK(result)) {
@@ -3837,8 +3889,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                        goto out;
                }
 
-               result = winreg_get_printer(mem_ctx, server_info,
-                                           smbd_messaging_context(),
+               result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
                                            NULL, printer, &info2);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
@@ -3846,7 +3897,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:
@@ -3898,6 +3950,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,
@@ -3905,7 +3958,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);
 }
 
 
@@ -3914,13 +3968,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);
 }
 
 /********************************************************************
@@ -3929,12 +3985,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);
 }
 
 /********************************************************************
@@ -3943,6 +4001,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)
@@ -3959,7 +4018,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);
 }
 
 /********************************************************************
@@ -3968,6 +4028,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)
@@ -3992,7 +4053,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);
 }
 
 /********************************************************************
@@ -4003,12 +4065,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);
 }
 
 /********************************************************************
@@ -4017,6 +4081,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,
@@ -4025,15 +4090,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 */
@@ -4045,13 +4115,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) {
@@ -4059,7 +4131,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) {
@@ -4075,6 +4148,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,
@@ -4082,7 +4156,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);
 }
 
 
@@ -4092,6 +4167,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,
@@ -4099,7 +4175,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);
 }
 
 /****************************************************************
@@ -4145,27 +4222,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:
@@ -4228,7 +4305,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:
@@ -4257,7 +4334,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:
@@ -4965,6 +5043,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,
@@ -4978,7 +5057,7 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
 
        result = winreg_get_printer(mem_ctx,
                                    server_info,
-                                   smbd_messaging_context(),
+                                   msg_ctx,
                                    servername,
                                    lp_const_servicename(snum),
                                    &pinfo2);
@@ -4990,7 +5069,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",
@@ -5008,7 +5088,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",
@@ -5090,7 +5171,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,
@@ -5148,7 +5231,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;
 }
@@ -5205,7 +5288,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);
 
@@ -5244,7 +5327,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",
@@ -5277,7 +5360,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);
@@ -5318,14 +5402,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;
@@ -5361,7 +5445,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;
 }
@@ -5637,7 +5722,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;
@@ -5661,6 +5746,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)
@@ -5677,7 +5763,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,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_DRIVERNAME,
@@ -5689,7 +5775,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);
                }
        }
 
@@ -5697,7 +5784,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,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_DESCRIPTION,
@@ -5706,7 +5793,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);
                }
        }
 
@@ -5714,7 +5802,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,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSHARENAME,
@@ -5723,7 +5811,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);
                }
        }
 
@@ -5740,7 +5830,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, p);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTERNAME,
@@ -5749,7 +5839,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);
                }
        }
 
@@ -5757,7 +5848,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,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PORTNAME,
@@ -5766,7 +5857,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);
                }
        }
 
@@ -5774,7 +5866,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,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_LOCATION,
@@ -5783,7 +5875,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);
                }
        }
 
@@ -5791,7 +5885,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,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSEPARATORFILE,
@@ -5800,7 +5894,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);
                }
        }
 
@@ -5809,7 +5905,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                SIVAL(buffer.data, 0, printer->starttime);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSTARTTIME,
@@ -5823,7 +5919,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                SIVAL(buffer.data, 0, printer->untiltime);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTENDTIME,
@@ -5837,7 +5933,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                SIVAL(buffer.data, 0, printer->priority);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRIORITY,
@@ -5852,7 +5948,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                       PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTKEEPPRINTEDJOBS,
@@ -5876,7 +5972,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, spooling);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
-                                         smbd_messaging_context(),
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSPOOLING,
@@ -5888,7 +5984,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,
-                                 smbd_messaging_context(),
+                                 msg_ctx,
                                  printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
                                  SPOOL_REG_SHORTSERVERNAME,
@@ -5910,7 +6006,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
        push_reg_sz(mem_ctx, &buffer, longname);
        winreg_set_printer_dataex(mem_ctx,
                                  server_info,
-                                 smbd_messaging_context(),
+                                 msg_ctx,
                                  printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
                                  SPOOL_REG_SERVERNAME,
@@ -5923,7 +6019,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
        push_reg_sz(mem_ctx, &buffer, uncname);
        winreg_set_printer_dataex(mem_ctx,
                                  server_info,
-                                 smbd_messaging_context(),
+                                 msg_ctx,
                                  printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
                                  SPOOL_REG_UNCNAME,
@@ -6022,6 +6118,7 @@ static WERROR update_printer(struct pipes_struct *p,
 
        update_dsspooler(tmp_ctx,
                         p->server_info,
+                        p->msg_ctx,
                         snum,
                         printer,
                         old_printer);
@@ -6079,7 +6176,8 @@ static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
                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;
@@ -6536,7 +6634,7 @@ WERROR _spoolss_EnumJobs(struct pipes_struct *p,
                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));
 
@@ -6609,7 +6707,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;
        }
 
@@ -6637,20 +6737,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;
@@ -6691,6 +6793,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,
@@ -6710,7 +6813,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)) {
@@ -6736,6 +6839,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)) {
@@ -6807,6 +6911,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,
@@ -6825,6 +6930,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,
@@ -6845,6 +6951,7 @@ static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
 
        return enumprinterdrivers_level_by_architecture(mem_ctx,
                                                        server_info,
+                                                       msg_ctx,
                                                        servername,
                                                        architecture,
                                                        level,
@@ -6882,6 +6989,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,
@@ -6978,6 +7086,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;
@@ -7324,7 +7433,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;
        }
 
@@ -7342,6 +7452,7 @@ static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
 
        update_dsspooler(p->mem_ctx,
                         p->server_info,
+                        p->msg_ctx,
                         0,
                         info2,
                         NULL);
@@ -7472,7 +7583,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;
@@ -8541,7 +8652,7 @@ WERROR _spoolss_GetJob(struct pipes_struct *p,
                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));