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)
| 65 | // Token. The token must have TOKEN_ADJUST_PRIVILEGES access. If the token |
| 66 | // does not already contain the privilege it cannot be enabled. |
| 67 | func 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. |
| 98 | func SetDebugPrivilege() { |
no test coverage detected