1 /* 2 * Copyright (c) 2022-2024 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 #ifndef ACCESSTOKENMANAGER_COMMAND_H 17 #define ACCESSTOKENMANAGER_COMMAND_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <getopt.h> 22 #include <map> 23 #include <string> 24 #include <vector> 25 26 #include "access_token.h" 27 #include "atm_tools_param_info.h" 28 29 namespace OHOS { 30 namespace Security { 31 namespace AccessToken { 32 class AtmCommand final { 33 public: 34 AtmCommand(int32_t argc, char *argv[]); 35 virtual ~AtmCommand() = default; 36 37 std::string ExecCommand(); 38 39 private: 40 std::string GetCommandErrorMsg() const; 41 int32_t RunAsCommandError(void); 42 std::string GetUnknownOptionMsg() const; 43 int32_t RunAsCommandMissingOptionArgument(void); 44 void RunAsCommandExistentOptionArgument(const int32_t& option, AtmToolsParamInfo& info); 45 std::string DumpRecordInfo(uint32_t tokenId, const std::string& permissionName); 46 std::string DumpUsedTypeInfo(uint32_t tokenId, const std::string& permissionName); 47 int32_t ModifyPermission(const OptType& type, AccessTokenID tokenId, const std::string& permissionName); 48 int32_t RunCommandByOperationType(const AtmToolsParamInfo& info); 49 int32_t HandleComplexCommand(const std::string& shortOption, const struct option longOption[], 50 const std::string& helpMsg); 51 int32_t SetToggleStatus(int32_t userID, const std::string& permissionName, const uint32_t& status); 52 int32_t GetToggleStatus(int32_t userID, const std::string& permissionName, std::string& statusInfo); 53 54 int32_t RunAsHelpCommand(); 55 int32_t RunAsCommonCommand(); 56 57 int32_t argc_; 58 char** argv_; 59 60 std::string cmd_; 61 std::vector<std::string> argList_; 62 63 std::string name_; 64 std::map<std::string, std::function<int32_t()>> commandMap_; 65 66 std::string resultReceiver_; 67 }; 68 } // namespace AccessToken 69 } // namespace Security 70 } // namespace OHOS 71 72 #endif // ACCESSTOKENMANAGER_COMMAND_H 73