2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Janusz Kozerski (j.kozerski@samsung.com)
23 #include <ima-evm-server.h>
31 printf("Invalid param.\n");
36 printf("Too few arguments\n");
41 printf("Error occurced %d\n", i);
44 void print_policy(const char** policy)
48 printf("%s\n", policy[i]);
56 printf(" im-console option\n");
58 printf(" -h\t\t\tPrint this message\n");
59 printf(" -s ima|evm state\tSet state IMA or EVM\n");
60 printf(" \t\t\tThe state of IMA can be one of: dis|enf|ign|fix\n");
61 printf(" \t\t\tThe state of EVM can be one of: dis|ena|fix\n");
62 printf(" -g ima|evm\t\tGet state of IMA or EVM\n");
63 printf(" -p\t\t\tGet policy from the kernel\n");
64 printf(" -l file\t\tLoad policy from the file into the kernel\n");
65 printf(" \t\t\tThe signature of the policy should be present in location file.sig\n");
68 int ima_state_to_server(const char* state)
70 if (strcmp(state, "dis") == 0)
71 return IMA_SERVER_API_STATE_DISABLED;
72 else if (strcmp(state, "enf") == 0)
73 return IMA_SERVER_API_STATE_ENFORCE;
74 else if (strcmp(state, "ign") == 0)
75 return IMA_SERVER_API_STATE_IGNORE;
76 else if (strcmp(state, "fix") == 0)
77 return IMA_SERVER_API_STATE_FIX;
84 int evm_state_to_server(const char* state)
86 if (strcmp(state, "dis") == 0)
87 return EVM_SERVER_API_STATE_DISABLED;
88 else if (strcmp(state, "ena") == 0)
89 return EVM_SERVER_API_STATE_ENABLED;
90 else if (strcmp(state, "fix") == 0)
91 return EVM_SERVER_API_STATE_FIX;
98 const char* ima_state_from_server(int state)
101 case IMA_SERVER_API_STATE_DISABLED: return "DISABLED";
102 case IMA_SERVER_API_STATE_IGNORE: return "IGNORE";
103 case IMA_SERVER_API_STATE_ENFORCE: return "ENFORCE";
104 case IMA_SERVER_API_STATE_FIX: return "FIX";
105 default: return "UNKNOWN";
109 const char* evm_state_from_server(int state)
112 case EVM_SERVER_API_STATE_DISABLED: return "DISABLED";
113 case EVM_SERVER_API_STATE_ENABLED: return "ENABLED";
114 case EVM_SERVER_API_STATE_FIX: return "FIX";
115 default: return "UNKNOWN";
119 int is_ima_module(const char* arg)
121 if (strcmp("ima", arg) == 0 || strcmp("IMA", arg) == 0)
126 int main (int argc, const char* argv[])
134 if (argv[i][0] != '-'){
138 switch (argv[i][1]) {
139 case 'h': help(); return 0;
146 if (is_ima_module(argv[i]))
147 ret = ima_evm_server_set_ima_state(ima_state_to_server(argv[i+1]));
149 ret = ima_evm_server_set_evm_state(evm_state_to_server(argv[i+1]));
151 if (ret == IMA_EVM_SERVER_API_SUCCESS)
152 printf("State changed\n");
162 if (is_ima_module(argv[i])) {
163 ret = ima_evm_server_get_ima_state(&state);
164 if (ret == IMA_EVM_SERVER_API_SUCCESS)
165 printf("%s\n", ima_state_from_server(state));
167 ret = ima_evm_server_get_evm_state(&state);
168 if (ret == IMA_EVM_SERVER_API_SUCCESS)
169 printf("%s\n", evm_state_from_server(state));
171 if (ret != IMA_EVM_SERVER_API_SUCCESS)
175 ret = ima_evm_server_get_policy(&policy);
176 if (ret != IMA_EVM_SERVER_API_SUCCESS) {
180 print_policy(policy);
182 default: inval(); return 0;