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

Karolin Seeger kseeger at samba.org
Mon Aug 13 13:54:02 UTC 2018


The branch, v4-9-test has been updated
       via  7751937 s3/smbd: Ensure quota code is only called when quota support detected
       via  31e07eb Shorten description in vfs_linux_xfs_sgid manual
       via  1a0d142 s3:waf: Install eventlogadm to /usr/sbin
       via  b1558f1 systemd: Only start smb when network interfaces are up
       via  39dc0db ctdb-eventd: Fix CID 1438155
       via  ec22496 ctdb: Fix a cut&paste error
       via  b0c0a19 s3/utils: fix regression where specifying -Unetbios/root works
       via  134f17c s3/smbd: allow set quota for non root user (when built with --enable-selftest)
       via  951722d s3/script/tests: Add simple (smb1 & smb2) get/set/list tests for smbcquotas
       via  a9d0df4 s3/script/test: modify existing smbcquota test to use SMB2 in addition to SMB1.
       via  b65c3de s3/smbd: smb2 server implementation for query get/set info.
       via  046d3a3 s3/smbd: adjust smb1 server to use idl structs and generated ndr push/pull funcs
       via  bdfcecc s3/libsmb: adjust smb2 code for new idl structs & generated ndr push/pull funcs.
       via  0ccd34a s3/libsmb: adjust smb1 cli code to use idl structs and ndr push/pull funcs.
       via  59bb7dd librpc/idl Add some query [getset]info quota related structures
       via  6c24eae s3/smbd: Don't stat when doing a quota operation (as it's a fake file)
       via  1d7b1dc s3/libsmb: Avoid potential smbpanic calling parse_user_quota_list.
       via  8b98831 s3/lib: Fix misleading typo in debug message
       via  6b5e4a7 s3-tldap: do not install test_tldap
      from  7894067 VERSION: Bump version up to 4.9.0rc3...

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


- Log -----------------------------------------------------------------
commit 77519371fe98404c081a58354ef0664f6be59ca2
Author: Noel Power <noel.power at suse.com>
Date:   Tue Aug 7 11:06:34 2018 +0100

    s3/smbd: Ensure quota code is only called when quota support detected
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13563
    Signed-off-by: Noel Power <noel.power at suse.com>
    
    Autobuild-User(v4-9-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-9-test): Mon Aug 13 15:53:27 CEST 2018 on sn-devel-144

commit 31e07ebfb688ac62f71f5023be8d14ca93d4191b
Author: Justin Stephenson <jstephen at redhat.com>
Date:   Mon Aug 6 11:24:18 2018 -0400

    Shorten description in vfs_linux_xfs_sgid manual
    
    this fixes a lexgrog parse error, the NAME subheader description
    of the vfs_linux_xfs_sgid(8) manual was too long, this will shorten
    the description and allow it to be correctly detected by mandb.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13562
    
    Signed-off-by: Justin Stephenson <jstephen at redhat.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    (cherry picked from commit 9b105651c754c7c98297a23c0c1e43d7d2e28139)

commit 1a0d1421a3ced92decbe6be6397316ebfe96131b
Author: Andreas Schneider <asn at samba.org>
Date:   Mon Aug 6 17:32:17 2018 +0200

    s3:waf: Install eventlogadm to /usr/sbin
    
    The eventlogadm binary needs write access to the registry which, by
    default, is only possible as root.
    
    https://bugzilla.samba.org/show_bug.cgi?id=13561
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    (cherry picked from commit 0530cccc41f683cb35d065ddcb3968cf4ef759f4)

