16cd6a6acSopenharmony_ci/*
26cd6a6acSopenharmony_ci* Copyright (c) 2024 Huawei Device Co., Ltd.
36cd6a6acSopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License");
46cd6a6acSopenharmony_ci* you may not use this file except in compliance with the License.
56cd6a6acSopenharmony_ci* You may obtain a copy of the License at
66cd6a6acSopenharmony_ci*
76cd6a6acSopenharmony_ci*   http://www.apache.org/licenses/LICENSE-2.0
86cd6a6acSopenharmony_ci*
96cd6a6acSopenharmony_ci* Unless required by applicable law or agreed to in writing, software
106cd6a6acSopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS,
116cd6a6acSopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126cd6a6acSopenharmony_ci* See the License for the specific language governing permissions and
136cd6a6acSopenharmony_ci* limitations under the License.
146cd6a6acSopenharmony_ci*/
156cd6a6acSopenharmony_ci
166cd6a6acSopenharmony_ci#ifndef _IGNORE_PATH_H_
176cd6a6acSopenharmony_ci#define _IGNORE_PATH_H_
186cd6a6acSopenharmony_ci
196cd6a6acSopenharmony_ci#include <stdbool.h>
206cd6a6acSopenharmony_ci#include <stddef.h>
216cd6a6acSopenharmony_ci#define SLASH_SUFFIX_LEN 1
226cd6a6acSopenharmony_ci#define STAR_SUFFIX_LEN 2
236cd6a6acSopenharmony_ci#define SYSTEM_IGNORE_CFG_PATH "/system/etc/selinux/ignore_cfg"
246cd6a6acSopenharmony_ci#define VENDOR_IGNORE_CFG_PATH "/vendor/etc/selinux/ignore_cfg"
256cd6a6acSopenharmony_ci
266cd6a6acSopenharmony_cienum skip_type {
276cd6a6acSopenharmony_ci    SKIP_NONE = 0,
286cd6a6acSopenharmony_ci    SKIP_SUB_DIR = 1,
296cd6a6acSopenharmony_ci    SKIP_SELF_SUB_DIR = 2
306cd6a6acSopenharmony_ci};
316cd6a6acSopenharmony_ci
326cd6a6acSopenharmony_citypedef struct ignore_path_node {
336cd6a6acSopenharmony_ci    char *path;
346cd6a6acSopenharmony_ci    struct ignore_path_node *next;
356cd6a6acSopenharmony_ci} ignore_path_node_t;
366cd6a6acSopenharmony_ci
376cd6a6acSopenharmony_citypedef struct ignore_paths {
386cd6a6acSopenharmony_ci    ignore_path_node_t *slash_suffix_paths;
396cd6a6acSopenharmony_ci    ignore_path_node_t *star_suffix_paths;
406cd6a6acSopenharmony_ci} ignore_paths_t;
416cd6a6acSopenharmony_ci
426cd6a6acSopenharmony_ciignore_path_node_t *insert_ignore_path(ignore_path_node_t **paths_ptr, const char *line);
436cd6a6acSopenharmony_cisize_t trim_newline(char *str);
446cd6a6acSopenharmony_ci
456cd6a6acSopenharmony_citypedef struct path_info {
466cd6a6acSopenharmony_ci    ignore_path_node_t **paths_ptr;
476cd6a6acSopenharmony_ci    unsigned int suffix_len;
486cd6a6acSopenharmony_ci} path_info_t;
496cd6a6acSopenharmony_ci
506cd6a6acSopenharmony_cipath_info_t trim_suffix_and_get_path_info(char *line, size_t real_length);
516cd6a6acSopenharmony_cibool load_ignore_cfg_from_file(const char *cfg_path);
526cd6a6acSopenharmony_cibool load_ignore_cfg();
536cd6a6acSopenharmony_cienum skip_type skip_ignore_relabel(const char *path);
546cd6a6acSopenharmony_civoid free_ignore_list(ignore_path_node_t **list_ptr);
556cd6a6acSopenharmony_ci
566cd6a6acSopenharmony_ci#endif // IGNORE_PATH_H
57