s3: Lift the smbd_messaging_context from construct_printer_info7
[amitay/samba.git] / source3 / rpc_server / srv_spoolss_nt.c
index 1c9b25cd7ee7f52918e93bf9c8e2e24491f3b387..7ec0162f1a936fd56163ee7528560937a1eeb12c 100644 (file)
@@ -381,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;
@@ -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;
        }
@@ -1368,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)) {
@@ -1647,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);
@@ -1764,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),
                                          "");
        }
@@ -1837,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)) {
@@ -1847,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);
@@ -1863,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)) {
@@ -1878,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);
 
@@ -1888,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);
@@ -1934,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;
 
@@ -1951,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);
@@ -1961,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;
        }
@@ -1984,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;
@@ -1994,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)) {
@@ -2002,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);
@@ -2013,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 */
 
@@ -2033,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;
        }
@@ -3450,6 +3462,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)
@@ -3512,7 +3525,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;
@@ -3723,6 +3740,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)
@@ -3738,7 +3756,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;
@@ -3785,6 +3804,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,
@@ -3815,7 +3835,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)) {
@@ -3830,8 +3850,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;
@@ -3839,7 +3858,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:
@@ -3891,6 +3911,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,
@@ -3898,7 +3919,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);
 }
 
 
@@ -3907,13 +3929,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);
 }
 
 /********************************************************************
@@ -3922,12 +3946,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);
 }
 
 /********************************************************************
@@ -3936,6 +3962,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)
@@ -3952,7 +3979,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);
 }
 
 /********************************************************************
@@ -3961,6 +3989,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)
@@ -3985,7 +4014,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);
 }
 
 /********************************************************************
@@ -3996,12 +4026,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);
 }
 
 /********************************************************************
@@ -4010,6 +4042,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,
@@ -4018,15 +4051,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 */
@@ -4038,13 +4076,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) {
@@ -4052,7 +4092,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) {
@@ -4068,6 +4109,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,
@@ -4075,7 +4117,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);
 }
 
 
@@ -4085,6 +4128,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,
@@ -4092,7 +4136,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);
 }
 
 /****************************************************************
@@ -4138,27 +4183,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:
@@ -4221,7 +4266,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:
@@ -4250,7 +4295,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:
@@ -4958,6 +5004,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,
@@ -4971,7 +5018,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);
@@ -4983,7 +5030,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",
@@ -5001,7 +5049,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",
@@ -5083,7 +5132,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,
@@ -5458,6 +5509,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);
 
@@ -5653,6 +5705,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)
@@ -5669,6 +5722,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,
@@ -5688,6 +5742,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,
@@ -5704,6 +5759,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,
@@ -5729,6 +5785,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,
@@ -5745,6 +5802,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,
@@ -5761,6 +5819,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,
@@ -5777,6 +5836,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,
@@ -5794,6 +5854,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,
@@ -5807,6 +5868,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,
@@ -5820,6 +5882,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,
@@ -5834,6 +5897,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,
@@ -5857,6 +5921,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,
@@ -5868,6 +5933,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,
@@ -5889,6 +5955,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,
@@ -5901,6 +5968,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,
@@ -5999,6 +6067,7 @@ static WERROR update_printer(struct pipes_struct *p,
 
        update_dsspooler(tmp_ctx,
                         p->server_info,
+                        p->msg_ctx,
                         snum,
                         printer,
                         old_printer);
@@ -6056,7 +6125,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;
@@ -6668,6 +6738,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,
@@ -6687,7 +6758,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)) {
@@ -6713,6 +6784,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)) {
@@ -6784,6 +6856,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,
@@ -6802,6 +6875,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,
@@ -6822,6 +6896,7 @@ static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
 
        return enumprinterdrivers_level_by_architecture(mem_ctx,
                                                        server_info,
+                                                       msg_ctx,
                                                        servername,
                                                        architecture,
                                                        level,
@@ -6859,6 +6934,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,
@@ -6905,6 +6981,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;
@@ -6954,6 +7031,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;
@@ -7300,7 +7378,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;
        }
 
@@ -7318,6 +7397,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);
@@ -7448,7 +7528,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;
@@ -7886,7 +7966,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;
        }
@@ -7901,6 +7982,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;
@@ -7944,6 +8026,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;
@@ -7959,6 +8042,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;
@@ -8007,6 +8091,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)) {
@@ -8023,6 +8108,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;
@@ -8631,6 +8717,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)) {
@@ -8645,6 +8732,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,
@@ -8737,6 +8825,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,
@@ -8762,6 +8851,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,
@@ -8772,6 +8862,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));
 
        }
@@ -8819,12 +8910,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);
        }
 
@@ -8859,6 +8952,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,
@@ -8932,11 +9026,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);
        }
 
@@ -8987,6 +9083,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,