4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-03-01 04:25:27 +08:00

22 Commits

Author SHA1 Message Date
Corinna Vinschen
dbd662300b Cygwin: seteuid: set errno if TranslateNameW fails
The call to TranslateNameW in s4uauth can fail and the code
leaves the function indicating an error, if so.  It just
misses to set errno in this case, so add that.

Fixes: 0fb497165f85 ("Cygwin: seteuid: use Kerberos/MsV1_0 S4U authentication by default")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-20 13:27:57 +01:00
Corinna Vinschen
25e5824fb1 Cygwin: get_posix_access: make sure pos is correctly set when used
The code merging permissions relies on `pos' being set to the number
of current entries in the local aclent_t buffer.  Commit 0e6d36766c83
("Cygwin: get_posix_access: move umask masking to the end") moved that
code to run earlier, but neglected to move setting `pos' correctly
as well.

Make sure to set `pos' inside the code block, as well as in the
final array size check, so `pos' is set correctly where it belongs.

Fixes: 0e6d36766c83 ("Cygwin: get_posix_access: move umask masking to the end")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 15:57:56 +01:00
Corinna Vinschen
a6bc726adf Cygwin: get_posix_access: initalize obj_idx
This fixes a false positive gcc warning.

Fixes: 01c9386fd805 ("Cygwin: get_posix_access: improve merging permissions")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 15:50:29 +01:00
Corinna Vinschen
0e6d36766c Cygwin: get_posix_access: move umask masking to the end
umask handling for new file gets overriden by subsequent merging of
permissions in Windows-generated ACLs.  Fix this by performing
umask masking after all other ACL manipulations.

Fixes: a8716448cecc ("Simplify "Windows-standard-like" permissions")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
01c9386fd8 Cygwin: get_posix_access: improve merging permissions
Add a second loop to the code snippet merging permissions in old-style
or Windows-generated ACLs.  This loop fixes up default ACL permissions
created from ACEs which are valid for the directory itself, as well as
getting inherited to child objects.

The FULL_ACE bit utilized for this is removed from the ACE at the
end of the function, together with the temporary DENY bits.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
a785d996c9 Revert "Cygwin: get_posix_access: do not merge permissions for just created files"
This reverts commit 971d2dffea7848270aa9dfb5c14dcd946c8971c0.

This patch was supposed to fix lots of FAILs in our own
testsuite/winsup.api/ltp/umask03.c test.  The reason was
that umask masking in get_posix_access when generating new files
was overriden by later code in the same function, merging
permissions in old-style or Windows generated ACLs.

However, the solution to skip merging was not the right thing,
because this breaks handling of Windows-generated ACLs.

Rather, umask masking should be performed pretty late, certainly
after merging permissions.  This will be done by a followup patch.

Fixes: 971d2dffea78 ("Cygwin: get_posix_access: do not merge permissions for just created files")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
3858f07dd8 Cygwin: get_posix_access: fix id in default:user and default:group entry
Setting the a_id in the default:user and default:group entries to
the actual uid and gid of the current owner/group doesn't make
sense.  Change to ACL_UNDEFINED_ID.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
a238211828 Cygwin: get_posix_access: don't drop admin and system perms in default ACL
The permissions of entries for SYSTEM and the Administrators group
are not added to the CLASS_OBJ entry, so they don't set the class
perms to rwx all the time.

This shouldn't be done for default perms, otherwise the resulting
permissions when generating new files might be surprisingly restricted
for Admins and SYSTEM.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
97c3835a03 Cygwin: get_posix_access: accomodate owner==group in default:group perms
When generating a default:group (Windows: CREATOR GROUP) ACL entry,
make sure to copy over user perms to the new default group entry.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:03 +01:00
Corinna Vinschen
662fc09013 Cygwin: get_posix_access: drop stray increment instruction
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:27:02 +01:00
Corinna Vinschen
8695b3a176 Cygwin: get_posix_access: Use correct type for local id variable
it's an id_t, not an int.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:26:53 +01:00
Corinna Vinschen
a1aa7462cd Cygwin: security.h: De-inline cygpsid::debug_print
This allows to use the function from GDB during debugging.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-15 12:26:53 +01:00
Corinna Vinschen
2e4db338ac Cygwin: access: Fix X_OK behaviour for backup operators and admins
After commit a0933cd17d19, access(_, X_OK) returns 0 if the user
holds SE_BACKUP_PRIVILEGE, even if the file's ACL denies execution
to the user.  This is triggered by trying to open the file with
FILE_OPEN_FOR_BACKUP_INTENT.

Fix check_file_access() so it checks for X_OK without specifying
the FILE_OPEN_FOR_BACKUP_INTENT flag if the file is not a directory.

Rearrange function slightly and add comments for easier comprehension.

Fixes: a0933cd17d19 ("Cygwin: access: Correction for samba/SMB share")
Reported-by: Bruno Haible <bruno@clisp.org>
Co-authored-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2025-01-08 16:13:14 +01:00
Takashi Yano
a0933cd17d Cygwin: access: Correction for samba/SMB share
Previously, access() and eaccess() does not determine the permissions
for files on samba/SMB share correctly. Even if the user logs-in as
the owner of the file, access() and eaccess() referes to others'
permissions. With this patch, to determine the permissions correctly,
NtOpenFile() with desired access mask is used.

Fixes: cf762b08cfb0 ("* security.cc (check_file_access): Create.")
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-12-11 07:32:22 +09:00
Corinna Vinschen
815eba882e Cygwin: path_conv: allow NULL handle in init_reopen_attr()
init_reopen_attr() doesn't guard against a NULL handle.  However,
there are scenarios calling functions deliberately with a NULL handle,
for instance, av::setup() calling check_file_access() only if opening
the file did NOT succeed.

So check for a NULL handle in init_reopen_attr() and if so, use the
name based approach filling the OBJECT_ATTRIBUTES struct, just as in
the has_buggy_reopen() case.

Fixes: 4c9d01fdad2a ("* mount.h (class fs_info): Add has_buggy_reopen flag and accessor methods.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-12-10 16:50:11 +01:00
Corinna Vinschen
1719169604 Cygwin: (mostly) drop NT4 and Samba < 3.0 support
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-20 12:31:50 +01:00
Corinna Vinschen
2100c6ef0d Cygwin: get/set security descriptors using FILE_OPEN_NO_RECALL
Add FILE_OPEN_NO_RECALL to NtOpenFile calls trying to fetch
or write file security descriptors so as not to recall them
from offline storage inadvertently.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-03-08 21:30:57 +01:00
Corinna Vinschen
971d2dffea Cygwin: get_posix_access: do not merge permissions for just created files
When creating the POSIX ACL rewrite, the code merging permissions from
everyone/group to group/user ACEs was accidentally called for newly
generated files as well.

This could result in broken permissions, if umask used unusual values
like "0100", granted permissions to everyone/group not granted to
group/user.

Make sure to skip permission merging if the file got just created and
we only want to set correct permissions for the first time.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Reported-by: Jon Turney <jon.turney@dronecode.org.uk>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-07-21 21:57:44 +02:00
Corinna Vinschen
498fce80ef Cygwin: get_posix_access: Make mode_t parameter mandatory
Avoid the mistake fixed in the preceeding commit by passing
the mode_t argument by reference.  This also affects a couple
other functions calling get_posix_access in turn.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL changes.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-09 21:58:44 +01:00
Corinna Vinschen
283583c5f2 Cygwin: mkdir: use correct default permissions filtered by umask
Older coreutils created directories with mode bits filtered through
umask.  Newer coreutils creates directories with full permissions,
0777 by default.

This new coreutils behaviour uncovered the fact that default ACEs for
newly created directories were not filtered by umask starting with
commit bc444e5aa4ca.

Fix it by applying umask on the default ACEs.

Fixes: bc444e5aa4ca ("Reapply POSIX ACL change.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2023-02-09 21:58:07 +01:00
Corinna Vinschen
2e03e5a040 Cygwin: authz: Use dedicated locks per datastructure
So far we use a single muto to guard three different datastructures
inside class authz_ctx: the authz HANDLE, the user context HANDLE
and the context cache list.  Split the single muto into three
independent SRWLOCKs and guard all datastrcutures as necessary to
avoid thread contention.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-22 14:25:05 +02:00
Corinna Vinschen
007e23d639 Cygwin: Reorganize cygwin source dir
Create subdirs and move files accordingly:

- DevDocs:  doc files
- fhandler: fhandler sources, split fhandler.cc into base.cc and null.cc
- local_includes: local include files
- scripts:  scripts called during build
- sec:      security sources

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-08-05 12:02:11 +02:00