Skip to content

Commit 1ab8e07

Browse files
authored
Merge pull request moby#3516 from gabriel-samfira/add-user-lookup-utility
[Windows] Add get-user-info utility
2 parents ec41bb8 + 24ceea7 commit 1ab8e07

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

cmd/buildkitd/main_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net"
99

1010
_ "github.com/moby/buildkit/solver/llbsolver/ops"
11+
_ "github.com/moby/buildkit/util/system/getuserinfo"
1112
"github.com/pkg/errors"
1213
)
1314

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package getuserinfo
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
8+
"golang.org/x/sys/windows"
9+
10+
"github.com/docker/docker/pkg/idtools"
11+
"github.com/docker/docker/pkg/reexec"
12+
)
13+
14+
const (
15+
getUserInfoCmd = "get-user-info"
16+
)
17+
18+
func init() {
19+
reexec.Register(getUserInfoCmd, userInfoMain)
20+
}
21+
22+
func userInfoMain() {
23+
if len(os.Args) != 2 {
24+
fmt.Println("Usage: get-user-info usernameOrGroup")
25+
os.Exit(1)
26+
}
27+
username := os.Args[1]
28+
sid, _, _, err := windows.LookupSID("", username)
29+
if err != nil {
30+
fmt.Println(err)
31+
os.Exit(3)
32+
}
33+
34+
ident := idtools.Identity{
35+
SID: sid.String(),
36+
}
37+
38+
asJson, err := json.Marshal(ident)
39+
if err != nil {
40+
fmt.Println(err)
41+
os.Exit(5)
42+
}
43+
fmt.Fprintf(os.Stdout, "%s", string(asJson))
44+
}

0 commit comments

Comments
 (0)