commit b1558f175600c041d4bff7f07df941f42c97e549
Author: Oleksandr Natalenko <oleksandr at redhat.com>
Date:   Fri Aug 3 14:34:47 2018 +0200

    systemd: Only start smb when network interfaces are up
    
    For smb, if the smb.conf contains explicit bindings to the network
    interfaces, the service must wait till network interfaces are up,
    otherwise the service won't be operational.
    
    The 0e571054a61e commit and the BZ 13184 have fixed this for nmb and
    samba, so do exactly the same here, for smb.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13559
    
    Signed-off-by: Oleksandr Natalenko <oleksandr at redhat.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>
    
    (cherry picked from commit a3d248f284eb2e5f4fe886310e481b28c9f1c392)

commit 39dc0db85f5e8ae4466c828eba9650e3610bf422
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Tue Jul 31 17:44:25 2018 +1000

    ctdb-eventd: Fix CID 1438155
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13554
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    
    Autobuild-User(master): Amitay Isaacs <amitay at samba.org>
    Autobuild-Date(master): Fri Aug  3 11:14:01 CEST 2018 on sn-devel-144
    
    (cherry picked from commit f7b2e5eec5ba1fa5f26694e6555a98cab0594a27)

commit ec2249635a356437594321f3f95aa1deedb5ff53
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Jul 31 21:53:39 2018 +0200

    ctdb: Fix a cut&paste error
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13554
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    (cherry picked from commit 33d012c3cebb5625e02450ac3b08c4245a3e985d)

commit b0c0a19da81dbf5b963f9524aa015547adb15bb9
Author: Noel Power <noel.power at suse.com>
Date:   Thu Jun 28 16:04:24 2018 +0100

    s3/utils: fix regression where specifying -Unetbios/root works
    
    Usually you need to be root on a linux server to modify quotas. Even
    with a linux server joined to a windows AD you could always log in as
    local root with smbcquotas. However in recent builds this has changed.
    This patch fixes this
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Noel Power <npower at samba.org>
    Autobuild-Date(master): Tue Jul 31 19:45:59 CEST 2018 on sn-devel-144

commit 134f17cee10c6db09e637e775945c8a7d230121c
Author: Noel Power <noel.power at suse.com>
Date:   Wed Mar 22 20:06:13 2017 +0000

    s3/smbd: allow set quota for non root user (when built with --enable-selftest)
    
    Currently it appears you need to be root to set quotas, for test purposes
    this requirement needs to be relaxed.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 951722d6eeac55dfa01056ce96be0c4ba3f1fbfa
Author: Noel Power <noel.power at suse.com>
Date:   Tue Mar 21 08:29:59 2017 +0000

    s3/script/tests: Add simple (smb1 & smb2) get/set/list tests for smbcquotas
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a9d0df49faa13fb6bfffb0295776bb3e5e3f04e1
Author: Noel Power <noel.power at suse.com>
Date:   Wed Mar 8 14:27:27 2017 +0000

    s3/script/test: modify existing smbcquota test to use SMB2 in addition to SMB1.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b65c3de5942a026afc953f7e82ec688977f44527
Author: Noel Power <noel.power at suse.com>
Date:   Fri May 26 16:02:33 2017 +0100

    s3/smbd: smb2 server implementation for query get/set info.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 046d3a3d05ba2e2737b56f54f953c31d93d22eab
Author: Noel Power <noel.power at suse.com>
Date:   Fri May 26 16:01:53 2017 +0100

    s3/smbd: adjust smb1 server to use idl structs and generated ndr push/pull funcs
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit bdfcecc3c507b0129a9e73ca3dfbb1c09b8c9bc9
Author: Noel Power <noel.power at suse.com>
Date:   Fri May 26 15:50:18 2017 +0100

    s3/libsmb: adjust smb2 code for new idl structs & generated ndr push/pull funcs.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0ccd34a5b4f5783e319490b57ca37df038933732
Author: Noel Power <noel.power at suse.com>
Date:   Fri May 26 15:01:17 2017 +0100

    s3/libsmb: adjust smb1 cli code to use idl structs and ndr push/pull funcs.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 59bb7dde27040d12ac33c4693cb3acabf4132005
