internal TokenPrivilege(MemoryMarshaler m) { LUID_AND_ATTRIBUTES la = (LUID_AND_ATTRIBUTES)m.ParseStruct(typeof(LUID_AND_ATTRIBUTES)); _luid = new Luid(la.Luid); _attributes = (PrivilegeAttributes)la.Attributes; }
private static AdjustPrivilegeResult AdjustPrivilege( AccessTokenHandle accessTokenHandle, Privilege privilege, PrivilegeAttributes privilegeAttributes) { return(AdjustPrivilege(accessTokenHandle, GetLuid(privilege), privilegeAttributes)); }
private static AdjustPrivilegeResult AdjustPrivilege( AccessTokenHandle accessTokenHandle, Luid luid, PrivilegeAttributes privilegeAttributes) { TokenPrivilege newState = new TokenPrivilege { PrivilegeCount = 1, Privilege = new LuidAndAttributes { Attributes = privilegeAttributes, Luid = luid } }; TokenPrivilege previousState = new TokenPrivilege(); int returnLength = 0; if (!NativeMethods.AdjustTokenPrivileges( accessTokenHandle, false, ref newState, Marshal.SizeOf(previousState), ref previousState, ref returnLength)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return (AdjustPrivilegeResult)previousState.PrivilegeCount; }
private static AdjustPrivilegeResult AdjustPrivilege( AccessTokenHandle accessTokenHandle, Luid luid, PrivilegeAttributes privilegeAttributes) { TokenPrivilege newState = new TokenPrivilege { PrivilegeCount = 1, Privilege = new LuidAndAttributes { Attributes = privilegeAttributes, Luid = luid } }; TokenPrivilege previousState = new TokenPrivilege(); int returnLength = 0; if (!NativeMethods.AdjustTokenPrivileges( accessTokenHandle, false, ref newState, Marshal.SizeOf(previousState), ref previousState, ref returnLength)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } return((AdjustPrivilegeResult)previousState.PrivilegeCount); }
public void AddPrivilege(Luid luid, PrivilegeAttributes attributes) { LuidAndAttributes priv = new LuidAndAttributes { Luid = luid, Attributes = attributes }; _privs.Add(priv); }
public TokenPrivilege(string systemName, string privilege, bool enabled) { BOOL rc = Win32.LookupPrivilegeValue(systemName, privilege, out LUID luid); Win32.CheckCall(rc); _luid = new Luid(luid); _attributes = (enabled ? PrivilegeAttributes.Enabled : 0); }
public TokenPrivilege(string systemName, string privilege, bool enabled) { LUID luid; BOOL rc = Win32.LookupPrivilegeValue(systemName, privilege, out luid); Win32.CheckCall(rc); _luid = new Luid(luid); _attributes = (enabled ? PrivilegeAttributes.Enabled : 0); }
private void enablePrivilegeToolStripMenuItem_Click(object sender, EventArgs e) { if (listViewPrivs.SelectedItems.Count > 0) { IEnumerable <TokenPrivilege> privs = GetSelectedItemTags(listViewPrivs).OfType <TokenPrivilege>(); bool all_enabled = AllPrivsEnabled(privs); PrivilegeAttributes attributes = all_enabled ? PrivilegeAttributes.Disabled : PrivilegeAttributes.Enabled; ModifyPrivileges(privs, attributes); } }
public PrivilegeSetting(string privilege, PrivilegeAttributes attributes) { Privileges p; if (!Enum.TryParse(privilege, out p)) { p = Privileges.UnknownPrivilege; } Privilege = p; Attributes = attributes; }
public static PrivilegeState GetPrivilegeState(PrivilegeAttributes privilegeAttributes) { if ((privilegeAttributes & PrivilegeAttributes.Enabled) == PrivilegeAttributes.Enabled) { return(PrivilegeState.Enabled); } if ((privilegeAttributes & PrivilegeAttributes.Removed) == PrivilegeAttributes.Removed) { return(PrivilegeState.Removed); } return(PrivilegeState.Disabled); }
public static PrivilegeState GetPrivilegeState(PrivilegeAttributes privilegeAttributes) { if ((privilegeAttributes & PrivilegeAttributes.Enabled) == PrivilegeAttributes.Enabled) { return PrivilegeState.Enabled; } if ((privilegeAttributes & PrivilegeAttributes.Removed) == PrivilegeAttributes.Removed) { return PrivilegeState.Removed; } return PrivilegeState.Disabled; }
protected override void ProcessRecord() { WriteVerbose("Getting current process handle"); using SafeHandle processToken = PrivilegeHelper.GetCurrentProcess(); WriteVerbose("Getting privilege info for all privileges on the current process"); Dictionary <string, PrivilegeAttributes> privilegeInfo = PrivilegeHelper.GetAllPrivilegeInfo(processToken); if (Name.Length == 0) { Name = privilegeInfo.Keys.ToArray(); } foreach (string privName in Name) { if (!PrivilegeHelper.CheckPrivilegeName(privName)) { ItemNotFoundException exp = new ItemNotFoundException($"Invalid privilege name '{privName}'"); WriteError(new ErrorRecord(exp, "PrivilegeNotFound", ErrorCategory.ObjectNotFound, privName)); continue; } string description = PrivilegeHelper.GetPrivilegeDisplayName(privName); bool enabled = false; bool enableByDefault = false; PrivilegeAttributes attr = PrivilegeAttributes.Removed; bool isRemoved = true; if (privilegeInfo.ContainsKey(privName)) { attr = privilegeInfo[privName]; enabled = (attr & PrivilegeAttributes.Enabled) != 0; enableByDefault = (attr & PrivilegeAttributes.EnabledByDefault) != 0; isRemoved = false; } WriteObject(new Privilege() { Name = privName, Description = description, Enabled = enabled, EnabledByDefault = enableByDefault, Attributes = attr, IsRemoved = isRemoved, }); } }
public unsafe void AdjustPrivilege(UInt64 priv, PrivilegeAttributes newState, out PrivilegeAttributes oldState) { TokenPrivilege inBuff = new TokenPrivilege(priv, newState); void * inBuffP = (void *)&inBuff; TokenPrivilege outBuff = new TokenPrivilege(); void * outBuffP = (void *)&outBuff; uint size = (uint)sizeof(TokenPrivilege); bool success = AdjustTokenPrivileges(tokenHandle, false, inBuffP, size, outBuffP, out _); if (!success) { throw new Win32Exception(); } oldState = outBuff.Privilege.Attributes; }
private void ModifyPrivileges(IEnumerable <TokenPrivilege> privs, PrivilegeAttributes attributes) { bool multi = privs.Count() > 1; foreach (TokenPrivilege priv in privs) { try { _token.SetPrivilege(priv.Luid, attributes); } catch (Exception ex) { if (!multi) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } UpdatePrivileges(); }
public static ATPrivilege FromValues(string name, PrivilegeAttributes attributes) { uint attrib = 0; switch (attributes) { case PrivilegeAttributes.REMOVED: attrib = Constants.SE_PRIVILEGE_REMOVED; break; case PrivilegeAttributes.ENABLED: attrib = Constants.SE_PRIVILEGE_ENABLED; break; case PrivilegeAttributes.DISABLED: attrib = Constants.SE_PRIVILEGE_DISABLED; break; default: throw new Exception("Unkwnon privilege attribute"); } return(ATPrivilege.FromValues(name, attrib)); }
/// <summary>Initializes a new instance of the <see cref="PrivilegeAndAttributes"/> class.</summary> /// <param name="p">The privilege.</param> /// <param name="a">The attribute.</param> public PrivilegeAndAttributes(SystemPrivilege p, PrivilegeAttributes a) { Privilege = p; Attributes = a; }
public TOKEN_PRIVILEGES(LUID luid, PrivilegeAttributes attribute) { PrivilegeCount = 1; Privileges.Luid = luid; Privileges.Attributes = attribute; }
public LUID_AND_ATTRIBUTES(LUID luid, PrivilegeAttributes attr) { Luid = luid; Attributes = attr; }
public LuidAndAttributes(LUID luid, PrivilegeAttributes attributes = default) { Luid = luid; Attributes = attributes; }
internal TokenPrivilege(string system_name, Luid luid, PrivilegeAttributes attribute) { _system_name = system_name; Luid = luid; Attributes = attribute; }
public static SafeCoTaskMemHandle AdjustPrivilege(this SafeHTOKEN hObj, SystemPrivilege priv, PrivilegeAttributes attr) { var newState = new PTOKEN_PRIVILEGES(priv.GetLUID(), attr); var prevState = PTOKEN_PRIVILEGES.GetAllocatedAndEmptyInstance(); if (!AdjustTokenPrivileges(hObj, false, newState, (uint)prevState.Size, prevState, out var retLen)) { throw new Win32Exception(); } prevState.Size = (int)retLen; return(prevState); }
/// <summary> /// Constructor /// </summary> /// <param name="luid">The privilege LUID</param> /// <param name="attribute">The privilege attributes</param> public TokenPrivilege(Luid luid, PrivilegeAttributes attribute) { Luid = luid; Attributes = attribute; }
internal PrivilegeInfo(NativeHelpers.LUID_AND_ATTRIBUTES la) { Name = TokenUtil.GetPrivilegeName(la.Luid); Attributes = (PrivilegeAttributes)la.Attributes; }
/// <summary> /// Constructor /// </summary> /// <param name="luid">The privilege LUID</param> /// <param name="attribute">The privilege attributes</param> public TokenPrivilege(Luid luid, PrivilegeAttributes attribute) : this(null, luid, attribute) { }
public void Deconstruct(out UInt64 LUID, out PrivilegeAttributes Attributes) { LUID = this.LUID; Attributes = this.Attributes; }
internal PrivilegeAndAttributes(Privilege privilege, PrivilegeAttributes privilegeAttributes) { this.privilege = privilege; this.privilegeAttributes = privilegeAttributes; }
private static AdjustPrivilegeResult AdjustPrivilege( AccessTokenHandle accessTokenHandle, Privilege privilege, PrivilegeAttributes privilegeAttributes) { return AdjustPrivilege(accessTokenHandle, GetLuid(privilege), privilegeAttributes); }
/// <summary> /// Constructor /// </summary> /// <param name="value">The privilege value</param> /// <param name="attribute">The privilege attributes</param> public TokenPrivilege(TokenPrivilegeValue value, PrivilegeAttributes attribute) : this(new Luid((uint)value, 0), attribute) { }
public TokenPrivileges(PrivilegeAttributes attributes, LUID luid) { PrivilegeCount = 1; Attributes = attributes; Luid = luid; }
/// <summary> /// Constructor /// </summary> /// <param name="name">The privilege name.</param> /// <param name="attribute">The privilege attributes</param> public TokenPrivilege(string name, PrivilegeAttributes attribute) : this(LookupPrivilegeLuid(name), attribute) { }
public PrivilegeSetting(Privilege privilege, PrivilegeAttributes attributes) { Privilege = privilege; Attributes = attributes; }
internal PrivilegeAndAttributes(SystemPrivilege p, PrivilegeAttributes a) { Privilege = p; Attributes = a; }
public void AddPrivilege(TokenPrivilegeValue name, PrivilegeAttributes attributes) { Luid luid = new Luid((uint)name, 0); AddPrivilege(luid, attributes); }
public TokenPrivilege(UInt64 LUID, PrivilegeAttributes attributes) : this() { Count = 1; Privilege = new LuidAndAttributes(LUID, attributes); }