Beispiel #1
0
        /// <summary>
        /// Modify groups in the context.
        /// </summary>
        /// <param name="type">The type of group to modify.</param>
        /// <param name="groups">The list of groups to modify.</param>
        /// <param name="operations">The list of operations. Should be same size of group list.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The NT status code.</returns>
        public NtStatus ModifyGroups(AuthZGroupSidType type, IEnumerable <UserGroup> groups, IEnumerable <AuthZSidOperation> operations, bool throw_on_error)
        {
            if (groups is null)
            {
                throw new ArgumentNullException(nameof(groups));
            }

            if (operations is null)
            {
                throw new ArgumentNullException(nameof(operations));
            }

            UserGroup[]         group_array = groups.ToArray();
            AuthZSidOperation[] ops_array   = operations.ToArray();
            if (group_array.Length != ops_array.Length)
            {
                throw new ArgumentException("Groups and Operations must be the same length.");
            }

            using (var buffer = SafeTokenGroupsBuffer.Create(groups)) {
                if (!SecurityNativeMethods.AuthzModifySids(_handle, SidTypeToInfoClass(type),
                                                           ops_array, buffer))
                {
                    return(NtObjectUtils.MapDosErrorToStatus().ToNtException(throw_on_error));
                }
            }
            return(NtStatus.STATUS_SUCCESS);
        }