Ejemplo n.º 1
0
        protected static int IPSecGetNegPolData(IntPtr hStore, Guid negGuid, out IPSEC_NEGPOL_DATA ipsecNegPolData)
        {
            ipsecNegPolData = new IPSEC_NEGPOL_DATA();

            //Allocate memory for the struct pointer.
            IntPtr ppIpsecNegPolData = Marshal.AllocHGlobal(Marshal.SizeOf(new IntPtr()));

            //Execute the native import.
            int hr = IPSecGetNegPolData(hStore, negGuid, ppIpsecNegPolData);

            if (hr != 0)
            {
                return(hr);
            }

            //Dereference the double pointer once.
            IntPtr pIpsecNegPolData = Marshal.ReadIntPtr(ppIpsecNegPolData);

            //Marshal the dereferenced pointer to a structure.
            ipsecNegPolData = (IPSEC_NEGPOL_DATA)Marshal.PtrToStructure(pIpsecNegPolData, typeof(IPSEC_NEGPOL_DATA));

            //Free memory.
            Marshal.FreeHGlobal(ppIpsecNegPolData);
            return(hr);
        }
Ejemplo n.º 2
0
        protected static int IPSecCreateNegPolData(IntPtr hStore, IPSEC_NEGPOL_DATA ipsecNegPolData)
        {
            IntPtr pIpsecNegPolData = Marshal.AllocHGlobal(Marshal.SizeOf(ipsecNegPolData));

            Marshal.StructureToPtr(ipsecNegPolData, pIpsecNegPolData, false);


            int hr = IPSecCreateNegPolData(hStore, pIpsecNegPolData);

            Marshal.FreeHGlobal(pIpsecNegPolData);
            return(hr);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a standalone filter action.
        /// </summary>
        /// <param name="hStore">A handle to the policy store.</param>
        /// <param name="name">The name to give the filter action.</param>
        /// <param name="action">The type of action.</param>
        /// <param name="ipsecNegPol">An out struct to return the data.</param>
        /// <param name="description">The description to give the filter action.</param>
        /// <returns>A WinError System Error Code.</returns>
        private int CreateFilterAction(string name, FilterActionType action, out IPSEC_NEGPOL_DATA ipsecNegPol, string description = "")
        {
            ipsecNegPol = new IPSEC_NEGPOL_DATA()
            {
                pszIpsecName     = name,
                pszDescription   = description,
                NegPolType       = GUID_NEGOTATION_TYPE_STANDARD,
                NegPolIdentifier = Guid.NewGuid(),
                dwWhenChanged    = (int)new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds(),
            };
            if (action == FilterActionType.Block)
            {
                ipsecNegPol.NegPolAction = GUID_NEGOTIATION_ACTION_BLOCK;
            }
            else
            {
                throw new NotImplementedException();
            }

            return(IPSecCreateNegPolData(hStore, ipsecNegPol));
        }