From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=68.232.149.214; helo=esa4.dell-outbound.iphmx.com; envelope-from=jim.dailey@dell.com; receiver=edk2-devel@lists.01.org Received: from esa4.dell-outbound.iphmx.com (esa4.dell-outbound.iphmx.com [68.232.149.214]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9E7B82116821C for ; Wed, 24 Oct 2018 09:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dell.com; i=@dell.com; q=dns/txt; s=smtpout; t=1540398929; x=1571934929; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=VFz1n77eYVqvXy5yTyH/O/xyh9HqV8bcfm+dBShl2Ls=; b=skQO7EmRs5j6/ETKa6FSDhs2vLcgrqtZU4KS4M7mRdWXfmZX3mQEzFpi 2qAzlz0GUNyUxjcIHFW2wEAROmf9+lvBojJkitaYBtzefGt7XXtC8JZNr HaEnEwPZKXu5cxReZPo8WbpyIA0qoKsxj3XzR+peq90hPOSnzkE6nxIAk 4=; X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2EYAAAuntBbhiWd50NjHQEBBQEHBQG?= =?us-ascii?q?BUQgBCwGDaSgKjANfiziEBJUeFIFmCwEBhGyDDiE0DQ0BAwEBAgEBAgEBAhA?= =?us-ascii?q?BAQEKCQsIKS+CNiKCZhYoPxIBPmgBBA4FCBqCf4ICnn+JVwEBAYIbiiWHf4J?= =?us-ascii?q?GgR2CF4ERh1UEb4UiAohrhXCPdQcCkGwfkDCUA4JBAgQCBAUCFIFDgg5wgzy?= =?us-ascii?q?CNBuOCG+KYIEugR8BAQ?= X-IPAS-Result: =?us-ascii?q?A2EYAAAuntBbhiWd50NjHQEBBQEHBQGBUQgBCwGDaSgKj?= =?us-ascii?q?ANfiziEBJUeFIFmCwEBhGyDDiE0DQ0BAwEBAgEBAgEBAhABAQEKCQsIKS+CN?= =?us-ascii?q?iKCZhYoPxIBPmgBBA4FCBqCf4ICnn+JVwEBAYIbiiWHf4JGgR2CF4ERh1UEb?= =?us-ascii?q?4UiAohrhXCPdQcCkGwfkDCUA4JBAgQCBAUCFIFDgg5wgzyCNBuOCG+KYIEug?= =?us-ascii?q?R8BAQ?= Received: from mx0b-00154901.pphosted.com ([67.231.157.37]) by esa4.dell-outbound.iphmx.com with ESMTP/TLS/AES256-SHA256; 24 Oct 2018 11:35:27 -0500 Received: from pps.filterd (m0144104.ppops.net [127.0.0.1]) by mx0b-00154901.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9OGXZ3V106872 for ; Wed, 24 Oct 2018 12:35:27 -0400 Received: from esa5.dell-outbound2.iphmx.com (esa5.dell-outbound2.iphmx.com [68.232.153.203]) by mx0b-00154901.pphosted.com with ESMTP id 2namddk302-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 24 Oct 2018 12:35:26 -0400 From: Received: from ausxippc106.us.dell.com ([143.166.85.156]) by esa5.dell-outbound2.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA256; 24 Oct 2018 22:34:58 +0600 X-LoopCount0: from 10.166.136.212 X-IronPort-AV: E=Sophos;i="5.54,421,1534827600"; d="scan'208";a="310034259" To: CC: , Thread-Topic: [edk2][PATCH 1/2] ShellPkg-Shell App: Provide fully-qualified path to shell scripts Thread-Index: AdRrt2dO57FC299ES2iPnMY7oYr17A== Date: Wed, 24 Oct 2018 16:35:23 +0000 Message-ID: <33689dc40acb404a909157fe967193a3@ausx13mps335.AMER.DELL.COM> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Enabled=True; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_SiteId=945c199a-83a2-4e80-9f8c-5a91be5752dd; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Owner=Jim_Dailey@Dell.com; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_SetDate=2018-10-24T16:22:16.0382209Z; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Name=External Public; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Application=Microsoft Azure Information Protection; MSIP_Label_17cb76b2-10b8-4fe1-93d4-2202842406cd_Extended_MSFT_Method=Manual; Sensitivity=External Public x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.143.18.86] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-10-24_06:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810240141 Subject: [PATCH 1/2] ShellPkg-Shell App: Provide fully-qualified path to shell scripts X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2018 16:35:29 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Add a function to return the fully-qualified version of some path. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jim Dailey --- ShellPkg/Include/Library/ShellLib.h | 40 +++++++++ ShellPkg/Library/UefiShellLib/UefiShellLib.c | 93 +++++++++++++++++++- 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/ShellPkg/Include/Library/ShellLib.h b/ShellPkg/Include/Library= /ShellLib.h index 92fddc50f5..cd7e9c47c3 100644 --- a/ShellPkg/Include/Library/ShellLib.h +++ b/ShellPkg/Include/Library/ShellLib.h @@ -2,6 +2,7 @@ Provides interface to shell functionality for shell commands and applica= tions. =20 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+ Copyright 2018 Dell Technologies.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -35,6 +36,45 @@ extern EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol; extern EFI_SHELL_PROTOCOL *gEfiShellProtocol; =20 +/** + Return the fully-qualified version of a relative path or an absolute pat= h that + does not include a file system reference. + + If ASSERTs are disabled, and if the input parameter is NULL or points to= NULL, + then NULL is returned. + + If the input path contains a ":", this function assumes that it is part = of a + reference to a file system (e.g. "FS0:"). In such a case, Path is clean= ed + and returned. + + If there is no working directory or there is not enough memory available= to + create the fully-qualified path, Path is cleaned and returned. + + Otherwise, the current file system or working directory (as appropriate)= is + prepended to Path. The input Path is freed and the resulting path is cl= eaned, + assigned to Path, and returned. + + NOTE: If the input path is an empty string, then the current working dir= ectory + (if it exists) is returned. In other words, an empty input path is trea= ted + exactly the same as ".". + + @param[in, out] Path On input, a pointer to some file or directory path= . On + output, a pointer to the clean and possibly fully- + qualified version of the input path. The input po= inter + may be freed and reassigned on output. + + @retval NULL The input pointer or the path itself was NULL. + + @return A pointer to the clean, fully-qualified version of Path. If mem= ory + allocation fails, or if there is no working directory, then a po= inter + to the clean, but not necessarily fully-qualified version of Pat= h. +**/ +CHAR16* +EFIAPI +FullyQualifyPath( + IN OUT CHAR16 **Path + ); + /** This function will retrieve the information about the file for the handl= e specified and store it in allocated pool memory. diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Librar= y/UefiShellLib/UefiShellLib.c index f04adbb63f..52ca3ce1b1 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -2,7 +2,7 @@ Provides interface to shell functionality for shell commands and applica= tions. =20 (C) Copyright 2016 Hewlett Packard Enterprise Development LP
- Copyright 2016 Dell Inc. + Copyright 2016-2018 Dell Technologies.
Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License @@ -36,6 +36,97 @@ EFI_HANDLE mEfiShellEnvironment2Handl= e; FILE_HANDLE_FUNCTION_MAP FileFunctionMap; EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationProtocol; =20 +/** + Return the fully-qualified version of a relative path or an absolute pat= h that + does not include a file system reference. + + If asserts are disabled, and if the input parameter is NULL or points to= NULL, + then NULL is returned. + + If the input path contains a ":", this function assumes that it is part = of a + reference to a file system (e.g. "FS0:"). In such a case, Path is clean= ed + and returned. + + If there is no working directory or there is not enough memory available= to + create the fully-qualified path, Path is cleaned and returned. + + Otherwise, the current file system or working directory (as appropriate)= is + prepended to Path. The input Path is freed and the resulting path is cl= eaned, + assigned to Path, and returned. + + NOTE: If the input path is an empty string, then the current working dir= ectory + (if it exists) is returned. In other words, an empty input path is trea= ted + exactly the same as ".". + + @param[in, out] Path On input, a pointer to some file or directory path= . On + output, a pointer to the clean and possibly fully- + qualified version of the input path. The input po= inter + may be freed and reassigned on output. + + @retval NULL The input pointer or the path itself was NULL. + + @return A pointer to the clean, fully-qualified version of Path. If mem= ory + allocation fails, or if there is no working directory, then a po= inter + to the clean, but not necessarily fully-qualified version of Pat= h. +**/ +CHAR16* +EFIAPI +FullyQualifyPath( + IN OUT CHAR16 **Path + ) +{ + CONST CHAR16 *WorkingPath; + CHAR16 *FullyQualifiedPath; + UINTN Size; + + ASSERT(Path !=3D NULL); + ASSERT(*Path !=3D NULL); + + // + // Handle erroneous input when asserts are disabled. + // + if (Path =3D=3D NULL || *Path =3D=3D NULL) { + return NULL; + } + + if (StrStr(*Path, L":") =3D=3D NULL) { + WorkingPath =3D ShellGetEnvironmentVariable(L"cwd"); + if (WorkingPath !=3D NULL) { + // + // Room for both strings plus one more character. + // + Size =3D StrSize(WorkingPath) + StrSize(*Path); + FullyQualifiedPath =3D AllocateZeroPool(Size); + if (FullyQualifiedPath !=3D NULL) { + if (**Path =3D=3D L'\\' || **Path =3D=3D L'/') { + // + // Absolute path: start with the current working directory, then + // truncate the new path after the file system part. + // + StrCpyS(FullyQualifiedPath, Size/sizeof(CHAR16), WorkingPath); + *(StrStr(FullyQualifiedPath, L":") + 1) =3D CHAR_NULL; + } else { + // + // Relative path: start with the working directory and append "\= ". + // + StrCpyS(FullyQualifiedPath, Size/sizeof(CHAR16), WorkingPath); + StrCatS(FullyQualifiedPath, Size/sizeof(CHAR16), L"\\"); + } + // + // Now append the absolute or relative path. + // + StrCatS(FullyQualifiedPath, Size/sizeof(CHAR16), *Path); + FreePool(*Path); + *Path =3D FullyQualifiedPath; + } + } + } + + PathCleanUpDirectories(*Path); + + return *Path; +} + /** Check if a Unicode character is a hexadecimal character. =20 --=20 2.17.0.windows.1