Ejemplo n.º 1
0
        public static void RevokePrivilegeToUser(string privilege, string user)
        {
            if (string.IsNullOrWhiteSpace(privilege))
            {
                throw new ArgumentException("Privilege cannot be empty.", "privilege");
            }

            if (string.IsNullOrWhiteSpace(privilege))
            {
                throw new ArgumentException("user cannot be empty.", "user");
            }

            string userSid = WindowsUsersAndGroups.GetLocalUserSid(user);

            HashSet <string> grants = GetPrivilegeGrants(privilege);

            string[] valuesToLookup = new string[]
            {
                userSid,
                string.Format(CultureInfo.InvariantCulture, "*{0}", userSid),
                user.ToUpperInvariant()
            };

            foreach (string value in valuesToLookup)
            {
                if (grants.Contains(value))
                {
                    grants.Remove(value);
                }
            }

            Save(privilege, grants);
        }
Ejemplo n.º 2
0
        public static bool UserHasPrivilege(string privilege, string user)
        {
            if (string.IsNullOrWhiteSpace(privilege))
            {
                throw new ArgumentException("Privilege cannot be empty.", "privilege");
            }

            if (string.IsNullOrWhiteSpace(privilege))
            {
                throw new ArgumentException("user cannot be empty.", "user");
            }

            string userSid = WindowsUsersAndGroups.GetLocalUserSid(user);

            HashSet <string> grants = GetPrivilegeGrants(privilege);

            string[] valuesToLookup = new string[]
            {
                userSid.ToUpperInvariant(),
                string.Format(CultureInfo.InvariantCulture, "*{0}", userSid).ToUpperInvariant(),
                user.ToUpperInvariant()
            };

            return(grants.Any(u => valuesToLookup.Contains(u.ToUpperInvariant().Trim())));
        }
Ejemplo n.º 3
0
        public static void GrantPrivilegeToUser(string privilege, string user)
        {
            if (string.IsNullOrWhiteSpace(privilege))
            {
                throw new ArgumentException("Privilege cannot be empty.", "privilege");
            }

            if (string.IsNullOrWhiteSpace(privilege))
            {
                throw new ArgumentException("user cannot be empty.", "user");
            }

            string userSid = WindowsUsersAndGroups.GetLocalUserSid(user);

            HashSet <string> grants = GetPrivilegeGrants(privilege);

            grants.Add(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "*{0}",
                    userSid));

            Save(privilege, grants);
        }