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 #include "selinux_adp.h"
16
17 #include "init_hook.h"
18 #include "init_module_engine.h"
19 #include "plugin_adapter.h"
20
SelinuxHook(const HOOK_INFO * hookInfo,void * cookie)21 static int SelinuxHook(const HOOK_INFO *hookInfo, void *cookie)
22 {
23 PLUGIN_LOGI("Install selinuxadp.");
24 InitModuleMgrInstall("selinuxadp");
25 return 0;
26 }
27
ServiceParseSelinuxHook(SERVICE_PARSE_CTX * serviceParseCtx)28 static void ServiceParseSelinuxHook(SERVICE_PARSE_CTX *serviceParseCtx)
29 {
30 char *fieldStr = cJSON_GetStringValue(cJSON_GetObjectItem(serviceParseCtx->serviceNode, SECON_STR_IN_CFG));
31 PLUGIN_CHECK(fieldStr != NULL, return, "No secon item in %s", serviceParseCtx->serviceName);
32 PLUGIN_LOGV("Cfg %s for %s", fieldStr, serviceParseCtx->serviceName);
33 DelServiceExtData(serviceParseCtx->serviceName, HOOK_ID_SELINUX);
34 AddServiceExtData(serviceParseCtx->serviceName, HOOK_ID_SELINUX, fieldStr, strlen(fieldStr) + 1);
35 }
36
MODULE_CONSTRUCTOR(void)37 MODULE_CONSTRUCTOR(void)
38 {
39 InitAddServiceParseHook(ServiceParseSelinuxHook);
40 InitAddGlobalInitHook(0, SelinuxHook);
41 }
42