Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run with internal flag when saving with sudo on Windows #3578

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

niten94
Copy link
Contributor

@niten94 niten94 commented Dec 16, 2024

The description of this pull request is written to try to summarize few details mentioned in #3541 and add others that have been found. Feedback, questions and suggestions are appreciated even if they are decided without too much thought or details cannot be understood well.

PowerShell is the only program available by default on Windows that can be used to write data in standard input to a file in place of dd, but a long script with around 10 lines has to be used when using PowerShell. Due to this, the command is changed to run micro itself with a new internal flag when saving using sudo on Windows.

Using ShellExecute in micro was mentioned in #3541 but data cannot be written to the standard input of the process started. Running micro itself with an internal flag may be the least worst method but there are no programs I know that temporarily retrieve permissions, so I cannot check if the method is considered fine.

I was saving C:\test.txt with ファイル内容 as content in ms932/shift_jis encoding when testing. There should be no text corruption when running micro again with micro -encoding ms932 C:\test.txt after file is saved. All programs below except runas worked and were checked if specifying arguments in sucmd has to be supported:

  • runas
    • available by default in Windows 2000 and newer but standard input was read as password when I tested
    • user to run command as needs to be specified
    • command and arguments are specified in one string
  • Sudo for Windows
    • source code is on GitHub but there is no page with official builds
    • can be enabled on settings in Windows 11
  • gsudo
    • seems to be known when searching programs like sudo on Windows
    • wrapper with sudo name can be added using installer
    • TokenSwitch mode is the current default mode but saving with sudo only worked when using TokenSwitch mode
      • .NET objects used in the code of other modes probably handle data in standard input as text

Closes #3541

@niten94 niten94 changed the title Save using PowerShell script when using sudo on Windows Run with internal flag when saving with sudo on Windows Dec 18, 2024
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.

[Feature Request] Add Sudo Support on Windows
1 participant