1 From cd3082b03487eaeddb0105807b5ad39b47aa65f1 Mon Sep 17 00:00:00 2001
2 From: Andreas Schneider <asn@samba.org>
3 Date: Tue, 8 Nov 2016 12:20:41 +0100
4 Subject: [PATCH] s3-spoolss: Remove printer from registry if it is unpublished
6 BUG: https://bugzilla.samba.org/show_bug.cgi?id=11665
8 Signed-off-by: Andreas Schneider <asn@samba.org>
9 Reviewed-by: Guenther Deschner <gd@samba.org>
11 source3/rpc_server/spoolss/srv_spoolss_nt.c | 34 ++++++++++++++++++++++++-----
12 1 file changed, 29 insertions(+), 5 deletions(-)
14 diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c
15 index 556cd4f..f1ab3fb 100644
16 --- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
17 +++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
18 @@ -4194,6 +4194,7 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
21 struct auth_serversupplied_info *session_info;
22 + struct spoolss_PrinterInfo2 *pinfo2 = NULL;
26 @@ -4218,7 +4219,7 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
29 if (is_printer_published(tmp_ctx, session_info, msg_ctx,
30 - servername, printer, NULL)) {
31 + servername, printer, &pinfo2)) {
33 werr = nt_printer_guid_get(tmp_ctx, session_info, msg_ctx,
35 @@ -4230,10 +4231,33 @@ static WERROR construct_printer_info7(TALLOC_CTX *mem_ctx,
36 werr = nt_printer_guid_retrieve(tmp_ctx, printer,
38 if (!W_ERROR_IS_OK(werr)) {
39 - DEBUG(1, ("Failed to retrieve GUID for "
40 - "printer [%s] from AD - "
41 - "Is the the printer still "
42 - "published ?\n", printer));
43 + DEBUG(3, ("Failed to retrieve GUID for "
44 + "printer [%s] from AD - %s\n",
47 + if (W_ERROR_EQUAL(werr, WERR_FILE_NOT_FOUND)) {
49 + * If we did not find it in AD, then it
50 + * is unpublished and we should reflect
51 + * this in the registry and return
54 + DEBUG(1, ("Unpublish printer [%s]\n",
55 + pinfo2->sharename));
56 + nt_printer_publish(tmp_ctx,
61 + r->guid = talloc_strdup(mem_ctx, "");
62 + r->action = DSPRINT_UNPUBLISH;
64 + if (r->guid == NULL) {
65 + werr = WERR_NOT_ENOUGH_MEMORY;