]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Application/IpsecConfig/PolicyEntryOperation.c
NetworkPkg: Clean up source files
[mirror_edk2.git] / NetworkPkg / Application / IpsecConfig / PolicyEntryOperation.c
index 05df9fa9198ee1e839a4907d017930cec8630f8e..7ecb8adc629a5c9a7c96c22e694037da7da25a9c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of policy entry operation function in IpSecConfig application.\r
 \r
 /** @file\r
   The implementation of policy entry operation function in IpSecConfig application.\r
 \r
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -271,7 +271,7 @@ CreateSpdEntry (
   //\r
   ValueStr = ShellCommandLineGetValue (ParamPackage, L"--name");\r
   if (ValueStr != NULL) {\r
   //\r
   ValueStr = ShellCommandLineGetValue (ParamPackage, L"--name");\r
   if (ValueStr != NULL) {\r
-    UnicodeStrToAsciiStr (ValueStr, (CHAR8 *) (*Data)->Name);\r
+    UnicodeStrToAsciiStrS (ValueStr, (CHAR8 *) (*Data)->Name, sizeof ((*Data)->Name));\r
     *Mask |= NAME;\r
   }\r
 \r
     *Mask |= NAME;\r
   }\r
 \r
@@ -785,7 +785,7 @@ CreateSadEntry (
     (*Data)->AlgoInfo.EspAlgoInfo.EncKeyLength = EncKeyLength;\r
     AsciiStr = AllocateZeroPool (EncKeyLength + 1);\r
     ASSERT (AsciiStr != NULL);\r
     (*Data)->AlgoInfo.EspAlgoInfo.EncKeyLength = EncKeyLength;\r
     AsciiStr = AllocateZeroPool (EncKeyLength + 1);\r
     ASSERT (AsciiStr != NULL);\r
-    UnicodeStrToAsciiStr (ValueStr, AsciiStr);\r
+    UnicodeStrToAsciiStrS (ValueStr, AsciiStr, EncKeyLength + 1);\r
     CopyMem ((*Data)->AlgoInfo.EspAlgoInfo.EncKey,  AsciiStr, EncKeyLength);\r
     FreePool (AsciiStr);\r
     *Mask |= ENCRYPT_KEY;\r
     CopyMem ((*Data)->AlgoInfo.EspAlgoInfo.EncKey,  AsciiStr, EncKeyLength);\r
     FreePool (AsciiStr);\r
     *Mask |= ENCRYPT_KEY;\r
@@ -814,7 +814,8 @@ CreateSadEntry (
   if (ValueStr != NULL) {\r
     (*Data)->AlgoInfo.EspAlgoInfo.AuthKeyLength = AuthKeyLength;\r
     AsciiStr = AllocateZeroPool (AuthKeyLength + 1);\r
   if (ValueStr != NULL) {\r
     (*Data)->AlgoInfo.EspAlgoInfo.AuthKeyLength = AuthKeyLength;\r
     AsciiStr = AllocateZeroPool (AuthKeyLength + 1);\r
-    UnicodeStrToAsciiStr (ValueStr, AsciiStr);\r
+    ASSERT (AsciiStr != NULL);\r
+    UnicodeStrToAsciiStrS (ValueStr, AsciiStr, AuthKeyLength + 1);\r
     CopyMem ((*Data)->AlgoInfo.EspAlgoInfo.AuthKey, AsciiStr, AuthKeyLength);\r
     FreePool (AsciiStr);\r
     *Mask |= AUTH_KEY;\r
     CopyMem ((*Data)->AlgoInfo.EspAlgoInfo.AuthKey, AsciiStr, AuthKeyLength);\r
     FreePool (AsciiStr);\r
     *Mask |= AUTH_KEY;\r
@@ -1103,7 +1104,7 @@ CreatePadEntry (
   ValueStr = ShellCommandLineGetValue (ParamPackage, L"--peer-id");\r
   if (ValueStr != NULL) {\r
     (*PadId)->PeerIdValid = TRUE;\r
   ValueStr = ShellCommandLineGetValue (ParamPackage, L"--peer-id");\r
   if (ValueStr != NULL) {\r
     (*PadId)->PeerIdValid = TRUE;\r
-    StrnCpy ((CHAR16 *) (*PadId)->Id.PeerId, ValueStr, ARRAY_SIZE ((*PadId)->Id.PeerId) - 1);\r
+    StrnCpyS ((CHAR16 *) (*PadId)->Id.PeerId, MAX_PEERID_LEN / sizeof (CHAR16), ValueStr, MAX_PEERID_LEN / sizeof (CHAR16) - 1);\r
     *Mask |= PEER_ID;\r
   }\r
 \r
     *Mask |= PEER_ID;\r
   }\r
 \r
@@ -1397,8 +1398,10 @@ CombineSpdEntry (
   //\r
   // Process Data\r
   //\r
   //\r
   // Process Data\r
   //\r
+  OldData->SaIdCount = 0;\r
+\r
   if ((Mask & NAME) != 0) {\r
   if ((Mask & NAME) != 0) {\r
-    AsciiStrCpy ((CHAR8 *) OldData->Name, (CHAR8 *) NewData->Name);\r
+    AsciiStrCpyS ((CHAR8 *) OldData->Name, MAX_PEERID_LEN, (CHAR8 *) NewData->Name);\r
   }\r
 \r
   if ((Mask & PACKET_FLAG) != 0) {\r
   }\r
 \r
   if ((Mask & PACKET_FLAG) != 0) {\r
@@ -1861,37 +1864,30 @@ EditOperatePolicyEntry (
                &CreateNew\r
                );\r
     if (!EFI_ERROR (Status)) {\r
                &CreateNew\r
                );\r
     if (!EFI_ERROR (Status)) {\r
+      //\r
+      // If the Selector already existed, this Entry will be updated by set data.\r
+      //\r
+      Status = mIpSecConfig->SetData (\r
+                               mIpSecConfig,\r
+                               Context->DataType,\r
+                               Context->Selector, /// New created selector.\r
+                               Data, /// Old date which has been modified, need to be set data.\r
+                               Selector\r
+                               );\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
       if (CreateNew) {\r
         //\r
       if (CreateNew) {\r
         //\r
-        // Insert new entry before old entry\r
+        // Edit the entry to a new one. So, we need delete the old entry.\r
         //\r
         Status = mIpSecConfig->SetData (\r
                                  mIpSecConfig,\r
                                  Context->DataType,\r
         //\r
         Status = mIpSecConfig->SetData (\r
                                  mIpSecConfig,\r
                                  Context->DataType,\r
-                                 Context->Selector,\r
-                                 Data,\r
-                                 Selector\r
-                                 );\r
-        ASSERT_EFI_ERROR (Status);\r
-        //\r
-        // Delete old entry\r
-        //\r
-        Status = mIpSecConfig->SetData (\r
-                                 mIpSecConfig,\r
-                                 Context->DataType,\r
-                                 Selector,\r
-                                 NULL,\r
+                                 Selector, /// Old selector.\r
+                                 NULL, /// NULL means to delete this Entry specified by Selector.\r
                                  NULL\r
                                  );\r
         ASSERT_EFI_ERROR (Status);\r
                                  NULL\r
                                  );\r
         ASSERT_EFI_ERROR (Status);\r
-      } else {\r
-        Status = mIpSecConfig->SetData (\r
-                                 mIpSecConfig,\r
-                                 Context->DataType,\r
-                                 Context->Selector,\r
-                                 Data,\r
-                                 NULL\r
-                                 );\r
       }\r
     }\r
 \r
       }\r
     }\r
 \r