5 #include "k5-platform.h"
11 #if defined(__MACH__) && defined(__APPLE__)
12 #include <TargetConditionals.h>
13 #define PROFILE_SUPPORTS_FOREIGN_NEWLINES
19 typedef long prf_magic_t;
22 * This is the structure which stores the profile information for a
23 * particular configuration file.
26 * - filespec, fslen are fixed after creation
27 * - refcount and next should only be tweaked with the global lock held
28 * - other fields can be tweaked after grabbing the in-struct lock
33 struct profile_node *root;
35 time_t timestamp; /* time tree was last updated from file */
36 unsigned long frac_ts; /* fractional part of timestamp, if any */
37 int flags; /* r/w, dirty */
38 int upd_serial; /* incremented when data changes */
42 /* Some separation between fields controlled by different
43 mutexes. Theoretically, both could be accessed at the same
44 time from different threads on different CPUs with separate
45 caches. Don't let the threads clobber each other's
46 changes. One mutex controlling the whole thing would be
47 better, but sufficient separation might suffice.
49 This is icky. I just hope it's adequate.
51 For next major release, fix this. */
52 union { double d; void *p; uint64_t ll; k5_mutex_t m; } pad;
54 int refcount; /* prf_file_t references */
55 struct _prf_data_t *next;
56 /* Was: "profile_filespec_t filespec". Now: flexible char
57 array ... except, we need to work in C89, so an array
58 length must be specified. */
59 const char filespec[sizeof("/etc/krb5.conf")];
62 typedef struct _prf_data_t *prf_data_t;
63 prf_data_t profile_make_prf_data(const char *);
67 struct _prf_data_t *data;
68 struct _prf_file_t *next;
71 typedef struct _prf_file_t *prf_file_t;
76 * Deprecated use of read/write profile flag.
77 * Check whether file is writable lazily so we don't call access as often.
79 #define PROFILE_FILE_DEPRECATED_RW 0x0001
80 #define PROFILE_FILE_DIRTY 0x0002
81 #define PROFILE_FILE_SHARED 0x0004
83 struct _prf_lib_handle_t {
86 struct plugin_file_handle *plugin_handle;
89 typedef struct _prf_lib_handle_t *prf_lib_handle_t;
92 * This structure defines the high-level, user visible profile_t
93 * object, which is used as a handle by users who need to query some
94 * configuration file(s)
98 prf_file_t first_file;
100 /* If non-null, use vtable operations instead of native ones. */
101 struct profile_vtable *vt;
103 prf_lib_handle_t lib_handle;
107 * Used by the profile iterator in prof_get.c
109 #define PROFILE_ITER_LIST_SECTION 0x0001
110 #define PROFILE_ITER_SECTIONS_ONLY 0x0002
111 #define PROFILE_ITER_RELATIONS_ONLY 0x0004
113 #define PROFILE_ITER_FINAL_SEEN 0x0100
116 * Check if a filespec is last in a list (NULL on UNIX, invalid FSSpec on MacOS
119 #define PROFILE_LAST_FILESPEC(x) (((x) == NULL) || ((x)[0] == '\0'))
121 /* profile_parse.c */
123 errcode_t profile_parse_file
124 (FILE *f, struct profile_node **root, char **ret_modspec);
126 errcode_t profile_process_directory
127 (const char *dirname, struct profile_node **root);
129 errcode_t profile_write_tree_file
130 (struct profile_node *root, FILE *dstfile);
132 errcode_t profile_write_tree_to_buffer
133 (struct profile_node *root, char **buf);
138 void profile_free_node
139 (struct profile_node *relation);
141 errcode_t profile_create_node
142 (const char *name, const char *value,
143 struct profile_node **ret_node);
145 errcode_t profile_verify_node
146 (struct profile_node *node);
148 errcode_t profile_add_node
149 (struct profile_node *section,
150 const char *name, const char *value,
151 struct profile_node **ret_node);
153 errcode_t profile_make_node_final
154 (struct profile_node *node);
156 int profile_is_node_final
157 (struct profile_node *node);
159 const char *profile_get_node_name
160 (struct profile_node *node);
162 const char *profile_get_node_value
163 (struct profile_node *node);
165 errcode_t profile_find_node
166 (struct profile_node *section,
167 const char *name, const char *value,
168 int section_flag, void **state,
169 struct profile_node **node);
171 errcode_t profile_find_node_relation
172 (struct profile_node *section,
173 const char *name, void **state,
174 char **ret_name, char **value);
176 errcode_t profile_find_node_subsection
177 (struct profile_node *section,
178 const char *name, void **state,
179 char **ret_name, struct profile_node **subsection);
181 errcode_t profile_get_node_parent
182 (struct profile_node *section,
183 struct profile_node **parent);
185 errcode_t profile_delete_node_relation
186 (struct profile_node *section, const char *name);
188 errcode_t profile_find_node_name
189 (struct profile_node *section, void **state,
192 errcode_t profile_node_iterator_create
193 (profile_t profile, const char *const *names,
194 int flags, void **ret_iter);
196 void profile_node_iterator_free
199 errcode_t profile_node_iterator
200 (void **iter_p, struct profile_node **ret_node,
201 char **ret_name, char **ret_value);
203 errcode_t profile_remove_node
204 (struct profile_node *node);
206 errcode_t profile_set_relation_value
207 (struct profile_node *node, const char *new_value);
209 errcode_t profile_rename_node
210 (struct profile_node *node, const char *new_name);
214 errcode_t KRB5_CALLCONV profile_copy (profile_t, profile_t *);
216 errcode_t profile_open_file
217 (const_profile_filespec_t file, prf_file_t *ret_prof,
220 #define profile_update_file(P, M) profile_update_file_data((P)->data, M)
221 errcode_t profile_update_file_data
222 (prf_data_t profile, char **ret_modspec);
223 #define profile_update_file_locked(P, M) profile_update_file_data_locked((P)->data, M)
224 errcode_t profile_update_file_data_locked
225 (prf_data_t data, char **ret_modspec);
227 #define profile_flush_file(P) (((P) && (P)->magic == PROF_MAGIC_FILE) ? profile_flush_file_data((P)->data) : PROF_MAGIC_FILE)
228 errcode_t profile_flush_file_data
231 #define profile_flush_file_to_file(P,F) (((P) && (P)->magic == PROF_MAGIC_FILE) ? profile_flush_file_data_to_file((P)->data, (F)) : PROF_MAGIC_FILE)
232 errcode_t profile_flush_file_data_to_file
233 (prf_data_t data, const char *outfile);
235 errcode_t profile_flush_file_data_to_buffer
236 (prf_data_t data, char **bufp);
238 void profile_free_file
239 (prf_file_t profile);
241 errcode_t profile_close_file
242 (prf_file_t profile);
244 int profile_file_is_writable
245 (prf_file_t profile);
247 void profile_dereference_data (prf_data_t);
248 void profile_dereference_data_locked (prf_data_t);
250 void profile_lock_global (void);
251 void profile_unlock_global (void);
253 /* prof_init.c -- included from profile.h */
254 errcode_t profile_ser_size
255 (const char *, profile_t, size_t *);
257 errcode_t profile_ser_externalize
258 (const char *, profile_t, unsigned char **, size_t *);
260 errcode_t profile_ser_internalize
261 (const char *, profile_t *, unsigned char **, size_t *);
265 errcode_t profile_get_value
266 (profile_t profile, const char **names, char **ret_value);
267 /* Others included from profile.h */
269 /* prof_set.c -- included from profile.h */