The branch, v4-17-test has been updated via 142a771d854 s3: libsmbclient: Fix smbc_stat() to return ENOENT on a non-existent file. via 09ec2b13e7c s4: torture: libsmbclient: Add a torture test to ensure smbc_stat() returns ENOENT on a non-existent file. from 7540755de6a s4:messaging: let imessaging_client_init() use imessaging_init_discard_incoming()
https://git.samba.org/?p=samba.git;a=shortlog;h=v4-17-test - Log ----------------------------------------------------------------- commit 142a771d85463216075913695d84530c6cb4ff9e Author: Jeremy Allison <j...@samba.org> Date: Mon Oct 17 13:24:27 2022 -0700 s3: libsmbclient: Fix smbc_stat() to return ENOENT on a non-existent file. Remove knownfail. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15195 Signed-off-by: Jeremy Allison <j...@samba.org> Reviewed-by: Pavel Filipenský <pfilipen...@samba.org> Autobuild-User(master): Jeremy Allison <j...@samba.org> Autobuild-Date(master): Wed Oct 19 00:13:56 UTC 2022 on sn-devel-184 (cherry picked from commit fd0c01da1c744ae6fd9d8675616d8b6d3531e469) Autobuild-User(v4-17-test): Jule Anger <jan...@samba.org> Autobuild-Date(v4-17-test): Wed Oct 19 11:52:24 UTC 2022 on sn-devel-184 commit 09ec2b13e7cccb0beeac6c87a9acd6ea5537d8ed Author: Jeremy Allison <j...@samba.org> Date: Mon Oct 17 13:14:41 2022 -0700 s4: torture: libsmbclient: Add a torture test to ensure smbc_stat() returns ENOENT on a non-existent file. Add knownfail. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15195 Signed-off-by: Jeremy Allison <j...@samba.org> Reviewed-by: Pavel Filipenský <pfilipen...@samba.org> (cherry picked from commit 9eda432836bfff3d3d4a365a08a5ecb54f0f2e34) ----------------------------------------------------------------------- Summary of changes: source3/libsmb/libsmb_file.c | 34 ++++++++++++---- source4/torture/libsmbclient/libsmbclient.c | 63 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 8 deletions(-) Changeset truncated at 500 lines: diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c index fa301b9fa18..98750754036 100644 --- a/source3/libsmb/libsmb_file.c +++ b/source3/libsmb/libsmb_file.c @@ -464,6 +464,7 @@ SMBC_getatr(SMBCCTX * context, struct timespec access_time_ts = {0}; struct timespec write_time_ts = {0}; struct timespec change_time_ts = {0}; + struct timespec w_time_ts = {0}; time_t write_time = 0; SMB_INO_T ino = 0; struct cli_credentials *creds = NULL; @@ -506,6 +507,7 @@ SMBC_getatr(SMBCCTX * context, } if (!srv->no_pathinfo2) { + bool not_supported_error = false; status = cli_qpathinfo2(targetcli, targetpath, &create_time_ts, @@ -518,11 +520,21 @@ SMBC_getatr(SMBCCTX * context, if (NT_STATUS_IS_OK(status)) { goto setup_stat; } + if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL) || + NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) { + not_supported_error = true; + } + if (!not_supported_error) { + /* "Normal error". Just return it to caller. */ + TALLOC_FREE(frame); + return status; + } } srv->no_pathinfo2 = True; if (!srv->no_pathinfo3) { + bool not_supported_error = false; status = cli_qpathinfo3(targetcli, targetpath, &create_time_ts, @@ -535,6 +547,15 @@ SMBC_getatr(SMBCCTX * context, if (NT_STATUS_IS_OK(status)) { goto setup_stat; } + if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL) || + NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) { + not_supported_error = true; + } + if (!not_supported_error) { + /* "Normal error". Just return it to caller. */ + TALLOC_FREE(frame); + return status; + } } srv->no_pathinfo3 = True; @@ -545,14 +566,11 @@ SMBC_getatr(SMBCCTX * context, } status = cli_getatr(targetcli, targetpath, &attr, &size, &write_time); - if (NT_STATUS_IS_OK(status)) { - struct timespec w_time_ts = - convert_time_t_to_timespec(write_time); - - access_time_ts = change_time_ts = write_time_ts = w_time_ts; - - goto setup_stat; + if (!NT_STATUS_IS_OK(status)) { + goto all_failed; } + w_time_ts = convert_time_t_to_timespec(write_time); + access_time_ts = change_time_ts = write_time_ts = w_time_ts; setup_stat: setup_stat(sb, @@ -573,7 +591,7 @@ all_failed: srv->no_pathinfo3 = False; TALLOC_FREE(frame); - return NT_STATUS_ACCESS_DENIED; + return status; } /* diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c index 82f64c38b69..d335cad3a4e 100644 --- a/source4/torture/libsmbclient/libsmbclient.c +++ b/source4/torture/libsmbclient/libsmbclient.c @@ -1412,6 +1412,67 @@ static bool torture_libsmbclient_rename(struct torture_context *tctx) return success; } +static bool torture_libsmbclient_getatr(struct torture_context *tctx) +{ + const char *smburl = torture_setting_string(tctx, "smburl", NULL); + SMBCCTX *ctx = NULL; + char *getatr_name = NULL; + struct stat st = {0}; + bool ok; + int ret = 0; + int err = 0; + + if (smburl == NULL) { + torture_fail(tctx, + "option --option=torture:smburl=" + "smb://user:password@server missing\n"); + } + + ok = torture_libsmbclient_init_context(tctx, &ctx); + torture_assert(tctx, ok, "Failed to init context"); + smbc_set_context(ctx); + + getatr_name = talloc_asprintf(tctx, + "%s/noexist", + smburl); + if (getatr_name == NULL) { + torture_result(tctx, + TORTURE_FAIL, + __location__": %s", + "talloc fail\n"); + return false; + } + /* Ensure the file doesn't exist. */ + smbc_unlink(getatr_name); + /* + * smbc_stat() internally uses SMBC_getatr(). + * Make sure doing getatr on a non-existent file gives + * an error of -1, errno = ENOENT. + */ + + ret = smbc_stat(getatr_name, &st); + if (ret == -1) { + err = errno; + } + torture_assert_int_equal(tctx, + ret, + -1, + talloc_asprintf(tctx, + "smbc_stat on '%s' should " + "get -1, got %d\n", + getatr_name, + ret)); + torture_assert_int_equal(tctx, + err, + ENOENT, + talloc_asprintf(tctx, + "smbc_stat on '%s' should " + "get errno = ENOENT, got %s\n", + getatr_name, + strerror(err))); + return true; +} + NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx) { struct torture_suite *suite; @@ -1438,6 +1499,8 @@ NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx) torture_suite_add_simple_test(suite, "rename", torture_libsmbclient_rename); + torture_suite_add_simple_test(suite, "getatr", + torture_libsmbclient_getatr); suite->description = talloc_strdup(suite, "libsmbclient interface tests"); -- Samba Shared Repository