From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id 88522385415B; Mon, 4 Jul 2022 23:05:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 88522385415B Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: implement getfacl(1) for socket files X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 1503d14af1472824322d8fa8a012173b3f27a733 X-Git-Newrev: 72f855f32b627e50fc232bbd798f6b99991ac68d Message-Id: <20220704230513.88522385415B@sourceware.org> Date: Mon, 4 Jul 2022 23:05:13 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jul 2022 23:05:13 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D72f855f32b6= 27e50fc232bbd798f6b99991ac68d commit 72f855f32b627e50fc232bbd798f6b99991ac68d Author: Ken Brown Date: Sat Jul 2 15:12:40 2022 -0400 Cygwin: implement getfacl(1) for socket files =20 Do this by defining the acl_get method for the fhandler_socket_local and fhandler_socket_unix classes. Also define acl_set for these classes. =20 Partially addresses: https://cygwin.com/pipermail/cygwin/2022-July/2517= 68.html Diff: --- winsup/cygwin/fhandler.h | 4 +++ winsup/cygwin/release/3.4.0 | 2 ++ winsup/cygwin/sec_posixacl.cc | 76 +++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 82 insertions(+) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index d5ec56a6d..cb5e08fa3 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -861,6 +861,8 @@ class fhandler_socket_local: public fhandler_socket_wso= ck int fchmod (mode_t newmode); int fchown (uid_t newuid, gid_t newgid); int facl (int, int, struct acl *); + struct __acl_t *acl_get (uint32_t); + int acl_set (struct __acl_t *, uint32_t); int link (const char *); =20 /* from here on: CLONING */ @@ -1143,6 +1145,8 @@ class fhandler_socket_unix : public fhandler_socket int fchmod (mode_t newmode); int fchown (uid_t newuid, gid_t newgid); int facl (int, int, struct acl *); + struct __acl_t *acl_get (uint32_t); + int acl_set (struct __acl_t *, uint32_t); int link (const char *); =20 /* select.cc */ diff --git a/winsup/cygwin/release/3.4.0 b/winsup/cygwin/release/3.4.0 index ff600deca..31b36dcfd 100644 --- a/winsup/cygwin/release/3.4.0 +++ b/winsup/cygwin/release/3.4.0 @@ -25,3 +25,5 @@ What changed: Bug Fixes --------- =20 +- Don't error out if getfacl(1) is called on a socket file. + Partially addresses: https://cygwin.com/pipermail/cygwin/2022-July/25176= 8.html diff --git a/winsup/cygwin/sec_posixacl.cc b/winsup/cygwin/sec_posixacl.cc index e7e5a9c3e..c2daa3309 100644 --- a/winsup/cygwin/sec_posixacl.cc +++ b/winsup/cygwin/sec_posixacl.cc @@ -633,6 +633,44 @@ fhandler_disk_file::acl_get (acl_type_t type) return acl; } =20 +acl_t +fhandler_socket_local::acl_get (acl_type_t type) +{ + if (!dev ().isfs ()) + /* acl_get_fd on a socket. */ + return fhandler_base::acl_get (type); + + /* acl_get_fd on a socket opened with O_PATH or acl_get_file on a + socket file. */ + if (get_flags () & O_PATH) + { + set_errno (EBADF); + return NULL; + } + fhandler_disk_file fh (pc); + return fh.acl_get (type); +} + +#ifdef __WITH_AF_UNIX +acl_t +fhandler_socket_unix::acl_get (acl_type_t type) +{ + if (!dev ().isfs ()) + /* acl_get_fd on a socket. */ + return fhandler_base::acl_get (type); + + /* acl_get_fd on a socket opened with O_PATH or acl_get_file on a + socket file. */ + if (get_flags () & O_PATH) + { + set_errno (EBADF); + return NULL; + } + fhandler_disk_file fh (pc); + return fh.acl_get (type); +} +#endif + extern "C" acl_t acl_get_fd (int fd) { @@ -765,6 +803,44 @@ fhandler_disk_file::acl_set (acl_t acl, acl_type_t typ= e) return ret; } =20 +int +fhandler_socket_local::acl_set (acl_t acl, acl_type_t type) +{ + if (!dev ().isfs ()) + /* acl_set_fd on a socket. */ + return fhandler_base::acl_set (acl, type); + + /* acl_set_fd on a socket opened with O_PATH or acl_set_file on a + socket file. */ + if (get_flags () & O_PATH) + { + set_errno (EBADF); + return -1; + } + fhandler_disk_file fh (pc); + return fh.acl_set (acl, type); +} + +#ifdef __WITH_AF_UNIX +int +fhandler_socket_unix::acl_set (acl_t acl, acl_type_t type) +{ + if (!dev ().isfs ()) + /* acl_set_fd on a socket. */ + return fhandler_base::acl_set (acl, type); + + /* acl_set_fd on a socket opened with O_PATH or acl_set_file on a + socket file. */ + if (get_flags () & O_PATH) + { + set_errno (EBADF); + return -1; + } + fhandler_disk_file fh (pc); + return fh.acl_set (acl, type); +} +#endif + extern "C" int acl_set_fd (int fd, acl_t acl) {