summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2021-03-11 18:02:44 +0100
committerJeremy Allison <jra@samba.org>2021-03-16 17:09:31 +0000
commite338d4fab47d78e28139979480902c8f95986a08 (patch)
treefbffd8ad0cc24fd6153152a551e6f8d22e2d4594 /source3
parent46cc9b512200fcd435be313e915c1b1fc0deb428 (diff)
downloadsamba-e338d4fab47d78e28139979480902c8f95986a08.tar.gz
printing: Move rap2jobid functions to their own file
This will make it easier to split out the spoolss functions later Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/include/printing.h3
-rw-r--r--source3/printing/printing.c144
-rw-r--r--source3/printing/printspoolss.c1
-rw-r--r--source3/printing/rap_jobid.c164
-rw-r--r--source3/printing/rap_jobid.h29
-rw-r--r--source3/smbd/lanman.c1
-rw-r--r--source3/smbd/reply.c1
-rw-r--r--source3/wscript_build1
8 files changed, 198 insertions, 146 deletions
diff --git a/source3/include/printing.h b/source3/include/printing.h
index 8a0bef31da1..20a2eb349d3 100644
--- a/source3/include/printing.h
+++ b/source3/include/printing.h
@@ -238,9 +238,6 @@ WERROR print_queue_resume(const struct auth_session_info *server_info,
struct messaging_context *msg_ctx, int snum);
WERROR print_queue_purge(const struct auth_session_info *server_info,
struct messaging_context *msg_ctx, int snum);
-uint16_t pjobid_to_rap(const char* sharename, uint32_t jobid);
-bool rap_to_pjobid(uint16_t rap_jobid, fstring sharename, uint32_t *pjobid);
-void rap_jobid_delete(const char* sharename, uint32_t jobid);
bool print_backend_init(struct messaging_context *msg_ctx);
void printing_end(void);
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 15a8bc7846c..403db853559 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -39,155 +39,13 @@
#include "lib/util/sys_rw_data.h"
#include "lib/util/string_wrappers.h"
#include "lib/global_contexts.h"
+#include "source3/printing/rap_jobid.h"
extern userdom_struct current_user_info;
/* Current printer interface */
static bool remove_from_jobs_added(const char* sharename, uint32_t jobid);
-/*
- the printing backend revolves around a tdb database that stores the
- SMB view of the print queue
-
- The key for this database is a jobid - a internally generated number that
- uniquely identifies a print job
-
- reading the print queue involves two steps:
- - possibly running lpq and updating the internal database from that
- - reading entries from the database
-
- jobids are assigned when a job starts spooling.
-*/
-
-static TDB_CONTEXT *rap_tdb;
-static uint16_t next_rap_jobid;
-struct rap_jobid_key {
- fstring sharename;
- uint32_t jobid;
-};
-
-/***************************************************************************
- Nightmare. LANMAN jobid's are 16 bit numbers..... We must map them to 32
- bit RPC jobids.... JRA.
-***************************************************************************/
-
-uint16_t pjobid_to_rap(const char* sharename, uint32_t jobid)
-{
- uint16_t rap_jobid;
- TDB_DATA data, key;
- struct rap_jobid_key jinfo;
- uint8_t buf[2];
-
- DEBUG(10,("pjobid_to_rap: called.\n"));
-
- if (!rap_tdb) {
- /* Create the in-memory tdb. */
- rap_tdb = tdb_open_log(NULL, 0, TDB_INTERNAL, (O_RDWR|O_CREAT), 0644);
- if (!rap_tdb)
- return 0;
- }
-
- ZERO_STRUCT( jinfo );
- fstrcpy( jinfo.sharename, sharename );
- jinfo.jobid = jobid;
- key.dptr = (uint8_t *)&jinfo;
- key.dsize = sizeof(jinfo);
-
- data = tdb_fetch(rap_tdb, key);
- if (data.dptr && data.dsize == sizeof(uint16_t)) {
- rap_jobid = SVAL(data.dptr, 0);
- SAFE_FREE(data.dptr);
- DEBUG(10,("pjobid_to_rap: jobid %u maps to RAP jobid %u\n",
- (unsigned int)jobid, (unsigned int)rap_jobid));
- return rap_jobid;
- }
- SAFE_FREE(data.dptr);
- /* Not found - create and store mapping. */
- rap_jobid = ++next_rap_jobid;
- if (rap_jobid == 0)
- rap_jobid = ++next_rap_jobid;
- SSVAL(buf,0,rap_jobid);
- data.dptr = buf;
- data.dsize = sizeof(rap_jobid);
- tdb_store(rap_tdb, key, data, TDB_REPLACE);
- tdb_store(rap_tdb, data, key, TDB_REPLACE);
-
- DEBUG(10,("pjobid_to_rap: created jobid %u maps to RAP jobid %u\n",
- (unsigned int)jobid, (unsigned int)rap_jobid));
- return rap_jobid;
-}
-
-bool rap_to_pjobid(uint16_t rap_jobid, fstring sharename, uint32_t *pjobid)
-{
- TDB_DATA data, key;
- uint8_t buf[2];
-
- DEBUG(10,("rap_to_pjobid called.\n"));
-
- if (!rap_tdb)
- return False;
-
- SSVAL(buf,0,rap_jobid);
- key.dptr = buf;
- key.dsize = sizeof(rap_jobid);
- data = tdb_fetch(rap_tdb, key);
- if ( data.dptr && data.dsize == sizeof(struct rap_jobid_key) )
- {
- struct rap_jobid_key *jinfo = (struct rap_jobid_key*)data.dptr;
- if (sharename != NULL) {
- fstrcpy( sharename, jinfo->sharename );
- }
- *pjobid = jinfo->jobid;
- DEBUG(10,("rap_to_pjobid: jobid %u maps to RAP jobid %u\n",
- (unsigned int)*pjobid, (unsigned int)rap_jobid));
- SAFE_FREE(data.dptr);
- return True;
- }
-
- DEBUG(10,("rap_to_pjobid: Failed to lookup RAP jobid %u\n",
- (unsigned int)rap_jobid));
- SAFE_FREE(data.dptr);
- return False;
-}
-
-void rap_jobid_delete(const char* sharename, uint32_t jobid)
-{
- TDB_DATA key, data;
- uint16_t rap_jobid;
- struct rap_jobid_key jinfo;
- uint8_t buf[2];
-
- DEBUG(10,("rap_jobid_delete: called.\n"));
-
- if (!rap_tdb)
- return;
-
- ZERO_STRUCT( jinfo );
- fstrcpy( jinfo.sharename, sharename );
- jinfo.jobid = jobid;
- key.dptr = (uint8_t *)&jinfo;
- key.dsize = sizeof(jinfo);
-
- data = tdb_fetch(rap_tdb, key);
- if (!data.dptr || (data.dsize != sizeof(uint16_t))) {
- DEBUG(10,("rap_jobid_delete: cannot find jobid %u\n",
- (unsigned int)jobid ));
- SAFE_FREE(data.dptr);
- return;
- }
-
- DEBUG(10,("rap_jobid_delete: deleting jobid %u\n",
- (unsigned int)jobid ));
-
- rap_jobid = SVAL(data.dptr, 0);
- SAFE_FREE(data.dptr);
- SSVAL(buf,0,rap_jobid);
- data.dptr = buf;
- data.dsize = sizeof(rap_jobid);
- tdb_delete(rap_tdb, key);
- tdb_delete(rap_tdb, data);
-}
-
static int get_queue_status(const char* sharename, print_status_struct *);
/****************************************************************************
diff --git a/source3/printing/printspoolss.c b/source3/printing/printspoolss.c
index fdd94b46e4e..f02f584ad48 100644
--- a/source3/printing/printspoolss.c
+++ b/source3/printing/printspoolss.c
@@ -26,6 +26,7 @@
#include "smbd/globals.h"
#include "../libcli/security/security.h"
#include "smbd/fd_handle.h"
+#include "source3/printing/rap_jobid.h"
struct print_file_data {
char *svcname;
diff --git a/source3/printing/rap_jobid.c b/source3/printing/rap_jobid.c
new file mode 100644
index 00000000000..7af3d4702d6
--- /dev/null
+++ b/source3/printing/rap_jobid.c
@@ -0,0 +1,164 @@
+/*
+ * Maintain rap vs spoolss jobids
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ the printing backend revolves around a tdb database that stores the
+ SMB view of the print queue
+
+ The key for this database is a jobid - a internally generated number that
+ uniquely identifies a print job
+
+ reading the print queue involves two steps:
+ - possibly running lpq and updating the internal database from that
+ - reading entries from the database
+
+ jobids are assigned when a job starts spooling.
+*/
+
+#include "rap_jobid.h"
+#include <tdb.h>
+#include "source3/include/util_tdb.h"
+#include "lib/util/string_wrappers.h"
+
+static TDB_CONTEXT *rap_tdb;
+static uint16_t next_rap_jobid;
+struct rap_jobid_key {
+ fstring sharename;
+ uint32_t jobid;
+};
+
+/***************************************************************************
+ Nightmare. LANMAN jobid's are 16 bit numbers..... We must map them to 32
+ bit RPC jobids.... JRA.
+***************************************************************************/
+
+uint16_t pjobid_to_rap(const char* sharename, uint32_t jobid)
+{
+ uint16_t rap_jobid;
+ TDB_DATA data, key;
+ struct rap_jobid_key jinfo;
+ uint8_t buf[2];
+
+ DEBUG(10,("pjobid_to_rap: called.\n"));
+
+ if (!rap_tdb) {
+ /* Create the in-memory tdb. */
+ rap_tdb = tdb_open_log(NULL, 0, TDB_INTERNAL, (O_RDWR|O_CREAT), 0644);
+ if (!rap_tdb)
+ return 0;
+ }
+
+ ZERO_STRUCT( jinfo );
+ fstrcpy( jinfo.sharename, sharename );
+ jinfo.jobid = jobid;
+ key.dptr = (uint8_t *)&jinfo;
+ key.dsize = sizeof(jinfo);
+
+ data = tdb_fetch(rap_tdb, key);
+ if (data.dptr && data.dsize == sizeof(uint16_t)) {
+ rap_jobid = SVAL(data.dptr, 0);
+ SAFE_FREE(data.dptr);
+ DEBUG(10,("pjobid_to_rap: jobid %u maps to RAP jobid %u\n",
+ (unsigned int)jobid, (unsigned int)rap_jobid));
+ return rap_jobid;
+ }
+ SAFE_FREE(data.dptr);
+ /* Not found - create and store mapping. */
+ rap_jobid = ++next_rap_jobid;
+ if (rap_jobid == 0)
+ rap_jobid = ++next_rap_jobid;
+ SSVAL(buf,0,rap_jobid);
+ data.dptr = buf;
+ data.dsize = sizeof(rap_jobid);
+ tdb_store(rap_tdb, key, data, TDB_REPLACE);
+ tdb_store(rap_tdb, data, key, TDB_REPLACE);
+
+ DEBUG(10,("pjobid_to_rap: created jobid %u maps to RAP jobid %u\n",
+ (unsigned int)jobid, (unsigned int)rap_jobid));
+ return rap_jobid;
+}
+
+bool rap_to_pjobid(uint16_t rap_jobid, fstring sharename, uint32_t *pjobid)
+{
+ TDB_DATA data, key;
+ uint8_t buf[2];
+
+ DEBUG(10,("rap_to_pjobid called.\n"));
+
+ if (!rap_tdb)
+ return False;
+
+ SSVAL(buf,0,rap_jobid);
+ key.dptr = buf;
+ key.dsize = sizeof(rap_jobid);
+ data = tdb_fetch(rap_tdb, key);
+ if ( data.dptr && data.dsize == sizeof(struct rap_jobid_key) )
+ {
+ struct rap_jobid_key *jinfo = (struct rap_jobid_key*)data.dptr;
+ if (sharename != NULL) {
+ fstrcpy( sharename, jinfo->sharename );
+ }
+ *pjobid = jinfo->jobid;
+ DEBUG(10,("rap_to_pjobid: jobid %u maps to RAP jobid %u\n",
+ (unsigned int)*pjobid, (unsigned int)rap_jobid));
+ SAFE_FREE(data.dptr);
+ return True;
+ }
+
+ DEBUG(10,("rap_to_pjobid: Failed to lookup RAP jobid %u\n",
+ (unsigned int)rap_jobid));
+ SAFE_FREE(data.dptr);
+ return False;
+}
+
+void rap_jobid_delete(const char* sharename, uint32_t jobid)
+{
+ TDB_DATA key, data;
+ uint16_t rap_jobid;
+ struct rap_jobid_key jinfo;
+ uint8_t buf[2];
+
+ DEBUG(10,("rap_jobid_delete: called.\n"));
+
+ if (!rap_tdb)
+ return;
+
+ ZERO_STRUCT( jinfo );
+ fstrcpy( jinfo.sharename, sharename );
+ jinfo.jobid = jobid;
+ key.dptr = (uint8_t *)&jinfo;
+ key.dsize = sizeof(jinfo);
+
+ data = tdb_fetch(rap_tdb, key);
+ if (!data.dptr || (data.dsize != sizeof(uint16_t))) {
+ DEBUG(10,("rap_jobid_delete: cannot find jobid %u\n",
+ (unsigned int)jobid ));
+ SAFE_FREE(data.dptr);
+ return;
+ }
+
+ DEBUG(10,("rap_jobid_delete: deleting jobid %u\n",
+ (unsigned int)jobid ));
+
+ rap_jobid = SVAL(data.dptr, 0);
+ SAFE_FREE(data.dptr);
+ SSVAL(buf,0,rap_jobid);
+ data.dptr = buf;
+ data.dsize = sizeof(rap_jobid);
+ tdb_delete(rap_tdb, key);
+ tdb_delete(rap_tdb, data);
+}
diff --git a/source3/printing/rap_jobid.h b/source3/printing/rap_jobid.h
new file mode 100644
index 00000000000..63256896f90
--- /dev/null
+++ b/source3/printing/rap_jobid.h
@@ -0,0 +1,29 @@
+/*
+ * Maintain rap vs spoolss jobids
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __PRINTING_RAP_JOBID_H__
+#define __PRINTING_RAP_JOBID_H__
+
+#include "includes.h"
+
+uint16_t pjobid_to_rap(const char *sharename, uint32_t jobid);
+bool rap_to_pjobid(
+ uint16_t rap_jobid, fstring sharename, uint32_t *pjobid);
+void rap_jobid_delete(const char *sharename, uint32_t jobid);
+
+#endif
diff --git a/source3/smbd/lanman.c b/source3/smbd/lanman.c
index 31ccd28d02f..92239273c15 100644
--- a/source3/smbd/lanman.c
+++ b/source3/smbd/lanman.c
@@ -44,6 +44,7 @@
#include "auth.h"
#include "rpc_server/rpc_ncacn_np.h"
#include "lib/util/string_wrappers.h"
+#include "source3/printing/rap_jobid.h"
#ifdef CHECK_TYPES
#undef CHECK_TYPES
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 5190e60b3f4..187b44cbef7 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -49,6 +49,7 @@
#include "smb1_utils.h"
#include "libcli/smb/smb2_posix.h"
#include "lib/util/string_wrappers.h"
+#include "source3/printing/rap_jobid.h"
/****************************************************************************
Ensure we check the path in *exactly* the same way as W2K for a findfirst/findnext
diff --git a/source3/wscript_build b/source3/wscript_build
index 5d04fcb41d1..e70491f6d70 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -790,6 +790,7 @@ bld.SAMBA3_SUBSYSTEM('PRINTBASE',
bld.SAMBA3_SUBSYSTEM('PRINTBACKEND',
source='''
printing/printing.c
+ printing/rap_jobid.c
printing/nt_printing.c
printing/nt_printing_tdb.c
printing/nt_printing_migrate_internal.c