printing: Introduce printer_list_printername_exists()
authorVolker Lendecke <vl@samba.org>
Sat, 13 Mar 2021 13:34:35 +0000 (14:34 +0100)
committerJeremy Allison <jra@samba.org>
Tue, 16 Mar 2021 17:09:31 +0000 (17:09 +0000)
Replace pcap_printername_ok(). Slightly different semantics: If the
printer list db has a corrupted record, this is not detected.

Why this patch? pcap_printername_ok() is a simple wrapper around the
tdb accessing function, and this reduces a dependency on pcap.c

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/param/service.c
source3/printing/load.c
source3/printing/pcap.c
source3/printing/printer_list.c
source3/printing/printer_list.h
source3/printing/printing.c
source3/printing/queue_process.c
source3/smbd/server_reload.c

index add6b40d619cb626ad92ad847770c1b757f569b1..880e79fb28471da1ff0d0d8079229b163dc1788c 100644 (file)
@@ -25,6 +25,7 @@
 #include "../librpc/gen_ndr/netlogon.h"
 #include "../libcli/security/security.h"
 #include "printing/pcap.h"
+#include "printing/printer_list.h"
 #include "passdb/lookup_sid.h"
 #include "auth.h"
 #include "lib/param/loadparm.h"
@@ -178,7 +179,7 @@ int find_service(TALLOC_CTX *ctx, const char *service_in, char **p_service_out)
                if (iPrinterService >= 0) {
                        DEBUG(3,("checking whether %s is a valid printer name...\n",
                                *p_service_out));
-                       if (pcap_printername_ok(*p_service_out)) {
+                       if (printer_list_printername_exists(*p_service_out)) {
                                DEBUG(3,("%s is a valid printer name\n",
                                        *p_service_out));
                                DEBUG(3,("adding %s as a printer service\n",
index 6fabec0fa469473eeef38850af8f2ecabdb905ef..5ee4267cfd093b47e769384b542790d603e0895e 100644 (file)
@@ -55,7 +55,7 @@ static void add_auto_printers(void)
                if (lp_servicenumber(p) >= 0)
                        continue;
                
-               if (pcap_printername_ok(p))
+               if (printer_list_printername_exists(p))
                        lp_add_printer(p, pnum);
        }
 
index 3600f9c50fcc9ae6c7c55fff1768edf5c89e975d..d348c658fd4b73692faf23fc61a5b9e06158d631 100644 (file)
@@ -211,15 +211,6 @@ done:
        return;
 }
 
-
-bool pcap_printername_ok(const char *printername)
-{
-       NTSTATUS status;
-
-       status = printer_list_get_printer(talloc_tos(), printername, NULL, NULL, 0);
-       return NT_STATUS_IS_OK(status);
-}
-
 /***************************************************************************
 run a function on each printer name in the printcap file.
 ***************************************************************************/
index 0e479072a229f4b152e8a87ba31fe4f33cf42be0..4efcc2e2dd868c8581945b59df1931a7e12619e7 100644 (file)
@@ -146,6 +146,27 @@ done:
        return status;
 }
 
+bool printer_list_printername_exists(const char *name)
+{
+       struct db_context *db = get_printer_list_db();
+       char *key = NULL;
+       bool ok;
+
+       if (db == NULL) {
+               return false;
+       }
+
+       key = talloc_asprintf_strupper_m(
+               talloc_tos(), PL_KEY_FORMAT, name);
+       if (key == NULL) {
+               return false;
+       }
+
+       ok = dbwrap_exists(db, string_term_tdb_data(key));
+       TALLOC_FREE(key);
+       return ok;
+}
+
 NTSTATUS printer_list_set_printer(TALLOC_CTX *mem_ctx,
                                  const char *name,
                                  const char *comment,
index b12c1923e7295a27c258d278f869be99759348e8..f30b3150671fcc6e72dd9af60e0c735ca3d97c81 100644 (file)
@@ -46,6 +46,8 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
                                  const char **location,
                                  time_t *last_refresh);
 
+bool printer_list_printername_exists(const char *name);
+
 /**
  * @brief Add a printer to the printer list database.
  *
index 70a891b89bee2cf40fdbc9d0cfc54ccf6b91bf4e..15a8bc7846c245f694fe8bd3e5979d85cde62cc1 100644 (file)
@@ -2731,7 +2731,8 @@ static WERROR print_job_checks(const struct auth_session_info *server_info,
        }
 
        /* for autoloaded printers, check that the printcap entry still exists */
-       if (lp_autoloaded(snum) && !pcap_printername_ok(sharename)) {
+       if (lp_autoloaded(snum) &&
+           !printer_list_printername_exists(sharename)) {
                DEBUG(3, ("print_job_checks: printer name %s check failed.\n",
                          sharename));
                return WERR_ACCESS_DENIED;
index b4f167956dcaadffb3650bb78d15d2514cd75b16..5938fd2a2622ef9d40d27f785249494eba34cb1a 100644 (file)
@@ -26,6 +26,7 @@
 #include "lib/util/util_process.h"
 #include "printing.h"
 #include "printing/pcap.h"
+#include "printing/printer_list.h"
 #include "printing/queue_process.h"
 #include "locking/proto.h"
 #include "locking/share_mode_lock.h"
@@ -98,7 +99,8 @@ static void delete_and_reload_printers_full(struct tevent_context *ev,
                pname = lp_printername(session_info, lp_sub, snum);
 
                /* check printer, but avoid removing non-autoloaded printers */
-               if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) {
+               if (lp_autoloaded(snum) &&
+                   !printer_list_printername_exists(pname)) {
                        DEBUG(3, ("removing stale printer %s\n", pname));
 
                        if (is_printer_published(session_info, session_info,
index 6e6f68e57167a015a6f2a8b14f1b35d02c0192b9..98ea2a4fda459407e2ac8c0bf733198aa8da7a04 100644 (file)
@@ -26,6 +26,7 @@
 #include "smbd/globals.h"
 #include "nt_printing.h"
 #include "printing/pcap.h"
+#include "printing/printer_list.h"
 #include "printing/load.h"
 #include "auth.h"
 #include "messages.h"
@@ -101,7 +102,8 @@ void delete_and_reload_printers(void)
                pname = lp_printername(frame, lp_sub, snum);
 
                /* check printer, but avoid removing non-autoloaded printers */
-               if (lp_autoloaded(snum) && !pcap_printername_ok(pname)) {
+               if (lp_autoloaded(snum) &&
+                   !printer_list_printername_exists(pname)) {
                        lp_killservice(snum);
                }
        }