internal FWP_TOKEN_INFORMATION ToStruct(DisposableList list)
        {
            var ret  = new FWP_TOKEN_INFORMATION();
            var sids = list.CreateSidAndAttributes(Sids);

            ret.sidCount           = Sids.Count;
            ret.sids               = list.AddResource(sids.ToBuffer()).DangerousGetHandle();
            ret.restrictedSidCount = RestrictedSids.Count;
            sids = list.CreateSidAndAttributes(RestrictedSids);
            ret.restrictedSids = list.AddResource(sids.ToBuffer()).DangerousGetHandle();
            return(ret);
        }
Ejemplo n.º 2
0
        private static NtStatus SetLoopbackException(Sid package_sid, bool remove, bool throw_on_error)
        {
            var result = GetLoopbackException(throw_on_error);

            if (!result.IsSuccess)
            {
                return(result.Status);
            }

            List <Sid> sids = result.Result.ToList();

            if (remove)
            {
                sids.RemoveAll(s => s == package_sid);
            }
            else
            {
                sids.Add(package_sid);
            }

            using (var list = new DisposableList())
            {
                return(AppModelNativeMethods.NetworkIsolationSetAppContainerConfig(sids.Count,
                                                                                   list.CreateSidAndAttributes(sids)).ToNtException(throw_on_error));
            }
        }
 /// <summary>
 /// Create a new AppContainerProfile.
 /// </summary>
 /// <param name="appcontainer_name">The name of the AppContainer.</param>
 /// <param name="display_name">A display name.</param>
 /// <param name="description">An optional description.</param>
 /// <param name="capabilities">An optional list of capability SIDs.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The created AppContainer profile.</returns>
 /// <remarks>If the profile already exists then it'll be opened instead.</remarks>
 public static NtResult <AppContainerProfile> Create(
     string appcontainer_name,
     string display_name,
     string description,
     IEnumerable <Sid> capabilities,
     bool throw_on_error)
 {
     using (var resources = new DisposableList())
     {
         var      caps   = resources.CreateSidAndAttributes(capabilities);
         NtStatus status = Win32NativeMethods.CreateAppContainerProfile(appcontainer_name, display_name, description,
                                                                        caps.Length > 0 ? caps : null, caps.Length, out SafeSidBufferHandle sid);
         if (status == NtObjectUtils.MapDosErrorToStatus(Win32Error.ERROR_ALREADY_EXISTS))
         {
             return(new AppContainerProfile(appcontainer_name).CreateResult());
         }
         resources.AddResource(sid);
         return(status.CreateResult(throw_on_error, () =>
         {
             using (sid)
             {
                 return new AppContainerProfile(appcontainer_name, sid.ToSid(),
                                                capabilities, display_name, description);
             }
         }));
     }
 }