param_manager.h 4.2 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 38 39 40 41 42 43
#define WORKSPACE_NAME_DAC "param_sec_dac"
#define WORKSPACE_NAME_NORMAL "param_storage"
#define WORKSPACE_NAME_DEF_SELINUX "u:object_r:default_param:s0"

#define PARAM_NEED_CHECK_IN_SERVICE 0x2
#define PARAM_CTRL_SERVICE 0x1

#define PARAM_WORKSPACE_CHECK(space, exper, ...) \
M
Mupceet 已提交
44
    if (((*space).flags & WORKSPACE_FLAGS_INIT) != WORKSPACE_FLAGS_INIT) { \
M
Mupceet 已提交
45 46 47
        PARAM_LOGE(__VA_ARGS__);     \
        exper;                       \
    }
Z
zhong_ning 已提交
48 49

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

typedef struct {
S
sun_fan 已提交
61 62
    ParamTaskPtr serverTask;
    ParamTaskPtr timer;
X
xionglei6 已提交
63
    ParamTaskPtr watcherTask;
M
Mupceet 已提交
64
} ParamService;
Z
zhong_ning 已提交
65 66

typedef struct {
S
sun_fan 已提交
67
    uint32_t flags;
M
Mupceet 已提交
68
    long long commitId;
S
sun_fan 已提交
69 70 71
    ParamTaskPtr saveTimer;
    time_t lastSaveTimer;
    PersistParamOps persistParamOps;
Z
zhong_ning 已提交
72 73
} ParamPersistWorkSpace;

4
411148299@qq.com 已提交
74
typedef void (*TraversalParamPtr)(ParamHandle handle, void *context);
Z
zhong_ning 已提交
75 76
typedef struct {
    TraversalParamPtr traversalParamPtr;
4
411148299@qq.com 已提交
77
    void *context;
M
Mupceet 已提交
78
    char *prefix;
Z
zhong_ning 已提交
79 80
} ParamTraversalContext;

M
Mupceet 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
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);
INIT_LOCAL_API int CheckParamValue(const ParamTrieNode *node, const char *name, const char *value);
INIT_LOCAL_API int CheckParamName(const char *name, int paramInfo);

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);

INIT_INNER_API int CheckParameterSet(const char *name, const char *value,
    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 已提交
112 113 114
#ifdef STARTUP_INIT_TEST
ParamService *GetParamService();
#endif
Z
zhong_ning 已提交
115 116 117 118 119 120
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif