Esempio n. 1
0
        /// <summary>
        /// Retrieves user-specific Extensible Authentication Protocol (EAP) information for the specified phone book entry.
        /// </summary>
        /// <param name="value">An <see cref="RasGetEapUserDataParams"/> containing call data.</param>
        /// <returns>If the function succeeds, the return value is zero.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="value"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public int GetEapUserData(RasGetEapUserDataParams value)
        {
            if (value == null)
            {
                ThrowHelper.ThrowArgumentNullException("value");
            }

            IntPtr bufferSize = value.BufferSize;

            int ret = SafeNativeMethods.RasGetEapUserData(value.UserToken, value.PhoneBookPath, value.EntryName, value.Address, ref bufferSize);
            value.BufferSize = bufferSize;

            return ret;
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves user-specific Extensible Authentication Protocol (EAP) information for the specified phone book entry.
        /// </summary>
        /// <param name="userToken">The handle of a Windows account token. This token is usually retrieved through a call to unmanaged code, such as a call to the Win32 API LogonUser function.</param>
        /// <param name="phoneBookPath">The full path and filename of a phone book file. If this parameter is a null reference (<b>Nothing</b> in Visual Basic), the default phone book is used.</param>
        /// <param name="entryName">The entry name to validate.</param>
        /// <returns>A byte array containing the EAP data, otherwise a null reference (<b>Nothing</b> in Visual Basic).</returns>
        public byte[] GetEapUserData(IntPtr userToken, string phoneBookPath, string entryName)
        {
            byte[] result = null;

            RasGetEapUserDataParams info = new RasGetEapUserDataParams();
            info.UserToken = userToken;
            info.PhoneBookPath = phoneBookPath;
            info.EntryName = entryName;
            info.BufferSize = IntPtr.Zero;

            bool retry = false;

            do
            {
                try
                {
                    info.Address = Marshal.AllocHGlobal(info.BufferSize);

                    int ret = SafeNativeMethods.Instance.GetEapUserData(info);
                    if (ret == NativeMethods.ERROR_BUFFER_TOO_SMALL)
                    {
                        retry = true;
                    }
                    else if (ret == NativeMethods.SUCCESS)
                    {
                        int bufferSize = info.BufferSize.ToInt32();

                        if (bufferSize != 0)
                        {
                            result = new byte[bufferSize];
                            Marshal.Copy(info.Address, result, 0, bufferSize);
                        }

                        retry = false;
                    }
                    else
                    {
                        ThrowHelper.ThrowRasException(ret);
                    }
                }
                catch (EntryPointNotFoundException)
                {
                    ThrowHelper.ThrowNotSupportedException(Resources.Exception_NotSupportedOnPlatform);
                }
                finally
                {
                    if (info.Address != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(info.Address);
                    }
                }
            }
            while (retry);

            return result;
        }
Esempio n. 3
0
        /// <summary>
        /// Retrieves user-specific Extensible Authentication Protocol (EAP) information for the specified phone book entry.
        /// </summary>
        /// <param name="value">An <see cref="RasGetEapUserDataParams"/> containing call data.</param>
        /// <returns>If the function succeeds, the return value is zero.</returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="value"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public int GetEapUserData(RasGetEapUserDataParams value)
        {
            if (value == null)
            {
                ThrowHelper.ThrowArgumentNullException("value");
            }

            IntPtr bufferSize = value.BufferSize;

            PInvokeCallTraceEvent evt = new PInvokeCallTraceEvent(NativeMethods.RasApi32Dll, "RasGetEapUserData");
            evt.Data.Add("userToken", value.UserToken);
            evt.Data.Add("phoneBookPath", value.PhoneBookPath);
            evt.Data.Add("entryName", value.EntryName);
            evt.Data.Add("address", value.Address);
            evt.Data.Add("bufferSize-IN", bufferSize);

            int result = 0;

            try
            {
                result = SafeNativeMethods.RasGetEapUserData(value.UserToken, value.PhoneBookPath, value.EntryName, value.Address, ref bufferSize);
                evt.ResultCode = result;
                evt.Data.Add("bufferSize-OUT", bufferSize);

                value.BufferSize = bufferSize;
            }
            finally
            {
                DiagnosticTrace.Default.TraceEvent(TraceEventType.Verbose, evt);
            }

            return result;
        }