1fc0b0055Sopenharmony_ci/* 2fc0b0055Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3fc0b0055Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fc0b0055Sopenharmony_ci * you may not use this file except in compliance with the License. 5fc0b0055Sopenharmony_ci * You may obtain a copy of the License at 6fc0b0055Sopenharmony_ci * 7fc0b0055Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fc0b0055Sopenharmony_ci * 9fc0b0055Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fc0b0055Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fc0b0055Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fc0b0055Sopenharmony_ci * See the License for the specific language governing permissions and 13fc0b0055Sopenharmony_ci * limitations under the License. 14fc0b0055Sopenharmony_ci */ 15fc0b0055Sopenharmony_ci 16fc0b0055Sopenharmony_ci#ifndef ACCESSTOKENMANAGER_COMMAND_H 17fc0b0055Sopenharmony_ci#define ACCESSTOKENMANAGER_COMMAND_H 18fc0b0055Sopenharmony_ci 19fc0b0055Sopenharmony_ci#include <cstdint> 20fc0b0055Sopenharmony_ci#include <functional> 21fc0b0055Sopenharmony_ci#include <getopt.h> 22fc0b0055Sopenharmony_ci#include <map> 23fc0b0055Sopenharmony_ci#include <string> 24fc0b0055Sopenharmony_ci#include <vector> 25fc0b0055Sopenharmony_ci 26fc0b0055Sopenharmony_ci#include "access_token.h" 27fc0b0055Sopenharmony_ci#include "atm_tools_param_info.h" 28fc0b0055Sopenharmony_ci 29fc0b0055Sopenharmony_cinamespace OHOS { 30fc0b0055Sopenharmony_cinamespace Security { 31fc0b0055Sopenharmony_cinamespace AccessToken { 32fc0b0055Sopenharmony_ciclass AtmCommand final { 33fc0b0055Sopenharmony_cipublic: 34fc0b0055Sopenharmony_ci AtmCommand(int32_t argc, char *argv[]); 35fc0b0055Sopenharmony_ci virtual ~AtmCommand() = default; 36fc0b0055Sopenharmony_ci 37fc0b0055Sopenharmony_ci std::string ExecCommand(); 38fc0b0055Sopenharmony_ci 39fc0b0055Sopenharmony_ciprivate: 40fc0b0055Sopenharmony_ci std::string GetCommandErrorMsg() const; 41fc0b0055Sopenharmony_ci int32_t RunAsCommandError(void); 42fc0b0055Sopenharmony_ci std::string GetUnknownOptionMsg() const; 43fc0b0055Sopenharmony_ci int32_t RunAsCommandMissingOptionArgument(void); 44fc0b0055Sopenharmony_ci void RunAsCommandExistentOptionArgument(const int32_t& option, AtmToolsParamInfo& info); 45fc0b0055Sopenharmony_ci std::string DumpRecordInfo(uint32_t tokenId, const std::string& permissionName); 46fc0b0055Sopenharmony_ci std::string DumpUsedTypeInfo(uint32_t tokenId, const std::string& permissionName); 47fc0b0055Sopenharmony_ci int32_t ModifyPermission(const OptType& type, AccessTokenID tokenId, const std::string& permissionName); 48fc0b0055Sopenharmony_ci int32_t RunCommandByOperationType(const AtmToolsParamInfo& info); 49fc0b0055Sopenharmony_ci int32_t HandleComplexCommand(const std::string& shortOption, const struct option longOption[], 50fc0b0055Sopenharmony_ci const std::string& helpMsg); 51fc0b0055Sopenharmony_ci int32_t SetToggleStatus(int32_t userID, const std::string& permissionName, const uint32_t& status); 52fc0b0055Sopenharmony_ci int32_t GetToggleStatus(int32_t userID, const std::string& permissionName, std::string& statusInfo); 53fc0b0055Sopenharmony_ci 54fc0b0055Sopenharmony_ci int32_t RunAsHelpCommand(); 55fc0b0055Sopenharmony_ci int32_t RunAsCommonCommand(); 56fc0b0055Sopenharmony_ci 57fc0b0055Sopenharmony_ci int32_t argc_; 58fc0b0055Sopenharmony_ci char** argv_; 59fc0b0055Sopenharmony_ci 60fc0b0055Sopenharmony_ci std::string cmd_; 61fc0b0055Sopenharmony_ci std::vector<std::string> argList_; 62fc0b0055Sopenharmony_ci 63fc0b0055Sopenharmony_ci std::string name_; 64fc0b0055Sopenharmony_ci std::map<std::string, std::function<int32_t()>> commandMap_; 65fc0b0055Sopenharmony_ci 66fc0b0055Sopenharmony_ci std::string resultReceiver_; 67fc0b0055Sopenharmony_ci}; 68fc0b0055Sopenharmony_ci} // namespace AccessToken 69fc0b0055Sopenharmony_ci} // namespace Security 70fc0b0055Sopenharmony_ci} // namespace OHOS 71fc0b0055Sopenharmony_ci 72fc0b0055Sopenharmony_ci#endif // ACCESSTOKENMANAGER_COMMAND_H 73