s3/rpc_server/spoolss: remove SETUP_SPOOLSS_NOTIFY_DATA_SECDESC
[samba.git] / source3 / rpc_server / spoolss / srv_spoolss_nt.c
index 0f9bfb701a6a32083e7941382e32c0e3c3853cc9..588aae4eb902c995ffaca9c5b053c554d90b8939 100644 (file)
@@ -38,7 +38,6 @@
 #include "../libcli/security/security.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"
@@ -56,6 +55,7 @@
 #include "printing/printer_list.h"
 #include "../lib/tsocket/tsocket.h"
 #include "rpc_client/cli_winreg_spoolss.h"
+#include "../libcli/smb/smbXcli_base.h"
 
 /* macros stolen from s4 spoolss server */
 #define SPOOLSS_BUFFER_UNION(fn,info,level) \
@@ -138,7 +138,7 @@ struct notify_back_channel {
 
        /* print notify back-channel pipe handle*/
        struct rpc_pipe_client *cli_pipe;
-       struct dcerpc_binding_handle *binding_handle;
+       struct cli_state *cli;
        uint32_t active_connections;
 };
 
@@ -251,6 +251,8 @@ static void srv_spoolss_replycloseprinter(int snum,
 
        /* weird if the test succeeds !!! */
        if (prn_hnd->notify.cli_chan == NULL ||
+           prn_hnd->notify.cli_chan->cli_pipe == NULL ||
+           prn_hnd->notify.cli_chan->cli_pipe->binding_handle == NULL ||
            prn_hnd->notify.cli_chan->active_connections == 0) {
                DEBUG(0, ("Trying to close unexisting backchannel!\n"));
                DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
@@ -259,7 +261,7 @@ static void srv_spoolss_replycloseprinter(int snum,
        }
 
        status = dcerpc_spoolss_ReplyClosePrinter(
-                                       prn_hnd->notify.cli_chan->binding_handle,
+                                       prn_hnd->notify.cli_chan->cli_pipe->binding_handle,
                                        talloc_tos(),
                                        &prn_hnd->notify.cli_hnd,
                                        &result);
@@ -275,8 +277,7 @@ static void srv_spoolss_replycloseprinter(int snum,
        /* if it's the last connection, deconnect the IPC$ share */
        if (prn_hnd->notify.cli_chan->active_connections == 1) {
 
-               prn_hnd->notify.cli_chan->binding_handle = NULL;
-               cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
+               cli_shutdown(prn_hnd->notify.cli_chan->cli);
                DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
                TALLOC_FREE(prn_hnd->notify.cli_chan);
 
@@ -288,6 +289,7 @@ static void srv_spoolss_replycloseprinter(int snum,
 
        if (prn_hnd->notify.cli_chan) {
                prn_hnd->notify.cli_chan->active_connections--;
+               prn_hnd->notify.cli_chan = NULL;
        }
 }
 
@@ -373,7 +375,7 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
                                  const char *sharename,
                                  struct messaging_context *msg_ctx)
 {
-       char *cmd = lp_deleteprinter_cmd();
+       char *cmd = lp_deleteprinter_command(talloc_tos());
        char *command = NULL;
        int ret;
        bool is_print_op = false;
@@ -416,14 +418,6 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
        if (ret != 0)
                return WERR_BADFID; /* What to return here? */
 
-       /* go ahead and re-read the services immediately */
-       become_root();
-       reload_services(msg_ctx, -1, false);
-       unbecome_root();
-
-       if ( lp_servicenumber( sharename ) >= 0 )
-               return WERR_ACCESS_DENIED;
-
        return WERR_OK;
 }
 
@@ -637,16 +631,17 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
 
        cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
                                    aprinter);
-       if ((cache_key != NULL) && gencache_get(cache_key, &tmp, NULL)) {
+       if ((cache_key != NULL) &&
+           gencache_get(cache_key, talloc_tos(), &tmp, NULL)) {
 
                found = (strcmp(tmp, printer_not_found) != 0);
                if (!found) {
                        DEBUG(4, ("Printer %s not found\n", aprinter));
-                       SAFE_FREE(tmp);
+                       TALLOC_FREE(tmp);
                        return WERR_INVALID_PRINTER_NAME;
                }
                fstrcpy(sname, tmp);
-               SAFE_FREE(tmp);
+               TALLOC_FREE(tmp);
        }
 
        /* Search all sharenames first as this is easier than pulling
@@ -658,7 +653,7 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
                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))) {
+               if (!(lp_snum_ok(snum) && lp_printable(snum))) {
                        continue;
                }
 
@@ -851,14 +846,6 @@ static bool is_monitoring_event(struct printer_handle *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, _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 = \
-               ndr_size_security_descriptor(_data->data.sd.sd, 0);
-
 static void init_systemtime_buffer(TALLOC_CTX *mem_ctx,
                                   struct tm *t,
                                   const char **pp,
@@ -1246,6 +1233,8 @@ static int send_notify2_printer(TALLOC_CTX *mem_ctx,
 
        /* Is there notification on this handle? */
        if (prn_hnd->notify.cli_chan == NULL ||
+           prn_hnd->notify.cli_chan->cli_pipe == NULL ||
+           prn_hnd->notify.cli_chan->cli_pipe->binding_handle == NULL ||
            prn_hnd->notify.cli_chan->active_connections == 0) {
                return 0;
        }
@@ -1278,7 +1267,7 @@ static int send_notify2_printer(TALLOC_CTX *mem_ctx,
        info.info0 = &info0;
 
        status = dcerpc_spoolss_RouterReplyPrinterEx(
-                               prn_hnd->notify.cli_chan->binding_handle,
+                               prn_hnd->notify.cli_chan->cli_pipe->binding_handle,
                                mem_ctx,
                                &prn_hnd->notify.cli_hnd,
                                prn_hnd->notify.change, /* color */
@@ -1518,6 +1507,7 @@ void srv_spoolss_cleanup(void)
 /**********************************************************************
  callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
  over all printers, upgrading ones as necessary
+ This is now *ONLY* called inside the background lpq updater. JRA.
  **********************************************************************/
 
 void do_drv_upgrade_printer(struct messaging_context *msg,
@@ -1550,7 +1540,7 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
        /* Iterate the printer list */
 
        for (snum = 0; snum < n_services; snum++) {
-               if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
+               if (!lp_snum_ok(snum) || !lp_printable(snum)) {
                        continue;
                }
 
@@ -1637,15 +1627,17 @@ WERROR _spoolss_OpenPrinter(struct pipes_struct *p,
                            struct spoolss_OpenPrinter *r)
 {
        struct spoolss_OpenPrinterEx e;
+       struct spoolss_UserLevel1 level1;
        WERROR werr;
 
-       ZERO_STRUCT(e.in.userlevel);
+       ZERO_STRUCT(level1);
 
        e.in.printername        = r->in.printername;
        e.in.datatype           = r->in.datatype;
        e.in.devmode_ctr        = r->in.devmode_ctr;
        e.in.access_mask        = r->in.access_mask;
-       e.in.level              = 0;
+       e.in.userlevel_ctr.level                = 1;
+       e.in.userlevel_ctr.user_info.level1     = &level1;
 
        e.out.handle            = r->out.handle;
 
@@ -1715,12 +1707,16 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
                return WERR_INVALID_PARAM;
        }
 
-       if (r->in.level > 3) {
+       if (!*r->in.printername) {
                return WERR_INVALID_PARAM;
        }
-       if ((r->in.level == 1 && !r->in.userlevel.level1) ||
-           (r->in.level == 2 && !r->in.userlevel.level2) ||
-           (r->in.level == 3 && !r->in.userlevel.level3)) {
+
+       if (r->in.userlevel_ctr.level > 3) {
+               return WERR_INVALID_PARAM;
+       }
+       if ((r->in.userlevel_ctr.level == 1 && !r->in.userlevel_ctr.user_info.level1) ||
+           (r->in.userlevel_ctr.level == 2 && !r->in.userlevel_ctr.user_info.level2) ||
+           (r->in.userlevel_ctr.level == 3 && !r->in.userlevel_ctr.user_info.level3)) {
                return WERR_INVALID_PARAM;
        }
 
@@ -1731,7 +1727,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
        result = open_printer_hnd(p, r->out.handle, r->in.printername, 0);
        if (!W_ERROR_IS_OK(result)) {
-               DEBUG(0,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
+               DEBUG(3,("_spoolss_OpenPrinterEx: Cannot open a printer handle "
                        "for printer %s\n", r->in.printername));
                ZERO_STRUCTP(r->out.handle);
                return result;
@@ -1801,7 +1797,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
                if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
                {
-                       if (!lp_ms_add_printer_wizard()) {
+                       if (!lp_show_add_printer_wizard()) {
                                close_printer_handle(p, r->out.handle);
                                ZERO_STRUCTP(r->out.handle);
                                return WERR_ACCESS_DENIED;
@@ -1812,13 +1808,8 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
                        if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
                            !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
-                           !nt_token_check_sid(&global_sid_Builtin_Print_Operators, p->session_info->security_token) &&
-                           !token_contains_name_in_list(
-                                   uidtoname(p->session_info->unix_token->uid),
-                                   p->session_info->info->domain_name,
-                                   NULL,
-                                   p->session_info->security_token,
-                                   lp_printer_admin(snum))) {
+                           !nt_token_check_sid(&global_sid_Builtin_Print_Operators,
+                                               p->session_info->security_token)) {
                                close_printer_handle(p, r->out.handle);
                                ZERO_STRUCTP(r->out.handle);
                                DEBUG(3,("access DENIED as user is not root, "
@@ -1890,7 +1881,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
                        rhost = raddr;
                }
 
-               if (!allow_access(lp_hostsdeny(snum), lp_hostsallow(snum),
+               if (!allow_access(lp_hosts_deny(snum), lp_hosts_allow(snum),
                                  rhost, raddr)) {
                        DEBUG(3, ("access DENIED (hosts allow/deny) for printer open\n"));
                        ZERO_STRUCTP(r->out.handle);
@@ -1899,10 +1890,10 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
                if (!user_ok_token(uidtoname(p->session_info->unix_token->uid), NULL,
                                   p->session_info->security_token, snum) ||
-                   !print_access_check(p->session_info,
-                                       p->msg_ctx,
-                                       snum,
-                                       r->in.access_mask)) {
+                   !W_ERROR_IS_OK(print_access_check(p->session_info,
+                                                     p->msg_ctx,
+                                                     snum,
+                                                     r->in.access_mask))) {
                        DEBUG(3, ("access DENIED for printer open\n"));
                        close_printer_handle(p, r->out.handle);
                        ZERO_STRUCTP(r->out.handle);
@@ -1944,24 +1935,12 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
         * save it here in case we get a job submission on this handle
         */
 
-        if ((Printer->printer_type != SPLHND_SERVER) &&
-            r->in.devmode_ctr.devmode) {
+        if ((Printer->printer_type != SPLHND_SERVER)
+         && (r->in.devmode_ctr.devmode != NULL)) {
                copy_devicemode(NULL, r->in.devmode_ctr.devmode,
                                &Printer->devmode);
         }
 
-#if 0  /* JERRY -- I'm doubtful this is really effective */
-       /* HACK ALERT!!! Sleep for 1/3 of a second to try trigger a LAN/WAN
-          optimization in Windows 2000 clients  --jerry */
-
-       if ( (r->in.access_mask == PRINTER_ACCESS_ADMINISTER)
-               && (RA_WIN2K == get_remote_arch()) )
-       {
-               DEBUG(10,("_spoolss_OpenPrinterEx: Enabling LAN/WAN hack for Win2k clients.\n"));
-               sys_usleep( 500000 );
-       }
-#endif
-
        return WERR_OK;
 }
 
@@ -2044,6 +2023,12 @@ static const struct print_architecture_table_node archi_table[]= {
        {NULL,                   "",            -1 }
 };
 
+static const int drv_cversion[] = {SPOOLSS_DRIVER_VERSION_9X,
+                                  SPOOLSS_DRIVER_VERSION_NT35,
+                                  SPOOLSS_DRIVER_VERSION_NT4,
+                                  SPOOLSS_DRIVER_VERSION_200X,
+                                  -1};
+
 static int get_version_id(const char *arch)
 {
        int i;
@@ -2066,24 +2051,19 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
 {
 
        struct spoolss_DriverInfo8 *info = NULL;
-       struct spoolss_DriverInfo8 *info_win2k = NULL;
        int                             version;
        WERROR                          status;
        struct dcerpc_binding_handle *b;
        TALLOC_CTX *tmp_ctx = NULL;
+       int i;
+       bool found;
 
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
           and not a printer admin, then fail */
 
-       if ( (p->session_info->unix_token->uid != sec_initial_uid())
-            && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
-               && !token_contains_name_in_list(
-                       uidtoname(p->session_info->unix_token->uid),
-                       p->session_info->info->domain_name,
-                       NULL,
-                       p->session_info->security_token,
-                       lp_printer_admin(-1)) )
-       {
+       if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
+           !security_token_has_privilege(p->session_info->security_token,
+                                         SEC_PRIV_PRINT_OPERATOR)) {
                return WERR_ACCESS_DENIED;
        }
 
@@ -2106,64 +2086,100 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
                goto done;
        }
 
-       status = winreg_get_driver(tmp_ctx, b,
-                                  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;
-
-                       status = winreg_get_driver(tmp_ctx, b,
-                                                  r->in.architecture,
-                                                  r->in.driver,
-                                                  version, &info);
-                       if (!W_ERROR_IS_OK(status)) {
-                               status = WERR_UNKNOWN_PRINTER_DRIVER;
-                               goto done;
-                       }
+       for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
+               status = winreg_get_driver(tmp_ctx, b,
+                                          r->in.architecture, r->in.driver,
+                                          drv_cversion[i], &info);
+               if (!W_ERROR_IS_OK(status)) {
+                       DEBUG(5, ("skipping del of driver with version %d\n",
+                                 drv_cversion[i]));
+                       continue;
                }
-               /* otherwise it was a failure */
-               else {
-                       status = WERR_UNKNOWN_PRINTER_DRIVER;
+               found = true;
+
+               if (printer_driver_in_use(tmp_ctx, b, info)) {
+                       status = WERR_PRINTER_DRIVER_IN_USE;
                        goto done;
                }
 
+               status = winreg_del_driver(tmp_ctx, b, info, drv_cversion[i]);
+               if (!W_ERROR_IS_OK(status)) {
+                       DEBUG(0, ("failed del of driver with version %d\n",
+                                 drv_cversion[i]));
+                       goto done;
+               }
        }
+       if (found == false) {
+               DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
+               status = WERR_UNKNOWN_PRINTER_DRIVER;
+       } else {
+               status = WERR_OK;
+       }
+
+done:
+       talloc_free(tmp_ctx);
+
+       return status;
+}
 
-       if (printer_driver_in_use(tmp_ctx,
-                                 b,
-                                 info)) {
+static WERROR spoolss_dpd_version(TALLOC_CTX *mem_ctx,
+                                 struct pipes_struct *p,
+                                 struct spoolss_DeletePrinterDriverEx *r,
+                                 struct dcerpc_binding_handle *b,
+                                 struct spoolss_DriverInfo8 *info)
+{
+       WERROR status;
+       bool delete_files;
+
+       if (printer_driver_in_use(mem_ctx, b, info)) {
                status = WERR_PRINTER_DRIVER_IN_USE;
                goto done;
        }
 
-       if (version == 2) {
-               status = winreg_get_driver(tmp_ctx, b,
-                                          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 = winreg_del_driver(tmp_ctx, b,
-                                                  info_win2k, 3);
-                       talloc_free(info_win2k);
-
-                       /* this should not have failed---if it did, report to client */
-                       if (!W_ERROR_IS_OK(status)) {
-                               goto done;
-                       }
+       /*
+        * we have a couple of cases to consider.
+        * (1) Are any files in use?  If so and DPD_DELETE_ALL_FILES is set,
+        *     then the delete should fail if **any** files overlap with
+        *     other drivers
+        * (2) If DPD_DELETE_UNUSED_FILES is set, then delete all
+        *     non-overlapping files
+        * (3) If neither DPD_DELETE_ALL_FILES nor DPD_DELETE_UNUSED_FILES
+        *     are set, then do not delete any files
+        * Refer to MSDN docs on DeletePrinterDriverEx() for details.
+        */
+
+       delete_files = r->in.delete_flags
+                       & (DPD_DELETE_ALL_FILES | DPD_DELETE_UNUSED_FILES);
+
+
+       if (delete_files) {
+               bool in_use = printer_driver_files_in_use(mem_ctx, b, info);
+               if (in_use && (r->in.delete_flags & DPD_DELETE_ALL_FILES)) {
+                       status = WERR_PRINTER_DRIVER_IN_USE;
+                       goto done;
                }
+               /*
+                * printer_driver_files_in_use() has trimmed overlapping files
+                * from info so they are not removed on DPD_DELETE_UNUSED_FILES
+                */
        }
 
-       status = winreg_del_driver(tmp_ctx, b,
-                                  info, version);
 
-done:
-       talloc_free(tmp_ctx);
+       status = winreg_del_driver(mem_ctx, b, info, info->version);
+       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->session_info, info);
+       }
+
+done:
        return status;
 }
 
@@ -2174,38 +2190,28 @@ done:
 WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                                      struct spoolss_DeletePrinterDriverEx *r)
 {
-       struct spoolss_DriverInfo8      *info = NULL;
-       struct spoolss_DriverInfo8      *info_win2k = NULL;
-       int                             version;
-       bool                            delete_files;
+       struct spoolss_DriverInfo8 *info = NULL;
        WERROR                          status;
        struct dcerpc_binding_handle *b;
        TALLOC_CTX *tmp_ctx = NULL;
+       int i;
+       bool found;
 
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
           and not a printer admin, then fail */
 
-       if ( (p->session_info->unix_token->uid != sec_initial_uid())
-               && !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR)
-               && !token_contains_name_in_list(
-                       uidtoname(p->session_info->unix_token->uid),
-                       p->session_info->info->domain_name,
-                       NULL,
-                       p->session_info->security_token, lp_printer_admin(-1)) )
-       {
+       if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
+           !security_token_has_privilege(p->session_info->security_token,
+                                         SEC_PRIV_PRINT_OPERATOR)) {
                return WERR_ACCESS_DENIED;
        }
 
        /* check that we have a valid driver name first */
-       if ((version = get_version_id(r->in.architecture)) == -1) {
+       if (get_version_id(r->in.architecture) == -1) {
                /* this is what NT returns */
                return WERR_INVALID_ENVIRONMENT;
        }
 
-       if (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) {
-               version = r->in.version;
-       }
-
        tmp_ctx = talloc_new(p->mem_ctx);
        if (!tmp_ctx) {
                return WERR_NOMEM;
@@ -2219,128 +2225,35 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
                goto done;
        }
 
-       status = winreg_get_driver(tmp_ctx, b,
-                                  r->in.architecture,
-                                  r->in.driver,
-                                  version,
-                                  &info);
-       if (!W_ERROR_IS_OK(status)) {
-               status = WERR_UNKNOWN_PRINTER_DRIVER;
-
-               /*
-                * if the client asked for a specific version,
-                * or this is something other than Windows NT x86,
-                * then we've failed
-                */
-
-               if ( (r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) || (version !=2) )
-                       goto done;
-
-               /* try for Win2k driver if "Windows NT x86" */
+       for (found = false, i = 0; drv_cversion[i] >= 0; i++) {
+               if ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION)
+                && (drv_cversion[i] != r->in.version)) {
+                       continue;
+               }
 
-               version = 3;
+               /* check if a driver with this version exists before delete */
                status = winreg_get_driver(tmp_ctx, b,
-                                          r->in.architecture,
-                                          r->in.driver,
-                                          version, &info);
+                                          r->in.architecture, r->in.driver,
+                                          drv_cversion[i], &info);
                if (!W_ERROR_IS_OK(status)) {
-                       status = WERR_UNKNOWN_PRINTER_DRIVER;
-                       goto done;
+                       DEBUG(5, ("skipping del of driver with version %d\n",
+                                 drv_cversion[i]));
+                       continue;
                }
-       }
-
-       if (printer_driver_in_use(tmp_ctx,
-                                 b,
-                                 info)) {
-               status = WERR_PRINTER_DRIVER_IN_USE;
-               goto done;
-       }
-
-       /*
-        * we have a couple of cases to consider.
-        * (1) Are any files in use?  If so and DPD_DELTE_ALL_FILE is set,
-        *     then the delete should fail if **any** files overlap with
-        *     other drivers
-        * (2) If DPD_DELTE_UNUSED_FILES is sert, then delete all
-        *     non-overlapping files
-        * (3) If neither DPD_DELTE_ALL_FILE nor DPD_DELTE_ALL_FILES
-        *     is set, the do not delete any files
-        * Refer to MSDN docs on DeletePrinterDriverEx() for details.
-        */
-
-       delete_files = r->in.delete_flags & (DPD_DELETE_ALL_FILES|DPD_DELETE_UNUSED_FILES);
-
-       /* fail if any files are in use and DPD_DELETE_ALL_FILES is set */
-
-       if (delete_files &&
-           (r->in.delete_flags & DPD_DELETE_ALL_FILES) &&
-           printer_driver_files_in_use(tmp_ctx,
-                                       b,
-                                       info)) {
-               /* no idea of the correct error here */
-               status = WERR_ACCESS_DENIED;
-               goto done;
-       }
-
-
-       /* also check for W32X86/3 if necessary; maybe we already have? */
-
-       if ( (version == 2) && ((r->in.delete_flags & DPD_DELETE_SPECIFIC_VERSION) != DPD_DELETE_SPECIFIC_VERSION)  ) {
-               status = winreg_get_driver(tmp_ctx, b,
-                                          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,
-                                                       b,
-                                                       info_win2k)) {
-                               /* no idea of the correct error here */
-                               talloc_free(info_win2k);
-                               status = WERR_ACCESS_DENIED;
-                               goto done;
-                       }
-
-                       /* if we get to here, we now have 2 driver info structures to remove */
-                       /* remove the Win2k driver first*/
-
-                       status = winreg_del_driver(tmp_ctx, b,
-                                                  info_win2k,
-                                                  3);
-
-                       /* this should not have failed---if it did, report to client */
-
-                       if (!W_ERROR_IS_OK(status)) {
-                               goto done;
-                       }
+               found = true;
 
-                       /*
-                        * 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(get_session_info_system(),
-                                                   info_win2k);
-                       }
+               status = spoolss_dpd_version(tmp_ctx, p, r, b, info);
+               if (!W_ERROR_IS_OK(status)) {
+                       DEBUG(0, ("failed to delete driver with version %d\n",
+                                 drv_cversion[i]));
+                       goto done;
                }
        }
-
-       status = winreg_del_driver(tmp_ctx, b,
-                                  info,
-                                  version);
-       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(get_session_info_system(), info);
+       if (found == false) {
+               DEBUG(0, ("driver %s not found for deletion\n", r->in.driver));
+               status = WERR_UNKNOWN_PRINTER_DRIVER;
+       } else {
+               status = WERR_OK;
        }
 
 done:
@@ -2362,26 +2275,26 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
 
        if (!strcasecmp_m(value, "W3SvcInstalled")) {
                *type = REG_DWORD;
-               data->value = 0x00;
+               SIVAL(&data->value, 0, 0x00);
                return WERR_OK;
        }
 
        if (!strcasecmp_m(value, "BeepEnabled")) {
                *type = REG_DWORD;
-               data->value = 0x00;
+               SIVAL(&data->value, 0, 0x00);
                return WERR_OK;
        }
 
        if (!strcasecmp_m(value, "EventLog")) {
                *type = REG_DWORD;
                /* formally was 0x1b */
-               data->value = 0x00;
+               SIVAL(&data->value, 0, 0x00);
                return WERR_OK;
        }
 
        if (!strcasecmp_m(value, "NetPopup")) {
                *type = REG_DWORD;
-               data->value = 0x00;
+               SIVAL(&data->value, 0, 0x00);
                return WERR_OK;
        }
 
@@ -2394,9 +2307,9 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
                   -- jerry */
 
                if (RA_WINNT == get_remote_arch()) {
-                       data->value = 0x02;
+                       SIVAL(&data->value, 0, 0x02);
                } else {
-                       data->value = 0x03;
+                       SIVAL(&data->value, 0, 0x03);
                }
 
                return WERR_OK;
@@ -2404,7 +2317,7 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
 
        if (!strcasecmp_m(value, "MinorVersion")) {
                *type = REG_DWORD;
-               data->value = 0x00;
+               SIVAL(&data->value, 0, 0x00);
                return WERR_OK;
        }
 
@@ -2420,9 +2333,13 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
                enum ndr_err_code ndr_err;
                struct spoolss_OSVersion os;
 
-               os.major                = 5;    /* Windows 2000 == 5.0 */
-               os.minor                = 0;
-               os.build                = 2195; /* build */
+               os.major                = lp_parm_int(GLOBAL_SECTION_SNUM,
+                                                     "spoolss", "os_major", 5);
+                                                     /* Windows 2000 == 5.0 */
+               os.minor                = lp_parm_int(GLOBAL_SECTION_SNUM,
+                                                     "spoolss", "os_minor", 0);
+               os.build                = lp_parm_int(GLOBAL_SECTION_SNUM,
+                                                     "spoolss", "os_build", 2195);
                os.extra_string         = "";   /* leave extra string empty */
 
                ndr_err = ndr_push_struct_blob(&blob, mem_ctx, &os,
@@ -2431,6 +2348,10 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
                        return WERR_GENERAL_FAILURE;
                }
 
+               if (DEBUGLEVEL >= 10) {
+                       NDR_PRINT_DEBUG(spoolss_OSVersion, &os);
+               }
+
                *type = REG_BINARY;
                data->binary = blob;
 
@@ -2463,9 +2384,9 @@ static WERROR getprinterdata_printer_server(TALLOC_CTX *mem_ctx,
                   member of a AD domain */
 
                if (lp_security() == SEC_ADS) {
-                       data->value = 0x01;
+                       SIVAL(&data->value, 0, 0x01);
                } else {
-                       data->value = 0x00;
+                       SIVAL(&data->value, 0, 0x00);
                }
                return WERR_OK;
        }
@@ -2513,11 +2434,10 @@ WERROR _spoolss_GetPrinterData(struct pipes_struct *p,
  Connect to the client machine.
 **********************************************************/
 
-static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
-                       struct sockaddr_storage *client_ss, const char *remote_machine)
+static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe, struct cli_state **pp_cli,
+                                     struct sockaddr_storage *client_ss, const char *remote_machine)
 {
        NTSTATUS ret;
-       struct cli_state *the_cli;
        struct sockaddr_storage rm_addr;
        char addr[INET6_ADDRSTRLEN];
 
@@ -2543,7 +2463,7 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
        }
 
        /* setup the connection */
-       ret = cli_full_connection( &the_cli, lp_netbios_name(), remote_machine,
+       ret = cli_full_connection( pp_cli, lp_netbios_name(), remote_machine,
                &rm_addr, 0, "IPC$", "IPC",
                "", /* username */
                "", /* domain */
@@ -2556,9 +2476,9 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
                return false;
        }
 
-       if ( cli_state_protocol(the_cli) != PROTOCOL_NT1 ) {
+       if ( smbXcli_conn_protocol((*pp_cli)->conn) != PROTOCOL_NT1 ) {
                DEBUG(0,("spoolss_connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
-               cli_shutdown(the_cli);
+               cli_shutdown(*pp_cli);
                return false;
        }
 
@@ -2567,11 +2487,11 @@ static bool spoolss_connect_to_client(struct rpc_pipe_client **pp_pipe,
         * Now start the NT Domain stuff :-).
         */
 
-       ret = cli_rpc_pipe_open_noauth(the_cli, &ndr_table_spoolss.syntax_id, pp_pipe);
+       ret = cli_rpc_pipe_open_noauth(*pp_cli, &ndr_table_spoolss, pp_pipe);
        if (!NT_STATUS_IS_OK(ret)) {
                DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
                        remote_machine, nt_errstr(ret)));
-               cli_shutdown(the_cli);
+               cli_shutdown(*pp_cli);
                return false;
        }
 
@@ -2611,17 +2531,16 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
                /* the +2 is to strip the leading 2 backslashs */
                fstrcpy(unix_printer, printer + 2);
 
-               chan = talloc_zero(back_channels, struct notify_back_channel);
+               chan = talloc_zero(NULL, struct notify_back_channel);
                if (!chan) {
                        return false;
                }
                chan->client_address = *client_ss;
 
-               if (!spoolss_connect_to_client(&chan->cli_pipe, client_ss, unix_printer)) {
+               if (!spoolss_connect_to_client(&chan->cli_pipe, &chan->cli, client_ss, unix_printer)) {
                        TALLOC_FREE(chan);
                        return false;
                }
-               chan->binding_handle = chan->cli_pipe->binding_handle;
 
                DLIST_ADD(back_channels, chan);
 
@@ -2629,6 +2548,16 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
                                   receive_notify2_message_list);
        }
 
+       if (chan->cli_pipe == NULL ||
+           chan->cli_pipe->binding_handle == NULL) {
+               DEBUG(0, ("srv_spoolss_replyopenprinter: error - "
+                       "NULL %s for printer %s\n",
+                       chan->cli_pipe == NULL ?
+                       "chan->cli_pipe" : "chan->cli_pipe->binding_handle",
+                       printer));
+               return false;
+       }
+
        /*
         * Tell the specific printing tdb we want messages for this printer
         * by registering our PID.
@@ -2639,7 +2568,7 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
                          printer));
        }
 
-       status = dcerpc_spoolss_ReplyOpenPrinter(chan->binding_handle,
+       status = dcerpc_spoolss_ReplyOpenPrinter(chan->cli_pipe->binding_handle,
                                                 talloc_tos(),
                                                 printer,
                                                 localprinter,
@@ -2728,7 +2657,7 @@ WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
        int snum = -1;
        struct spoolss_NotifyOption *option = r->in.notify_options;
        struct sockaddr_storage client_ss;
-       socklen_t client_len;
+       ssize_t client_len;
 
        /* store the notify value in the printer struct */
 
@@ -2835,7 +2764,7 @@ static void spoolss_notify_share_name(struct messaging_context *msg_ctx,
                                      struct spoolss_PrinterInfo2 *pinfo2,
                                      TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(snum));
+       SETUP_SPOOLSS_NOTIFY_DATA_STRING(data, lp_servicename(talloc_tos(), snum));
 }
 
 /*******************************************************************
@@ -2881,7 +2810,7 @@ static void spoolss_notify_comment(struct messaging_context *msg_ctx,
        const char *p;
 
        if (*pinfo2->comment == '\0') {
-               p = lp_comment(snum);
+               p = lp_comment(talloc_tos(), snum);
        } else {
                p = pinfo2->comment;
        }
@@ -3006,7 +2935,9 @@ static void spoolss_notify_security_desc(struct messaging_context *msg_ctx,
                                         struct spoolss_PrinterInfo2 *pinfo2,
                                         TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_SECDESC(data, pinfo2->secdesc);
+       data->data.sd.sd = dup_sec_desc(mem_ctx, pinfo2->secdesc);
+       data->data.sd.sd_size = ndr_size_security_descriptor(data->data.sd.sd,
+                                                            0);
 }
 
 /*******************************************************************
@@ -3275,7 +3206,7 @@ static void spoolss_notify_job_position(struct messaging_context *msg_ctx,
                                        struct spoolss_PrinterInfo2 *pinfo2,
                                        TALLOC_CTX *mem_ctx)
 {
-       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->job);
+       SETUP_SPOOLSS_NOTIFY_DATA_INTEGER(data, queue->sysjob);
 }
 
 /*******************************************************************
@@ -3448,7 +3379,7 @@ static bool construct_notify_printer_info(struct messaging_context *msg_ctx,
 
        DEBUG(4,("construct_notify_printer_info: Notify type: [%s], number of notify info: [%d] on printer: [%s]\n",
                (type == PRINTER_NOTIFY_TYPE ? "PRINTER_NOTIFY_TYPE" : "JOB_NOTIFY_TYPE"),
-               option_type->count, lp_servicename(snum)));
+               option_type->count, lp_servicename(talloc_tos(), snum)));
 
        for(field_num=0; field_num < option_type->count; field_num++) {
                field = option_type->fields[field_num].field;
@@ -3607,7 +3538,7 @@ static WERROR printserver_notify_info(struct pipes_struct *p,
                for (snum = 0; snum < n_services; snum++) {
                        if (!lp_browseable(snum) ||
                            !lp_snum_ok(snum) ||
-                           !lp_print_ok(snum)) {
+                           !lp_printable(snum)) {
                                continue; /* skip */
                        }
 
@@ -3615,12 +3546,12 @@ static WERROR printserver_notify_info(struct pipes_struct *p,
                        result = winreg_get_printer_internal(mem_ctx,
                                                    get_session_info_system(),
                                                    p->msg_ctx,
-                                                   lp_servicename(snum),
+                                                   lp_servicename(talloc_tos(), snum),
                                                    &pinfo2);
                        if (!W_ERROR_IS_OK(result)) {
                                DEBUG(4, ("printserver_notify_info: "
                                          "Failed to get printer [%s]\n",
-                                         lp_servicename(snum)));
+                                         lp_servicename(talloc_tos(), snum)));
                                continue;
                        }
 
@@ -3676,6 +3607,7 @@ static WERROR printer_notify_info(struct pipes_struct *p,
        print_status_struct status;
        struct spoolss_PrinterInfo2 *pinfo2 = NULL;
        WERROR result;
+       struct tdb_print_db *pdb;
 
        DEBUG(4,("printer_notify_info\n"));
 
@@ -3699,13 +3631,19 @@ static WERROR printer_notify_info(struct pipes_struct *p,
                return WERR_BADFID;
        }
 
+       pdb = get_print_db_byname(Printer->sharename);
+       if (pdb == NULL) {
+               return WERR_BADFID;
+       }
+
        /* Maybe we should use the SYSTEM session_info here... */
        result = winreg_get_printer_internal(mem_ctx,
                                    get_session_info_system(),
                                    p->msg_ctx,
-                                   lp_servicename(snum), &pinfo2);
+                                   lp_servicename(talloc_tos(), snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
-               return WERR_BADFID;
+               result = WERR_BADFID;
+               goto err_pdb_drop;
        }
 
        /*
@@ -3714,10 +3652,11 @@ static WERROR printer_notify_info(struct pipes_struct *p,
         */
        pinfo2->servername = talloc_strdup(pinfo2, Printer->servername);
        if (pinfo2->servername == NULL) {
-               return WERR_NOMEM;
+               result = WERR_NOMEM;
+               goto err_pdb_drop;
        }
 
-       for (i=0; i<option->count; i++) {
+       for (i = 0; i < option->count; i++) {
                option_type = option->types[i];
 
                switch (option_type.type) {
@@ -3736,12 +3675,21 @@ static WERROR printer_notify_info(struct pipes_struct *p,
                        count = print_queue_status(p->msg_ctx, snum, &queue,
                                                   &status);
 
-                       for (j=0; j<count; j++) {
+                       for (j = 0; j < count; j++) {
+                               uint32_t jobid;
+                               jobid = sysjob_to_jobid_pdb(pdb,
+                                                           queue[j].sysjob);
+                               if (jobid == (uint32_t)-1) {
+                                       DEBUG(2, ("ignoring untracked job %d\n",
+                                                 queue[j].sysjob));
+                                       continue;
+                               }
+                               /* FIXME check return value */
                                construct_notify_jobs_info(p->msg_ctx,
                                                           &queue[j], info,
                                                           pinfo2, snum,
                                                           &option_type,
-                                                          queue[j].job,
+                                                          jobid,
                                                           mem_ctx);
                        }
 
@@ -3766,7 +3714,10 @@ static WERROR printer_notify_info(struct pipes_struct *p,
        */
 
        talloc_free(pinfo2);
-       return WERR_OK;
+       result = WERR_OK;
+err_pdb_drop:
+       release_print_db(pdb);
+       return result;
 }
 
 /****************************************************************
@@ -3992,7 +3943,7 @@ static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
        r->flags                = flags;
 
        if (info2->comment == NULL || info2->comment[0] == '\0') {
-               r->comment      = talloc_strdup(mem_ctx, lp_comment(snum));
+               r->comment      = lp_comment(mem_ctx, snum);
        } else {
                r->comment      = talloc_strdup(mem_ctx, info2->comment); /* saved comment */
        }
@@ -4042,7 +3993,7 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
                return result;
        }
 
-       r->sharename            = talloc_strdup(mem_ctx, lp_servicename(snum));
+       r->sharename            = lp_servicename(mem_ctx, snum);
        W_ERROR_HAVE_NO_MEMORY(r->sharename);
        r->portname             = talloc_strdup(mem_ctx, info2->portname);
        W_ERROR_HAVE_NO_MEMORY(r->portname);
@@ -4050,7 +4001,7 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
        W_ERROR_HAVE_NO_MEMORY(r->drivername);
 
        if (info2->comment[0] == '\0') {
-               r->comment      = talloc_strdup(mem_ctx, lp_comment(snum));
+               r->comment      = lp_comment(mem_ctx, snum);
        } else {
                r->comment      = talloc_strdup(mem_ctx, info2->comment);
        }
@@ -4093,8 +4044,22 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
        r->cjobs                = count;
        r->averageppm           = info2->averageppm;
 
-       copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
-       if (!r->devmode) {
+       if (info2->devmode != NULL) {
+               result = copy_devicemode(mem_ctx,
+                                        info2->devmode,
+                                        &r->devmode);
+               if (!W_ERROR_IS_OK(result)) {
+                       return result;
+               }
+       } else if (lp_default_devmode(snum)) {
+               result = spoolss_create_default_devmode(mem_ctx,
+                                                       info2->printername,
+                                                       &r->devmode);
+               if (!W_ERROR_IS_OK(result)) {
+                       return result;
+               }
+       } else {
+               r->devmode = NULL;
                DEBUG(8,("Returning NULL Devicemode!\n"));
        }
 
@@ -4228,21 +4193,47 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
                                      struct spoolss_PrinterInfo7 *r,
                                      int snum)
 {
-       const struct auth_session_info *session_info = get_session_info_system();
-       struct GUID guid;
+       const struct auth_session_info *session_info;
+       char *printer;
+       WERROR werr;
+       TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+       if (tmp_ctx == NULL) {
+               return WERR_NOMEM;
+       }
+
+       session_info = get_session_info_system();
+       SMB_ASSERT(session_info != NULL);
+
+       printer = lp_servicename(tmp_ctx, snum);
+       if (printer == NULL) {
+               DEBUG(0, ("invalid printer snum %d\n", snum));
+               werr = WERR_INVALID_PARAM;
+               goto out_tmp_free;
+       }
 
-       if (is_printer_published(mem_ctx, session_info, msg_ctx,
-                                servername,
-                                lp_servicename(snum), &guid, NULL)) {
+       if (is_printer_published(tmp_ctx, session_info, msg_ctx,
+                                servername, printer, NULL)) {
+               struct GUID guid;
+               werr = nt_printer_guid_get(tmp_ctx, session_info, msg_ctx,
+                                          printer, &guid);
+               if (!W_ERROR_IS_OK(werr)) {
+                       goto out_tmp_free;
+               }
                r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
                r->action = DSPRINT_PUBLISH;
        } else {
                r->guid = talloc_strdup(mem_ctx, "");
                r->action = DSPRINT_UNPUBLISH;
        }
-       W_ERROR_HAVE_NO_MEMORY(r->guid);
+       if (r->guid == NULL) {
+               werr = WERR_NOMEM;
+               goto out_tmp_free;
+       }
 
-       return WERR_OK;
+       werr = WERR_OK;
+out_tmp_free:
+       talloc_free(tmp_ctx);
+       return werr;
 }
 
 /********************************************************************
@@ -4264,8 +4255,22 @@ static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
                return result;
        }
 
-       copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
-       if (!r->devmode) {
+       if (info2->devmode != NULL) {
+               result = copy_devicemode(mem_ctx,
+                                        info2->devmode,
+                                        &r->devmode);
+               if (!W_ERROR_IS_OK(result)) {
+                       return result;
+               }
+       } else if (lp_default_devmode(snum)) {
+               result = spoolss_create_default_devmode(mem_ctx,
+                                                       info2->printername,
+                                                       &r->devmode);
+               if (!W_ERROR_IS_OK(result)) {
+                       return result;
+               }
+       } else {
+               r->devmode = NULL;
                DEBUG(8,("Returning NULL Devicemode!\n"));
        }
 
@@ -4280,7 +4285,7 @@ static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
 
 static bool snum_is_shared_printer(int snum)
 {
-       return (lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum));
+       return (lp_browseable(snum) && lp_snum_ok(snum) && lp_printable(snum));
 }
 
 /********************************************************************
@@ -4475,7 +4480,8 @@ static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
 
        DEBUG(4,("enum_all_printers_info_1_name\n"));
 
-       if ((servername[0] == '\\') && (servername[1] == '\\')) {
+       if (servername != NULL &&
+           (servername[0] == '\\') && (servername[1] == '\\')) {
                s = servername + 2;
        }
 
@@ -4510,7 +4516,8 @@ static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
           listed. Windows responds to this call with a
           WERR_CAN_NOT_COMPLETE so we should do the same. */
 
-       if (servername[0] == '\\' && servername[1] == '\\') {
+       if (servername != NULL &&
+           (servername[0] == '\\') && (servername[1] == '\\')) {
                 s = servername + 2;
        }
 
@@ -4902,8 +4909,10 @@ static WERROR string_array_from_driver_info(TALLOC_CTX *mem_ctx,
                             &array, &num_strings);
        }
 
-       if (presult) {
+       if (presult != NULL) {
                *presult = array;
+       } else {
+               talloc_free(array);
        }
 
        return WERR_OK;
@@ -5649,6 +5658,7 @@ WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
 {
        struct printer_handle *printer;
        WERROR result;
+       uint32_t version = r->in.client_major_version;
 
        int snum;
 
@@ -5673,13 +5683,19 @@ WERROR _spoolss_GetPrinterDriver2(struct pipes_struct *p,
                return WERR_BADFID;
        }
 
+       if (r->in.client_major_version == SPOOLSS_DRIVER_VERSION_2012) {
+               DEBUG(3,("_spoolss_GetPrinterDriver2: v4 driver requested, "
+                       "downgrading to v3\n"));
+               version = SPOOLSS_DRIVER_VERSION_200X;
+       }
+
        result = construct_printer_driver_info_level(p->mem_ctx,
                                                     get_session_info_system(),
                                                     p->msg_ctx,
                                                     r->in.level, r->out.info,
                                                     snum, printer->servername,
                                                     r->in.architecture,
-                                                    r->in.client_major_version);
+                                                    version);
        if (!W_ERROR_IS_OK(result)) {
                TALLOC_FREE(r->out.info);
                return result;
@@ -5766,11 +5782,11 @@ WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
                return WERR_INVALID_HANDLE;
        }
 
-       if (r->in.level != 1) {
+       if (r->in.info_ctr->level != 1) {
                return WERR_UNKNOWN_LEVEL;
        }
 
-       info_1 = r->in.info.info1;
+       info_1 = r->in.info_ctr->info.info1;
 
        /*
         * a nice thing with NT is it doesn't listen to what you tell it.
@@ -5781,7 +5797,13 @@ WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
         */
 
        if (info_1->datatype) {
-               if (strcmp(info_1->datatype, "RAW") != 0) {
+               /*
+                * The v4 driver model used in Windows 8 declares print jobs
+                * intended to bypass the XPS processing layer by setting
+                * datatype to "XPS_PASS" instead of "RAW".
+                */
+                if ((strcmp(info_1->datatype, "RAW") != 0)
+                 && (strcmp(info_1->datatype, "XPS_PASS") != 0)) {
                        *r->out.job_id = 0;
                        return WERR_INVALID_DATATYPE;
                }
@@ -6152,7 +6174,7 @@ static bool check_printer_ok(TALLOC_CTX *mem_ctx,
 
 static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
 {
-       char *cmd = lp_addport_cmd();
+       char *cmd = lp_addport_command(talloc_tos());
        char *command = NULL;
        int ret;
        bool is_print_op = false;
@@ -6198,12 +6220,22 @@ static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const
 /****************************************************************************
 ****************************************************************************/
 
+static bool spoolss_conn_snum_used(struct smbd_server_connection *sconn,
+                                  int snum)
+{
+       /*
+        * As we do not know if we are embedded in the file server process
+        * or not, we have to pretend that all shares are in use.
+        */
+       return true;
+}
+
 static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
                             struct spoolss_SetPrinterInfo2 *info2,
                             const char *remote_machine,
                             struct messaging_context *msg_ctx)
 {
-       char *cmd = lp_addprinter_cmd();
+       char *cmd = lp_addprinter_command(talloc_tos());
        char **qlines;
        char *command = NULL;
        int numlines;
@@ -6256,7 +6288,7 @@ static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
 
        /* reload our services immediately */
        become_root();
-       reload_services(msg_ctx, -1, false);
+       reload_services(NULL, spoolss_conn_snum_used, false);
        unbecome_root();
 
        numlines = 0;
@@ -6294,6 +6326,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
        WERROR result = WERR_OK;
        struct dcerpc_binding_handle *b;
        TALLOC_CTX *tmp_ctx;
+       bool ok;
 
        tmp_ctx = talloc_new(mem_ctx);
        if (!tmp_ctx) {
@@ -6308,15 +6341,26 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       if (force_update || !strequal(printer->drivername, old_printer->drivername)) {
-               push_reg_sz(tmp_ctx, &buffer, printer->drivername);
-               winreg_set_printer_dataex(tmp_ctx, b,
+       if (printer->drivername != NULL &&
+           (force_update ||
+            !strequal(printer->drivername, old_printer->drivername))) {
+               ok = push_reg_sz(tmp_ctx, &buffer, printer->drivername);
+               if (!ok) {
+                       DEBUG(0, ("%s data corrupted\n", SPOOL_REG_DRIVERNAME));
+                       result = WERR_INVALID_DATA;
+                       goto done;
+               }
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_DRIVERNAME,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DRIVERNAME));
+                       goto done;
+               }
 
                if (!force_update) {
                        DEBUG(10,("update_printer: changing driver [%s]!  Sending event!\n",
@@ -6328,15 +6372,26 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                }
        }
 
-       if (force_update || !strequal(printer->comment, old_printer->comment)) {
-               push_reg_sz(tmp_ctx, &buffer, printer->comment);
-               winreg_set_printer_dataex(tmp_ctx, b,
+       if (printer->comment != NULL &&
+           (force_update ||
+            !strequal(printer->comment, old_printer->comment))) {
+               ok = push_reg_sz(tmp_ctx, &buffer, printer->comment);
+               if (!ok) {
+                       DEBUG(0, ("comment data corrupted\n"));
+                       result = WERR_INVALID_DATA;
+                       goto done;
+               }
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_DESCRIPTION,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_DESCRIPTION));
+                       goto done;
+               }
 
                if (!force_update) {
                        notify_printer_comment(server_event_context(), msg_ctx,
@@ -6345,15 +6400,26 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                }
        }
 
-       if (force_update || !strequal(printer->sharename, old_printer->sharename)) {
-               push_reg_sz(tmp_ctx, &buffer, printer->sharename);
-               winreg_set_printer_dataex(tmp_ctx, b,
+       if (printer->sharename != NULL &&
+           (force_update ||
+            !strequal(printer->sharename, old_printer->sharename))) {
+               ok = push_reg_sz(tmp_ctx, &buffer, printer->sharename);
+               if (!ok) {
+                       DEBUG(0, ("sharename data corrupted\n"));
+                       result = WERR_INVALID_DATA;
+                       goto done;
+               }
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSHARENAME,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
+                       goto done;
+               }
 
                if (!force_update) {
                        notify_printer_sharename(server_event_context(),
@@ -6363,7 +6429,9 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                }
        }
 
-       if (force_update || !strequal(printer->printername, old_printer->printername)) {
+       if (printer->printername != NULL &&
+           (force_update ||
+            !strequal(printer->printername, old_printer->printername))) {
                const char *p;
 
                p = strrchr(printer->printername, '\\' );
@@ -6373,14 +6441,23 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                        p = printer->printername;
                }
 
-               push_reg_sz(tmp_ctx, &buffer, p);
-               winreg_set_printer_dataex(tmp_ctx, b,
+               ok = push_reg_sz(tmp_ctx, &buffer, p);
+               if (!ok) {
+                       DEBUG(0, ("printername data corrupted\n"));
+                       result = WERR_INVALID_DATA;
+                       goto done;
+               }
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTERNAME,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSHARENAME));
+                       goto done;
+               }
 
                if (!force_update) {
                        notify_printer_printername(server_event_context(),
@@ -6388,15 +6465,26 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                }
        }
 
-       if (force_update || !strequal(printer->portname, old_printer->portname)) {
-               push_reg_sz(tmp_ctx, &buffer, printer->portname);
-               winreg_set_printer_dataex(tmp_ctx, b,
+       if (printer->portname != NULL &&
+           (force_update ||
+            !strequal(printer->portname, old_printer->portname))) {
+               ok = push_reg_sz(tmp_ctx, &buffer, printer->portname);
+               if (!ok) {
+                       DEBUG(0, ("portname data corrupted\n"));
+                       result = WERR_INVALID_DATA;
+                       goto done;
+               }
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PORTNAME,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PORTNAME));
+                       goto done;
+               }
 
                if (!force_update) {
                        notify_printer_port(server_event_context(),
@@ -6405,15 +6493,26 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                }
        }
 
-       if (force_update || !strequal(printer->location, old_printer->location)) {
-               push_reg_sz(tmp_ctx, &buffer, printer->location);
-               winreg_set_printer_dataex(tmp_ctx, b,
+       if (printer->location != NULL &&
+           (force_update ||
+            !strequal(printer->location, old_printer->location))) {
+               ok = push_reg_sz(tmp_ctx, &buffer, printer->location);
+               if (!ok) {
+                       DEBUG(0, ("location data corrupted\n"));
+                       result = WERR_INVALID_DATA;
+                       goto done;
+               }
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_LOCATION,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_LOCATION));
+                       goto done;
+               }
 
                if (!force_update) {
                        notify_printer_location(server_event_context(),
@@ -6423,15 +6522,26 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                }
        }
 
-       if (force_update || !strequal(printer->sepfile, old_printer->sepfile)) {
-               push_reg_sz(tmp_ctx, &buffer, printer->sepfile);
-               winreg_set_printer_dataex(tmp_ctx, b,
+       if (printer->sepfile != NULL &&
+           (force_update ||
+            !strequal(printer->sepfile, old_printer->sepfile))) {
+               ok = push_reg_sz(tmp_ctx, &buffer, printer->sepfile);
+               if (!ok) {
+                       DEBUG(0, ("sepfile data corrupted\n"));
+                       result = WERR_INVALID_DATA;
+                       goto done;
+               }
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSEPARATORFILE,
                                          REG_SZ,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSEPARATORFILE));
+                       goto done;
+               }
 
                if (!force_update) {
                        notify_printer_sepfile(server_event_context(),
@@ -6441,53 +6551,73 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                }
        }
 
-       if (force_update || printer->starttime != old_printer->starttime) {
+       if (printer->starttime != 0 &&
+           (force_update ||
+            printer->starttime != old_printer->starttime)) {
                buffer = data_blob_talloc(tmp_ctx, NULL, 4);
                SIVAL(buffer.data, 0, printer->starttime);
-               winreg_set_printer_dataex(tmp_ctx, b,
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTSTARTTIME,
                                          REG_DWORD,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTSTARTTIME));
+                       goto done;
+               }
        }
 
-       if (force_update || printer->untiltime != old_printer->untiltime) {
+       if (printer->untiltime != 0 &&
+           (force_update ||
+            printer->untiltime != old_printer->untiltime)) {
                buffer = data_blob_talloc(tmp_ctx, NULL, 4);
                SIVAL(buffer.data, 0, printer->untiltime);
-               winreg_set_printer_dataex(tmp_ctx, b,
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTENDTIME,
                                          REG_DWORD,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
+                       goto done;
+               }
        }
 
        if (force_update || printer->priority != old_printer->priority) {
                buffer = data_blob_talloc(tmp_ctx, NULL, 4);
                SIVAL(buffer.data, 0, printer->priority);
-               winreg_set_printer_dataex(tmp_ctx, b,
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRIORITY,
                                          REG_DWORD,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
+                       goto done;
+               }
        }
 
        if (force_update || printer->attributes != old_printer->attributes) {
                buffer = data_blob_talloc(tmp_ctx, NULL, 4);
                SIVAL(buffer.data, 0, (printer->attributes &
                                       PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS));
-               winreg_set_printer_dataex(tmp_ctx, b,
+               result = winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
                                          SPOOL_REG_PRINTKEEPPRINTEDJOBS,
                                          REG_DWORD,
                                          buffer.data,
                                          buffer.length);
+               if (!W_ERROR_IS_OK(result)) {
+                       DEBUG(0, ("Failed to set %s\n", SPOOL_REG_PRINTENDTIME));
+                       goto done;
+               }
 
                switch (printer->attributes & 0x3) {
                        case 0:
@@ -6502,7 +6632,12 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                        default:
                                spooling = "unknown";
                }
-               push_reg_sz(tmp_ctx, &buffer, spooling);
+               ok = push_reg_sz(tmp_ctx, &buffer, spooling);
+               if (!ok) {
+                       DEBUG(0, ("printSpooling data corrupted\n"));
+                       result = WERR_INVALID_DATA;
+                       goto done;
+               }
                winreg_set_printer_dataex(tmp_ctx, b,
                                          printer->sharename,
                                          SPOOL_DSSPOOLER_KEY,
@@ -6512,14 +6647,23 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                          buffer.length);
        }
 
-       push_reg_sz(tmp_ctx, &buffer, lp_netbios_name());
-       winreg_set_printer_dataex(tmp_ctx, b,
+       ok = push_reg_sz(tmp_ctx, &buffer, lp_netbios_name());
+       if (!ok) {
+               DEBUG(0, ("shortServerName data corrupted\n"));
+               result = WERR_INVALID_DATA;
+               goto done;
+       }
+       result = winreg_set_printer_dataex(tmp_ctx, b,
                                  printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
                                  SPOOL_REG_SHORTSERVERNAME,
                                  REG_SZ,
                                  buffer.data,
                                  buffer.length);
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SHORTSERVERNAME));
+               goto done;
+       }
 
        dnsdomname = get_mydnsfullname();
        if (dnsdomname != NULL && dnsdomname[0] != '\0') {
@@ -6532,25 +6676,43 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       push_reg_sz(tmp_ctx, &buffer, longname);
-       winreg_set_printer_dataex(tmp_ctx, b,
-                                 printer->sharename,
-                                 SPOOL_DSSPOOLER_KEY,
-                                 SPOOL_REG_SERVERNAME,
-                                 REG_SZ,
-                                 buffer.data,
-                                 buffer.length);
+       ok = push_reg_sz(tmp_ctx, &buffer, longname);
+       if (!ok) {
+               DEBUG(0, ("longname data corrupted\n"));
+               result = WERR_INVALID_DATA;
+               goto done;
+       }
+       result = winreg_set_printer_dataex(tmp_ctx, b,
+                                          printer->sharename,
+                                          SPOOL_DSSPOOLER_KEY,
+                                          SPOOL_REG_SERVERNAME,
+                                          REG_SZ,
+                                          buffer.data,
+                                          buffer.length);
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("Failed to set %s\n", SPOOL_REG_SERVERNAME));
+               goto done;
+       }
 
        uncname = talloc_asprintf(tmp_ctx, "\\\\%s\\%s",
                                  lp_netbios_name(), printer->sharename);
-       push_reg_sz(tmp_ctx, &buffer, uncname);
-       winreg_set_printer_dataex(tmp_ctx, b,
+       ok = push_reg_sz(tmp_ctx, &buffer, uncname);
+       if (!ok) {
+               DEBUG(0, ("uncName data corrupted\n"));
+               result = WERR_INVALID_DATA;
+               goto done;
+       }
+       result = winreg_set_printer_dataex(tmp_ctx, b,
                                  printer->sharename,
                                  SPOOL_DSSPOOLER_KEY,
                                  SPOOL_REG_UNCNAME,
                                  REG_SZ,
                                  buffer.data,
                                  buffer.length);
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("Failed to set %s\n", SPOOL_REG_UNCNAME));
+               goto done;
+       }
 
 done:
        talloc_free(tmp_ctx);
@@ -6628,7 +6790,7 @@ static WERROR update_printer(struct pipes_struct *p,
        /* Call addprinter hook */
        /* Check changes to see if this is really needed */
 
-       if (*lp_addprinter_cmd() &&
+       if (*lp_addprinter_command(talloc_tos()) &&
                        (!strequal(printer->drivername, old_printer->drivername) ||
                         !strequal(printer->comment, old_printer->comment) ||
                         !strequal(printer->portname, old_printer->portname) ||
@@ -6651,12 +6813,15 @@ static WERROR update_printer(struct pipes_struct *p,
                }
        }
 
-       update_dsspooler(tmp_ctx,
-                        get_session_info_system(),
-                        p->msg_ctx,
-                        snum,
-                        printer,
-                        old_printer);
+       result = update_dsspooler(tmp_ctx,
+                                 get_session_info_system(),
+                                 p->msg_ctx,
+                                 snum,
+                                 printer,
+                                 old_printer);
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
 
        printer_mask &= ~SPOOLSS_PRINTER_INFO_SECDESC;
 
@@ -6705,7 +6870,7 @@ static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
        result = winreg_get_printer_internal(p->mem_ctx,
                                    get_session_info_system(),
                                    p->msg_ctx,
-                                   lp_servicename(snum),
+                                   lp_servicename(talloc_tos(), snum),
                                    &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                return WERR_BADFID;
@@ -6879,9 +7044,9 @@ static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
 
        t = gmtime(&queue->time);
 
-       r->job_id               = queue->job;
+       r->job_id               = queue->sysjob;
 
-       r->printer_name         = talloc_strdup(mem_ctx, lp_servicename(snum));
+       r->printer_name         = lp_servicename(mem_ctx, snum);
        W_ERROR_HAVE_NO_MEMORY(r->printer_name);
        r->server_name          = talloc_strdup(mem_ctx, pinfo2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->server_name);
@@ -6920,9 +7085,9 @@ static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
 
        t = gmtime(&queue->time);
 
-       r->job_id               = queue->job;
+       r->job_id               = queue->sysjob;
 
-       r->printer_name         = talloc_strdup(mem_ctx, lp_servicename(snum));
+       r->printer_name         = lp_servicename(mem_ctx, snum);
        W_ERROR_HAVE_NO_MEMORY(r->printer_name);
        r->server_name          = talloc_strdup(mem_ctx, pinfo2->servername);
        W_ERROR_HAVE_NO_MEMORY(r->server_name);
@@ -6973,10 +7138,10 @@ static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
                             int position, int snum,
                             struct spoolss_PrinterInfo2 *pinfo2)
 {
-       r->job_id               = queue->job;
+       r->job_id               = queue->sysjob;
        r->next_job_id          = 0;
        if (next_queue) {
-               r->next_job_id  = next_queue->job;
+               r->next_job_id  = next_queue->sysjob;
        }
        r->reserved             = 0;
 
@@ -7285,17 +7450,13 @@ WERROR _spoolss_SetJob(struct pipes_struct *p,
                }
                break;
        case SPOOLSS_JOB_CONTROL_PAUSE:
-               if (print_job_pause(session_info, p->msg_ctx,
-                                   snum, r->in.job_id, &errcode)) {
-                       errcode = WERR_OK;
-               }
+               errcode = print_job_pause(session_info, p->msg_ctx,
+                                         snum, r->in.job_id);
                break;
        case SPOOLSS_JOB_CONTROL_RESTART:
        case SPOOLSS_JOB_CONTROL_RESUME:
-               if (print_job_resume(session_info, p->msg_ctx,
-                                    snum, r->in.job_id, &errcode)) {
-                       errcode = WERR_OK;
-               }
+               errcode = print_job_resume(session_info, p->msg_ctx,
+                                          snum, r->in.job_id);
                break;
        case 0:
                errcode = WERR_OK;
@@ -7703,7 +7864,7 @@ static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
 
 static WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines)
 {
-       char *cmd = lp_enumports_cmd();
+       char *cmd = lp_enumports_command(talloc_tos());
        char **qlines = NULL;
        char *command = NULL;
        int numlines;
@@ -7967,7 +8128,7 @@ static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
        /* FIXME!!!  smbd should check to see if the driver is installed before
           trying to add a printer like this  --jerry */
 
-       if (*lp_addprinter_cmd() ) {
+       if (*lp_addprinter_command(talloc_tos()) ) {
                char *raddr;
 
                raddr = tsocket_address_inet_addr_string(p->remote_address,
@@ -7993,10 +8154,10 @@ static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
        }
 
        /* you must be a printer admin to add a new printer */
-       if (!print_access_check(p->session_info,
-                               p->msg_ctx,
-                               snum,
-                               PRINTER_ACCESS_ADMINISTER)) {
+       if (!W_ERROR_IS_OK(print_access_check(p->session_info,
+                                             p->msg_ctx,
+                                             snum,
+                                             PRINTER_ACCESS_ADMINISTER))) {
                return WERR_ACCESS_DENIED;
        }
 
@@ -8012,12 +8173,15 @@ static WERROR spoolss_addprinterex_level_2(struct pipes_struct *p,
                info2_mask = ~SPOOLSS_PRINTER_INFO_DEVMODE;
        }
 
-       update_dsspooler(p->mem_ctx,
-                        get_session_info_system(),
-                        p->msg_ctx,
-                        0,
-                        info2,
-                        NULL);
+       err = update_dsspooler(p->mem_ctx,
+                              get_session_info_system(),
+                              p->msg_ctx,
+                              0,
+                              info2,
+                              NULL);
+       if (!W_ERROR_IS_OK(err)) {
+               return err;
+       }
 
        err = winreg_update_printer_internal(p->mem_ctx,
                                    get_session_info_system(),
@@ -8221,7 +8385,7 @@ static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
                                          char **path)
 {
        const char *pservername = NULL;
-       const char *long_archi = SPOOLSS_ARCHITECTURE_NT_X86;
+       const char *long_archi;
        const char *short_archi;
 
        *path = NULL;
@@ -8229,6 +8393,10 @@ static WERROR compose_spoolss_server_path(TALLOC_CTX *mem_ctx,
        /* environment may be empty */
        if (environment && strlen(environment)) {
                long_archi = environment;
+       } else {
+               long_archi = lp_parm_const_string(GLOBAL_SECTION_SNUM,
+                                                 "spoolss", "architecture",
+                                                 SPOOLSS_ARCHITECTURE_NT_X86);
        }
 
        /* servername may be empty */
@@ -8550,7 +8718,7 @@ WERROR _spoolss_DeletePrinterData(struct pipes_struct *p,
 WERROR _spoolss_AddForm(struct pipes_struct *p,
                        struct spoolss_AddForm *r)
 {
-       struct spoolss_AddFormInfo1 *form = r->in.info.info1;
+       struct spoolss_AddFormInfo1 *form;
        int snum = -1;
        WERROR status = WERR_OK;
        struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
@@ -8569,16 +8737,21 @@ WERROR _spoolss_AddForm(struct pipes_struct *p,
           and not a printer admin, then fail */
 
        if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
-           !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
-           !token_contains_name_in_list(uidtoname(p->session_info->unix_token->uid),
-                                         p->session_info->info->domain_name,
-                                         NULL,
-                                         p->session_info->security_token,
-                                         lp_printer_admin(snum))) {
+           !security_token_has_privilege(p->session_info->security_token,
+                                         SEC_PRIV_PRINT_OPERATOR)) {
                DEBUG(2,("_spoolss_Addform: denied by insufficient permissions.\n"));
                return WERR_ACCESS_DENIED;
        }
 
+       if (r->in.info_ctr->level != 1) {
+               return WERR_INVALID_LEVEL;
+       }
+
+       form = r->in.info_ctr->info.info1;
+       if (!form) {
+               return WERR_INVALID_PARAM;
+       }
+
        switch (form->flags) {
        case SPOOLSS_FORM_USER:
        case SPOOLSS_FORM_BUILTIN:
@@ -8647,12 +8820,8 @@ WERROR _spoolss_DeleteForm(struct pipes_struct *p,
        }
 
        if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
-           !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
-           !token_contains_name_in_list(uidtoname(p->session_info->unix_token->uid),
-                                         p->session_info->info->domain_name,
-                                         NULL,
-                                         p->session_info->security_token,
-                                         lp_printer_admin(snum))) {
+           !security_token_has_privilege(p->session_info->security_token,
+                                         SEC_PRIV_PRINT_OPERATOR)) {
                DEBUG(2,("_spoolss_DeleteForm: denied by insufficient permissions.\n"));
                return WERR_ACCESS_DENIED;
        }
@@ -8700,7 +8869,7 @@ done:
 WERROR _spoolss_SetForm(struct pipes_struct *p,
                        struct spoolss_SetForm *r)
 {
-       struct spoolss_AddFormInfo1 *form = r->in.info.info1;
+       struct spoolss_AddFormInfo1 *form;
        const char *form_name = r->in.form_name;
        int snum = -1;
        WERROR status = WERR_OK;
@@ -8721,16 +8890,21 @@ WERROR _spoolss_SetForm(struct pipes_struct *p,
           and not a printer admin, then fail */
 
        if ((p->session_info->unix_token->uid != sec_initial_uid()) &&
-            !security_token_has_privilege(p->session_info->security_token, SEC_PRIV_PRINT_OPERATOR) &&
-            !token_contains_name_in_list(uidtoname(p->session_info->unix_token->uid),
-                                         p->session_info->info->domain_name,
-                                         NULL,
-                                         p->session_info->security_token,
-                                         lp_printer_admin(snum))) {
+            !security_token_has_privilege(p->session_info->security_token,
+                                          SEC_PRIV_PRINT_OPERATOR)) {
                DEBUG(2,("_spoolss_Setform: denied by insufficient permissions.\n"));
                return WERR_ACCESS_DENIED;
        }
 
+       if (r->in.info_ctr->level != 1) {
+               return WERR_INVALID_LEVEL;
+       }
+
+       form = r->in.info_ctr->info.info1;
+       if (!form) {
+               return WERR_INVALID_PARAM;
+       }
+
        tmp_ctx = talloc_new(p->mem_ctx);
        if (!tmp_ctx) {
                return WERR_NOMEM;
@@ -9154,7 +9328,7 @@ static WERROR getjob_level_1(TALLOC_CTX *mem_ctx,
        bool found = false;
 
        for (i=0; i<count; i++) {
-               if (queue[i].job == (int)jobid) {
+               if (queue[i].sysjob == (int)jobid) {
                        found = true;
                        break;
                }
@@ -9189,7 +9363,7 @@ static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
        WERROR result;
 
        for (i=0; i<count; i++) {
-               if (queue[i].job == (int)jobid) {
+               if (queue[i].sysjob == (int)jobid) {
                        found = true;
                        break;
                }
@@ -9207,7 +9381,7 @@ static WERROR getjob_level_2(TALLOC_CTX *mem_ctx,
         *  a failure condition
         */
 
-       devmode = print_job_devmode(lp_const_servicename(snum), jobid);
+       devmode = print_job_devmode(mem_ctx, lp_const_servicename(snum), jobid);
        if (!devmode) {
                result = spoolss_create_default_devmode(mem_ctx,
                                                pinfo2->printername,
@@ -9505,7 +9679,7 @@ WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
        }
 
        result = winreg_get_printer(tmp_ctx, b,
-                                   lp_servicename(snum),
+                                   lp_servicename(talloc_tos(), snum),
                                    &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                goto done;
@@ -10259,7 +10433,7 @@ WERROR _spoolss_AddPort(struct pipes_struct *p,
 WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
                                 struct spoolss_GetPrinterDriver *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10270,7 +10444,7 @@ WERROR _spoolss_GetPrinterDriver(struct pipes_struct *p,
 WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
                            struct spoolss_ReadPrinter *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10281,7 +10455,7 @@ WERROR _spoolss_ReadPrinter(struct pipes_struct *p,
 WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
                                     struct spoolss_WaitForPrinterChange *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10292,7 +10466,7 @@ WERROR _spoolss_WaitForPrinterChange(struct pipes_struct *p,
 WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
                              struct spoolss_ConfigurePort *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10303,7 +10477,7 @@ WERROR _spoolss_ConfigurePort(struct pipes_struct *p,
 WERROR _spoolss_DeletePort(struct pipes_struct *p,
                           struct spoolss_DeletePort *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10314,7 +10488,7 @@ WERROR _spoolss_DeletePort(struct pipes_struct *p,
 WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
                                struct spoolss_CreatePrinterIC *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10325,7 +10499,7 @@ WERROR _spoolss_CreatePrinterIC(struct pipes_struct *p,
 WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
                                         struct spoolss_PlayGDIScriptOnPrinterIC *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10336,7 +10510,7 @@ WERROR _spoolss_PlayGDIScriptOnPrinterIC(struct pipes_struct *p,
 WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
                                struct spoolss_DeletePrinterIC *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10347,7 +10521,7 @@ WERROR _spoolss_DeletePrinterIC(struct pipes_struct *p,
 WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
                                     struct spoolss_AddPrinterConnection *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10358,7 +10532,7 @@ WERROR _spoolss_AddPrinterConnection(struct pipes_struct *p,
 WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
                                        struct spoolss_DeletePrinterConnection *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10369,7 +10543,7 @@ WERROR _spoolss_DeletePrinterConnection(struct pipes_struct *p,
 WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
                                  struct spoolss_PrinterMessageBox *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10380,7 +10554,7 @@ WERROR _spoolss_PrinterMessageBox(struct pipes_struct *p,
 WERROR _spoolss_AddMonitor(struct pipes_struct *p,
                           struct spoolss_AddMonitor *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10391,7 +10565,7 @@ WERROR _spoolss_AddMonitor(struct pipes_struct *p,
 WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
                              struct spoolss_DeleteMonitor *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10402,7 +10576,7 @@ WERROR _spoolss_DeleteMonitor(struct pipes_struct *p,
 WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
                                     struct spoolss_DeletePrintProcessor *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10413,7 +10587,7 @@ WERROR _spoolss_DeletePrintProcessor(struct pipes_struct *p,
 WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
                                 struct spoolss_AddPrintProvidor *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10424,7 +10598,7 @@ WERROR _spoolss_AddPrintProvidor(struct pipes_struct *p,
 WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
                                    struct spoolss_DeletePrintProvidor *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10435,7 +10609,7 @@ WERROR _spoolss_DeletePrintProvidor(struct pipes_struct *p,
 WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
                                                   struct spoolss_FindFirstPrinterChangeNotification *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10446,7 +10620,7 @@ WERROR _spoolss_FindFirstPrinterChangeNotification(struct pipes_struct *p,
 WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
                                                  struct spoolss_FindNextPrinterChangeNotification *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10457,7 +10631,7 @@ WERROR _spoolss_FindNextPrinterChangeNotification(struct pipes_struct *p,
 WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct *p,
                                                            struct spoolss_RouterFindFirstPrinterChangeNotificationOld *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10468,7 +10642,7 @@ WERROR _spoolss_RouterFindFirstPrinterChangeNotificationOld(struct pipes_struct
 WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
                                 struct spoolss_ReplyOpenPrinter *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10479,7 +10653,7 @@ WERROR _spoolss_ReplyOpenPrinter(struct pipes_struct *p,
 WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
                                   struct spoolss_RouterReplyPrinter *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10490,7 +10664,7 @@ WERROR _spoolss_RouterReplyPrinter(struct pipes_struct *p,
 WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
                                  struct spoolss_ReplyClosePrinter *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10501,7 +10675,7 @@ WERROR _spoolss_ReplyClosePrinter(struct pipes_struct *p,
 WERROR _spoolss_AddPortEx(struct pipes_struct *p,
                          struct spoolss_AddPortEx *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10512,7 +10686,7 @@ WERROR _spoolss_AddPortEx(struct pipes_struct *p,
 WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
                                                         struct spoolss_RouterFindFirstPrinterChangeNotification *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10523,7 +10697,7 @@ WERROR _spoolss_RouterFindFirstPrinterChangeNotification(struct pipes_struct *p,
 WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
                            struct spoolss_SpoolerInit *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10534,7 +10708,7 @@ WERROR _spoolss_SpoolerInit(struct pipes_struct *p,
 WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
                               struct spoolss_ResetPrinterEx *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10545,7 +10719,7 @@ WERROR _spoolss_ResetPrinterEx(struct pipes_struct *p,
 WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
                                     struct spoolss_RouterReplyPrinterEx *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10556,7 +10730,7 @@ WERROR _spoolss_RouterReplyPrinterEx(struct pipes_struct *p,
 WERROR _spoolss_44(struct pipes_struct *p,
                   struct spoolss_44 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10567,7 +10741,7 @@ WERROR _spoolss_44(struct pipes_struct *p,
 WERROR _spoolss_SetPort(struct pipes_struct *p,
                        struct spoolss_SetPort *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10578,7 +10752,7 @@ WERROR _spoolss_SetPort(struct pipes_struct *p,
 WERROR _spoolss_4a(struct pipes_struct *p,
                   struct spoolss_4a *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10589,7 +10763,7 @@ WERROR _spoolss_4a(struct pipes_struct *p,
 WERROR _spoolss_4b(struct pipes_struct *p,
                   struct spoolss_4b *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10600,7 +10774,7 @@ WERROR _spoolss_4b(struct pipes_struct *p,
 WERROR _spoolss_4c(struct pipes_struct *p,
                   struct spoolss_4c *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10611,7 +10785,7 @@ WERROR _spoolss_4c(struct pipes_struct *p,
 WERROR _spoolss_53(struct pipes_struct *p,
                   struct spoolss_53 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10622,7 +10796,7 @@ WERROR _spoolss_53(struct pipes_struct *p,
 WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
                                        struct spoolss_AddPerMachineConnection *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10633,7 +10807,7 @@ WERROR _spoolss_AddPerMachineConnection(struct pipes_struct *p,
 WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
                                           struct spoolss_DeletePerMachineConnection *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10644,7 +10818,7 @@ WERROR _spoolss_DeletePerMachineConnection(struct pipes_struct *p,
 WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
                                          struct spoolss_EnumPerMachineConnections *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10655,7 +10829,7 @@ WERROR _spoolss_EnumPerMachineConnections(struct pipes_struct *p,
 WERROR _spoolss_5a(struct pipes_struct *p,
                   struct spoolss_5a *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10666,7 +10840,7 @@ WERROR _spoolss_5a(struct pipes_struct *p,
 WERROR _spoolss_5b(struct pipes_struct *p,
                   struct spoolss_5b *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10677,7 +10851,7 @@ WERROR _spoolss_5b(struct pipes_struct *p,
 WERROR _spoolss_5c(struct pipes_struct *p,
                   struct spoolss_5c *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10688,7 +10862,7 @@ WERROR _spoolss_5c(struct pipes_struct *p,
 WERROR _spoolss_5d(struct pipes_struct *p,
                   struct spoolss_5d *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10699,7 +10873,7 @@ WERROR _spoolss_5d(struct pipes_struct *p,
 WERROR _spoolss_5e(struct pipes_struct *p,
                   struct spoolss_5e *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10710,7 +10884,7 @@ WERROR _spoolss_5e(struct pipes_struct *p,
 WERROR _spoolss_5f(struct pipes_struct *p,
                   struct spoolss_5f *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10721,18 +10895,18 @@ WERROR _spoolss_5f(struct pipes_struct *p,
 WERROR _spoolss_60(struct pipes_struct *p,
                   struct spoolss_60 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
 /****************************************************************
- _spoolss_61
+ _spoolss_RpcSendRecvBidiData
 ****************************************************************/
 
-WERROR _spoolss_61(struct pipes_struct *p,
-                  struct spoolss_61 *r)
+WERROR _spoolss_RpcSendRecvBidiData(struct pipes_struct *p,
+                                   struct spoolss_RpcSendRecvBidiData *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10743,7 +10917,7 @@ WERROR _spoolss_61(struct pipes_struct *p,
 WERROR _spoolss_62(struct pipes_struct *p,
                   struct spoolss_62 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10754,7 +10928,7 @@ WERROR _spoolss_62(struct pipes_struct *p,
 WERROR _spoolss_63(struct pipes_struct *p,
                   struct spoolss_63 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10765,7 +10939,7 @@ WERROR _spoolss_63(struct pipes_struct *p,
 WERROR _spoolss_64(struct pipes_struct *p,
                   struct spoolss_64 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10776,7 +10950,7 @@ WERROR _spoolss_64(struct pipes_struct *p,
 WERROR _spoolss_65(struct pipes_struct *p,
                   struct spoolss_65 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10787,7 +10961,7 @@ WERROR _spoolss_65(struct pipes_struct *p,
 WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
                                      struct spoolss_GetCorePrinterDrivers *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10798,7 +10972,7 @@ WERROR _spoolss_GetCorePrinterDrivers(struct pipes_struct *p,
 WERROR _spoolss_67(struct pipes_struct *p,
                   struct spoolss_67 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10809,7 +10983,7 @@ WERROR _spoolss_67(struct pipes_struct *p,
 WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
                                            struct spoolss_GetPrinterDriverPackagePath *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10820,7 +10994,7 @@ WERROR _spoolss_GetPrinterDriverPackagePath(struct pipes_struct *p,
 WERROR _spoolss_69(struct pipes_struct *p,
                   struct spoolss_69 *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10831,7 +11005,7 @@ WERROR _spoolss_69(struct pipes_struct *p,
 WERROR _spoolss_6a(struct pipes_struct *p,
                   struct spoolss_6a *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10842,7 +11016,7 @@ WERROR _spoolss_6a(struct pipes_struct *p,
 WERROR _spoolss_6b(struct pipes_struct *p,
                   struct spoolss_6b *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10853,7 +11027,7 @@ WERROR _spoolss_6b(struct pipes_struct *p,
 WERROR _spoolss_6c(struct pipes_struct *p,
                   struct spoolss_6c *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }
 
@@ -10864,6 +11038,50 @@ WERROR _spoolss_6c(struct pipes_struct *p,
 WERROR _spoolss_6d(struct pipes_struct *p,
                   struct spoolss_6d *r)
 {
-       p->rng_fault_state = true;
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+       return WERR_NOT_SUPPORTED;
+}
+
+/****************************************************************
+ _spoolss_RpcGetJobNamedPropertyValue
+****************************************************************/
+
+WERROR _spoolss_RpcGetJobNamedPropertyValue(struct pipes_struct *p,
+                                           struct spoolss_RpcGetJobNamedPropertyValue *r)
+{
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+       return WERR_NOT_SUPPORTED;
+}
+
+/****************************************************************
+ _spoolss_RpcSetJobNamedProperty
+****************************************************************/
+
+WERROR _spoolss_RpcSetJobNamedProperty(struct pipes_struct *p,
+                                      struct spoolss_RpcSetJobNamedProperty *r)
+{
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+       return WERR_NOT_SUPPORTED;
+}
+
+/****************************************************************
+ _spoolss_RpcDeleteJobNamedProperty
+****************************************************************/
+
+WERROR _spoolss_RpcDeleteJobNamedProperty(struct pipes_struct *p,
+                                         struct spoolss_RpcDeleteJobNamedProperty *r)
+{
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
+       return WERR_NOT_SUPPORTED;
+}
+
+/****************************************************************
+ _spoolss_RpcEnumJobNamedProperties
+****************************************************************/
+
+WERROR _spoolss_RpcEnumJobNamedProperties(struct pipes_struct *p,
+                                         struct spoolss_RpcEnumJobNamedProperties *r)
+{
+       p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
        return WERR_NOT_SUPPORTED;
 }