[sys] windows: add CreateProcessAsUser

131 views
Skip to first unread message

Jason A. Donenfeld (Gerrit)

unread,
May 25, 2021, 10:19:05 AM5/25/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Jason A. Donenfeld has uploaded this change for review.

View Change

windows: add CreateProcessAsUser

The syscall package already has this, but this one does not, so add this
simple companion to CreateProcess.

Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
---
M windows/syscall_windows.go
M windows/zsyscall_windows.go
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
index bb6aaf8..7d7d351 100644
--- a/windows/syscall_windows.go
+++ b/windows/syscall_windows.go
@@ -220,6 +220,7 @@
//sys CancelIo(s Handle) (err error)
//sys CancelIoEx(s Handle, o *Overlapped) (err error)
//sys CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) = CreateProcessW
+//sys CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) = CreateProcessAsUserW
//sys initializeProcThreadAttributeList(attrlist *ProcThreadAttributeList, attrcount uint32, flags uint32, size *uintptr) (err error) = InitializeProcThreadAttributeList
//sys deleteProcThreadAttributeList(attrlist *ProcThreadAttributeList) = DeleteProcThreadAttributeList
//sys updateProcThreadAttribute(attrlist *ProcThreadAttributeList, flags uint32, attr uintptr, value unsafe.Pointer, size uintptr, prevvalue unsafe.Pointer, returnedsize *uintptr) (err error) = UpdateProcThreadAttribute
diff --git a/windows/zsyscall_windows.go b/windows/zsyscall_windows.go
index 559bc84..86989b5 100644
--- a/windows/zsyscall_windows.go
+++ b/windows/zsyscall_windows.go
@@ -185,6 +185,7 @@
procCreateMutexW = modkernel32.NewProc("CreateMutexW")
procCreateNamedPipeW = modkernel32.NewProc("CreateNamedPipeW")
procCreatePipe = modkernel32.NewProc("CreatePipe")
+ procCreateProcessAsUserW = modkernel32.NewProc("CreateProcessAsUserW")
procCreateProcessW = modkernel32.NewProc("CreateProcessW")
procCreateSymbolicLinkW = modkernel32.NewProc("CreateSymbolicLinkW")
procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
@@ -1577,6 +1578,18 @@
return
}

