s3: Lift the smbd_messaging_context from winreg_printer_getform1
[amitay/samba.git] / source3 / rpc_server / srv_spoolss_nt.c
index 8e376f9c6d475d47fd8609cf2b1c22abaf504952..d066369b1acba3e0719d63376dfb83161291c27d 100644 (file)
@@ -8,6 +8,7 @@
  *  Copyright (C) Gerald Carter                       2000-2004,
  *  Copyright (C) Tim Potter                   2001-2002.
  *  Copyright (C) Guenther Deschner            2009-2010.
+ *  Copyright (C) Andreas Schneider            2010.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
    up, all the errors returned are DOS errors, not NT status codes. */
 
 #include "includes.h"
+#include "nt_printing.h"
 #include "srv_spoolss_util.h"
 #include "../librpc/gen_ndr/srv_spoolss.h"
 #include "../librpc/gen_ndr/cli_spoolss.h"
 #include "rpc_client/init_spoolss.h"
 #include "librpc/gen_ndr/messaging.h"
+#include "librpc/gen_ndr/ndr_security.h"
 #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
-
-#define MAGIC_DISPLAY_FREQUENCY 0xfade2bad
-
 static Printer_entry *printers_list;
 
 typedef struct _counter_printer_0 {
@@ -75,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 */
+
+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 */
 
-extern struct standard_mapping printer_std_mapping, printserver_std_mapping;
+const struct standard_mapping printserver_std_mapping = {
+       SERVER_READ,
+       SERVER_WRITE,
+       SERVER_EXECUTE,
+       SERVER_ALL_ACCESS
+};
 
 /* API table for Xcv Monitor functions */
 
@@ -148,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;
@@ -161,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;
@@ -178,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--;
@@ -205,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);
                }
        }
 
@@ -222,7 +245,6 @@ static int printer_entry_destructor(Printer_entry *Printer)
        Printer->notify.client_connected = false;
 
        TALLOC_FREE(Printer->devmode);
-       free_a_printer( &Printer->printer_info, 2 );
 
        /* Remove from the internal list. */
        DLIST_REMOVE(printers_list, Printer);
@@ -233,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;
@@ -250,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);
 
