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 #ifndef STARTUP_INIT_TEST // do not install
25 InitModuleMgrInstall("selinuxadp");
26 #endif
27 return 0;
28 }
29
ServiceParseSelinuxHook(SERVICE_PARSE_CTX * serviceParseCtx)30 static void ServiceParseSelinuxHook(SERVICE_PARSE_CTX *serviceParseCtx)
31 {
32 char *fieldStr = cJSON_GetStringValue(cJSON_GetObjectItem(serviceParseCtx->serviceNode, SECON_STR_IN_CFG));
33 PLUGIN_CHECK(fieldStr != NULL, return, "No secon item in %s", serviceParseCtx->serviceName);
34 PLUGIN_LOGV("Cfg %s for %s", fieldStr, serviceParseCtx->serviceName);
35 DelServiceExtData(serviceParseCtx->serviceName, HOOK_ID_SELINUX);
36 AddServiceExtData(serviceParseCtx->serviceName, HOOK_ID_SELINUX, fieldStr, strlen(fieldStr) + 1);
37 }
38
MODULE_CONSTRUCTOR(void)39 MODULE_CONSTRUCTOR(void)
40 {
41 InitAddServiceParseHook(ServiceParseSelinuxHook);
42 InitAddGlobalInitHook(0, SelinuxHook);
43 }
44