public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: SMBFS mount's file cannot be made executable
Date: Mon, 9 Dec 2024 12:11:56 +0100	[thread overview]
Message-ID: <Z1bQfIgv7MIDL1fB@calimero.vinschen.de> (raw)
In-Reply-To: <20241208081338.e097563889a03619fc467930@nifty.ne.jp>

On Dec  8 08:13, Takashi Yano via Cygwin wrote:
> On Tue, 19 Nov 2024 21:54:44 +0100
> Corinna Vinschen wrote:
> > No, we can't do that, it's too simple.
> > 
> > Just kidding.
> > 
> > This is so simple, I'm puzzled we never tried that before.  Or, if we
> > did, it's a loooong time ago...
> > 
> > If we really do this, we don't even need to call get_file_sd().  And it
> > should use NtOpenFile and reopen semantics i.e.  pc.init_reopen_attr().
> > Also, the sharing flags should allow all access.  And the `effective'
> > argument needs to be taken into account.
> 
> I have a question. What pc.init_reopen_attr() is for? I tested with
> pc.get_object_attr() instead, it works.

init_reopen_attr() uses the "open by handle" functionality as in the
Win32 API ReOpenFile().  It only does so if the filesystem supports it.
Samba usually does, so it's not clear to me why pc.init_reopen_attr()
fails for you.

> What handle should I pass to pc.init_reopen_attr()?

You could pass pc.handle().  Is pc.handle() in this scenario NULL,
perhaps?

> @@ -709,12 +615,44 @@ check_file_access (path_conv &pc, int flags, bool effective)
>      desired |= FILE_WRITE_DATA;
>    if (flags & X_OK)
>      desired |= FILE_EXECUTE;
> -  if (!get_file_sd (pc.handle (), pc, sd, false))
> +
> +  NTSTATUS status;
> +  if (!effective && cygheap->user.issetuid ())
> +    {
> +      /* Strip impersonation token temporarily */
> +      HANDLE tok = NO_IMPERSONATION;
> +      status = NtSetInformationThread (GetCurrentThread (),
> +				       ThreadImpersonationToken,
> +				       &tok, sizeof (tok));
> +      if (!NT_SUCCESS (status))
> +	{
> +	  debug_printf("NtSetInformationThread() for stripping "
> +		       "impersonation token failed: %y", status);
> +	  __seterrno_from_nt_status (status);
> +	  return ret;
> +	}
> +    }

You can simplify this:

	if (!effective)
	  cygheap->user.deimpersonate ();
   
> +  if (!effective && cygheap->user.issetuid ())
> +    {
> +      /* Recover impersonation token */
> +      HANDLE tok = cygheap->user.imp_token () ?: hProcImpToken;
> +      status = NtSetInformationThread (GetCurrentThread (),
> +				       ThreadImpersonationToken,
> +				       &tok, sizeof (tok));
> +      if (!NT_SUCCESS (status))
> +	debug_printf("NtSetInformationThread() for recovering "
> +		     "impersonation token failed: %y", status);
>      }

And this:

	if (!effective)
	  cygheap->user.reimpersonate ();

But please let's move to cygwin-patches for this.


Thanks,
Corinna

  parent reply	other threads:[~2024-12-09 11:11 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 15:42 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2024-11-08 11:51 ` Takashi Yano
2024-11-08 13:11   ` Corinna Vinschen
2024-11-11 10:31     ` Takashi Yano
2024-11-11 10:31       ` Takashi Yano via Cygwin
2024-11-11 10:56       ` Corinna Vinschen
2024-11-11 10:56         ` Corinna Vinschen via Cygwin
2024-11-11 11:19         ` Takashi Yano
2024-11-11 11:19           ` Takashi Yano via Cygwin
2024-11-11 11:32           ` Takashi Yano
2024-11-11 11:32             ` Takashi Yano via Cygwin
2024-11-11 11:40             ` Takashi Yano
2024-11-11 11:40               ` Takashi Yano via Cygwin
2024-11-11 12:03               ` Corinna Vinschen
2024-11-11 12:03                 ` Corinna Vinschen via Cygwin
2024-11-11 12:19                 ` Takashi Yano
2024-11-11 12:19                   ` Takashi Yano via Cygwin
2024-11-11 13:35                   ` Corinna Vinschen
2024-11-11 13:35                     ` Corinna Vinschen via Cygwin
2024-11-11 19:29                     ` Takashi Yano
2024-11-11 19:29                       ` Takashi Yano via Cygwin
2024-11-12  8:54                       ` Takashi Yano
2024-11-12 11:56                         ` Corinna Vinschen
2024-11-13  9:17                           ` Takashi Yano
2024-11-13 15:10                             ` Bill Stewart
2024-11-13 15:37                               ` Takashi Yano
2024-11-13 15:58                                 ` Bill Stewart
2024-11-13 16:08                                   ` Takashi Yano
2024-11-15 15:21                                     ` Takashi Yano
2024-11-18 16:26                                       ` Corinna Vinschen
2024-11-19  8:58                                         ` Takashi Yano
2024-11-19 20:54                                           ` Corinna Vinschen
2024-12-07 23:13                                             ` Takashi Yano
2024-12-08  7:57                                               ` Takashi Yano
2024-12-09 11:11                                               ` Corinna Vinschen [this message]
2024-11-12 11:31                       ` Corinna Vinschen
2024-11-11 11:51           ` Takashi Yano
2024-11-11 11:51             ` Takashi Yano via Cygwin
2024-11-11 11:59           ` Corinna Vinschen
2024-11-11 11:59             ` Corinna Vinschen via Cygwin
2024-11-11 12:25             ` Takashi Yano
2024-11-11 12:25               ` Takashi Yano via Cygwin
2024-11-11 13:00             ` Takashi Yano
2024-11-11 13:00               ` Takashi Yano via Cygwin
2024-11-11 13:18               ` Corinna Vinschen
2024-11-11 13:18                 ` Corinna Vinschen via Cygwin
2024-11-08 16:07   ` [EXTERNAL] " Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2024-11-11  9:04     ` Takashi Yano
2024-11-11  9:04       ` Takashi Yano via Cygwin
2019-08-12 19:05 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-13  8:28 ` KAVALAGIOS Panagiotis (EEAS-EXT)
     [not found] ` <704986a5a4ab41709eb963dcd23887b1@BELBRU-EXMP101.eeas.europa.eu>
2019-08-13 12:27   ` Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-13 18:34     ` Achim Gratz
2019-08-13 18:35     ` Andrey Repin
2019-08-13 23:19       ` Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-14 20:05         ` Andrey Repin
2019-08-14  0:53 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-14  2:36 ` Ken Brown
2019-08-14 16:59 ` Achim Gratz
2019-08-14  4:24 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-14 11:22 ` Ken Brown
2019-08-14 22:58   ` Brian Inglis
2019-08-14 14:07 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-15  1:28 ` Ken Brown
2019-08-14 20:39 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-15  1:31 ` Ken Brown
2019-08-15  1:40 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-15  2:59 ` Brian Inglis
2019-08-15  2:00 Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin
2019-08-15  9:21 ` L A Walsh
2019-08-15  9:23 ` L A Walsh
2019-08-21  7:12   ` Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z1bQfIgv7MIDL1fB@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).