summaryrefslogtreecommitdiffstats
path: root/src/util/sss_ini.h
blob: 4e3f67fd6d358345dd3f11a1a0a5b37ba4418bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
    SSSD

    sss_ini.c

    Authors:
        Ondrej Kos <okos@redhat.com>

    Copyright (C) 2013 Red Hat


    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef __SSS_INI_H__
#define __SSS_INI_H__

#include <stdbool.h>

/**
 * @brief INI data structure
 */
struct sss_ini;

/**
 * @brief create new ini data object
 *
 * @param[in] tmp_ctx  talloc context
 *
 * @return
 *  - pointer to newly allocated and initialized structure
 *  - NULL in case of error
 */
struct sss_ini* sss_ini_new(TALLOC_CTX *tmp_ctx);


/**
 * @brief Open ini file or use fallback_cfg if file is not present. Include
 *        configuration snippets and perform access check.
 *
 * @param[in] self          pointer to sss_ini structure
 * @param[in] config_file   ini file
 * @param[in] config_dir    directory containing ini files to be included
 *
 * @return
 *  - EOK - success
 *  - ERR_INI_OPEN_FAILED - sss_ini_open failed
 *  - ERR_INI_INVALID_PERMISSION - access check failed
 *  - ERR_INI_PARSE_FAILED - failed to parse configuration file
 *  - ERR_INI_ADD_SNIPPETS_FAILED - failed to add configuration snippets
 */
int sss_ini_read_sssd_conf(struct sss_ini *self,
                           const char *config_file,
                           const char *config_dir);

/**
 * @brief Open ini file or use fallback_cfg if file is not present
 *
 * @param[in] self          pointer to sss_ini structure
 * @param[in] config_file   ini file
 * @param[in] fallback_cfg  string with ini content. This parameter is used
 *                          when config_file doesn't exist or it is set to NULL
 *
 * @return error code
 */
int sss_ini_open(struct sss_ini *self,
                 const char *config_file,
                 const char *fallback_cfg);

/**
 * @brief Check whether sss_ini_open() reported that ini file is
 *        not present
 *
 * @param[in] self  pointer to sss_ini structure
 *
 * @return
 *   - true   we are using ini file
 *   - false  file was not found
 */
bool sss_ini_exists(struct sss_ini *self);

/**
 * @brief get Cstat structure of the ini file
 */
int sss_ini_get_stat(struct sss_ini *self);

/**
 * @brief Get mtime of the ini file
 */
int sss_ini_get_mtime(struct sss_ini *self,
                      size_t timestr_len,
                      char *timestr);

/**
 * @brief Get pointer to list of snippet parsing errors
 */
struct ref_array *
sss_ini_get_ra_error_list(struct sss_ini *self);

/**
 * @brief Get pointer to list of successfully merged snippet files
 */
struct ref_array *
sss_ini_get_ra_success_list(struct sss_ini *self);

/**
 * @brief Get configuration object
 */
int sss_ini_get_cfgobj(struct sss_ini *self,
                       const char *section, const char *name);

/**
 * @brief Check configuration object
 */
int sss_ini_check_config_obj(struct sss_ini *self);

/**
 * @brief Get int value
 */
int sss_ini_get_int_config_value(struct sss_ini *self,
                                 int strict, int def, int *error);

/**
 * @brief Get string value
 */
const char *sss_ini_get_string_config_value(struct sss_ini *self,
                                            int *error);

/**
 * @brief Create LDIF
 */
int sss_confdb_create_ldif(TALLOC_CTX *mem_ctx,
                           struct sss_ini *self,
                           const char *only_section,
                           const char **config_ldif);

/**
 * @brief Validate sssd.conf if libini_config support it
 */
int sss_ini_call_validators(struct sss_ini *data,
                            const char *rules_path);

/**
 * @brief Get errors from validators in array of strings
 */
int sss_ini_call_validators_strs(TALLOC_CTX *mem_ctx,
                                 struct sss_ini *data,
                                 const char *rules_path,
                                 char ***_strs,
                                 size_t *_num_errors);

#endif /* __SSS_INI_H__ */