diff --git a/MODULE.bazel b/MODULE.bazel index 8e687088a..7fd1396eb 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -136,20 +136,6 @@ register_toolchains( deb = use_repo_rule("@download_utils//download/deb:defs.bzl", "download_deb") -deb( - name = "acl-deb", - build = "//third_party/acl:acl.BUILD", - urls = ["https://archive.ubuntu.com/ubuntu/pool/main/a/acl/libacl1-dev_2.2.52-3build1_amd64.deb"], - visibility = ["//visibility:public"], -) - -deb( - name = "acl-deb-aarch64", - build = "//third_party/acl:acl.BUILD", - urls = ["https://ports.ubuntu.com/ubuntu-ports/pool/main/a/acl/libacl1-dev_2.2.52-3build1_arm64.deb"], - visibility = ["//visibility:public"], -) - deb( name = "valgrind-deb", build = "//third_party/valgrind:valgrind.BUILD", @@ -183,6 +169,26 @@ deb( visibility = ["//visibility:public"], ) +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "bazel_attr", + build_file = "//third_party/attr:attr.BUILD", + patch_args = ["-p1"], + patches = ["//third_party/attr:attr.patch"], + strip_prefix = "attr-2.5.2", + urls = ["https://download.savannah.gnu.org/releases/attr/attr-2.5.2.tar.gz"], +) + +http_archive( + name = "bazel_acl", + build_file = "//third_party/acl:acl.BUILD", + patch_args = ["-p1"], + patches = ["//third_party/acl:acl.patch"], + strip_prefix = "acl-2.3.2", + urls = ["https://download.savannah.gnu.org/releases/acl/acl-2.3.2.tar.gz"], +) + bazel_dep(name = "flatbuffers", version = "25.12.19") bazel_dep(name = "nlohmann_json", version = "3.11.3") bazel_dep(name = "bazel_skylib", version = "1.9.0") diff --git a/score/os/acl_impl.cpp b/score/os/acl_impl.cpp index 31b08c738..4cf514145 100644 --- a/score/os/acl_impl.cpp +++ b/score/os/acl_impl.cpp @@ -400,11 +400,18 @@ score::cpp::expected AclInstance::acl_to_text(const Acl ssize_t* const len_p) const noexcept /* KW_SUPPRESS_END:MISRA.VAR.HIDDEN:Wrapper function is identifiable through namespace usage */ { + if ((acl == nullptr) || (len_p == nullptr)) + { + errno = EINVAL; + return score::cpp::make_unexpected(score::os::Error::createFromErrno()); + } + auto* const acl_text = ::acl_to_text(acl, len_p); if (acl_text == nullptr) { return score::cpp::make_unexpected(score::os::Error::createFromErrno()); } + return acl_text; } diff --git a/score/os/test/acl_test.cpp b/score/os/test/acl_test.cpp index 1aae50239..fb69755cd 100644 --- a/score/os/test/acl_test.cpp +++ b/score/os/test/acl_test.cpp @@ -242,15 +242,14 @@ TEST_F(AclTestFixture, AclToTextToReturnErrorIfPassInvalidAcl) RecordProperty("Verifies", "SCR-46010294"); RecordProperty("ASIL", "QM"); RecordProperty("Description", "ACL shall return error if pass invalid ACL"); - RecordProperty("TestType", "requirements-based"); // requirements test - RecordProperty("DerivationTechnique", "requirements-analysis"); // requirements + RecordProperty("TestType", "requirements-based"); + RecordProperty("DerivationTechnique", "requirements-analysis"); - auto* result = ::acl_get_file("", ACL_TYPE_ACCESS); ssize_t len{0}; - auto res = unit_.acl_to_text(result, &len); - ASSERT_FALSE(res.has_value()); - ::acl_free(result); + auto res = unit_.acl_to_text(nullptr, &len); + + ASSERT_FALSE(res.has_value()); } // Test to set fd return error if invalid parameters are passed diff --git a/third_party/acl/BUILD b/third_party/acl/BUILD index fa7b7c013..174b4ffcb 100644 --- a/third_party/acl/BUILD +++ b/third_party/acl/BUILD @@ -13,9 +13,6 @@ alias( name = "acl", - actual = select({ - "@platforms//cpu:aarch64": "@acl-deb-aarch64//:acl", - "//conditions:default": "@acl-deb//:acl", - }), + actual = "@bazel_acl//:acl", visibility = ["//:__subpackages__"], ) diff --git a/third_party/acl/acl.BUILD b/third_party/acl/acl.BUILD index cc0ddef4d..3eab31f47 100644 --- a/third_party/acl/acl.BUILD +++ b/third_party/acl/acl.BUILD @@ -1,5 +1,5 @@ # ******************************************************************************* -# Copyright (c) 2025 Contributors to the Eclipse Foundation +# Copyright (c) 2026 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -11,18 +11,78 @@ # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* +""" Bazel BUILD file for the ACL library. +""" + load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( - name = "acl", - srcs = select({ - "@platforms//cpu:aarch64": ["usr/lib/libacl.a"], - "@platforms//cpu:x86_64": ["usr/lib/libacl.a"], + name = "config", + hdrs = select({ + "@platforms//os:linux": ["bazel/configs/linux/config.h"], + }), + strip_include_prefix = select({ + "@platforms//os:linux": "bazel/configs/linux", }), +) + +cc_library( + name = "acl_h", + hdrs = ["include/acl.h"], + copts = [ + '-DEXPORT=__attribute__((visibility("default"))) extern', + ], + include_prefix = "sys", + includes = ["include"], + strip_include_prefix = "include", +) + +cc_library( + name = "libacl_h", + hdrs = ["include/libacl.h"], + include_prefix = "acl", + includes = ["include"], + strip_include_prefix = "include", +) + +cc_library( + name = "includes", hdrs = [ - "usr/include/acl/libacl.h", - "usr/include/sys/acl.h", + "include/acl_ea.h", + "include/misc.h", + "include/walk_tree.h", + ], + includes = ["include"], +) + +cc_library( + name = "acl", + srcs = glob(["libacl/*c"]) + [ + "libmisc/high_water_alloc.c", + "libmisc/next_line.c", + "libmisc/quote.c", + "libmisc/uid_gid_lookup.c", + "libmisc/unquote.c", + "libmisc/walk_tree.c", ], - includes = ["usr/include/"], + hdrs = glob(["libacl/*h"]), + copts = [ + "-include libacl/perm_copy.h", + "-include", + "config.h", + "-Wno-error=missing-prototypes", + "-Wno-error=cast-qual", + "-Wno-error=int-conversion", + "-Wno-error=implicit-function-declaration", + ], + includes = ["libacl"], + linkstatic = True, visibility = ["//visibility:public"], + deps = [ + ":acl_h", + ":config", + ":includes", + ":libacl_h", + "@bazel_attr//:attr", + ], ) diff --git a/third_party/acl/acl.patch b/third_party/acl/acl.patch new file mode 100644 index 000000000..9cca2df09 --- /dev/null +++ b/third_party/acl/acl.patch @@ -0,0 +1,83 @@ +diff --git a/bazel/configs/linux/config.h b/bazel/configs/linux/config.h +new file mode 100644 +index 0000000..e7c5ff6 +--- /dev/null ++++ b/bazel/configs/linux/config.h +@@ -0,0 +1,41 @@ ++#ifndef ACL_CONFIG_H ++#define ACL_CONFIG_H ++ ++#define HAVE_CONFIG_H 1 ++ ++#define PACKAGE "acl" ++#define PACKAGE_NAME "acl" ++#define PACKAGE_VERSION "2.3.2" ++#define VERSION "2.3.2" ++ ++/* Headers */ ++#define HAVE_ERRNO_H 1 ++#define HAVE_FCNTL_H 1 ++#define HAVE_LIMITS_H 1 ++#define HAVE_STDARG_H 1 ++#define HAVE_STDDEF_H 1 ++#define HAVE_STDINT_H 1 ++#define HAVE_STDLIB_H 1 ++#define HAVE_STRING_H 1 ++#define HAVE_SYS_ACL_H 1 ++#define HAVE_SYS_STAT_H 1 ++#define HAVE_SYS_TYPES_H 1 ++#define HAVE_UNISTD_H 1 ++ ++/* Functions */ ++#define HAVE_FCHMOD 1 ++#define HAVE_FCHOWN 1 ++#define HAVE_GETXATTR 1 ++#define HAVE_FGETXATTR 1 ++#define HAVE_SETXATTR 1 ++#define HAVE_FSETXATTR 1 ++#define HAVE_LISTXATTR 1 ++#define HAVE_FLISTXATTR 1 ++#define HAVE_REMOVEXATTR 1 ++#define HAVE_FREMOVEXATTR 1 ++ ++/* Linux behavior */ ++#define HAVE_VISIBILITY_ATTRIBUTE 1 ++#define EXPORT __attribute__ ((visibility ("default"))) extern ++ ++#endif /* ACL_CONFIG_H */ +diff --git a/include/acl.h b/include/acl.h +index 710bf31..4edc471 100644 +--- a/include/acl.h ++++ b/include/acl.h +@@ -21,6 +21,7 @@ + #define __SYS_ACL_H + + #include ++#include "config.h" + + #ifdef __cplusplus + extern "C" { +diff --git a/libacl/acl_get_fd.c b/libacl/acl_get_fd.c +index 089ec79..ff930ca 100644 +--- a/libacl/acl_get_fd.c ++++ b/libacl/acl_get_fd.c +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + #include "libacl.h" + #include "__acl_from_xattr.h" + +diff --git a/libacl/acl_get_file.c b/libacl/acl_get_file.c +index 4a86d1a..f062bf2 100644 +--- a/libacl/acl_get_file.c ++++ b/libacl/acl_get_file.c +@@ -19,6 +19,7 @@ + */ + + #include "config.h" ++#include + #include + #include + #include diff --git a/third_party/attr/BUILD b/third_party/attr/BUILD new file mode 100644 index 000000000..7942eaaa9 --- /dev/null +++ b/third_party/attr/BUILD @@ -0,0 +1,18 @@ +# ******************************************************************************* +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +alias( + name = "attr", + actual = "@bazel_attr//:attr", + visibility = ["//:__subpackages__"], +) diff --git a/third_party/attr/attr.BUILD b/third_party/attr/attr.BUILD new file mode 100644 index 000000000..1a01e5dea --- /dev/null +++ b/third_party/attr/attr.BUILD @@ -0,0 +1,77 @@ +# ******************************************************************************* +# Copyright (c) 2026 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +""" The BUILD file for the bazel_attr module. This module provides a C library for + extended attributes (xattr) on Linux. It includes a configuration header and + the source files for the library. The library is built as a static library and + is visible to other modules. The configuration header is selected based on the + platform, and the library depends on the platforms and rules_cc modules. +""" + +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "config", + hdrs = select({ + "@platforms//os:linux": ["bazel/configs/linux/config.h"], + }), + strip_include_prefix = select({ + "@platforms//os:linux": "bazel/configs/linux", + }), +) + +cc_library( + name = "attr_h", + hdrs = [ + "include/attributes.h", + "include/libattr.h", + ], + include_prefix = "attr", + includes = ["include"], + strip_include_prefix = "include", +) + +cc_library( + name = "includes", + hdrs = [ + "include/error_context.h", + "include/misc.h", + "include/nls.h", + "include/walk_tree.h", + ], + includes = ["include"], +) + +cc_library( + name = "attr", + srcs = [ + "libattr/libattr.c", + ], + hdrs = [ + "libattr/libattr.h", + ], + copts = [ + "-DSYSCONFDIR=\\\"$(location :xattr.conf)\\\"", + "-Wno-error=cast-qual", + "-Wno-error=missing-prototypes", + ], + data = [":xattr.conf"], + includes = ["libattr"], + linkstatic = True, + visibility = ["//visibility:public"], + deps = [ + ":attr_h", + ":config", + ":includes", + ], +) diff --git a/third_party/attr/attr.patch b/third_party/attr/attr.patch new file mode 100644 index 000000000..97d2be02d --- /dev/null +++ b/third_party/attr/attr.patch @@ -0,0 +1,54 @@ +diff --git a/bazel/configs/linux/config.h b/bazel/configs/linux/config.h +new file mode 100644 +index 0000000..a0dac0e +--- /dev/null ++++ b/bazel/configs/linux/config.h +@@ -0,0 +1,47 @@ ++ ++ ++#ifndef ATTR_CONFIG_H ++#define ATTR_CONFIG_H ++ ++#define HAVE_CONFIG_H 1 ++ ++#define PACKAGE "attr" ++#define PACKAGE_NAME "attr" ++#define PACKAGE_VERSION "2.5.2" ++#define VERSION "2.5.2" ++ ++/* Headers */ ++#define HAVE_ERRNO_H 1 ++#define HAVE_FCNTL_H 1 ++#define HAVE_LIMITS_H 1 ++#define HAVE_STDDEF_H 1 ++#define HAVE_STDINT_H 1 ++#define HAVE_STDLIB_H 1 ++#define HAVE_STRING_H 1 ++#define HAVE_SYS_STAT_H 1 ++#define HAVE_SYS_TYPES_H 1 ++#define HAVE_SYS_XATTR_H 1 ++#define HAVE_UNISTD_H 1 ++ ++/* Functions */ ++#define HAVE_GETXATTR 1 ++#define HAVE_LGETXATTR 1 ++#define HAVE_FGETXATTR 1 ++ ++#define HAVE_SETXATTR 1 ++#define HAVE_LSETXATTR 1 ++#define HAVE_FSETXATTR 1 ++ ++#define HAVE_LISTXATTR 1 ++#define HAVE_LLISTXATTR 1 ++#define HAVE_FLISTXATTR 1 ++ ++#define HAVE_REMOVEXATTR 1 ++#define HAVE_LREMOVEXATTR 1 ++#define HAVE_FREMOVEXATTR 1 ++ ++/* Linux behavior */ ++#define HAVE_VISIBILITY_ATTRIBUTE 1 ++#define EXPORT __attribute__ ((visibility ("default"))) extern ++ ++#endif /* ATTR_CONFIG_H */ +\ No newline at end of file