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 #pragma once 20 21 #include <sys/socket.h> 22 23 #ifdef __cplusplus 24 #if __cplusplus 25 extern "C" { 26 #endif 27 #endif 28 29 typedef struct ParameterNode { 30 const char *paraName; 31 const char *paraContext; 32 int index; 33 } ParameterNode; 34 35 typedef struct ParamContextsList { 36 struct ParameterNode info; 37 struct ParamContextsList *next; 38 } ParamContextsList; 39 40 typedef struct SrcInfo { 41 int sockFd; 42 struct ucred uc; 43 } SrcInfo; 44 45 /** 46 * @brief init param selinux 47 * 48 * @param isInit is init process 49 */ 50 int InitParamSelinux(int isInit); 51 52 /** 53 * @brief get param context list, for context-named files generate 54 * free with DestroyParamList 55 * 56 * @return head of param context list 57 */ 58 ParamContextsList *GetParamList(void); 59 60 /** 61 * @brief destroy param list get from GetParamList 62 * 63 * @param list the head of contexts list 64 */ 65 void DestroyParamList(ParamContextsList **list); 66 67 /** 68 * @brief for a particular paraName, get its context 69 * 70 * @param paraName the name of param 71 * 72 * @return context for given paraName 73 */ 74 const char *GetParamLabel(const char *paraName); 75 /** 76 * @brief for a particular paraName, get its context index 77 * 78 * @param paraName the name of param 79 * 80 * @return context index for given paraName 81 */ 82 int GetParamLabelIndex(const char *paraName); 83 84 #ifdef __cplusplus 85 #if __cplusplus 86 } 87 #endif /* __cplusplus */ 88 #endif /* __cplusplus */ 89 90 #endif // SELINUX_PARAMETER_H 91