[SCM] Samba Shared Repository - branch v4-2-test updated

Karolin Seeger kseeger at samba.org
Mon Nov 17 15:25:07 MST 2014


The branch, v4-2-test has been updated
       via  d1b9915 pdb_tdb: Fix a TALLOC/SAFE_FREE mixup
       via  7552e2e s3-keytab: fix keytab array NULL termination.
       via  db7234f Added note about the support end of Samba 3 to WHATSNEW.TXT
       via  c279635 btrfs: don't leak opened directory handle
       via  c1ca930 spoolss: remove unused fill_job_info3()
       via  b7f4c0f spoolss: fix jobid in level 3 EnumJobs response
       via  2a9764a spoolss: fix jobid in level 2 GetJob and EnumJobs responses
       via  3a3577d spoolss: fix jobid in level 1 GetJob and EnumJobs responses
       via  65d62dc spoolss: fix GetJob jobid lookups
       via  e95a6c0 printing: add jobid_to_sysjob helper function
      from  aea86fb WHATSNEW: CTDB integrated build

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-2-test


- Log -----------------------------------------------------------------
commit d1b99159640669a06bc705dece617428168ea695
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Nov 11 10:35:50 2014 +0000

    pdb_tdb: Fix a TALLOC/SAFE_FREE mixup
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=10932
    invalid free in pdb_tdb
    
    Autobuild-User(v4-2-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-2-test): Mon Nov 17 23:24:51 CET 2014 on sn-devel-104

commit 7552e2eceecd7bfb500215ced8d2b997f37b202e
Author: Matt Rogers <mrogers at redhat.com>
Date:   Wed Nov 12 17:21:05 2014 +0100

    s3-keytab: fix keytab array NULL termination.
    
    Signed-off-by: Matt Rogers <mrogers at redhat.com>
    Reviewed-by: Guenther Deschner <gd at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 0de6799996955fbf8e19ace8c4b7b61f5a262cb5)
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=10933
    net ads join -k can segfault with existing keytab entries

commit db7234f7e11f633f8cad7e9d099bd4d56f61bb63
Author: Marc Muehlfeld <mmuehlfeld at samba.org>
Date:   Mon Nov 10 21:08:31 2014 +0100

    Added note about the support end of Samba 3 to WHATSNEW.TXT
    
    This note should mention, that with the release of 4.2, the support
    for the 3.6. series has ended. Also it should clarify the common
    misconception, that Samba 4.x doens't support previous features like
    NT4 domain support.
    
    Signed-off-by: Marc Muehlfeld <mmuehlfeld at samba.org>
    Signed-off-by: Karolin Seeger <kseeger at samba.org>

commit c27963503a29b5761206646298fa7e72ef0ec44f
Author: Noel Power <noel.power at suse.com>
Date:   Tue Nov 4 16:52:49 2014 +0100

    btrfs: don't leak opened directory handle
    
    Closing a directory handle file descriptor via close() is undefined,
    according to:
    http://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    (cherry picked from commit 6faef4d213e76077bdbaf83cf07f0261c11dc757)
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=10918

commit c1ca930dcb2f8e6f0462d79728d1749433b6fce6
Author: David Disseldorp <ddiss at samba.org>
Date:   Thu Oct 30 01:37:51 2014 +0100

    spoolss: remove unused fill_job_info3()
    
    This logic has been moved into the previous EnumJobs(level=3) caller.
    The info3 structure only contains two fields that are used, so it
    doesn't make sense to have a separate helper for it.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit d772b98283f289917a6a8370808d4d0912899384)

commit b7f4c0f9e840631e9deee46ff95d6f2e740222ab
Author: David Disseldorp <ddiss at samba.org>
Date:   Thu Oct 30 01:37:50 2014 +0100

    spoolss: fix jobid in level 3 EnumJobs response
    
    Until now, these responses have incorrectly carried the printing backend
    job identifier (sysjob), rather than the one allocated and returned by
    Samba on job submission.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=10905
    
    Reported-by: Franz Pförtsch <franz.pfoertsch at brose.com>
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 5e7ab3d2f4f7950099561eb22d6a9a1536297442)

commit 2a9764ab5c23349e3f13b242482967b1c4904766
Author: David Disseldorp <ddiss at samba.org>
Date:   Thu Oct 30 01:37:49 2014 +0100

    spoolss: fix jobid in level 2 GetJob and EnumJobs responses
    
    Until now, these responses have incorrectly carried the printing backend
    job identifier (sysjob), rather than the one allocated and returned by
    Samba on job submission.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=10905
    
    Reported-by: Franz Pförtsch <franz.pfoertsch at brose.com>
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 45abaf81c67b62bab571df208931241afa660802)

commit 3a3577dfe35eb88e6202f3c48cdf19bec71fbe1a
Author: David Disseldorp <ddiss at samba.org>
Date:   Thu Oct 30 01:37:48 2014 +0100

    spoolss: fix jobid in level 1 GetJob and EnumJobs responses
    
    Until now, these responses have incorrectly carried the printing backend
    job identifier (sysjob), rather than the one allocated and returned by
    Samba on job submission.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=10905
    
    Reported-by: Franz Pförtsch <franz.pfoertsch at brose.com>
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 4d7f5d2af6ef6960dccaccf89c6e88947e2591bf)

commit 65d62dcdbb37c7b1743093f4ce9ee9428352d164
Author: David Disseldorp <ddiss at samba.org>
Date:   Thu Oct 30 01:37:47 2014 +0100

    spoolss: fix GetJob jobid lookups
    
    Clients issue GetJob requests using the jobid assigned by the spoolss
    server. The corresponding printing backend (sysjob) identifier needs to
    be resolved to locate the correct print queue entry.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=10905
    
    Reported-by: Franz Pförtsch <franz.pfoertsch at brose.com>
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 3a28ae56977235d3c9e3abcd1f24b220e536c50d)

commit e95a6c096c6b185f784e290fc0e57a21dc16d7d8
Author: David Disseldorp <ddiss at samba.org>
Date:   Thu Oct 30 01:37:46 2014 +0100

    printing: add jobid_to_sysjob helper function
    
    Samba needs to deal with two types of print job identifiers, those
    allocated by the printing backend (sysjob ids), and those allocated
    by Samba's spoolss server (jobids).
    
    This change adds a helper function to map spoolss jobids to sysjob ids,
    to go alongside the corresponding sysjob to jobid mapping function.
    
    Signed-off-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 77b5be1742ee7aa2733a25bfa6a3af369f5c9401)

-----------------------------------------------------------------------

Summary of changes:
 WHATSNEW.txt                                |  33 +++++
 source3/include/printing.h                  |   1 +
 source3/libads/kerberos_keytab.c            |   3 +-
 source3/modules/vfs_btrfs.c                 |  22 ++-
 source3/passdb/pdb_tdb.c                    |   2 +-
 source3/printing/printing.c                 |  70 ++++++---
 source3/rpc_server/spoolss/srv_spoolss_nt.c | 212 ++++++++++++++++++----------
 7 files changed, 241 insertions(+), 102 deletions(-)


Changeset truncated at 500 lines:

diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index 64ed26d..1673911 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -9,6 +9,39 @@ system at https://bugzilla.samba.org/.
 Samba 4.2 will be the next version of the Samba suite.
 
 
+IMPORTANT NOTE ABOUT THE SUPPORT END OF SAMBA 3
+=================================================
+
+With the final release of Samba 4.2, the last series of Samba 3 has
+been discontinued! People still running 3.6.x or earlier,should
+consider moving to a more recent and maintained version (4.0 - 4.2).
+One of the common misconceptions is that Samba 4.x automatically
+means "Active Directory only": This is wrong!
+
+Acting as an Active Directory Domain Controller is just one of the
+enhancements included in Samba 4.0 and later. Version 4.0 was just the
+next release after the 3.6 series and contains all the features of the
+previous ones - including the NT4-style (classic) domain support. This
+means you can update a Samba 3.x NT4-style PDC to 4.x, just as you've
+updated in the past (e.g. from 3.4.x to 3.5.x). You don't have to move
+your NT4-style domain to an Active Directory!
+
+And of course the possibility remains unchanged, to setup a new NT4-style
+PDC with Samba 4.x, like done in the past (e.g. with openLDAP backend).
+Active Directory support in Samba 4 is additional and does not replace
+any of these features. We do understand the difficulty presented by
+existing LDAP structures and for that reason there isn't a plan to
+decommission the classic PDC support. It remains tested by the continuous
+integration system.
+
+The code that supports the classic Domain Controller is also the same
+code that supports the internal 'Domain' of standalone servers and
+Domain Member Servers. This means that we still use this code, even
+when not acting as an AD Domain Controller. It is also the basis for
+some of the features of FreeIPA and so it gets development attention
+from that direction as well.
+
+
 UPGRADING
 =========
 
diff --git a/source3/include/printing.h b/source3/include/printing.h
index ec5a53b..563659a 100644
--- a/source3/include/printing.h
+++ b/source3/include/printing.h
@@ -195,6 +195,7 @@ uint16_t print_spool_rap_jobid(struct print_file_data *print_file);
 
 uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob);
 uint32 sysjob_to_jobid(int unix_jobid);
+int jobid_to_sysjob_pdb(struct tdb_print_db *pdb, uint32_t jobid);
 bool print_notify_register_pid(int snum);
 bool print_notify_deregister_pid(int snum);
 bool print_job_exists(const char* sharename, uint32 jobid);
diff --git a/source3/libads/kerberos_keytab.c b/source3/libads/kerberos_keytab.c
index 43c755c..ae3d80e39 100644
--- a/source3/libads/kerberos_keytab.c
+++ b/source3/libads/kerberos_keytab.c
@@ -667,14 +667,13 @@ int ads_keytab_create_default(ADS_STRUCT *ads)
 		goto done;
 	}
 
-	oldEntries = talloc_array(frame, char *, found);
+	oldEntries = talloc_zero_array(frame, char *, found + 1);
 	if (!oldEntries) {
 		DEBUG(1, (__location__ ": Failed to allocate space to store "
 			  "the old keytab entries (talloc failed?).\n"));
 		ret = -1;
 		goto done;
 	}
