s3-spoolss: make it possible to have and announce a [prnproc$] share on the printserver.
[mat/samba.git] / source3 / rpc_server / srv_spoolss_nt.c
index 75d7ac7164c682f34b24507dd0a7e6e687dcf74f..c05ba66e427d354f11bf51e079fca1f68acc550e 100644 (file)
@@ -61,6 +61,8 @@
 #define MAX_OPEN_PRINTER_EXS 50
 #endif
 
+struct notify_back_channel;
+
 /* structure to store the printer handles */
 /* and a reference to what it's pointing to */
 /* and the notify info asked about */
@@ -71,7 +73,7 @@ struct printer_handle {
        bool page_started;
        uint32 jobid; /* jobid in printing backend */
        int printer_type;
-       fstring servername;
+       const char *servername;
        fstring sharename;
        uint32 type;
        uint32 access_granted;
@@ -81,8 +83,8 @@ struct printer_handle {
                fstring localmachine;
                uint32 printerlocal;
                struct spoolss_NotifyOption *option;
-               struct policy_handle client_hnd;
-               bool client_connected;
+               struct policy_handle cli_hnd;
+               struct notify_back_channel *cli_chan;
                uint32 change;
                /* are we in a FindNextPrinterChangeNotify() call? */
                bool fnpcn;
@@ -114,12 +116,17 @@ struct printer_session_counter {
 static struct printer_session_counter *counter_list;
 
 struct notify_back_channel {
+       struct notify_back_channel *prev, *next;
+
+       /* associated client */
+       struct sockaddr_storage client_address;
+
        /* print notify back-channel pipe handle*/
        struct rpc_pipe_client *cli_pipe;
-       uint32_t active_channels;
+       uint32_t active_connections;
 };
 
-static struct notify_back_channel back_channel = { NULL, 0 };
+static struct notify_back_channel *back_channels;
 
 /* Map generic permissions to printer object specific permissions */
 
@@ -143,7 +150,7 @@ const struct standard_mapping printserver_std_mapping = {
 
 struct xcv_api_table {
        const char *name;
-       WERROR(*fn) (TALLOC_CTX *mem_ctx, NT_USER_TOKEN *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
+       WERROR(*fn) (TALLOC_CTX *mem_ctx, struct security_token *token, DATA_BLOB *in, DATA_BLOB *out, uint32_t *needed);
 };
 
 static void prune_printername_cache(void);
@@ -210,9 +217,8 @@ static int nt_printq_status(int v)
  Disconnect from the client
 ****************************************************************************/
 
-static void srv_spoolss_replycloseprinter(
-       int snum, struct policy_handle *handle,
-       struct messaging_context *msg_ctx)
+static void srv_spoolss_replycloseprinter(int snum,
+                                         struct printer_handle *prn_hnd)
 {
        WERROR result;
        NTSTATUS status;
@@ -222,34 +228,40 @@ static void srv_spoolss_replycloseprinter(
         * by deregistering our PID.
         */
 
-       if (!print_notify_deregister_pid(snum))
-               DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", lp_const_servicename(snum) ));
+       if (!print_notify_deregister_pid(snum)) {
+               DEBUG(0, ("Failed to register our pid for printer %s\n",
+                         lp_const_servicename(snum)));
+       }
 
        /* weird if the test succeeds !!! */
-       if (back_channel.active_channels == 0) {
-               DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
+       if (prn_hnd->notify.cli_chan == 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);
+               TALLOC_FREE(prn_hnd->notify.cli_chan);
                return;
        }
 
-       status = rpccli_spoolss_ReplyClosePrinter(back_channel.cli_pipe, talloc_tos(),
-                                                 handle,
-                                                 &result);
-       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
-               DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
-                       win_errstr(result)));
+       status = rpccli_spoolss_ReplyClosePrinter(
+                                       prn_hnd->notify.cli_chan->cli_pipe,
+                                       talloc_tos(),
+                                       &prn_hnd->notify.cli_hnd,
+                                       &result);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("reply_close_printer failed [%s].\n",
+                         win_errstr(result)));
+       }
 
        /* if it's the last connection, deconnect the IPC$ share */
-       if (back_channel.active_channels == 1) {
+       if (prn_hnd->notify.cli_chan->active_connections == 1) {
 
-               cli_shutdown(rpc_pipe_np_smb_conn(back_channel.cli_pipe));
-               /*
-                * The above call shuts down the pipe also.
-                */
-               back_channel.cli_pipe = NULL;
+               cli_shutdown(rpc_pipe_np_smb_conn(prn_hnd->notify.cli_chan->cli_pipe));
+               DLIST_REMOVE(back_channels, prn_hnd->notify.cli_chan);
+               TALLOC_FREE(prn_hnd->notify.cli_chan);
 
-               if (msg_ctx != NULL) {
-                       messaging_deregister(msg_ctx, MSG_PRINTER_NOTIFY2,
-                                            NULL);
+               if (prn_hnd->notify.msg_ctx != NULL) {
+                       messaging_deregister(prn_hnd->notify.msg_ctx,
+                                            MSG_PRINTER_NOTIFY2, NULL);
 
                        /*
                         * Tell the serverid.tdb we're no longer
@@ -257,12 +269,14 @@ static void srv_spoolss_replycloseprinter(
                         */
 
                        serverid_register_msg_flags(
-                               messaging_server_id(msg_ctx),
+                               messaging_server_id(prn_hnd->notify.msg_ctx),
                                false, FLAG_MSG_PRINT_NOTIFY);
                }
        }
 
-       back_channel.active_channels--;
+       if (prn_hnd->notify.cli_chan) {
+               prn_hnd->notify.cli_chan->active_connections--;
+       }
 }
 
 /****************************************************************************
@@ -271,20 +285,23 @@ static void srv_spoolss_replycloseprinter(
 
 static int printer_entry_destructor(struct printer_handle *Printer)
 {
-       if (Printer->notify.client_connected == true) {
+       if (Printer->notify.cli_chan != NULL &&
+           Printer->notify.cli_chan->active_connections > 0) {
                int snum = -1;
 
-               if ( Printer->printer_type == SPLHND_SERVER) {
-                       snum = -1;
-                       srv_spoolss_replycloseprinter(
-                               snum, &Printer->notify.client_hnd,
-                               Printer->notify.msg_ctx);
-               } else if (Printer->printer_type == SPLHND_PRINTER) {
+               switch(Printer->printer_type) {
+               case SPLHND_SERVER:
+                       srv_spoolss_replycloseprinter(snum, Printer);
+                       break;
+
+               case SPLHND_PRINTER:
                        snum = print_queue_snum(Printer->sharename);
-                       if (snum != -1)
-                               srv_spoolss_replycloseprinter(
-                                       snum, &Printer->notify.client_hnd,
-                                       Printer->notify.msg_ctx);
+                       if (snum != -1) {
+                               srv_spoolss_replycloseprinter(snum, Printer);
+                       }
+                       break;
+               default:
+                       break;
                }
        }
 
@@ -293,8 +310,6 @@ static int printer_entry_destructor(struct printer_handle *Printer)
        Printer->notify.localmachine[0]='\0';
        Printer->notify.printerlocal=0;
        TALLOC_FREE(Printer->notify.option);
-       Printer->notify.client_connected = false;
-
        TALLOC_FREE(Printer->devmode);
 
        /* Remove from the internal list. */
@@ -342,14 +357,13 @@ static bool close_printer_handle(struct pipes_struct *p, struct policy_handle *h
  Delete a printer given a handle.
 ****************************************************************************/
 
-static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
+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 *command = NULL;
        int ret;
-       SE_PRIV se_printop = SE_PRINT_OPERATOR;
        bool is_print_op = false;
 
        /* can't fail if we don't try */
@@ -364,7 +378,7 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
                return WERR_NOMEM;
        }
        if ( token )
-               is_print_op = user_has_privileges( token, &se_printop );
+               is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
 
        DEBUG(10,("Running [%s]\n", command));
 
@@ -395,7 +409,7 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
        reload_services(msg_ctx, -1, false);
        unbecome_root();
 
-       if ( lp_servicenumber( sharename )  > 0 )
+       if ( lp_servicenumber( sharename ) >= 0 )
                return WERR_ACCESS_DENIED;
 
        return WERR_OK;
@@ -533,6 +547,7 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
        bool found = false;
        struct spoolss_PrinterInfo2 *info2 = NULL;
        WERROR result;
+       char *p;
 
        /*
         * Hopefully nobody names his printers like this. Maybe \ or ,
@@ -555,8 +570,10 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
                if (!is_myname_or_ipaddr(servername)) {
                        return false;
                }
-
-               fstrcpy(Printer->servername, servername);
+               Printer->servername = talloc_asprintf(Printer, "\\\\%s", servername);
+               if (Printer->servername == NULL) {
+                       return false;
+               }
        }
 
        if (Printer->printer_type == SPLHND_SERVER) {
@@ -569,6 +586,18 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
 
        DEBUGADD(5, ("searching for [%s]\n", aprinter));
 
+       if ((p = strchr(aprinter, ',')) != NULL) {
+               if (*p == ' ')
+                       p++;
+               if (strnequal(p+1, "DrvConvert", strlen("DrvConvert")) ||
+                   strnequal(p+1, " DrvConvert", strlen(" DrvConvert"))) {
+                       *p = '\0';
+               } else if (strnequal(p+1, "LocalOnly", strlen("LocalOnly")) ||
+                          strnequal(p+1, " LocalOnly", strlen(" LocalOnly"))) {
+                       *p = '\0';
+               }
+       }
+
        /* check for the Port Monitor Interface */
        if ( strequal( aprinter, SPL_XCV_MONITOR_TCPMON ) ) {
                Printer->printer_type = SPLHND_PORTMON_TCP;
@@ -635,7 +664,6 @@ static bool set_printer_hnd_name(TALLOC_CTX *mem_ctx,
                result = winreg_get_printer(mem_ctx,
                                            server_info,
                                            msg_ctx,
-                                           servername,
                                            sname,
                                            &info2);
                if ( !W_ERROR_IS_OK(result) ) {
@@ -1082,168 +1110,205 @@ static void construct_info_data(struct spoolss_Notify *info_data,
  back registered
  **********************************************************************/
 
-static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
+static int build_notify2_messages(TALLOC_CTX *mem_ctx,
+                                 struct printer_handle *prn_hnd,
+                                 SPOOLSS_NOTIFY_MSG *messages,
+                                 uint32_t num_msgs,
+                                 struct spoolss_Notify **_notifies,
+                                 int *_count)
 {
-       struct printer_handle    *p;
-       TALLOC_CTX               *mem_ctx = notify_ctr_getctx( ctr );
-       SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
-       SPOOLSS_NOTIFY_MSG       *messages;
-       int                      sending_msg_count;
-
-       if ( !msg_group ) {
-               DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
-               return;
-       }
-
-       messages = msg_group->msgs;
+       struct spoolss_Notify *notifies;
+       SPOOLSS_NOTIFY_MSG *msg;
+       int count = 0;
+       uint32_t id;
+       int i;
 
-       if ( !messages ) {
-               DEBUG(5,("send_notify2_changes() called with no messages!\n"));
-               return;
+       notifies = talloc_zero_array(mem_ctx,
+                                    struct spoolss_Notify, num_msgs);
+       if (!notifies) {
+               return ENOMEM;
        }
 
-       DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
-
-       /* loop over all printers */
+       for (i = 0; i < num_msgs; i++) {
 
-       for (p = printers_list; p; p = p->next) {
-               struct spoolss_Notify *notifies;
-               uint32_t count = 0;
-               uint32_t id;
-               int     i;
+               msg = &messages[i];
 
-               /* Is there notification on this handle? */
+               /* Are we monitoring this event? */
 
-               if ( !p->notify.client_connected )
+               if (!is_monitoring_event(prn_hnd, msg->type, msg->field)) {
                        continue;
+               }
 
-               DEBUG(10,("Client connected! [\\\\%s\\%s]\n", p->servername, p->sharename));
+               DEBUG(10, ("Sending message type [0x%x] field [0x%2x] "
+                          "for printer [%s]\n",
+                          msg->type, msg->field, prn_hnd->sharename));
 
-               /* For this printer?  Print servers always receive
-                   notifications. */
+               /*
+                * if the is a printer notification handle and not a job
+                * notification type, then set the id to 0.
+                * Otherwise just use what was specified in the message.
+                *
+                * When registering change notification on a print server
+                * handle we always need to send back the id (snum) matching
+                * the printer for which the change took place.
+                * For change notify registered on a printer handle,
+                * this does not matter and the id should be 0.
+                *
+                * --jerry
+                */
 
-               if ( ( p->printer_type == SPLHND_PRINTER )  &&
-                   ( !strequal(msg_group->printername, p->sharename) ) )
-                       continue;
+               if ((msg->type == PRINTER_NOTIFY_TYPE) &&
+                   (prn_hnd->printer_type == SPLHND_PRINTER)) {
+                       id = 0;
+               } else {
+                       id = msg->id;
+               }
 
-               DEBUG(10,("Our printer\n"));
+               /* Convert unix jobid to smb jobid */
 
-               /* allocate the max entries possible */
+               if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
+                       id = sysjob_to_jobid(msg->id);
 
-               notifies = TALLOC_ZERO_ARRAY(mem_ctx, struct spoolss_Notify, msg_group->num_msgs);
-               if (!notifies) {
-                       return;
+                       if (id == -1) {
+                               DEBUG(3, ("no such unix jobid %d\n",
+                                         msg->id));
+                               continue;
+                       }
                }
 
-               /* build the array of change notifications */
+               construct_info_data(&notifies[count],
+                                   msg->type, msg->field, id);
 
-               sending_msg_count = 0;
+               switch(msg->type) {
+               case PRINTER_NOTIFY_TYPE:
+                       if (printer_notify_table[msg->field].fn) {
+                               printer_notify_table[msg->field].fn(msg,
+                                               &notifies[count], mem_ctx);
+                       }
+                       break;
 
-               for ( i=0; i<msg_group->num_msgs; i++ ) {
-                       SPOOLSS_NOTIFY_MSG      *msg = &messages[i];
+               case JOB_NOTIFY_TYPE:
+                       if (job_notify_table[msg->field].fn) {
+                               job_notify_table[msg->field].fn(msg,
+                                               &notifies[count], mem_ctx);
+                       }
+                       break;
 
-                       /* Are we monitoring this event? */
+               default:
+                       DEBUG(5, ("Unknown notification type %d\n",
+                                 msg->type));
+                       continue;
+               }
 
-                       if (!is_monitoring_event(p, msg->type, msg->field))
-                               continue;
+               count++;
+       }
 
-                       sending_msg_count++;
+       *_notifies = notifies;
+       *_count = count;
 
+       return 0;
+}
 
-                       DEBUG(10,("process_notify2_message: Sending message type [0x%x] field [0x%2x] for printer [%s]\n",
-                               msg->type, msg->field, p->sharename));
+static int send_notify2_printer(TALLOC_CTX *mem_ctx,
+                               struct printer_handle *prn_hnd,
+                               SPOOLSS_NOTIFY_MSG_GROUP *msg_group)
+{
+       struct spoolss_Notify *notifies;
+       int count = 0;
+       union spoolss_ReplyPrinterInfo info;
+       struct spoolss_NotifyInfo info0;
+       uint32_t reply_result;
+       NTSTATUS status;
+       WERROR werr;
+       int ret;
 
-                       /*
-                        * if the is a printer notification handle and not a job notification
-                        * type, then set the id to 0.  Other wise just use what was specified
-                        * in the message.
-                        *
-                        * When registering change notification on a print server handle
-                        * we always need to send back the id (snum) matching the printer
-                        * for which the change took place.  For change notify registered
-                        * on a printer handle, this does not matter and the id should be 0.
-                        *
-                        * --jerry
-                        */
+       /* Is there notification on this handle? */
+       if (prn_hnd->notify.cli_chan == NULL ||
+           prn_hnd->notify.cli_chan->active_connections == 0) {
+               return 0;
+       }
 
-                       if ( ( p->printer_type == SPLHND_PRINTER ) && ( msg->type == PRINTER_NOTIFY_TYPE ) )
-                               id = 0;
-                       else
-                               id = msg->id;
+       DEBUG(10, ("Client connected! [\\\\%s\\%s]\n",
+                  prn_hnd->servername, prn_hnd->sharename));
 
+       /* For this printer? Print servers always receive notifications. */
+       if ((prn_hnd->printer_type == SPLHND_PRINTER)  &&
+           (!strequal(msg_group->printername, prn_hnd->sharename))) {
+               return 0;
+       }
 
-                       /* Convert unix jobid to smb jobid */
+       DEBUG(10,("Our printer\n"));
+
+       /* build the array of change notifications */
+       ret = build_notify2_messages(mem_ctx, prn_hnd,
+                                    msg_group->msgs,
+                                    msg_group->num_msgs,
+                                    &notifies, &count);
+       if (ret) {
+               return ret;
+       }
+
+       info0.version   = 0x2;
+       info0.flags     = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
+       info0.count     = count;
+       info0.notifies  = notifies;
+
+       info.info0 = &info0;
+
+       status = rpccli_spoolss_RouterReplyPrinterEx(
+                               prn_hnd->notify.cli_chan->cli_pipe,
+                               mem_ctx,
+                               &prn_hnd->notify.cli_hnd,
+                               prn_hnd->notify.change, /* color */
+                               prn_hnd->notify.flags,
+                               &reply_result,
+                               0, /* reply_type, must be 0 */
+                               info, &werr);
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
+               DEBUG(1, ("RouterReplyPrinterEx to client: %s "
+                         "failed: %s\n",
+                         prn_hnd->notify.cli_chan->cli_pipe->srv_name_slash,
+                         win_errstr(werr)));
+       }
+       switch (reply_result) {
+       case 0:
+               break;
+       case PRINTER_NOTIFY_INFO_DISCARDED:
+       case PRINTER_NOTIFY_INFO_DISCARDNOTED:
+       case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
+               break;
+       default:
+               break;
+       }
 
-                       if (msg->flags & SPOOLSS_NOTIFY_MSG_UNIX_JOBID) {
-                               id = sysjob_to_jobid(msg->id);
+       return 0;
+}
 
-                               if (id == -1) {
-                                       DEBUG(3, ("no such unix jobid %d\n", msg->id));
-                                       goto done;
-                               }
-                       }
+static void send_notify2_changes( SPOOLSS_NOTIFY_MSG_CTR *ctr, uint32_t idx )
+{
+       struct printer_handle    *p;
+       TALLOC_CTX               *mem_ctx = notify_ctr_getctx( ctr );
+       SPOOLSS_NOTIFY_MSG_GROUP *msg_group = notify_ctr_getgroup( ctr, idx );
+       int ret;
 
-                       construct_info_data(&notifies[count],
-                                           (enum spoolss_NotifyType) msg->type,
-                                           msg->field,
-                                           id);
+       if ( !msg_group ) {
+               DEBUG(5,("send_notify2_changes() called with no msg group!\n"));
+               return;
+       }
 
-                       switch(msg->type) {
-                       case PRINTER_NOTIFY_TYPE:
-                               if ( printer_notify_table[msg->field].fn )
-                                       printer_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
-                               break;
+       if (!msg_group->msgs) {
+               DEBUG(5, ("send_notify2_changes() called with no messages!\n"));
+               return;
+       }
 
-                       case JOB_NOTIFY_TYPE:
-                               if ( job_notify_table[msg->field].fn )
-                                       job_notify_table[msg->field].fn(msg, &notifies[count], mem_ctx);
-                               break;
+       DEBUG(8,("send_notify2_changes: Enter...[%s]\n", msg_group->printername));
 
-                       default:
-                               DEBUG(5, ("Unknown notification type %d\n", msg->type));
-                               goto done;
-                       }
+       /* loop over all printers */
 
-                       count++;
-               }
-
-               if ( sending_msg_count ) {
-                       NTSTATUS status;
-                       WERROR werr;
-                       union spoolss_ReplyPrinterInfo info;
-                       struct spoolss_NotifyInfo info0;
-                       uint32_t reply_result;
-
-                       info0.version   = 0x2;
-                       info0.flags     = count ? 0x00020000 /* ??? */ : PRINTER_NOTIFY_INFO_DISCARDED;
-                       info0.count     = count;
-                       info0.notifies  = notifies;
-
-                       info.info0 = &info0;
-
-                       status = rpccli_spoolss_RouterReplyPrinterEx(back_channel.cli_pipe, mem_ctx,
-                                                                    &p->notify.client_hnd,
-                                                                    p->notify.change, /* color */
-                                                                    p->notify.flags,
-                                                                    &reply_result,
-                                                                    0, /* reply_type, must be 0 */
-                                                                    info,
-                                                                    &werr);
-                       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(werr)) {
-                               DEBUG(1,("RouterReplyPrinterEx to client: %s failed: %s\n",
-                                       back_channel.cli_pipe->srv_name_slash,
-                                       win_errstr(werr)));
-                       }
-                       switch (reply_result) {
-                               case 0:
-                                       break;
-                               case PRINTER_NOTIFY_INFO_DISCARDED:
-                               case PRINTER_NOTIFY_INFO_DISCARDNOTED:
-                               case PRINTER_NOTIFY_INFO_COLOR_MISMATCH:
-                                       break;
-                               default:
-                                       break;
-                       }
+       for (p = printers_list; p; p = p->next) {
+               ret = send_notify2_printer(mem_ctx, p, msg_group);
+               if (ret) {
+                       goto done;
                }
        }
 
@@ -1410,6 +1475,18 @@ static bool srv_spoolss_drv_upgrade_printer(const char *drivername,
        return true;
 }
 
+void srv_spoolss_cleanup(void)
+{
+       struct printer_session_counter *session_counter;
+
+       for (session_counter = counter_list;
+            session_counter != NULL;
+            session_counter = counter_list) {
+               DLIST_REMOVE(counter_list, session_counter);
+               TALLOC_FREE(session_counter);
+       }
+}
+
 /**********************************************************************
  callback to receive a MSG_PRINTER_DRVUPGRADE message and interate
  over all printers, upgrading ones as necessary
@@ -1429,7 +1506,6 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
        const char *drivername;
        int snum;
        int n_services = lp_numservices();
-       size_t len;
 
        tmp_ctx = talloc_new(NULL);
        if (!tmp_ctx) return;
@@ -1441,8 +1517,7 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
                goto done;
        }
 
-       len = MIN(data->length,sizeof(drivername)-1);
-       drivername = talloc_strndup(tmp_ctx, (const char *)data->data, len);
+       drivername = talloc_strndup(tmp_ctx, (const char *)data->data, data->length);
        if (!drivername) {
                DEBUG(0, ("do_drv_upgrade_printer: Out of memoery ?!\n"));
                goto done;
@@ -1458,8 +1533,12 @@ void do_drv_upgrade_printer(struct messaging_context *msg,
                        continue;
                }
 
+               /* ignore [printers] share */
+               if (strequal(lp_const_servicename(snum), "printers")) {
+                       continue;
+               }
+
                result = winreg_get_printer(tmp_ctx, server_info, msg,
-                                           NULL,
                                            lp_const_servicename(snum),
                                            &pinfo2);
 
@@ -1506,14 +1585,13 @@ void update_monitored_printq_cache(struct messaging_context *msg_ctx)
        int snum;
 
        /* loop through all printers and update the cache where
-          client_connected == true */
-       while ( printer )
-       {
-               if ( (printer->printer_type == SPLHND_PRINTER)
-                       && printer->notify.client_connected )
-               {
+          a client is connected */
+       while (printer) {
+               if ((printer->printer_type == SPLHND_PRINTER) &&
+                   ((printer->notify.cli_chan != NULL) &&
+                    (printer->notify.cli_chan->active_connections > 0))) {
                        snum = print_queue_snum(printer->sharename);
-                       print_queue_status(msg_ctx, snum, NULL, NULL );
+                       print_queue_status(msg_ctx, snum, NULL, NULL);
                }
 
                printer = printer->next;
@@ -1680,8 +1758,6 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
                if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
                {
-                       SE_PRIV se_printop = SE_PRINT_OPERATOR;
-
                        if (!lp_ms_add_printer_wizard()) {
                                close_printer_handle(p, r->out.handle);
                                ZERO_STRUCTP(r->out.handle);
@@ -1692,8 +1768,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
                           and not a printer admin, then fail */
 
                        if ((p->server_info->utok.uid != sec_initial_uid()) &&
-                           !user_has_privileges(p->server_info->ptok,
-                                                &se_printop ) &&
+                           !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
                            !token_contains_name_in_list(
                                    uidtoname(p->server_info->utok.uid),
                                    p->server_info->info3->base.domain.string,
@@ -1761,7 +1836,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
                if (!user_ok_token(uidtoname(p->server_info->utok.uid), NULL,
                                   p->server_info->ptok, snum) ||
-                   !print_access_check(get_server_info_system(),
+                   !print_access_check(p->server_info,
                                        p->msg_ctx,
                                        snum,
                                        r->in.access_mask)) {
@@ -1789,7 +1864,6 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
                winreg_create_printer(p->mem_ctx,
                                      get_server_info_system(),
                                      p->msg_ctx,
-                                     Printer->servername,
                                      lp_const_servicename(snum));
 
                break;
@@ -1932,13 +2006,12 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
        struct spoolss_DriverInfo8 *info_win2k = NULL;
        int                             version;
        WERROR                          status;
-       SE_PRIV                         se_printop = SE_PRINT_OPERATOR;
 
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
           and not a printer admin, then fail */
 
        if ( (p->server_info->utok.uid != sec_initial_uid())
-               && !user_has_privileges(p->server_info->ptok, &se_printop )
+            && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
                && !token_contains_name_in_list(
                        uidtoname(p->server_info->utok.uid),
                        p->server_info->info3->base.domain.string,
@@ -2038,13 +2111,12 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
        int                             version;
        bool                            delete_files;
        WERROR                          status;
-       SE_PRIV                         se_printop = SE_PRINT_OPERATOR;
 
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
           and not a printer admin, then fail */
 
        if ( (p->server_info->utok.uid != sec_initial_uid())
-               && !user_has_privileges(p->server_info->ptok, &se_printop )
+               && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
                && !token_contains_name_in_list(
                        uidtoname(p->server_info->utok.uid),
                        p->server_info->info3->base.domain.string,
@@ -2443,23 +2515,43 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
                                        uint32_t localprinter,
                                        enum winreg_Type type,
                                        struct policy_handle *handle,
+                                       struct notify_back_channel **_chan,
                                        struct sockaddr_storage *client_ss,
                                        struct messaging_context *msg_ctx)
 {
        WERROR result;
        NTSTATUS status;
+       struct notify_back_channel *chan;
+
+       for (chan = back_channels; chan; chan = chan->next) {
+               if (memcmp(&chan->client_address, client_ss,
+                          sizeof(struct sockaddr_storage)) == 0) {
+                       break;
+               }
+       }
 
        /*
         * If it's the first connection, contact the client
         * and connect to the IPC$ share anonymously
         */
-       if (back_channel.active_channels == 0) {
+       if (!chan) {
                fstring unix_printer;
 
-               fstrcpy(unix_printer, printer+2); /* the +2 is to strip the leading 2 backslashs */
+               /* the +2 is to strip the leading 2 backslashs */
+               fstrcpy(unix_printer, printer + 2);
 
-               if ( !spoolss_connect_to_client( &back_channel.cli_pipe, client_ss, unix_printer ))
+               chan = talloc_zero(back_channels, 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)) {
+                       TALLOC_FREE(chan);
+                       return false;
+               }
+
+               DLIST_ADD(back_channels, chan);
 
                messaging_register(msg_ctx, NULL, MSG_PRINTER_NOTIFY2,
                                   receive_notify2_message_list);
@@ -2474,12 +2566,12 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
         * by registering our PID.
         */
 
-       if (!print_notify_register_pid(snum))
-               DEBUG(0,("print_notify_register_pid: Failed to register our pid for printer %s\n", printer ));
-
-       back_channel.active_channels++;
+       if (!print_notify_register_pid(snum)) {
+               DEBUG(0, ("Failed to register our pid for printer %s\n",
+                         printer));
+       }
 
-       status = rpccli_spoolss_ReplyOpenPrinter(back_channel.cli_pipe, talloc_tos(),
+       status = rpccli_spoolss_ReplyOpenPrinter(chan->cli_pipe, talloc_tos(),
                                                 printer,
                                                 localprinter,
                                                 type,
@@ -2487,9 +2579,12 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
                                                 NULL,
                                                 handle,
                                                 &result);
-       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result))
-               DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
-                       win_errstr(result)));
+       if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) {
+               DEBUG(5, ("Client RPC returned [%s]\n", win_errstr(result)));
+       }
+
+       chan->active_connections++;
+       *_chan = chan;
 
        return (W_ERROR_IS_OK(result));
 }
@@ -2601,11 +2696,11 @@ WERROR _spoolss_RemoteFindFirstPrinterChangeNotifyEx(struct pipes_struct *p,
 
        if(!srv_spoolss_replyopenprinter(snum, Printer->notify.localmachine,
                                        Printer->notify.printerlocal, REG_SZ,
-                                       &Printer->notify.client_hnd,
-                                       &client_ss, p->msg_ctx))
+                                       &Printer->notify.cli_hnd,
+                                       &Printer->notify.cli_chan,
+                                       &client_ss, p->msg_ctx)) {
                return WERR_SERVER_UNAVAILABLE;
-
-       Printer->notify.client_connected = true;
+       }
 
        return WERR_OK;
 }
@@ -3425,7 +3520,6 @@ static WERROR printserver_notify_info(struct pipes_struct *p,
                        result = winreg_get_printer(mem_ctx,
                                                    get_server_info_system(),
                                                    p->msg_ctx,
-                                                   Printer->servername,
                                                    lp_servicename(snum),
                                                    &pinfo2);
                        if (!W_ERROR_IS_OK(result)) {
@@ -3512,7 +3606,6 @@ static WERROR printer_notify_info(struct pipes_struct *p,
        result = winreg_get_printer(mem_ctx,
                                    get_server_info_system(),
                                    p->msg_ctx,
-                                   Printer->servername,
                                    lp_servicename(snum), &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
                return WERR_BADFID;
@@ -3612,7 +3705,8 @@ WERROR _spoolss_RouterRefreshPrinterChangeNotify(struct pipes_struct *p,
 
        Printer->notify.fnpcn = true;
 
-       if (Printer->notify.client_connected) {
+       if (Printer->notify.cli_chan != NULL &&
+           Printer->notify.cli_chan->active_connections > 0) {
                DEBUG(10,("_spoolss_RouterRefreshPrinterChangeNotify: "
                        "Saving change value in request [%x]\n",
                        r->in.change_low));
@@ -3639,6 +3733,46 @@ done:
        return result;
 }
 
+/********************************************************************
+ ********************************************************************/
+
+static WERROR create_printername(TALLOC_CTX *mem_ctx,
+                                const char *servername,
+                                const char *printername,
+                                const char **printername_p)
+{
+       /* FIXME: add lp_force_printername() */
+
+       if (servername == NULL) {
+               *printername_p = talloc_strdup(mem_ctx, printername);
+               W_ERROR_HAVE_NO_MEMORY(*printername_p);
+               return WERR_OK;
+       }
+
+       if (servername[0] == '\\' && servername[1] == '\\') {
+               servername += 2;
+       }
+
+       *printername_p = talloc_asprintf(mem_ctx, "\\\\%s\\%s", servername, printername);
+       W_ERROR_HAVE_NO_MEMORY(*printername_p);
+
+       return WERR_OK;
+}
+
+/********************************************************************
+ ********************************************************************/
+
+static void compose_devicemode_devicename(struct spoolss_DeviceMode *dm,
+                                         const char *printername)
+{
+       if (dm == NULL) {
+               return;
+       }
+
+       dm->devicename = talloc_strndup(dm, printername,
+                                       MIN(strlen(printername), 31));
+}
+
 /********************************************************************
  * construct_printer_info_0
  * fill a printer_info_0 struct
@@ -3648,6 +3782,7 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
                                      const struct auth_serversupplied_info *server_info,
                                      struct messaging_context *msg_ctx,
                                      struct spoolss_PrinterInfo2 *info2,
+                                     const char *servername,
                                      struct spoolss_PrinterInfo0 *r,
                                      int snum)
 {
@@ -3655,12 +3790,19 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
        struct printer_session_counter *session_counter;
        struct timeval setuptime;
        print_status_struct status;
+       WERROR result;
 
-       r->printername          = talloc_strdup(mem_ctx, info2->printername);
-       W_ERROR_HAVE_NO_MEMORY(r->printername);
+       result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
 
-       r->servername           = talloc_strdup(mem_ctx, info2->servername);
-       W_ERROR_HAVE_NO_MEMORY(r->servername);
+       if (servername) {
+               r->servername = talloc_strdup(mem_ctx, servername);
+               W_ERROR_HAVE_NO_MEMORY(r->servername);
+       } else {
+               r->servername = NULL;
+       }
 
        count = print_queue_length(msg_ctx, snum, &status);
 
@@ -3735,16 +3877,13 @@ static WERROR construct_printer_info0(TALLOC_CTX *mem_ctx,
 static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
                                      const struct spoolss_PrinterInfo2 *info2,
                                      uint32_t flags,
+                                     const char *servername,
                                      struct spoolss_PrinterInfo1 *r,
                                      int snum)
 {
-       r->flags                = flags;
+       WERROR result;
 
-       r->description          = talloc_asprintf(mem_ctx, "%s,%s,%s",
-                                                 info2->printername,
-                                                 info2->drivername,
-                                                 info2->location);
-       W_ERROR_HAVE_NO_MEMORY(r->description);
+       r->flags                = flags;
 
        if (info2->comment == NULL || info2->comment[0] == '\0') {
                r->comment      = talloc_strdup(mem_ctx, lp_comment(snum));
@@ -3753,8 +3892,16 @@ static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
        }
        W_ERROR_HAVE_NO_MEMORY(r->comment);
 
-       r->name                 = talloc_strdup(mem_ctx, info2->printername);
-       W_ERROR_HAVE_NO_MEMORY(r->name);
+       result = create_printername(mem_ctx, servername, info2->printername, &r->name);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
+       r->description          = talloc_asprintf(mem_ctx, "%s,%s,%s",
+                                                 r->name,
+                                                 info2->drivername,
+                                                 r->comment);
+       W_ERROR_HAVE_NO_MEMORY(r->description);
 
        return WERR_OK;
 }
@@ -3767,18 +3914,28 @@ static WERROR construct_printer_info1(TALLOC_CTX *mem_ctx,
 static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
                                      struct messaging_context *msg_ctx,
                                      const struct spoolss_PrinterInfo2 *info2,
+                                     const char *servername,
                                      struct spoolss_PrinterInfo2 *r,
                                      int snum)
 {
        int count;
        print_status_struct status;
+       WERROR result;
 
        count = print_queue_length(msg_ctx, snum, &status);
 
-       r->servername           = talloc_strdup(mem_ctx, info2->servername);
-       W_ERROR_HAVE_NO_MEMORY(r->servername);
-       r->printername          = talloc_strdup(mem_ctx, info2->printername);
-       W_ERROR_HAVE_NO_MEMORY(r->printername);
+       if (servername) {
+               r->servername           = talloc_strdup(mem_ctx, servername);
+               W_ERROR_HAVE_NO_MEMORY(r->servername);
+       } else {
+               r->servername           = NULL;
+       }
+
+       result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
        r->sharename            = talloc_strdup(mem_ctx, lp_servicename(snum));
        W_ERROR_HAVE_NO_MEMORY(r->sharename);
        r->portname             = talloc_strdup(mem_ctx, info2->portname);
@@ -3819,6 +3976,8 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
                DEBUG(8,("Returning NULL Devicemode!\n"));
        }
 
+       compose_devicemode_devicename(r->devmode, r->printername);
+
        r->secdesc = NULL;
 
        if (info2->secdesc != NULL) {
@@ -3838,6 +3997,7 @@ static WERROR construct_printer_info2(TALLOC_CTX *mem_ctx,
 
 static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
                                      const struct spoolss_PrinterInfo2 *info2,
+                                     const char *servername,
                                      struct spoolss_PrinterInfo3 *r,
                                      int snum)
 {
@@ -3861,13 +4021,23 @@ static WERROR construct_printer_info3(TALLOC_CTX *mem_ctx,
 
 static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
                                      const struct spoolss_PrinterInfo2 *info2,
+                                     const char *servername,
                                      struct spoolss_PrinterInfo4 *r,
                                      int snum)
 {
-       r->printername  = talloc_strdup(mem_ctx, info2->printername);
-       W_ERROR_HAVE_NO_MEMORY(r->printername);
-       r->servername   = talloc_strdup(mem_ctx, info2->servername);
-       W_ERROR_HAVE_NO_MEMORY(r->servername);
+       WERROR result;
+
+       result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
+       if (servername) {
+               r->servername   = talloc_strdup(mem_ctx, servername);
+               W_ERROR_HAVE_NO_MEMORY(r->servername);
+       } else {
+               r->servername = NULL;
+       }
 
        r->attributes   = info2->attributes;
 
@@ -3881,11 +4051,17 @@ static WERROR construct_printer_info4(TALLOC_CTX *mem_ctx,
 
 static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
                                      const struct spoolss_PrinterInfo2 *info2,
+                                     const char *servername,
                                      struct spoolss_PrinterInfo5 *r,
                                      int snum)
 {
-       r->printername  = talloc_strdup(mem_ctx, info2->printername);
-       W_ERROR_HAVE_NO_MEMORY(r->printername);
+       WERROR result;
+
+       result = create_printername(mem_ctx, servername, info2->printername, &r->printername);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
        r->portname     = talloc_strdup(mem_ctx, info2->portname);
        W_ERROR_HAVE_NO_MEMORY(r->portname);
 
@@ -3906,6 +4082,7 @@ static WERROR construct_printer_info5(TALLOC_CTX *mem_ctx,
 static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
                                      struct messaging_context *msg_ctx,
                                      const struct spoolss_PrinterInfo2 *info2,
+                                     const char *servername,
                                      struct spoolss_PrinterInfo6 *r,
                                      int snum)
 {
@@ -3926,7 +4103,7 @@ static WERROR construct_printer_info6(TALLOC_CTX *mem_ctx,
 
 static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
                                      struct messaging_context *msg_ctx,
-                                     struct printer_handle *print_hnd,
+                                     const char *servername,
                                      struct spoolss_PrinterInfo7 *r,
                                      int snum)
 {
@@ -3942,7 +4119,7 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
        }
 
        if (is_printer_published(mem_ctx, server_info, msg_ctx,
-                                print_hnd->servername,
+                                servername,
                                 lp_servicename(snum), &guid, NULL)) {
                r->guid = talloc_strdup_upper(mem_ctx, GUID_string2(mem_ctx, &guid));
                r->action = DSPRINT_PUBLISH;
@@ -3963,14 +4140,25 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
 
 static WERROR construct_printer_info8(TALLOC_CTX *mem_ctx,
                                      const struct spoolss_PrinterInfo2 *info2,
+                                     const char *servername,
                                      struct spoolss_DeviceModeInfo *r,
                                      int snum)
 {
+       WERROR result;
+       const char *printername;
+
+       result = create_printername(mem_ctx, servername, info2->printername, &printername);
+       if (!W_ERROR_IS_OK(result)) {
+               return result;
+       }
+
        copy_devicemode(mem_ctx, info2->devmode, &r->devmode);
        if (!r->devmode) {
                DEBUG(8,("Returning NULL Devicemode!\n"));
        }
 
+       compose_devicemode_devicename(r->devmode, printername);
+
        return WERR_OK;
 }
 
@@ -3990,6 +4178,7 @@ static bool snum_is_shared_printer(int snum)
 static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                                           const struct auth_serversupplied_info *server_info,
                                           struct messaging_context *msg_ctx,
+                                          const char *servername,
                                           uint32_t level,
                                           uint32_t flags,
                                           union spoolss_PrinterInfo **info_p,
@@ -4021,7 +4210,6 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                result = winreg_create_printer(mem_ctx,
                                               server_info,
                                               msg_ctx,
-                                              NULL,
                                               printer);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
@@ -4036,7 +4224,7 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                }
 
                result = winreg_get_printer(mem_ctx, server_info, msg_ctx,
-                                           NULL, printer, &info2);
+                                           printer, &info2);
                if (!W_ERROR_IS_OK(result)) {
                        goto out;
                }
@@ -4045,22 +4233,27 @@ static WERROR enum_all_printers_info_level(TALLOC_CTX *mem_ctx,
                case 0:
                        result = construct_printer_info0(info, server_info,
                                                         msg_ctx, info2,
+                                                        servername,
                                                         &info[count].info0, snum);
                        break;
                case 1:
                        result = construct_printer_info1(info, info2, flags,
+                                                        servername,
                                                         &info[count].info1, snum);
                        break;
                case 2:
                        result = construct_printer_info2(info, msg_ctx, info2,
+                                                        servername,
                                                         &info[count].info2, snum);
                        break;
                case 4:
                        result = construct_printer_info4(info, info2,
+                                                        servername,
                                                         &info[count].info4, snum);
                        break;
                case 5:
                        result = construct_printer_info5(info, info2,
+                                                        servername,
                                                         &info[count].info5, snum);
                        break;
 
@@ -4105,7 +4298,7 @@ static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
        DEBUG(4,("enum_all_printers_info_0\n"));
 
        return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
-                                           0, flags, info, count);
+                                           servername, 0, flags, info, count);
 }
 
 
@@ -4115,6 +4308,7 @@ static WERROR enumprinters_level0(TALLOC_CTX *mem_ctx,
 static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
                                       const struct auth_serversupplied_info *server_info,
                                       struct messaging_context *msg_ctx,
+                                      const char *servername,
                                       uint32_t flags,
                                       union spoolss_PrinterInfo **info,
                                       uint32_t *count)
@@ -4122,7 +4316,7 @@ static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
        DEBUG(4,("enum_all_printers_info_1\n"));
 
        return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
-                                           1, flags, info, count);
+                                           servername, 1, flags, info, count);
 }
 
 /********************************************************************
@@ -4132,13 +4326,14 @@ static WERROR enum_all_printers_info_1(TALLOC_CTX *mem_ctx,
 static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
                                             const struct auth_serversupplied_info *server_info,
                                             struct messaging_context *msg_ctx,
+                                            const char *servername,
                                             union spoolss_PrinterInfo **info,
                                             uint32_t *count)
 {
        DEBUG(4,("enum_all_printers_info_1_local\n"));
 
        return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
-                                       PRINTER_ENUM_ICON8, info, count);
+                                       servername, PRINTER_ENUM_ICON8, info, count);
 }
 
 /********************************************************************
@@ -4148,16 +4343,16 @@ static WERROR enum_all_printers_info_1_local(TALLOC_CTX *mem_ctx,
 static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
                                            const struct auth_serversupplied_info *server_info,
                                            struct messaging_context *msg_ctx,
-                                           const char *name,
+                                           const char *servername,
                                            union spoolss_PrinterInfo **info,
                                            uint32_t *count)
 {
-       const char *s = name;
+       const char *s = servername;
 
        DEBUG(4,("enum_all_printers_info_1_name\n"));
 
-       if ((name[0] == '\\') && (name[1] == '\\')) {
-               s = name + 2;
+       if ((servername[0] == '\\') && (servername[1] == '\\')) {
+               s = servername + 2;
        }
 
        if (!is_myname_or_ipaddr(s)) {
@@ -4165,7 +4360,7 @@ static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
        }
 
        return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
-                                       PRINTER_ENUM_ICON8, info, count);
+                                       servername, PRINTER_ENUM_ICON8, info, count);
 }
 
 /********************************************************************
@@ -4175,11 +4370,11 @@ static WERROR enum_all_printers_info_1_name(TALLOC_CTX *mem_ctx,
 static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
                                               const struct auth_serversupplied_info *server_info,
                                               struct messaging_context *msg_ctx,
-                                              const char *name,
+                                              const char *servername,
                                               union spoolss_PrinterInfo **info,
                                               uint32_t *count)
 {
-       const char *s = name;
+       const char *s = servername;
 
        DEBUG(4,("enum_all_printers_info_1_network\n"));
 
@@ -4191,8 +4386,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 (name[0] == '\\' && name[1] == '\\') {
-                s = name + 2;
+       if (servername[0] == '\\' && servername[1] == '\\') {
+                s = servername + 2;
        }
 
        if (is_myname_or_ipaddr(s)) {
@@ -4200,7 +4395,7 @@ static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
        }
 
        return enum_all_printers_info_1(mem_ctx, server_info, msg_ctx,
-                                       PRINTER_ENUM_NAME, info, count);
+                                       servername, PRINTER_ENUM_NAME, info, count);
 }
 
 /********************************************************************
@@ -4212,13 +4407,14 @@ static WERROR enum_all_printers_info_1_network(TALLOC_CTX *mem_ctx,
 static WERROR enum_all_printers_info_2(TALLOC_CTX *mem_ctx,
                                       const struct auth_serversupplied_info *server_info,
                                       struct messaging_context *msg_ctx,
+                                      const char *servername,
                                       union spoolss_PrinterInfo **info,
                                       uint32_t *count)
 {
        DEBUG(4,("enum_all_printers_info_2\n"));
 
        return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
-                                           2, 0, info, count);
+                                           servername, 2, 0, info, count);
 }
 
 /********************************************************************
@@ -4229,7 +4425,7 @@ static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
                                  const struct auth_serversupplied_info *server_info,
                                  struct messaging_context *msg_ctx,
                                  uint32_t flags,
-                                 const char *name,
+                                 const char *servername,
                                  union spoolss_PrinterInfo **info,
                                  uint32_t *count)
 {
@@ -4237,18 +4433,18 @@ static WERROR enumprinters_level1(TALLOC_CTX *mem_ctx,
 
        if (flags & PRINTER_ENUM_LOCAL) {
                return enum_all_printers_info_1_local(mem_ctx, server_info,
-                                                     msg_ctx, info, count);
+                                                     msg_ctx, servername, info, count);
        }
 
        if (flags & PRINTER_ENUM_NAME) {
                return enum_all_printers_info_1_name(mem_ctx, server_info,
-                                                    msg_ctx, name, info,
+                                                    msg_ctx, servername, info,
                                                     count);
        }
 
        if (flags & PRINTER_ENUM_NETWORK) {
                return enum_all_printers_info_1_network(mem_ctx, server_info,
-                                                       msg_ctx, name, info,
+                                                       msg_ctx, servername, info,
                                                        count);
        }
 
@@ -4268,16 +4464,19 @@ static WERROR enumprinters_level2(TALLOC_CTX *mem_ctx,
                                  uint32_t *count)
 {
        if (flags & PRINTER_ENUM_LOCAL) {
+
                return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
+                                               servername,
                                                info, count);
        }
 
        if (flags & PRINTER_ENUM_NAME) {
-               if (!is_myname_or_ipaddr(canon_servername(servername))) {
+               if (servername && !is_myname_or_ipaddr(canon_servername(servername))) {
                        return WERR_INVALID_NAME;
                }
 
                return enum_all_printers_info_2(mem_ctx, server_info, msg_ctx,
+                                               servername,
                                                info, count);
        }
 
@@ -4303,7 +4502,7 @@ static WERROR enumprinters_level4(TALLOC_CTX *mem_ctx,
        DEBUG(4,("enum_all_printers_info_4\n"));
 
        return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
-                                           4, flags, info, count);
+                                           servername, 4, flags, info, count);
 }
 
 
@@ -4322,7 +4521,7 @@ static WERROR enumprinters_level5(TALLOC_CTX *mem_ctx,
        DEBUG(4,("enum_all_printers_info_5\n"));
 
        return enum_all_printers_info_level(mem_ctx, server_info, msg_ctx,
-                                           5, flags, info, count);
+                                           servername, 5, flags, info, count);
 }
 
 /****************************************************************
@@ -4333,7 +4532,6 @@ WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
                             struct spoolss_EnumPrinters *r)
 {
        const struct auth_serversupplied_info *server_info = get_server_info_system();
-       const char *name = NULL;
        WERROR result;
 
        /* that's an [in out] buffer */
@@ -4361,35 +4559,39 @@ WERROR _spoolss_EnumPrinters(struct pipes_struct *p,
         * Level 5: same as Level 2
         */
 
-       if (r->in.server) {
-               name = talloc_strdup_upper(p->mem_ctx, r->in.server);
-               W_ERROR_HAVE_NO_MEMORY(name);
+       if (r->in.server && r->in.server[0] == '\0') {
+               r->in.server = NULL;
        }
 
        switch (r->in.level) {
        case 0:
                result = enumprinters_level0(p->mem_ctx, server_info,
-                                            p->msg_ctx, r->in.flags, name,
+                                            p->msg_ctx, r->in.flags,
+                                            r->in.server,
                                             r->out.info, r->out.count);
                break;
        case 1:
                result = enumprinters_level1(p->mem_ctx, server_info,
-                                            p->msg_ctx, r->in.flags, name,
+                                            p->msg_ctx, r->in.flags,
+                                            r->in.server,
                                             r->out.info, r->out.count);
                break;
        case 2:
                result = enumprinters_level2(p->mem_ctx, server_info,
-                                            p->msg_ctx, r->in.flags, name,
+                                            p->msg_ctx, r->in.flags,
+                                            r->in.server,
                                             r->out.info, r->out.count);
                break;
        case 4:
                result = enumprinters_level4(p->mem_ctx, server_info,
-                                            p->msg_ctx, r->in.flags, name,
+                                            p->msg_ctx, r->in.flags,
+                                            r->in.server,
                                             r->out.info, r->out.count);
                break;
        case 5:
                result = enumprinters_level5(p->mem_ctx, server_info,
-                                            p->msg_ctx, r->in.flags, name,
+                                            p->msg_ctx, r->in.flags,
+                                            r->in.server,
                                             r->out.info, r->out.count);
                break;
        default:
@@ -4420,7 +4622,6 @@ WERROR _spoolss_GetPrinter(struct pipes_struct *p,
        struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
        struct spoolss_PrinterInfo2 *info2 = NULL;
        WERROR result = WERR_OK;
-       const char *servername = NULL;
        int snum;
 
        /* that's an [in out] buffer */
@@ -4431,22 +4632,21 @@ WERROR _spoolss_GetPrinter(struct pipes_struct *p,
 
        *r->out.needed = 0;
 
-       if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
+       if (Printer == NULL) {
                return WERR_BADFID;
        }
 
-       if (Printer != NULL || Printer->servername != NULL) {
-               servername = Printer->servername;
+       if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
+               return WERR_BADFID;
        }
 
        result = winreg_get_printer(p->mem_ctx,
                                    get_server_info_system(),
                                    p->msg_ctx,
-                                   servername,
                                    lp_const_servicename(snum),
                                    &info2);
        if (!W_ERROR_IS_OK(result)) {
-               return result;
+               goto out;
        }
 
        switch (r->in.level) {
@@ -4455,41 +4655,49 @@ WERROR _spoolss_GetPrinter(struct pipes_struct *p,
                                                 get_server_info_system(),
                                                 p->msg_ctx,
                                                 info2,
+                                                Printer->servername,
                                                 &r->out.info->info0,
                                                 snum);
                break;
        case 1:
                result = construct_printer_info1(p->mem_ctx, info2,
                                                 PRINTER_ENUM_ICON8,
+                                                Printer->servername,
                                                 &r->out.info->info1, snum);
                break;
        case 2:
                result = construct_printer_info2(p->mem_ctx, p->msg_ctx, info2,
+                                                Printer->servername,
                                                 &r->out.info->info2, snum);
                break;
        case 3:
                result = construct_printer_info3(p->mem_ctx, info2,
+                                                Printer->servername,
                                                 &r->out.info->info3, snum);
                break;
        case 4:
                result = construct_printer_info4(p->mem_ctx, info2,
+                                                Printer->servername,
                                                 &r->out.info->info4, snum);
                break;
        case 5:
                result = construct_printer_info5(p->mem_ctx, info2,
+                                                Printer->servername,
                                                 &r->out.info->info5, snum);
                break;
        case 6:
                result = construct_printer_info6(p->mem_ctx, p->msg_ctx, info2,
+                                                Printer->servername,
                                                 &r->out.info->info6, snum);
                break;
        case 7:
                result = construct_printer_info7(p->mem_ctx, p->msg_ctx,
-                                                Printer,
+                                                Printer->servername,
                                                 &r->out.info->info7, snum);
                break;
        case 8:
                result = construct_printer_info8(p->mem_ctx, info2,
+                                                Printer->servername,
                                                 &r->out.info->info8, snum);
                break;
        default:
@@ -4497,6 +4705,7 @@ WERROR _spoolss_GetPrinter(struct pipes_struct *p,
                break;
        }
 
+ out:
        if (!W_ERROR_IS_OK(result)) {
                DEBUG(0, ("_spoolss_GetPrinter: failed to construct printer info level %d - %s\n",
                          r->in.level, win_errstr(result)));
@@ -5205,10 +5414,13 @@ static WERROR construct_printer_driver_info_level(TALLOC_CTX *mem_ctx,
        struct spoolss_DriverInfo8 *driver;
        WERROR result;
 
+       if (level == 101) {
+               return WERR_UNKNOWN_LEVEL;
+       }
+
        result = winreg_get_printer(mem_ctx,
                                    server_info,
                                    msg_ctx,
-                                   servername,
                                    lp_const_servicename(snum),
                                    &pinfo2);
 
@@ -5438,7 +5650,7 @@ WERROR _spoolss_StartDocPrinter(struct pipes_struct *p,
                return WERR_BADFID;
        }
 
-       werr = print_job_start(get_server_info_system(),
+       werr = print_job_start(p->server_info,
                               p->msg_ctx,
                               p->client_id->name,
                               snum,
@@ -5541,7 +5753,7 @@ WERROR _spoolss_WritePrinter(struct pipes_struct *p,
 static WERROR control_printer(struct policy_handle *handle, uint32_t command,
                              struct pipes_struct *p)
 {
-       const struct auth_serversupplied_info *server_info = get_server_info_system();
+       const struct auth_serversupplied_info *server_info = p->server_info;
        int snum;
        WERROR errcode = WERR_BADFUNC;
        struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
@@ -5600,7 +5812,7 @@ WERROR _spoolss_AbortPrinter(struct pipes_struct *p,
                return WERR_SPL_NO_STARTDOC;
        }
 
-       errcode = print_job_delete(get_server_info_system(),
+       errcode = print_job_delete(p->server_info,
                                   p->msg_ctx,
                                   snum,
                                   Printer->jobid);
@@ -5771,12 +5983,11 @@ static bool check_printer_ok(TALLOC_CTX *mem_ctx,
 /****************************************************************************
 ****************************************************************************/
 
-static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri)
+static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const char *portname, const char *uri)
 {
        char *cmd = lp_addport_cmd();
        char *command = NULL;
        int ret;
-       SE_PRIV se_printop = SE_PRINT_OPERATOR;
        bool is_print_op = false;
 
        if ( !*cmd ) {
@@ -5790,7 +6001,7 @@ static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *p
        }
 
        if ( token )
-               is_print_op = user_has_privileges( token, &se_printop );
+               is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
 
        DEBUG(10,("Running [%s]\n", command));
 
@@ -5820,7 +6031,7 @@ static WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *p
 /****************************************************************************
 ****************************************************************************/
 
-static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
+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)
@@ -5831,7 +6042,6 @@ static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
        int numlines;
        int ret;
        int fd;
-       SE_PRIV se_printop = SE_PRINT_OPERATOR;
        bool is_print_op = false;
 
        if (!remote_machine) {
@@ -5848,7 +6058,7 @@ static bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token,
        }
 
        if ( token )
-               is_print_op = user_has_privileges( token, &se_printop );
+               is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
 
        DEBUG(10,("Running [%s]\n", command));
 
@@ -5933,7 +6143,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                printer->drivername));
 
                        notify_printer_driver(server_event_context(), msg_ctx,
-                                             snum, printer->drivername);
+                                             snum, printer->drivername ?
+                                             printer->drivername : "");
                }
        }
 
@@ -5951,7 +6162,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
 
                if (!force_update) {
                        notify_printer_comment(server_event_context(), msg_ctx,
-                                              snum, printer->comment);
+                                              snum, printer->comment ?
+                                              printer->comment : "");
                }
        }
 
@@ -5970,7 +6182,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                if (!force_update) {
                        notify_printer_sharename(server_event_context(),
                                                 msg_ctx,
-                                                snum, printer->sharename);
+                                                snum, printer->sharename ?
+                                                printer->sharename : "");
                }
        }
 
@@ -5997,7 +6210,7 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
 
                if (!force_update) {
                        notify_printer_printername(server_event_context(),
-                                                  msg_ctx, snum, p);
+                                                  msg_ctx, snum, p ? p : "");
                }
        }
 
@@ -6015,7 +6228,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
 
                if (!force_update) {
                        notify_printer_port(server_event_context(),
-                                           msg_ctx, snum, printer->portname);
+                                           msg_ctx, snum, printer->portname ?
+                                           printer->portname : "");
                }
        }
 
@@ -6034,7 +6248,8 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                if (!force_update) {
                        notify_printer_location(server_event_context(),
                                                msg_ctx, snum,
-                                               printer->location);
+                                               printer->location ?
+                                               printer->location : "");
                }
        }
 
@@ -6051,9 +6266,10 @@ static WERROR update_dsspooler(TALLOC_CTX *mem_ctx,
                                          buffer.length);
 
                if (!force_update) {
-                       notify_printer_location(server_event_context(),
-                                               msg_ctx, snum,
-                                               printer->location);
+                       notify_printer_sepfile(server_event_context(),
+                                              msg_ctx, snum,
+                                              printer->sepfile ?
+                                              printer->sepfile : "");
                }
        }
 
@@ -6202,7 +6418,6 @@ static WERROR update_printer(struct pipes_struct *p,
        struct spoolss_SetPrinterInfo2 *printer = info_ctr->info.info2;
        struct spoolss_PrinterInfo2 *old_printer;
        struct printer_handle *Printer = find_printer_index_by_hnd(p, handle);
-       const char *servername = NULL;
        int snum;
        WERROR result = WERR_OK;
        TALLOC_CTX *tmp_ctx;
@@ -6224,14 +6439,9 @@ static WERROR update_printer(struct pipes_struct *p,
                goto done;
        }
 
-       if (Printer != NULL || Printer->servername != NULL) {
-               servername = Printer->servername;
-       }
-
        result = winreg_get_printer(tmp_ctx,
                                    get_server_info_system(),
                                    p->msg_ctx,
-                                   servername,
                                    lp_const_servicename(snum),
                                    &old_printer);
        if (!W_ERROR_IS_OK(result)) {
@@ -6329,7 +6539,6 @@ static WERROR publish_or_unpublish_printer(struct pipes_struct *p,
        result = winreg_get_printer(p->mem_ctx,
                                    get_server_info_system(),
                                    p->msg_ctx,
-                                   Printer->servername,
                                    lp_servicename(snum),
                                    &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
@@ -6447,17 +6656,17 @@ WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
                return WERR_BADFID;
        }
 
-       if (Printer->notify.client_connected == true) {
+       if (Printer->notify.cli_chan != NULL &&
+           Printer->notify.cli_chan->active_connections > 0) {
                int snum = -1;
 
-               if ( Printer->printer_type == SPLHND_SERVER)
-                       snum = -1;
-               else if ( (Printer->printer_type == SPLHND_PRINTER) &&
-                               !get_printer_snum(p, r->in.handle, &snum, NULL) )
-                       return WERR_BADFID;
+               if (Printer->printer_type == SPLHND_PRINTER) {
+                       if (!get_printer_snum(p, r->in.handle, &snum, NULL)) {
+                               return WERR_BADFID;
+                       }
+               }
 
-               srv_spoolss_replycloseprinter(
-                       snum, &Printer->notify.client_hnd, p->msg_ctx);
+               srv_spoolss_replycloseprinter(snum, Printer);
        }
 
        Printer->notify.flags=0;
@@ -6465,7 +6674,6 @@ WERROR _spoolss_FindClosePrinterNotify(struct pipes_struct *p,
        Printer->notify.localmachine[0]='\0';
        Printer->notify.printerlocal=0;
        TALLOC_FREE(Printer->notify.option);
-       Printer->notify.client_connected = false;
 
        return WERR_OK;
 }
@@ -6794,7 +7002,6 @@ WERROR _spoolss_EnumJobs(struct pipes_struct *p,
        result = winreg_get_printer(p->mem_ctx,
                                    get_server_info_system(),
                                    p->msg_ctx,
-                                   NULL,
                                    lp_const_servicename(snum),
                                    &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
@@ -6890,7 +7097,7 @@ static WERROR spoolss_setjob_1(TALLOC_CTX *mem_ctx,
 WERROR _spoolss_SetJob(struct pipes_struct *p,
                       struct spoolss_SetJob *r)
 {
-       const struct auth_serversupplied_info *server_info = get_server_info_system();
+       const struct auth_serversupplied_info *server_info = p->server_info;
        int snum;
        WERROR errcode = WERR_BADFUNC;
 
@@ -7602,7 +7809,7 @@ 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(get_server_info_system(),
+       if (!print_access_check(p->server_info,
                                p->msg_ctx,
                                snum,
                                PRINTER_ACCESS_ADMINISTER)) {
@@ -8161,7 +8368,6 @@ WERROR _spoolss_AddForm(struct pipes_struct *p,
        struct spoolss_AddFormInfo1 *form = r->in.info.info1;
        int snum = -1;
        WERROR status = WERR_OK;
-       SE_PRIV se_printop = SE_PRINT_OPERATOR;
 
        struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
 
@@ -8177,8 +8383,8 @@ WERROR _spoolss_AddForm(struct pipes_struct *p,
           and not a printer admin, then fail */
 
        if ((p->server_info->utok.uid != sec_initial_uid()) &&
-            !user_has_privileges(p->server_info->ptok, &se_printop) &&
-            !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
+           !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
+           !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
                                          p->server_info->info3->base.domain.string,
                                          NULL,
                                          p->server_info->ptok,
@@ -8235,7 +8441,6 @@ WERROR _spoolss_DeleteForm(struct pipes_struct *p,
        struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
        int snum = -1;
        WERROR status = WERR_OK;
-       SE_PRIV se_printop = SE_PRINT_OPERATOR;
 
        DEBUG(5,("_spoolss_DeleteForm\n"));
 
@@ -8246,8 +8451,8 @@ WERROR _spoolss_DeleteForm(struct pipes_struct *p,
        }
 
        if ((p->server_info->utok.uid != sec_initial_uid()) &&
-            !user_has_privileges(p->server_info->ptok, &se_printop) &&
-            !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
+           !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
+           !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
                                          p->server_info->info3->base.domain.string,
                                          NULL,
                                          p->server_info->ptok,
@@ -8295,7 +8500,6 @@ WERROR _spoolss_SetForm(struct pipes_struct *p,
        const char *form_name = r->in.form_name;
        int snum = -1;
        WERROR status = WERR_OK;
-       SE_PRIV se_printop = SE_PRINT_OPERATOR;
 
        struct printer_handle *Printer = find_printer_index_by_hnd(p, r->in.handle);
 
@@ -8311,7 +8515,7 @@ WERROR _spoolss_SetForm(struct pipes_struct *p,
           and not a printer admin, then fail */
 
        if ((p->server_info->utok.uid != sec_initial_uid()) &&
-            !user_has_privileges(p->server_info->ptok, &se_printop) &&
+            !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
             !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
                                          p->server_info->info3->base.domain.string,
                                          NULL,
@@ -8425,6 +8629,10 @@ WERROR _spoolss_EnumPrintProcessors(struct pipes_struct *p,
        *r->out.needed = 0;
        *r->out.info = NULL;
 
+       if (!get_short_archi(r->in.environment)) {
+               return WERR_INVALID_ENVIRONMENT;
+       }
+
        switch (r->in.level) {
        case 1:
                result = enumprintprocessors_level_1(p->mem_ctx, r->out.info,
@@ -8516,6 +8724,11 @@ WERROR _spoolss_EnumPrintProcDataTypes(struct pipes_struct *p,
        *r->out.needed = 0;
        *r->out.info = NULL;
 
+       if (r->in.print_processor_name == NULL ||
+           !strequal(r->in.print_processor_name, "winprint")) {
+               return WERR_UNKNOWN_PRINTPROCESSOR;
+       }
+
        switch (r->in.level) {
        case 1:
                result = enumprintprocdatatypes_level_1(p->mem_ctx, r->out.info,
@@ -8826,7 +9039,6 @@ WERROR _spoolss_GetJob(struct pipes_struct *p,
        result = winreg_get_printer(p->mem_ctx,
                                    get_server_info_system(),
                                    p->msg_ctx,
-                                   NULL,
                                    lp_const_servicename(snum),
                                    &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
@@ -9044,7 +9256,6 @@ WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
        result = winreg_get_printer(Printer,
                                    get_server_info_system(),
                                    p->msg_ctx,
-                                   Printer->servername,
                                    lp_servicename(snum),
                                    &pinfo2);
        if (!W_ERROR_IS_OK(result)) {
@@ -9395,6 +9606,9 @@ WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
                                           struct spoolss_GetPrintProcessorDirectory *r)
 {
        WERROR result;
+       fstring prnproc_share;
+       bool prnproc_share_exists = false;
+       int snum;
 
        /* that's an [in out] buffer */
 
@@ -9411,10 +9625,17 @@ WERROR _spoolss_GetPrintProcessorDirectory(struct pipes_struct *p,
 
        /* We always should reply with a local print processor directory so that
         * users are not forced to have a [prnproc$] share on the Samba spoolss
-        * server - Guenther */
+        * server, if users decide to do so, lets announce it though - Guenther */
+
+       fstrcpy(prnproc_share, "prnproc$");
+
+       snum = find_service(prnproc_share);
+       if (snum != -1) {
+               prnproc_share_exists = true;
+       }
 
        result = getprintprocessordirectory_level_1(p->mem_ctx,
-                                                   NULL, /* r->in.server */
+                                                   prnproc_share_exists ? r->in.server : NULL,
                                                    r->in.environment,
                                                    &r->out.info->info1);
        if (!W_ERROR_IS_OK(result)) {
@@ -9453,7 +9674,7 @@ static bool push_monitorui_buf(TALLOC_CTX *mem_ctx, DATA_BLOB *buf,
 *******************************************************************/
 
 static WERROR xcvtcp_monitorui(TALLOC_CTX *mem_ctx,
-                              NT_USER_TOKEN *token, DATA_BLOB *in,
+                              struct security_token *token, DATA_BLOB *in,
                               DATA_BLOB *out, uint32_t *needed)
 {
        const char *dllname = "tcpmonui.dll";
@@ -9508,7 +9729,7 @@ static bool pull_port_data_2(TALLOC_CTX *mem_ctx,
 *******************************************************************/
 
 static WERROR xcvtcp_addport(TALLOC_CTX *mem_ctx,
-                            NT_USER_TOKEN *token, DATA_BLOB *in,
+                            struct security_token *token, DATA_BLOB *in,
                             DATA_BLOB *out, uint32_t *needed)
 {
        struct spoolss_PortData1 port1;
@@ -9600,7 +9821,7 @@ struct xcv_api_table xcvtcp_cmds[] = {
 };
 
 static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
-                                    NT_USER_TOKEN *token, const char *command,
+                                    struct security_token *token, const char *command,
                                     DATA_BLOB *inbuf,
                                     DATA_BLOB *outbuf,
                                     uint32_t *needed )
@@ -9622,7 +9843,7 @@ static WERROR process_xcvtcp_command(TALLOC_CTX *mem_ctx,
 #if 0  /* don't support management using the "Local Port" monitor */
 
 static WERROR xcvlocal_monitorui(TALLOC_CTX *mem_ctx,
-                                NT_USER_TOKEN *token, DATA_BLOB *in,
+                                struct security_token *token, DATA_BLOB *in,
                                 DATA_BLOB *out, uint32_t *needed)
 {
        const char *dllname = "localui.dll";
@@ -9659,7 +9880,7 @@ struct xcv_api_table xcvlocal_cmds[] = {
 *******************************************************************/
 
 static WERROR process_xcvlocal_command(TALLOC_CTX *mem_ctx,
-                                      NT_USER_TOKEN *token, const char *command,
+                                      struct security_token *token, const char *command,
                                       DATA_BLOB *inbuf, DATA_BLOB *outbuf,
                                       uint32_t *needed)
 {
@@ -10083,11 +10304,11 @@ WERROR _spoolss_44(struct pipes_struct *p,
 }
 
 /****************************************************************
- _spoolss_47
+ _spoolss_SetPort
 ****************************************************************/
 
-WERROR _spoolss_47(struct pipes_struct *p,
-                  struct spoolss_47 *r)
+WERROR _spoolss_SetPort(struct pipes_struct *p,
+                       struct spoolss_SetPort *r)
 {
        p->rng_fault_state = true;
        return WERR_NOT_SUPPORTED;