1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 17 #include <iostream> 18 #include <sstream> 19 #include <vector> 20 #include <cstring> 21 #include "sandbox_manager_log.h" 22 23 namespace OHOS { 24 namespace AccessControl { 25 namespace SandboxManager { 26 27 #define MASK_INFO "***" 28 const std::string CURRENT_DIR = "."; 29 const std::string PARENT_DIR = ".."; 30 const std::string EMPTY_PATH = "empty path"; 31 const std::string NULL_PATH = "null path"; 32 MaskRealPath(const char * path)33std::string SandboxManagerLog::MaskRealPath(const char *path) 34 { 35 if (path == nullptr) { 36 return NULL_PATH; 37 } 38 39 if (strlen(path) == 0) { 40 return EMPTY_PATH; 41 } 42 43 std::istringstream stream(path); 44 std::string part; 45 std::string retStr; 46 47 while (std::getline(stream, part, '/')) { 48 if (!part.empty()) { 49 if (part == CURRENT_DIR || part == PARENT_DIR) { 50 retStr.append(part); 51 } else { 52 retStr.push_back(part[0]); 53 retStr.append(MASK_INFO); 54 } 55 retStr.append("/"); 56 } else { 57 /* means find "//" */ 58 retStr.append("/"); 59 } 60 } 61 62 if (path[strlen(path) - 1] != '/') { 63 retStr.pop_back(); 64 } 65 66 return retStr; 67 } 68 69 } // namespace SandboxManager 70 } // namespace AccessControl 71 } // namespace OHOS 72