-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use faccessat instead of custom permission check
Unix.access uses RUID and RGID, which is not correct when doing a PATH-search. The faccessat function is able to check permissions using EUID and EGID instead. opam's hand-rolled check_permissions function is therefore replaced with a binding for faccessat. This simultaneously fixes two other things: - Platforms (such as Cygwin) which use ACLs no longer need special support, because their implementations of faccessat already take ACLs into account - We no longer use Unix.getgroups which means that we work around a problem with binaries built using musl libc and then used on systems where a user belongs to more than 32 groups (cf. https://www.openwall.com/lists/musl/2021/07/03/1)
- Loading branch information
1 parent
56ef9b6
commit b16317b
Showing
7 changed files
with
84 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/**************************************************************************/ | ||
/* */ | ||
/* Copyright 2024 Kate Deplaix */ | ||
/* */ | ||
/* All rights reserved. This file is distributed under the terms of the */ | ||
/* GNU Lesser General Public License version 2.1, with the special */ | ||
/* exception on linking described in the file LICENSE. */ | ||
/* */ | ||
/**************************************************************************/ | ||
|
||
/* Needed for the Windows string conversion functions on older OCaml */ | ||
#define CAML_INTERNALS | ||
|
||
#include <caml/mlvalues.h> | ||
#include <caml/alloc.h> | ||
#include <caml/memory.h> | ||
#include <caml/signals.h> | ||
#include <caml/osdeps.h> | ||
#include <caml/unixsupport.h> | ||
#include <caml/version.h> | ||
|
||
#ifndef _WIN32 | ||
|
||
#include <fcntl.h> | ||
#include <unistd.h> | ||
|
||
#else | ||
|
||
#include <io.h> | ||
|
||
/* mingw-w64 defines R_OK */ | ||
#ifndef R_OK | ||
#define R_OK 4 | ||
#endif | ||
|
||
#endif | ||
|
||
#if OCAML_VERSION < 50000 | ||
#define caml_unix_access unix_access | ||
#endif | ||
|
||
CAMLprim value opam_is_executable(value path) | ||
{ | ||
CAMLparam1(path); | ||
char_os * p; | ||
int ret; | ||
|
||
caml_unix_check_path(path, "faccessat"); | ||
p = caml_stat_strdup_to_os(String_val(path)); | ||
caml_enter_blocking_section(); | ||
#ifdef _WIN32 | ||
/* No execute bit on Windows */ | ||
ret = _waccess(p, R_OK); | ||
#else | ||
ret = faccessat(AT_FDCWD, p, X_OK, AT_EACCESS); | ||
#endif | ||
caml_leave_blocking_section(); | ||
caml_stat_free(p); | ||
CAMLreturn(Val_bool(ret == 0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters