]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
printing: rework nt_printer_guid_store to return errors
authorAndreas Schneider <asn@samba.org>
Thu, 18 Dec 2014 15:13:27 +0000 (15:13 +0000)
committerKarolin Seeger <kseeger@samba.org>
Sun, 15 Mar 2015 21:13:08 +0000 (22:13 +0100)
Callers can now choose whether or not to ignore errors.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11018

Pair-programmed-with: David Disseldorp <ddiss@samba.org>
Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
(cherry picked from commit 6595ced146a53dcef9bbd5d2deb82a44c8ce1a1a)

source3/include/nt_printing.h
source3/printing/nt_printing_ads.c

index 3dfe1bc2401a4d379e23966d8dc34614ea567931..914e2e3e4a017223d3f39863ec8d0c6eb828be27 100644 (file)
@@ -135,6 +135,9 @@ bool print_access_check(const struct auth_session_info *server_info,
 WERROR nt_printer_guid_retrieve(TALLOC_CTX *mem_ctx, const char *printer,
                                struct GUID *pguid);
 
+WERROR nt_printer_guid_store(struct messaging_context *msg_ctx,
+                            const char *printer, struct GUID guid);
+
 WERROR nt_printer_guid_get(TALLOC_CTX *mem_ctx,
                           const struct auth_session_info *session_info,
                           struct messaging_context *msg_ctx,
index e9c3e1a65b85ec2d8db82fbfd47b5067e3d50038..4f7dfaaa4c3bd8b4388a392b3f24797e82d5b083 100644 (file)
 /*****************************************************************
  ****************************************************************/
 
-static void store_printer_guid(struct messaging_context *msg_ctx,
-                              const char *printer, struct GUID guid)
+WERROR nt_printer_guid_store(struct messaging_context *msg_ctx,
+                            const char *printer, struct GUID guid)
 {
        TALLOC_CTX *tmp_ctx;
-       struct auth_session_info *session_info = NULL;
+       const struct auth_session_info *session_info;
        const char *guid_str;
        DATA_BLOB blob;
-       NTSTATUS status;
        WERROR result;
 
        tmp_ctx = talloc_new(NULL);
        if (!tmp_ctx) {
-               DEBUG(0, ("store_printer_guid: Out of memory?!\n"));
-               return;
+               DEBUG(0, ("Out of memory?!\n"));
+               return WERR_NOMEM;
        }
 
-       status = make_session_info_system(tmp_ctx, &session_info);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("store_printer_guid: "
-                         "Could not create system session_info\n"));
+       session_info = get_session_info_system();
+       if (session_info == NULL) {
+               DEBUG(0, ("Could not get system session_info\n"));
+               result = WERR_NOMEM;
                goto done;
        }
 
        guid_str = GUID_string(tmp_ctx, &guid);
        if (!guid_str) {
-               DEBUG(0, ("store_printer_guid: Out of memory?!\n"));
+               DEBUG(0, ("Out of memory?!\n"));
+               result = WERR_NOMEM;
                goto done;
        }
 
@@ -68,9 +68,9 @@ static void store_printer_guid(struct messaging_context *msg_ctx,
           Vista to whine */
 
        if (!push_reg_sz(tmp_ctx, &blob, guid_str)) {
-               DEBUG(0, ("store_printer_guid: "
-                         "Could not marshall string %s for objectGUID\n",
+               DEBUG(0, ("Could not marshall string %s for objectGUID\n",
                          guid_str));
+               result = WERR_NOMEM;
                goto done;
        }
 
@@ -79,12 +79,15 @@ static void store_printer_guid(struct messaging_context *msg_ctx,
                                           SPOOL_DSSPOOLER_KEY, "objectGUID",
                                           REG_SZ, blob.data, blob.length);
        if (!W_ERROR_IS_OK(result)) {
-               DEBUG(0, ("store_printer_guid: "
-                         "Failed to store GUID for printer %s\n", printer));
+               DEBUG(0, ("Failed to store GUID for printer %s\n", printer));
+               goto done;
        }
 
+       result = WERR_OK;
 done:
        talloc_free(tmp_ctx);
+
+       return result;
 }
 
 static WERROR nt_printer_dn_lookup(TALLOC_CTX *mem_ctx,
@@ -468,6 +471,7 @@ static WERROR nt_printer_publish_ads(struct messaging_context *msg_ctx,
        if (!ADS_ERR_OK(ads_rc)) {
                DEBUG(3, ("error publishing %s: %s\n",
                          printer, ads_errstr(ads_rc)));
+               /* XXX failed to publish, so no guid to retrieve */
        }
 
        win_rc = nt_printer_guid_retrieve_internal(ads, printer_dn, &guid);
@@ -476,8 +480,13 @@ static WERROR nt_printer_publish_ads(struct messaging_context *msg_ctx,
                return win_rc;
        }
 
-       /* TODO add a return value */
-       store_printer_guid(msg_ctx, printer, guid);
+       win_rc = nt_printer_guid_store(msg_ctx, printer, guid);
+       if (!W_ERROR_IS_OK(win_rc)) {
+               DEBUG(3, ("failed to store printer %s guid\n",
+                         printer));
+               /* not catastrophic, retrieve on next use */
+               win_rc = WERR_OK;
+       }
 
        TALLOC_FREE(ctx);
 
@@ -704,6 +713,12 @@ bool is_printer_published(TALLOC_CTX *mem_ctx,
        return true;
 }
 #else
+WERROR nt_printer_guid_store(struct messaging_context *msg_ctx,
+                          const char *printer, struct GUID guid)
+{
+       return WERR_NOT_SUPPORTED;
+}
+
 WERROR nt_printer_guid_retrieve(TALLOC_CTX *mem_ctx, const char *printer,
                                struct GUID *pguid)
 {