1 /* 2 * Copyright (c) 2024 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 _IGNORE_PATH_H_ 17 #define _IGNORE_PATH_H_ 18 19 #include <stdbool.h> 20 #include <stddef.h> 21 #define SLASH_SUFFIX_LEN 1 22 #define STAR_SUFFIX_LEN 2 23 #define SYSTEM_IGNORE_CFG_PATH "/system/etc/selinux/ignore_cfg" 24 #define VENDOR_IGNORE_CFG_PATH "/vendor/etc/selinux/ignore_cfg" 25 26 enum SkipType { 27 SKIP_NONE = 0, 28 SKIP_SUB_DIR = 1, 29 SKIP_SELF_SUB_DIR = 2 30 }; 31 32 typedef struct ignore_path_node { 33 char *path; 34 struct ignore_path_node *next; 35 } ignore_path_node_t; 36 37 typedef struct ignore_paths { 38 ignore_path_node_t *slash_suffix_paths; 39 ignore_path_node_t *star_suffix_paths; 40 } ignore_paths_t; 41 42 ignore_path_node_t *insert_ignore_path(ignore_path_node_t **paths_ptr, const char *line); 43 size_t trim_newline(char *str); 44 45 typedef struct path_info { 46 ignore_path_node_t **paths_ptr; 47 int suffix_len; 48 } path_info_t; 49 50 path_info_t trim_suffix_and_get_path_info(char *line, size_t real_length); 51 bool load_ignore_cfg_from_file(const char *cfg_path); 52 bool load_ignore_cfg(); 53 enum SkipType skip_ignore_relabel(const char *path); 54 void free_ignore_list(ignore_path_node_t **list_ptr); 55 56 #endif // IGNORE_PATH_H 57