• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef SELINUX_PARAMETER_H
17 #define SELINUX_PARAMETER_H
18 
19 #include <sys/socket.h>
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26 
27 typedef struct ParameterNode {
28     char *paraName;
29     char *paraContext;
30 } ParameterNode;
31 
32 typedef struct ParamContextsList {
33     struct ParameterNode info;
34     struct ParamContextsList *next;
35 } ParamContextsList;
36 
37 /**
38  * @brief set selinux log print to dmesg
39  */
40 void SetSelinuxLogCallback(void);
41 
42 /**
43  * @brief get param context list, for context-named files generate
44  * free with DestroyParamList
45  *
46  * @return head of param context list
47  */
48 ParamContextsList *GetParamList(void);
49 
50 /**
51  * @brief destroy param list get from GetParamList
52  *
53  * @param list the head of contexts list
54  */
55 void DestroyParamList(ParamContextsList **list);
56 
57 /**
58  * @brief for a particular paraName, get its context
59  *
60  * @param paraName the name of param
61  * @param context the selinux context of param, must free it after use
62  *
63  * @return 0 for success, or an error code
64  */
65 int GetParamLabel(const char *paraName, char **context);
66 
67 /**
68  * @brief for read particular paraName, check its selinux permmisson
69  *
70  * @param paraName the name of param
71  * @return 0 for success, or an error code
72  */
73 int ReadParamCheck(const char *paraName);
74 
75 /**
76  * @brief for write particular paraName, get its context
77  *
78  * @param paraName the name of param
79  * @param uc contains pid, uid, gid info
80  * @return 0 for success, or an error code
81  */
82 int SetParamCheck(const char *paraName, struct ucred *uc);
83 
84 #ifdef __cplusplus
85 #if __cplusplus
86 }
87 #endif /* __cplusplus */
88 #endif /* __cplusplus */
89 
90 #endif // SELINUX_PARAMETER_H
91