From 8751db3a9d6b6dd9da0bc3d7208792e668418414 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 28 Oct 2022 15:28:41 -0700 Subject: [PATCH 1/2] s4: torture: Show return value for smbc_getxattr() is incorrect (returns >0 for success, should return zero). Add torture test to show smbc_getxattr() should return -1 on failure, 0 on success. Add knownfail. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14808 Signed-off-by: Jeremy Allison Reviewed-by: David Mulder (cherry picked from commit 74636dfe24c15677261fc40c0a4ec62404898cf4) --- selftest/knownfail.d/libsmbclient_getxattr | 1 + source4/torture/libsmbclient/libsmbclient.c | 94 +++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 selftest/knownfail.d/libsmbclient_getxattr diff --git a/selftest/knownfail.d/libsmbclient_getxattr b/selftest/knownfail.d/libsmbclient_getxattr new file mode 100644 index 00000000000..f27656f4ce4 --- /dev/null +++ b/selftest/knownfail.d/libsmbclient_getxattr @@ -0,0 +1 @@ +^samba4.libsmbclient.getxattr.* diff --git a/source4/torture/libsmbclient/libsmbclient.c b/source4/torture/libsmbclient/libsmbclient.c index d335cad3a4e..55ea26f5bc8 100644 --- a/source4/torture/libsmbclient/libsmbclient.c +++ b/source4/torture/libsmbclient/libsmbclient.c @@ -1473,6 +1473,98 @@ static bool torture_libsmbclient_getatr(struct torture_context *tctx) return true; } +static bool torture_libsmbclient_getxattr(struct torture_context *tctx) +{ + const char *smburl = torture_setting_string(tctx, "smburl", NULL); + int fhandle = -1; + SMBCCTX *ctx = NULL; + char *getxattr_name = NULL; + char value[4096]; + bool ok = false; + int ret = -1; + + 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); + + getxattr_name = talloc_asprintf(tctx, + "%s/getxattr", + smburl); + if (getxattr_name == NULL) { + torture_result(tctx, + TORTURE_FAIL, + __location__": %s", + "talloc fail\n"); + return false; + } + /* Ensure the file doesn't exist. */ + smbc_unlink(getxattr_name); + + /* Create testfile. */ + fhandle = smbc_creat(getxattr_name, 0666); + if (fhandle < 0) { + torture_fail_goto(tctx, + done, + talloc_asprintf(tctx, + "failed to create file '%s': %s", + getxattr_name, + strerror(errno))); + } + ret = smbc_close(fhandle); + torture_assert_int_equal_goto(tctx, + ret, + 0, + ok, + done, + talloc_asprintf(tctx, + "failed to close handle for '%s'", + getxattr_name)); + + /* + * Ensure getting a non-existent attribute returns -1. + */ + ret = smbc_getxattr(getxattr_name, "foobar", value, sizeof(value)); + torture_assert_int_equal_goto(tctx, + ret, + -1, + ok, + done, + talloc_asprintf(tctx, + "smbc_getxattr(foobar) on '%s' should " + "get -1, got %d\n", + getxattr_name, + ret)); + + /* + * Ensure getting a valid attribute returns 0. + */ + ret = smbc_getxattr(getxattr_name, "system.*", value, sizeof(value)); + torture_assert_int_equal_goto(tctx, + ret, + 0, + ok, + done, + talloc_asprintf(tctx, + "smbc_getxattr(foobar) on '%s' should " + "get -1, got %d\n", + getxattr_name, + ret)); + + ok = true; + + done: + + smbc_unlink(getxattr_name); + smbc_free_context(ctx, 1); + return ok; +} + NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx) { struct torture_suite *suite; @@ -1501,6 +1593,8 @@ NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx) torture_libsmbclient_rename); torture_suite_add_simple_test(suite, "getatr", torture_libsmbclient_getatr); + torture_suite_add_simple_test(suite, "getxattr", + torture_libsmbclient_getxattr); suite->description = talloc_strdup(suite, "libsmbclient interface tests"); -- 2.34.1 From aac48577658eeecc6b68973c90eff27b0176b3c8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 28 Oct 2022 15:31:39 -0700 Subject: [PATCH 2/2] s3: libsmbclient: Fix smbc_getxattr() to return 0 on success. Remove knownfail. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14808 Signed-off-by: Jeremy Allison Reviewed-by: David Mulder Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Tue Nov 1 18:31:22 UTC 2022 on sn-devel-184 (cherry picked from commit bdbb38d16c8eaff33484bb747efa639c4d8e7f35) --- selftest/knownfail.d/libsmbclient_getxattr | 1 - source3/libsmb/libsmb_xattr.c | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) delete mode 100644 selftest/knownfail.d/libsmbclient_getxattr diff --git a/selftest/knownfail.d/libsmbclient_getxattr b/selftest/knownfail.d/libsmbclient_getxattr deleted file mode 100644 index f27656f4ce4..00000000000 --- a/selftest/knownfail.d/libsmbclient_getxattr +++ /dev/null @@ -1 +0,0 @@ -^samba4.libsmbclient.getxattr.* diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c index e0e328a9a69..c8aa0743f54 100644 --- a/source3/libsmb/libsmb_xattr.c +++ b/source3/libsmb/libsmb_xattr.c @@ -2180,7 +2180,11 @@ SMBC_getxattr_ctx(SMBCCTX *context, errno = SMBC_errno(context, srv->cli); } TALLOC_FREE(frame); - return ret; + /* + * static function cacl_get returns a value greater than zero + * on success. Map this to zero meaning success. + */ + return ret < 0 ? -1 : 0; } /* Unsupported attribute name */ -- 2.34.1