Author: Noel Power <noel.power at suse.com>
Date:   Thu Mar 2 09:20:24 2017 +0000

    librpc/idl Add some query [getset]info quota related structures
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6c24eaeab1f3864efa57b44177241101e7d82974
Author: Noel Power <noel.power at suse.com>
Date:   Tue Feb 28 11:36:47 2017 +0000

    s3/smbd: Don't stat when doing a quota operation (as it's a fake file)
    
    calling SMB_VFS_STAT on the quota fake file fails and caused
    FS_INFO/FileFsControlInfo request to error out early, in turn stopped a
    Win8.1 client from proceeding with quota queries.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 1d7b1dc0f5735f4d4192e80a0389eea1ba399bc0
Author: Noel Power <noel.power at suse.com>
Date:   Tue Feb 28 15:04:16 2017 +0000

    s3/libsmb: Avoid potential smbpanic calling parse_user_quota_list.
    
    Calling parse_user_quota_list with a NULL buffer can cause a panic, while
    this shouldn't happen, I managed to trigger this with an early implementation
    of SMB2 quota support in smbd which didn't pass back NT_STATUS_NO_MORE_ENTRIES
    when handling a SMB2_0_INFO_QUOTA GETINFO message.
    OTHOH the Windows client handled the same situation gracefully.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 8b98831d0fafc86b5308c204d672cc6ead85f0e0
Author: Noel Power <noel.power at suse.com>
Date:   Wed Mar 22 14:53:22 2017 +0000

    s3/lib: Fix misleading typo in debug message
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13553
    
    Signed-off-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6b5e4a71dfa763d61aab1f92dae215ac27fecaaf
Author: Günther Deschner <gd at samba.org>
Date:   Thu Jul 12 23:32:36 2018 +0200

    s3-tldap: do not install test_tldap
    
    Guenther
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13529
    
    Signed-off-by: Guenther Deschner <gd at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Sat Jul 14 03:09:00 CEST 2018 on sn-devel-144
    
    (cherry picked from commit 26fd7096b1f99a2754f634669d5432109023bfa5)

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

Summary of changes:
 ctdb/common/path.c                                 |   2 +-
 ctdb/event/event_tool.c                            |   2 +-
 docs-xml/manpages/vfs_linux_xfs_sgid.8.xml         |   2 +-
 librpc/idl/quota.idl                               |  54 ++
 librpc/idl/wscript_build                           |   1 +
 librpc/wscript_build                               |   5 +
 packaging/systemd/smb.service.in                   |   3 +-
 selftest/target/Samba3.pm                          |   9 +
 source3/lib/sysquotas.c                            |   2 +-
 source3/libsmb/cli_smb2_fnum.c                     |  94 ++-
 source3/libsmb/cliquota.c                          | 392 ++++++------
 source3/libsmb/proto.h                             |   6 +
 source3/script/tests/getset_quota.py               | 154 +++++
 source3/script/tests/test_dfree_quota.sh           |  14 +-
 source3/script/tests/test_smbcquota.py             | 244 ++++++++
 .../script/tests/test_smbcquota.sh                 |  42 +-
 source3/selftest/tests.py                          |   1 +
 source3/smbd/nttrans.c                             | 662 ++++++++++++---------
 source3/smbd/proto.h                               |  14 +
 source3/smbd/smb2_getinfo.c                        |  87 ++-
 source3/smbd/smb2_setinfo.c                        |  41 ++
 source3/smbd/trans2.c                              |   3 +-
 source3/utils/smbcquotas.c                         |   3 +-
 source3/utils/wscript_build                        |   3 +-
 source3/wscript_build                              |   5 +-
 25 files changed, 1330 insertions(+), 515 deletions(-)
 create mode 100644 librpc/idl/quota.idl
 create mode 100755 source3/script/tests/getset_quota.py
 create mode 100755 source3/script/tests/test_smbcquota.py
 copy python/samba/tests/policy.py => source3/script/tests/test_smbcquota.sh (52%)
 mode change 100644 => 100755


