]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootSupport.c
NetworkPkg: Add PCD to enable the HTTP connections switch
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootSupport.c
index bdb29ae9a0f6c57fafcb71ff802d8ee665a3054f..69b129f9d2caa4696afc09aacaaadb389f4b456c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support functions implementation for UEFI HTTP boot driver.\r
 \r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials are licensed and made available under\r
 the terms and conditions of the BSD License that accompanies this distribution.\r
@@ -988,6 +988,57 @@ HttpIoRecvResponse (
   return Status;\r
 }\r
 \r
+/**\r
+  This function checks the HTTP(S) URI scheme.\r
+\r
+  @param[in]    Uri              The pointer to the URI string.\r
+  \r
+  @retval EFI_SUCCESS            The URI scheme is valid.\r
+  @retval EFI_INVALID_PARAMETER  The URI scheme is not HTTP or HTTPS.\r
+  @retval EFI_ACCESS_DENIED      HTTP is disabled and the URI is HTTP.\r
+\r
+**/\r
+EFI_STATUS\r
+HttpBootCheckUriScheme (\r
+  IN      CHAR8                  *Uri\r
+  )\r
+{\r
+  UINTN                Index;\r
+  EFI_STATUS           Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  //\r
+  // Convert the scheme to all lower case.\r
+  //\r
+  for (Index = 0; Index < AsciiStrLen (Uri); Index++) {\r
+    if (Uri[Index] == ':') {\r
+      break;\r
+    }\r
+    if (Uri[Index] >= 'A' && Uri[Index] <= 'Z') {\r
+      Uri[Index] -= (CHAR8)('A' - 'a');\r
+    }\r
+  }\r
+\r
+  //\r
+  // Return EFI_INVALID_PARAMETER if the URI is not HTTP or HTTPS.\r
+  //\r
+  if ((AsciiStrnCmp (Uri, "http://", 7) != 0) && (AsciiStrnCmp (Uri, "https://", 8) != 0)) {\r
+    DEBUG ((EFI_D_ERROR, "HttpBootCheckUriScheme: Invalid Uri.\n"));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // HTTP is disabled, return EFI_ACCESS_DENIED if the URI is HTTP.\r
+  //\r
+  if (!PcdGetBool (PcdAllowHttpConnections) && (AsciiStrnCmp (Uri, "http://", 7) == 0)) {\r
+    DEBUG ((EFI_D_ERROR, "HttpBootCheckUriScheme: HTTP is disabled.\n"));\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
 /**\r
   Get the URI address string from the input device path.\r
 \r