@@ -269,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;
@@ -300,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 )
@@ -331,9 +354,10 @@ 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;
 
        if (!Printer) {
                DEBUG(2,("delete_printer_handle: Invalid handle (%s:%u:%u)\n",
@@ -356,20 +380,22 @@ static WERROR delete_printer_handle(pipes_struct *p, struct policy_handle *hnd)
        /* this does not need a become root since the access check has been
           done on the handle already */
 
-       if (del_a_printer( Printer->sharename ) != 0) {
+       result = winreg_delete_printer_key(p->mem_ctx, p->server_info,
+                                          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);
@@ -427,15 +453,19 @@ static bool set_printer_hnd_printertype(Printer_entry *Printer, const char *hand
  XcvDataPort() interface.
 ****************************************************************************/
 
-static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
+static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
+                                struct auth_serversupplied_info *server_info,
+                                Printer_entry *Printer,
+                                const char *handlename)
 {
        int snum;
        int n_services=lp_numservices();
-       char *aprinter, *printername;
-       const char *servername;
+       char *aprinter;
+       const char *printername;
+       const char *servername = NULL;
        fstring sname;
        bool found = false;
-       NT_PRINTER_INFO_LEVEL *printer = NULL;
+       struct spoolss_PrinterInfo2 *info2 = NULL;
        WERROR result;
 
        DEBUG(4,("Setting printer name=%s (len=%lu)\n", handlename,
@@ -448,27 +478,24 @@ static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
                        *aprinter = '\0';
                        aprinter++;
                }
-       } else {
-               servername = global_myname();
-       }
-
-       /* save the servername to fill in replies on this handle */
-
-       if ( !is_myname_or_ipaddr( servername ) )
-               return false;
+               if (!is_myname_or_ipaddr(servername)) {
+                       return false;
+               }
 
-       fstrcpy( Printer->servername, servername );
+               fstrcpy(Printer->servername, servername);
+       }
 
-       if ( Printer->printer_type == SPLHND_SERVER )
+       if (Printer->printer_type == SPLHND_SERVER) {
                return true;
+       }
 
-       if ( Printer->printer_type != SPLHND_PRINTER )
+       if (Printer->printer_type != SPLHND_PRINTER) {
                return false;
+       }
 
-       DEBUGADD(5, ("searching for [%s]\n", aprinter ));
+       DEBUGADD(5, ("searching for [%s]\n", aprinter));
 
        /* check for the Port Monitor Interface */
-
        if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
                Printer->printer_type = SPLHND_PORTMON_TCP;
                fstrcpy(sname, SPL_XCV_MONITOR_TCPMON);
@@ -485,65 +512,60 @@ static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
           that calls out to map_username() */
 
        /* do another loop to look for printernames */
-
-       for (snum=0; !found && snum<n_services; snum++) {
+       for (snum = 0; !found && snum < n_services; snum++) {
+               const char *printer = lp_const_servicename(snum);
 
                /* no point going on if this is not a printer */
+               if (!(lp_snum_ok(snum) && lp_print_ok(snum))) {
+                       continue;
+               }
 
-               if ( !(lp_snum_ok(snum) && lp_print_ok(snum)) )
+               /* ignore [printers] share */
+               if (strequal(printer, "printers")) {
                        continue;
+               }
 
-               fstrcpy(sname, lp_servicename(snum));
-               if ( strequal( aprinter, sname ) ) {
+               fstrcpy(sname, printer);
+               if (strequal(aprinter, printer)) {
                        found = true;
                        break;
                }
 
                /* no point looking up the printer object if
                   we aren't allowing printername != sharename */
-
-               if ( lp_force_printername(snum) )
+               if (lp_force_printername(snum)) {
                        continue;
+               }
 
-               fstrcpy(sname, lp_servicename(snum));
-
-               printer = NULL;
-
-               /* This call doesn't fill in the location or comment from
-                * a CUPS server for efficiency with large numbers of printers.
-                * JRA.
-                */
-
-               result = get_a_printer_search( NULL, &printer, 2, sname );
+               result = winreg_get_printer(mem_ctx,
+                                           server_info,
+                                           smbd_messaging_context(),
+                                           servername,
+                                           sname,
+                                           &info2);
                if ( !W_ERROR_IS_OK(result) ) {
-                       DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
-                               sname, win_errstr(result)));
+                       DEBUG(2,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
+                                sname, win_errstr(result)));
                        continue;
                }
 
-               /* printername is always returned as \\server\printername */
-               if ( !(printername = strchr_m(&printer->info_2->printername[2], '\\')) ) {
-                       DEBUG(0,("set_printer_hnd_name: info2->printername in wrong format! [%s]\n",
-                               printer->info_2->printername));
-                       free_a_printer( &printer, 2);
-                       continue;
+               printername = strrchr(info2->printername, '\\');
+               if (printername == NULL) {
+                       printername = info2->printername;
+               } else {
+                       printername++;
                }
 
-               printername++;
-
-               if ( strequal(printername, aprinter) ) {
-                       free_a_printer( &printer, 2);
+               if (strequal(printername, aprinter)) {
                        found = true;
                        break;
                }
 
                DEBUGADD(10, ("printername: %s\n", printername));
 
-               free_a_printer( &printer, 2);
+               TALLOC_FREE(info2);
        }
 
-       free_a_printer( &printer, 2);
-
        if ( !found ) {
                DEBUGADD(4,("Printer not found\n"));
                return false;
@@ -560,7 +582,7 @@ static bool set_printer_hnd_name(Printer_entry *Printer, const char *handlename)
  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;
@@ -588,7 +610,7 @@ static bool open_printer_hnd(pipes_struct *p, struct policy_handle *hnd,
                return false;
        }
 
-       if (!set_printer_hnd_name(new_printer, name)) {
+       if (!set_printer_hnd_name(p->mem_ctx, p->server_info, new_printer, name)) {
                close_printer_handle(p, hnd);
                return false;
        }
@@ -670,12 +692,13 @@ static bool is_monitoring_event(Printer_entry *p, uint16_t notify_type,
 #define SETUP_SPOOLSS_NOTIFY_DATA_DEVMODE(_data, _devmode) \
        _data->data.devmode.devmode = _devmode;
 
-#define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _size, _sd) \
+#define SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(_data, _sd) \
        _data->data.sd.sd = dup_sec_desc(mem_ctx, _sd); \
        if (!_data->data.sd.sd) { \
                _data->data.sd.sd_size = 0; \
        } \
-       _data->data.sd.sd_size = _size;
+       _data->data.sd.sd_size = \
+               ndr_size_security_descriptor(_data->data.sd.sd, 0);
 
 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
                                   struct tm *t,
@@ -941,10 +964,9 @@ static int notify_msg_ctr_addmsg( SPOOLSS_NOTIFY_MSG_CTR *ctr, SPOOLSS_NOTIFY_MS
        return ctr->num_groups;
 }
 
-void construct_info_data(struct spoolss_Notify *info_data,
-                        enum spoolss_NotifyType type,
-                        uint16_t field,
-                        int id);
+static void construct_info_data(struct spoolss_Notify *info_data,
+                               enum spoolss_NotifyType type,
+                               uint16_t field, int id);
 
 /***********************************************************************
  Send a change notication message on all handles which have a call
@@ -1258,7 +1280,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);
 
@@ -1268,8 +1291,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);
 
@@ -1287,47 +1309,78 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
                            struct server_id server_id,
                            DATA_BLOB *data)
 {
-       fstring drivername;
+       TALLOC_CTX *tmp_ctx;
+       struct auth_serversupplied_info *server_info = NULL;
+       struct spoolss_PrinterInfo2 *pinfo2;
+       NTSTATUS status;
+       WERROR result;
+       const char *drivername;
        int snum;
        int n_services = lp_numservices();
        size_t len;
 
+       tmp_ctx = talloc_new(NULL);
+       if (!tmp_ctx) return;
+
+       status = make_server_info_system(tmp_ctx, &server_info);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("do_drv_upgrade_printer: "
+                         "Could not create system server_info\n"));
+               goto done;
+       }
+
        len = MIN(data->length,sizeof(drivername)-1);
-       strncpy(drivername, (const char *)data->data, len);
+       drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
+       if (!drivername) {
+               DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
+               goto done;
+       }
 
-       DEBUG(10,("do_drv_upgrade_printer: Got message for new driver [%s]\n", drivername ));
+       DEBUG(10, ("do_drv_upgrade_printer: "
+                  "Got message for new driver [%s]\n", drivername));
 
        /* Iterate the printer list */
 
-       for (snum=0; snum<n_services; snum++)
-       {
-               if (lp_snum_ok(snum) && lp_print_ok(snum) )
-               {
-                       WERROR result;
-                       NT_PRINTER_INFO_LEVEL *printer = NULL;
+       for (snum = 0; snum < n_services; snum++) {
+               if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
+                       continue;
+               }
 
-                       result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
-                       if (!W_ERROR_IS_OK(result))
-                               continue;
+               result = winreg_get_printer(tmp_ctx, server_info, msg,
+                                           NULL,
+                                           lp_const_servicename(snum),
+                                           &pinfo2);
 
-                       if (printer && printer->info_2 && !strcmp(drivername, printer->info_2->drivername))
-                       {
-                               DEBUG(6,("Updating printer [%s]\n", printer->info_2->printername));
+               if (!W_ERROR_IS_OK(result)) {
+                       continue;
+               }
 
-                               /* all we care about currently is the change_id */
+               if (!pinfo2->drivername) {
+                       continue;
+               }
 
-                               result = mod_a_printer(printer, 2);
-                               if (!W_ERROR_IS_OK(result)) {
-                                       DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n",
-                                               win_errstr(result)));
-                               }
-                       }
+               if (strcmp(drivername, pinfo2->drivername) != 0) {
+                       continue;
+               }
+
+               DEBUG(6,("Updating printer [%s]\n", pinfo2->printername));
 
-                       free_a_printer(&printer, 2);
+               /* 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)) {
+                       DEBUG(3, ("do_drv_upgrade_printer: "
+                                 "Failed to update changeid [%s]\n",
+                                 win_errstr(result)));
                }
        }
 
        /* all done */
+done:
+       talloc_free(tmp_ctx);
 }
 
 /********************************************************************
@@ -1361,7 +1414,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;
@@ -1429,7 +1482,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;
@@ -1445,6 +1498,8 @@ WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
        DEBUGADD(3,("checking name: %s\n", r->in.printername));
 
        if (!open_printer_hnd(p, r->out.handle, r->in.printername, 0)) {
+               DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
+                       " for printer %s\n", r->in.printername));
                ZERO_STRUCTP(r->out.handle);
                return WERR_INVALID_PARAM;
        }
@@ -1616,6 +1671,12 @@ WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
                DEBUG(4,("Setting printer access = %s\n", (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
                        ? "PRINTER_ACCESS_ADMINISTER" : "PRINTER_ACCESS_USE" ));
 
+               winreg_create_printer(p->mem_ctx,
+                                     p->server_info,
+                                     p->msg_ctx,
+                                     Printer->servername,
+                                     lp_const_servicename(snum));
+
                break;
 
        default:
@@ -1652,78 +1713,11 @@ WERROR _spoolss_OpenPrinterEx(pipes_struct *p,
        return WERR_OK;
 }
 
-/****************************************************************************
-****************************************************************************/
-
-static bool printer_info2_to_nt_printer_info2(struct spoolss_SetPrinterInfo2 *r,
-                                             NT_PRINTER_INFO_LEVEL_2 *d)
-{
-       DEBUG(7,("printer_info2_to_nt_printer_info2\n"));
-
-       if (!r || !d) {
-               return false;
-       }
-
-       d->attributes           = r->attributes;
-       d->priority             = r->priority;
-       d->default_priority     = r->defaultpriority;
-       d->starttime            = r->starttime;
-       d->untiltime            = r->untiltime;
-       d->status               = r->status;
-       d->cjobs                = r->cjobs;
-
-       fstrcpy(d->servername,  r->servername);
-       fstrcpy(d->printername, r->printername);
-       fstrcpy(d->sharename,   r->sharename);
-       fstrcpy(d->portname,    r->portname);
-       fstrcpy(d->drivername,  r->drivername);
-       slprintf(d->comment, sizeof(d->comment)-1, "%s", r->comment);
-       fstrcpy(d->location,    r->location);
-       fstrcpy(d->sepfile,     r->sepfile);
-       fstrcpy(d->printprocessor, r->printprocessor);
-       fstrcpy(d->datatype,    r->datatype);
-       fstrcpy(d->parameters,  r->parameters);
-
-       return true;
-}
-
-/****************************************************************************
-****************************************************************************/
-
-static bool convert_printer_info(struct spoolss_SetPrinterInfoCtr *info_ctr,
-                                NT_PRINTER_INFO_LEVEL *printer)
-{
-       bool ret;
-
-       switch (info_ctr->level) {
-       case 2:
-               /* allocate memory if needed.  Messy because
-                  convert_printer_info is used to update an existing
-                  printer or build a new one */
-
-               if (!printer->info_2) {
-                       printer->info_2 = TALLOC_ZERO_P(printer, NT_PRINTER_INFO_LEVEL_2);
-                       if (!printer->info_2) {
-                               DEBUG(0,("convert_printer_info: "
-                                       "talloc() failed!\n"));
-                               return false;
-                       }
-               }
-
-               ret = printer_info2_to_nt_printer_info2(info_ctr->info.info2,
-                                                       printer->info_2);
-               printer->info_2->setuptime = time(NULL);
-               return ret;
-       }
-
-       return false;
-}
-
 /****************************************************************
  _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);
@@ -1753,11 +1747,12 @@ 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);
        WERROR result;
+       int snum;
 
        if (Printer && Printer->document_started) {
                struct spoolss_EndDocPrinter e;
@@ -1767,9 +1762,15 @@ WERROR _spoolss_DeletePrinter(pipes_struct *p,
                _spoolss_EndDocPrinter(p, &e);
        }
 
-       result = delete_printer_handle(p, r->in.handle);
+       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),
+                                         "");
+       }
 
-       update_c_setprinter(false);
+       result = delete_printer_handle(p, r->in.handle);
 
        return result;
 }
@@ -1808,7 +1809,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)
 {
 
@@ -1816,7 +1817,6 @@ WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
        struct spoolss_DriverInfo8 *info_win2k = NULL;
        int                             version;
        WERROR                          status;
-       WERROR                          status_win2k = WERR_ACCESS_DENIED;
        SE_PRIV                         se_printop = SE_PRINT_OPERATOR;
 
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
@@ -1839,19 +1839,20 @@ WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
        if ((version = get_version_id(r->in.architecture)) == -1)
                return WERR_INVALID_ENVIRONMENT;
 
-       if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
-                                               r->in.architecture,
-                                               version)))
-       {
+       status = winreg_get_driver(p->mem_ctx, p->server_info,
+                                  r->in.architecture, r->in.driver,
+                                  version, &info);
+       if (!W_ERROR_IS_OK(status)) {
                /* try for Win2k driver if "Windows NT x86" */
 
                if ( version == 2 ) {
                        version = 3;
-                       if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx,
-                                                               &info,
-                                                               r->in.driver,
-                                                               r->in.architecture,
-                                                               version))) {
+
+                       status = winreg_get_driver(p->mem_ctx, p->server_info,
+                                                  r->in.architecture,
+                                                  r->in.driver,
+                                                  version, &info);
+                       if (!W_ERROR_IS_OK(status)) {
                                status = WERR_UNKNOWN_PRINTER_DRIVER;
                                goto done;
                        }
@@ -1864,43 +1865,35 @@ WERROR _spoolss_DeletePrinterDriver(pipes_struct *p,
 
        }
 
-       if (printer_driver_in_use(info)) {
+       if (printer_driver_in_use(p->mem_ctx, p->server_info, info)) {
                status = WERR_PRINTER_DRIVER_IN_USE;
                goto done;
        }
 
-       if ( version == 2 )
-       {
-               if (W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx,
-                                                      &info_win2k,
-                                                      r->in.driver,
-                                                      r->in.architecture, 3)))
-               {
+       if (version == 2) {
+               status = winreg_get_driver(p->mem_ctx, p->server_info,
+                                          r->in.architecture,
+                                          r->in.driver, 3, &info_win2k);
+               if (W_ERROR_IS_OK(status)) {
                        /* if we get to here, we now have 2 driver info structures to remove */
                        /* remove the Win2k driver first*/
 
-                       status_win2k = delete_printer_driver(
-                               p, info_win2k, 3, false);
-                       free_a_printer_driver(info_win2k);
+                       status = winreg_del_driver(p->mem_ctx,
+                                                  p->server_info,
+                                                  info_win2k, 3);
+                       talloc_free(info_win2k);
 
                        /* this should not have failed---if it did, report to client */
-                       if ( !W_ERROR_IS_OK(status_win2k) )
-                       {
-                               status = status_win2k;
+                       if (!W_ERROR_IS_OK(status)) {
                                goto done;
                        }
                }
        }
 
-       status = delete_printer_driver(p, info, version, false);
-
-       /* if at least one of the deletes succeeded return OK */
-
-       if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
-               status = WERR_OK;
+       status = winreg_del_driver(p->mem_ctx, p->server_info, info, version);
 
 done:
-       free_a_printer_driver(info);
+       talloc_free(info);
 
        return status;
 }
@@ -1909,7 +1902,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;
@@ -1917,7 +1910,6 @@ WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
        int                             version;
        bool                            delete_files;
        WERROR                          status;
-       WERROR                          status_win2k = WERR_ACCESS_DENIED;
        SE_PRIV                         se_printop = SE_PRINT_OPERATOR;
 
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
@@ -1943,11 +1935,12 @@ WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
        if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
                version = r->in.version;
 
-       status = get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
-                                     r->in.architecture, version);
+       status = winreg_get_driver(p->mem_ctx, p->server_info,
+                                  r->in.architecture, r->in.driver,
+                                  version, &info);
+       if (!W_ERROR_IS_OK(status)) {
+               status = WERR_UNKNOWN_PRINTER_DRIVER;
 
-       if ( !W_ERROR_IS_OK(status) )
-       {
                /*
                 * if the client asked for a specific version,
                 * or this is something other than Windows NT x86,
@@ -1960,15 +1953,17 @@ WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
                /* try for Win2k driver if "Windows NT x86" */
 
                version = 3;
-               if (!W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info, r->in.driver,
-                                                       r->in.architecture,
-                                                       version))) {
+               status = winreg_get_driver(info, p->server_info,
+                                          r->in.architecture,
+                                          r->in.driver,
+                                          version, &info);
+               if (!W_ERROR_IS_OK(status)) {
                        status = WERR_UNKNOWN_PRINTER_DRIVER;
                        goto done;
                }
        }
 
-       if (printer_driver_in_use(info)) {
+       if (printer_driver_in_use(info, p->server_info, info)) {
                status = WERR_PRINTER_DRIVER_IN_USE;
                goto done;
        }
@@ -1989,7 +1984,9 @@ WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
 
        /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
 
-       if (delete_files && printer_driver_files_in_use(info, info) & (r->in.delete_flags & DPD_DELETE_ALL_FILES)) {
+       if (delete_files &&
+           (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
+           printer_driver_files_in_use(info, p->server_info, info)) {
                /* no idea of the correct error here */
                status = WERR_ACCESS_DENIED;
                goto done;
@@ -1999,14 +1996,17 @@ 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)  ) {
-               if (W_ERROR_IS_OK(get_a_printer_driver(p->mem_ctx, &info_win2k,
-                                                      r->in.driver,
-                                                      r->in.architecture, 3)))
-               {
-
-                       if (delete_files && printer_driver_files_in_use(info, info_win2k) & (r->in.delete_flags & DPD_DELETE_ALL_FILES) ) {
+               status = winreg_get_driver(info, p->server_info,
+                                          r->in.architecture,
+                                          r->in.driver, 3, &info_win2k);
+               if (W_ERROR_IS_OK(status)) {
+
+                       if (delete_files &&
+                           (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
+                           printer_driver_files_in_use(info, p->server_info,
+                                                       info_win2k)) {
                                /* no idea of the correct error here */
-                               free_a_printer_driver(info_win2k);
+                               talloc_free(info_win2k);
                                status = WERR_ACCESS_DENIED;
                                goto done;
                        }
@@ -2014,50 +2014,47 @@ WERROR _spoolss_DeletePrinterDriverEx(pipes_struct *p,
                        /* if we get to here, we now have 2 driver info structures to remove */
                        /* remove the Win2k driver first*/
 
-                       status_win2k = delete_printer_driver(
-                               p, info_win2k, 3, delete_files);
-                       free_a_printer_driver(info_win2k);
+                       status = winreg_del_driver(info, p->server_info,
+                                                  info_win2k, 3);
 
                        /* this should not have failed---if it did, report to client */
 
-                       if ( !W_ERROR_IS_OK(status_win2k) )
+                       if (!W_ERROR_IS_OK(status)) {
                                goto done;
+                       }
+
+                       /*
+                        * now delete any associated files if delete_files is
+                        * true. Even if this part failes, we return succes
+                        * because the driver doesn not exist any more
+                        */
+                       if (delete_files) {
+                               delete_driver_files(p->server_info,
+                                                   info_win2k);
+                       }
                }
        }
 
-       status = delete_printer_driver(p, info, version, delete_files);
+       status = winreg_del_driver(info, p->server_info, info, version);
+       if (!W_ERROR_IS_OK(status)) {
+               goto done;
+       }
 
-       if ( W_ERROR_IS_OK(status) || W_ERROR_IS_OK(status_win2k) )
-               status = WERR_OK;
-done:
-       free_a_printer_driver(info);
+       /*
+        * now delete any associated files if delete_files is
+        * true. Even if this part failes, we return succes
+        * because the driver doesn not exist any more
+        */
+       if (delete_files) {
+               delete_driver_files(p->server_info, info);
+       }
 
+done:
+       talloc_free(info);
        return status;
 }
 
 
-/****************************************************************************
- Internal routine for removing printerdata
- ***************************************************************************/
-
-static WERROR delete_printer_dataex( NT_PRINTER_INFO_LEVEL *printer, const char *key, const char *value )
-{
-       return delete_printer_data( printer->info_2, key, value );
-}
-
-/****************************************************************************
- Internal routine for storing printerdata
- ***************************************************************************/
-
-WERROR set_printer_dataex(NT_PRINTER_INFO_LEVEL *printer,
-                         const char *key, const char *value,
-                         uint32_t type, uint8_t *data, int real_len)
-{
-       /* the registry objects enforce uniqueness based on value name */
-
-       return add_printer_data( printer->info_2, key, value, type, data, real_len );
-}
-
 /********************************************************************
  GetPrinterData on a printer server Handle.
 ********************************************************************/
@@ -2202,7 +2199,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;
@@ -2245,7 +2242,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;
@@ -2294,7 +2291,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;
@@ -2311,14 +2309,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);
        }
 
        /*
@@ -2407,7 +2403,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;
@@ -2428,6 +2424,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);
@@ -2452,7 +2449,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;
@@ -2467,10 +2465,10 @@ WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(pipes_struct *p,
 static void spoolss_notify_server_name(int snum,
                                       struct spoolss_Notify *data,
                                       print_queue_struct *queue,
-                                      NT_PRINTER_INFO_LEVEL *printer,
+                                      struct spoolss_PrinterInfo2 *pinfo2,
                                       TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->servername);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->servername);
 }
 
 /*******************************************************************
@@ -2480,14 +2478,14 @@ static void spoolss_notify_server_name(int snum,
 static void spoolss_notify_printer_name(int snum,
                                        struct spoolss_Notify *data,
                                        print_queue_struct *queue,
-                                       NT_PRINTER_INFO_LEVEL *printer,
+                                       struct spoolss_PrinterInfo2 *pinfo2,
                                        TALLOC_CTX *mem_ctx)
 {
        /* the notify name should not contain the \\server\ part */
-       char *p = strrchr(printer->info_2->printername, '\\');
+       const char *p = strrchr(pinfo2->printername, '\\');
 
        if (!p) {
-               p = printer->info_2->printername;
+               p = pinfo2->printername;
        } else {
                p++;
        }
@@ -2502,7 +2500,7 @@ static void spoolss_notify_printer_name(int snum,
 static void spoolss_notify_share_name(int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
-                                     NT_PRINTER_INFO_LEVEL *printer,
+                                     struct spoolss_PrinterInfo2 *pinfo2,
                                      TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
@@ -2515,10 +2513,10 @@ static void spoolss_notify_share_name(int snum,
 static void spoolss_notify_port_name(int snum,
                                     struct spoolss_Notify *data,
                                     print_queue_struct *queue,
-                                    NT_PRINTER_INFO_LEVEL *printer,
+                                    struct spoolss_PrinterInfo2 *pinfo2,
                                     TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->portname);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->portname);
 }
 
 /*******************************************************************
@@ -2529,10 +2527,10 @@ static void spoolss_notify_port_name(int snum,
 static void spoolss_notify_driver_name(int snum,
                                       struct spoolss_Notify *data,
                                       print_queue_struct *queue,
-                                      NT_PRINTER_INFO_LEVEL *printer,
+                                      struct spoolss_PrinterInfo2 *pinfo2,
                                       TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->drivername);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->drivername);
 }
 
 /*******************************************************************
@@ -2542,18 +2540,18 @@ static void spoolss_notify_driver_name(int snum,
 static void spoolss_notify_comment(int snum,
                                   struct spoolss_Notify *data,
                                   print_queue_struct *queue,
-                                  NT_PRINTER_INFO_LEVEL *printer,
+                                  struct spoolss_PrinterInfo2 *pinfo2,
                                   TALLOC_CTX *mem_ctx)
 {
-       char *p;
+       const char *p;
 
-       if (*printer->info_2->comment == '\0') {
+       if (*pinfo2->comment == '\0') {
                p = lp_comment(snum);
        } else {
-               p = printer->info_2->comment;
+               p = pinfo2->comment;
        }
 
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->comment);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, p);
 }
 
 /*******************************************************************
@@ -2564,10 +2562,10 @@ static void spoolss_notify_comment(int snum,
 static void spoolss_notify_location(int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
-                                   NT_PRINTER_INFO_LEVEL *printer,
+                                   struct spoolss_PrinterInfo2 *pinfo2,
                                    TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->location);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->location);
 }
 
 /*******************************************************************
@@ -2578,7 +2576,7 @@ static void spoolss_notify_location(int snum,
 static void spoolss_notify_devmode(int snum,
                                   struct spoolss_Notify *data,
                                   print_queue_struct *queue,
-                                  NT_PRINTER_INFO_LEVEL *printer,
+                                  struct spoolss_PrinterInfo2 *pinfo2,
                                   TALLOC_CTX *mem_ctx)
 {
        /* for a dummy implementation we have to zero the fields */
@@ -2592,10 +2590,10 @@ static void spoolss_notify_devmode(int snum,
 static void spoolss_notify_sepfile(int snum,
                                   struct spoolss_Notify *data,
                                   print_queue_struct *queue,
-                                  NT_PRINTER_INFO_LEVEL *printer,
+                                  struct spoolss_PrinterInfo2 *pinfo2,
                                   TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->sepfile);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->sepfile);
 }
 
 /*******************************************************************
@@ -2606,10 +2604,10 @@ static void spoolss_notify_sepfile(int snum,
 static void spoolss_notify_print_processor(int snum,
                                           struct spoolss_Notify *data,
                                           print_queue_struct *queue,
-                                          NT_PRINTER_INFO_LEVEL *printer,
+                                          struct spoolss_PrinterInfo2 *pinfo2,
                                           TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->printprocessor);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->printprocessor);
 }
 
 /*******************************************************************
@@ -2620,10 +2618,10 @@ static void spoolss_notify_print_processor(int snum,
 static void spoolss_notify_parameters(int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
-                                     NT_PRINTER_INFO_LEVEL *printer,
+                                     struct spoolss_PrinterInfo2 *pinfo2,
                                      TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->parameters);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->parameters);
 }
 
 /*******************************************************************
@@ -2634,10 +2632,10 @@ static void spoolss_notify_parameters(int snum,
 static void spoolss_notify_datatype(int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
-                                   NT_PRINTER_INFO_LEVEL *printer,
+                                   struct spoolss_PrinterInfo2 *pinfo2,
                                    TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, printer->info_2->datatype);
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, pinfo2->datatype);
 }
 
 /*******************************************************************
@@ -2649,12 +2647,10 @@ static void spoolss_notify_datatype(int snum,
 static void spoolss_notify_security_desc(int snum,
                                         struct spoolss_Notify *data,
                                         print_queue_struct *queue,
-                                        NT_PRINTER_INFO_LEVEL *printer,
+                                        struct spoolss_PrinterInfo2 *pinfo2,
                                         TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data,
-                                         printer->info_2->secdesc_buf->sd_size,
-                                         printer->info_2->secdesc_buf->sd);
+       SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
 }
 
 /*******************************************************************
@@ -2665,10 +2661,10 @@ static void spoolss_notify_security_desc(int snum,
 static void spoolss_notify_attributes(int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
-                                     NT_PRINTER_INFO_LEVEL *printer,
+                                     struct spoolss_PrinterInfo2 *pinfo2,
                                      TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->attributes);
+       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->attributes);
 }
 
 /*******************************************************************
@@ -2678,10 +2674,10 @@ static void spoolss_notify_attributes(int snum,
 static void spoolss_notify_priority(int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
-                                   NT_PRINTER_INFO_LEVEL *printer,
+                                   struct spoolss_PrinterInfo2 *pinfo2,
                                    TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->priority);
+       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->priority);
 }
 
 /*******************************************************************
@@ -2691,10 +2687,10 @@ static void spoolss_notify_priority(int snum,
 static void spoolss_notify_default_priority(int snum,
                                            struct spoolss_Notify *data,
                                            print_queue_struct *queue,
-                                           NT_PRINTER_INFO_LEVEL *printer,
+                                           struct spoolss_PrinterInfo2 *pinfo2,
                                            TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->default_priority);
+       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->defaultpriority);
 }
 
 /*******************************************************************
@@ -2704,10 +2700,10 @@ static void spoolss_notify_default_priority(int snum,
 static void spoolss_notify_start_time(int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
-                                     NT_PRINTER_INFO_LEVEL *printer,
+                                     struct spoolss_PrinterInfo2 *pinfo2,
                                      TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->starttime);
+       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->starttime);
 }
 
 /*******************************************************************
@@ -2717,10 +2713,10 @@ static void spoolss_notify_start_time(int snum,
 static void spoolss_notify_until_time(int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
-                                     NT_PRINTER_INFO_LEVEL *printer,
+                                     struct spoolss_PrinterInfo2 *pinfo2,
                                      TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->untiltime);
+       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->untiltime);
 }
 
 /*******************************************************************
@@ -2730,7 +2726,7 @@ static void spoolss_notify_until_time(int snum,
 static void spoolss_notify_status(int snum,
                                  struct spoolss_Notify *data,
                                  print_queue_struct *queue,
-                                 NT_PRINTER_INFO_LEVEL *printer,
+                                 struct spoolss_PrinterInfo2 *pinfo2,
                                  TALLOC_CTX *mem_ctx)
 {
        print_status_struct status;
@@ -2746,7 +2742,7 @@ static void spoolss_notify_status(int snum,
 static void spoolss_notify_cjobs(int snum,
                                 struct spoolss_Notify *data,
                                 print_queue_struct *queue,
-                                NT_PRINTER_INFO_LEVEL *printer,
+                                struct spoolss_PrinterInfo2 *pinfo2,
                                 TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, print_queue_length(snum, NULL));
@@ -2759,12 +2755,12 @@ static void spoolss_notify_cjobs(int snum,
 static void spoolss_notify_average_ppm(int snum,
                                       struct spoolss_Notify *data,
                                       print_queue_struct *queue,
-                                      NT_PRINTER_INFO_LEVEL *printer,
+                                      struct spoolss_PrinterInfo2 *pinfo2,
                                       TALLOC_CTX *mem_ctx)
 {
        /* always respond 8 pages per minutes */
        /* a little hard ! */
-       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, printer->info_2->averageppm);
+       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, pinfo2->averageppm);
 }
 
 /*******************************************************************
@@ -2774,7 +2770,7 @@ static void spoolss_notify_average_ppm(int snum,
 static void spoolss_notify_username(int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
-                                   NT_PRINTER_INFO_LEVEL *printer,
+                                   struct spoolss_PrinterInfo2 *pinfo2,
                                    TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_user);
@@ -2787,7 +2783,7 @@ static void spoolss_notify_username(int snum,
 static void spoolss_notify_job_status(int snum,
                                      struct spoolss_Notify *data,
                                      print_queue_struct *queue,
-                                     NT_PRINTER_INFO_LEVEL *printer,
+                                     struct spoolss_PrinterInfo2 *pinfo2,
                                      TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, nt_printj_status(queue->status));
@@ -2800,7 +2796,7 @@ static void spoolss_notify_job_status(int snum,
 static void spoolss_notify_job_name(int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
-                                   NT_PRINTER_INFO_LEVEL *printer,
+                                   struct spoolss_PrinterInfo2 *pinfo2,
                                    TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, queue->fs_file);
@@ -2813,7 +2809,7 @@ static void spoolss_notify_job_name(int snum,
 static void spoolss_notify_job_status_string(int snum,
                                             struct spoolss_Notify *data,
                                             print_queue_struct *queue,
-                                            NT_PRINTER_INFO_LEVEL *printer,
+                                            struct spoolss_PrinterInfo2 *pinfo2,
                                             TALLOC_CTX *mem_ctx)
 {
        /*
@@ -2851,7 +2847,7 @@ static void spoolss_notify_job_status_string(int snum,
 static void spoolss_notify_job_time(int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
-                                   NT_PRINTER_INFO_LEVEL *printer,
+                                   struct spoolss_PrinterInfo2 *pinfo2,
                                    TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, 0);
@@ -2864,7 +2860,7 @@ static void spoolss_notify_job_time(int snum,
 static void spoolss_notify_job_size(int snum,
                                    struct spoolss_Notify *data,
                                    print_queue_struct *queue,
-                                   NT_PRINTER_INFO_LEVEL *printer,
+                                   struct spoolss_PrinterInfo2 *pinfo2,
                                    TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->size);
@@ -2876,7 +2872,7 @@ static void spoolss_notify_job_size(int snum,
 static void spoolss_notify_total_pages(int snum,
                                struct spoolss_Notify *data,
                                print_queue_struct *queue,
-                               NT_PRINTER_INFO_LEVEL *printer,
+                               struct spoolss_PrinterInfo2 *pinfo2,
                                TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->page_count);
@@ -2888,7 +2884,7 @@ static void spoolss_notify_total_pages(int snum,
 static void spoolss_notify_pages_printed(int snum,
                                struct spoolss_Notify *data,
                                print_queue_struct *queue,
-                               NT_PRINTER_INFO_LEVEL *printer,
+                               struct spoolss_PrinterInfo2 *pinfo2,
                                TALLOC_CTX *mem_ctx)
 {
        /* Add code when back-end tracks this */
@@ -2902,7 +2898,7 @@ static void spoolss_notify_pages_printed(int snum,
 static void spoolss_notify_job_position(int snum,
                                        struct spoolss_Notify *data,
                                        print_queue_struct *queue,
-                                       NT_PRINTER_INFO_LEVEL *printer,
+                                       struct spoolss_PrinterInfo2 *pinfo2,
                                        TALLOC_CTX *mem_ctx)
 {
        SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
@@ -2915,7 +2911,7 @@ static void spoolss_notify_job_position(int snum,
 static void spoolss_notify_submitted_time(int snum,
                                          struct spoolss_Notify *data,
                                          print_queue_struct *queue,
-                                         NT_PRINTER_INFO_LEVEL *printer,
+                                         struct spoolss_PrinterInfo2 *pinfo2,
                                          TALLOC_CTX *mem_ctx)
 {
        data->data.string.string = NULL;
@@ -2935,7 +2931,8 @@ struct s_notify_info_data_table
        enum spoolss_NotifyTable variable_type;
        void (*fn) (int snum, struct spoolss_Notify *data,
                    print_queue_struct *queue,
-                   NT_PRINTER_INFO_LEVEL *printer, TALLOC_CTX *mem_ctx);
+                   struct spoolss_PrinterInfo2 *pinfo2,
+                   TALLOC_CTX *mem_ctx);
 };
 
 /* A table describing the various print notification constants and
@@ -3040,10 +3037,9 @@ static bool search_notify(enum spoolss_NotifyType type,
 /****************************************************************************
 ****************************************************************************/
 
-void construct_info_data(struct spoolss_Notify *info_data,
-                        enum spoolss_NotifyType type,
-                        uint16_t field,
-                        int id)
+static void construct_info_data(struct spoolss_Notify *info_data,
+                               enum spoolss_NotifyType type,
+                               uint16_t field, int id)
 {
        info_data->type                 = type;
        info_data->field.field          = field;
@@ -3059,6 +3055,7 @@ void construct_info_data(struct spoolss_Notify *info_data,
 
 static bool construct_notify_printer_info(Printer_entry *print_hnd,
                                          struct spoolss_NotifyInfo *info,
+                                         struct spoolss_PrinterInfo2 *pinfo2,
                                          int snum,
                                          const struct spoolss_NotifyOptionType *option_type,
                                          uint32_t id,
@@ -3069,7 +3066,6 @@ static bool construct_notify_printer_info(Printer_entry *print_hnd,
        uint16_t field;
 
        struct spoolss_Notify *current_data;
-       NT_PRINTER_INFO_LEVEL *printer = NULL;
        print_queue_struct *queue=NULL;
 
        type = option_type->type;
@@ -3078,9 +3074,6 @@ static bool construct_notify_printer_info(Printer_entry *print_hnd,
                (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
                option_type->count, lp_servicename(snum)));
 
-       if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &printer, 2, lp_const_servicename(snum))))
-               return false;
-
        for(field_num=0; field_num < option_type->count; field_num++) {
                field = option_type->fields[field_num].field;
 
@@ -3094,7 +3087,6 @@ static bool construct_notify_printer_info(Printer_entry *print_hnd,
                                                      info->count + 1);
                if (info->notifies == NULL) {
                        DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
-                       free_a_printer(&printer, 2);
                        return false;
                }
 
@@ -3102,16 +3094,17 @@ static bool construct_notify_printer_info(Printer_entry *print_hnd,
 
                construct_info_data(current_data, type, field, id);
 
-               DEBUG(10,("construct_notify_printer_info: calling [%s]  snum=%d  printername=[%s])\n",
-                               notify_info_data_table[j].name, snum, printer->info_2->printername ));
+               DEBUG(10, ("construct_notify_printer_info: "
+                          "calling [%s]  snum=%d  printername=[%s])\n",
+                          notify_info_data_table[j].name, snum,
+                          pinfo2->printername));
 
                notify_info_data_table[j].fn(snum, current_data, queue,
-                                            printer, mem_ctx);
+                                            pinfo2, mem_ctx);
 
                info->count++;
        }
 
-       free_a_printer(&printer, 2);
        return true;
 }
 
@@ -3123,7 +3116,7 @@ static bool construct_notify_printer_info(Printer_entry *print_hnd,
 
 static bool construct_notify_jobs_info(print_queue_struct *queue,
                                       struct spoolss_NotifyInfo *info,
-                                      NT_PRINTER_INFO_LEVEL *printer,
+                                      struct spoolss_PrinterInfo2 *pinfo2,
                                       int snum,
                                       const struct spoolss_NotifyOptionType *option_type,
                                       uint32_t id,
@@ -3160,7 +3153,7 @@ static bool construct_notify_jobs_info(print_queue_struct *queue,
 
                construct_info_data(current_data, type, field, id);
                notify_info_data_table[j].fn(snum, current_data, queue,
-                                            printer, mem_ctx);
+                                            pinfo2, mem_ctx);
                info->count++;
        }
 
@@ -3197,7 +3190,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)
@@ -3208,6 +3201,8 @@ static WERROR printserver_notify_info(pipes_struct *p,
        int i;
        struct spoolss_NotifyOption *option;
        struct spoolss_NotifyOptionType option_type;
+       struct spoolss_PrinterInfo2 *pinfo2 = NULL;
+       WERROR result;
 
        DEBUG(4,("printserver_notify_info\n"));
 
@@ -3232,10 +3227,33 @@ static WERROR printserver_notify_info(pipes_struct *p,
                if (option_type.type != PRINTER_NOTIFY_TYPE)
                        continue;
 
-               for (snum=0; snum<n_services; snum++)
-               {
-                       if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
-                               construct_notify_printer_info ( Printer, info, snum, &option_type, snum, mem_ctx );
+               for (snum = 0; snum < n_services; snum++) {
+                       if (!lp_browseable(snum) ||
+                           !lp_snum_ok(snum) ||
+                           !lp_print_ok(snum)) {
+                               continue; /* skip */
+                       }
+
+                       /* 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)) {
+                               DEBUG(4, ("printserver_notify_info: "
+                                         "Failed to get printer [%s]\n",
+                                         lp_servicename(snum)));
+                               continue;
+                       }
+
+
+                       construct_notify_printer_info(Printer, info,
+                                                     pinfo2, snum,
+                                                     &option_type, snum,
+                                                     mem_ctx);
+
+                       TALLOC_FREE(pinfo2);
                }
        }
 
@@ -3264,7 +3282,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)
 {
@@ -3277,6 +3296,8 @@ static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
        int count,j;
        print_queue_struct *queue=NULL;
        print_status_struct status;
+       struct spoolss_PrinterInfo2 *pinfo2 = NULL;
+       WERROR result;
 
        DEBUG(4,("printer_notify_info\n"));
 
@@ -3298,40 +3319,42 @@ static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
 
        get_printer_snum(p, hnd, &snum, NULL);
 
+       /* Maybe we should use the SYSTEM server_info here... */
+       result = winreg_get_printer(mem_ctx, p->server_info, p->msg_ctx,
+                                   Printer->servername,
+                                   lp_servicename(snum), &pinfo2);
+       if (!W_ERROR_IS_OK(result)) {
+               return WERR_BADFID;
+       }
+
        for (i=0; i<option->count; i++) {
                option_type = option->types[i];
 
                switch (option_type.type) {
                case PRINTER_NOTIFY_TYPE:
-                       if(construct_notify_printer_info(Printer, info, snum,
-                                                        &option_type, id,
-                                                        mem_ctx))
+                       if (construct_notify_printer_info(Printer, info,
+                                                         pinfo2, snum,
+                                                         &option_type, id,
+                                                         mem_ctx)) {
                                id--;
+                       }
                        break;
 
-               case JOB_NOTIFY_TYPE: {
-                       NT_PRINTER_INFO_LEVEL *printer = NULL;
+               case JOB_NOTIFY_TYPE:
 
                        count = print_queue_status(snum, &queue, &status);
 
-                       if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))))
-                               goto done;
-
                        for (j=0; j<count; j++) {
                                construct_notify_jobs_info(&queue[j], info,
-                                                          printer, snum,
+                                                          pinfo2, snum,
                                                           &option_type,
                                                           queue[j].job,
                                                           mem_ctx);
                        }
 
-                       free_a_printer(&printer, 2);
-
-               done:
                        SAFE_FREE(queue);
                        break;
                }
-               }
        }
 
        /*
@@ -3348,6 +3371,8 @@ static WERROR printer_notify_info(pipes_struct *p, struct policy_handle *hnd,
                info->data[i].id, info->data[i].size, info->data[i].enc_type));
        }
        */
+
+       talloc_free(pinfo2);
        return WERR_OK;
 }
 
@@ -3355,7 +3380,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;
@@ -3426,19 +3451,20 @@ done:
  ********************************************************************/
 
 static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
-                                     const NT_PRINTER_INFO_LEVEL *ntprinter,
+                                     struct auth_serversupplied_info *server_info,
+                                     struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_PrinterInfo0 *r,
                                      int snum)
 {
        int count;
        counter_printer_0 *session_counter;
-       time_t setuptime;
+       struct timeval setuptime;
        print_status_struct status;
 
-       r->printername          = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
+       r->printername          = talloc_strdup(mem_ctx, info2->printername);
        W_ERROR_HAVE_NO_MEMORY(r->printername);
 
-       r->servername           = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
+       r->servername           = talloc_strdup(mem_ctx, info2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->servername);
 
        count = print_queue_length(snum, &status);
@@ -3466,9 +3492,8 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
        r->total_jobs                   = 0;
        r->total_bytes                  = 0;
 
-       setuptime = (time_t)ntprinter->info_2->setuptime;
-
-       init_systemtime(&r->time, gmtime(&setuptime));
+       get_startup_time(&setuptime);
+       init_systemtime(&r->time, gmtime(&setuptime.tv_sec));
 
        /* JFM:
         * the global_counter should be stored in a TDB as it's common to all the clients
@@ -3489,11 +3514,16 @@ 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;
-       r->change_id                    = ntprinter->info_2->changeid; /* ChangeID in milliseconds*/
+
+       /* ChangeID in milliseconds*/
+       winreg_printer_get_changeid(mem_ctx, server_info,
+                                   smbd_messaging_context(),
+                                   info2->sharename, &r->change_id);
+
        r->last_error                   = WERR_OK;
        r->status                       = nt_printq_status(status.status);
        r->enumerate_network_printers   = 0x0;
-       r->c_setprinter                 = get_c_setprinter(); /* monotonically increasing sum of delta printer counts */
+       r->c_setprinter                 = 0x0;
        r->processor_architecture       = 0x0;
        r->processor_level              = 0x6;          /* 6  ???*/
        r->ref_ic                       = 0;
@@ -3504,43 +3534,13 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
 }
 
 
-/****************************************************************************
- Create a spoolss_DeviceMode struct. Returns talloced memory.
-****************************************************************************/
-
-struct spoolss_DeviceMode *construct_dev_mode(TALLOC_CTX *mem_ctx,
-                                             const char *servicename)
-{
-       NT_PRINTER_INFO_LEVEL   *printer = NULL;
-       struct spoolss_DeviceMode *devmode = NULL;
-
-       DEBUG(7,("construct_dev_mode\n"));
-
-       DEBUGADD(8,("getting printer characteristics\n"));
-
-       if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, servicename)))
-               return NULL;
-
-       if (!printer->info_2->devmode) {
-               DEBUG(5, ("BONG! There was no device mode!\n"));
-               goto done;
-       }
-
-        devmode = talloc_steal(mem_ctx, printer->info_2->devmode);
-
-done:
-       free_a_printer(&printer,2);
-
-       return devmode;
-}
-
 /********************************************************************
  * construct_printer_info1
  * fill a spoolss_PrinterInfo1 struct
 ********************************************************************/
 
 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
-                                     const NT_PRINTER_INFO_LEVEL *ntprinter,
+                                     const struct spoolss_PrinterInfo2 *info2,
                                      uint32_t flags,
                                      struct spoolss_PrinterInfo1 *r,
                                      int snum)
@@ -3548,19 +3548,19 @@ static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
        r->flags                = flags;
 
        r->description          = talloc_asprintf(mem_ctx, "%s,%s,%s",
-                                                 ntprinter->info_2->printername,
-                                                 ntprinter->info_2->drivername,
-                                                 ntprinter->info_2->location);
+                                                 info2->printername,
+                                                 info2->drivername,
+                                                 info2->location);
        W_ERROR_HAVE_NO_MEMORY(r->description);
 
-       if (*ntprinter->info_2->comment == '\0') {
+       if (info2->comment == NULL || info2->comment[0] == '\0') {
                r->comment      = talloc_strdup(mem_ctx, lp_comment(snum));
        } else {
-               r->comment      = talloc_strdup(mem_ctx, ntprinter->info_2->comment); /* saved comment */
+               r->comment      = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
        }
        W_ERROR_HAVE_NO_MEMORY(r->comment);
 
-       r->name                 = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
+       r->name                 = talloc_strdup(mem_ctx, info2->printername);
        W_ERROR_HAVE_NO_MEMORY(r->name);
 
        return WERR_OK;
@@ -3572,67 +3572,66 @@ static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
 ********************************************************************/
 
 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
-                                     const NT_PRINTER_INFO_LEVEL *ntprinter,
+                                     const struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_PrinterInfo2 *r,
                                      int snum)
 {
        int count;
-
        print_status_struct status;
 
        count = print_queue_length(snum, &status);
 
-       r->servername           = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
+       r->servername           = talloc_strdup(mem_ctx, info2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->servername);
-       r->printername          = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
+       r->printername          = talloc_strdup(mem_ctx, info2->printername);
        W_ERROR_HAVE_NO_MEMORY(r->printername);
        r->sharename            = talloc_strdup(mem_ctx, lp_servicename(snum));
        W_ERROR_HAVE_NO_MEMORY(r->sharename);
-       r->portname             = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
+       r->portname             = talloc_strdup(mem_ctx, info2->portname);
        W_ERROR_HAVE_NO_MEMORY(r->portname);
-       r->drivername           = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
+       r->drivername           = talloc_strdup(mem_ctx, info2->drivername);
        W_ERROR_HAVE_NO_MEMORY(r->drivername);
 
-       if (*ntprinter->info_2->comment == '\0') {
+       if (info2->comment[0] == '\0') {
                r->comment      = talloc_strdup(mem_ctx, lp_comment(snum));
        } else {
-               r->comment      = talloc_strdup(mem_ctx, ntprinter->info_2->comment);
+               r->comment      = talloc_strdup(mem_ctx, info2->comment);
        }
        W_ERROR_HAVE_NO_MEMORY(r->comment);
 
-       r->location             = talloc_strdup(mem_ctx, ntprinter->info_2->location);
+       r->location             = talloc_strdup(mem_ctx, info2->location);
        W_ERROR_HAVE_NO_MEMORY(r->location);
-       r->sepfile              = talloc_strdup(mem_ctx, ntprinter->info_2->sepfile);
+       r->sepfile              = talloc_strdup(mem_ctx, info2->sepfile);
        W_ERROR_HAVE_NO_MEMORY(r->sepfile);
-       r->printprocessor       = talloc_strdup(mem_ctx, ntprinter->info_2->printprocessor);
+       r->printprocessor       = talloc_strdup(mem_ctx, info2->printprocessor);
        W_ERROR_HAVE_NO_MEMORY(r->printprocessor);
-       r->datatype             = talloc_strdup(mem_ctx, ntprinter->info_2->datatype);
+       r->datatype             = talloc_strdup(mem_ctx, info2->datatype);
        W_ERROR_HAVE_NO_MEMORY(r->datatype);
-       r->parameters           = talloc_strdup(mem_ctx, ntprinter->info_2->parameters);
+       r->parameters           = talloc_strdup(mem_ctx, info2->parameters);
        W_ERROR_HAVE_NO_MEMORY(r->parameters);
 
-       r->attributes           = ntprinter->info_2->attributes;
+       r->attributes           = info2->attributes;
 
-       r->priority             = ntprinter->info_2->priority;
-       r->defaultpriority      = ntprinter->info_2->default_priority;
-       r->starttime            = ntprinter->info_2->starttime;
-       r->untiltime            = ntprinter->info_2->untiltime;
+       r->priority             = info2->priority;
+       r->defaultpriority      = info2->defaultpriority;
+       r->starttime            = info2->starttime;
+       r->untiltime            = info2->untiltime;
        r->status               = nt_printq_status(status.status);
        r->cjobs                = count;
-       r->averageppm           = ntprinter->info_2->averageppm;
+       r->averageppm           = info2->averageppm;
 
-       r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
+       copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
        if (!r->devmode) {
                DEBUG(8,("Returning NULL Devicemode!\n"));
        }
 
-       r->secdesc              = NULL;
+       r->secdesc = NULL;
 
-       if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
+       if (info2->secdesc != NULL) {
                /* don't use talloc_steal() here unless you do a deep steal of all
                   the SEC_DESC members */
 
-               r->secdesc      = dup_sec_desc(mem_ctx, ntprinter->info_2->secdesc_buf->sd);
+               r->secdesc      = dup_sec_desc(mem_ctx, info2->secdesc);
        }
 
        return WERR_OK;
@@ -3644,18 +3643,17 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
-                                     const NT_PRINTER_INFO_LEVEL *ntprinter,
+                                     const struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_PrinterInfo3 *r,
                                      int snum)
 {
        /* These are the components of the SD we are returning. */
 
-       if (ntprinter->info_2->secdesc_buf && ntprinter->info_2->secdesc_buf->sd_size != 0) {
+       if (info2->secdesc != NULL) {
                /* don't use talloc_steal() here unless you do a deep steal of all
                   the SEC_DESC members */
 
-               r->secdesc = dup_sec_desc(mem_ctx,
-                                         ntprinter->info_2->secdesc_buf->sd);
+               r->secdesc = dup_sec_desc(mem_ctx, info2->secdesc);
                W_ERROR_HAVE_NO_MEMORY(r->secdesc);
        }
 
@@ -3668,16 +3666,16 @@ static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
-                                     const NT_PRINTER_INFO_LEVEL *ntprinter,
+                                     const struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_PrinterInfo4 *r,
                                      int snum)
 {
-       r->printername  = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
+       r->printername  = talloc_strdup(mem_ctx, info2->printername);
        W_ERROR_HAVE_NO_MEMORY(r->printername);
-       r->servername   = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
+       r->servername   = talloc_strdup(mem_ctx, info2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->servername);
 
-       r->attributes   = ntprinter->info_2->attributes;
+       r->attributes   = info2->attributes;
 
        return WERR_OK;
 }
@@ -3688,19 +3686,18 @@ static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
-                                     const NT_PRINTER_INFO_LEVEL *ntprinter,
+                                     const struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_PrinterInfo5 *r,
                                      int snum)
 {
-       r->printername  = talloc_strdup(mem_ctx, ntprinter->info_2->printername);
+       r->printername  = talloc_strdup(mem_ctx, info2->printername);
        W_ERROR_HAVE_NO_MEMORY(r->printername);
-       r->portname     = talloc_strdup(mem_ctx, ntprinter->info_2->portname);
+       r->portname     = talloc_strdup(mem_ctx, info2->portname);
        W_ERROR_HAVE_NO_MEMORY(r->portname);
 
-       r->attributes   = ntprinter->info_2->attributes;
+       r->attributes   = info2->attributes;
 
        /* these two are not used by NT+ according to MSDN */
-
        r->device_not_selected_timeout          = 0x0;  /* have seen 0x3a98 */
        r->transmission_retry_timeout           = 0x0;  /* have seen 0xafc8 */
 
@@ -3713,7 +3710,7 @@ static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
-                                     const NT_PRINTER_INFO_LEVEL *ntprinter,
+                                     const struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_PrinterInfo6 *r,
                                      int snum)
 {
@@ -3737,9 +3734,19 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
                                      struct spoolss_PrinterInfo7 *r,
                                      int snum)
 {
+       struct auth_serversupplied_info *server_info;
        struct GUID guid;
+       NTSTATUS status;
+
+       status = make_server_info_system(mem_ctx, &server_info);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("construct_printer_info7: "
+                         "Could not create system server_info\n"));
+               return WERR_NOMEM;
+       }
 
-       if (is_printer_published(print_hnd, snum, &guid)) {
+       if (is_printer_published(mem_ctx, server_info, print_hnd->servername,
+                                lp_servicename(snum), &guid, NULL)) {
                r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
                r->action = DSPRINT_PUBLISH;
        } else {
@@ -3748,6 +3755,7 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
        }
        W_ERROR_HAVE_NO_MEMORY(r->guid);
 
+       TALLOC_FREE(server_info);
        return WERR_OK;
 }
 
@@ -3757,11 +3765,11 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
-                                     const NT_PRINTER_INFO_LEVEL *ntprinter,
+                                     const struct spoolss_PrinterInfo2 *info2,
                                      struct spoolss_DeviceModeInfo *r,
                                      int snum)
 {
-       r->devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
+       copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
        if (!r->devmode) {
                DEBUG(8,("Returning NULL Devicemode!\n"));
        }
@@ -3783,6 +3791,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,
                                           uint32_t level,
                                           uint32_t flags,
                                           union spoolss_PrinterInfo **info_p,
@@ -3799,14 +3808,26 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
 
        for (snum = 0; snum < n_services; snum++) {
 
-               NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
+               const char *printer;
+               struct spoolss_PrinterInfo2 *info2;
 
                if (!snum_is_shared_printer(snum)) {
                        continue;
                }
 
+               printer = lp_const_servicename(snum);
+
                DEBUG(4,("Found a printer in smb.conf: %s[%x]\n",
-                       lp_servicename(snum), snum));
+                       printer, snum));
+
+               result = winreg_create_printer(mem_ctx,
+                                              server_info,
+                                              smbd_messaging_context(),
+                                              NULL,
+                                              printer);
+               if (!W_ERROR_IS_OK(result)) {
+                       goto out;
+               }
 
                info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
                                            union spoolss_PrinterInfo,