Changeset truncated at 500 lines:

diff --git a/ctdb/common/path.c b/ctdb/common/path.c
index 36706e4..1656646 100644
--- a/ctdb/common/path.c
+++ b/ctdb/common/path.c
@@ -149,7 +149,7 @@ const char *path_vardir(void)
 {
 	bool ok;
 
-	if (! ctdb_paths.rundir_set) {
+	if (! ctdb_paths.vardir_set) {
 		ok = path_construct(ctdb_paths.vardir, "var");
 		if (!ok) {
 			D_ERR("Failed to construct VARDIR\n");
diff --git a/ctdb/event/event_tool.c b/ctdb/event/event_tool.c
index 4768c67..f18deb8 100644
--- a/ctdb/event/event_tool.c
+++ b/ctdb/event/event_tool.c
@@ -320,7 +320,7 @@ static int event_command_script_list(TALLOC_CTX *mem_ctx,
 
 	subdir = talloc_asprintf(mem_ctx, "events/%s", argv[0]);
 	if (subdir == NULL) {
-		ret = ENOMEM;
+		return ENOMEM;
 	}
 
 	data_dir = path_datadir_append(mem_ctx, subdir);
diff --git a/docs-xml/manpages/vfs_linux_xfs_sgid.8.xml b/docs-xml/manpages/vfs_linux_xfs_sgid.8.xml
index 2bc67e5..7382033 100644
--- a/docs-xml/manpages/vfs_linux_xfs_sgid.8.xml
+++ b/docs-xml/manpages/vfs_linux_xfs_sgid.8.xml
@@ -13,7 +13,7 @@
 
 <refnamediv>
 	<refname>vfs_linux_xfs_sgid</refname>
-	<refpurpose>Workaround XFS sgid bit not inherited during mkdir with default acl on Linux older than 3.1</refpurpose>
+	<refpurpose>Workaround XFS sgid bit not inherited</refpurpose>
 </refnamediv>
 
 <refsynopsisdiv>
diff --git a/librpc/idl/quota.idl b/librpc/idl/quota.idl
new file mode 100644
index 0000000..7c4d00a
--- /dev/null
+++ b/librpc/idl/quota.idl
@@ -0,0 +1,54 @@
+#include "idl_types.h"
+
+import "security.idl";
+
+[
+	pointer_default(unique)
+]
+
+interface file_quota {
+
+	/* MS-FSCC 2.4.33.1 */
+	typedef [public] struct {
+		uint32 next_entry_offset;
+		uint32 sid_length;
+		dom_sid sid;
+	} file_get_quota_info;
+
+	/* MS-FSCC 2.4.33 */
+	typedef [public] struct {
+		uint32 next_entry_offset;
+		uint32 sid_length;
+		hyper change_time;
+		hyper quota_used;
+		hyper quota_threshold;
+		hyper quota_limit;
+		dom_sid sid;
+	} file_quota_information;
+}
+
+interface smb2_query_quoata
+{
+	/* MS-SMB2 2.2.37.1 */
+	typedef [public] struct {
+		uint8 return_single;
+		uint8 restart_scan;
+		uint16 reserved;
+		uint32 sid_list_length;
+		uint32 start_sid_length;
+		uint32 start_sid_offset;
+	} smb2_query_quota_info;
+}
+
+interface smb1_nt_transact_query_quota
+{
+	/* MS-SMB 2.2.7.5.1 */
+	typedef [public] struct {
+		uint16 fid;
+		uint8 return_single_entry;
+		uint8 restart_scan;
+		uint32 sid_list_length;
+		uint32 start_sid_length;
+		uint32 start_sid_offset;
+	} nttrans_query_quota_params;
+}
diff --git a/librpc/idl/wscript_build b/librpc/idl/wscript_build
index 75eba7d..f1588cd 100644
--- a/librpc/idl/wscript_build
+++ b/librpc/idl/wscript_build
@@ -38,6 +38,7 @@ bld.SAMBA_PIDL_LIST('PIDL',
                     fsrvp_state.idl
                     cab.idl
                     nfs4acl.idl
+                    quota.idl
                     ''',
                     options='--header --ndr-parser',
                     output_dir='../gen_ndr')
diff --git a/librpc/wscript_build b/librpc/wscript_build
index 36414fb..824c0f9 100644
--- a/librpc/wscript_build
+++ b/librpc/wscript_build
@@ -399,6 +399,11 @@ bld.SAMBA_SUBSYSTEM('NDR_SMB2_LEASE_STRUCT',
     public_headers='gen_ndr/smb2_lease_struct.h'
     )
 
+bld.SAMBA_SUBSYSTEM('NDR_QUOTA',
+    source='gen_ndr/ndr_quota.c',
+    public_deps='ndr',
+    )
+
 bld.SAMBA_SUBSYSTEM('NDR_SCHANNEL',
     source='ndr/ndr_schannel.c gen_ndr/ndr_schannel.c',
     public_deps='ndr ndr_nbt'
diff --git a/packaging/systemd/smb.service.in b/packaging/systemd/smb.service.in
index dcaf7ef..18912ef 100644
--- a/packaging/systemd/smb.service.in
+++ b/packaging/systemd/smb.service.in
@@ -1,7 +1,8 @@
 [Unit]
 Description=Samba SMB Daemon
 Documentation=man:smbd(8) man:samba(7) man:smb.conf(5)
-After=network.target nmb.service winbind.service
+Wants=network-online.target
+After=network.target network-online.target nmb.service winbind.service
 
 [Service]
 Type=notify
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index a553405..fee7e21 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -842,6 +842,9 @@ sub setup_fileserver
 	push(@dirs, "$dfree_share_dir/subdir2");
 	push(@dirs, "$dfree_share_dir/subdir3");
 
+	my $quotadir_dir="$share_dir/quota";
+	push(@dirs, $quotadir_dir);
+
 	my $valid_users_sharedir="$share_dir/valid_users";
 	push(@dirs,$valid_users_sharedir);
 
@@ -868,6 +871,8 @@ sub setup_fileserver
 	usershare allow guests = yes
 	usershare prefix allow list = $usershare_sharedir
 
+	get quota command = $prefix_abs/getset_quota.py
+	set quota command = $prefix_abs/getset_quota.py
 [lowercase]
 	path = $lower_case_share_dir
 	comment = smb username is [%U]
@@ -2127,6 +2132,10 @@ sub provision($$$$$$$$$)
 	vfs objects = acl_xattr fake_acls xattr_tdb fake_dfq
 	inherit owner = yes
 	include = $dfqconffile
+[quotadir]
+	path = $shrdir/quota
+	admin users = $unix_name
+
 [acl_xattr_ign_sysacl_posix]
 	copy = tmp
 	acl_xattr:ignore system acls = yes
diff --git a/source3/lib/sysquotas.c b/source3/lib/sysquotas.c
index eef87be..9b2d37b 100644
--- a/source3/lib/sysquotas.c
+++ b/source3/lib/sysquotas.c
@@ -418,7 +418,7 @@ static int command_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t
 			return -1;
 		}
 
-		DEBUG (3, ("get_quota: Running command %s\n", syscmd));
+		DBG_NOTICE("set_quota: Running command %s\n", syscmd);
 
 		lines = file_lines_pload(talloc_tos(), syscmd, NULL);
 		SAFE_FREE(syscmd);
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 1eb1bea..f0b0cac 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -41,6 +41,7 @@
 #include "lib/util_ea.h"
 #include "librpc/gen_ndr/ndr_ioctl.h"
 #include "ntioctl.h"
+#include "librpc/gen_ndr/ndr_quota.h"
 
 struct smb2_hnd {
 	uint64_t fid_persistent;
@@ -2909,12 +2910,16 @@ NTSTATUS cli_smb2_get_user_quota(struct cli_state *cli,
 {
 	NTSTATUS status;
 	DATA_BLOB inbuf = data_blob_null;
+	DATA_BLOB info_blob = data_blob_null;
 	DATA_BLOB outbuf = data_blob_null;
 	struct smb2_hnd *ph = NULL;
 	TALLOC_CTX *frame = talloc_stackframe();
 	unsigned sid_len;
 	unsigned int offset;
-	uint8_t *buf;
+	struct smb2_query_quota_info query = {0};
+	struct file_get_quota_info info = {0};
+	enum ndr_err_code err;
+	struct ndr_push *ndr_push = NULL;
 
 	if (smbXcli_conn_has_async_calls(cli->conn)) {
 		/*
@@ -2936,27 +2941,52 @@ NTSTATUS cli_smb2_get_user_quota(struct cli_state *cli,
 
 	sid_len = ndr_size_dom_sid(&pqt->sid, 0);
 
-	inbuf = data_blob_talloc_zero(frame, 24 + sid_len);
-	if (inbuf.data == NULL) {
+	query.return_single = 1;
+	if (sid_len < 0) {
+		status = NT_STATUS_INVALID_PARAMETER;
+		goto fail;
+	}
+
+	info.next_entry_offset = 0;
+	info.sid_length = sid_len;
+	info.sid = pqt->sid;
+
+	err = ndr_push_struct_blob(
+			&info_blob,
+			frame,
+			&info,
+			(ndr_push_flags_fn_t)ndr_push_file_get_quota_info);
+
+	if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
+		status = NT_STATUS_INTERNAL_ERROR;
+		goto fail;
+	}
+
+	query.sid_list_length = info_blob.length;
+	ndr_push = ndr_push_init_ctx(frame);
+	if (!ndr_push) {
 		status = NT_STATUS_NO_MEMORY;
 		goto fail;
 	}
 
-	buf = inbuf.data;
+	err = ndr_push_smb2_query_quota_info(ndr_push,
+					     NDR_SCALARS | NDR_BUFFERS,
+					     &query);
 
-	SCVAL(buf, 0, 1);	   /* ReturnSingle */
-	SCVAL(buf, 1, 0);	   /* RestartScan */
-	SSVAL(buf, 2, 0);	   /* Reserved */
-	if (8 + sid_len < 8) {
-		status = NT_STATUS_INVALID_PARAMETER;
+	if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
+		status = NT_STATUS_INTERNAL_ERROR;
+		goto fail;
+	}
+
+	err = ndr_push_array_uint8(ndr_push, NDR_SCALARS, info_blob.data,
+				   info_blob.length);
+
+	if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
+		status = NT_STATUS_INTERNAL_ERROR;
 		goto fail;
 	}
-	SIVAL(buf, 4, 8 + sid_len); /* SidListLength */
-	SIVAL(buf, 8, 0);	   /* StartSidLength */
-	SIVAL(buf, 12, 0);	  /* StartSidOffset */
-	SIVAL(buf, 16, 0);	  /* NextEntryOffset */
-	SIVAL(buf, 20, sid_len);    /* SidLength */
-	sid_linearize(buf + 24, sid_len, &pqt->sid);
+	inbuf.data = ndr_push->data;
+	inbuf.length = ndr_push->offset;
 
 	status = smb2cli_query_info(cli->conn, cli->timeout, cli->smb2.session,
 				    cli->smb2.tcon, 4, /* in_info_type */
@@ -3001,7 +3031,8 @@ NTSTATUS cli_smb2_list_user_quota_step(struct cli_state *cli,
 	DATA_BLOB outbuf = data_blob_null;
 	struct smb2_hnd *ph = NULL;
 	TALLOC_CTX *frame = talloc_stackframe();
-	uint8_t *buf;
+	struct smb2_query_quota_info info = {0};
+	enum ndr_err_code err;
 
 	if (smbXcli_conn_has_async_calls(cli->conn)) {
 		/*
@@ -3021,20 +3052,19 @@ NTSTATUS cli_smb2_list_user_quota_step(struct cli_state *cli,
 		goto cleanup;
 	}
 
-	inbuf = data_blob_talloc_zero(frame, 16);
-	if (inbuf.data == NULL) {
-		status = NT_STATUS_NO_MEMORY;
-		goto cleanup;
-	}
 
-	buf = inbuf.data;
+	info.restart_scan = first ? 1 : 0;
 
-	SCVAL(buf, 0, 0);	     /* ReturnSingle */
-	SCVAL(buf, 1, first ? 1 : 0); /* RestartScan */
-	SSVAL(buf, 2, 0);	     /* Reserved */
-	SIVAL(buf, 4, 0);	     /* SidListLength */
-	SIVAL(buf, 8, 0);	     /* StartSidLength */
-	SIVAL(buf, 12, 0);	    /* StartSidOffset */
+	err = ndr_push_struct_blob(
+			&inbuf,
+			frame,
+			&info,
+			(ndr_push_flags_fn_t)ndr_push_smb2_query_quota_info);
+
+	if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
+		status = NT_STATUS_INTERNAL_ERROR;
+		goto cleanup;
+	}
 
 	status = smb2cli_query_info(cli->conn, cli->timeout, cli->smb2.session,
 				    cli->smb2.tcon, 4, /* in_info_type */
@@ -3046,6 +3076,14 @@ NTSTATUS cli_smb2_list_user_quota_step(struct cli_state *cli,
 				    ph->fid_persistent, ph->fid_volatile, frame,
 				    &outbuf);
 
+	/*
+	 * safeguard against panic from calling parse_user_quota_list with
+	 * NULL buffer
+	 */
+	if (NT_STATUS_IS_OK(status) && outbuf.length == 0) {
+		status = NT_STATUS_NO_MORE_ENTRIES;
+	}
+
 	if (!NT_STATUS_IS_OK(status)) {
 		goto cleanup;
 	}
diff --git a/source3/libsmb/cliquota.c b/source3/libsmb/cliquota.c
index e22ccdd..8efd2bb 100644
--- a/source3/libsmb/cliquota.c
+++ b/source3/libsmb/cliquota.c
@@ -24,6 +24,7 @@
 #include "../libcli/security/security.h"
 #include "trans2.h"
 #include "../libcli/smb/smbXcli_base.h"
+#include "librpc/gen_ndr/ndr_quota.h"
 
 NTSTATUS cli_get_quota_handle(struct cli_state *cli, uint16_t *quota_fnum)
 {
@@ -75,61 +76,39 @@ bool parse_user_quota_record(const uint8_t *rdata,
 			     unsigned int *offset,
 			     SMB_NTQUOTA_STRUCT *pqt)
 {
-	int sid_len;
-	SMB_NTQUOTA_STRUCT qt;
-
-	ZERO_STRUCT(qt);
-
-	if (!rdata||!offset||!pqt) {
-		smb_panic("parse_quota_record: called with NULL POINTER!");
-	}
-
-	if (rdata_count < 40) {
-		return False;
-	}
+	struct file_quota_information info = {0};
+	TALLOC_CTX *frame = talloc_stackframe();
+	DATA_BLOB blob;
+	enum ndr_err_code err;
+	bool result = false;
 
-	/* offset to next quota record.
-	 * 4 bytes IVAL(rdata,0)
-	 * unused here...
-	 */
-	*offset = IVAL(rdata,0);
-
-	/* sid len */
-	sid_len = IVAL(rdata,4);
-	if (40 + sid_len < 40) {
-		return false;
-	}
-
-	if (rdata_count < 40+sid_len) {
-		return False;		
-	}
+	blob.data = discard_const_p(uint8_t, rdata);
+	blob.length = rdata_count;
+	err = ndr_pull_struct_blob(
+			&blob,
+			frame,
+			&info,
+			(ndr_pull_flags_fn_t)ndr_pull_file_quota_information);
 
-	if (*offset != 0 && *offset < 40 + sid_len) {
-		return false;
+	if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
+		goto out;
 	}
 
-	/* unknown 8 bytes in pdata 
-	 * maybe its the change time in NTTIME
-	 */
+	*offset = info.next_entry_offset;
 
-	/* the used space 8 bytes (uint64_t)*/
-	qt.usedspace = BVAL(rdata,16);
+	ZERO_STRUCTP(pqt);
+	pqt->usedspace = info.quota_used;
 
-	/* the soft quotas 8 bytes (uint64_t)*/
-	qt.softlim = BVAL(rdata,24);
+	pqt->softlim = info.quota_threshold;
 
-	/* the hard quotas 8 bytes (uint64_t)*/
-	qt.hardlim = BVAL(rdata,32);
-
-	if (!sid_parse(rdata+40,sid_len,&qt.sid)) {
-		return false;
-	}
+	pqt->hardlim = info.quota_limit;
 
-	qt.qtype = SMB_USER_QUOTA_TYPE;
-
-	*pqt = qt;
-
-	return True;
+	pqt->qtype = SMB_USER_QUOTA_TYPE;
+	pqt->sid = info.sid;
+	result = true;
+out:
+	TALLOC_FREE(frame);
+	return result;
 }
 
 NTSTATUS parse_user_quota_list(const uint8_t *curdata,
@@ -217,111 +196,12 @@ NTSTATUS build_user_quota_buffer(SMB_NTQUOTA_LIST *qt_list,
 				 DATA_BLOB *outbuf,
 				 SMB_NTQUOTA_LIST **end_ptr)
 {
-	uint32_t qt_len = 0;
-	uint8_t *entry;
-	uint32_t entry_len;
-	int sid_len;
-	SMB_NTQUOTA_LIST *qtl;
-	DATA_BLOB qbuf = data_blob_null;
-	NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
-
-	if (qt_list == NULL) {
-		status = NT_STATUS_OK;
-		*outbuf = data_blob_null;
-		if (end_ptr) {
-			*end_ptr = NULL;
-		}
-		return NT_STATUS_OK;
-	}
-
-	for (qtl = qt_list; qtl != NULL; qtl = qtl->next) {
-
-		sid_len = ndr_size_dom_sid(&qtl->quotas->sid, 0);
-		if (47 + sid_len < 47) {
-			status = NT_STATUS_INVALID_PARAMETER;
-			goto fail;
-		}
-		entry_len = 40 + sid_len;
-		entry_len = ((entry_len + 7) / 8) * 8;
-
-		if (qt_len + entry_len < qt_len) {
-			status = NT_STATUS_INVALID_PARAMETER;
-			goto fail;
-		}
-		qt_len += entry_len;
-	}
-
-	if (maxlen > 0 && qt_len > maxlen) {
-		qt_len = maxlen;
-	}
-
-	qbuf = data_blob_talloc_zero(mem_ctx, qt_len);
-	if (qbuf.data == NULL) {
-		status = NT_STATUS_NO_MEMORY;
-		goto fail;
-	}
-
-	for (qt_len = 0, entry = qbuf.data; qt_list != NULL;
-	     qt_list = qt_list->next, qt_len += entry_len, entry += entry_len) {
-
-		sid_len = ndr_size_dom_sid(&qt_list->quotas->sid, 0);
-		entry_len = 40 + sid_len;
-		entry_len = ((entry_len + 7) / 8) * 8;
-
-		if (qt_len + entry_len > qbuf.length) {
-			/* check for not-enough room even for a single
-			 * entry
-			 */


-- 
Samba Shared Repository



More information about the samba-cvs mailing list