summaryrefslogtreecommitdiff
path: root/source3/printing
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2021-03-13 14:34:35 +0100
committerJeremy Allison <jra@samba.org>2021-03-16 17:09:31 +0000
commit46cc9b512200fcd435be313e915c1b1fc0deb428 (patch)
tree62ee756bf8bd3bc85b5283be2204e8f2c4aa44de /source3/printing
parente09f29eedd718f4e02fd0de55e69af877713b46d (diff)
downloadsamba-46cc9b512200fcd435be313e915c1b1fc0deb428.tar.gz
printing: Introduce printer_list_printername_exists()
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>
Diffstat (limited to 'source3/printing')
-rw-r--r--source3/printing/load.c2
-rw-r--r--source3/printing/pcap.c9
-rw-r--r--source3/printing/printer_list.c21
-rw-r--r--source3/printing/printer_list.h2
-rw-r--r--source3/printing/printing.c3
-rw-r--r--source3/printing/queue_process.c4
6 files changed, 29 insertions, 12 deletions
diff --git a/source3/printing/load.c b/source3/printing/load.c
index 6fabec0fa46..5ee4267cfd0 100644
--- a/source3/printing/load.c
+++ b/source3/printing/load.c
@@ -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);
}
diff --git a/source3/printing/pcap.c b/source3/printing/pcap.c
index 3600f9c50fc..d348c658fd4 100644
--- a/source3/printing/pcap.c
+++ b/source3/printing/pcap.c
@@ -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.
***************************************************************************/
diff --git a/source3/printing/printer_list.c b/source3/printing/printer_list.c
index 0e479072a22..4efcc2e2dd8 100644
--- a/source3/printing/printer_list.c
+++ b/source3/printing/printer_list.c
@@ -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,
diff --git a/source3/printing/printer_list.h b/source3/printing/printer_list.h
index b12c1923e72..f30b3150671 100644
--- a/source3/printing/printer_list.h
+++ b/source3/printing/printer_list.h
@@ -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.
*
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 70a891b89be..15a8bc7846c 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -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;
diff --git a/source3/printing/queue_process.c b/source3/printing/queue_process.c
index b4f167956dc..5938fd2a262 100644
--- a/source3/printing/queue_process.c
+++ b/source3/printing/queue_process.c
@@ -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,