1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00
Commit Graph

4913 Commits

Author SHA1 Message Date
Volker Lendecke
e4aa9a970a libsmb: Pass "struct timespec" to SMBC_setatr()
Prepare to set higher-precision timestamps. No change in behaviour so
far: The {.tv_nsec=SAMBA_UTIME_OMIT} implicitly sets .tv_sec=0, and
SMBC_setatr() only looks at .tv_sec

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2020-04-08 14:46:40 +00:00
Volker Lendecke
aa1f34219d libsmb: Make cli_setpathinfo_ext() take structs instead of pointers
This simplifies the next commit: With direct (small) structs on the
stack we don't need declared variables in the callers

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2020-04-08 14:46:39 +00:00
Volker Lendecke
6cb1f20f73 libsmb: Use cli_setfileinfo_send() in cli_ftruncate_send()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2020-04-08 14:46:39 +00:00
Volker Lendecke
b46b5a6408 libsmb: Use cli_setfilefinfo_send() in cli_nt_delete_on_close_send()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2020-04-08 14:46:39 +00:00
Volker Lendecke
bf61a0d7f3 libsmb: Add cli_setfileinfo_send/recv()
Encapsulate TRANSACT2_SETFILEINFO like cli_setpathinfo_send() does for
TRANSACT2_SETPATHINFO.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2020-04-08 14:46:39 +00:00
Volker Lendecke
fbf55d124d libsmb: Remove a typedef
No API change, this is not used publically

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2020-04-08 14:46:39 +00:00
Volker Lendecke
eadbaabca1 libsmb: Use ARRAY_DEL_ELEMENT() in remove_duplicate_addrs2()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2020-03-26 14:43:31 +00:00
Volker Lendecke
487ca0754d libsmb: Use ARRAY_DEL_ELEMENT() in sort_acl()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2020-03-26 14:43:31 +00:00
Andrew Bartlett
5c1867ba45 py3: Remove #define PyInt_FromLong PyLong_FromLong
This allows us to end the use of Python 2/3 compatability macros.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Noel Power
2020-03-23 19:12:43 +00:00
Volker Lendecke
39c910fd9c libsmb: Don't try to find posix stat info in SMBC_getatr()
This wrongly used "frame" instead of "fname", which can never have
worked. A first attempt to fix in 51551e0d53 caused a few followup
patches in an attempt to clean up the test failures 51551e0d53
introduced. They were reverted after a few discussions. So rather than
changing behaviour, just remove the code that introduced the valgrind
error again.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Fri Mar 20 05:06:07 UTC 2020 on sn-devel-184
2020-03-20 05:06:07 +00:00
Volker Lendecke
9653a10738 libsmbclient: Put it back to a known, well-working state
For adapting unix extensions in our client libraries, we need a fresh start
with additional APIs. We can't change existing application behaviour.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-03-10 21:25:33 +00:00
Volker Lendecke
a1856f07b3 libsmb: Use posix open in SMBC_open_ctx
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-03-03 17:48:38 +00:00
Volker Lendecke
c2e012fe11 libsmb: Use posix result in SMBC_readdirplus2_ctx
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-03-03 17:48:37 +00:00
Volker Lendecke
890c94d585 libsmb: Implement SMB_FIND_FILE_UNIX_INFO2 dir listing
This keeps the original SMB_STRUCT_STAT coming from posix as part of
struct file_info. It is a slight waste of space, as the timestamps are
kept twice, but having a full SMB_STRUCT_STAT with the nlink!=0
validity check makes thinking about which mode/size/etc is the correct
one a no-brainer. We can save space later by referencing only one set
of time stamps for example.

This for the time fixes readdirplus2, but for the wrong reason: We don't yet
create files the "proper" way using posix create.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-03-03 17:48:37 +00:00
Volker Lendecke
128545ba4f libsmb: Introduce fetch_file_unix_basic_info2()
Will be used in clilist.c for SMB_FIND_FILE_UNIX_INFO2

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-03-03 17:48:37 +00:00
Volker Lendecke
9cc546956d libsmb: Factor out fetch_file_unix_basic_info()
Will be used in clilist.c for SMB_FIND_FILE_UNIX_INFO2

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-03-03 17:48:37 +00:00
Volker Lendecke
edfc19f1eb libsmb: Fix a typo
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-03-03 17:48:37 +00:00
Stefan Metzmacher
b1ebfec39e s3:libsmb: move cli_set_message() to source3/libsmb/nmblib.c
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-26 19:45:36 +00:00
Stefan Metzmacher
03562cf128 s3:libsmb: use only a timeout of 250ms in name_resolve_bcast_send()
We use the same value for broadcasts in name_query().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-26 19:45:36 +00:00
Stefan Metzmacher
08a7f5c47d s3:libsmb: pass dest_ss to cli_cm_open()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-26 19:45:36 +00:00
Stefan Metzmacher
e0c502728f s3:libsmb: pass dest_ss to cli_cm_connect() down to cli_connect_nb()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-26 19:45:36 +00:00
Volker Lendecke
c3242b4dfc libsmb: Fill in device which we don't get from cli_posix_stat
SMB1 unix extensions don't carry st_dev for stat

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14101

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Feb 26 00:50:32 UTC 2020 on sn-devel-184
2020-02-26 00:50:32 +00:00
Volker Lendecke
51551e0d53 libsmb: Pass the correct path to cli_posix_stat()
This fixes doing strlen() on talloc_tos(), about which valgrind is pretty
unhappy. Without this patch we survive the tests because we have fallbacks to
the non-posix flavors of stat(). With this patch in place cli_posix_stat()
becomes functional in this code path. This creates conflicts with the readdir
libsmbclient tests, which need fixing separately.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14101

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 23:23:39 +00:00
Volker Lendecke
15769f11a4 libsmb: Don't pass "sbuf" to cli_posix_stat_send()
Don't pass in the result buffer upon _send(), let the _recv() function
fill this in. Internal API only, adapt to current conventions.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 17:44:45 +00:00
Volker Lendecke
6d282d610f libsmb: Avoid casts
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 17:44:45 +00:00
Volker Lendecke
42f744d871 libsmb: Use IS[DOT]DOT
strequal is not necessary here

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 17:44:44 +00:00
Volker Lendecke
78eae77ec1 libsmb: Remove a pointless ZERO_STRUCT()
"c" is a pointer that was initialized to NULL above

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 17:44:44 +00:00
Volker Lendecke
d7281e3210 libsmb: Simplify callers of SMBC_dlist_contains()
This function already does the NULL check on the file pointer

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 17:44:44 +00:00
Volker Lendecke
427e10e8e3 libsmb: Make SMBC_dlist_contains return bool
It returned True/False, and is used as boolean only. Modernize
formatting a bit.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 17:44:44 +00:00
Volker Lendecke
c3a2cc9ba2 libsmb: Align calls to SMBC_dlist_contains()
Everywhere else it's called as !SMBC_dlist_contains()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 17:44:44 +00:00
Volker Lendecke
a4a96a90bf libsmb: Add a NULL check
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-02-25 17:44:44 +00:00
Stefan Metzmacher
c403fa1a7f krb5_wrap: move source3/libads/krb5_errs.c to lib/krb5_wrap/krb5_errs.c
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2020-02-10 16:32:37 +00:00
Douglas Bagnall
3bc7acc626 nmblib: avoid undefined behaviour in handle_name_ptrs()
If *offset is length - 1, we would read ubuf[(*offset)+1] as the lower
bits of the new *offset. This value is undefined, but because it is
checked against the valid range, there is no way to read further
beyond that one byte.