@@ -3816,41 +3837,40 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                        goto out;
                }
 
-               result = get_a_printer(NULL, &ntprinter, 2,
-                                      lp_const_servicename(snum));
+               result = winreg_get_printer(mem_ctx, server_info,
+                                           smbd_messaging_context(),
+                                           NULL, printer, &info2);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
                }
 
                switch (level) {
                case 0:
-                       result = construct_printer_info0(info, ntprinter,
+                       result = construct_printer_info0(info, server_info, info2,
                                                         &info[count].info0, snum);
                        break;
                case 1:
-                       result = construct_printer_info1(info, ntprinter, flags,
+                       result = construct_printer_info1(info, info2, flags,
                                                         &info[count].info1, snum);
                        break;
                case 2:
-                       result = construct_printer_info2(info, ntprinter,
+                       result = construct_printer_info2(info, info2,
                                                         &info[count].info2, snum);
                        break;
                case 4:
-                       result = construct_printer_info4(info, ntprinter,
+                       result = construct_printer_info4(info, info2,
                                                         &info[count].info4, snum);
                        break;
                case 5:
-                       result = construct_printer_info5(info, ntprinter,
+                       result = construct_printer_info5(info, info2,
                                                         &info[count].info5, snum);
                        break;
 
                default:
                        result = WERR_UNKNOWN_LEVEL;
-                       free_a_printer(&ntprinter, 2);
                        goto out;
                }
 
-               free_a_printer(&ntprinter, 2);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
                }
@@ -3877,6 +3897,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,
                                  uint32_t flags,
                                  const char *servername,
                                  union spoolss_PrinterInfo **info,
@@ -3884,7 +3905,7 @@ static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
 {
        DEBUG(4,("enum_all_printers_info_0\n"));
 
-       return enum_all_printers_info_level(mem_ctx, 0, flags, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, 0, flags, info, count);
 }
 
 
@@ -3892,13 +3913,14 @@ 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,
                                       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, 1, flags, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, 1, flags, info, count);
 }
 
 /********************************************************************
@@ -3906,12 +3928,13 @@ 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,
                                             union spoolss_PrinterInfo **info,
                                             uint32_t *count)
 {
        DEBUG(4,("enum_all_printers_info_1_local\n"));
 
-       return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
+       return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
 }
 
 /********************************************************************
@@ -3919,6 +3942,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,
                                            const char *name,
                                            union spoolss_PrinterInfo **info,
                                            uint32_t *count)
@@ -3935,7 +3959,7 @@ static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
                return WERR_INVALID_NAME;
        }
 
-       return enum_all_printers_info_1(mem_ctx, PRINTER_ENUM_ICON8, info, count);
+       return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_ICON8, info, count);
 }
 
 /********************************************************************
@@ -3943,6 +3967,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,
                                               const char *name,
                                               union spoolss_PrinterInfo **info,
                                               uint32_t *count)
@@ -3967,7 +3992,7 @@ 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, PRINTER_ENUM_NAME, info, count);
+       return enum_all_printers_info_1(mem_ctx, server_info, PRINTER_ENUM_NAME, info, count);
 }
 
 /********************************************************************
@@ -3977,12 +4002,13 @@ 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,
                                       union spoolss_PrinterInfo **info,
                                       uint32_t *count)
 {
        DEBUG(4,("enum_all_printers_info_2\n"));
 
-       return enum_all_printers_info_level(mem_ctx, 2, 0, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, 2, 0, info, count);
 }
 
 /********************************************************************
@@ -3990,6 +4016,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,
                                  uint32_t flags,
                                  const char *name,
                                  union spoolss_PrinterInfo **info,
@@ -3998,15 +4025,15 @@ 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, info, count);
+               return enum_all_printers_info_1_local(mem_ctx, server_info, info, count);
        }
 
        if (flags & PRINTER_ENUM_NAME) {
-               return enum_all_printers_info_1_name(mem_ctx, name, info, count);
+               return enum_all_printers_info_1_name(mem_ctx, server_info, name, info, count);
        }
 
        if (flags & PRINTER_ENUM_NETWORK) {
-               return enum_all_printers_info_1_network(mem_ctx, name, info, count);
+               return enum_all_printers_info_1_network(mem_ctx, server_info, name, info, count);
        }
 
        return WERR_OK; /* NT4sp5 does that */
@@ -4017,13 +4044,14 @@ static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
+                                 struct auth_serversupplied_info *server_info,
                                  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, info, count);
+               return enum_all_printers_info_2(mem_ctx, server_info, info, count);
        }
 
        if (flags & PRINTER_ENUM_NAME) {
@@ -4031,7 +4059,7 @@ static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
                        return WERR_INVALID_NAME;
                }
 