+func CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
+ var _p0 uint32
+ if inheritHandles {
+ _p0 = 1
+ }
+ r1, _, e1 := syscall.Syscall12(procCreateProcessAsUserW.Addr(), 11, uintptr(token), uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0)
+ if r1 == 0 {
+ err = errnoErr(e1)
+ }
+ return
+}
+
func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
var _p0 uint32
if inheritHandles {

To view, visit change 322489. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sys
Gerrit-Branch: master
Gerrit-Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
Gerrit-Change-Number: 322489
Gerrit-PatchSet: 1
Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
Gerrit-MessageType: newchange

Jason A. Donenfeld (Gerrit)

unread,
May 25, 2021, 10:19:16 AM5/25/21
to goph...@pubsubhelper.golang.org, Alex Brainman, Brad Fitzpatrick, golang-co...@googlegroups.com

Attention is currently required from: Alex Brainman, Brad Fitzpatrick.

Patch set 1:Run-TryBot +1Trust +1

View Change

    To view, visit change 322489. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
    Gerrit-Change-Number: 322489
    Gerrit-PatchSet: 1
    Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Jason A. Donenfeld <Ja...@zx2c4.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Attention: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Comment-Date: Tue, 25 May 2021 14:19:12 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Brad Fitzpatrick (Gerrit)

    unread,
    May 25, 2021, 10:23:06 AM5/25/21
    to Jason A. Donenfeld, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Go Bot, Alex Brainman, golang-co...@googlegroups.com

    Attention is currently required from: Jason A. Donenfeld, Alex Brainman.

    Patch set 1:Code-Review +2Trust +1

    View Change

    1 comment:

    • Patchset:

      • Patch Set #1:

        random tab character midline in the first file. otherwise LGTM.

    To view, visit change 322489. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
    Gerrit-Change-Number: 322489
    Gerrit-PatchSet: 1
    Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Jason A. Donenfeld <Ja...@zx2c4.com>
    Gerrit-Attention: Jason A. Donenfeld <Ja...@zx2c4.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Comment-Date: Tue, 25 May 2021 14:23:03 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Jason A. Donenfeld (Gerrit)

    unread,
    May 25, 2021, 10:27:54 AM5/25/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Jason A. Donenfeld, Alex Brainman.

    Jason A. Donenfeld uploaded patch set #2 to this change.

    View Change

    windows: add CreateProcessAsUser

    The syscall package already has this, but this one does not, so add this
    simple companion to CreateProcess.

    Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
    ---
    M windows/syscall_windows.go
    M windows/zsyscall_windows.go
    2 files changed, 14 insertions(+), 0 deletions(-)

    To view, visit change 322489. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: sys
    Gerrit-Branch: master
    Gerrit-Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
    Gerrit-Change-Number: 322489
    Gerrit-PatchSet: 2
    Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
    Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Jason A. Donenfeld <Ja...@zx2c4.com>
    Gerrit-Attention: Jason A. Donenfeld <Ja...@zx2c4.com>
    Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
    Gerrit-MessageType: newpatchset

    Jason A. Donenfeld (Gerrit)

    unread,
    May 25, 2021, 10:28:58 AM5/25/21
    to goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Go Bot, Alex Brainman, golang-co...@googlegroups.com

    Attention is currently required from: Alex Brainman.

    Patch set 2:Run-TryBot +1Trust +1

    View Change

      To view, visit change 322489. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
      Gerrit-Change-Number: 322489
      Gerrit-PatchSet: 2
      Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-Attention: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Comment-Date: Tue, 25 May 2021 14:28:54 +0000

      Jason A. Donenfeld (Gerrit)

      unread,
      May 25, 2021, 10:32:27 AM5/25/21
      to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go Bot, Brad Fitzpatrick, Alex Brainman, golang-co...@googlegroups.com

      Jason A. Donenfeld submitted this change.

      View Change

      Approvals: Brad Fitzpatrick: Looks good to me, approved; Trusted Jason A. Donenfeld: Trusted; Run TryBots Go Bot: TryBots succeeded
      windows: add CreateProcessAsUser

      The syscall package already has this, but this one does not, so add this
      simple companion to CreateProcess.

      Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
      Reviewed-on: https://go-review.googlesource.com/c/sys/+/322489
      Trust: Jason A. Donenfeld <Ja...@zx2c4.com>
      Trust: Brad Fitzpatrick <brad...@golang.org>
      Run-TryBot: Jason A. Donenfeld <Ja...@zx2c4.com>
      TryBot-Result: Go Bot <go...@golang.org>
      Reviewed-by: Brad Fitzpatrick <brad...@golang.org>

      ---
      M windows/syscall_windows.go
      M windows/zsyscall_windows.go
      2 files changed, 14 insertions(+), 0 deletions(-)

      diff --git a/windows/syscall_windows.go b/windows/syscall_windows.go
      index bb6aaf8..183173a 100644
      1 is the latest approved patch-set. The change was submitted with unreviewed changes in the following files: The name of the file: windows/syscall_windows.go Insertions: 1, Deletions: 1. ``` @@ -222:223, +222:223 @@ - //sys CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) = CreateProcessAsUserW + //sys CreateProcessAsUser(token Token, appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) = CreateProcessAsUserW ```

      To view, visit change 322489. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
      Gerrit-Change-Number: 322489
      Gerrit-PatchSet: 3
      Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-MessageType: merged

      Alex Brainman (Gerrit)

      unread,
      May 29, 2021, 4:37:56 AM5/29/21
      to Jason A. Donenfeld, goph...@pubsubhelper.golang.org, Go Bot, Brad Fitzpatrick, golang-co...@googlegroups.com

      Attention is currently required from: Jason A. Donenfeld.

      View Change

      1 comment:

      To view, visit change 322489. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
      Gerrit-Change-Number: 322489
      Gerrit-PatchSet: 3
      Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-Attention: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-Comment-Date: Sat, 29 May 2021 08:37:50 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Gerrit-MessageType: comment

      Jason A. Donenfeld (Gerrit)

      unread,
      May 31, 2021, 12:59:17 PM5/31/21
      to goph...@pubsubhelper.golang.org, Go Bot, Brad Fitzpatrick, Alex Brainman, golang-co...@googlegroups.com

      View Change

      1 comment:

      • File windows/syscall_windows.go:

        • version in $GOROOT uses CreateProcessAsUserW from advapi32.dll […]

          Good catch. Interesting that this code still works; looks like there's an alias. I'll send a followup CL.

      To view, visit change 322489. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: sys
      Gerrit-Branch: master
      Gerrit-Change-Id: I8533f91245630dcf39705ae56a22c1217871f968
      Gerrit-Change-Number: 322489
      Gerrit-PatchSet: 3
      Gerrit-Owner: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-Reviewer: Alex Brainman <alex.b...@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Go Bot <go...@golang.org>
      Gerrit-Reviewer: Jason A. Donenfeld <Ja...@zx2c4.com>
      Gerrit-Comment-Date: Mon, 31 May 2021 16:59:12 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Alex Brainman <alex.b...@gmail.com>
      Gerrit-MessageType: comment
      Reply all
      Reply to author
      Forward
      0 new messages