s3: Lift the smbd_messaging_context from nt_printer_publish
[amitay/samba.git] / source3 / rpc_server / srv_spoolss_nt.c
index f93b41aa7f338cc94f43e6189fb0cf03f8dfddb4..b8a8526eec24b317495dd25ad7d2cd8dd5ac798b 100644 (file)
@@ -38,6 +38,8 @@
 #include "registry.h"
 #include "registry/reg_objects.h"
 #include "include/printing.h"
+#include "secrets.h"
+#include "../librpc/gen_ndr/netlogon.h"
 
 /* macros stolen from s4 spoolss server */
 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
 
 #define SPOOLSS_BUFFER_OK(val_true,val_false) ((r->in.offered >= *r->out.needed)?val_true:val_false)
 
-
-extern userdom_struct current_user_info;
-
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
 
-#ifndef MAX_OPEN_PRINTER_EXS
-#define MAX_OPEN_PRINTER_EXS 50
-#endif
-
 static Printer_entry *printers_list;
 
 typedef struct _counter_printer_0 {
@@ -77,9 +72,23 @@ static struct rpc_pipe_client *notify_cli_pipe; /* print notify back-channel pip
 static uint32_t smb_connections = 0;
 
 
-/* in printing/nt_printing.c */
+/* Map generic permissions to printer object specific permissions */
 
-extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
+const struct standard_mapping printer_std_mapping = {
+       PRINTER_READ,
+       PRINTER_WRITE,
+       PRINTER_EXECUTE,
+       PRINTER_ALL_ACCESS
+};
+
+/* Map generic permissions to print server object specific permissions */
+
+const struct standard_mapping printserver_std_mapping = {
+       SERVER_READ,
+       SERVER_WRITE,
+       SERVER_EXECUTE,
+       SERVER_ALL_ACCESS
+};
 
 /* API table for Xcv Monitor functions */
 
@@ -150,7 +159,9 @@ static int nt_printq_status(int v)
  Disconnect from the client
 ****************************************************************************/
 
-static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle)
+static void srv_spoolss_replycloseprinter(
+       int snum, struct policy_handle *handle,
+       struct messaging_context *msg_ctx)
 {
        WERROR result;
        NTSTATUS status;
@@ -163,7 +174,7 @@ static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle
        if (!print_notify_deregister_pid(snum))
                DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
 
-       /* weird if the test succeds !!! */
+       /* weird if the test succeeds !!! */
        if (smb_connections==0) {
                DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
                return;
@@ -180,17 +191,24 @@ static void srv_spoolss_replycloseprinter(int snum, struct policy_handle *handle
        if (smb_connections==1) {
 
                cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
-               notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
+               /*
+                * The above call shuts down the pipe also.
+                */
+               notify_cli_pipe = NULL;
 
-               messaging_deregister(smbd_messaging_context(),
-                                    MSG_PRINTER_NOTIFY2, NULL);
+               if (msg_ctx != NULL) {
+                       messaging_deregister(msg_ctx, MSG_PRINTER_NOTIFY2,
+                                            NULL);
 
-               /* Tell the connections db we're no longer interested in
-                * printer notify messages. */
+                       /*
+                        * Tell the serverid.tdb we're no longer
+                        * interested in printer notify messages.
+                        */
 
-               serverid_register_msg_flags(
-                       messaging_server_id(smbd_messaging_context()),
-                       false, FLAG_MSG_PRINT_NOTIFY);
+                       serverid_register_msg_flags(
+                               messaging_server_id(msg_ctx),
+                               false, FLAG_MSG_PRINT_NOTIFY);
+               }
        }
 
        smb_connections--;
@@ -207,12 +225,15 @@ static int printer_entry_destructor(Printer_entry *Printer)
 
                if ( Printer->printer_type == SPLHND_SERVER) {
                        snum = -1;
-                       srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
+                       srv_spoolss_replycloseprinter(
+                               snum, &Printer->notify.client_hnd,
+                               Printer->notify.msg_ctx);
                } else if (Printer->printer_type == SPLHND_PRINTER) {
                        snum = print_queue_snum(Printer->sharename);
                        if (snum != -1)
-                               srv_spoolss_replycloseprinter(snum,
-                                               &Printer->notify.client_hnd);
+                               srv_spoolss_replycloseprinter(
+                                       snum, &Printer->notify.client_hnd,
+                                       Printer->notify.msg_ctx);
                }
        }
 
@@ -234,7 +255,7 @@ static int printer_entry_destructor(Printer_entry *Printer)
   find printer index by handle
 ****************************************************************************/
 
-static Printer_entry *find_printer_index_by_hnd(pipes_struct *p,
+static Printer_entry *find_printer_index_by_hnd(struct pipes_struct *p,
                                                struct policy_handle *hnd)
 {
        Printer_entry *find_printer = NULL;
@@ -251,7 +272,7 @@ static Printer_entry *find_printer_index_by_hnd(pipes_struct *p,
  Close printer index by handle.
 ****************************************************************************/
 
-static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
+static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
 
@@ -270,7 +291,9 @@ static bool close_printer_handle(pipes_struct *p, struct policy_handle *hnd)
  Delete a printer given a handle.
 ****************************************************************************/
 
-static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename)
+static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
+                                 const char *sharename,
+                                 struct messaging_context *msg_ctx)
 {
        char *cmd = lp_deleteprinter_cmd();
        char *command = NULL;
@@ -301,8 +324,7 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const c
 
        if ( (ret = smbrun(command, NULL)) == 0 ) {
                /* Tell everyone we updated smb.conf. */
-               message_send_all(smbd_messaging_context(),
-                                MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
+               message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
        }
 
        if ( is_print_op )
@@ -332,7 +354,7 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const c
  Delete a printer given a handle.
 ****************************************************************************/
 
-static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
+static WERROR delete_printer_handle(struct pipes_struct *p, struct policy_handle *hnd)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
        WERROR result;
@@ -359,21 +381,21 @@ static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
           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;
        }
 
        return delete_printer_hook(p->mem_ctx, p->server_info->ptok,
-                                  Printer->sharename );
+                                  Printer->sharename, p->msg_ctx);
 }
 
 /****************************************************************************
  Return the snum of a printer corresponding to an handle.
 ****************************************************************************/
 
-static bool get_printer_snum(pipes_struct *p, struct policy_handle *hnd,
+static bool get_printer_snum(struct pipes_struct *p, struct policy_handle *hnd,
                             int *number, struct share_params **params)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
@@ -433,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)
 {
@@ -440,7 +463,7 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
        int n_services=lp_numservices();
        char *aprinter;
        const char *printername;
-       const char *servername;
+       const char *servername = NULL;
        fstring sname;
        bool found = false;
        struct spoolss_PrinterInfo2 *info2 = NULL;
@@ -517,11 +540,12 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
 
                result = winreg_get_printer(mem_ctx,
                                            server_info,
+                                           msg_ctx,
                                            servername,
                                            sname,
                                            &info2);
                if ( !W_ERROR_IS_OK(result) ) {
-                       DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
+                       DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
                                 sname, win_errstr(result)));
                        continue;
                }
@@ -559,7 +583,7 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
  Find first available printer slot. creates a printer handle for you.
  ****************************************************************************/
 
-static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
+static bool open_printer_hnd(struct pipes_struct *p, struct policy_handle *hnd,
                             const char *name, uint32_t access_granted)
 {
        Printer_entry *new_printer;
@@ -587,7 +611,8 @@ static bool open_printer_hnd(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;
        }
@@ -1257,7 +1282,8 @@ static void receive_notify2_message_list(struct messaging_context *msg,
  driver
  ********************************************************************/
 
-static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
+static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
+                                           struct messaging_context *msg_ctx)
 {
        int len = strlen(drivername);
 
@@ -1267,8 +1293,7 @@ static bool srv_spoolss_drv_upgrade_printer(const char *drivername)
        DEBUG(10,("srv_spoolss_drv_upgrade_printer: Sending message about driver upgrade [%s]\n",
                drivername));
 
-       messaging_send_buf(smbd_messaging_context(),
-                          messaging_server_id(smbd_messaging_context()),
+       messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx),
                           MSG_PRINTER_DRVUPGRADE,
                           (uint8_t *)drivername, len+1);
 
@@ -1323,7 +1348,8 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
                        continue;
                }
 
-               result = winreg_get_printer(tmp_ctx, server_info, NULL,
+               result = winreg_get_printer(tmp_ctx, server_info, msg,
+                                           NULL,
                                            lp_const_servicename(snum),
                                            &pinfo2);
 
@@ -1331,6 +1357,10 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
                        continue;
                }
 
+               if (!pinfo2->drivername) {
+                       continue;
+               }
+
                if (strcmp(drivername, pinfo2->drivername) != 0) {
                        continue;
                }
@@ -1340,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)) {
@@ -1385,7 +1416,7 @@ void update_monitored_printq_cache( void )
  _spoolss_OpenPrinter
 ****************************************************************/
 
-WERROR _spoolss_OpenPrinter(pipes_struct *p,
+WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
                            struct spoolss_OpenPrinter *r)
 {
        struct spoolss_OpenPrinterEx e;
@@ -1453,7 +1484,7 @@ static WERROR copy_devicemode(TALLOC_CTX *mem_ctx,
  _spoolss_OpenPrinterEx
 ****************************************************************/
 
-WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
+WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
                              struct spoolss_OpenPrinterEx *r)
 {
        int snum;
@@ -1619,7 +1650,7 @@ WERROR _spoolss_OpenPrinterEx(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);
@@ -1644,6 +1675,7 @@ WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
 
                winreg_create_printer(p->mem_ctx,
                                      p->server_info,
+                                     p->msg_ctx,
                                      Printer->servername,
                                      lp_const_servicename(snum));
 
@@ -1687,7 +1719,7 @@ WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
  _spoolss_ClosePrinter
 ****************************************************************/
 
-WERROR _spoolss_ClosePrinter(pipes_struct *p,
+WERROR _spoolss_ClosePrinter(struct pipes_struct *p,
                             struct spoolss_ClosePrinter *r)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -1717,7 +1749,7 @@ WERROR _spoolss_ClosePrinter(pipes_struct *p,
  _spoolss_DeletePrinter
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinter(pipes_struct *p,
+WERROR _spoolss_DeletePrinter(struct pipes_struct *p,
                              struct spoolss_DeletePrinter *r)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -1735,6 +1767,7 @@ WERROR _spoolss_DeletePrinter(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),
                                          "");
        }
@@ -1778,7 +1811,7 @@ static int get_version_id(const char *arch)
  _spoolss_DeletePrinterDriver
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
+WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
                                    struct spoolss_DeletePrinterDriver *r)
 {
 
@@ -1808,7 +1841,7 @@ WERROR _spoolss_DeletePrinterDriver(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)) {
@@ -1818,6 +1851,7 @@ WERROR _spoolss_DeletePrinterDriver(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);
@@ -1834,13 +1868,15 @@ WERROR _spoolss_DeletePrinterDriver(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)) {
@@ -1849,6 +1885,7 @@ WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
 
                        status = winreg_del_driver(p->mem_ctx,
                                                   p->server_info,
+                                                  p->msg_ctx,
                                                   info_win2k, 3);
                        talloc_free(info_win2k);
 
@@ -1859,7 +1896,8 @@ WERROR _spoolss_DeletePrinterDriver(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);
@@ -1871,7 +1909,7 @@ done:
  _spoolss_DeletePrinterDriverEx
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
+WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                                      struct spoolss_DeletePrinterDriverEx *r)
 {
        struct spoolss_DriverInfo8      *info = NULL;
@@ -1905,8 +1943,8 @@ WERROR _spoolss_DeletePrinterDriverEx(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;
 
@@ -1922,7 +1960,7 @@ WERROR _spoolss_DeletePrinterDriverEx(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);
@@ -1932,7 +1970,7 @@ WERROR _spoolss_DeletePrinterDriverEx(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;
        }
@@ -1955,7 +1993,8 @@ WERROR _spoolss_DeletePrinterDriverEx(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;
@@ -1965,7 +2004,7 @@ WERROR _spoolss_DeletePrinterDriverEx(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)) {
@@ -1973,6 +2012,7 @@ WERROR _spoolss_DeletePrinterDriverEx(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);
@@ -1984,7 +2024,7 @@ WERROR _spoolss_DeletePrinterDriverEx(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 */
 
@@ -2004,7 +2044,8 @@ WERROR _spoolss_DeletePrinterDriverEx(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;
        }
@@ -2168,7 +2209,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
  _spoolss_GetPrinterData
 ****************************************************************/
 
-WERROR _spoolss_GetPrinterData(pipes_struct *p,
+WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
                               struct spoolss_GetPrinterData *r)
 {
        struct spoolss_GetPrinterDataEx r2;
@@ -2211,7 +2252,7 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
                        addr));
        }
 
-       if (ismyaddr((struct sockaddr *)&rm_addr)) {
+       if (ismyaddr((struct sockaddr *)(void *)&rm_addr)) {
                DEBUG(0,("spoolss_connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n",
                        addr));
                return false;
@@ -2260,7 +2301,8 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
 static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
                                        uint32_t localprinter, uint32_t type,
                                        struct policy_handle *handle,
-                                       struct sockaddr_storage *client_ss)
+                                       struct sockaddr_storage *client_ss,
+                                       struct messaging_context *msg_ctx)
 {
        WERROR result;
        NTSTATUS status;
@@ -2277,14 +2319,12 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
                if ( !spoolss_connect_to_client( &notify_cli_pipe, client_ss, unix_printer ))
                        return false;
 
-               messaging_register(smbd_messaging_context(), NULL,
-                                  MSG_PRINTER_NOTIFY2,
+               messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
                                   receive_notify2_message_list);
                /* Tell the connections db we're now interested in printer
                 * notify messages. */
-               serverid_register_msg_flags(
-                       messaging_server_id(smbd_messaging_context()),
-                       true, FLAG_MSG_PRINT_NOTIFY);
+               serverid_register_msg_flags(messaging_server_id(msg_ctx),
+                                           true, FLAG_MSG_PRINT_NOTIFY);
        }
 
        /*
@@ -2373,7 +2413,7 @@ static struct spoolss_NotifyOption *dup_spoolss_NotifyOption(TALLOC_CTX *mem_ctx
  * called from api_spoolss_rffpcnex
 ****************************************************************/
 
-WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
+WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
                                                     struct spoolss_RemoteFindFirstPrinterChangeNotifyEx *r)
 {
        int snum = -1;
@@ -2394,6 +2434,7 @@ WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
        Printer->notify.flags           = r->in.flags;
        Printer->notify.options         = r->in.options;
        Printer->notify.printerlocal    = r->in.printer_local;
+       Printer->notify.msg_ctx         = p->msg_ctx;
 
        TALLOC_FREE(Printer->notify.option);
        Printer->notify.option = dup_spoolss_NotifyOption(Printer, option);
@@ -2418,7 +2459,8 @@ WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
 
        if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
                                        Printer->notify.printerlocal, 1,
-                                       &Printer->notify.client_hnd, &client_ss))
+                                       &Printer->notify.client_hnd,
+                                       &client_ss, p->msg_ctx))
                return WERR_SERVER_UNAVAILABLE;
 
        Printer->notify.client_connected = true;
@@ -3158,7 +3200,7 @@ static bool construct_notify_jobs_info(print_queue_struct *queue,
  *
  ********************************************************************/
 
-static WERROR printserver_notify_info(pipes_struct *p,
+static WERROR printserver_notify_info(struct pipes_struct *p,
                                      struct policy_handle *hnd,
                                      struct spoolss_NotifyInfo *info,
                                      TALLOC_CTX *mem_ctx)
@@ -3202,8 +3244,9 @@ static WERROR printserver_notify_info(pipes_struct *p,
                                continue; /* skip */
                        }
 
-                       /* FIXME: should we use a SYSTEM server_info here? */
+                       /* Maybe we should use the SYSTEM server_info here... */
                        result = winreg_get_printer(mem_ctx, p->server_info,
+                                                   p->msg_ctx,
                                                    Printer->servername,
                                                    lp_servicename(snum),
                                                    &pinfo2);
@@ -3249,7 +3292,8 @@ static WERROR printserver_notify_info(pipes_struct *p,
  *
  ********************************************************************/
 
-static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
+static WERROR printer_notify_info(struct pipes_struct *p,
+                                 struct policy_handle *hnd,
                                  struct spoolss_NotifyInfo *info,
                                  TALLOC_CTX *mem_ctx)
 {
@@ -3285,8 +3329,8 @@ static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
 
        get_printer_snum(p, hnd, &snum, NULL);
 
-       /* FIXME: should we use a SYSTEM server_info here ? */
-       result = winreg_get_printer(mem_ctx, p->server_info,
+       /* Maybe we should use the SYSTEM server_info here... */
+       result = winreg_get_printer(mem_ctx, p->server_info, p->msg_ctx,
                                    Printer->servername,
                                    lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
@@ -3346,7 +3390,7 @@ static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
  _spoolss_RouterRefreshPrinterChangeNotify
 ****************************************************************/
 
-WERROR _spoolss_RouterRefreshPrinterChangeNotify(pipes_struct *p,
+WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
                                                 struct spoolss_RouterRefreshPrinterChangeNotify *r)
 {
        struct spoolss_NotifyInfo *info;
@@ -3418,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)
@@ -3480,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;
@@ -3753,6 +3802,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,
@@ -3783,6 +3833,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
 
                result = winreg_create_printer(mem_ctx,
                                               server_info,
+                                              msg_ctx,
                                               NULL,
                                               printer);
                if (!W_ERROR_IS_OK(result)) {
@@ -3797,7 +3848,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                        goto out;
                }
 
-               result = winreg_get_printer(mem_ctx, server_info,
+               result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
                                            NULL, printer, &info2);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
@@ -3805,7 +3856,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:
@@ -3857,6 +3909,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,
@@ -3864,7 +3917,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);
 }
 
 
@@ -3873,13 +3927,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);
 }
 
 /********************************************************************
@@ -3888,12 +3944,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);
 }
 
 /********************************************************************
@@ -3902,6 +3960,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)
@@ -3918,7 +3977,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);
 }
 
 /********************************************************************
@@ -3927,6 +3987,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)
@@ -3951,7 +4012,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);
 }
 
 /********************************************************************
@@ -3962,12 +4024,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);
 }
 
 /********************************************************************
@@ -3976,6 +4040,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,
@@ -3984,15 +4049,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 */
@@ -4004,13 +4074,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) {
@@ -4018,7 +4090,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) {
@@ -4034,6 +4107,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,
@@ -4041,7 +4115,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);
 }
 
 
@@ -4051,6 +4126,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,
@@ -4058,14 +4134,15 @@ 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);
 }
 
 /****************************************************************
  _spoolss_EnumPrinters
 ****************************************************************/
 