-               return enum_all_printers_info_2(mem_ctx, info, count);
+               return enum_all_printers_info_2(mem_ctx, server_info, info, count);
        }
 
        if (flags & PRINTER_ENUM_REMOTE) {
@@ -4046,6 +4074,7 @@ static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
+                                 struct auth_serversupplied_info *server_info,
                                  uint32_t flags,
                                  const char *servername,
                                  union spoolss_PrinterInfo **info,
@@ -4053,7 +4082,7 @@ static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
 {
        DEBUG(4,("enum_all_printers_info_4\n"));
 
-       return enum_all_printers_info_level(mem_ctx, 4, flags, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, 4, flags, info, count);
 }
 
 
@@ -4062,6 +4091,7 @@ static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
+                                 struct auth_serversupplied_info *server_info,
                                  uint32_t flags,
                                  const char *servername,
                                  union spoolss_PrinterInfo **info,
@@ -4069,14 +4099,14 @@ static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
 {
        DEBUG(4,("enum_all_printers_info_5\n"));
 
-       return enum_all_printers_info_level(mem_ctx, 5, flags, info, count);
+       return enum_all_printers_info_level(mem_ctx, server_info, 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;
@@ -4114,23 +4144,28 @@ WERROR _spoolss_EnumPrinters(pipes_struct *p,
 
        switch (r->in.level) {
        case 0:
-               result = enumprinters_level0(p->mem_ctx, r->in.flags, name,
+               result = enumprinters_level0(p->mem_ctx, p->server_info,
+                                            r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        case 1:
-               result = enumprinters_level1(p->mem_ctx, r->in.flags, name,
+               result = enumprinters_level1(p->mem_ctx, p->server_info,
+                                            r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        case 2:
-               result = enumprinters_level2(p->mem_ctx, r->in.flags, name,
+               result = enumprinters_level2(p->mem_ctx, p->server_info,
+                                            r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        case 4:
-               result = enumprinters_level4(p->mem_ctx, r->in.flags, name,
+               result = enumprinters_level4(p->mem_ctx, p->server_info,
+                                            r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        case 5:
-               result = enumprinters_level5(p->mem_ctx, r->in.flags, name,
+               result = enumprinters_level5(p->mem_ctx, p->server_info,
+                                            r->in.flags, name,
                                             r->out.info, r->out.count);
                break;
        default:
@@ -4155,13 +4190,13 @@ 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);
-       NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
+       struct spoolss_PrinterInfo2 *info2 = NULL;
        WERROR result = WERR_OK;
-
+       const char *servername = NULL;
        int snum;
 
        /* that's an [in out] buffer */
@@ -4176,40 +4211,49 @@ WERROR _spoolss_GetPrinter(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = get_a_printer(Printer, &ntprinter, 2,
-                              lp_const_servicename(snum));
+       if (Printer != NULL || Printer->servername != NULL) {
+               servername = Printer->servername;
+       }
+
+       result = winreg_get_printer(p->mem_ctx,
+                                   p->server_info,
+                                   p->msg_ctx,
+                                   servername,
+                                   lp_const_servicename(snum),
+                                   &info2);
        if (!W_ERROR_IS_OK(result)) {
                return result;
        }
 
        switch (r->in.level) {
        case 0:
-               result = construct_printer_info0(p->mem_ctx, ntprinter,
+               result = construct_printer_info0(p->mem_ctx, p->server_info,
+                                                info2,
                                                 &r->out.info->info0, snum);
                break;
        case 1:
-               result = construct_printer_info1(p->mem_ctx, ntprinter,
+               result = construct_printer_info1(p->mem_ctx, info2,
                                                 PRINTER_ENUM_ICON8,
                                                 &r->out.info->info1, snum);
                break;
        case 2:
-               result = construct_printer_info2(p->mem_ctx, ntprinter,
+               result = construct_printer_info2(p->mem_ctx, info2,
                                                 &r->out.info->info2, snum);
                break;
        case 3:
-               result = construct_printer_info3(p->mem_ctx, ntprinter,
+               result = construct_printer_info3(p->mem_ctx, info2,
                                                 &r->out.info->info3, snum);
                break;
        case 4:
-               result = construct_printer_info4(p->mem_ctx, ntprinter,
+               result = construct_printer_info4(p->mem_ctx, info2,
                                                 &r->out.info->info4, snum);
                break;
        case 5:
-               result = construct_printer_info5(p->mem_ctx, ntprinter,
+               result = construct_printer_info5(p->mem_ctx, info2,
                                                 &r->out.info->info5, snum);
                break;
        case 6:
-               result = construct_printer_info6(p->mem_ctx, ntprinter,
+               result = construct_printer_info6(p->mem_ctx, info2,
                                                 &r->out.info->info6, snum);
                break;
        case 7:
@@ -4217,7 +4261,7 @@ WERROR _spoolss_GetPrinter(pipes_struct *p,
                                                 &r->out.info->info7, snum);
                break;
        case 8:
-               result = construct_printer_info8(p->mem_ctx, ntprinter,
+               result = construct_printer_info8(p->mem_ctx, info2,
                                                 &r->out.info->info8, snum);
                break;
        default:
@@ -4225,9 +4269,9 @@ WERROR _spoolss_GetPrinter(pipes_struct *p,
                break;
        }
 
-       free_a_printer(&ntprinter, 2);
-
        if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
+                         r->in.level, win_errstr(result)));
                TALLOC_FREE(r->out.info);
                return result;
        }
@@ -4242,30 +4286,52 @@ WERROR _spoolss_GetPrinter(pipes_struct *p,
 /********************************************************************
  ********************************************************************/
 
-static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
+#define FILL_DRIVER_STRING(mem_ctx, in, out) \
+       do { \
+               if (in && strlen(in)) { \
+                       out = talloc_strdup(mem_ctx, in); \
+               } else { \
+                       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) \
+       do { \
+               if (in && strlen(in)) { \
+                       out = talloc_asprintf(mem_ctx, "\\\\%s\\print$\\%s\\%d\\%s", server, get_short_archi(arch), ver, in); \
+               } else { \
+                       out = talloc_strdup(mem_ctx, ""); \
+               } \
+               W_ERROR_HAVE_NO_MEMORY(out); \
+       } while (0);
+
+static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
                                                  const char **string_array,
-                                                 const char *cservername)
+                                                 const char ***presult,
+                                                 const char *cservername,
+                                                 const char *arch,
+                                                 int version)
 {
        int i, num_strings = 0;
        const char **array = NULL;
 
-       if (!string_array) {
-               return NULL;
+       if (string_array == NULL) {
+               return WERR_INVALID_PARAMETER;;
        }
 
        for (i=0; string_array[i] && string_array[i][0] != '\0'; i++) {
+               const char *str = NULL;
 
-               const char *str = talloc_asprintf(mem_ctx, "\\\\%s%s",
-                                                 cservername, string_array[i]);
-               if (!str) {
-                       TALLOC_FREE(array);
-                       return NULL;
+               if (cservername == NULL || arch == NULL) {
+                       FILL_DRIVER_STRING(mem_ctx, string_array[i], str);
+               } else {
+                       FILL_DRIVER_UNC_STRING(mem_ctx, cservername, arch, version, string_array[i], str);
                }
 
-
                if (!add_string_to_array(mem_ctx, str, &array, &num_strings)) {
                        TALLOC_FREE(array);
-                       return NULL;
+                       return WERR_NOMEM;
                }
        }
 
@@ -4274,28 +4340,12 @@ static const char **string_array_from_driver_info(TALLOC_CTX *mem_ctx,
                             &array, &num_strings);
        }
 
-       return array;
-}
-
-#define FILL_DRIVER_STRING(mem_ctx, in, out) \
-       do { \
-               if (in && strlen(in)) { \
-                       out = talloc_strdup(mem_ctx, in); \
-                       W_ERROR_HAVE_NO_MEMORY(out); \
-               } else { \
-                       out = NULL; \
-               } \
-       } while (0);
+       if (presult) {
+               *presult = array;
+       }
 
-#define FILL_DRIVER_UNC_STRING(mem_ctx, server, in, out) \
-       do { \
-               if (in && strlen(in)) { \
-                       out = talloc_asprintf(mem_ctx, "\\\\%s%s", server, in); \
-               } else { \
-                       out = talloc_strdup(mem_ctx, ""); \
-               } \
-               W_ERROR_HAVE_NO_MEMORY(out); \
-       } while (0);
+       return WERR_OK;
+}
 
 /********************************************************************
  * fill a spoolss_DriverInfo1 struct
@@ -4332,14 +4382,20 @@ static WERROR fill_printer_driver_info2(TALLOC_CTX *mem_ctx,
        W_ERROR_HAVE_NO_MEMORY(r->architecture);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->driver_path,
                               r->driver_path);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->data_file,
                               r->data_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->config_file,
                               r->config_file);
 
@@ -4365,18 +4421,26 @@ static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
        W_ERROR_HAVE_NO_MEMORY(r->architecture);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->driver_path,
                               r->driver_path);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->data_file,
                               r->data_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->config_file,
                               r->config_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->help_file,
                               r->help_file);
 
@@ -4388,10 +4452,12 @@ static WERROR fill_printer_driver_info3(TALLOC_CTX *mem_ctx,
                           driver->default_datatype,
                           r->default_datatype);
 
-       r->dependent_files = string_array_from_driver_info(mem_ctx,
-                                                          driver->dependent_files,
-                                                          cservername);
-       return WERR_OK;
+       return string_array_from_driver_info(mem_ctx,
+                                            driver->dependent_files,
+                                            &r->dependent_files,
+                                            cservername,
+                                            driver->architecture,
+                                            driver->version);
 }
 
 /********************************************************************
@@ -4404,6 +4470,7 @@ static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
                                        const char *servername)
 {
        const char *cservername = canon_servername(servername);
+       WERROR result;
 
        r->version              = driver->version;
 
@@ -4413,24 +4480,38 @@ static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
        W_ERROR_HAVE_NO_MEMORY(r->architecture);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->driver_path,
                               r->driver_path);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->data_file,
                               r->data_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->config_file,
                               r->config_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->help_file,
                               r->help_file);
 
-       r->dependent_files = string_array_from_driver_info(mem_ctx,
-                                                          driver->dependent_files,
-                                                          cservername);
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->dependent_files,
+                                              &r->dependent_files,
+                                              cservername,
+                                              driver->architecture,
+                                              driver->version);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
 
        FILL_DRIVER_STRING(mem_ctx,
                           driver->monitor_name,
@@ -4440,11 +4521,13 @@ static WERROR fill_printer_driver_info4(TALLOC_CTX *mem_ctx,
                           driver->default_datatype,
                           r->default_datatype);
 
-       r->previous_names = string_array_from_driver_info(mem_ctx,
-                                                         driver->previous_names,
-                                                         cservername);
 
-       return WERR_OK;
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->previous_names,
+                                              &r->previous_names,
+                                              NULL, NULL, 0);
+
+       return result;
 }
 
 /********************************************************************
@@ -4466,14 +4549,20 @@ static WERROR fill_printer_driver_info5(TALLOC_CTX *mem_ctx,
        W_ERROR_HAVE_NO_MEMORY(r->architecture);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->driver_path,
                               r->driver_path);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->data_file,
                               r->data_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->config_file,
                               r->config_file);
 
@@ -4493,6 +4582,7 @@ static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
                                        const char *servername)
 {
        const char *cservername = canon_servername(servername);
+       WERROR result;
 
        r->version              = driver->version;
 
@@ -4502,18 +4592,26 @@ static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
        W_ERROR_HAVE_NO_MEMORY(r->architecture);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->driver_path,
                               r->driver_path);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->data_file,
                               r->data_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->config_file,
                               r->config_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->help_file,
                               r->help_file);
 
@@ -4525,14 +4623,25 @@ static WERROR fill_printer_driver_info6(TALLOC_CTX *mem_ctx,
                           driver->default_datatype,
                           r->default_datatype);
 
-       r->dependent_files = string_array_from_driver_info(mem_ctx,
-                                                          driver->dependent_files,
-                                                          cservername);
-       r->previous_names = string_array_from_driver_info(mem_ctx,
-                                                         driver->previous_names,
-                                                         cservername);
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->dependent_files,
+                                              &r->dependent_files,
+                                              cservername,
+                                              driver->architecture,
+                                              driver->version);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
 
-       r->driver_date          = driver->driver_date;
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->previous_names,
+                                              &r->previous_names,
+                                              NULL, NULL, 0);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
+       r->driver_date          = driver->driver_date;
        r->driver_version       = driver->driver_version;
 
        FILL_DRIVER_STRING(mem_ctx,
@@ -4561,6 +4670,7 @@ static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
                                        const char *servername)
 {
        const char *cservername = canon_servername(servername);
+       WERROR result;
 
        r->version              = driver->version;
 
@@ -4570,18 +4680,26 @@ static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
        W_ERROR_HAVE_NO_MEMORY(r->architecture);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->driver_path,
                               r->driver_path);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->data_file,
                               r->data_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->config_file,
                               r->config_file);
 
        FILL_DRIVER_UNC_STRING(mem_ctx, cservername,
+                              driver->architecture,
+                              driver->version,
                               driver->help_file,
                               r->help_file);
 
@@ -4593,12 +4711,23 @@ static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
                           driver->default_datatype,
                           r->default_datatype);
 
-       r->dependent_files = string_array_from_driver_info(mem_ctx,
-                                                          driver->dependent_files,
-                                                          cservername);
-       r->previous_names = string_array_from_driver_info(mem_ctx,
-                                                         driver->previous_names,
-                                                         cservername);
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->dependent_files,
+                                              &r->dependent_files,
+                                              cservername,
+                                              driver->architecture,
+                                              driver->version);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->previous_names,
+                                              &r->previous_names,
+                                              NULL, NULL, 0);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
 
        r->driver_date          = driver->driver_date;
        r->driver_version       = driver->driver_version;
@@ -4623,9 +4752,13 @@ static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
                           driver->vendor_setup,
                           r->vendor_setup);
 
-       r->color_profiles = string_array_from_driver_info(mem_ctx,
-                                                         driver->color_profiles,
-                                                         cservername);
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->color_profiles,
+                                              &r->color_profiles,
+                                              NULL, NULL, 0);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
 
        FILL_DRIVER_STRING(mem_ctx,
                           driver->inf_path,
@@ -4633,9 +4766,13 @@ static WERROR fill_printer_driver_info8(TALLOC_CTX *mem_ctx,
 
        r->printer_driver_attributes    = driver->printer_driver_attributes;
 
-       r->core_driver_dependencies = string_array_from_driver_info(mem_ctx,
-                                                                   driver->core_driver_dependencies,
-                                                                   cservername);
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->core_driver_dependencies,
+                                              &r->core_driver_dependencies,
+                                              NULL, NULL, 0);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
 
        r->min_inbox_driver_ver_date    = driver->min_inbox_driver_ver_date;
        r->min_inbox_driver_ver_version = driver->min_inbox_driver_ver_version;
@@ -4796,9 +4933,14 @@ static WERROR fill_printer_driver_info101(TALLOC_CTX *mem_ctx,
                           driver->default_datatype,
                           r->default_datatype);
 
-       r->previous_names = string_array_from_driver_info(mem_ctx,
-                                                         driver->previous_names,
-                                                         cservername);
+       result = string_array_from_driver_info(mem_ctx,
+                                              driver->previous_names,
+                                              &r->previous_names,
+                                              NULL, NULL, 0);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
        r->driver_date          = driver->driver_date;
        r->driver_version       = driver->driver_version;
 
@@ -4822,6 +4964,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,
                                                  uint32_t level,
                                                  union spoolss_DriverInfo *r,
                                                  int snum,
@@ -4829,11 +4972,16 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
                                                  const char *architecture,
                                                  uint32_t version)
 {
-       NT_PRINTER_INFO_LEVEL *printer = NULL;
+       struct spoolss_PrinterInfo2 *pinfo2 = NULL;
        struct spoolss_DriverInfo8 *driver;
        WERROR result;
 
-       result = get_a_printer(NULL, &printer, 2, lp_const_servicename(snum));
+       result = winreg_get_printer(mem_ctx,
+                                   server_info,
+                                   smbd_messaging_context(),
+                                   servername,
+                                   lp_const_servicename(snum),
+                                   &pinfo2);
 
        DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
                win_errstr(result)));
@@ -4842,8 +4990,8 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
                return WERR_INVALID_PRINTER_NAME;
        }
 
-       result = get_a_printer_driver(mem_ctx, &driver, printer->info_2->drivername,
-                                     architecture, version);
+       result = winreg_get_driver(mem_ctx, server_info, architecture,
+                                  pinfo2->drivername, version, &driver);
 
        DEBUG(8,("construct_printer_driver_info_level: status: %s\n",
                win_errstr(result)));
@@ -4854,18 +5002,19 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
                 */
 
                if (version < 3) {
-                       free_a_printer(&printer, 2);
+                       talloc_free(pinfo2);
                        return WERR_UNKNOWN_PRINTER_DRIVER;
                }
 
                /* Yes - try again with a WinNT driver. */
                version = 2;
-               result = get_a_printer_driver(mem_ctx, &driver, printer->info_2->drivername,
-                                             architecture, version);
+               result = winreg_get_driver(mem_ctx, server_info, architecture,
+                                          pinfo2->drivername,
+                                          version, &driver);
                DEBUG(8,("construct_printer_driver_level: status: %s\n",
                        win_errstr(result)));
                if (!W_ERROR_IS_OK(result)) {
-                       free_a_printer(&printer, 2);
+                       talloc_free(pinfo2);
                        return WERR_UNKNOWN_PRINTER_DRIVER;
                }
        }
@@ -4902,8 +5051,8 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
                break;
        }
 
-       free_a_printer(&printer, 2);
-       free_a_printer_driver(driver);
+       talloc_free(pinfo2);
+       talloc_free(driver);
 
        return result;
 }
@@ -4912,13 +5061,12 @@ 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;
        WERROR result;
 
-       const char *servername;
        int snum;
 
        /* that's an [in out] buffer */
@@ -4938,15 +5086,13 @@ WERROR _spoolss_GetPrinterDriver2(pipes_struct *p,
        *r->out.server_major_version = 0;
        *r->out.server_minor_version = 0;
 
-       servername = get_server_name(printer);
-
        if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
                return WERR_BADFID;
        }
 
-       result = construct_printer_driver_info_level(p->mem_ctx, r->in.level,
-                                                    r->out.info, snum,
-                                                    servername,
+       result = construct_printer_driver_info_level(p->mem_ctx, p->server_info,
+                                                    r->in.level, r->out.info,
+                                                    snum, printer->servername,
                                                     r->in.architecture,
                                                     r->in.client_major_version);
        if (!W_ERROR_IS_OK(result)) {
@@ -4966,7 +5112,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);
@@ -4985,7 +5131,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;
@@ -5011,12 +5157,13 @@ 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;
        int snum;
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
+       WERROR werr;
 
        if (!Printer) {
                DEBUG(2,("_spoolss_StartDocPrinter: "
@@ -5025,6 +5172,13 @@ WERROR _spoolss_StartDocPrinter(pipes_struct *p,
                return WERR_BADFID;
        }
 
+       if (Printer->jobid) {
+               DEBUG(2, ("_spoolss_StartDocPrinter: "
+                         "StartDocPrinter called twice! "
+                         "(existing jobid = %d)\n", Printer->jobid));
+               return WERR_INVALID_HANDLE;
+       }
+
        if (r->in.level != 1) {
                return WERR_UNKNOWN_LEVEL;
        }
@@ -5051,15 +5205,15 @@ WERROR _spoolss_StartDocPrinter(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       Printer->jobid = print_job_start(p->server_info, snum,
-                                        info_1->document_name,
-                                        Printer->devmode);
+       werr = print_job_start(p->server_info, snum,
+                               info_1->document_name, info_1->output_file,
+                               Printer->devmode, &Printer->jobid);
 
        /* An error occured in print_job_start() so return an appropriate
           NT error code. */
 
-       if (Printer->jobid == -1) {
-               return map_werror_from_unix(errno);
+       if (!W_ERROR_IS_OK(werr)) {
+               return werr;
        }
 
        Printer->document_started = true;
@@ -5072,10 +5226,11 @@ 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);
+       NTSTATUS status;
        int snum;
 
        if (!Printer) {
@@ -5089,17 +5244,22 @@ WERROR _spoolss_EndDocPrinter(pipes_struct *p,
        }
 
        Printer->document_started = false;
-       print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
-       /* error codes unhandled so far ... */
+       status = print_job_end(snum, Printer->jobid, NORMAL_CLOSE);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(2, ("_spoolss_EndDocPrinter: "
+                         "print_job_end failed [%s]\n",
+                         nt_errstr(status)));
+       }
 
-       return WERR_OK;
+       Printer->jobid = 0;
+       return ntstatus_to_werror(status);
 }
 
 /****************************************************************
  _spoolss_WritePrinter
 ****************************************************************/
 
-WERROR _spoolss_WritePrinter(pipes_struct *p,
+WERROR _spoolss_WritePrinter(struct pipes_struct *p,
                             struct spoolss_WritePrinter *r)
 {
        ssize_t buffer_written;
@@ -5116,6 +5276,7 @@ WERROR _spoolss_WritePrinter(pipes_struct *p,
        if (!get_printer_snum(p, r->in.handle, &snum, NULL))
                return WERR_BADFID;
 
+       /* print_job_write takes care of checking for PJOB_SMBD_SPOOLING */
        buffer_written = print_job_write(snum, Printer->jobid,
                                                   (const char *)r->in.data.data,
                                                   (SMB_OFF_T)-1,
@@ -5140,7 +5301,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;
@@ -5180,7 +5341,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);
@@ -5196,7 +5357,11 @@ WERROR _spoolss_AbortPrinter(pipes_struct *p,
        if (!get_printer_snum(p, r->in.handle, &snum, NULL))
                return WERR_BADFID;
 
-       print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
+       if (!Printer->document_started) {
+               return WERR_SPL_NO_STARTDOC;
+       }
+
+       errcode = print_job_delete(p->server_info, snum, Printer->jobid);
 
        return errcode;
 }
@@ -5207,9 +5372,12 @@ 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 sec_desc_buf *new_secdesc_ctr = NULL, *old_secdesc_ctr = NULL;
+       struct spoolss_security_descriptor *new_secdesc = NULL;
+       struct spoolss_security_descriptor *old_secdesc = NULL;
+       const char *printer;
        WERROR result;
        int snum;
 
@@ -5223,11 +5391,12 @@ static WERROR update_printer_sec(struct policy_handle *handle,
                goto done;
        }
 
-       if (!secdesc_ctr) {
+       if (secdesc_ctr == NULL) {
                DEBUG(10,("update_printer_sec: secdesc_ctr is NULL !\n"));
                result = WERR_INVALID_PARAM;
                goto done;
        }
+       printer = lp_const_servicename(snum);
 
        /* Check the user has permissions to change the security
           descriptor.  By experimentation with two NT machines, the user
@@ -5242,9 +5411,13 @@ static WERROR update_printer_sec(struct policy_handle *handle,
 
        /* NT seems to like setting the security descriptor even though
           nothing may have actually changed. */
-
-       if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
-               DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
+       result = winreg_get_printer_secdesc(p->mem_ctx,
+                                           p->server_info,
+                                           p->msg_ctx,
+                                           printer,
+                                           &old_secdesc);
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(2,("update_printer_sec: winreg_get_printer_secdesc() failed\n"));
                result = WERR_BADFID;
                goto done;
        }
@@ -5253,9 +5426,9 @@ static WERROR update_printer_sec(struct policy_handle *handle,
                struct security_acl *the_acl;
                int i;
 
-               the_acl = old_secdesc_ctr->sd->dacl;
+               the_acl = old_secdesc->dacl;
                DEBUG(10, ("old_secdesc_ctr for %s has %d aces:\n",
-                          lp_printername(snum), the_acl->num_aces));
+                          printer, the_acl->num_aces));
 
                for (i = 0; i < the_acl->num_aces; i++) {
                        DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
@@ -5267,7 +5440,7 @@ static WERROR update_printer_sec(struct policy_handle *handle,
 
                if (the_acl) {
                        DEBUG(10, ("secdesc_ctr for %s has %d aces:\n",
-                                  lp_printername(snum), the_acl->num_aces));
+                                  printer, the_acl->num_aces));
 
                        for (i = 0; i < the_acl->num_aces; i++) {
                                DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
@@ -5279,71 +5452,76 @@ static WERROR update_printer_sec(struct policy_handle *handle,
                }
        }
 
-       new_secdesc_ctr = sec_desc_merge_buf(p->mem_ctx, secdesc_ctr, old_secdesc_ctr);
-       if (!new_secdesc_ctr) {
+       new_secdesc = sec_desc_merge(p->mem_ctx, secdesc_ctr->sd, old_secdesc);
+       if (new_secdesc == NULL) {
                result = WERR_NOMEM;
                goto done;
        }
 
-       if (security_descriptor_equal(new_secdesc_ctr->sd, old_secdesc_ctr->sd)) {
+       if (security_descriptor_equal(new_secdesc, old_secdesc)) {
                result = WERR_OK;
                goto done;
        }
 
-       result = nt_printing_setsec(Printer->sharename, new_secdesc_ctr);
+       result = winreg_set_printer_secdesc(p->mem_ctx,
+                                           p->server_info,
+                                           p->msg_ctx,
+                                           printer,
+                                           new_secdesc);
 
  done:
-
        return result;
 }
 
 /********************************************************************
  Canonicalize printer info from a client
-
- ATTN: It does not matter what we set the servername to hear
- since we do the necessary work in get_a_printer() to set it to
- the correct value based on what the client sent in the
- _spoolss_open_printer_ex().
  ********************************************************************/
 
-static bool check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
+static bool check_printer_ok(TALLOC_CTX *mem_ctx,
+                            struct spoolss_SetPrinterInfo2 *info2,
+                            int snum)
 {
        fstring printername;
        const char *p;
 
        DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s "
                "portname=%s drivername=%s comment=%s location=%s\n",
-               info->servername, info->printername, info->sharename,
-               info->portname, info->drivername, info->comment, info->location));
+               info2->servername, info2->printername, info2->sharename,
+               info2->portname, info2->drivername, info2->comment,
+               info2->location));
 
        /* we force some elements to "correct" values */
-       slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", global_myname());
-       fstrcpy(info->sharename, lp_servicename(snum));
+       info2->servername = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
+       if (info2->servername == NULL) {
+               return false;
+       }
+       info2->sharename = talloc_strdup(mem_ctx, lp_const_servicename(snum));
+       if (info2->sharename == NULL) {
+               return false;
+       }
 
        /* check to see if we allow printername != sharename */
-
-       if ( lp_force_printername(snum) ) {
-               slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
-                       global_myname(), info->sharename );
+       if (lp_force_printername(snum)) {
+               info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
+                                       global_myname(), info2->sharename);
        } else {
-
                /* make sure printername is in \\server\printername format */
-
-               fstrcpy( printername, info->printername );
+               fstrcpy(printername, info2->printername);
                p = printername;
                if ( printername[0] == '\\' && printername[1] == '\\' ) {
                        if ( (p = strchr_m( &printername[2], '\\' )) != NULL )
                                p++;
                }
 
-               slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s",
-                        global_myname(), p );
+               info2->printername = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
+                                       global_myname(), p);
+       }
+       if (info2->printername == NULL) {
+               return false;
        }
 
-       info->attributes |= PRINTER_ATTRIBUTE_SAMBA;
-       info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
-
-
+       info2->attributes |= PRINTER_ATTRIBUTE_SAMBA;
+       info2->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA;
 
        return true;
 }
@@ -5400,7 +5578,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, NT_PRINTER_INFO_LEVEL *printer)
+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;
@@ -5410,24 +5591,16 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEV
        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\"",
-                       cmd, printer->info_2->printername, printer->info_2->sharename,
-                       printer->info_2->portname, printer->info_2->drivername,
-                       printer->info_2->location, printer->info_2->comment, remote_machine);
+                       cmd, info2->printername, info2->sharename,
+                       info2->portname, info2->drivername,
+                       info2->location, info2->comment, remote_machine);
        if (!command) {
                return false;
        }
@@ -5444,8 +5617,7 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEV
 
        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 )
@@ -5456,7 +5628,6 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEV
        DEBUGADD(10,("returned [%d]\n", ret));
 
        TALLOC_FREE(command);
-       TALLOC_FREE(remote_machine);
 
        if ( ret != 0 ) {
                if (fd != -1)
@@ -5480,7 +5651,7 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEV
 
        if (numlines) {
                /* Set the portname to what the script says the portname should be. */
-               strncpy(printer->info_2->portname, qlines[0], sizeof(printer->info_2->portname));
+               info2->portname = talloc_strdup(ctx, qlines[0]);
                DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
        }
 
@@ -5488,252 +5659,402 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEV
        return true;
 }
 
-
-/********************************************************************
- * Called by spoolss_api_setprinter
- * when updating a printer description.
- ********************************************************************/
-
-static WERROR update_printer(pipes_struct *p, struct policy_handle *handle,
-                            struct spoolss_SetPrinterInfoCtr *info_ctr,
-                            struct spoolss_DeviceMode *devmode)
+static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
+                              struct auth_serversupplied_info *server_info,
+                              int snum,
+                              struct spoolss_SetPrinterInfo2 *printer,
+                              struct spoolss_PrinterInfo2 *old_printer)
 {
-       int snum;
-       NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
-       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
-       WERROR result;
+       bool force_update = (old_printer == NULL);
+       const char *dnsdomname;
+       const char *longname;
+       const char *uncname;
+       const char *spooling;
        DATA_BLOB buffer;
-       fstring asc_buffer;
-
-       DEBUG(8,("update_printer\n"));
-
-       result = WERR_OK;
-
-       if (!Printer) {
-               result = WERR_BADFID;
-               goto done;
-       }
-
-       if (!get_printer_snum(p, handle, &snum, NULL)) {
-               result = WERR_BADFID;
-               goto done;
-       }
-
-       if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum))) ||
-           (!W_ERROR_IS_OK(get_a_printer(Printer, &old_printer, 2, lp_const_servicename(snum))))) {
-               result = WERR_BADFID;
-               goto done;
-       }
+       WERROR result = WERR_OK;
 
-       DEBUGADD(8,("Converting info_2 struct\n"));
+       if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
+               push_reg_sz(mem_ctx, &buffer, printer->drivername);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
+                                         SPOOL_DSSPOOLER_KEY,
+                                         SPOOL_REG_DRIVERNAME,
+                                         REG_SZ,
+                                         buffer.data,
+                                         buffer.length);
 
-       /*
-        * convert_printer_info converts the incoming
-        * info from the client and overwrites the info
-        * just read from the tdb in the pointer 'printer'.
-        */
+               if (!force_update) {
+                       DEBUG(10,("update_printer: changing driver [%s]!  Sending event!\n",
+                               printer->drivername));
 
-       if (!convert_printer_info(info_ctr, printer)) {
-               result =  WERR_NOMEM;
-               goto done;
+                       notify_printer_driver(snum, printer->drivername);
+               }
        }
 
-       if (devmode) {
-               /* we have a valid devmode
-                  convert it and link it*/
+       if (force_update || !strequal(printer->comment, old_printer->comment)) {
+               push_reg_sz(mem_ctx, &buffer, printer->comment);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
+                                         SPOOL_DSSPOOLER_KEY,
+                                         SPOOL_REG_DESCRIPTION,
+                                         REG_SZ,
+                                         buffer.data,
+                                         buffer.length);
 
-               DEBUGADD(8,("update_printer: Converting the devicemode struct\n"));
-               result = copy_devicemode(printer->info_2, devmode,
-                                        &printer->info_2->devmode);
-               if (!W_ERROR_IS_OK(result)) {
-                       return result;
+               if (!force_update) {
+                       notify_printer_comment(snum, printer->comment);
                }
        }
 
-       /* Do sanity check on the requested changes for Samba */
+       if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
+               push_reg_sz(mem_ctx, &buffer, printer->sharename);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
+                                         SPOOL_DSSPOOLER_KEY,
+                                         SPOOL_REG_PRINTSHARENAME,
+                                         REG_SZ,
+                                         buffer.data,
+                                         buffer.length);
 
-       if (!check_printer_ok(printer->info_2, snum)) {
-               result = WERR_INVALID_PARAM;
-               goto done;
+               if (!force_update) {
+                       notify_printer_sharename(snum, printer->sharename);
+               }
        }
 
-       /* FIXME!!! If the driver has changed we really should verify that
-          it is installed before doing much else   --jerry */
-
-       /* Check calling user has permission to update printer description */
-
-       if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
-               DEBUG(3, ("update_printer: printer property change denied by handle\n"));
-               result = WERR_ACCESS_DENIED;
-               goto done;
-       }
+       if (force_update || !strequal(printer->printername, old_printer->printername)) {
+               const char *p;
 
-       /* Call addprinter hook */
-       /* Check changes to see if this is really needed */
+               p = strrchr(printer->printername, '\\' );
+               if (p != NULL) {
+                       p++;
+               } else {
+                       p = printer->printername;
+               }
 
-       if ( *lp_addprinter_cmd()
-               && (!strequal(printer->info_2->drivername, old_printer->info_2->drivername)
-                       || !strequal(printer->info_2->comment, old_printer->info_2->comment)
-                       || !strequal(printer->info_2->portname, old_printer->info_2->portname)
-                       || !strequal(printer->info_2->location, old_printer->info_2->location)) )
-       {
-               /* add_printer_hook() will call reload_services() */
+               push_reg_sz(mem_ctx, &buffer, p);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
+                                         SPOOL_DSSPOOLER_KEY,
+                                         SPOOL_REG_PRINTERNAME,
+                                         REG_SZ,
+                                         buffer.data,
+                                         buffer.length);
 
-               if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
-                                      printer) ) {
-                       result = WERR_ACCESS_DENIED;
-                       goto done;
+               if (!force_update) {
+                       notify_printer_printername(snum, p);
                }
        }
 
-       /*
-        * When a *new* driver is bound to a printer, the drivername is used to
-        * lookup previously saved driver initialization info, which is then
-        * bound to the printer, simulating what happens in the Windows arch.
-        */
-       if (!strequal(printer->info_2->drivername, old_printer->info_2->drivername))
-       {
-               DEBUG(10,("update_printer: changing driver [%s]!  Sending event!\n",
-                       printer->info_2->drivername));
+       if (force_update || !strequal(printer->portname, old_printer->portname)) {
+               push_reg_sz(mem_ctx, &buffer, printer->portname);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
+                                         SPOOL_DSSPOOLER_KEY,
+                                         SPOOL_REG_PORTNAME,
+                                         REG_SZ,
+                                         buffer.data,
+                                         buffer.length);
 
-               notify_printer_driver(snum, printer->info_2->drivername);
+               if (!force_update) {
+                       notify_printer_port(snum, printer->portname);
+               }
        }
 
-       /*
-        * flag which changes actually occured.  This is a small subset of
-        * all the possible changes.  We also have to update things in the
-        * DsSpooler key.
-        */
-
-       if (!strequal(printer->info_2->comment, old_printer->info_2->comment)) {
-               push_reg_sz(talloc_tos(), &buffer, printer->info_2->comment);
-               winreg_set_printer_dataex(p->mem_ctx,
-                                         p->server_info,
-                                         printer->info_2->sharename,
+       if (force_update || !strequal(printer->location, old_printer->location)) {
+               push_reg_sz(mem_ctx, &buffer, printer->location);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
-                                         "description",
+                                         SPOOL_REG_LOCATION,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
 
-               notify_printer_comment(snum, printer->info_2->comment);
+               if (!force_update) {
+                       notify_printer_location(snum, printer->location);
+               }
        }
 
-       if (!strequal(printer->info_2->sharename, old_printer->info_2->sharename)) {
-               push_reg_sz(talloc_tos(), &buffer, printer->info_2->sharename);
-               winreg_set_printer_dataex(p->mem_ctx,
-                                         p->server_info,
-                                         printer->info_2->sharename,
+       if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
+               push_reg_sz(mem_ctx, &buffer, printer->sepfile);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
-                                         "shareName",
+                                         SPOOL_REG_PRINTSEPARATORFILE,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
 
-               notify_printer_sharename(snum, printer->info_2->sharename);
+               if (!force_update) {
+                       notify_printer_location(snum, printer->location);
+               }
        }
 
-       if (!strequal(printer->info_2->printername, old_printer->info_2->printername)) {
-               char *pname;
-
-               if ( (pname = strchr_m( printer->info_2->printername+2, '\\' )) != NULL )
-                       pname++;
-               else
-                       pname = printer->info_2->printername;
-
-
-               push_reg_sz(talloc_tos(), &buffer, pname);
-               winreg_set_printer_dataex(p->mem_ctx,
-                                         p->server_info,
-                                         printer->info_2->sharename,
+       if (force_update || printer->starttime != old_printer->starttime) {
+               buffer = data_blob_talloc(mem_ctx, NULL, 4);
+               SIVAL(buffer.data, 0, printer->starttime);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
-                                         "printerName",
-                                         REG_SZ,
+                                         SPOOL_REG_PRINTSTARTTIME,
+                                         REG_DWORD,
                                          buffer.data,
                                          buffer.length);
-
-               notify_printer_printername( snum, pname );
        }
 
-       if (!strequal(printer->info_2->portname, old_printer->info_2->portname)) {
-               push_reg_sz(talloc_tos(), &buffer, printer->info_2->portname);
-               winreg_set_printer_dataex(p->mem_ctx,
-                                         p->server_info,
-                                         printer->info_2->sharename,
+       if (force_update || printer->untiltime != old_printer->untiltime) {
+               buffer = data_blob_talloc(mem_ctx, NULL, 4);
+               SIVAL(buffer.data, 0, printer->untiltime);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
-                                         "portName",
-                                         REG_SZ,
+                                         SPOOL_REG_PRINTENDTIME,
+                                         REG_DWORD,
                                          buffer.data,
                                          buffer.length);
+       }
 
-               notify_printer_port(snum, printer->info_2->portname);
+       if (force_update || printer->priority != old_printer->priority) {
+               buffer = data_blob_talloc(mem_ctx, NULL, 4);
+               SIVAL(buffer.data, 0, printer->priority);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
+                                         SPOOL_DSSPOOLER_KEY,
+                                         SPOOL_REG_PRIORITY,
+                                         REG_DWORD,
+                                         buffer.data,
+                                         buffer.length);
        }
 
-       if (!strequal(printer->info_2->location, old_printer->info_2->location)) {
-               push_reg_sz(talloc_tos(), &buffer, printer->info_2->location);
-               winreg_set_printer_dataex(p->mem_ctx,
-                                         p->server_info,
-                                         printer->info_2->sharename,
+       if (force_update || printer->attributes != old_printer->attributes) {
+               buffer = data_blob_talloc(mem_ctx, NULL, 4);
+               SIVAL(buffer.data, 0, (printer->attributes &
+                                      PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
-                                         "location",
-                                         REG_SZ,
+                                         SPOOL_REG_PRINTKEEPPRINTEDJOBS,
+                                         REG_DWORD,
                                          buffer.data,
                                          buffer.length);
 
-               notify_printer_location(snum, printer->info_2->location);
+               switch (printer->attributes & 0x3) {
+                       case 0:
+                               spooling = SPOOL_REGVAL_PRINTWHILESPOOLING;
+                               break;
+                       case 1:
+                               spooling = SPOOL_REGVAL_PRINTAFTERSPOOLED;
+                               break;
+                       case 2:
+                               spooling = SPOOL_REGVAL_PRINTDIRECT;
+                               break;
+                       default:
+                               spooling = "unknown";
+               }
+               push_reg_sz(mem_ctx, &buffer, spooling);
+               winreg_set_printer_dataex(mem_ctx,
+                                         server_info,
+                                         smbd_messaging_context(),
+                                         printer->sharename,
+                                         SPOOL_DSSPOOLER_KEY,
+                                         SPOOL_REG_PRINTSPOOLING,
+                                         REG_SZ,
+                                         buffer.data,
+                                         buffer.length);
        }
 
-       /* here we need to update some more DsSpooler keys */
-       /* uNCName, serverName, shortServerName */
-
-       push_reg_sz(talloc_tos(), &buffer, global_myname());
-       winreg_set_printer_dataex(p->mem_ctx,
-                                 p->server_info,
-                                 printer->info_2->sharename,
+       push_reg_sz(mem_ctx, &buffer, global_myname());
+       winreg_set_printer_dataex(mem_ctx,
+                                 server_info,
+                                 smbd_messaging_context(),
+                                 printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
-                                 "serverName",
+                                 SPOOL_REG_SHORTSERVERNAME,
                                  REG_SZ,
                                  buffer.data,
                                  buffer.length);
-       winreg_set_printer_dataex(p->mem_ctx,
-                                 p->server_info,
-                                 printer->info_2->sharename,
+
+       dnsdomname = get_mydnsfullname();
+       if (dnsdomname != NULL && dnsdomname[0] != '\0') {
+               longname = talloc_strdup(mem_ctx, dnsdomname);
+       } else {
+               longname = talloc_strdup(mem_ctx, global_myname());
+       }
+       if (longname == NULL) {
+               result = WERR_NOMEM;
+               goto done;
+       }
+
+       push_reg_sz(mem_ctx, &buffer, longname);
+       winreg_set_printer_dataex(mem_ctx,
+                                 server_info,
+                                 smbd_messaging_context(),
+                                 printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
-                                 "shortServerName",
+                                 SPOOL_REG_SERVERNAME,
                                  REG_SZ,
                                  buffer.data,
                                  buffer.length);
 
-       slprintf( asc_buffer, sizeof(asc_buffer)-1, "\\\\%s\\%s",
-                 global_myname(), printer->info_2->sharename );
-       push_reg_sz(talloc_tos(), &buffer, asc_buffer);
-       winreg_set_printer_dataex(p->mem_ctx,
-                                 p->server_info,
-                                 printer->info_2->sharename,
+       uncname = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
+                                 global_myname(), printer->sharename);
+       push_reg_sz(mem_ctx, &buffer, uncname);
+       winreg_set_printer_dataex(mem_ctx,
+                                 server_info,
+                                 smbd_messaging_context(),
+                                 printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
-                                 "uNCName",
+                                 SPOOL_REG_UNCNAME,
                                  REG_SZ,
                                  buffer.data,
                                  buffer.length);
 
-       /* Update printer info */
-       result = mod_a_printer(printer, 2);
-
 done:
-       free_a_printer(&printer, 2);
-       free_a_printer(&old_printer, 2);
+       return result;
+}
+
+/********************************************************************
+ * Called by spoolss_api_setprinter
+ * when updating a printer description.
+ ********************************************************************/
 
+static WERROR update_printer(struct pipes_struct *p,
+                            struct policy_handle *handle,
+                            struct spoolss_SetPrinterInfoCtr *info_ctr,
+                            struct spoolss_DeviceMode *devmode)
+{
+       uint32_t printer_mask = SPOOLSS_PRINTER_INFO_ALL;
+       struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
+       struct spoolss_PrinterInfo2 *old_printer;
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
+       const char *servername = NULL;
+       int snum;
+       WERROR result = WERR_OK;
+       TALLOC_CTX *tmp_ctx;
+
+       DEBUG(8,("update_printer\n"));
+
+       tmp_ctx = talloc_new(p->mem_ctx);
+       if (tmp_ctx == NULL) {
+               return WERR_NOMEM;
+       }
+
+       if (!Printer) {
+               result = WERR_BADFID;
+               goto done;
+       }
+
+       if (!get_printer_snum(p, handle, &snum, NULL)) {
+               result = WERR_BADFID;
+               goto done;
+       }
+
+       if (Printer != NULL || Printer->servername != NULL) {
+               servername = Printer->servername;
+       }
+
+       result = winreg_get_printer(tmp_ctx,
+                                   p->server_info,
+                                   p->msg_ctx,
+                                   servername,
+                                   lp_const_servicename(snum),
+                                   &old_printer);
+       if (!W_ERROR_IS_OK(result)) {
+               result = WERR_BADFID;
+               goto done;
+       }
+
+       /* Do sanity check on the requested changes for Samba */
+       if (!check_printer_ok(tmp_ctx, printer, snum)) {
+               result = WERR_INVALID_PARAM;
+               goto done;
+       }
+
+       /* FIXME!!! If the driver has changed we really should verify that
+          it is installed before doing much else   --jerry */
+
+       /* Check calling user has permission to update printer description */
+       if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
+               DEBUG(3, ("update_printer: printer property change denied by handle\n"));
+               result = WERR_ACCESS_DENIED;
+               goto done;
+       }
+
+       /* Call addprinter hook */
+       /* Check changes to see if this is really needed */
+
+       if (*lp_addprinter_cmd() &&
+                       (!strequal(printer->drivername, old_printer->drivername) ||
+                        !strequal(printer->comment, old_printer->comment) ||
+                        !strequal(printer->portname, old_printer->portname) ||
+                        !strequal(printer->location, old_printer->location)) )
+       {
+               /* add_printer_hook() will call reload_services() */
+               if (!add_printer_hook(tmp_ctx, p->server_info->ptok,
+                                     printer, p->client_address,
+                                     p->msg_ctx)) {
+                       result = WERR_ACCESS_DENIED;
+                       goto done;
+               }
+       }
+
+       update_dsspooler(tmp_ctx,
+                        p->server_info,
+                        snum,
+                        printer,
+                        old_printer);
+
+       printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
+
+       if (devmode == NULL) {
+               printer_mask &= ~SPOOLSS_PRINTER_INFO_DEVMODE;
+       }
+       result = winreg_update_printer(tmp_ctx,
+                                      p->server_info,
+                                      p->msg_ctx,
+                                      printer->sharename,
+                                      printer_mask,
+                                      printer,
+                                      devmode,
+                                      NULL);
+
+done:
+       talloc_free(tmp_ctx);
 
        return result;
 }
 
 /****************************************************************************
 ****************************************************************************/
-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)
 {
 #ifdef HAVE_ADS
+       struct spoolss_PrinterInfo2 *pinfo2 = NULL;
+       WERROR result;
        int snum;
        Printer_entry *Printer;
 
@@ -5751,8 +6072,16 @@ static WERROR publish_or_unpublish_printer(pipes_struct *p,
        if (!get_printer_snum(p, handle, &snum, NULL))
                return WERR_BADFID;
 
-       nt_printer_publish(Printer, snum, info7->action);
+       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);
+
+       TALLOC_FREE(pinfo2);
        return WERR_OK;
 #else
        return WERR_UNKNOWN_LEVEL;
@@ -5762,60 +6091,38 @@ 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;
-       NT_PRINTER_INFO_LEVEL *printer = NULL;
        Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
-       WERROR result;
+       uint32_t info2_mask = SPOOLSS_PRINTER_INFO_DEVMODE;
 
        DEBUG(8,("update_printer_devmode\n"));
 
-       result = WERR_OK;
-
        if (!Printer) {
-               result = WERR_BADFID;
-               goto done;
-       }
-
-       if (!get_printer_snum(p, handle, &snum, NULL)) {
-               result = WERR_BADFID;
-               goto done;
-       }
-
-       if (!W_ERROR_IS_OK(get_a_printer(Printer, &printer, 2, lp_const_servicename(snum)))) {
-               result = WERR_BADFID;
-               goto done;
+               return WERR_BADFID;
        }
 
-       if (devmode) {
-               /* we have a valid devmode, copy it */
-
-               DEBUGADD(8, ("update_printer: Copying the devicemode struct\n"));
-               result = copy_devicemode(printer->info_2, devmode,
-                                        &printer->info_2->devmode);
-               if (!W_ERROR_IS_OK(result)) {
-                       goto done;
-               }
+       if (!get_printer_snum(p, handle, &snum, NULL)) {
+               return WERR_BADFID;
        }
 
        /* Check calling user has permission to update printer description */
-
        if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
                DEBUG(3, ("update_printer: printer property change denied by handle\n"));
-               result = WERR_ACCESS_DENIED;
-               goto done;
+               return WERR_ACCESS_DENIED;
        }
 
-
-       /* Update printer info */
-       result = mod_a_printer(printer, 2);
-
-done:
-       free_a_printer(&printer, 2);
-
-       return result;
+       return winreg_update_printer(p->mem_ctx,
+                                    p->server_info,
+                                    p->msg_ctx,
+                                    lp_const_servicename(snum),
+                                    info2_mask,
+                                    NULL,
+                                    devmode,
+                                    NULL);
 }
 
 
@@ -5823,7 +6130,7 @@ done:
  _spoolss_SetPrinter
 ****************************************************************/
 
-WERROR _spoolss_SetPrinter(pipes_struct *p,
+WERROR _spoolss_SetPrinter(struct pipes_struct *p,
                           struct spoolss_SetPrinter *r)
 {
        WERROR result;
@@ -5868,7 +6175,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);
@@ -5888,7 +6195,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;
@@ -5905,7 +6213,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)) {
@@ -5930,7 +6238,7 @@ static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
                             struct spoolss_JobInfo1 *r,
                             const print_queue_struct *queue,
                             int position, int snum,
-                            const NT_PRINTER_INFO_LEVEL *ntprinter)
+                            struct spoolss_PrinterInfo2 *pinfo2)
 {
        struct tm *t;
 
@@ -5940,7 +6248,7 @@ static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
 
        r->printer_name         = talloc_strdup(mem_ctx, lp_servicename(snum));
        W_ERROR_HAVE_NO_MEMORY(r->printer_name);
-       r->server_name          = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
+       r->server_name          = talloc_strdup(mem_ctx, pinfo2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->server_name);
        r->user_name            = talloc_strdup(mem_ctx, queue->fs_user);
        W_ERROR_HAVE_NO_MEMORY(r->user_name);
@@ -5970,7 +6278,7 @@ static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
                             struct spoolss_JobInfo2 *r,
                             const print_queue_struct *queue,
                             int position, int snum,
-                            const NT_PRINTER_INFO_LEVEL *ntprinter,
+                            struct spoolss_PrinterInfo2 *pinfo2,
                             struct spoolss_DeviceMode *devmode)
 {
        struct tm *t;
@@ -5981,7 +6289,7 @@ static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
 
        r->printer_name         = talloc_strdup(mem_ctx, lp_servicename(snum));
        W_ERROR_HAVE_NO_MEMORY(r->printer_name);
-       r->server_name          = talloc_strdup(mem_ctx, ntprinter->info_2->servername);
+       r->server_name          = talloc_strdup(mem_ctx, pinfo2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->server_name);
        r->user_name            = talloc_strdup(mem_ctx, queue->fs_user);
        W_ERROR_HAVE_NO_MEMORY(r->user_name);
@@ -5995,7 +6303,7 @@ static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
        W_ERROR_HAVE_NO_MEMORY(r->print_processor);
        r->parameters           = talloc_strdup(mem_ctx, "");
        W_ERROR_HAVE_NO_MEMORY(r->parameters);
-       r->driver_name          = talloc_strdup(mem_ctx, ntprinter->info_2->drivername);
+       r->driver_name          = talloc_strdup(mem_ctx, pinfo2->drivername);
        W_ERROR_HAVE_NO_MEMORY(r->driver_name);
 
        r->devmode              = devmode;
@@ -6028,7 +6336,7 @@ static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
                             const print_queue_struct *queue,
                             const print_queue_struct *next_queue,
                             int position, int snum,
-                            const NT_PRINTER_INFO_LEVEL *ntprinter)
+                            struct spoolss_PrinterInfo2 *pinfo2)
 {
        r->job_id               = queue->job;
        r->next_job_id          = 0;
@@ -6047,7 +6355,7 @@ static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
 static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
                              const print_queue_struct *queue,
                              uint32_t num_queues, int snum,
-                              const NT_PRINTER_INFO_LEVEL *ntprinter,
+                              struct spoolss_PrinterInfo2 *pinfo2,
                              union spoolss_JobInfo **info_p,
                              uint32_t *count)
 {
@@ -6066,7 +6374,7 @@ static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
                                        &queue[i],
                                        i,
                                        snum,
-                                       ntprinter);
+                                       pinfo2);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
                }
@@ -6091,7 +6399,7 @@ static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
 static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
                              const print_queue_struct *queue,
                              uint32_t num_queues, int snum,
-                              const NT_PRINTER_INFO_LEVEL *ntprinter,
+                              struct spoolss_PrinterInfo2 *pinfo2,
                              union spoolss_JobInfo **info_p,
                              uint32_t *count)
 {
@@ -6105,12 +6413,13 @@ static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
        *count = num_queues;
 
        for (i=0; i<*count; i++) {
-
                struct spoolss_DeviceMode *devmode;
 
-               devmode = construct_dev_mode(info, lp_const_servicename(snum));
-               if (!devmode) {
-                       result = WERR_NOMEM;
+               result = spoolss_create_default_devmode(info,
+                                                       pinfo2->printername,
+                                                       &devmode);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(3, ("Can't proceed w/o a devmode!"));
                        goto out;
                }
 
@@ -6119,7 +6428,7 @@ static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
                                        &queue[i],
                                        i,
                                        snum,
-                                       ntprinter,
+                                       pinfo2,
                                        devmode);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
@@ -6145,7 +6454,7 @@ static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
 static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
                              const print_queue_struct *queue,
                              uint32_t num_queues, int snum,
-                              const NT_PRINTER_INFO_LEVEL *ntprinter,
+                              struct spoolss_PrinterInfo2 *pinfo2,
                              union spoolss_JobInfo **info_p,
                              uint32_t *count)
 {
@@ -6171,7 +6480,7 @@ static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
                                        next_queue,
                                        i,
                                        snum,
-                                       ntprinter);
+                                       pinfo2);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
                }
@@ -6193,11 +6502,11 @@ 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;
-       NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
+       struct spoolss_PrinterInfo2 *pinfo2 = NULL;
        int snum;
        print_status_struct prt_status;
        print_queue_struct *queue = NULL;
@@ -6221,7 +6530,8 @@ WERROR _spoolss_EnumJobs(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
+       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;
        }
@@ -6232,22 +6542,22 @@ WERROR _spoolss_EnumJobs(pipes_struct *p,
 
        if (count == 0) {
                SAFE_FREE(queue);
-               free_a_printer(&ntprinter, 2);
+               TALLOC_FREE(pinfo2);
                return WERR_OK;
        }
 
        switch (r->in.level) {
        case 1:
                result = enumjobs_level1(p->mem_ctx, queue, count, snum,
-                                        ntprinter, r->out.info, r->out.count);
+                                        pinfo2, r->out.info, r->out.count);
                break;
        case 2:
                result = enumjobs_level2(p->mem_ctx, queue, count, snum,
-                                        ntprinter, r->out.info, r->out.count);
+                                        pinfo2, r->out.info, r->out.count);
                break;
        case 3:
                result = enumjobs_level3(p->mem_ctx, queue, count, snum,
-                                        ntprinter, r->out.info, r->out.count);
+                                        pinfo2, r->out.info, r->out.count);
                break;
        default:
                result = WERR_UNKNOWN_LEVEL;
@@ -6255,7 +6565,7 @@ WERROR _spoolss_EnumJobs(pipes_struct *p,
        }
 
        SAFE_FREE(queue);
-       free_a_printer(&ntprinter, 2);
+       TALLOC_FREE(pinfo2);
 
        if (!W_ERROR_IS_OK(result)) {
                return result;
@@ -6275,7 +6585,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;
@@ -6310,7 +6620,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;
@@ -6327,7 +6637,9 @@ WERROR _spoolss_SetJob(pipes_struct *p,
        switch (r->in.command) {
        case SPOOLSS_JOB_CONTROL_CANCEL:
        case SPOOLSS_JOB_CONTROL_DELETE:
-               if (print_job_delete(p->server_info, snum, r->in.job_id, &errcode)) {
+               errcode = print_job_delete(p->server_info,
+                                          snum, r->in.job_id);
+               if (W_ERROR_EQUAL(errcode, WERR_PRINTER_HAS_JOBS_QUEUED)) {
                        errcode = WERR_OK;
                }
                break;
@@ -6378,6 +6690,7 @@ WERROR _spoolss_SetJob(pipes_struct *p,
 ****************************************************************************/
 
 static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
+                                                      struct auth_serversupplied_info *server_info,
                                                       const char *servername,
                                                       const char *architecture,
                                                       uint32_t level,
@@ -6385,32 +6698,32 @@ static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
                                                       uint32_t *count_p)
 {
        int i;
-       int ndrivers;
        uint32_t version;
-       fstring *list = NULL;
        struct spoolss_DriverInfo8 *driver;
        union spoolss_DriverInfo *info = NULL;
        uint32_t count = 0;
        WERROR result = WERR_OK;
+       uint32_t num_drivers;
+       const char **drivers;
 
        *count_p = 0;
        *info_p = NULL;
 
        for (version=0; version<DRIVER_MAX_VERSION; version++) {
-               list = NULL;
-               ndrivers = get_ntdrivers(&list, architecture, version);
-               DEBUGADD(4,("we have:[%d] drivers in environment [%s] and version [%d]\n",
-                       ndrivers, architecture, version));
-
-               if (ndrivers == -1) {
-                       result = WERR_NOMEM;
+               result = winreg_get_driver_list(mem_ctx, server_info,
+                                               architecture, version,
+                                               &num_drivers, &drivers);
+               if (!W_ERROR_IS_OK(result)) {
                        goto out;
                }
+               DEBUG(4, ("we have:[%d] drivers in environment"
+                         " [%s] and version [%d]\n",
+                         num_drivers, architecture, version));
 
-               if (ndrivers != 0) {
+               if (num_drivers != 0) {
                        info = TALLOC_REALLOC_ARRAY(mem_ctx, info,
                                                    union spoolss_DriverInfo,
-                                                   count + ndrivers);
+                                                   count + num_drivers);
                        if (!info) {
                                DEBUG(0,("enumprinterdrivers_level_by_architecture: "
                                        "failed to enlarge driver info buffer!\n"));
@@ -6419,11 +6732,12 @@ static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
                        }
                }
 
-               for (i=0; i<ndrivers; i++) {
-                       DEBUGADD(5,("\tdriver: [%s]\n", list[i]));
-                       ZERO_STRUCT(driver);
-                       result = get_a_printer_driver(mem_ctx, &driver, list[i],
-                                                     architecture, version);
+               for (i = 0; i < num_drivers; i++) {
+                       DEBUG(5, ("\tdriver: [%s]\n", drivers[i]));
+
+                       result = winreg_get_driver(mem_ctx, server_info,
+                                                  architecture, drivers[i],
+                                                  version, &driver);
                        if (!W_ERROR_IS_OK(result)) {
                                goto out;
                        }
@@ -6462,19 +6776,19 @@ static WERROR enumprinterdrivers_level_by_architecture(TALLOC_CTX *mem_ctx,
                                break;
                        }
 
-                       free_a_printer_driver(driver);
+                       TALLOC_FREE(driver);
 
                        if (!W_ERROR_IS_OK(result)) {
                                goto out;
                        }
                }
 
-               count += ndrivers;
-               SAFE_FREE(list);
+               count += num_drivers;
+               TALLOC_FREE(drivers);
        }
 
  out:
-       SAFE_FREE(list);
+       TALLOC_FREE(drivers);
 
        if (!W_ERROR_IS_OK(result)) {
                TALLOC_FREE(info);
@@ -6492,6 +6806,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,
                                       const char *servername,
                                       const char *architecture,
                                       uint32_t level,
@@ -6509,6 +6824,7 @@ static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
                        uint32_t count = 0;
 
                        result = enumprinterdrivers_level_by_architecture(mem_ctx,
+                                                                         server_info,
                                                                          servername,
                                                                          archi_table[a].long_archi,
                                                                          level,
@@ -6528,6 +6844,7 @@ static WERROR enumprinterdrivers_level(TALLOC_CTX *mem_ctx,
        }
 
        return enumprinterdrivers_level_by_architecture(mem_ctx,
+                                                       server_info,
                                                        servername,
                                                        architecture,
                                                        level,
@@ -6539,7 +6856,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;
@@ -6563,7 +6880,9 @@ WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
                return WERR_UNKNOWN_PRINTER_DRIVER;
        }
 
-       result = enumprinterdrivers_level(p->mem_ctx, cservername,
+       result = enumprinterdrivers_level(p->mem_ctx,
+                                         p->server_info,
+                                         cservername,
                                          r->in.environment,
                                          r->in.level,
                                          r->out.info,
@@ -6582,91 +6901,14 @@ WERROR _spoolss_EnumPrinterDrivers(pipes_struct *p,
        return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
 }
 
-/****************************************************************************
-****************************************************************************/
-
-static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
-                              struct spoolss_FormInfo1 *r,
-                              const nt_forms_struct *form)
-{
-       r->form_name    = talloc_strdup(mem_ctx, form->name);
-       W_ERROR_HAVE_NO_MEMORY(r->form_name);
-
-       r->flags        = form->flag;
-       r->size.width   = form->width;
-       r->size.height  = form->length;
-       r->area.left    = form->left;
-       r->area.top     = form->top;
-       r->area.right   = form->right;
-       r->area.bottom  = form->bottom;
-
-       return WERR_OK;
-}
-
-/****************************************************************
- spoolss_enumforms_level1
-****************************************************************/
-
-static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
-                                      const nt_forms_struct *builtin_forms,
-                                      uint32_t num_builtin_forms,
-                                      const nt_forms_struct *user_forms,
-                                      uint32_t num_user_forms,
-                                      union spoolss_FormInfo **info_p,
-                                      uint32_t *count)
-{
-       union spoolss_FormInfo *info;
-       WERROR result = WERR_OK;
-       int i;
-
-       *count = num_builtin_forms + num_user_forms;
-
-       info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
-       W_ERROR_HAVE_NO_MEMORY(info);
-
-       /* construct the list of form structures */
-       for (i=0; i<num_builtin_forms; i++) {
-               DEBUGADD(6,("Filling builtin form number [%d]\n",i));
-               result = fill_form_info_1(info, &info[i].info1,
-                                         &builtin_forms[i]);
-               if (!W_ERROR_IS_OK(result)) {
-                       goto out;
-               }
-       }
-
-       for (i=0; i<num_user_forms; i++) {
-               DEBUGADD(6,("Filling user form number [%d]\n",i));
-               result = fill_form_info_1(info, &info[i+num_builtin_forms].info1,
-                                         &user_forms[i]);
-               if (!W_ERROR_IS_OK(result)) {
-                       goto out;
-               }
-       }
-
- out:
-       if (!W_ERROR_IS_OK(result)) {
-               TALLOC_FREE(info);
-               *count = 0;
-               return result;
-       }
-
-       *info_p = info;
-
-       return WERR_OK;
-}
-
 /****************************************************************
  _spoolss_EnumForms
 ****************************************************************/
 
-WERROR _spoolss_EnumForms(pipes_struct *p,
+WERROR _spoolss_EnumForms(struct pipes_struct *p,
                          struct spoolss_EnumForms *r)
 {
        WERROR result;
-       nt_forms_struct *user_forms = NULL;
-       nt_forms_struct *builtin_forms = NULL;
-       uint32_t num_user_forms;
-       uint32_t num_builtin_forms;
 
        *r->out.count = 0;
        *r->out.needed = 0;
@@ -6682,39 +6924,27 @@ WERROR _spoolss_EnumForms(pipes_struct *p,
        DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
        DEBUGADD(5,("Info level [%d]\n",          r->in.level));
 
-       num_builtin_forms = get_builtin_ntforms(&builtin_forms);
-       DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
-       num_user_forms = get_ntforms(&user_forms);
-       DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
-
-       if (num_user_forms + num_builtin_forms == 0) {
-               SAFE_FREE(builtin_forms);
-               SAFE_FREE(user_forms);
-               return WERR_NO_MORE_ITEMS;
-       }
-
        switch (r->in.level) {
        case 1:
-               result = spoolss_enumforms_level1(p->mem_ctx,
-                                                 builtin_forms,
-                                                 num_builtin_forms,
-                                                 user_forms,
-                                                 num_user_forms,
-                                                 r->out.info,
-                                                 r->out.count);
+               result = winreg_printer_enumforms1(p->mem_ctx,
+                                                  p->server_info,
+                                                  p->msg_ctx,
+                                                  r->out.count,
+                                                  r->out.info);
                break;
        default:
                result = WERR_UNKNOWN_LEVEL;
                break;
        }
 
-       SAFE_FREE(user_forms);
-       SAFE_FREE(builtin_forms);
-
        if (!W_ERROR_IS_OK(result)) {
                return result;
        }
 
+       if (*r->out.count == 0) {
+               return WERR_NO_MORE_ITEMS;
+       }
+
        *r->out.needed  = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
                                                     spoolss_EnumForms, 
                                                     *r->out.info, r->in.level,
@@ -6725,53 +6955,14 @@ WERROR _spoolss_EnumForms(pipes_struct *p,
        return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
 }
 
-/****************************************************************
-****************************************************************/
-
-static WERROR find_form_byname(const char *name,
-                              nt_forms_struct *form)
-{
-       nt_forms_struct *list = NULL;
-       int num_forms = 0, i = 0;
-
-       if (get_a_builtin_ntform_by_string(name, form)) {
-               return WERR_OK;
-       }
-
-       num_forms = get_ntforms(&list);
-       DEBUGADD(5,("Number of forms [%d]\n", num_forms));
-
-       if (num_forms == 0) {
-               return WERR_BADFID;
-       }
-
-       /* Check if the requested name is in the list of form structures */
-       for (i = 0; i < num_forms; i++) {
-
-               DEBUG(4,("checking form %s (want %s)\n", list[i].name, name));
-
-               if (strequal(name, list[i].name)) {
-                       DEBUGADD(6,("Found form %s number [%d]\n", name, i));
-                       *form = list[i];
-                       SAFE_FREE(list);
-                       return WERR_OK;
-               }
-       }
-
-       SAFE_FREE(list);
-
-       return WERR_BADFID;
-}
-
 /****************************************************************
  _spoolss_GetForm
 ****************************************************************/
 
-WERROR _spoolss_GetForm(pipes_struct *p,
+WERROR _spoolss_GetForm(struct pipes_struct *p,
                        struct spoolss_GetForm *r)
 {
        WERROR result;
-       nt_forms_struct form;
 
        /* that's an [in out] buffer */
 
@@ -6783,19 +6974,14 @@ WERROR _spoolss_GetForm(pipes_struct *p,
        DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
        DEBUGADD(5,("Info level [%d]\n",          r->in.level));
 
-       result = find_form_byname(r->in.form_name, &form);
-       if (!W_ERROR_IS_OK(result)) {
-               TALLOC_FREE(r->out.info);
-               return result;
-       }
-
        switch (r->in.level) {
        case 1:
-               result = fill_form_info_1(p->mem_ctx,
-                                         &r->out.info->info1,
-                                         &form);
+               result = winreg_printer_getform1(p->mem_ctx,
+                                                p->server_info,
+                                                p->msg_ctx,
+                                                r->in.form_name,
+                                                &r->out.info->info1);
                break;
-
        default:
                result = WERR_UNKNOWN_LEVEL;
                break;
@@ -7019,7 +7205,7 @@ out:
  _spoolss_EnumPorts
 ****************************************************************/
 
-WERROR _spoolss_EnumPorts(pipes_struct *p,
+WERROR _spoolss_EnumPorts(struct pipes_struct *p,
                          struct spoolss_EnumPorts *r)
 {
        WERROR result;
@@ -7066,76 +7252,55 @@ 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,
-                                          struct security_descriptor *sec_desc,
+                                          struct security_descriptor *secdesc,
                                           struct spoolss_UserLevelCtr *user_ctr,
                                           struct policy_handle *handle)
 {
-       NT_PRINTER_INFO_LEVEL *printer = NULL;
-       fstring name;
+       struct spoolss_SetPrinterInfo2 *info2 = info_ctr->info.info2;
+       uint32_t info2_mask = SPOOLSS_PRINTER_INFO_ALL;
        int     snum;
        WERROR err = WERR_OK;
 
-       if ( !(printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) {
-               DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
-               return WERR_NOMEM;
-       }
-
-       /* convert from UNICODE to ASCII - this allocates the info_2 struct inside *printer.*/
-       if (!convert_printer_info(info_ctr, printer)) {
-               free_a_printer(&printer, 2);
-               return WERR_NOMEM;
-       }
-
        /* samba does not have a concept of local, non-shared printers yet, so
         * make sure we always setup sharename - gd */
-       if ((printer->info_2->sharename[0] == '\0') && (printer->info_2->printername != '\0')) {
+       if ((info2->sharename == NULL || info2->sharename[0] == '\0') &&
+           (info2->printername != NULL && info2->printername[0] != '\0')) {
                DEBUG(5, ("spoolss_addprinterex_level_2: "
                        "no sharename has been set, setting printername %s as sharename\n",
-                       printer->info_2->printername));
-               fstrcpy(printer->info_2->sharename, printer->info_2->printername);
+                       info2->printername));
+               info2->sharename = info2->printername;
        }
 
        /* check to see if the printer already exists */
-
-       if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
+       if ((snum = print_queue_snum(info2->sharename)) != -1) {
                DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
-                       printer->info_2->sharename));
-               free_a_printer(&printer, 2);
+                       info2->sharename));
                return WERR_PRINTER_ALREADY_EXISTS;
        }
 
        if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
-               if ((snum = print_queue_snum(printer->info_2->printername)) != -1) {
+               if ((snum = print_queue_snum(info2->printername)) != -1) {
                        DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
-                               printer->info_2->printername));
-                       free_a_printer(&printer, 2);
+                               info2->printername));
                        return WERR_PRINTER_ALREADY_EXISTS;
                }
        }
 
        /* validate printer info struct */
-       if (!info_ctr->info.info2->printername ||
-           strlen(info_ctr->info.info2->printername) == 0) {
-               free_a_printer(&printer,2);
+       if (!info2->printername || strlen(info2->printername) == 0) {
                return WERR_INVALID_PRINTER_NAME;
        }
-       if (!info_ctr->info.info2->portname ||
-           strlen(info_ctr->info.info2->portname) == 0) {
-               free_a_printer(&printer,2);
+       if (!info2->portname || strlen(info2->portname) == 0) {
                return WERR_UNKNOWN_PORT;
        }
-       if (!info_ctr->info.info2->drivername ||
-           strlen(info_ctr->info.info2->drivername) == 0) {
-               free_a_printer(&printer,2);
+       if (!info2->drivername || strlen(info2->drivername) == 0) {
                return WERR_UNKNOWN_PRINTER_DRIVER;
        }
-       if (!info_ctr->info.info2->printprocessor ||
-           strlen(info_ctr->info.info2->printprocessor) == 0) {
-               free_a_printer(&printer,2);
+       if (!info2->printprocessor || strlen(info2->printprocessor) == 0) {
                return WERR_UNKNOWN_PRINTPROCESSOR;
        }
 
@@ -7144,32 +7309,23 @@ static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
 
        if (*lp_addprinter_cmd() ) {
                if ( !add_printer_hook(p->mem_ctx, p->server_info->ptok,
-                                      printer) ) {
-                       free_a_printer(&printer,2);
+                                      info2, p->client_address,
+                                      p->msg_ctx) ) {
                        return WERR_ACCESS_DENIED;
                }
        } else {
                DEBUG(0,("spoolss_addprinterex_level_2: add printer for printer %s called and no"
                        "smb.conf parameter \"addprinter command\" is defined. This"
                        "parameter must exist for this call to succeed\n",
-                       printer->info_2->sharename ));
+                       info2->sharename ));
        }
 
-       /* use our primary netbios name since get_a_printer() will convert
-          it to what the client expects on a case by case basis */
-
-       slprintf(name, sizeof(name)-1, "\\\\%s\\%s", global_myname(),
-             printer->info_2->sharename);
-
-
-       if ((snum = print_queue_snum(printer->info_2->sharename)) == -1) {
-               free_a_printer(&printer,2);
+       if ((snum = print_queue_snum(info2->sharename)) == -1) {
                return WERR_ACCESS_DENIED;
        }
 
        /* you must be a printer admin to add a new printer */
        if (!print_access_check(p->server_info, snum, PRINTER_ACCESS_ADMINISTER)) {
-               free_a_printer(&printer,2);
                return WERR_ACCESS_DENIED;
        }
 
@@ -7177,48 +7333,38 @@ static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
         * Do sanity check on the requested changes for Samba.
         */
 
-       if (!check_printer_ok(printer->info_2, snum)) {
-               free_a_printer(&printer,2);
+       if (!check_printer_ok(p->mem_ctx, info2, snum)) {
                return WERR_INVALID_PARAM;
        }
 
-       /*
-        * When a printer is created, the drivername bound to the printer is used
-        * to lookup previously saved driver initialization info, which is then
-        * bound to the new printer, simulating what happens in the Windows arch.
-        */
-
-       if (devmode)
-       {
-               /* A valid devmode was included, convert and link it
-               */
-               DEBUGADD(10, ("spoolss_addprinterex_level_2: devmode included, converting\n"));
-
-               err = copy_devicemode(printer, devmode,
-                                     &printer->info_2->devmode);
-               if (!W_ERROR_IS_OK(err)) {
-                       return err;
-               }
+       if (devmode == NULL) {
+               info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
        }
 
-       /* write the ASCII on disk */
-       err = mod_a_printer(printer, 2);
+       update_dsspooler(p->mem_ctx,
+                        p->server_info,
+                        0,
+                        info2,
+                        NULL);
+
+       err = winreg_update_printer(p->mem_ctx,
+                                   p->server_info,
+                                   p->msg_ctx,
+                                   info2->sharename,
+                                   info2_mask,
+                                   info2,
+                                   devmode,
+                                   secdesc);
        if (!W_ERROR_IS_OK(err)) {
-               free_a_printer(&printer,2);
                return err;
        }
 
-       if (!open_printer_hnd(p, handle, name, PRINTER_ACCESS_ADMINISTER)) {
+       if (!open_printer_hnd(p, handle, info2->printername, PRINTER_ACCESS_ADMINISTER)) {
                /* Handle open failed - remove addition. */
-               del_a_printer(printer->info_2->sharename);
-               free_a_printer(&printer,2);
                ZERO_STRUCTP(handle);
                return WERR_ACCESS_DENIED;
        }
 
-       update_c_setprinter(false);
-       free_a_printer(&printer,2);
-
        return WERR_OK;
 }
 
@@ -7226,7 +7372,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) {
@@ -7250,7 +7396,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;
@@ -7274,11 +7420,11 @@ 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;
-       char *driver_name = NULL;
+       const char *driver_name = NULL;
        uint32_t version;
        const char *fn;
 
@@ -7327,8 +7473,9 @@ WERROR _spoolss_AddPrinterDriverEx(pipes_struct *p,
                goto done;
        }
 
-       if (add_a_printer_driver(p->mem_ctx, r->in.info_ctr, &driver_name, &version)!=0) {
-               err = WERR_ACCESS_DENIED;
+       err = winreg_add_driver(p->mem_ctx, p->server_info,
+                                r->in.info_ctr, &driver_name, &version);
+       if (!W_ERROR_IS_OK(err)) {
                goto done;
        }
 
@@ -7339,7 +7486,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));
        }
@@ -7352,7 +7499,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;
@@ -7478,7 +7625,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;
@@ -7516,7 +7663,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;
@@ -7656,7 +7803,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;
@@ -7675,7 +7822,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);
@@ -7707,7 +7854,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;
@@ -7723,20 +7870,15 @@ 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;
-       nt_forms_struct tmpForm;
        int snum = -1;
        WERROR status = WERR_OK;
-       NT_PRINTER_INFO_LEVEL *printer = NULL;
        SE_PRIV se_printop = SE_PRINT_OPERATOR;
 
-       int count=0;
-       nt_forms_struct *list=NULL;
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
-       int i;
 
        DEBUG(5,("_spoolss_AddForm\n"));
 
@@ -7746,19 +7888,6 @@ WERROR _spoolss_AddForm(pipes_struct *p,
                return WERR_BADFID;
        }
 
-
-       /* forms can be added on printer or on the print server handle */
-
-       if ( Printer->printer_type == SPLHND_PRINTER )
-       {
-               if (!get_printer_snum(p, r->in.handle, &snum, NULL))
-                       return WERR_BADFID;
-
-               status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
-               if (!W_ERROR_IS_OK(status))
-                       goto done;
-       }
-
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
           and not a printer admin, then fail */
 
@@ -7770,8 +7899,7 @@ WERROR _spoolss_AddForm(pipes_struct *p,
                                          p->server_info->ptok,
                                          lp_printer_admin(snum))) {
                DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
-               status = WERR_ACCESS_DENIED;
-               goto done;
+               return WERR_ACCESS_DENIED;
        }
 
        switch (form->flags) {
@@ -7780,46 +7908,31 @@ WERROR _spoolss_AddForm(pipes_struct *p,
        case SPOOLSS_FORM_PRINTER:
                break;
        default:
-               status = WERR_INVALID_PARAM;
-               goto done;
-       }
-
-       /* can't add if builtin */
-
-       if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
-               status = WERR_FILE_EXISTS;
-               goto done;
-       }
-
-       count = get_ntforms(&list);
-
-       for (i=0; i < count; i++) {
-               if (strequal(form->form_name, list[i].name)) {
-                       status = WERR_FILE_EXISTS;
-                       goto done;
-               }
+               return WERR_INVALID_PARAM;
        }
 
-       if(!add_a_form(&list, form, &count)) {
-               status =  WERR_NOMEM;
-               goto done;
+       status = winreg_printer_addform1(p->mem_ctx, p->server_info,
+                                        p->msg_ctx, form);
+       if (!W_ERROR_IS_OK(status)) {
+               return status;
        }
 
-       become_root();
-       write_ntforms(&list, count);
-       unbecome_root();
-
        /*
         * ChangeID must always be set if this is a printer
         */
+       if (Printer->printer_type == SPLHND_PRINTER) {
+               if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
+                       return WERR_BADFID;
+               }
 
-       if ( Printer->printer_type == SPLHND_PRINTER )
-               status = mod_a_printer(printer, 2);
-
-done:
-       if ( printer )
-               free_a_printer(&printer, 2);
-       SAFE_FREE(list);
+               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;
+               }
+       }
 
        return status;
 }
@@ -7828,19 +7941,14 @@ done:
  _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;
-       nt_forms_struct tmpForm;
-       int count=0;
-       nt_forms_struct *list=NULL;
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
        int snum = -1;
        WERROR status = WERR_OK;
-       NT_PRINTER_INFO_LEVEL *printer = NULL;
        SE_PRIV se_printop = SE_PRINT_OPERATOR;
-       bool ret = false;
 
        DEBUG(5,("_spoolss_DeleteForm\n"));
 
@@ -7850,18 +7958,6 @@ WERROR _spoolss_DeleteForm(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       /* forms can be deleted on printer of on the print server handle */
-
-       if ( Printer->printer_type == SPLHND_PRINTER )
-       {
-               if (!get_printer_snum(p, r->in.handle, &snum, NULL))
-                       return WERR_BADFID;
-
-               status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
-               if (!W_ERROR_IS_OK(status))
-                       goto done;
-       }
-
        if ((p->server_info->utok.uid != sec_initial_uid()) &&
             !user_has_privileges(p->server_info->ptok, &se_printop) &&
             !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
@@ -7873,34 +7969,30 @@ WERROR _spoolss_DeleteForm(pipes_struct *p,
                return WERR_ACCESS_DENIED;
        }
 
-
-       /* can't delete if builtin */
-
-       if (get_a_builtin_ntform_by_string(form_name,&tmpForm)) {
-               status = WERR_INVALID_PARAM;
-               goto done;
-       }
-
-       count = get_ntforms(&list);
-
-       become_root();
-       ret = delete_a_form(&list, form_name, &count, &status);
-       unbecome_root();
-       if (ret == false) {
-               goto done;
+       status = winreg_printer_deleteform1(p->mem_ctx,
+                                           p->server_info,
+                                           p->msg_ctx,
+                                           form_name);
+       if (!W_ERROR_IS_OK(status)) {
+               return status;
        }
 
        /*
         * ChangeID must always be set if this is a printer
         */
+       if (Printer->printer_type == SPLHND_PRINTER) {
+               if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
+                       return WERR_BADFID;
+               }
 
-       if ( Printer->printer_type == SPLHND_PRINTER )
-               status = mod_a_printer(printer, 2);
-
-done:
-       if ( printer )
-               free_a_printer(&printer, 2);
-       SAFE_FREE(list);
+               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;
+               }
+       }
 
        return status;
 }
@@ -7909,18 +8001,15 @@ done:
  _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;
-       nt_forms_struct tmpForm;
+       const char *form_name = r->in.form_name;
        int snum = -1;
        WERROR status = WERR_OK;
-       NT_PRINTER_INFO_LEVEL *printer = NULL;
        SE_PRIV se_printop = SE_PRINT_OPERATOR;
 
-       int count=0;
-       nt_forms_struct *list=NULL;
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
 
        DEBUG(5,("_spoolss_SetForm\n"));
@@ -7931,18 +8020,6 @@ WERROR _spoolss_SetForm(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       /* forms can be modified on printer of on the print server handle */
-
-       if ( Printer->printer_type == SPLHND_PRINTER )
-       {
-               if (!get_printer_snum(p, r->in.handle, &snum, NULL))
-                       return WERR_BADFID;
-
-               status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
-               if (!W_ERROR_IS_OK(status))
-                       goto done;
-       }
-
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
           and not a printer admin, then fail */
 
@@ -7954,34 +8031,34 @@ WERROR _spoolss_SetForm(pipes_struct *p,
                                          p->server_info->ptok,
                                          lp_printer_admin(snum))) {
                DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
-               status = WERR_ACCESS_DENIED;
-               goto done;
+               return WERR_ACCESS_DENIED;
        }
 
-       /* can't set if builtin */
-       if (get_a_builtin_ntform_by_string(form->form_name, &tmpForm)) {
-               status = WERR_INVALID_PARAM;
-               goto done;
+       status = winreg_printer_setform1(p->mem_ctx,
+                                        p->server_info,
+                                        p->msg_ctx,
+                                        form_name,
+                                        form);
+       if (!W_ERROR_IS_OK(status)) {
+               return status;
        }
 
-       count = get_ntforms(&list);
-       update_a_form(&list, form, count);
-       become_root();
-       write_ntforms(&list, count);
-       unbecome_root();
-
        /*
         * ChangeID must always be set if this is a printer
         */
+       if (Printer->printer_type == SPLHND_PRINTER) {
+               if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
+                       return WERR_BADFID;
+               }
 
-       if ( Printer->printer_type == SPLHND_PRINTER )
-               status = mod_a_printer(printer, 2);
-
-
-done:
-       if ( printer )
-               free_a_printer(&printer, 2);
-       SAFE_FREE(list);
+               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;
+               }
+       }
 
        return status;
 }
@@ -8037,7 +8114,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;
@@ -8135,7 +8212,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;
@@ -8293,7 +8370,7 @@ out:
  _spoolss_EnumMonitors
 ****************************************************************/
 
-WERROR _spoolss_EnumMonitors(pipes_struct *p,
+WERROR _spoolss_EnumMonitors(struct pipes_struct *p,
                             struct spoolss_EnumMonitors *r)
 {
        WERROR result;
@@ -8350,7 +8427,7 @@ WERROR _spoolss_EnumMonitors(pipes_struct *p,
 static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
                             const print_queue_struct *queue,
                             int count, int snum,
-                            const NT_PRINTER_INFO_LEVEL *ntprinter,
+                            struct spoolss_PrinterInfo2 *pinfo2,
                             uint32_t jobid,
                             struct spoolss_JobInfo1 *r)
 {
@@ -8374,7 +8451,7 @@ static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
                              &queue[i],
                              i,
                              snum,
-                             ntprinter);
+                             pinfo2);
 }
 
 /****************************************************************************
@@ -8383,13 +8460,14 @@ static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
 static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
                             const print_queue_struct *queue,
                             int count, int snum,
-                            const NT_PRINTER_INFO_LEVEL *ntprinter,
+                            struct spoolss_PrinterInfo2 *pinfo2,
                             uint32_t jobid,
                             struct spoolss_JobInfo2 *r)
 {
        int i = 0;
        bool found = false;
        struct spoolss_DeviceMode *devmode;
+       WERROR result;
 
        for (i=0; i<count; i++) {
                if (queue[i].job == (int)jobid) {
@@ -8412,8 +8490,13 @@ static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
 
        devmode = print_job_devmode(lp_const_servicename(snum), jobid);
        if (!devmode) {
-               devmode = construct_dev_mode(mem_ctx, lp_const_servicename(snum));
-               W_ERROR_HAVE_NO_MEMORY(devmode);
+               result = spoolss_create_default_devmode(mem_ctx,
+                                               pinfo2->printername,
+                                               &devmode);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(3, ("Can't proceed w/o a devmode!"));
+                       return result;
+               }
        }
 
        return fill_job_info2(mem_ctx,
@@ -8421,7 +8504,7 @@ static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
                              &queue[i],
                              i,
                              snum,
-                             ntprinter,
+                             pinfo2,
                              devmode);
 }
 
@@ -8429,11 +8512,11 @@ 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;
-       NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
+       struct spoolss_PrinterInfo2 *pinfo2 = NULL;
        int snum;
        int count;
        print_queue_struct      *queue = NULL;
@@ -8453,7 +8536,8 @@ WERROR _spoolss_GetJob(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = get_a_printer(NULL, &ntprinter, 2, lp_servicename(snum));
+       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;
        }
@@ -8466,12 +8550,12 @@ WERROR _spoolss_GetJob(pipes_struct *p,
        switch (r->in.level) {
        case 1:
                result = getjob_level_1(p->mem_ctx,
-                                       queue, count, snum, ntprinter,
+                                       queue, count, snum, pinfo2,
                                        r->in.job_id, &r->out.info->info1);
                break;
        case 2:
                result = getjob_level_2(p->mem_ctx,
-                                       queue, count, snum, ntprinter,
+                                       queue, count, snum, pinfo2,
                                        r->in.job_id, &r->out.info->info2);
                break;
        default:
@@ -8480,7 +8564,7 @@ WERROR _spoolss_GetJob(pipes_struct *p,
        }
 
        SAFE_FREE(queue);
-       free_a_printer(&ntprinter, 2);
+       TALLOC_FREE(pinfo2);
 
        if (!W_ERROR_IS_OK(result)) {
                TALLOC_FREE(r->out.info);
@@ -8498,7 +8582,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)
 {
 
@@ -8578,6 +8662,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)) {
@@ -8592,6 +8677,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,
@@ -8620,7 +8706,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;
@@ -8664,7 +8750,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);
@@ -8684,6 +8770,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,
@@ -8709,6 +8796,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,
@@ -8719,6 +8807,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));
 
        }
@@ -8732,10 +8821,10 @@ done:
  _spoolss_DeletePrinterDataEx
 ****************************************************************/
 
-WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
+WERROR _spoolss_DeletePrinterDataEx(struct pipes_struct *p,
                                    struct spoolss_DeletePrinterDataEx *r)
 {
-       NT_PRINTER_INFO_LEVEL   *printer = NULL;
+       const char *printer;
        int             snum=0;
        WERROR          status = WERR_OK;
        Printer_entry   *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -8749,9 +8838,6 @@ WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       if (!get_printer_snum(p, r->in.handle, &snum, NULL))
-               return WERR_BADFID;
-
        if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
                DEBUG(3, ("_spoolss_DeletePrinterDataEx: "
                        "printer properties change denied by handle\n"));
@@ -8762,16 +8848,23 @@ WERROR _spoolss_DeletePrinterDataEx(pipes_struct *p,
                return WERR_NOMEM;
        }
 
-       status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
-       if (!W_ERROR_IS_OK(status))
-               return status;
-
-       status = delete_printer_dataex( printer, r->in.key_name, r->in.value_name );
-
-       if ( W_ERROR_IS_OK(status) )
-               mod_a_printer( printer, 2 );
+       if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
+               return WERR_BADFID;
+       }
+       printer = lp_const_servicename(snum);
 
-       free_a_printer(&printer, 2);
+       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);
+       }
 
        return status;
 }
@@ -8780,17 +8873,13 @@ 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)
 {
-       fstring         *keynames = NULL;
-       int             num_keys;
+       uint32_t        num_keys;
        Printer_entry   *Printer = find_printer_index_by_hnd(p, r->in.handle);
-       NT_PRINTER_DATA *data;
-       NT_PRINTER_INFO_LEVEL   *printer = NULL;
        int             snum = 0;
        WERROR          result = WERR_BADFILE;
-       int i;
        const char **array = NULL;
        DATA_BLOB blob;
 
@@ -8806,47 +8895,17 @@ WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
                return WERR_BADFID;
        }
 
-       result = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
+       result = winreg_enum_printer_key(p->mem_ctx,
+                                        p->server_info,
+                                        p->msg_ctx,
+                                        lp_const_servicename(snum),
+                                        r->in.key_name,
+                                        &num_keys,
+                                        &array);
        if (!W_ERROR_IS_OK(result)) {
-               return result;
-       }
-
-       /* get the list of subkey names */
-
-       data = printer->info_2->data;
-
-       num_keys = get_printer_subkeys(data, r->in.key_name, &keynames);
-       if (num_keys == -1) {
-               result = WERR_BADFILE;
-               goto done;
-       }
-
-       array = talloc_zero_array(r->out.key_buffer, const char *, num_keys + 2);
-       if (!array) {
-               result = WERR_NOMEM;
                goto done;
        }
 
-       if (!num_keys) {
-               array[0] = talloc_strdup(array, "");
-               if (!array[0]) {
-                       result = WERR_NOMEM;
-                       goto done;
-               }
-       }
-
-       for (i=0; i < num_keys; i++) {
-
-               DEBUG(10,("_spoolss_EnumPrinterKey: adding keyname: %s\n",
-                       keynames[i]));
-
-               array[i] = talloc_strdup(array, keynames[i]);
-               if (!array[i]) {
-                       result = WERR_NOMEM;
-                       goto done;
-               }
-       }
-
        if (!push_reg_multi_sz(p->mem_ctx, &blob, array)) {
                result = WERR_NOMEM;
                goto done;
@@ -8870,9 +8929,6 @@ WERROR _spoolss_EnumPrinterKey(pipes_struct *p,
                }
        }
 
-       free_a_printer(&printer, 2);
-       SAFE_FREE(keynames);
-
        return result;
 }
 
@@ -8880,13 +8936,13 @@ 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);
-       NT_PRINTER_INFO_LEVEL   *printer = NULL;
        int                     snum=0;
        WERROR                  status;
+       const char *printer;
 
        DEBUG(5,("_spoolss_DeletePrinterKey\n"));
 
@@ -8897,12 +8953,12 @@ WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
        }
 
        /* if keyname == NULL, return error */
-
        if ( !r->in.key_name )
                return WERR_INVALID_PARAM;
 
-       if (!get_printer_snum(p, r->in.handle, &snum, NULL))
+       if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
                return WERR_BADFID;
+       }
 
        if (Printer->access_granted != PRINTER_ACCESS_ADMINISTER) {
                DEBUG(3, ("_spoolss_DeletePrinterKey: "
@@ -8910,18 +8966,20 @@ WERROR _spoolss_DeletePrinterKey(pipes_struct *p,
                return WERR_ACCESS_DENIED;
        }
 
-       status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
-       if (!W_ERROR_IS_OK(status))
-               return status;
-
-       /* delete the key and all subneys */
-
-       status = delete_all_printer_data( printer->info_2, r->in.key_name );
-
-       if ( W_ERROR_IS_OK(status) )
-               status = mod_a_printer(printer, 2);
+       printer = lp_const_servicename(snum);
 
-       free_a_printer( &printer, 2 );
+       /* 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);
+       }
 
        return status;
 }
@@ -8930,7 +8988,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;
@@ -8970,6 +9028,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,
@@ -9039,7 +9098,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;
@@ -9326,7 +9385,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);
@@ -9399,7 +9458,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
@@ -9414,7 +9473,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 */
@@ -9426,7 +9485,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;
@@ -9437,7 +9496,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;
@@ -9448,7 +9507,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;
@@ -9459,7 +9518,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;
@@ -9470,7 +9529,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;
@@ -9481,7 +9540,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;
@@ -9492,7 +9551,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;
@@ -9503,7 +9562,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;
@@ -9514,7 +9573,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;
@@ -9525,7 +9584,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;
@@ -9536,7 +9595,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;
@@ -9547,7 +9606,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;
@@ -9558,7 +9617,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;
@@ -9569,7 +9628,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;
@@ -9580,7 +9639,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;
@@ -9591,7 +9650,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;
@@ -9602,7 +9661,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;
@@ -9613,7 +9672,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;
@@ -9624,7 +9683,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;
@@ -9635,7 +9694,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;
@@ -9646,7 +9705,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;
@@ -9657,7 +9716,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;
@@ -9668,7 +9727,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;
@@ -9679,7 +9738,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;
@@ -9690,7 +9749,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;
@@ -9701,7 +9760,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;
@@ -9712,7 +9771,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;
@@ -9723,7 +9782,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;
@@ -9734,7 +9793,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;
@@ -9745,7 +9804,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;
@@ -9756,7 +9815,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;
@@ -9767,7 +9826,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;
@@ -9778,7 +9837,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;
@@ -9789,7 +9848,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;
@@ -9800,7 +9859,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;
@@ -9811,7 +9870,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;
@@ -9822,7 +9881,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;
@@ -9833,7 +9892,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;
@@ -9844,7 +9903,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;
@@ -9855,7 +9914,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;
@@ -9866,7 +9925,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;
@@ -9877,7 +9936,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;
@@ -9888,7 +9947,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;
@@ -9899,7 +9958,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;
@@ -9910,7 +9969,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;
@@ -9921,7 +9980,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;
@@ -9932,7 +9991,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;
@@ -9943,7 +10002,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;
@@ -9954,7 +10013,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;
@@ -9965,7 +10024,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;
@@ -9976,7 +10035,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;
@@ -9987,7 +10046,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;
@@ -9998,7 +10057,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;
@@ -10009,7 +10068,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;
@@ -10020,7 +10079,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;
@@ -10031,7 +10090,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;