Credit to oss-fuzz.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14242
OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20193

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Fri Feb  7 10:19:39 UTC 2020 on sn-devel-184
2020-02-07 10:19:39 +00:00
Jeremy Allison
ad236bb759 s3: lib: nmblib. Clean up and harden nmb packet processing.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14239
OSS-FUZZ: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20156
OSS-FUZZ: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=20157

Credit to oss-fuzz.
No security implications.

Signed-off-by: Jeremy Allison <jra@samba.org>
Pair programmed with: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Tue Jan 21 23:33:41 UTC 2020 on sn-devel-184
2020-01-21 23:33:41 +00:00
Volker Lendecke
37eb87d2be lib: Align integer types
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-01-19 18:29:39 +00:00
Samuel Cabrero
2198da1b9b s3:libsmb: Fix querying all names registered within broadcast area
Wait for additional replies until timeout when '*' is given to nmblookup
as name.

Introduced by 8da8c36b53.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=8927

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2020-01-15 21:25:34 +00:00
Andreas Schneider
8b04590e4d libsmbclient: If over SMB1 first try to do a posix stat on the file.
Disable in future, if server doesn't support this.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14101

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Dec 19 15:44:25 UTC 2019 on sn-devel-184
2019-12-19 15:44:25 +00:00
Andreas Schneider
b3e3cb3bbd s3:libsmb: Add a setup_stat_from_stat_ex() function
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14101

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-12-19 14:20:42 +00:00
Andreas Schneider
0fe9dc5219 s3:libsmb: Return a 'struct stat' buffer for SMBC_getatr()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14101

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-12-19 14:20:42 +00:00
Andreas Schneider
bf9a3a7aa1 s3:libsmb: Add try_posixinfo to SMBSRV struct. Only enable for SMB1 with UNIX for now.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14101

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-12-19 14:20:42 +00:00
Andreas Schneider
ea51a426e5 s3:libsmb: Generate the inode only based on the path component
Currently we use the full smb url which includes also username and
password.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14101

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-12-19 14:20:41 +00:00
Isaac Boukris
dce944e8a1 smbdes: convert E_old_pw_hash to use gnutls
Signed-off-by: Isaac Boukris <iboukris@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-12-10 00:30:31 +00:00
Ralph Boehme
1b9c31ef6a libsmb: add cli_setpathinfo_ext()
This takes a struct timespec instead of just time_t as cli_setpathinfo_basic()
does. This is needed to pass sentinel values -1 in the smbclient utime command.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=7771

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-12-06 00:17:36 +00:00
Jeremy Allison
ff47cc661d s3: libsmb: Ensure return from net_share_enum_rpc() sets cli->raw_status on error.
Convert net_share_enum_rpc() to return an NTSTATUS and ensure the
status is set correctly on error so SMBC_errno() can return it.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14176

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>

Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Tue Nov  5 12:36:48 UTC 2019 on sn-devel-184
2019-11-05 12:36:48 +00:00
Puran Chand
2b060f9350 s3:smbclient added ABI signature file
Signed-off-by: Puran Chand <pchand@vmware.com>
Reviewed-by: Andreas Schneider <asn@samba.org>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Wed Oct 30 22:18:15 UTC 2019 on sn-devel-184
2019-10-30 22:18:15 +00:00
Jeremy Allison
abbbbbff37 s3: libsmb: Added new API smbc_readdirplus2()
Returns the same as smbc_readdirplus() but also
can return a struct stat if passed in by the caller.

struct stat is synthesized from the data
returned by the SMB server.

Signed-off-by: Puran Chand <pchand@vmware.com>
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-10-30 20:44:31 +00:00
Jeremy Allison
e26487aab0 s3: libsmb: Add missing ino field to internal struct smbc_dirplus_list.
This should have been added to struct libsmb_file_info, but
this is user-visible so I don't want to change this now. Adding
it to the containing struct allows us to synthesise a struct stat
to return from smbc_readdirplus2() to return all the info from
the server to callers.

Signed-off-by: Puran Chand <pchand@vmware.com>
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-10-30 20:44:31 +00:00
Jeremy Allison
1f0715c0e5 s3: libsmb: Move setting all struct stat fields into setup_stat().
That way we only have one place where a struct stat is synthesised
for libsmbclient callers.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-10-30 20:44:31 +00:00
Jeremy Allison
7d3b4f47be s3: libsmb: Move setting st->st_ino into setup_stat.
Signed-off-by: Puran Chand <pchand@vmware.com>
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-10-30 20:44:31 +00:00
Jeremy Allison
d44a84295b s3: libsmb: Change generate_inode()/setup_stat() to modern coding standards.
Change setup_stat() to be void. It doesn't return anything. Export
so it can be used by upcoming smbc_readdirplus2() call.

Remove unused SMBCCTX *context parameters.
Remove unused talloc_stackframe().

Signed-off-by: Puran Chand <pchand@vmware.com>
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-10-30 20:44:31 +00:00
Jeremy Allison
1cfcad6283 s3: libsmb: Ensure we don't call cli_RNetShareEnum() on an SMB1 connection.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14174

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-10-30 20:44:31 +00:00
Jeremy Allison
7ccc302b4b CVE-2019-10218 - s3: libsmb: Protect SMB2 client code from evil server returned names.
Disconnect with NT_STATUS_INVALID_NETWORK_RESPONSE if so.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14071

Signed-off-by: Jeremy Allison <jra@samba.org>
2019-10-29 10:04:45 +00:00
Jeremy Allison
9f7a622b2b CVE-2019-10218 - s3: libsmb: Protect SMB1 client code from evil server returned names.
Disconnect with NT_STATUS_INVALID_NETWORK_RESPONSE if so.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14071

Signed-off-by: Jeremy Allison <jra@samba.org>
2019-10-29 10:04:44 +00:00
Noel Power
6ebd0ba735 s3/libsmb: clang: Fix 'the left operand of '-' is a garbage value'
Fixes:

