Skip to content

Add new config option to support thread token based agent process to …#133

Open
masatma wants to merge 2 commits intorprichard:masterfrom
masatma:master
Open

Add new config option to support thread token based agent process to …#133
masatma wants to merge 2 commits intorprichard:masterfrom
masatma:master

Conversation

@masatma
Copy link
Copy Markdown

@masatma masatma commented Nov 10, 2017

Create agent proces from the thread token instead of current process. This is usefull when winpty.dll is called by Windows Service program to impersonate to the original user from a remote process.

…start

- Create agent proces from the thread token instead of current process. This is usefull when winpty.dll is called by Windows Service program to impersonate to the original user from a remote process.
Copy link
Copy Markdown
Owner

@rprichard rprichard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this change seems basically OK.

Comment thread src/include/winpty_constants.h Outdated
* See https://github.com/rprichard/winpty/issues/58. */
#define WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION 0x8ull

/* Create agent proces from the thread token instead of current process.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/proces/process

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread src/include/winpty_constants.h Outdated
#define WINPTY_FLAG_ALLOW_CURPROC_DESKTOP_CREATION 0x8ull

/* Create agent proces from the thread token instead of current process.
* This is usefull when winpty.dll is called by Windows Service program to
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/usefull/useful

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread src/libwinpty/winpty.cc
&sui,
&pi);
if (!success) {
CloseHandle(token);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this code use RAII (i.e. OwnedHandle), but I can fix that up myself after merging the change.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left as is.

Comment thread src/libwinpty/winpty.cc Outdated
nullptr,
nullptr,
FALSE,
CREATE_DEFAULT_ERROR_MODE | CREATE_BREAKAWAY_FROM_JOB | CREATE_UNICODE_ENVIRONMENT | NORMAL_PRIORITY_CLASS,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about these creation flags.

  • startAgentProcess is already called with a creation flags parameter, which is currently only set to either DETACHED_PROCESS (for --create-desktop) or CREATE_NEW_CONSOLE (normal code path). This code doesn't ever use CREATE_NEW_CONSOLE, so I assume it reuses its parent's console, if it has one?
  • Regarding the specific flags:
    • CREATE_DEFAULT_ERROR_MODE: I wonder if this ought to be the default behavior for winpty -- there was a complaint a while ago about crash handling and winpty (When run in Terminal a programs unhandled exceptions don't produce debug dialog in win32  microsoft/vscode#32134), but I never looked into it. Maybe this creation flag fixes the problem?
    • CREATE_UNICODE_ENVIRONMENT: lpEnvironment is null; does this do anything?
    • CREATE_BREAKAWAY_FROM_JOB and NORMAL_PRIORITY_CLASS: I wonder if these flags should really be set by WINPTY_FLAG_IMPERSONATE_THREAD or whether they're orthogonal settings. Maybe winpty needs a way to specify arbitrary creation flags for the agent and/or the agent's child?

@masatma
Copy link
Copy Markdown
Author

masatma commented Mar 23, 2018

can you push this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants