-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Windows] Add get-user-info utility #3516
Merged
crazy-max
merged 2 commits into
moby:master
from
gabriel-samfira:add-user-lookup-utility
Jan 30, 2023
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,47 @@ | ||||||
package getuserinfo | ||||||
|
||||||
import ( | ||||||
"encoding/json" | ||||||
"fmt" | ||||||
"os" | ||||||
"syscall" | ||||||
|
||||||
"github.com/docker/docker/pkg/idtools" | ||||||
"github.com/docker/docker/pkg/reexec" | ||||||
) | ||||||
|
||||||
const ( | ||||||
getUserInfoCmd = "get-user-info" | ||||||
) | ||||||
|
||||||
func init() { | ||||||
reexec.Register(getUserInfoCmd, userInfoMain) | ||||||
} | ||||||
|
||||||
func userInfoMain() { | ||||||
if len(os.Args) != 2 { | ||||||
fmt.Println("Usage: get-user-info usernameOrGroup") | ||||||
os.Exit(1) | ||||||
} | ||||||
username := os.Args[1] | ||||||
sid, _, _, err := syscall.LookupSID("", username) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if err != nil { | ||||||
fmt.Println(err) | ||||||
os.Exit(3) | ||||||
} | ||||||
|
||||||
sidAsString, err := sid.String() | ||||||
if err != nil { | ||||||
fmt.Println(err) | ||||||
os.Exit(4) | ||||||
} | ||||||
ident := idtools.Identity{ | ||||||
SID: sidAsString, | ||||||
} | ||||||
asJson, err := json.Marshal(ident) | ||||||
if err != nil { | ||||||
fmt.Println(err) | ||||||
os.Exit(5) | ||||||
} | ||||||
fmt.Fprintf(os.Stdout, "%s", string(asJson)) | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use
"golang.org/x/sys/windows"
instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x/sys
is where new stuff gets added. Thesyscall
package only changes when those changes need to support the standard library.The
LookupSID()
function from thesyscall
package is identical to the one inx/sys/windows
, and calls into a stable Windows API which, judging by Microsofts track record for backwards compatibility, will probably remain unchanged for many many years.Unless we want to use an old version of
go
that does not have this function in the standard library, I think we can usesyscall
.If you prefer, I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are already using this pkg
buildkit/session/sshforward/sshprovider/agentprovider_windows.go
Line 13 in c3eddbf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My recollection of a discussion in the go-winio repo was that we were leaning towards preferring
x/sys/windows
oversyscall
where possible. I have a PR there for example which replaces all uses ofsyscall
withx/sys/windows
versions.Which I would like to come back to at some point; it was delayed because there was a
syscall.Handle
in a public API being changed towindows.Handle
and they wanted to batch that up some other API breaks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it's settled. Will replace with
x/sys/windows
ASAP.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record, the PR and discussion I mentioned is microsoft/go-winio#197.