-	memset(oldEntries, '\0', found * sizeof(char *));
 
 	ret = krb5_kt_start_seq_get(context, keytab, &cursor);
 	if (ret == KRB5_KT_END || ret == ENOENT) {
diff --git a/source3/modules/vfs_btrfs.c b/source3/modules/vfs_btrfs.c
index c1e17b3..5144239 100644
--- a/source3/modules/vfs_btrfs.c
+++ b/source3/modules/vfs_btrfs.c
@@ -245,23 +245,29 @@ static NTSTATUS btrfs_get_compression(struct vfs_handle_struct *handle,
 	int fd;
 	bool opened = false;
 	NTSTATUS status;
+	DIR *dir = NULL;
 
 	if ((fsp != NULL) && (fsp->fh->fd != -1)) {
 		fd = fsp->fh->fd;
 	} else if (smb_fname != NULL) {
 		if (S_ISDIR(smb_fname->st.st_ex_mode)) {
-			DIR *dir = opendir(smb_fname->base_name);
+			dir = opendir(smb_fname->base_name);
 			if (dir == NULL) {
 				return NT_STATUS_UNSUCCESSFUL;
 			}
+			opened = true;
 			fd = dirfd(dir);
+			if (fd < 0) {
+				status = NT_STATUS_UNSUCCESSFUL;
+				goto err_close;
+			}
 		} else {
 			fd = open(smb_fname->base_name, O_RDONLY);
+			if (fd < 0) {
+				return NT_STATUS_UNSUCCESSFUL;
+			}
+			opened = true;
 		}
-		if (fd < 0) {
-			return NT_STATUS_UNSUCCESSFUL;
-		}
-		opened = true;
 	} else {
 		return NT_STATUS_INVALID_PARAMETER;
 	}
@@ -281,7 +287,11 @@ static NTSTATUS btrfs_get_compression(struct vfs_handle_struct *handle,
 	status = NT_STATUS_OK;
 err_close:
 	if (opened) {
-		close(fd);
+		if (dir != NULL) {
+			closedir(dir);
+		} else {
+			close(fd);
+		}
 	}
 
 	return status;
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index 9dd4451..94d9d52 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -600,7 +600,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods,
 
 	if (!init_samu_from_buffer(user, SAMU_BUFFER_LATEST, data.dptr, data.dsize)) {
 		DEBUG(0,("pdb_getsampwent: Bad struct samu entry returned from TDB!\n"));
-		SAFE_FREE(data.dptr);
+		TALLOC_FREE(data.dptr);
 		return NT_STATUS_NO_MEMORY;
 	}
 
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index dcfd2a2..a02e353 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -490,19 +490,18 @@ err_out:
 	return pjob;
 }
 
-/* Convert a unix jobid to a smb jobid */
-
-struct unixjob_traverse_state {
+struct job_traverse_state {
 	int sysjob;
-	uint32 sysjob_to_jobid_value;
+	uint32_t jobid;
 };
 
-static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
-			       TDB_DATA data, void *private_data)
+/* find spoolss jobid based on sysjob */
+static int sysjob_to_jobid_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
+				       TDB_DATA data, void *private_data)
 {
 	struct printjob *pjob;
-	struct unixjob_traverse_state *state =
-		(struct unixjob_traverse_state *)private_data;
+	struct job_traverse_state *state =
+		(struct job_traverse_state *)private_data;
 
 	if (!data.dptr || data.dsize == 0)
 		return 0;
@@ -512,7 +511,7 @@ static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
 		return 0;
 
 	if (state->sysjob == pjob->sysjob) {
-		state->sysjob_to_jobid_value = pjob->jobid;
+		state->jobid = pjob->jobid;
 		return 1;
 	}
 
@@ -521,14 +520,14 @@ static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
 
 uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
 {
-	struct unixjob_traverse_state state;
+	struct job_traverse_state state;
 
 	state.sysjob = sysjob;
-	state.sysjob_to_jobid_value = (uint32)-1;
+	state.jobid = (uint32_t)-1;
 
-	tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
+	tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state);
 
-	return state.sysjob_to_jobid_value;
+	return state.jobid;
 }
 
 /****************************************************************************
@@ -540,10 +539,10 @@ uint32 sysjob_to_jobid(int unix_jobid)
 {
 	int services = lp_numservices();
 	int snum;
-	struct unixjob_traverse_state state;
+	struct job_traverse_state state;
 
 	state.sysjob = unix_jobid;
-	state.sysjob_to_jobid_value = (uint32)-1;
+	state.jobid = (uint32_t)-1;
 
 	for (snum = 0; snum < services; snum++) {
 		struct tdb_print_db *pdb;
@@ -553,14 +552,49 @@ uint32 sysjob_to_jobid(int unix_jobid)
 		if (!pdb) {
 			continue;
 		}
-		tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
+		tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state);
 		release_print_db(pdb);
-		if (state.sysjob_to_jobid_value != (uint32)-1)
-			return state.sysjob_to_jobid_value;
+		if (state.jobid != (uint32_t)-1)
+			return state.jobid;
 	}
 	return (uint32)-1;
 }
 
+/* find sysjob based on spoolss jobid */
+static int jobid_to_sysjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
+				       TDB_DATA data, void *private_data)
+{
+	struct printjob *pjob;
+	struct job_traverse_state *state =
+		(struct job_traverse_state *)private_data;
+
+	if (!data.dptr || data.dsize == 0)
+		return 0;
+
+	pjob = (struct printjob *)data.dptr;
+	if (key.dsize != sizeof(uint32_t))
+		return 0;
+
+	if (state->jobid == pjob->jobid) {
+		state->sysjob = pjob->sysjob;
+		return 1;
+	}
+
+	return 0;
+}
+
+int jobid_to_sysjob_pdb(struct tdb_print_db *pdb, uint32_t jobid)
+{
+	struct job_traverse_state state;
+
+	state.sysjob = -1;
+	state.jobid = jobid;
+
+	tdb_traverse(pdb->tdb, jobid_to_sysjob_traverse_fn, &state);
+
+	return state.sysjob;
+}
+
 /****************************************************************************
  Send notifications based on what has changed after a pjob_store.
 ****************************************************************************/
diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c
index 552d4cb..f6fbfda 100644
--- a/source3/rpc_server/spoolss/srv_spoolss_nt.c
+++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c
@@ -7057,6 +7057,7 @@ fill_job_info1
 static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
 			     struct spoolss_JobInfo1 *r,
 			     const print_queue_struct *queue,
+			     uint32_t jobid,
 			     int position, int snum,
 			     struct spoolss_PrinterInfo2 *pinfo2)
 {
@@ -7064,7 +7065,7 @@ static WERROR fill_job_info1(TALLOC_CTX *mem_ctx,
 
 	t = gmtime(&queue->time);
 
-	r->job_id		= queue->sysjob;
+	r->job_id		= jobid;
 
 	r->printer_name		= lp_servicename(mem_ctx, snum);
 	W_ERROR_HAVE_NO_MEMORY(r->printer_name);
@@ -7097,6 +7098,7 @@ fill_job_info2
 static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
 			     struct spoolss_JobInfo2 *r,
 			     const print_queue_struct *queue,
+			     uint32_t jobid,
 			     int position, int snum,
 			     struct spoolss_PrinterInfo2 *pinfo2,
 			     struct spoolss_DeviceMode *devmode)
@@ -7105,7 +7107,7 @@ static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
 
 	t = gmtime(&queue->time);
 
-	r->job_id		= queue->sysjob;
+	r->job_id		= jobid;
 
 	r->printer_name		= lp_servicename(mem_ctx, snum);
 	W_ERROR_HAVE_NO_MEMORY(r->printer_name);
@@ -7148,27 +7150,6 @@ static WERROR fill_job_info2(TALLOC_CTX *mem_ctx,
 }
 
 /****************************************************************************
-fill_job_info3
-****************************************************************************/
-
-static WERROR fill_job_info3(TALLOC_CTX *mem_ctx,
-			     struct spoolss_JobInfo3 *r,
-			     const print_queue_struct *queue,
-			     const print_queue_struct *next_queue,
-			     int position, int snum,
-			     struct spoolss_PrinterInfo2 *pinfo2)
-{
-	r->job_id		= queue->sysjob;
-	r->next_job_id		= 0;
-	if (next_queue) {
-		r->next_job_id	= next_queue->sysjob;
-	}
-	r->reserved		= 0;
-
-	return WERR_OK;
-}
-
-/****************************************************************************
  Enumjobs at level 1.
 ****************************************************************************/
 
@@ -7182,34 +7163,56 @@ static WERROR enumjobs_level1(TALLOC_CTX *mem_ctx,
 	union spoolss_JobInfo *info;
 	int i;
 	WERROR result = WERR_OK;
+	uint32_t num_filled;
+	struct tdb_print_db *pdb;
 
 	info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
-	W_ERROR_HAVE_NO_MEMORY(info);
+	if (info == NULL) {
+		result = WERR_NOMEM;
+		goto err_out;
+	}
 
-	*count = num_queues;
+	pdb = get_print_db_byname(pinfo2->sharename);
+	if (pdb == NULL) {
+		result = WERR_INVALID_PARAM;
+		goto err_info_free;
+	}
+
+	num_filled = 0;
+	for (i = 0; i < num_queues; i++) {
+		uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
+		if (jobid == (uint32_t)-1) {
+			DEBUG(4, ("skipping sysjob %d\n", queue[i].sysjob));
+			continue;
+		}
 
-	for (i=0; i<*count; i++) {
 		result = fill_job_info1(info,
-					&info[i].info1,
+					&info[num_filled].info1,
 					&queue[i],
+					jobid,
 					i,
 					snum,
 					pinfo2);
 		if (!W_ERROR_IS_OK(result)) {
-			goto out;
+			goto err_pdb_drop;
 		}
-	}
 
- out:
-	if (!W_ERROR_IS_OK(result)) {
-		TALLOC_FREE(info);
-		*count = 0;
-		return result;
+		num_filled++;
 	}
 
+	release_print_db(pdb);
 	*info_p = info;
+	*count = num_filled;
 
 	return WERR_OK;
+
+err_pdb_drop:
+	release_print_db(pdb);
+err_info_free:
+	TALLOC_FREE(info);
+err_out:
+	*count = 0;
+	return result;
 }
 
 /****************************************************************************
@@ -7226,45 +7229,65 @@ static WERROR enumjobs_level2(TALLOC_CTX *mem_ctx,
 	union spoolss_JobInfo *info;
 	int i;
 	WERROR result = WERR_OK;
+	uint32_t num_filled;
+	struct tdb_print_db *pdb;
 
 	info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
-	W_ERROR_HAVE_NO_MEMORY(info);
+	if (info == NULL) {
+		result = WERR_NOMEM;
+		goto err_out;
+	}
 
-	*count = num_queues;
+	pdb = get_print_db_byname(pinfo2->sharename);
+	if (pdb == NULL) {
+		result = WERR_INVALID_PARAM;
+		goto err_info_free;
+	}
 
-	for (i=0; i<*count; i++) {
+	num_filled = 0;
+	for (i = 0; i< num_queues; i++) {
 		struct spoolss_DeviceMode *devmode;
+		uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
+		if (jobid == (uint32_t)-1) {
+			DEBUG(4, ("skipping sysjob %d\n", queue[i].sysjob));
+			continue;
+		}
 
 		result = spoolss_create_default_devmode(info,
 							pinfo2->printername,
 							&devmode);
 		if (!W_ERROR_IS_OK(result)) {
 			DEBUG(3, ("Can't proceed w/o a devmode!"));
-			goto out;
+			goto err_pdb_drop;
 		}
 
 		result = fill_job_info2(info,
-					&info[i].info2,
+					&info[num_filled].info2,
 					&queue[i],
+					jobid,
 					i,
 					snum,
 					pinfo2,
 					devmode);
 		if (!W_ERROR_IS_OK(result)) {
-			goto out;
+			goto err_pdb_drop;
 		}
+		num_filled++;
 	}
 
- out:
-	if (!W_ERROR_IS_OK(result)) {
-		TALLOC_FREE(info);
-		*count = 0;
-		return result;
-	}
-
+	release_print_db(pdb);
 	*info_p = info;
+	*count = num_filled;
 
 	return WERR_OK;
+
+err_pdb_drop:
+	release_print_db(pdb);
+err_info_free:
+	TALLOC_FREE(info);
+err_out:
+	*count = 0;
+	return result;
 }
 
 /****************************************************************************
@@ -7281,41 +7304,51 @@ static WERROR enumjobs_level3(TALLOC_CTX *mem_ctx,
 	union spoolss_JobInfo *info;
 	int i;
 	WERROR result = WERR_OK;
+	uint32_t num_filled;
+	struct tdb_print_db *pdb;
 
 	info = talloc_array(mem_ctx, union spoolss_JobInfo, num_queues);
-	W_ERROR_HAVE_NO_MEMORY(info);
-
-	*count = num_queues;
+	if (info == NULL) {
+		result = WERR_NOMEM;
+		goto err_out;
+	}
 
-	for (i=0; i<*count; i++) {
-		const print_queue_struct *next_queue = NULL;
+	pdb = get_print_db_byname(pinfo2->sharename);
+	if (pdb == NULL) {
+		result = WERR_INVALID_PARAM;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list