Exemplo n.º 1
0
 /// <summary>
 /// Sets a privilege's attributes.
 /// </summary>
 /// <param name="privilegeName">The name of the privilege.</param>
 /// <param name="attributes">The new attributes of the privilege.</param>
 /// <returns>True if the function succeeded, otherwise false.</returns>
 public bool TrySetPrivilege(string privilegeName, SePrivilegeAttributes attributes)
 {
     return(this.TrySetPrivilege(
                LsaPolicyHandle.LookupPolicyHandle.LookupPrivilegeValue(privilegeName),
                attributes
                ));
 }
Exemplo n.º 2
0
        private Privilege(TokenHandle tokenHandle, string name, bool hasLuid, Luid luid, SePrivilegeAttributes attributes)
            : base(tokenHandle != null)
        {
            _tokenHandle = tokenHandle;

            if (_tokenHandle != null)
            {
                _tokenHandle.Reference();
            }

            _name       = name;
            _attributes = attributes;

            if (!hasLuid)
            {
                if (_name == null)
                {
                    throw new ArgumentException("You must specify either a LUID or a name.");
                }

                _luid = LsaPolicyHandle.LookupPolicyHandle.LookupPrivilegeValue(_name);
            }
            else
            {
                _luid = luid;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Sets a privilege's attributes.
 /// </summary>
 /// <param name="privilegeName">The name of the privilege.</param>
 /// <param name="attributes">The new attributes of the privilege.</param>
 public void SetPrivilege(string privilegeName, SePrivilegeAttributes attributes)
 {
     if (!this.TrySetPrivilege(privilegeName, attributes))
     {
         Win32.Throw();
     }
 }
Exemplo n.º 4
0
 public void SetPrivilege(Luid privilegeLuid, SePrivilegeAttributes attributes)
 {
     if (!this.TrySetPrivilege(privilegeLuid, attributes))
     {
         Win32.Throw();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Sets a privilege's attributes.
        /// </summary>
        /// <param name="privilegeName">The name of the privilege.</param>
        /// <param name="attributes">The new attributes of the privilege.</param>
        public void SetPrivilege(string privilegeName, SePrivilegeAttributes attributes)
        {
            Luid privilegeLuid;

            if (!Win32.LookupPrivilegeValue(null, privilegeName, out privilegeLuid))
            {
                throw new Exception("Invalid privilege name '" + privilegeName + "'.");
            }

            this.SetPrivilege(privilegeLuid, attributes);
        }
Exemplo n.º 6
0
        public void DumpAddPrivilege(
            string name,
            string displayName,
            SePrivilegeAttributes attributes
            )
        {
            ListViewItem item = listPrivileges.Items.Add(name.ToLowerInvariant(), name, 0);

            item.BackColor = GetAttributeColor(attributes);
            item.SubItems.Add(new ListViewItem.ListViewSubItem(item, GetAttributeString(attributes)));
            item.SubItems.Add(new ListViewItem.ListViewSubItem(item, displayName));
        }
Exemplo n.º 7
0
        public NtStatus TrySetPrivilege(Luid privilegeLuid, SePrivilegeAttributes attributes)
        {
            TokenPrivileges tkp = new TokenPrivileges
            {
                Privileges     = new LuidAndAttributes[1],
                PrivilegeCount = 1
            };

            tkp.Privileges[0].Attributes = attributes;
            tkp.Privileges[0].Luid       = privilegeLuid;

            return(Win32.NtAdjustPrivilegesToken(this, false, ref tkp, 0, IntPtr.Zero, IntPtr.Zero));
        }
Exemplo n.º 8
0
        public void SetPrivilege(Luid privilegeLuid, SePrivilegeAttributes attributes)
        {
            TokenPrivileges tkp = new TokenPrivileges();

            tkp.Privileges = new LuidAndAttributes[1];

            tkp.PrivilegeCount           = 1;
            tkp.Privileges[0].Attributes = attributes;
            tkp.Privileges[0].Luid       = privilegeLuid;

            Win32.AdjustTokenPrivileges(this, false, ref tkp, 0, IntPtr.Zero, IntPtr.Zero);

            if (Marshal.GetLastWin32Error() != 0)
            {
                Win32.ThrowLastError();
            }
        }
Exemplo n.º 9
0
 private string GetAttributeString(SePrivilegeAttributes Attributes)
 {
     if ((Attributes & SePrivilegeAttributes.EnabledByDefault) != 0)
     {
         return("Default Enabled");
     }
     else if ((Attributes & SePrivilegeAttributes.Enabled) != 0)
     {
         return("Enabled");
     }
     else if (Attributes == SePrivilegeAttributes.Disabled)
     {
         return("Disabled");
     }
     else
     {
         return("Unknown");
     }
 }
Exemplo n.º 10
0
 private Color GetAttributeColor(SePrivilegeAttributes Attributes)
 {
     if ((Attributes & SePrivilegeAttributes.EnabledByDefault) != 0)
     {
         return(Color.FromArgb(0xc0f0c0));
     }
     else if ((Attributes & SePrivilegeAttributes.Enabled) != 0)
     {
         return(Color.FromArgb(0xe0f0e0));
     }
     else if (Attributes == SePrivilegeAttributes.Disabled)
     {
         return(Color.FromArgb(0xf0e0e0));
     }
     else
     {
         return(Color.White);
     }
 }
Exemplo n.º 11
0
        private Privilege(TokenHandle tokenHandle, string name, bool hasLuid, Luid luid, SePrivilegeAttributes attributes)
            : base(tokenHandle != null)
        {
            _tokenHandle = tokenHandle;

            if (_tokenHandle != null)
                _tokenHandle.Reference();

            _name = name;
            _attributes = attributes;

            if (!hasLuid)
            {
                if (_name == null)
                    throw new ArgumentException("You must specify either a LUID or a name.");

                _luid = LsaPolicyHandle.LookupPolicyHandle.LookupPrivilegeValue(_name);
            }
            else
            {
                _luid = luid;
            }
        }
Exemplo n.º 12
0
 public Privilege(Luid luid, SePrivilegeAttributes attributes)
     : this(null, luid, attributes)
 {
 }
Exemplo n.º 13
0
 public Privilege(TokenHandle tokenHandle, string name, SePrivilegeAttributes attributes)
     : this(tokenHandle, name, false, Luid.Empty, attributes)
 {
 }
Exemplo n.º 14
0
 private void SetState(TokenHandle tokenHandle, SePrivilegeAttributes attributes)
 {
     _attributes = attributes;
     _tokenHandle.SetPrivilege(_luid, _attributes);
 }
Exemplo n.º 15
0
 public Privilege(Luid luid, SePrivilegeAttributes attributes)
     : this(null, luid, attributes)
 { }
Exemplo n.º 16
0
 private Color GetAttributeColor(SePrivilegeAttributes Attributes)
 {
     if ((Attributes & SePrivilegeAttributes.EnabledByDefault) != 0)
         return Color.FromArgb(0xc0f0c0);
     else if ((Attributes & SePrivilegeAttributes.Enabled) != 0)
         return Color.FromArgb(0xe0f0e0);
     else if (Attributes == SePrivilegeAttributes.Disabled)
         return Color.FromArgb(0xf0e0e0);
     else
         return Color.White;
 }
Exemplo n.º 17
0
 private string GetAttributeString(SePrivilegeAttributes Attributes)
 {
     if ((Attributes & SePrivilegeAttributes.EnabledByDefault) != 0)
         return "Default Enabled";
     else if ((Attributes & SePrivilegeAttributes.Enabled) != 0)
         return "Enabled";
     else if (Attributes == SePrivilegeAttributes.Disabled)
         return "Disabled";
     else
         return "Unknown";
 }
Exemplo n.º 18
0
 public Privilege(TokenHandle tokenHandle, string name, SePrivilegeAttributes attributes)
     : this(tokenHandle, name, false, Luid.Empty, attributes)
 { }
Exemplo n.º 19
0
 public Privilege(TokenHandle tokenHandle, Luid luid, SePrivilegeAttributes attributes)
     : this(tokenHandle, null, true, luid, attributes)
 {
 }
Exemplo n.º 20
0
 public Privilege(TokenHandle tokenHandle, Luid luid, SePrivilegeAttributes attributes)
     : this(tokenHandle, null, true, luid, attributes)
 { }
Exemplo n.º 21
0
 /// <summary>
 /// Sets a privilege's attributes.
 /// </summary>
 /// <param name="privilegeName">The name of the privilege.</param>
 /// <param name="attributes">The new attributes of the privilege.</param>
 public void SetPrivilege(string privilegeName, SePrivilegeAttributes attributes)
 {
     this.TrySetPrivilege(privilegeName, attributes).ThrowIf();
 }
Exemplo n.º 22
0
 public void SetPrivilege(Luid privilegeLuid, SePrivilegeAttributes attributes)
 {
     this.TrySetPrivilege(privilegeLuid, attributes).ThrowIf();
 }
Exemplo n.º 23
0
        public void DumpAddPrivilege(
            string name,
            string displayName,
            SePrivilegeAttributes attributes
            )
        {
            ListViewItem item = listPrivileges.Items.Add(name.ToLowerInvariant(), name, 0);

            item.BackColor = GetAttributeColor(attributes);
            item.SubItems.Add(new ListViewItem.ListViewSubItem(item, GetAttributeString(attributes)));
            item.SubItems.Add(new ListViewItem.ListViewSubItem(item, displayName));
        }
Exemplo n.º 24
0
 private void SetState(TokenHandle tokenHandle, SePrivilegeAttributes attributes)
 {
     _attributes = attributes;
     _tokenHandle.SetPrivilege(_luid, _attributes);
 }