| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include <sys/stat.h> |
| 5 |
|
| 6 |
#include "basic-forward.h" |
| 7 |
|
| 8 |
typedef enum ConfFilesFlags { |
| 9 |
CONF_FILES_EXECUTABLE = 1 << 0, /* inode must be marked executable */ |
| 10 |
CONF_FILES_REGULAR = 1 << 1, /* inode must be regular file */ |
| 11 |
CONF_FILES_DIRECTORY = 1 << 2, /* inode must be directory */ |
| 12 |
CONF_FILES_BASENAME = 1 << 3, /* only return basename of file, not full path */ |
| 13 |
CONF_FILES_FILTER_MASKED_BY_SYMLINK = 1 << 4, /* implement /dev/null symlink based masking */ |
| 14 |
CONF_FILES_FILTER_MASKED_BY_EMPTY = 1 << 5, /* implement masking by empty file */ |
| 15 |
CONF_FILES_FILTER_MASKED = CONF_FILES_FILTER_MASKED_BY_SYMLINK | CONF_FILES_FILTER_MASKED_BY_EMPTY, |
| 16 |
CONF_FILES_TRUNCATE_SUFFIX = 1 << 6, /* truncate specified suffix from return filename or path */ |
| 17 |
CONF_FILES_WARN = 1 << 7, /* warn on some errors */ |
| 18 |
CONF_FILES_DONT_PREFIX_ROOT = 1 << 8, /* don't prefix the specified root path to the resulting paths */ |
| 19 |
} ConfFilesFlags; |
| 20 |
|
| 21 |
typedef struct ConfFile { |
| 22 |
char *filename; /* filename of the discovered file (i.e. without any directory prefix) */ |
| 23 |
char *result; /* full path to the file (with the directory prefix fully resolved, but the filename part left as is) */ |
| 24 |
char *original_path; /* full path to the file (original – non-resolved – directory prefix + filename part left as is) */ |
| 25 |
char *resolved_path; /* fully resolved path to the file with both directory prefix and filename fully resolved */ |
| 26 |
int fd; /* O_PATH fd to resolved_path, -EBADF if resolved_path does not exist */ |
| 27 |
struct stat st; /* stat of the file. */ |
| 28 |
} ConfFile; |
| 29 |
|
| 30 |
ConfFile* conf_file_free(ConfFile *c); |
| 31 |
DEFINE_TRIVIAL_CLEANUP_FUNC(ConfFile*, conf_file_free); |
| 32 |
void conf_file_free_array(ConfFile **array, size_t n); |
| 33 |
|
| 34 |
int conf_file_new_at(const char *path, const char *root, int rfd, ConfFilesFlags flags, ConfFile **ret); |
| 35 |
int conf_file_new(const char *path, const char *root, ConfFilesFlags flags, ConfFile **ret); |
| 36 |
|
| 37 |
int conf_files_list(char ***ret, const char *suffix, const char *root, ConfFilesFlags flags, const char *dir); |
| 38 |
int conf_files_list_at(char ***ret, const char *suffix, int rfd, ConfFilesFlags flags, const char *dir); |
| 39 |
int conf_files_list_strv(char ***ret, const char *suffix, const char *root, ConfFilesFlags flags, const char* const* dirs); |
| 40 |
int conf_files_list_strv_at(char ***ret, const char *suffix, int rfd, ConfFilesFlags flags, const char * const *dirs); |
| 41 |
int conf_files_list_nulstr(char ***ret, const char *suffix, const char *root, ConfFilesFlags flags, const char *dirs); |
| 42 |
int conf_files_list_nulstr_at(char ***ret, const char *suffix, int rfd, ConfFilesFlags flags, const char *dirs); |
| 43 |
|
| 44 |
int conf_files_list_full(const char *suffix, const char *root, ConfFilesFlags flags, const char *dir, ConfFile ***ret_files, size_t *ret_n_files); |
| 45 |
int conf_files_list_at_full(const char *suffix, int rfd, ConfFilesFlags flags, const char *dir, ConfFile ***ret_files, size_t *ret_n_files); |
| 46 |
int conf_files_list_strv_full(const char *suffix, const char *root, ConfFilesFlags flags, const char * const *dirs, ConfFile ***ret_files, size_t *ret_n_files); |
| 47 |
int conf_files_list_strv_at_full(const char *suffix, int rfd, ConfFilesFlags flags, const char * const *dirs, ConfFile ***ret_files, size_t *ret_n_files); |
| 48 |
int conf_files_list_nulstr_full(const char *suffix, const char *root, ConfFilesFlags flags, const char *dirs, ConfFile ***ret_files, size_t *ret_n_files); |
| 49 |
int conf_files_list_nulstr_at_full(const char *suffix, int rfd, ConfFilesFlags flags, const char *dirs, ConfFile ***ret_files, size_t *ret_n_files); |
| 50 |
|
| 51 |
int conf_files_list_with_replacement( |
| 52 |
const char *root, |
| 53 |
char **config_dirs, |
| 54 |
const char *replacement, |
| 55 |
char ***ret_files, |
| 56 |
char **ret_inserted); |
| 57 |
int conf_files_list_dropins( |
| 58 |
char ***ret, |
| 59 |
const char *dropin_dirname, |
| 60 |
const char *root, |
| 61 |
int root_fd, |
| 62 |
ConfFilesFlags flags, |
| 63 |
const char * const *dirs); |
| 64 |
|
| 65 |
typedef int parse_line_t( |
| 66 |
const char *fname, |
| 67 |
unsigned line, |
| 68 |
const char *buffer, |
| 69 |
bool *invalid_config, |
| 70 |
void *userdata); |
| 71 |
|
| 72 |
int conf_file_read( |
| 73 |
const char *root, |
| 74 |
const char **config_dirs, |
| 75 |
const char *fn, |
| 76 |
parse_line_t parse_line, |
| 77 |
void *userdata, |
| 78 |
bool ignore_enoent, |
| 79 |
bool *invalid_config); |