source3/libsmb/clifile.c:360:19: warning: The left operand of '-' is a garbage value <--[clang]
        if (data[num_data-1] != '\0') {
                 ~~~~~~~~^
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Ralph Boehme <slow@samba.org>

Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Tue Oct 22 18:48:43 UTC 2019 on sn-devel-184
2019-10-22 18:48:43 +00:00
Noel Power
4ef40d41f6 s3/libsmb: clang: Fix 'Assigned value is garbage or undefined'
Fixes:

source3/libsmb/clirap.c:1490:9: warning: Assigned value is garbage or undefined <--[clang]
                *mode = attr;
                      ^ ~~~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-10-22 17:28:27 +00:00
Noel Power
6162100998 s3/libsmb: clang: Fix 'Value stored to 'p' is never read'
Fixes:

source3/libsmb/clirap.c:145:3: warning: Value stored to 'p' is never read <--[clang]
                p = rdata;
                ^   ~~~~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-10-22 17:28:27 +00:00
Noel Power
764bb47a37 s3/libsmb: clang: Fix 'Assigned value is garbage or undefined'
Fixes:

source3/libsmb/smbsock_connect.c:786:13: warning: Assigned value is garbage or undefined <--[clang]
                state->fd = fd;
                          ^ ~~
1 warning generated.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-10-22 17:28:27 +00:00
Noel Power
4995a0e7e0 s3/libsmb: clang: Fix 'Value stored to 'create_options' is never read'
It looks like the create_options are accumulated as the depending on the
failure reasons returned for cli_smb2_create_fnum (except for when a
directory is encountered) this looks like a mistake
Fixes:

source3/libsmb/cli_smb2_fnum.c:1870:3: warning: Value stored to 'create_options' is never read <--[clang]
                create_options |= FILE_DIRECTORY_FILE;
                ^
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-10-22 17:28:27 +00:00
Noel Power
25a256bedf s3/libsmb: clang: Fix 'Dereference of undefined pointer value'
Fixes:

source3/libsmb/clidfs.c:350:3: warning: Dereference of undefined pointer value <--[clang]
                DLIST_ADD_END(referring_cli, cli);
                ^
1 warning generated.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-10-22 17:28:27 +00:00
Noel Power
7a4da41c1e s3/libsmd: clang: Fix some uninitialized value errors
Fixes:

source3/libsmb/clilist.c:534:14: warning: 1st function call argument is an uninitialized value <--[clang]
        num_finfo = talloc_array_length(finfo);
                    ^
source3/libsmb/clilist.c:1007:13: warning: The right operand of '<' is a garbage value <--[clang]
        for (i=0; i<num_finfo; i++) {
                   ^~~~~~~~~~
2 warnings generated.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-10-22 17:28:27 +00:00
Noel Power
e9dd8821ad s3/libsmb: clang: Fix 'Value stored to 'p' is never read'
Fixes:

source3/libsmb/climessage.c:73:2: warning: Value stored to 'p' is never read <--[clang]
        p += hlen;
        ^    ~~~~
1 warning generated.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-10-22 17:28:27 +00:00
Jeremy Allison
d495074ee2 s3: libsmb: Ensure SMB1 cli_qpathinfo2() doesn't return an inode number.
The info level it uses doesn't return that, previously we
were using the field that is returned as the EA size as
the inode number (which is usually zero, so the code in
libsmbclient would then synthesize an inode number from
a hash of the pathname, which is all it can do for SMB1).

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14161

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-10-18 16:07:35 +00:00
Isaac Boukris
7259197bf7 s3:libsmb: Link libsmb against pthread
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14140

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
2019-10-16 09:33:32 +00:00
Andreas Schneider
7e36de99d7 s3:libsmb: Do not check the SPNEGO neg token for KRB5
The list is not protected and this could be a downgrade attack.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14106

Pair-Programmed-With: Isaac Boukris <iboukris@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>

Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Isaac Boukris <iboukris@redhat.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-10-12 14:33:32 +00:00
Andreas Schneider
b84abb3a46 s3:libnet: Require sealed LDAP SASL connections for joining
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
2019-10-09 07:06:35 +00:00
Noel Power
ee6300470d s3/libsmb: clang: Fix 'Value stored during its initialization is never read'
Fixes:

source3/libsmb/cliconnect.c:1877:11: warning: Value stored to 'status' during its initialization is never read <--[clang]
        NTSTATUS status = NT_STATUS_NO_MEMORY;

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-09-30 23:12:41 +00:00
Noel Power
18e2d6b009 s3/libsmb: clang: Fix 'warning: Value stored to 'p' is never read'
Fixes:

source3/libsmb/cliconnect.c:649:2: warning: Value stored to 'p' is never read <--[clang]
        p += ret;
        ^    ~~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Sep 26 19:59:24 UTC 2019 on sn-devel-184
2019-09-26 19:59:24 +00:00
Noel Power
2138bd93bb s3/libsmb: clang: value stored to 'idx_current' is never read
Fixes:

source3/libsmb/trusts_util.c:602:2: warning: Value stored to 'idx_current' is never read <--[clang]
        idx_current = idx;
        ^             ~~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-09-26 18:41:28 +00:00
Noel Power
50ff6c965f s3/libsmb: clang: Fix 'Value stored during its initialization is never read'
Fixes:

source3/libsmb/dsgetdcname.c:1012:11: warning: Value stored to 'status' during its initialization is never read <--[clang]
        NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
                 ^~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

source3/libsmb/dsgetdcname.c:1099:11: warning: Value stored to 'status' during its initialization is never read <--[clang]
        NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
                 ^~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-09-26 18:41:27 +00:00
Stefan Metzmacher
6ed18c12c5 s3:libsmb: let cli_session_creds_prepare_krb5() update the canonicalized principal to cli_credentials
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14124

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
2019-09-24 18:30:37 +00:00
Stefan Metzmacher
361fb0efab s3:libsmb: avoid wrong debug message in cli_session_creds_prepare_krb5()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14124

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
2019-09-24 18:30:37 +00:00
Jeremy Allison
0d9b164549 s3: libsmbclient: Fix smbc_lseekdir() to work with smbc_readdirplus().
If returning files the dir_list and the dirplus_list have exactly the same
entries, we just need to keep the next pointers in sync on seek.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14094

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
2019-09-03 16:15:36 +00:00
Jeremy Allison
754cec7756 s3: libsmbclient: Ensure SMBC_getdents_ctx() also updates the readdirplus pointers.
If we are returning file entries, we
have a duplicate list in dirplus.

Update dirplus_next also so readdir and
readdirplus are kept in sync.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14094

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
2019-09-03 16:15:36 +00:00
Jeremy Allison
3d82b7d11c s3: libsmbclient: Ensure SMBC_readdirplus_ctx() also updates the readdir pointers.
If we are returning file entries, we
have a duplicate list in dir_list.

Update dir_next also so readdir and
readdirplus are kept in sync.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14094

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
2019-09-03 16:15:36 +00:00
Jeremy Allison
4bca8e097f s3: libsmbclient: Ensure SMBC_readdir_ctx() also updates the readdirplus pointers.
If we are returning file entries, we
have a duplicate list in dirplus.

Update dirplus_next also so readdir and
readdirplus are kept in sync.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14094

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
2019-09-03 16:15:36 +00:00
Mathieu Parent
c5e97f1aa1 Spelling fixes s/wont /won't /
Signed-off-by: Mathieu Parent <math.parent@gmail.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-09-01 22:21:27 +00:00
Mathieu Parent
a59e0ec895 Spelling fixes s/hierachy/hierarchy/
Signed-off-by: Mathieu Parent <math.parent@gmail.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-09-01 22:21:26 +00:00
Noel Power
0be320393b s3/libsmb: clang: Fix 'Value stored during initialization is never read'
Fixes:

source3/libsmb/cliquota.c:340:11: warning: Value stored to 'status' during its initialization is never read <--[clang]
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
                 ^~~~~~   ~~~~~~~~~~~~~~~~~~~~~~
source3/libsmb/cliquota.c:357:4: warning: Value stored to 'status' is never read <--[clang]
                        status = NT_STATUS_OK;
                        ^        ~~~~~~~~~~~~
2 warnings generated.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>

Autobuild-User(master): Gary Lockyer <gary@samba.org>
Autobuild-Date(master): Wed Aug 28 03:06:42 UTC 2019 on sn-devel-184
2019-08-28 03:06:42 +00:00
Noel Power
0c91634ebe s3/libsmb: clang: Fix 'Value stored to 'status' is never read'
Fixes:

source3/libsmb/cliquota.c:340:11: warning: Value stored to 'status' during its initialization is never read <--[clang]
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
                 ^~~~~~   ~~~~~~~~~~~~~~~~~~~~~~
/home/samba/samba/source3/libsmb/cliquota.c:357:4: warning: Value stored to 'status' is never read <--[clang]
                        status = NT_STATUS_OK;
                        ^        ~~~~~~~~~~~~
2 warnings generated.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-28 01:47:40 +00:00
Noel Power
f8b5c47ad5 s3/libsmb: clang: Fix 'warning: Value stored to 'status' is never read'
Fixes:

source3/libsmb/namequery.c:2938:2: warning: Value stored to 'status' is never read <--[clang]
        status = NT_STATUS_OK;
        ^        ~~~~~~~~~~~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-28 01:47:40 +00:00
Noel Power
32aa8f9195 s3/libsmb: clang: Fix 2nd function call argument is an uninitialized value
source3/libsmb/namequery.c:2719:11: warning: 2nd function call argument is an uninitialized value <--[clang]
                                        if (!convert_ss2service(return_iplist,
                                             ^
source3/libsmb/namequery.c:2733:10: warning: 2nd function call argument is an uninitialized value <--[clang]
                                if (!convert_ss2service(return_iplist,
                                     ^
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-28 01:47:40 +00:00
Noel Power
6ef4736c3f s3/libsmb: clang: Fix Value set during its initialization is never read
Fixes:
source3/libsmb/namequery.c:2584:11: warning: Value stored to 'status' during its initialization is never read  <--[clang]
        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-28 01:47:40 +00:00
Noel Power
2abe785264 s3/libsmb: clang: Fix: The right operand of '<' is a garbage value
Fixes:

source3/libsmb/namequery.c:977:12: warning: The right operand of '<' is a garbage value <--[clang]
        for (i=0;i<count;i++) {
                  ^~~~~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-28 01:47:40 +00:00
Noel Power
61c5b891a1 s3/libsmb: clang: Fix value stored to 'offset' is never read
Fixes:

source3/libsmb/nmblib.c:479:2: warning: Value stored to 'offset' is never read <--[clang]
        offset += 10+rec->rdlength;
        ^         ~~~~~~~~~~~~~~~~
1 warning generated.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-28 01:47:40 +00:00
Noel Power
2575e4066b s3/libsmb: clang: Fix 'warning: Assigned value is garbage or undefined '
Fixes:

source3/libsmb/clireadwrite.c:1259:17: warning: Assigned value is garbage or undefined <--[clang]
        state->written += written;
                       ^  ~~~~~~~

source3/libsmb/clireadwrite.c:1722:14: warning: The left operand of '>' is a garbage value <--[clang]
        if (written > expected) {
            ~~~~~~~ ^

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>

Autobuild-User(master): Gary Lockyer <gary@samba.org>
Autobuild-Date(master): Wed Aug 28 00:22:49 UTC 2019 on sn-devel-184
2019-08-28 00:22:49 +00:00
Noel Power
ad8fd31441 s3/libsmb: clang: Fix 'Assigned value is garbage or undefined'
Fixes:

source3/libsmb/clireadwrite.c:851:10: warning: Assigned value is garbage or undefined <--[clang]
                *nread = ret;
                       ^

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-27 23:04:37 +00:00
Noel Power
fcb0355a74 s3/libsmb: clang: Fix '2nd func call argument is uninitalized value'
Fixes:

source3/libsmb/clireadwrite.c:805:2: warning: 2nd function call argument is an uninitialized value <--[clang]
        memcpy(state->buf, buf, received);
        ^                  ~~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-27 23:04:37 +00:00
Noel Power
e1ef992236 s3/libsmb: clang: Fix 'The left operand of '>' or '<' is a garbage value
Fixes:

source3/libsmb/clireadwrite.c:601:15: warning: The left operand of '>' is a garbage value <--[clang]
        if (received > expected) {

source3/libsmb/clireadwrite.c:799:16: warning: The left operand of '<' is a garbage value <--[clang]
        if ((received < 0) || (received > state->buflen)) {
             ~~~~~~~~ ^

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-27 23:04:37 +00:00
Noel Power
e874cc909a s3/libsmb: clang: Fix 'Value stored to 'p' is never read' warning
Fixes:

source3/libsmb/clirap2.c:1197:4: warning: Value stored to 'p' is never read <--[clang]
                        p += rap_getstringp(frame,
                        ^    ~~~~~~~~~~~~~~~~~~~~~
source3/libsmb/clirap2.c:1525:5: warning: Value stored to 'p' is never read <--[clang]
                                p += rap_getstring(frame,
                                ^    ~~~~~~~~~~~~~~~~~~~~
source3/libsmb/clirap2.c:2358:3: warning: Value stored to 'p' is never read <--[clang]
                p += WORDSIZE;            /* skip rsize */
                ^    ~~~~~~~~
source3/libsmb/clirap2.c:2380:3: warning: Value stored to 'p' is never read <--[clang]
                p += rap_getstringp(frame,
                ^    ~~~~~~~~~~~~~~~~~~~~~
4 warnings generated.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-27 23:04:37 +00:00
Noel Power
bf567380a7 s3/libsmb: clang: Fix 'Value stored to 'ea_size' is never read'
Fixes:

source3/libsmb/clifile.c:5290:2: warning: Value stored to 'ea_size' is never read <--[clang]
        ea_size = (size_t)IVAL(rdata,0);
        ^         ~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-27 23:04:37 +00:00
Noel Power
ce9fef5fd5 s3/libsmb: clang: Fix 'Assigned value is garbage or undefined'
Fixes:

source3/libsmb/clifile.c:4898:10: warning: Assigned value is garbage or undefined <--[clang]
                *bsize = (uint64_t)old_bsize;
                       ^ ~~~~~~~~~~~~~~~~~~~
source3/libsmb/clifile.c:4901:10: warning: Assigned value is garbage or undefined <--[clang]
                *total = (uint64_t)old_total;
                       ^ ~~~~~~~~~~~~~~~~~~~
source3/libsmb/clifile.c:4904:10: warning: Assigned value is garbage or undefined <--[clang]
                *avail = (uint64_t)old_avail;

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-27 23:04:37 +00:00
Noel Power
4bb9255473 s3/libsmb: clang: Fix 'The left operand of '&' is a garbage value'
Fixes:

source3/libsmb/clifile.c:3108:26: warning: The left operand of '&' is a garbage value <--[clang]
            (cr.file_attributes & FILE_ATTRIBUTE_DIRECTORY))
             ~~~~~~~~~~~~~~~~~~ ^

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-27 23:04:37 +00:00
Noel Power
e06d34e98e s3/libsmb: clang: Fix 'The left operand of '!=' is a garbage value'
Fixes:

source3/libsmb/clifile.c:789:15: warning: The left operand of '!=' is a garbage value <--[clang]
        if (num_data != 100) {
            ~~~~~~~~ ^

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-08-27 23:04:37 +00:00
Andreas Schneider
0947d8388d s3:libsmb: Use GnuTLS RC4 in clirap
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14031

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-07-26 01:48:24 +00:00
Douglas Bagnall
a2680b4435 s3/libsmb/py: avoid null deref with bad python arguments
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-07-22 22:20:26 +00:00
Volker Lendecke
56521c5fbf libsmb: Make cli_lockingx cancellable
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-06-20 17:18:18 +00:00
Volker Lendecke
7fe67a4782 lib: Fix a typo
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-06-20 17:18:17 +00:00
Volker Lendecke
22aeb005d9 libsmb: Use cli_lockingx() in cli_unlock()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-06-18 12:54:00 +00:00
Volker Lendecke
5211f6afdf libsmb: Use cli_lockingx() in cli_locktype()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-06-18 12:54:00 +00:00
Volker Lendecke
25c7b92fc2 libsmb: Use cli_lockingx() in cli_oplock_ack()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-06-18 12:53:59 +00:00
Volker Lendecke
cc69f49cba libsmb: Add async cli_lockingx()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-06-18 12:53:59 +00:00
Volker Lendecke
a8301bfbe8 libsmb: Remove unused is_andx_req
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-06-18 12:53:59 +00:00
Volker Lendecke
aec8b4a2a9 libsmb: Remove unused cli_[un]lock64()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-06-18 12:53:59 +00:00
Volker Lendecke
52096b498d libsmb: Align integer types
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-06-18 12:53:58 +00:00
Rikard Falkeborn
730037504d s3: libsmbclient: Fix return value if cli_open() fails
Returning -1 in a function with bool as return value type is the same
as returning true. Change to false to indicate the error.

Detected by the help of cppcheck.

Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Reviewed-by: Ralph Böhme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-05-19 17:34:21 +00:00
Noel Power
cea41645fb s3: squash 'cast between incompatible function types' warning
Some functions (e.g. py_smb_savefile) have an extra unecessary
*kwargs param in their signatures, these definitions are
causing 'cast between incompatible function types' warnings when
compiled with -Wcast-function-type. Some other functions have
the *kwargs which causes "cast between incompatible function types'
warnings which need to be squashed with use of the
PY_DISCARD_FUNC_SIG macro.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-05-16 17:55:17 +00:00
Andreas Schneider
28518c579d s3:libsmb: Add missing OOM check in fill_quota_buffer()
Found by covscan (csbuild).

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Noel Power <nopower@suse.com>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed May 15 00:45:58 UTC 2019 on sn-devel-184
2019-05-15 00:45:58 +00:00
Andreas Schneider
99eb720338 s3:libsmb: Fix C99 initializer in cli_smb2_fnum.c
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
2019-04-29 16:04:28 +00:00
Andreas Schneider
011a47f04d s3:libsmb: Add some useful debug output to cliconnect
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13861

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-04-02 01:12:09 +00:00
Volker Lendecke
0876712ce8 libsmb: Make cli_posix_chown/chmod proper tevent_req functions
This prepares for making them smb2-aware

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Mon Apr  1 19:00:11 UTC 2019 on sn-devel-144
2019-04-01 19:00:11 +00:00
Volker Lendecke
aac203907f libsmb: Rename InfoType from [MS-SMB2] according to the spec
This makes it easier to find this via internet search

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-04-01 17:58:16 +00:00
Volker Lendecke
3e1d8ab125 libsmb: Change cli_posix_readlink to return talloc'ed target
This is a deviation from the Posix readlink function that from my
point of view makes this function easier to use. In Posix, probably
the assumption is that readlink is cheap, so someone under memory
constraints could just start with a small buffer and incrementally
increase the buffer size. For us, it's a network round-trip, and we
have the luxury of [mt]alloc, which the syscall kernel interface does
not have.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Mar 27 12:31:37 UTC 2019 on sn-devel-144
2019-03-27 12:31:37 +00:00
Volker Lendecke
3478e9d124 libsmb: Don't pass "cli" to cli_posix_readlink_recv
From my point of view the option to change "cli" between
cli_posix_readlink_send and _recv is not necessary.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-27 11:20:23 +00:00
Volker Lendecke
c7fae52ff0 libsmb: Rename "readlink_state" to "cli_posix_readlink_state"
This is more in line with most other users of tevent_req: The state is
called fully after the routines it acts as a state repository for.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-27 11:20:23 +00:00
Volker Lendecke
f9a6992e80 libsmb: Fix valgrind errors in cli_smb2_get_reparse_point
Both tevent_req_nterror and tevent_req_is_nterror invalidate
"state". Pull the variables out of "state" before calling those two
functions.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-27 11:20:23 +00:00
Volker Lendecke
5c6fdb5dc7 libsmb: Fix cli_smb2_get_reparse_point_fnum_send
Use the correct state variable type

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-03-26 03:03:23 +00:00
Volker Lendecke
2a430625e7 libsmb: Make SMB1-only cli_nt_hardlink calls static
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Mar 20 23:32:31 UTC 2019 on sn-devel-144
2019-03-20 23:32:31 +00:00
Volker Lendecke
b5af004b23 libsmb: Introduce protocol-agnostic cli_hardlink
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-20 22:07:45 +00:00
Volker Lendecke
b4c87b09b6 libsmb: Use cli_smb2_set_info_fnum()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-20 22:07:45 +00:00
Volker Lendecke
c013aad7b7 libsmb: Simplify cli_smb2_ftruncate
We don't need to talloc 8 bytes, they can live on the stack. When we
go async, this can go into the state struct.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-20 22:07:45 +00:00
Volker Lendecke
32c5b6c1c2 libsmb: Simplify cli_smb2_delete_on_close
Use cli_smb2_set_info_fnum, remove "state" variables

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-20 22:07:45 +00:00
Volker Lendecke
4f5b9e509f libsmb: Add cli_smb2_set_info_fnum
This wraps getting the file handle from the fnum

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-20 22:07:45 +00:00
Volker Lendecke
e872227bfb libsmb: Fix a "assuming signed overflow does not occur" error
Eventually we need to convert internal_resolve_name to "size_t" for
"return_count". But that's a patch for another day :-)

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-03-18 19:21:24 +00:00
Volker Lendecke
7da54f6fd3 libsmb: Align integer types
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-03-18 19:21:24 +00:00
Volker Lendecke
4e6f32ad7d libsmb: Use cli_smb2_query_info_fnum
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-18 19:21:24 +00:00
Volker Lendecke
5909709e3b libsmb: Add cli_smb2_query_info_fnum
This wraps getting the file handle from the fnum

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-18 19:21:24 +00:00
Volker Lendecke
7e6991565e libsmb: Change cli_posix_stat_send to take a pointer to sbuf
This moves the parsing work from the _recv function into the _done
function. This makes writing the SMB2 call easier later on: We can
have a smb2-specific done function doing the smb2-specific work and we
don't have to fork on protocol in the _recv function.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-18 19:21:24 +00:00
Volker Lendecke
cfc3f32038 libsmb: Make cli_posix_[sym|hard]link proper tevent_req functions
Simplify adding SMB2 to those functions

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-18 19:21:23 +00:00
Volker Lendecke
2040196e10 libsmb: Use tevent_req_simple_finish_ntstatus
Less lines of code

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-18 19:21:23 +00:00
Volker Lendecke
afd5d34f5e libsmb: Use sid_parse()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-03-12 00:42:19 +00:00
Volker Lendecke
7caf2cbdf1 libsmb: Use tevent_req_simple_finish_ntstatus
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Fri Mar  8 19:16:18 UTC 2019 on sn-devel-144
2019-03-08 19:16:18 +00:00
Volker Lendecke
9a38dc0c1f libsmb: Add "in_cblobs" to cli_smb2_unlink
This reveals the fact that unlink is an open/close in smb2 through the
API. This is not nice, but it's an internal API with currently only
one user. And it enables posix semantics for the open easily.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-08 18:20:10 +00:00
Volker Lendecke
7fc3b2b264 libsmb: Add "in_cblobs" to cli_smb2_rmdir
This reveals the fact that rmdir is an open/close in smb2 through the
API. This is not nice, but it's an internal API with currently only
one user. And it enables posix semantics for the open easily.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-08 18:20:10 +00:00
Volker Lendecke
20ebd17685 libsmb: Make cli_smb2_unlink async
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-08 18:20:10 +00:00
Volker Lendecke
3873437ee0 libsmb: Simplify cli_smb2_mxac
smb2_create_blob_find() can search for a create blob for us

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-08 18:20:10 +00:00
Ralph Boehme
52e1171e21 s3:libsmb: add cli_query_mxac()
Works only for SMB2.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-04 18:11:17 +00:00
Ralph Boehme
c8c6da2c29 s3:libsmb: add cli_smb2_query_mxac()
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-04 18:11:16 +00:00
Volker Lendecke
d1c2fe8907 libsmb: Make cli_posix_unlink/rmdir proper tevent_req/subreq pairs
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Mar  2 00:55:56 UTC 2019 on sn-devel-144
2019-03-02 00:55:56 +00:00
Volker Lendecke
65c269d538 libsmb: Use tevent_req_simple_finish_ntstatus()
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-01 23:58:11 +00:00
Volker Lendecke
743b922ad9 libsmb: Use tevent_req_simple_finish_ntstatus()
Less lines... Just rediscovered this function :-)

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-01 23:58:11 +00:00
Volker Lendecke
99ef0ba048 libsmb: Make cli_smb2_rmdir asynchronous
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Fri Mar  1 01:30:35 UTC 2019 on sn-devel-144
2019-03-01 01:30:34 +00:00
Volker Lendecke
02f4080284 libsmb: add in/out cblobs to cli_smb2_create_fnum
This is driven by the imminent smb2 unix extensions, we'll want to make use of
it from source3/libsmb.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-01 00:32:12 +00:00
Volker Lendecke
56e08d3996 libsmb: Avoid a separate "cblobs" var sending smb2 create
Less lines of code, and we will add custom cblobs soon. This change
makes that logic easier.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-01 00:32:12 +00:00
Volker Lendecke
a787c319f1 libsmb: Reformat the cli_smb2_create_fnum_send args
We'll add parameters in the next commit, make that commit a bit more obvious

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-01 00:32:12 +00:00
Volker Lendecke
26f18b9bd7 libsmb: Resolve special _recv handling in cli_ntcreate
cli_smb2_create_fnum_recv will gain output create blobs soon and thus
differ from the NT1 function.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-02-25 19:36:20 +01:00
Volker Lendecke
5dd67797ca libsmb: Fix a resource leak in cli_posix_mkdir
smbd does posix_mkdir if the wire flags are exactly

	if (wire_open_mode == (SMB_O_CREAT|SMB_O_DIRECTORY))

open_flags_to_wire however adds a SMB_O_RDONLY, so that we enter the
normal open routine which happens to create a directory as well. The
main difference is that posix_mkdir does *NOT* return an open
handle. As we did not enter this code path due to the SMB_O_RDONLY we
leak a SMB1 fd per cli_posix_mkdir call.

Pretty hard to test automatically, this would be an interaction with
smbstatus.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-02-22 21:48:11 +01:00
Volker Lendecke
529c61d0c9 libsmb: Pull up wire_flags calculation from open_internal
This avoids passing down a boolean

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-02-22 21:48:11 +01:00
Volker Lendecke
64176f00bf libsmb: Convert cli_posix_open to normal tevent_req pattern
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-02-22 21:48:11 +01:00
Mark Niggemann
02c9bee85a set caller allocation units in statvfs f_bavail
Signed-off-by: Mark Niggemann <mark.niggemann@ge.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Bjoern Jacke <bjacke@samba.org>

Autobuild-User(master): Björn Jacke <bjacke@samba.org>
Autobuild-Date(master): Fri Feb 22 15:04:55 CET 2019 on sn-devel-144
2019-02-22 15:04:54 +01:00
Andreas Schneider
96df6878ed lib:util: Move discard_const(_p) to own header for libndr.h
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13778

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-02-14 15:59:26 +01:00
Aurelien Aptel
584dfc15fd libsmb,s3/smbd: dump SMB3+ session keys if debug parm is set
Use of previously added smb.conf global param.

Sample usage:

$ smbclient //localhost/scratch --option='debugencryption=yes' \
                                 -e -mSMB3 -U aaptel%aaptel -c quit
debug encryption: dumping generated session keys
Session Id    [0000] 26 48 BF FD 00 00 00 00                             &H......
Session Key   [0000] 63 D6 CA BC 08 C8 4A D2   45 F6 AE 35 AB 4A B3 3B   c.....J. E..5.J.;
Signing Key   [0000] 4E FE 35 92 AC 13 14 FC   C9 17 62 B1 82 20 A4 12   N.5..... ..b.. ..
App Key       [0000] A5 0F F4 8B 2F FB 0D FF   F2 BF EE 39 E6 6D F5 0A   ..../... ...9.m..
ServerIn Key  [0000] 2A 02 7E E1 D3 58 D8 12   4C 63 76 AE 59 17 5A E4   *.~..X.. Lcv.Y.Z.
ServerOut Key [0000] 59 F2 5B 7F 66 8F 31 A0   A5 E4 A8 D8 2F BA 00 38   Y.[.f.1. ..../..8

We can now simply pass -ouat:smb2_seskey_list:<sesid>,<seskey> to
wireshark or tshark:

$ tshark -ouat:smb2_seskey_list:2648BFFD00000000,63D6CABC08C84AD245F6AE35AB4AB33B \
          -Y smb2 -r capture.pcap -Tfields -e _ws.col.Info
Negotiate Protocol Response
Negotiate Protocol Request
Negotiate Protocol Response
Session Setup Request, NTLMSSP_NEGOTIATE
Session Setup Response, Error: STATUS_MORE_PROCESSING_REQUIRED, NTLMSSP_CHALLENGE
Session Setup Request, NTLMSSP_AUTH, User: WORKGROUP\aaptel
Session Setup Response
Tree Connect Request Tree: \\localhost\IPC$
Tree Connect Response
Decrypted SMB3;Ioctl Request FSCTL_DFS_GET_REFERRALS, File: \localhost\scratch
Decrypted SMB3;Ioctl Response, Error: STATUS_NOT_FOUND
Decrypted SMB3;Tree Disconnect Request
Decrypted SMB3;Tree Disconnect Response
Decrypted SMB3;Tree Connect Request Tree: \\localhost\scratch
Decrypted SMB3;Tree Connect Response
Decrypted SMB3;Tree Disconnect Request
Decrypted SMB3;Tree Disconnect Response

For more info on Wireshark decryption support see
https://wiki.samba.org/index.php/Wireshark_Decryption

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Reviewed-by: Noel Power <npower@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>

Autobuild-User(master): David Disseldorp <ddiss@samba.org>
Autobuild-Date(master): Sat Feb  9 21:43:25 CET 2019 on sn-devel-144
2019-02-09 21:43:25 +01:00
Douglas Bagnall
96cdacae14 s3/libsmb/py: match input argument types with C types
If PyArg_ParseTupleAndKeywords() is given, say, an "H" format (meaning
unsigned short int) but the referenced variable is a plain unsigned
int, the top 16 bits of the variable will be left undefined. In that
case we should use an "I" format (and/or initialize the variable).

In many cases the change is fairly innocuous, such as when "i" and "I"
are mixed (for signed and unsigned ints respectively), but the
resulting write is the same size and probably gives the same result in
practice.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Noel Power <npower@samba.org>
2019-02-08 13:31:38 +01:00
Noel Power
2814690d8f Cleanup (decref) some objects added to list.
PyList_Append doesn't steal references, so if the item created is
a temp object, created just to be added to the list we need to
 decref the item appended in order for it to be released.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-02-07 13:44:30 +01:00
Noel Power
a8e10a1249 Decrement references to python objects passed to Py_BuildValue
Py_BuildValue when processing format 'O' will
  'Pass a Python object untouched (except for its reference count,
   which is incremented by one'

Basically this means if you are using a new reference to a PyObject
to pass to BuildValue (to be used with the 'O' format) the reference
*isn't* stolen so you really do need to DECREF it in order to ensure
it gets cleaned up.

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-02-07 13:44:30 +01:00
Tim Beale
8c097b4a31 s3:pylibsmb: Initialize pointers to NULL in new API code
Fix a few uninitialized pointers that managed to sneak through review.

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-01-26 00:53:10 +01:00
Jeremy Allison
2c113522fe s3:libsmb: Store file allocation size in struct file_info.
We get this already, from SMB2_FIND_ID_BOTH_DIRECTORY_INFO
so return it.

For SMB1 leave this as zero so callers know it hasn't
been initialized.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-01-18 20:11:22 +01:00
Puran Chand
c5a69c9f0c s3:libsmb: parse_finfo_id_both_directory_info capture FileID in SMB2_FIND_ID_BOTH_DIRECTORY_INFO response
This captures the FileID in struct file_info while parsing SMB2_FIND_ID_BOTH_DIRECTORY_INFO
response

Refered MS doc for spec:- https://msdn.microsoft.com/en-us/library/cc246290.aspx

Signed-off-by: Puran Chand <pchand@vmware.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
2019-01-18 20:11:22 +01:00
Tim Beale
0304b08de5 s3:pylibsmb: Add FILE_READ_ATTRIBUTES access to .loadfile() API
Add FILE_READ_ATTRIBUTES when opening the file handle, as we need to
read the file's size.

The .loadfile() API can end up calling cli_qfileinfo_basic() to get the
file size. This can end up doing a 'FILE_ALL_INFORMATION' SMBv2 request
underneath, which the MS-SMB2 spec (section 3.3.5.20.1 Handling
SMB2_0_INFO_FILE) says the file handle must have FILE_READ_ATTRIBUTES
access granted.

I noticed this problem when running .loadfile() against the NTVFS
server.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-01-17 01:40:30 +01:00
Tim Beale
b982811b60 s3:pylibsmb: Add .set_acl API to SMB py bindings
This is pretty similar code to py_smb_getacl(), except it's calling
cli_set_security_descriptor() instead of cli_query_security_descriptor()

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-01-17 01:40:30 +01:00
Justin Stephenson
c324f84a2f s3:libsmb: Honor disable_netbios option in smbsock_connect_send
If disable_netbios is set, return before the tevent timer is triggered
to prevent outgoing netbios connections.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13727

Signed-off-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Wed Jan 16 08:54:23 CET 2019 on sn-devel-144
2019-01-16 08:54:23 +01:00
Tim Beale
bae415453e s3:pylibsmb: Add .get_acl() API to SMB py bindings
There is no obvious async-equivalent of cli_query_security_descriptor(),
so it will throw an error if anyone tries to use it in multi-threaded
mode. Currently only samba-tool and tests use the (s4) .get_acl() API,
both of which will be fine using the synchronous API.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-01-14 03:30:20 +01:00
Tim Beale
fd355dff90 s3:libsmb: cli_smb2_list() can sometimes fail initially on a connection
cli_smb2_list() appears to be a slightly unique SMB operation in that it
specifies the max transaction size for the response buffer size. The
Python bindings highlighted a problem where if cli_smb2_list() were one
of the first operations performed on the SMBv2 connection, it would fail
due to insufficient credits. Because the response buffer size is
(potentially) so much larger, it requires more credits (128) compared
with other SMB operations.

When talking to a samba DC, the connection credits seem to start off at
1, then increase by 32 for every SMB reply we receive back from the
server. After cli_full_connection(), the connection has 65 credits. The
cli_smb2_create_fnum() in cli_smb2_list() adds another 32 credits, but
this is still less than the 128 that smb2cli_query_directory() requires.

This problem doesn't happen for smbclient because the cli_cm_open() API
it uses ends up sending more messages, and so the connection has more
credits.

This patch changes cli_smb2_list(), so it requests a smaller response
buffer size if it doesn't have enough credits available for the max
transaction size. smb2cli_query_directory() is already in a loop, so it
can span multiple SMB messages if for some reason the transaction size
isn't big enough for the listings.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13736

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>

Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Thu Jan 10 02:40:16 CET 2019 on sn-devel-144
2019-01-10 02:40:16 +01:00
Justin Stephenson
ecbb2f78ce s3:smbpasswd: Print debug message about Netbios
With a preceding patch, cli_connect_nb() will return
NT_STATUS_NOT_SUPPORTED when 'disable netbios' is set in smb.conf.

Print an informative error message to indicate Netbios is disabled
if this occurs.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13727

Signed-off-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Noel Power <nopower@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-01-09 18:40:44 +01:00
Justin Stephenson
499f051c9d s3:libsmb: Print debug message about Netbios
With a preceding patch, cli_connect_nb() will return
NT_STATUS_NOT_SUPPORTED when 'disable netbios' is set in smb.conf.

Print an informative error message to indicate Netbios is disabled
if this occurs.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13727

Signed-off-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Noel Power <nopower@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-01-09 18:40:44 +01:00
Justin Stephenson
78f51a1d3c s3:libsmb: Check disable_netbios in socket connect
If the disable_netbios option is set then return NT_STATUS_NOT_SUPPORTED
for a port 139 connection in the low level socket connection code.

Signed-off-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Noel Power <nopower@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-01-09 18:40:44 +01:00
Tim Beale
a9def5c697 s3:libsmb: Revert SMB Py bindings name back to libsmb_samba_internal
In order to make it clear that the APIs in these Python bindings are
unstable and should not be used by external consumers, this patch
changes the name of the Python bindings back to libsmb_samba_internal.

To make the Python code that uses these bindings (i.e. samba-tool, etc)
look a little cleaner, we can just change the module name as we import
it, e.g.

  from samba.samba3 import libsmb_samba_internal as libsmb

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Stefan Metzmacher <metze@samba.org>

Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Wed Jan  9 14:30:31 CET 2019 on sn-devel-144
2019-01-09 14:30:31 +01:00
Volker Lendecke
fa945bc1e0 libsmb: Use strlcpy instead of StrnCpy
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2019-01-08 03:40:26 +01:00
Tim Beale
3ba32aa55f s3:pylibsmb: Add flags used by .list() to SMB Py bindings
These flags are exposed by the s4 code. Python code that calls .list()
checks the returned attribs/mode for the directory listing, e.g. to work
out whether something is a sub-directory:

  if item['attrib'] & libsmb.FILE_ATTRIBUTE_DIRECTORY...

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-01-07 22:48:28 +01:00
Tim Beale
27e2b5c6c0 s3:pylibsmb: Rename 'credentials' param to match s4
s4 just calls it 'creds'. Renaming it will make it easier to convert
existing SMB connections over to use the new bindings.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2019-01-07 22:48:28 +01:00
Tim Beale
8662ff6720 s3:pylibsmb: Rename libsmb_samba_internal Py bindings to libsmb
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-01-07 22:48:27 +01:00
Tim Beale
9a3e640bba s3:pylibsmb: Add .deltree() API to SMB py bindings
This basically re-uses the underlying functionality of existing APIs in
order to support a .deltree() API, i.e.
- we use the .list() functionality (i.e. do_listing()) to traverse every
  item in the given directory.
- we then use either .unlink() (i.e. unlink_file()) or .rmdir() (i.e.
  remove_dir()) to delete the individual item.
- sub-directories are handled recursively, by repeating the process.

Note that the .deltree() API is currently only really used for testing
(and deleting GPO files). So the recursion is never going to be
excessive.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:08 +01:00
Tim Beale
ea00215d53 s3:pylibsmb: Minor refactor to py_cli_list() variables
Add a define for the file attribute mask (we'll reuse it in a subsequent
patch), and make the variable type explicit.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:08 +01:00
Tim Beale
1d0d1a758b s3:libsmb: Avoid duplicated code by making cli_read_sink() public
cli_read_sink() and pull_helper() were essentially identical. By making
cli_read_sink() non-static, we can delete the latter.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-01-07 01:23:08 +01:00
Tim Beale
d7c7d6203b s3:pylibsmb: Add .loadfile() API to SMB py bindings
Add a .loadfile API to read a file's contents. This provides a
convenient way to read a file and is consistent with the existing
source4 API, which is used by things like the GPO python code and the
ntacls backup.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-01-07 01:23:08 +01:00
Tim Beale
0af78faf5c s3:pylibsmb: Add .savefile() API to SMB py bindings
This provides a simple API for writing a file's contents and makes the
s3 API consistent with the s4 API.

All the async APIs here support SMBv2 so we don't need to use the sync
APIs at all.

Note that we have the choice here of using either cli_write_send() or
cli_push_send(). I chose the latter, because that's what smbclient uses.
It also appears to handle writing a large file better (i.e. one that
exceeds the max write size of the underlying connection).

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-01-07 01:23:08 +01:00
Tim Beale
e4d1d53597 s3:pylibsmb: Free async .list() memory
finfos was being allocated but never freed.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:08 +01:00
Tim Beale
6bcd64a4f1 s3:pylibsmb: Make s3 and s4 listings return the same dict
Make the python dictionary generated by the s3 .list() use the same keys
as the current source4 dict. The reason for using the source4 dict is
that other python code depends on these keys (e.g. ntacls.py), whereas
the source3 API is currently unused.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-01-07 01:23:08 +01:00
Tim Beale
5f1ed29d6b s3:pylibsmb: Don't return '.'/'..' in .list()
The source4 .list() API wasn't doing this. This makes source3 and source4
have *almost* equivalent functionality, so we can start usign the
source3 API in the tests.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Tim Beale
3ac4866d15 s3:pylibsmb: Make .list() work for SMBv2
In order for .list() to work on an SMBv2 connection we need to
use the synchronous API.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Tim Beale
057161039f s3:pylibsmb: Split code out into do_listing() helper
We'll want to reuse the directory listing function for the deltree API.
This patch splits the bulk of the work out into a do_listing() helper
function.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Tim Beale
2033208a4a s3:pylibsmb: Split out code into list_helper()
Refactor out the code so we can re-use it for the synchronous API as
well.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Tim Beale
40f4e52732 s3:pylibsmb: Consolidate .readdir()/.list() py bindings API
Rename the .readdir API to .list and make the parameters match up with
the s4 python bindings, i.e. 'mask' is optional and separate from the
directory parameter.

Note that nothing uses the .readdir source3 API currently, so it's safe
to rename.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Tim Beale
c4dee3437a s3:pylibsmb: Add .chkpath() API to SMB py bindings
Note that this is checking the existence of *directories*, not *files*.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Tim Beale
6a40e538df s3:pylibsmb: Add .mkdir(), .rmdir() APIS to SMB py bindings
I kept these separate from the chkpath API because it's a nice way to
use the old s4 API in the tests to verify the new s3 API works
correctly.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Tim Beale
8096419c71 s3:pylibsmb: Add .unlink() API to SMB Py bindings
Add a basic .unlink() API to the source3 bindings. This is based on the
source4 python bindings, but uses the source3 client library APIs.
(We use a helper function to do most of the work, because we will need
to reuse it in order to support the deltree API).

Update the source4 test to use the source3 API. We will gradually
convert it over, and then delete the source4 python bindings.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Tim Beale
6fff2c26da s3:pylibsmb: Make lp a mandatory param for the SMB connection
Currently establishing the SMB connection relies on having initialized
the global source3 loadparm.

This patch makes the lp param mandatory, so that you always have to pass
the parameter in when establishing the SMB connection.

It also makes the source3 API more consistent with the current source4
API, which will make it easier to replace the source4 version later.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-01-07 01:23:07 +01:00
Stefan Metzmacher
deb0c2bdcb s3:pylibsmb: add settimeout()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2018-12-23 18:15:19 +01:00
Stefan Metzmacher
ecafdcb391 s3:pylibsmb: allow ImpersonationLevel argument to create()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Thu Dec 13 12:35:06 CET 2018 on sn-devel-144
2018-12-13 12:35:05 +01:00
Stefan Metzmacher
c8a5e89d9f s3:libsmb: pass impersonation_level to cli_ntcreate_send()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Stefan Metzmacher
ed0deadf62 s3:libsmb: pass ImpersonationLevel to cli_ntcreate1_send()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Stefan Metzmacher
850aef94dc s3:libsmb: pass impersonation_level to cli_smb2_create_fnum()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Stefan Metzmacher
be464c1dc8 s3:libsmb: pass impersonation_level to cli_smb2_create_fnum_send()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Stefan Metzmacher
64e68abdc9 s3:pylibsmb: make use of protocol independent cli_read_send/recv in py_cli_read()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Stefan Metzmacher
3c3b44004f s3:pylibsmb: make use of protocol independent cli_write_send/recv in py_cli_write()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Tim Beale
9fb0d8e7e2 s3:libsmb: add comments for cli_write_send/cli_push_send
Added a code comment highlighting this 2 APIs do similar jobs, and tried
to explain why you might want to use one over the other.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Stefan Metzmacher
6a3d2c3345 s3:libsmb: add cli_write_send/recv which work with SMB1/2/3
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Stefan Metzmacher
0af6b33544 s3:pylibsmb: make use of PYARG_BYTES_LEN in py_cli_write()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:24 +01:00
Stefan Metzmacher
60148c9ee1 s3:pylibsmb: make use of PyBytes_FromStringAndSize() in py_cli_read()
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:23 +01:00
Tim Beale
aaf7aaa6e2 s3:pylibsmb: .get_oplock_break API is dependent on multi_threaded=True
The .get_oplock_break is dependent on the pthread code, which is only
used when creating a SMB connection with multi_threaded=True.

Add an explicit error to the .get_oplock_break() if someone tries to use
it in non-multithreaded mode.

Initializing self->oplock_waiter in non-multithreaded mode is similarly
redundant if the API can never be used.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Tim Beale <timbeale@catalyst.net.nz>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:23 +01:00
Stefan Metzmacher
fdc62b03ca s3:pylibsmb: remember that a connection uses SMB1
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7113
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11892
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Tim Beale <timbeale@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-13 08:52:23 +01:00