• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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     int32_t RunAsCommandExistentOptionArgument(const int32_t& option, AtmToolsParamInfo& info);
45     std::string DumpRecordInfo(uint32_t tokenId, const std::string& permissionName);
46     int32_t ModifyPermission(const OptType& type, AccessTokenID tokenId, const std::string& permissionName);
47     int32_t RunCommandByOperationType(const AtmToolsParamInfo& info);
48     int32_t HandleComplexCommand(const std::string& shortOption, const struct option longOption[],
49         const std::string& helpMsg);
50 
51     int32_t RunAsHelpCommand();
52     int32_t RunAsCommonCommand();
53 
54     int32_t argc_;
55     char** argv_;
56 
57     std::string cmd_;
58     std::vector<std::string> argList_;
59 
60     std::string name_;
61     std::map<std::string, std::function<int32_t()>> commandMap_;
62 
63     std::string resultReceiver_;
64 };
65 } // namespace AccessToken
66 } // namespace Security
67 } // namespace OHOS
68 
69 #endif // ACCESSTOKENMANAGER_COMMAND_H
70