public override void ApplyConfig() { IntPtr pStruct = IntPtr.Zero; HttpApi.HTTP_SERVICE_CONFIG_IP_LISTEN_PARAM setStruct = new HttpApi.HTTP_SERVICE_CONFIG_IP_LISTEN_PARAM(); try { setStruct.pAddress = HttpApi.BuildSockaddr(2, 0, _address); setStruct.AddrLength = (short)Marshal.SizeOf(typeof(HttpApi.sockaddr)); pStruct = Marshal.AllocHGlobal(Marshal.SizeOf(setStruct)); Marshal.StructureToPtr(setStruct, pStruct, false); if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Removed)) { HttpApi.Error error = HttpApi.HttpDeleteServiceConfiguration( IntPtr.Zero, HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigIPListenList, pStruct, Marshal.SizeOf(setStruct), IntPtr.Zero); if (error != HttpApi.Error.NO_ERROR) { throw new HttpApiException(error, "HttpDeleteServiceConfiguration (IPLISTEN) failed. Error = " + error); } } if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Added)) { HttpApi.Error error = HttpApi.HttpSetServiceConfiguration( IntPtr.Zero, HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigIPListenList, pStruct, Marshal.SizeOf(setStruct), IntPtr.Zero); if (error != HttpApi.Error.NO_ERROR) { throw new HttpApiException(error, "HttpSetServiceConfiguration (IPLISTEN) failed. Error = " + error); } } } finally { if (setStruct.pAddress != IntPtr.Zero) { Marshal.FreeHGlobal(setStruct.pAddress); } if (pStruct != IntPtr.Zero) { Marshal.FreeHGlobal(pStruct); } } }
public static Hashtable QueryConfig() { Hashtable items = new Hashtable(); HttpApi.HTTP_SERVICE_CONFIG_SSL_QUERY query = new HttpApi.HTTP_SERVICE_CONFIG_SSL_QUERY(); query.QueryDesc = HttpApi.HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext; IntPtr pInput = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(HttpApi.HTTP_SERVICE_CONFIG_SSL_QUERY))); try { for (query.dwToken = 0; ; query.dwToken++) { Marshal.StructureToPtr(query, pInput, false); int requiredBufferLength = 0; HttpApi.Error error = QueryServiceConfig(pInput, IntPtr.Zero, 0, out requiredBufferLength); if (error == HttpApi.Error.ERROR_NO_MORE_ITEMS) { break; } else if (error != HttpApi.Error.ERROR_INSUFFICIENT_BUFFER) { throw new HttpApiException(error, "HttpQueryServiceConfiguration (SSL) failed. Error = " + error); } IntPtr pOutput = Marshal.AllocHGlobal(requiredBufferLength); try { HttpApi.ZeroMemory(pOutput, requiredBufferLength); error = QueryServiceConfig(pInput, pOutput, requiredBufferLength, out requiredBufferLength); if (error != HttpApi.Error.NO_ERROR) { throw new HttpApiException(error, "HttpQueryServiceConfiguration (SSL) failed. Error = " + error); } SslConfigItem item = Deserialize(pOutput); items.Add(item.Key, item); } finally { Marshal.FreeHGlobal(pOutput); } } } finally { Marshal.FreeHGlobal(pInput); } return(items); }
public static Hashtable QueryConfig() { Hashtable items = new Hashtable(); int requiredBufferLength = 0; HttpApi.Error error = QueryServiceConfig(IntPtr.Zero, 0, out requiredBufferLength); if ((error != HttpApi.Error.ERROR_FILE_NOT_FOUND) && (error != HttpApi.Error.ERROR_NOT_FOUND)) { if (error != HttpApi.Error.ERROR_INSUFFICIENT_BUFFER) { throw new HttpApiException(error, "HttpQueryServiceConfiguration (IPLISTEN) failed. Error = " + error); } IntPtr pOutput = Marshal.AllocHGlobal(requiredBufferLength); try { HttpApi.ZeroMemory(pOutput, requiredBufferLength); error = QueryServiceConfig(pOutput, requiredBufferLength, out requiredBufferLength); if (error != HttpApi.Error.NO_ERROR) { throw new HttpApiException(error, "HttpQueryServiceConfiguration (IPLISTEN) failed. Error = " + error); } HttpApi.HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY output = (HttpApi.HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY)Marshal.PtrToStructure(pOutput, typeof(HttpApi.HTTP_SERVICE_CONFIG_IP_LISTEN_QUERY)); int addrSize = Marshal.SizeOf(typeof(HttpApi.SOCKADDR_STORAGE)); IntPtr pAddress = HttpApi.IncIntPtr(pOutput, 8); // Increment past the addrcount member and padding for (int i = 0; i < output.AddrCount; i++) { IpListenConfigItem item = new IpListenConfigItem(); item.Address = new IPAddress((long)Marshal.ReadInt32(pAddress, 4) & 0x00000000ffffffff); item.Status = ModifiedStatus.Unmodified; items.Add(item.Key, item); pAddress = HttpApi.IncIntPtr(pAddress, addrSize); // Increment to the next IP address } } finally { Marshal.FreeHGlobal(pOutput); } } return(items); }
public override void ApplyConfig() { IntPtr pStruct = IntPtr.Zero; HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET setStruct = new HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET(); setStruct.KeyDesc.pUrlPrefix = _url; setStruct.ParamDesc.pStringSecurityDescriptor = _acl.ToSddl(); try { pStruct = Marshal.AllocHGlobal(Marshal.SizeOf(setStruct)); Marshal.StructureToPtr(setStruct, pStruct, false); if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Removed)) { HttpApi.Error error = HttpApi.HttpDeleteServiceConfiguration( IntPtr.Zero, HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pStruct, Marshal.SizeOf(setStruct), IntPtr.Zero); if (error != HttpApi.Error.NO_ERROR) { throw new HttpApiException(error, "HttpDeleteServiceConfiguration (URLACL) failed. Error = " + error); } } if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Added)) { HttpApi.Error error = HttpApi.HttpSetServiceConfiguration( IntPtr.Zero, HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pStruct, Marshal.SizeOf(setStruct), IntPtr.Zero); if (error != HttpApi.Error.NO_ERROR) { throw new HttpApiException(error, "HttpSetServiceConfiguration (URLACL) failed. Error = " + error); } } } finally { if (pStruct != IntPtr.Zero) { Marshal.DestroyStructure(pStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_URLACL_SET)); Marshal.FreeHGlobal(pStruct); } } }
public override void ApplyConfig() { IntPtr pStruct = IntPtr.Zero; HttpApi.HTTP_SERVICE_CONFIG_SSL_SET setStruct = ToStruct(); try { pStruct = Marshal.AllocHGlobal(Marshal.SizeOf(setStruct)); Marshal.StructureToPtr(setStruct, pStruct, false); if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Removed)) { HttpApi.Error error = HttpApi.HttpDeleteServiceConfiguration( IntPtr.Zero, HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo, pStruct, Marshal.SizeOf(setStruct), IntPtr.Zero); if (error != HttpApi.Error.NO_ERROR) { throw new HttpApiException(error, "HttpDeleteServiceConfiguration (SSL) failed. Error = " + error); } } if ((Status == ModifiedStatus.Modified) || (Status == ModifiedStatus.Added)) { HttpApi.Error error = HttpApi.HttpSetServiceConfiguration( IntPtr.Zero, HttpApi.HTTP_SERVICE_CONFIG_ID.HttpServiceConfigSSLCertInfo, pStruct, Marshal.SizeOf(setStruct), IntPtr.Zero); if (error != HttpApi.Error.NO_ERROR) { throw new HttpApiException(error, "HttpSetServiceConfiguration (SSL) failed. Error = " + error); } } } finally { if (pStruct != IntPtr.Zero) { Marshal.DestroyStructure(pStruct, typeof(HttpApi.HTTP_SERVICE_CONFIG_SSL_SET)); Marshal.FreeHGlobal(pStruct); } FreeStruct(setStruct); } }
private void MainForm_Load(object sender, System.EventArgs e) { /*if(!SecurityApi.IsAdmin) * { * MessageBox.Show( * this, * "HttpConfig must be run by a machine administrator.", * "Insufficient Privileges", * MessageBoxButtons.OK, * MessageBoxIcon.Stop); * * Close(); * }*/ try { HttpApi.Error error = HttpApi.HttpInitialize( new HttpApi.HTTPAPI_VERSION(1, 0), HttpApi.InitFlag.HTTP_INITIALIZE_CONFIG, IntPtr.Zero); if (error != HttpApi.Error.NO_ERROR) { MessageBox.Show(this, "HttpInitialize failed (" + error.ToString() + "). The application will exit.", "Initialization Error"); Close(); } else { _isInitialized = true; LoadHttpConfigData(); } } catch (Exception ex) { DisplayError(ex); } }
public HttpApiException(HttpApi.Error error, string message, Exception innerException) : base(message, innerException) { HttpApiErrorCode = error; }
public HttpApiException(HttpApi.Error error, string message) : base(message) { HttpApiErrorCode = error; }
public HttpApiException(HttpApi.Error error) : base() { HttpApiErrorCode = error; }