MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / adjustTokenPrivileges

Function adjustTokenPrivileges

pkg/sys/privilege.go:67–95  ·  view source on GitHub ↗

adjustTokenPrivileges enables/disables the specified privileges in the given Token. The token must have TOKEN_ADJUST_PRIVILEGES access. If the token does not already contain the privilege it cannot be enabled.

(token windows.Token, state uint32, privileges ...string)

Source from the content-addressed store, hash-verified

65// Token. The token must have TOKEN_ADJUST_PRIVILEGES access. If the token
66// does not already contain the privilege it cannot be enabled.
67func adjustTokenPrivileges(token windows.Token, state uint32, privileges ...string) error {
68 privValues, err := mapPrivileges(privileges)
69 if err != nil {
70 return err
71 }
72
73 var b bytes.Buffer
74 if err := binary.Write(&b, binary.LittleEndian, uint32(len(privValues))); err != nil {
75 return err
76 }
77 for _, p := range privValues {
78 if err := binary.Write(&b, binary.LittleEndian, p); err != nil {
79 continue
80 }
81 if err := binary.Write(&b, binary.LittleEndian, state); err != nil {
82 continue
83 }
84 }
85
86 privs := (*windows.Tokenprivileges)(unsafe.Pointer(&b.Bytes()[0]))
87 err = windows.AdjustTokenPrivileges(token, false, privs, uint32(b.Len()), nil, nil)
88 if err != nil {
89 return err
90 }
91 if err == ErrorNotAllAsigned {
92 return errors.Wrap(err, "error not all privileges were assigned")
93 }
94 return nil
95}
96
97// SetDebugPrivilege sets the debug privilege in the current process token.
98func SetDebugPrivilege() {

Callers 2

enablePrivilegesFunction · 0.85
removePrivilegesFunction · 0.85

Calls 3

mapPrivilegesFunction · 0.85
WriteMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected