github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/dokan/winacl/sid_windows.go (about)

     1  // Copyright 2016 Keybase Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD
     3  // license that can be found in the LICENSE file.
     4  
     5  package winacl
     6  
     7  import (
     8  	"syscall"
     9  )
    10  
    11  // SID wraps syscall.SID.
    12  type SID syscall.SID
    13  
    14  // currentProcessUserSid is a utility to get the
    15  // SID of the current user running the process.
    16  func currentProcessUserSid() (*SID, error) {
    17  	tok, err := syscall.OpenCurrentProcessToken()
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  	defer tok.Close()
    22  	tokUser, err := tok.GetTokenUser()
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	return (*SID)(tokUser.User.Sid), nil
    27  }
    28  
    29  func currentProcessPrimaryGroupSid() (*SID, error) {
    30  	tok, err := syscall.OpenCurrentProcessToken()
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  	defer tok.Close()
    35  	tokGroup, err := tok.GetTokenPrimaryGroup()
    36  	if err != nil {
    37  		return nil, err
    38  	}
    39  	return (*SID)(tokGroup.PrimaryGroup), nil
    40  }