-WERROR _spoolss_EnumPrinters(pipes_struct *p,
+WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
                             struct spoolss_EnumPrinters *r)
 {
        const char *name = NULL;
@@ -4104,27 +4181,27 @@ WERROR _spoolss_EnumPrinters(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:
@@ -4149,7 +4226,7 @@ WERROR _spoolss_EnumPrinters(pipes_struct *p,
  _spoolss_GetPrinter
 ****************************************************************/
 
-WERROR _spoolss_GetPrinter(pipes_struct *p,
+WERROR _spoolss_GetPrinter(struct pipes_struct *p,
                           struct spoolss_GetPrinter *r)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -4176,6 +4253,7 @@ WERROR _spoolss_GetPrinter(pipes_struct *p,
 
        result = winreg_get_printer(p->mem_ctx,
                                    p->server_info,
+                                   p->msg_ctx,
                                    servername,
                                    lp_const_servicename(snum),
                                    &info2);
@@ -4186,7 +4264,7 @@ WERROR _spoolss_GetPrinter(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:
@@ -4248,10 +4326,10 @@ WERROR _spoolss_GetPrinter(pipes_struct *p,
        do { \
                if (in && strlen(in)) { \
                        out = talloc_strdup(mem_ctx, in); \
-                       W_ERROR_HAVE_NO_MEMORY(out); \
                } else { \
-                       out = NULL; \
+                       out = talloc_strdup(mem_ctx, ""); \
                } \
+               W_ERROR_HAVE_NO_MEMORY(out); \
        } while (0);
 
 #define FILL_DRIVER_UNC_STRING(mem_ctx, server, arch, ver, in, out) \
@@ -4923,6 +5001,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,
@@ -4936,6 +5015,7 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
 
        result = winreg_get_printer(mem_ctx,
                                    server_info,
+                                   msg_ctx,
                                    servername,
                                    lp_const_servicename(snum),
                                    &pinfo2);
@@ -4947,7 +5027,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",
@@ -4965,7 +5046,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",
@@ -5018,7 +5100,7 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
  _spoolss_GetPrinterDriver2
 ****************************************************************/
 
-WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
+WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
                                  struct spoolss_GetPrinterDriver2 *r)
 {
        Printer_entry *printer;
@@ -5047,7 +5129,9 @@ WERROR _spoolss_GetPrinterDriver2(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,
@@ -5069,7 +5153,7 @@ WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
  _spoolss_StartPagePrinter
 ****************************************************************/
 
-WERROR _spoolss_StartPagePrinter(pipes_struct *p,
+WERROR _spoolss_StartPagePrinter(struct pipes_struct *p,
                                 struct spoolss_StartPagePrinter *r)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -5088,7 +5172,7 @@ WERROR _spoolss_StartPagePrinter(pipes_struct *p,
  _spoolss_EndPagePrinter
 ****************************************************************/
 
-WERROR _spoolss_EndPagePrinter(pipes_struct *p,
+WERROR _spoolss_EndPagePrinter(struct pipes_struct *p,
                               struct spoolss_EndPagePrinter *r)
 {
        int snum;
@@ -5114,7 +5198,7 @@ WERROR _spoolss_EndPagePrinter(pipes_struct *p,
  _spoolss_StartDocPrinter
 ****************************************************************/
 
-WERROR _spoolss_StartDocPrinter(pipes_struct *p,
+WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
                                struct spoolss_StartDocPrinter *r)
 {
        struct spoolss_DocumentInfo1 *info_1;
@@ -5183,7 +5267,7 @@ WERROR _spoolss_StartDocPrinter(pipes_struct *p,
  _spoolss_EndDocPrinter
 ****************************************************************/
 
-WERROR _spoolss_EndDocPrinter(pipes_struct *p,
+WERROR _spoolss_EndDocPrinter(struct pipes_struct *p,
                              struct spoolss_EndDocPrinter *r)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -5216,7 +5300,7 @@ WERROR _spoolss_EndDocPrinter(pipes_struct *p,
  _spoolss_WritePrinter
 ****************************************************************/
 
-WERROR _spoolss_WritePrinter(pipes_struct *p,
+WERROR _spoolss_WritePrinter(struct pipes_struct *p,
                             struct spoolss_WritePrinter *r)
 {
        ssize_t buffer_written;
@@ -5258,7 +5342,7 @@ WERROR _spoolss_WritePrinter(pipes_struct *p,
  ********************************************************************/
 
 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
-                             pipes_struct *p)
+                             struct pipes_struct *p)
 {
        int snum;
        WERROR errcode = WERR_BADFUNC;
@@ -5298,7 +5382,7 @@ static WERROR control_printer(struct policy_handle *handle, uint32_t command,
  * for spooling"
 ****************************************************************/
 
-WERROR _spoolss_AbortPrinter(pipes_struct *p,
+WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
                             struct spoolss_AbortPrinter *r)
 {
        Printer_entry   *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -5329,7 +5413,8 @@ WERROR _spoolss_AbortPrinter(pipes_struct *p,
  ********************************************************************/
 
 static WERROR update_printer_sec(struct policy_handle *handle,
-                                pipes_struct *p, struct sec_desc_buf *secdesc_ctr)
+                                struct pipes_struct *p,
+                                struct sec_desc_buf *secdesc_ctr)
 {
        struct spoolss_security_descriptor *new_secdesc = NULL;
        struct spoolss_security_descriptor *old_secdesc = NULL;
@@ -5369,6 +5454,7 @@ static WERROR update_printer_sec(struct policy_handle *handle,
           nothing may have actually changed. */
        result = winreg_get_printer_secdesc(p->mem_ctx,
                                            p->server_info,
+                                           p->msg_ctx,
                                            printer,
                                            &old_secdesc);
        if (!W_ERROR_IS_OK(result)) {
@@ -5381,7 +5467,7 @@ static WERROR update_printer_sec(struct policy_handle *handle,
                struct security_acl *the_acl;
                int i;
 
-               the_acl = secdesc_ctr->sd->dacl;
+               the_acl = old_secdesc->dacl;
                DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
                           printer, the_acl->num_aces));
 
@@ -5420,6 +5506,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);
 
@@ -5532,8 +5619,10 @@ static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *p
 /****************************************************************************
 ****************************************************************************/
 
-bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
-                     struct spoolss_SetPrinterInfo2 *info2)
+static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
+                            struct spoolss_SetPrinterInfo2 *info2,
+                            const char *remote_machine,
+                            struct messaging_context *msg_ctx)
 {
        char *cmd = lp_addprinter_cmd();
        char **qlines;
@@ -5543,18 +5632,10 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
        int fd;
        SE_PRIV se_printop = SE_PRINT_OPERATOR;
        bool is_print_op = false;
-       char *remote_machine = talloc_strdup(ctx, "%m");
 
        if (!remote_machine) {
                return false;
        }
-       remote_machine = talloc_sub_basic(ctx,
-                               current_user_info.smb_name,
-                               current_user_info.domain,
-                               remote_machine);
-       if (!remote_machine) {
-               return false;
-       }
 
        command = talloc_asprintf(ctx,
                        "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
@@ -5577,8 +5658,7 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
 
        if ( (ret = smbrun(command, &fd)) == 0 ) {
                /* Tell everyone we updated smb.conf. */
-               message_send_all(smbd_messaging_context(),
-                                MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
+               message_send_all(msg_ctx, MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
        }
 
        if ( is_print_op )
@@ -5589,7 +5669,6 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
        DEBUGADD(10,("returned [%d]\n", ret));
 
        TALLOC_FREE(command);
-       TALLOC_FREE(remote_machine);
 
        if ( ret != 0 ) {
                if (fd != -1)
@@ -5623,6 +5702,7 @@ 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)
@@ -5639,6 +5719,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->drivername);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_DRIVERNAME,
@@ -5658,6 +5739,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->comment);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_DESCRIPTION,
@@ -5674,6 +5756,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,
@@ -5699,6 +5782,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, p);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTERNAME,
@@ -5715,6 +5799,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->portname);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PORTNAME,
@@ -5731,6 +5816,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                push_reg_sz(mem_ctx, &buffer, printer->location);
                winreg_set_printer_dataex(mem_ctx,
                                          server_info,
+                                         msg_ctx,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_LOCATION,
@@ -5747,6 +5833,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,
@@ -5764,6 +5851,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,
@@ -5777,6 +5865,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,
@@ -5790,6 +5879,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,
@@ -5804,6 +5894,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,
@@ -5827,6 +5918,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,
@@ -5838,6 +5930,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,
@@ -5859,6 +5952,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,
@@ -5871,6 +5965,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,
@@ -5887,7 +5982,8 @@ done:
  * when updating a printer description.
  ********************************************************************/
 
-static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
+static WERROR update_printer(struct pipes_struct *p,
+                            struct policy_handle *handle,
                             struct spoolss_SetPrinterInfoCtr *info_ctr,
                             struct spoolss_DeviceMode *devmode)
 {
@@ -5923,6 +6019,7 @@ static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
 
        result = winreg_get_printer(tmp_ctx,
                                    p->server_info,
+                                   p->msg_ctx,
                                    servername,
                                    lp_const_servicename(snum),
                                    &old_printer);
@@ -5958,7 +6055,8 @@ static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
        {
                /* add_printer_hook() will call reload_services() */
                if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
-                                     printer) ) {
+                                     printer, p->client_address,
+                                     p->msg_ctx)) {
                        result = WERR_ACCESS_DENIED;
                        goto done;
                }
@@ -5966,6 +6064,7 @@ static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
 
        update_dsspooler(tmp_ctx,
                         p->server_info,
+                        p->msg_ctx,
                         snum,
                         printer,
                         old_printer);
@@ -5977,6 +6076,7 @@ static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
        }
        result = winreg_update_printer(tmp_ctx,
                                       p->server_info,
+                                      p->msg_ctx,
                                       printer->sharename,
                                       printer_mask,
                                       printer,
@@ -5991,7 +6091,7 @@ done:
 
 /****************************************************************************
 ****************************************************************************/
-static WERROR publish_or_unpublish_printer(pipes_struct *p,
+static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
                                           struct policy_handle *handle,
                                           struct spoolss_SetPrinterInfo7 *info7)
 {
@@ -6015,14 +6115,15 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p,
        if (!get_printer_snum(p, handle, &snum, NULL))
                return WERR_BADFID;
 
-       result = winreg_get_printer(p->mem_ctx, p->server_info,
+       result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
                                    Printer->servername,
                                    lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                return WERR_BADFID;
        }
 
-       nt_printer_publish(pinfo2, p->server_info, pinfo2, info7->action);
+       nt_printer_publish(pinfo2, p->server_info, p->msg_ctx, pinfo2,
+                          info7->action);
 
        TALLOC_FREE(pinfo2);
        return WERR_OK;
@@ -6034,7 +6135,8 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p,
 /********************************************************************
  ********************************************************************/
 
-static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *handle,
+static WERROR update_printer_devmode(struct pipes_struct *p,
+                                    struct policy_handle *handle,
                                     struct spoolss_DeviceMode *devmode)
 {
        int snum;
@@ -6059,6 +6161,7 @@ static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *hand
 
        return winreg_update_printer(p->mem_ctx,
                                     p->server_info,
+                                    p->msg_ctx,
                                     lp_const_servicename(snum),
                                     info2_mask,
                                     NULL,
@@ -6071,7 +6174,7 @@ static WERROR update_printer_devmode(pipes_struct *p, struct policy_handle *hand
  _spoolss_SetPrinter
 ****************************************************************/
 
-WERROR _spoolss_SetPrinter(pipes_struct *p,
+WERROR _spoolss_SetPrinter(struct pipes_struct *p,
                           struct spoolss_SetPrinter *r)
 {
        WERROR result;
@@ -6116,7 +6219,7 @@ WERROR _spoolss_SetPrinter(pipes_struct *p,
  _spoolss_FindClosePrinterNotify
 ****************************************************************/
 
-WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
+WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
                                       struct spoolss_FindClosePrinterNotify *r)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -6136,7 +6239,8 @@ WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
                                !get_printer_snum(p, r->in.handle, &snum, NULL) )
                        return WERR_BADFID;
 
-               srv_spoolss_replycloseprinter(snum, &Printer->notify.client_hnd);
+               srv_spoolss_replycloseprinter(
+                       snum, &Printer->notify.client_hnd, p->msg_ctx);
        }
 
        Printer->notify.flags=0;
@@ -6153,7 +6257,7 @@ WERROR _spoolss_FindClosePrinterNotify(pipes_struct *p,
  _spoolss_AddJob
 ****************************************************************/
 
-WERROR _spoolss_AddJob(pipes_struct *p,
+WERROR _spoolss_AddJob(struct pipes_struct *p,
                       struct spoolss_AddJob *r)
 {
        if (!r->in.buffer && (r->in.offered != 0)) {
@@ -6442,7 +6546,7 @@ static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
  _spoolss_EnumJobs
 ****************************************************************/
 
-WERROR _spoolss_EnumJobs(pipes_struct *p,
+WERROR _spoolss_EnumJobs(struct pipes_struct *p,
                         struct spoolss_EnumJobs *r)
 {
        WERROR result;
@@ -6470,8 +6574,8 @@ WERROR _spoolss_EnumJobs(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
-                                   lp_servicename(snum), &pinfo2);
+       result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
+                                   NULL, lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                return result;
        }
@@ -6525,7 +6629,7 @@ WERROR _spoolss_EnumJobs(pipes_struct *p,
  _spoolss_ScheduleJob
 ****************************************************************/
 
-WERROR _spoolss_ScheduleJob(pipes_struct *p,
+WERROR _spoolss_ScheduleJob(struct pipes_struct *p,
                            struct spoolss_ScheduleJob *r)
 {
        return WERR_OK;
@@ -6560,7 +6664,7 @@ static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
  _spoolss_SetJob
 ****************************************************************/
 
-WERROR _spoolss_SetJob(pipes_struct *p,
+WERROR _spoolss_SetJob(struct pipes_struct *p,
                       struct spoolss_SetJob *r)
 {
        int snum;
@@ -6631,6 +6735,7 @@ WERROR _spoolss_SetJob(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,
@@ -6650,7 +6755,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)) {
@@ -6676,6 +6781,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)) {
@@ -6747,6 +6853,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,
@@ -6765,6 +6872,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,
@@ -6785,6 +6893,7 @@ static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
 
        return enumprinterdrivers_level_by_architecture(mem_ctx,
                                                        server_info,
+                                                       msg_ctx,
                                                        servername,
                                                        architecture,
                                                        level,
@@ -6796,7 +6905,7 @@ static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
  _spoolss_EnumPrinterDrivers
 ****************************************************************/
 
-WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
+WERROR _spoolss_EnumPrinterDrivers(struct pipes_struct *p,
                                   struct spoolss_EnumPrinterDrivers *r)
 {
        const char *cservername;
@@ -6822,6 +6931,7 @@ WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
 
        result = enumprinterdrivers_level(p->mem_ctx,
                                          p->server_info,
+                                         p->msg_ctx,
                                          cservername,
                                          r->in.environment,
                                          r->in.level,
@@ -6845,7 +6955,7 @@ WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
  _spoolss_EnumForms
 ****************************************************************/
 
-WERROR _spoolss_EnumForms(pipes_struct *p,
+WERROR _spoolss_EnumForms(struct pipes_struct *p,
                          struct spoolss_EnumForms *r)
 {
        WERROR result;
@@ -6868,6 +6978,7 @@ WERROR _spoolss_EnumForms(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;
@@ -6898,7 +7009,7 @@ WERROR _spoolss_EnumForms(pipes_struct *p,
  _spoolss_GetForm
 ****************************************************************/
 
-WERROR _spoolss_GetForm(pipes_struct *p,
+WERROR _spoolss_GetForm(struct pipes_struct *p,
                        struct spoolss_GetForm *r)
 {
        WERROR result;
@@ -6917,6 +7028,7 @@ WERROR _spoolss_GetForm(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;
@@ -7143,7 +7255,7 @@ out:
  _spoolss_EnumPorts
 ****************************************************************/
 
-WERROR _spoolss_EnumPorts(pipes_struct *p,
+WERROR _spoolss_EnumPorts(struct pipes_struct *p,
                          struct spoolss_EnumPorts *r)
 {
        WERROR result;
@@ -7190,7 +7302,7 @@ WERROR _spoolss_EnumPorts(pipes_struct *p,
 /****************************************************************************
 ****************************************************************************/
 
-static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
+static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
                                           const char *server,
                                           struct spoolss_SetPrinterInfoCtr *info_ctr,
                                           struct spoolss_DeviceMode *devmode,
@@ -7247,7 +7359,8 @@ static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
 
        if (*lp_addprinter_cmd() ) {
                if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
-                                      info2) ) {
+                                      info2, p->client_address,
+                                      p->msg_ctx) ) {
                        return WERR_ACCESS_DENIED;
                }
        } else {
@@ -7262,7 +7375,8 @@ static WERROR spoolss_addprinterex_level_2(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;
        }
 
@@ -7280,12 +7394,14 @@ static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
 
        update_dsspooler(p->mem_ctx,
                         p->server_info,
+                        p->msg_ctx,
                         0,
                         info2,
                         NULL);
 
        err = winreg_update_printer(p->mem_ctx,
                                    p->server_info,
+                                   p->msg_ctx,
                                    info2->sharename,
                                    info2_mask,
                                    info2,
@@ -7308,7 +7424,7 @@ static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
  _spoolss_AddPrinterEx
 ****************************************************************/
 
-WERROR _spoolss_AddPrinterEx(pipes_struct *p,
+WERROR _spoolss_AddPrinterEx(struct pipes_struct *p,
                             struct spoolss_AddPrinterEx *r)
 {
        switch (r->in.info_ctr->level) {
@@ -7332,7 +7448,7 @@ WERROR _spoolss_AddPrinterEx(pipes_struct *p,
  _spoolss_AddPrinter
 ****************************************************************/
 
-WERROR _spoolss_AddPrinter(pipes_struct *p,
+WERROR _spoolss_AddPrinter(struct pipes_struct *p,
                           struct spoolss_AddPrinter *r)
 {
        struct spoolss_AddPrinterEx a;
@@ -7356,7 +7472,7 @@ WERROR _spoolss_AddPrinter(pipes_struct *p,
  _spoolss_AddPrinterDriverEx
 ****************************************************************/
 
-WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
+WERROR _spoolss_AddPrinterDriverEx(struct pipes_struct *p,
                                   struct spoolss_AddPrinterDriverEx *r)
 {
        WERROR err = WERR_OK;
@@ -7409,7 +7525,7 @@ WERROR _spoolss_AddPrinterDriverEx(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;
@@ -7422,7 +7538,7 @@ WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
         * to update each printer bound to this driver.   --jerry
         */
 
-       if (!srv_spoolss_drv_upgrade_printer(driver_name)) {
+       if (!srv_spoolss_drv_upgrade_printer(driver_name, p->msg_ctx)) {
                DEBUG(0,("%s: Failed to send message about upgrading driver [%s]!\n",
                        fn, driver_name));
        }
@@ -7435,7 +7551,7 @@ done:
  _spoolss_AddPrinterDriver
 ****************************************************************/
 
-WERROR _spoolss_AddPrinterDriver(pipes_struct *p,
+WERROR _spoolss_AddPrinterDriver(struct pipes_struct *p,
                                 struct spoolss_AddPrinterDriver *r)
 {
        struct spoolss_AddPrinterDriverEx a;
@@ -7561,7 +7677,7 @@ static WERROR getprinterdriverdir_level_1(TALLOC_CTX *mem_ctx,
  _spoolss_GetPrinterDriverDirectory
 ****************************************************************/
 
-WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
+WERROR _spoolss_GetPrinterDriverDirectory(struct pipes_struct *p,
                                          struct spoolss_GetPrinterDriverDirectory *r)
 {
        WERROR werror;
@@ -7599,7 +7715,7 @@ WERROR _spoolss_GetPrinterDriverDirectory(pipes_struct *p,
  _spoolss_EnumPrinterData
 ****************************************************************/
 
-WERROR _spoolss_EnumPrinterData(pipes_struct *p,
+WERROR _spoolss_EnumPrinterData(struct pipes_struct *p,
                                struct spoolss_EnumPrinterData *r)
 {
        WERROR result;
@@ -7739,7 +7855,7 @@ WERROR _spoolss_EnumPrinterData(pipes_struct *p,
  _spoolss_SetPrinterData
 ****************************************************************/
 
-WERROR _spoolss_SetPrinterData(pipes_struct *p,
+WERROR _spoolss_SetPrinterData(struct pipes_struct *p,
                               struct spoolss_SetPrinterData *r)
 {
        struct spoolss_SetPrinterDataEx r2;
@@ -7758,7 +7874,7 @@ WERROR _spoolss_SetPrinterData(pipes_struct *p,
  _spoolss_ResetPrinter
 ****************************************************************/
 
-WERROR _spoolss_ResetPrinter(pipes_struct *p,
+WERROR _spoolss_ResetPrinter(struct pipes_struct *p,
                             struct spoolss_ResetPrinter *r)
 {
        Printer_entry   *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -7790,7 +7906,7 @@ WERROR _spoolss_ResetPrinter(pipes_struct *p,
  _spoolss_DeletePrinterData
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinterData(pipes_struct *p,
+WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
                                  struct spoolss_DeletePrinterData *r)
 {
        struct spoolss_DeletePrinterDataEx r2;
@@ -7806,7 +7922,7 @@ WERROR _spoolss_DeletePrinterData(pipes_struct *p,
  _spoolss_AddForm
 ****************************************************************/
 
-WERROR _spoolss_AddForm(pipes_struct *p,
+WERROR _spoolss_AddForm(struct pipes_struct *p,
                        struct spoolss_AddForm *r)
 {
        struct spoolss_AddFormInfo1 *form = r->in.info.info1;
@@ -7847,7 +7963,8 @@ WERROR _spoolss_AddForm(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;
        }
@@ -7862,6 +7979,7 @@ WERROR _spoolss_AddForm(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;
@@ -7875,7 +7993,7 @@ WERROR _spoolss_AddForm(pipes_struct *p,
  _spoolss_DeleteForm
 ****************************************************************/
 
-WERROR _spoolss_DeleteForm(pipes_struct *p,
+WERROR _spoolss_DeleteForm(struct pipes_struct *p,
                           struct spoolss_DeleteForm *r)
 {
        const char *form_name = r->in.form_name;
@@ -7905,6 +8023,7 @@ WERROR _spoolss_DeleteForm(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;
@@ -7920,6 +8039,7 @@ WERROR _spoolss_DeleteForm(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;
@@ -7933,7 +8053,7 @@ WERROR _spoolss_DeleteForm(pipes_struct *p,
  _spoolss_SetForm
 ****************************************************************/
 
-WERROR _spoolss_SetForm(pipes_struct *p,
+WERROR _spoolss_SetForm(struct pipes_struct *p,
                        struct spoolss_SetForm *r)
 {
        struct spoolss_AddFormInfo1 *form = r->in.info.info1;
@@ -7968,6 +8088,7 @@ WERROR _spoolss_SetForm(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)) {
@@ -7984,6 +8105,7 @@ WERROR _spoolss_SetForm(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;
@@ -8044,7 +8166,7 @@ static WERROR enumprintprocessors_level_1(TALLOC_CTX *mem_ctx,
  _spoolss_EnumPrintProcessors
 ****************************************************************/
 
-WERROR _spoolss_EnumPrintProcessors(pipes_struct *p,
+WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
                                    struct spoolss_EnumPrintProcessors *r)
 {
        WERROR result;
@@ -8142,7 +8264,7 @@ static WERROR enumprintprocdatatypes_level_1(TALLOC_CTX *mem_ctx,
  _spoolss_EnumPrintProcDataTypes
 ****************************************************************/
 
-WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p,
+WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
                                       struct spoolss_EnumPrintProcDataTypes *r)
 {
        WERROR result;
@@ -8300,7 +8422,7 @@ out:
  _spoolss_EnumMonitors
 ****************************************************************/
 
-WERROR _spoolss_EnumMonitors(pipes_struct *p,
+WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
                             struct spoolss_EnumMonitors *r)
 {
        WERROR result;
@@ -8442,7 +8564,7 @@ static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
  _spoolss_GetJob
 ****************************************************************/
 
-WERROR _spoolss_GetJob(pipes_struct *p,
+WERROR _spoolss_GetJob(struct pipes_struct *p,
                       struct spoolss_GetJob *r)
 {
        WERROR result = WERR_OK;
@@ -8466,8 +8588,8 @@ WERROR _spoolss_GetJob(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = winreg_get_printer(p->mem_ctx, p->server_info, NULL,
-                                   lp_servicename(snum), &pinfo2);
+       result = winreg_get_printer(p->mem_ctx, p->server_info, p->msg_ctx,
+                                   NULL, lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                return result;
        }
@@ -8512,7 +8634,7 @@ WERROR _spoolss_GetJob(pipes_struct *p,
  _spoolss_GetPrinterDataEx
 ****************************************************************/
 
-WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
+WERROR _spoolss_GetPrinterDataEx(struct pipes_struct *p,
                                 struct spoolss_GetPrinterDataEx *r)
 {
 
@@ -8592,6 +8714,7 @@ WERROR _spoolss_GetPrinterDataEx(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)) {
@@ -8606,6 +8729,7 @@ WERROR _spoolss_GetPrinterDataEx(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,
@@ -8634,7 +8758,7 @@ WERROR _spoolss_GetPrinterDataEx(pipes_struct *p,
  _spoolss_SetPrinterDataEx
 ****************************************************************/
 
-WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
+WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
                                 struct spoolss_SetPrinterDataEx *r)
 {
        struct spoolss_PrinterInfo2 *pinfo2 = NULL;
@@ -8678,7 +8802,7 @@ WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
                return WERR_ACCESS_DENIED;
        }
 
-       result = winreg_get_printer(Printer, p->server_info,
+       result = winreg_get_printer(Printer, p->server_info, p->msg_ctx,
                                    Printer->servername,
                                    lp_servicename(snum),
                                    &pinfo2);
@@ -8698,6 +8822,7 @@ WERROR _spoolss_SetPrinterDataEx(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,
@@ -8723,6 +8848,7 @@ WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
                         */
                        winreg_set_printer_dataex(p->mem_ctx,
                                                  p->server_info,
+                                                 p->msg_ctx,
                                                  pinfo2->sharename,
                                                  str,
                                                  r->in.value_name,
@@ -8733,6 +8859,7 @@ WERROR _spoolss_SetPrinterDataEx(pipes_struct *p,
 
                result = winreg_printer_update_changeid(p->mem_ctx,
                                                        p->server_info,
+                                                       p->msg_ctx,
                                                        lp_const_servicename(snum));
 
        }
@@ -8746,7 +8873,7 @@ done:
  _spoolss_DeletePrinterDataEx
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
+WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
                                    struct spoolss_DeletePrinterDataEx *r)
 {
        const char *printer;
@@ -8780,12 +8907,14 @@ WERROR _spoolss_DeletePrinterDataEx(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);
        }
 
@@ -8796,7 +8925,7 @@ WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
  _spoolss_EnumPrinterKey
 ****************************************************************/
 
-WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
+WERROR _spoolss_EnumPrinterKey(struct pipes_struct *p,
                               struct spoolss_EnumPrinterKey *r)
 {
        uint32_t        num_keys;
@@ -8820,6 +8949,7 @@ WERROR _spoolss_EnumPrinterKey(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,
@@ -8858,7 +8988,7 @@ WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
  _spoolss_DeletePrinterKey
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
+WERROR _spoolss_DeletePrinterKey(struct pipes_struct *p,
                                 struct spoolss_DeletePrinterKey *r)
 {
        Printer_entry           *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -8893,11 +9023,13 @@ WERROR _spoolss_DeletePrinterKey(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);
        }
 
@@ -8908,7 +9040,7 @@ WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
  _spoolss_EnumPrinterDataEx
 ****************************************************************/
 
-WERROR _spoolss_EnumPrinterDataEx(pipes_struct *p,
+WERROR _spoolss_EnumPrinterDataEx(struct pipes_struct *p,
                                  struct spoolss_EnumPrinterDataEx *r)
 {
        uint32_t        count = 0;
@@ -8948,6 +9080,7 @@ WERROR _spoolss_EnumPrinterDataEx(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,
@@ -9017,7 +9150,7 @@ static WERROR getprintprocessordirectory_level_1(TALLOC_CTX *mem_ctx,
  _spoolss_GetPrintProcessorDirectory
 ****************************************************************/
 
-WERROR _spoolss_GetPrintProcessorDirectory(pipes_struct *p,
+WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
                                           struct spoolss_GetPrintProcessorDirectory *r)
 {
        WERROR result;
@@ -9304,7 +9437,7 @@ static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
  _spoolss_XcvData
 ****************************************************************/
 
-WERROR _spoolss_XcvData(pipes_struct *p,
+WERROR _spoolss_XcvData(struct pipes_struct *p,
                        struct spoolss_XcvData *r)
 {
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -9377,7 +9510,7 @@ WERROR _spoolss_XcvData(pipes_struct *p,
  _spoolss_AddPrintProcessor
 ****************************************************************/
 
-WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
+WERROR _spoolss_AddPrintProcessor(struct pipes_struct *p,
                                  struct spoolss_AddPrintProcessor *r)
 {
        /* for now, just indicate success and ignore the add.  We'll
@@ -9392,7 +9525,7 @@ WERROR _spoolss_AddPrintProcessor(pipes_struct *p,
  _spoolss_AddPort
 ****************************************************************/
 
-WERROR _spoolss_AddPort(pipes_struct *p,
+WERROR _spoolss_AddPort(struct pipes_struct *p,
                        struct spoolss_AddPort *r)
 {
        /* do what w2k3 does */
@@ -9404,7 +9537,7 @@ WERROR _spoolss_AddPort(pipes_struct *p,
  _spoolss_GetPrinterDriver
 ****************************************************************/
 
-WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
+WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
                                 struct spoolss_GetPrinterDriver *r)
 {
        p->rng_fault_state = true;
@@ -9415,7 +9548,7 @@ WERROR _spoolss_GetPrinterDriver(pipes_struct *p,
  _spoolss_ReadPrinter
 ****************************************************************/
 
-WERROR _spoolss_ReadPrinter(pipes_struct *p,
+WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
                            struct spoolss_ReadPrinter *r)
 {
        p->rng_fault_state = true;
@@ -9426,7 +9559,7 @@ WERROR _spoolss_ReadPrinter(pipes_struct *p,
  _spoolss_WaitForPrinterChange
 ****************************************************************/
 
-WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
+WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
                                     struct spoolss_WaitForPrinterChange *r)
 {
        p->rng_fault_state = true;
@@ -9437,7 +9570,7 @@ WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
  _spoolss_ConfigurePort
 ****************************************************************/
 
-WERROR _spoolss_ConfigurePort(pipes_struct *p,
+WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
                              struct spoolss_ConfigurePort *r)
 {
        p->rng_fault_state = true;
@@ -9448,7 +9581,7 @@ WERROR _spoolss_ConfigurePort(pipes_struct *p,
  _spoolss_DeletePort
 ****************************************************************/
 
-WERROR _spoolss_DeletePort(pipes_struct *p,
+WERROR _spoolss_DeletePort(struct pipes_struct *p,
                           struct spoolss_DeletePort *r)
 {
        p->rng_fault_state = true;
@@ -9459,7 +9592,7 @@ WERROR _spoolss_DeletePort(pipes_struct *p,
  _spoolss_CreatePrinterIC
 ****************************************************************/
 
-WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
+WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
                                struct spoolss_CreatePrinterIC *r)
 {
        p->rng_fault_state = true;
@@ -9470,7 +9603,7 @@ WERROR _spoolss_CreatePrinterIC(pipes_struct *p,
  _spoolss_PlayGDIScriptOnPrinterIC
 ****************************************************************/
 
-WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
+WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
                                         struct spoolss_PlayGDIScriptOnPrinterIC *r)
 {
        p->rng_fault_state = true;
@@ -9481,7 +9614,7 @@ WERROR _spoolss_PlayGDIScriptOnPrinterIC(pipes_struct *p,
  _spoolss_DeletePrinterIC
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
+WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
                                struct spoolss_DeletePrinterIC *r)
 {
        p->rng_fault_state = true;
@@ -9492,7 +9625,7 @@ WERROR _spoolss_DeletePrinterIC(pipes_struct *p,
  _spoolss_AddPrinterConnection
 ****************************************************************/
 
-WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
+WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
                                     struct spoolss_AddPrinterConnection *r)
 {
        p->rng_fault_state = true;
@@ -9503,7 +9636,7 @@ WERROR _spoolss_AddPrinterConnection(pipes_struct *p,
  _spoolss_DeletePrinterConnection
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
+WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
                                        struct spoolss_DeletePrinterConnection *r)
 {
        p->rng_fault_state = true;
@@ -9514,7 +9647,7 @@ WERROR _spoolss_DeletePrinterConnection(pipes_struct *p,
  _spoolss_PrinterMessageBox
 ****************************************************************/
 
-WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
+WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
                                  struct spoolss_PrinterMessageBox *r)
 {
        p->rng_fault_state = true;
@@ -9525,7 +9658,7 @@ WERROR _spoolss_PrinterMessageBox(pipes_struct *p,
  _spoolss_AddMonitor
 ****************************************************************/
 
-WERROR _spoolss_AddMonitor(pipes_struct *p,
+WERROR _spoolss_AddMonitor(struct pipes_struct *p,
                           struct spoolss_AddMonitor *r)
 {
        p->rng_fault_state = true;
@@ -9536,7 +9669,7 @@ WERROR _spoolss_AddMonitor(pipes_struct *p,
  _spoolss_DeleteMonitor
 ****************************************************************/
 
-WERROR _spoolss_DeleteMonitor(pipes_struct *p,
+WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
                              struct spoolss_DeleteMonitor *r)
 {
        p->rng_fault_state = true;
@@ -9547,7 +9680,7 @@ WERROR _spoolss_DeleteMonitor(pipes_struct *p,
  _spoolss_DeletePrintProcessor
 ****************************************************************/
 
-WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
+WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
                                     struct spoolss_DeletePrintProcessor *r)
 {
        p->rng_fault_state = true;
@@ -9558,7 +9691,7 @@ WERROR _spoolss_DeletePrintProcessor(pipes_struct *p,
  _spoolss_AddPrintProvidor
 ****************************************************************/
 
-WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
+WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
                                 struct spoolss_AddPrintProvidor *r)
 {
        p->rng_fault_state = true;
@@ -9569,7 +9702,7 @@ WERROR _spoolss_AddPrintProvidor(pipes_struct *p,
  _spoolss_DeletePrintProvidor
 ****************************************************************/
 
-WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
+WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
                                    struct spoolss_DeletePrintProvidor *r)
 {
        p->rng_fault_state = true;
@@ -9580,7 +9713,7 @@ WERROR _spoolss_DeletePrintProvidor(pipes_struct *p,
  _spoolss_FindFirstPrinterChangeNotification
 ****************************************************************/
 
-WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
+WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
                                                   struct spoolss_FindFirstPrinterChangeNotification *r)
 {
        p->rng_fault_state = true;
@@ -9591,7 +9724,7 @@ WERROR _spoolss_FindFirstPrinterChangeNotification(pipes_struct *p,
  _spoolss_FindNextPrinterChangeNotification
 ****************************************************************/
 
-WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
+WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
                                                  struct spoolss_FindNextPrinterChangeNotification *r)
 {
        p->rng_fault_state = true;
@@ -9602,7 +9735,7 @@ WERROR _spoolss_FindNextPrinterChangeNotification(pipes_struct *p,
  _spoolss_RouterFindFirstPrinterChangeNotificationOld
 ****************************************************************/
 
-WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
+WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
                                                            struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
 {
        p->rng_fault_state = true;
@@ -9613,7 +9746,7 @@ WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(pipes_struct *p,
  _spoolss_ReplyOpenPrinter
 ****************************************************************/
 
-WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
+WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
                                 struct spoolss_ReplyOpenPrinter *r)
 {
        p->rng_fault_state = true;
@@ -9624,7 +9757,7 @@ WERROR _spoolss_ReplyOpenPrinter(pipes_struct *p,
  _spoolss_RouterReplyPrinter
 ****************************************************************/
 
-WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
+WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
                                   struct spoolss_RouterReplyPrinter *r)
 {
        p->rng_fault_state = true;
@@ -9635,7 +9768,7 @@ WERROR _spoolss_RouterReplyPrinter(pipes_struct *p,
  _spoolss_ReplyClosePrinter
 ****************************************************************/
 
-WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
+WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
                                  struct spoolss_ReplyClosePrinter *r)
 {
        p->rng_fault_state = true;
@@ -9646,7 +9779,7 @@ WERROR _spoolss_ReplyClosePrinter(pipes_struct *p,
  _spoolss_AddPortEx
 ****************************************************************/
 
-WERROR _spoolss_AddPortEx(pipes_struct *p,
+WERROR _spoolss_AddPortEx(struct pipes_struct *p,
                          struct spoolss_AddPortEx *r)
 {
        p->rng_fault_state = true;
@@ -9657,7 +9790,7 @@ WERROR _spoolss_AddPortEx(pipes_struct *p,
  _spoolss_RouterFindFirstPrinterChangeNotification
 ****************************************************************/
 
-WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
+WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
                                                         struct spoolss_RouterFindFirstPrinterChangeNotification *r)
 {
        p->rng_fault_state = true;
@@ -9668,7 +9801,7 @@ WERROR _spoolss_RouterFindFirstPrinterChangeNotification(pipes_struct *p,
  _spoolss_SpoolerInit
 ****************************************************************/
 
-WERROR _spoolss_SpoolerInit(pipes_struct *p,
+WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
                            struct spoolss_SpoolerInit *r)
 {
        p->rng_fault_state = true;
@@ -9679,7 +9812,7 @@ WERROR _spoolss_SpoolerInit(pipes_struct *p,
  _spoolss_ResetPrinterEx
 ****************************************************************/
 
-WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
+WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
                               struct spoolss_ResetPrinterEx *r)
 {
        p->rng_fault_state = true;
@@ -9690,7 +9823,7 @@ WERROR _spoolss_ResetPrinterEx(pipes_struct *p,
  _spoolss_RouterReplyPrinterEx
 ****************************************************************/
 
-WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
+WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
                                     struct spoolss_RouterReplyPrinterEx *r)
 {
        p->rng_fault_state = true;
@@ -9701,7 +9834,7 @@ WERROR _spoolss_RouterReplyPrinterEx(pipes_struct *p,
  _spoolss_44
 ****************************************************************/
 
-WERROR _spoolss_44(pipes_struct *p,
+WERROR _spoolss_44(struct pipes_struct *p,
                   struct spoolss_44 *r)
 {
        p->rng_fault_state = true;
@@ -9712,7 +9845,7 @@ WERROR _spoolss_44(pipes_struct *p,
  _spoolss_47
 ****************************************************************/
 
-WERROR _spoolss_47(pipes_struct *p,
+WERROR _spoolss_47(struct pipes_struct *p,
                   struct spoolss_47 *r)
 {
        p->rng_fault_state = true;
@@ -9723,7 +9856,7 @@ WERROR _spoolss_47(pipes_struct *p,
  _spoolss_4a
 ****************************************************************/
 
-WERROR _spoolss_4a(pipes_struct *p,
+WERROR _spoolss_4a(struct pipes_struct *p,
                   struct spoolss_4a *r)
 {
        p->rng_fault_state = true;
@@ -9734,7 +9867,7 @@ WERROR _spoolss_4a(pipes_struct *p,
  _spoolss_4b
 ****************************************************************/
 
-WERROR _spoolss_4b(pipes_struct *p,
+WERROR _spoolss_4b(struct pipes_struct *p,
                   struct spoolss_4b *r)
 {
        p->rng_fault_state = true;
@@ -9745,7 +9878,7 @@ WERROR _spoolss_4b(pipes_struct *p,
  _spoolss_4c
 ****************************************************************/
 
-WERROR _spoolss_4c(pipes_struct *p,
+WERROR _spoolss_4c(struct pipes_struct *p,
                   struct spoolss_4c *r)
 {
        p->rng_fault_state = true;
@@ -9756,7 +9889,7 @@ WERROR _spoolss_4c(pipes_struct *p,
  _spoolss_53
 ****************************************************************/
 
-WERROR _spoolss_53(pipes_struct *p,
+WERROR _spoolss_53(struct pipes_struct *p,
                   struct spoolss_53 *r)
 {
        p->rng_fault_state = true;
@@ -9767,7 +9900,7 @@ WERROR _spoolss_53(pipes_struct *p,
  _spoolss_55
 ****************************************************************/
 
-WERROR _spoolss_55(pipes_struct *p,
+WERROR _spoolss_55(struct pipes_struct *p,
                   struct spoolss_55 *r)
 {
        p->rng_fault_state = true;
@@ -9778,7 +9911,7 @@ WERROR _spoolss_55(pipes_struct *p,
  _spoolss_56
 ****************************************************************/
 
-WERROR _spoolss_56(pipes_struct *p,
+WERROR _spoolss_56(struct pipes_struct *p,
                   struct spoolss_56 *r)
 {
        p->rng_fault_state = true;
@@ -9789,7 +9922,7 @@ WERROR _spoolss_56(pipes_struct *p,
  _spoolss_57
 ****************************************************************/
 
-WERROR _spoolss_57(pipes_struct *p,
+WERROR _spoolss_57(struct pipes_struct *p,
                   struct spoolss_57 *r)
 {
        p->rng_fault_state = true;
@@ -9800,7 +9933,7 @@ WERROR _spoolss_57(pipes_struct *p,
  _spoolss_5a
 ****************************************************************/
 
-WERROR _spoolss_5a(pipes_struct *p,
+WERROR _spoolss_5a(struct pipes_struct *p,
                   struct spoolss_5a *r)
 {
        p->rng_fault_state = true;
@@ -9811,7 +9944,7 @@ WERROR _spoolss_5a(pipes_struct *p,
  _spoolss_5b
 ****************************************************************/
 
-WERROR _spoolss_5b(pipes_struct *p,
+WERROR _spoolss_5b(struct pipes_struct *p,
                   struct spoolss_5b *r)
 {
        p->rng_fault_state = true;
@@ -9822,7 +9955,7 @@ WERROR _spoolss_5b(pipes_struct *p,
  _spoolss_5c
 ****************************************************************/
 
-WERROR _spoolss_5c(pipes_struct *p,
+WERROR _spoolss_5c(struct pipes_struct *p,
                   struct spoolss_5c *r)
 {
        p->rng_fault_state = true;
@@ -9833,7 +9966,7 @@ WERROR _spoolss_5c(pipes_struct *p,
  _spoolss_5d
 ****************************************************************/
 
-WERROR _spoolss_5d(pipes_struct *p,
+WERROR _spoolss_5d(struct pipes_struct *p,
                   struct spoolss_5d *r)
 {
        p->rng_fault_state = true;
@@ -9844,7 +9977,7 @@ WERROR _spoolss_5d(pipes_struct *p,
  _spoolss_5e
 ****************************************************************/
 
-WERROR _spoolss_5e(pipes_struct *p,
+WERROR _spoolss_5e(struct pipes_struct *p,
                   struct spoolss_5e *r)
 {
        p->rng_fault_state = true;
@@ -9855,7 +9988,7 @@ WERROR _spoolss_5e(pipes_struct *p,
  _spoolss_5f
 ****************************************************************/
 
-WERROR _spoolss_5f(pipes_struct *p,
+WERROR _spoolss_5f(struct pipes_struct *p,
                   struct spoolss_5f *r)
 {
        p->rng_fault_state = true;
@@ -9866,7 +9999,7 @@ WERROR _spoolss_5f(pipes_struct *p,
  _spoolss_60
 ****************************************************************/
 
-WERROR _spoolss_60(pipes_struct *p,
+WERROR _spoolss_60(struct pipes_struct *p,
                   struct spoolss_60 *r)
 {
        p->rng_fault_state = true;
@@ -9877,7 +10010,7 @@ WERROR _spoolss_60(pipes_struct *p,
  _spoolss_61
 ****************************************************************/
 
-WERROR _spoolss_61(pipes_struct *p,
+WERROR _spoolss_61(struct pipes_struct *p,
                   struct spoolss_61 *r)
 {
        p->rng_fault_state = true;
@@ -9888,7 +10021,7 @@ WERROR _spoolss_61(pipes_struct *p,
  _spoolss_62
 ****************************************************************/
 
-WERROR _spoolss_62(pipes_struct *p,
+WERROR _spoolss_62(struct pipes_struct *p,
                   struct spoolss_62 *r)
 {
        p->rng_fault_state = true;
@@ -9899,7 +10032,7 @@ WERROR _spoolss_62(pipes_struct *p,
  _spoolss_63
 ****************************************************************/
 
-WERROR _spoolss_63(pipes_struct *p,
+WERROR _spoolss_63(struct pipes_struct *p,
                   struct spoolss_63 *r)
 {
        p->rng_fault_state = true;
@@ -9910,7 +10043,7 @@ WERROR _spoolss_63(pipes_struct *p,
  _spoolss_64
 ****************************************************************/
 
-WERROR _spoolss_64(pipes_struct *p,
+WERROR _spoolss_64(struct pipes_struct *p,
                   struct spoolss_64 *r)
 {
        p->rng_fault_state = true;
@@ -9921,7 +10054,7 @@ WERROR _spoolss_64(pipes_struct *p,
  _spoolss_65
 ****************************************************************/
 
-WERROR _spoolss_65(pipes_struct *p,
+WERROR _spoolss_65(struct pipes_struct *p,
                   struct spoolss_65 *r)
 {
        p->rng_fault_state = true;
@@ -9932,7 +10065,7 @@ WERROR _spoolss_65(pipes_struct *p,
  _spoolss_GetCorePrinterDrivers
 ****************************************************************/
 
-WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
+WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
                                      struct spoolss_GetCorePrinterDrivers *r)
 {
        p->rng_fault_state = true;
@@ -9943,7 +10076,7 @@ WERROR _spoolss_GetCorePrinterDrivers(pipes_struct *p,
  _spoolss_67
 ****************************************************************/
 
-WERROR _spoolss_67(pipes_struct *p,
+WERROR _spoolss_67(struct pipes_struct *p,
                   struct spoolss_67 *r)
 {
        p->rng_fault_state = true;
@@ -9954,7 +10087,7 @@ WERROR _spoolss_67(pipes_struct *p,
  _spoolss_GetPrinterDriverPackagePath
 ****************************************************************/
 
-WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
+WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
                                            struct spoolss_GetPrinterDriverPackagePath *r)
 {
        p->rng_fault_state = true;
@@ -9965,7 +10098,7 @@ WERROR _spoolss_GetPrinterDriverPackagePath(pipes_struct *p,
  _spoolss_69
 ****************************************************************/
 
-WERROR _spoolss_69(pipes_struct *p,
+WERROR _spoolss_69(struct pipes_struct *p,
                   struct spoolss_69 *r)
 {
        p->rng_fault_state = true;
@@ -9976,7 +10109,7 @@ WERROR _spoolss_69(pipes_struct *p,
  _spoolss_6a
 ****************************************************************/
 
-WERROR _spoolss_6a(pipes_struct *p,
+WERROR _spoolss_6a(struct pipes_struct *p,
                   struct spoolss_6a *r)
 {
        p->rng_fault_state = true;
@@ -9987,7 +10120,7 @@ WERROR _spoolss_6a(pipes_struct *p,
  _spoolss_6b
 ****************************************************************/
 
-WERROR _spoolss_6b(pipes_struct *p,
+WERROR _spoolss_6b(struct pipes_struct *p,
                   struct spoolss_6b *r)
 {
        p->rng_fault_state = true;
@@ -9998,7 +10131,7 @@ WERROR _spoolss_6b(pipes_struct *p,
  _spoolss_6c
 ****************************************************************/
 
-WERROR _spoolss_6c(pipes_struct *p,
+WERROR _spoolss_6c(struct pipes_struct *p,
                   struct spoolss_6c *r)
 {
        p->rng_fault_state = true;
@@ -10009,7 +10142,7 @@ WERROR _spoolss_6c(pipes_struct *p,
  _spoolss_6d
 ****************************************************************/
 
-WERROR _spoolss_6d(pipes_struct *p,
+WERROR _spoolss_6d(struct pipes_struct *p,
                   struct spoolss_6d *r)
 {
        p->rng_fault_state = true;