param_manager.h 4.7 KB
Newer Older
Z
zhong_ning 已提交
1
/*
M
Mupceet 已提交
2
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
Z
zhong_ning 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef BASE_STARTUP_PARAM_MANAGER_H
#define BASE_STARTUP_PARAM_MANAGER_H
M
Mupceet 已提交
18
#include <pthread.h>
Z
zhong_ning 已提交
19 20 21
#include <stdio.h>
#include <string.h>

M
Mupceet 已提交
22 23 24
#include "init_param.h"
#include "list.h"
#include "param_osadp.h"
S
sun_fan 已提交
25 26
#include "param_persist.h"
#include "param_security.h"
Z
zhong_ning 已提交
27
#include "param_trie.h"
S
sun_fan 已提交
28 29
#include "param_utils.h"

Z
zhong_ning 已提交
30 31 32 33 34 35
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

M
Mupceet 已提交
36 37
#define WORKSPACE_NAME_DAC "param_sec_dac"
#define WORKSPACE_NAME_DEF_SELINUX "u:object_r:default_param:s0"
M
Mupceet 已提交
38 39 40 41 42
#ifndef PARAM_SUPPORT_SELINUX
#define WORKSPACE_NAME_NORMAL "param_storage"
#else
#define WORKSPACE_NAME_NORMAL WORKSPACE_NAME_DEF_SELINUX
#endif
M
Mupceet 已提交
43 44 45 46 47

#define PARAM_NEED_CHECK_IN_SERVICE 0x2
#define PARAM_CTRL_SERVICE 0x1

#define PARAM_WORKSPACE_CHECK(space, exper, ...) \
M
Mupceet 已提交
48
    if (((*space).flags & WORKSPACE_FLAGS_INIT) != WORKSPACE_FLAGS_INIT) { \
M
Mupceet 已提交
49 50 51
        PARAM_LOGE(__VA_ARGS__);     \
        exper;                       \
    }
Z
zhong_ning 已提交
52 53

typedef struct {
S
sun_fan 已提交
54
    uint32_t flags;
M
Mupceet 已提交
55 56 57 58 59 60 61 62 63 64
    ParamSecurityLabel securityLabel;
    ParamSecurityOps paramSecurityOps[PARAM_SECURITY_MAX];
    HashMapHandle workSpaceHashHandle;
    ListHead workSpaceList;
#ifdef PARAMWORKSPACE_NEED_MUTEX
    ParamRWMutex rwlock;
#endif
} ParamWorkSpace;

typedef struct {
S
sun_fan 已提交
65 66
    ParamTaskPtr serverTask;
    ParamTaskPtr timer;
X
xionglei6 已提交
67
    ParamTaskPtr watcherTask;
M
Mupceet 已提交
68
} ParamService;
Z
zhong_ning 已提交
69 70

typedef struct {
S
sun_fan 已提交
71
    uint32_t flags;
M
Mupceet 已提交
72
    long long commitId;
S
sun_fan 已提交
73 74 75
    ParamTaskPtr saveTimer;
    time_t lastSaveTimer;
    PersistParamOps persistParamOps;
Z
zhong_ning 已提交
76 77
} ParamPersistWorkSpace;

M
Mupceet 已提交
78 79 80 81 82 83 84
typedef struct {
    char realKey[PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 1];
    char cmdName[32];
    uint32_t valueOffset;
    uint8_t ctrlParam;
} ServiceCtrlInfo;

4
411148299@qq.com 已提交
85
typedef void (*TraversalParamPtr)(ParamHandle handle, void *context);
Z
zhong_ning 已提交
86 87
typedef struct {
    TraversalParamPtr traversalParamPtr;
4
411148299@qq.com 已提交
88
    void *context;
M
Mupceet 已提交
89
    char *prefix;
Z
zhong_ning 已提交
90 91
} ParamTraversalContext;

M
Mupceet 已提交
92 93 94 95 96 97
INIT_LOCAL_API int AddWorkSpace(const char *name, int onlyRead, uint32_t spacesize);
INIT_LOCAL_API WorkSpace *GetFirstWorkSpace(void);
INIT_LOCAL_API WorkSpace *GetNextWorkSpace(WorkSpace *curr);
INIT_LOCAL_API WorkSpace *GetWorkSpace(const char *name);
INIT_LOCAL_API ParamTrieNode *GetTrieNodeByHandle(ParamHandle handle);
INIT_LOCAL_API int ReadParamWithCheck(const char *name, uint32_t op, ParamHandle *handle);
M
Mupceet 已提交
98
INIT_LOCAL_API int CheckParamValue(const ParamTrieNode *node, const char *name, const char *value, uint8_t paramType);
M
Mupceet 已提交
99
INIT_LOCAL_API int CheckParamName(const char *name, int paramInfo);
M
Mupceet 已提交
100
INIT_LOCAL_API uint8_t GetParamValueType(const char *name);
M
Mupceet 已提交
101 102 103 104 105 106 107 108 109 110 111 112

INIT_LOCAL_API ParamNode *SystemCheckMatchParamWait(const char *name, const char *value);
INIT_LOCAL_API int WriteParam(const char *name, const char *value, uint32_t *dataIndex, int onlyAdd);
INIT_LOCAL_API int AddSecurityLabel(const ParamAuditData *auditData);
INIT_LOCAL_API ParamSecurityLabel *GetParamSecurityLabel(void);

INIT_LOCAL_API void LoadParamFromBuild(void);
INIT_LOCAL_API int LoadParamFromCmdLine(void);
INIT_LOCAL_API int InitPersistParamWorkSpace(void);
INIT_LOCAL_API void ClosePersistParamWorkSpace(void);
INIT_LOCAL_API int WritePersistParam(const char *name, const char *value);

M
Mupceet 已提交
113
INIT_LOCAL_API int CheckParameterSet(const char *name, const char *value,
M
Mupceet 已提交
114 115 116 117 118 119 120 121 122 123
    const ParamSecurityLabel *srcLabel, int *ctrlService);
INIT_INNER_API ParamHandle GetParamHandle(const WorkSpace *workSpace, uint32_t index, const char *name);
INIT_INNER_API int CheckParamPermission(const ParamSecurityLabel *srcLabel, const char *name, uint32_t mode);
INIT_INNER_API int InitParamWorkSpace(int onlyRead);
INIT_INNER_API void CloseParamWorkSpace(void);
INIT_INNER_API const char *GetSelinuxContent(const char *name);
INIT_INNER_API ParamWorkSpace *GetParamWorkSpace(void);

INIT_INNER_API int GetParamSecurityAuditData(const char *name, int type, ParamAuditData *auditData);
INIT_INNER_API int SysCheckParamExist(const char *name);
M
Mupceet 已提交
124 125
INIT_LOCAL_API int GetServiceCtrlInfo(const char *name, const char *value, ServiceCtrlInfo **ctrlInfo);

M
Mupceet 已提交
126 127 128
#ifdef STARTUP_INIT_TEST
ParamService *GetParamService();
#endif
Z
zhong_ning 已提交
129 130 131 132 133 134
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif