Path: blob/main/crypto/krb5/src/util/profile/prof_int.h
34878 views
/*1* prof-int.h2*/34#include "k5-platform.h"5#include "k5-thread.h"6#include "k5-plugin.h"78#include <time.h>910#if defined(__MACH__) && defined(__APPLE__)11#include <TargetConditionals.h>12#define PROFILE_SUPPORTS_FOREIGN_NEWLINES13#endif1415#include "com_err.h"16#include "profile.h"1718typedef long prf_magic_t;1920/*21* This is the structure which stores the profile information for a22* particular configuration file.23*24* Locking strategy:25* - filespec, fslen are fixed after creation26* - refcount and next should only be tweaked with the global lock held27* - other fields can be tweaked after grabbing the in-struct lock28*/29struct _prf_data_t {30prf_magic_t magic;31k5_mutex_t lock;32struct profile_node *root;33time_t last_stat;34time_t timestamp; /* time tree was last updated from file */35unsigned long frac_ts; /* fractional part of timestamp, if any */36int flags; /* r/w, dirty */37int upd_serial; /* incremented when data changes */3839size_t fslen;4041/* Some separation between fields controlled by different42mutexes. Theoretically, both could be accessed at the same43time from different threads on different CPUs with separate44caches. Don't let the threads clobber each other's45changes. One mutex controlling the whole thing would be46better, but sufficient separation might suffice.4748This is icky. I just hope it's adequate.4950For next major release, fix this. */51union { double d; void *p; uint64_t ll; k5_mutex_t m; } pad;5253int refcount; /* prf_file_t references */54struct _prf_data_t *next;55/* Was: "profile_filespec_t filespec". Now: flexible char56array ... except, we need to work in C89, so an array57length must be specified. */58const char filespec[sizeof("/etc/krb5.conf")];59};6061typedef struct _prf_data_t *prf_data_t;62prf_data_t profile_make_prf_data(const char *);6364struct _prf_file_t {65prf_magic_t magic;66struct _prf_data_t *data;67struct _prf_file_t *next;68};6970typedef struct _prf_file_t *prf_file_t;7172/*73* The profile flags74*/75#define PROFILE_FILE_NO_RELOAD 0x000176#define PROFILE_FILE_DIRTY 0x000277#define PROFILE_FILE_SHARED 0x00047879struct _prf_lib_handle_t {80k5_mutex_t lock;81int refcount;82struct plugin_file_handle *plugin_handle;83};8485typedef struct _prf_lib_handle_t *prf_lib_handle_t;8687/*88* This structure defines the high-level, user visible profile_t89* object, which is used as a handle by users who need to query some90* configuration file(s)91*/92struct _profile_t {93prf_magic_t magic;94prf_file_t first_file;9596/* If non-null, use vtable operations instead of native ones. */97struct profile_vtable *vt;98void *cbdata;99prf_lib_handle_t lib_handle;100};101102/*103* Used by the profile iterator in prof_get.c104*/105#define PROFILE_ITER_LIST_SECTION 0x0001106#define PROFILE_ITER_SECTIONS_ONLY 0x0002107#define PROFILE_ITER_RELATIONS_ONLY 0x0004108109#define PROFILE_ITER_FINAL_SEEN 0x0100110111/*112* Check if a filespec is last in a list (NULL on UNIX, invalid FSSpec on MacOS113*/114115#define PROFILE_LAST_FILESPEC(x) (((x) == NULL) || ((x)[0] == '\0'))116117/* profile_parse.c */118119errcode_t profile_parse_file120(FILE *f, struct profile_node **root, char **ret_modspec);121122errcode_t profile_process_directory123(const char *dirname, struct profile_node **root);124125errcode_t profile_write_tree_file126(struct profile_node *root, FILE *dstfile);127128errcode_t profile_write_tree_to_buffer129(struct profile_node *root, char **buf);130131132/* prof_tree.c */133134void profile_free_node135(struct profile_node *relation);136137errcode_t profile_create_node138(const char *name, const char *value,139struct profile_node **ret_node);140141struct profile_node *profile_copy_node142(struct profile_node *oldnode);143144errcode_t profile_verify_node145(struct profile_node *node);146147errcode_t profile_add_node148(struct profile_node *section,149const char *name, const char *value, int check_final,150struct profile_node **ret_node);151152errcode_t profile_make_node_final153(struct profile_node *node);154155int profile_is_node_final156(struct profile_node *node);157158const char *profile_get_node_name159(struct profile_node *node);160161const char *profile_get_node_value162(struct profile_node *node);163164errcode_t profile_find_node165(struct profile_node *section,166const char *name, const char *value,167int section_flag, void **state,168struct profile_node **node);169170errcode_t profile_find_node_relation171(struct profile_node *section,172const char *name, void **state,173char **ret_name, char **value, int *ret_final);174175errcode_t profile_find_node_subsection176(struct profile_node *section,177const char *name, void **state,178char **ret_name, struct profile_node **subsection);179180errcode_t profile_get_node_parent181(struct profile_node *section,182struct profile_node **parent);183184errcode_t profile_delete_node_relation185(struct profile_node *section, const char *name);186187errcode_t profile_find_node_name188(struct profile_node *section, void **state,189char **ret_name);190191errcode_t profile_node_iterator_create192(profile_t profile, const char *const *names,193int flags, void **ret_iter);194195void profile_node_iterator_free196(void **iter_p);197198errcode_t profile_node_iterator199(void **iter_p, struct profile_node **ret_node,200char **ret_name, char **ret_value);201202errcode_t profile_remove_node203(struct profile_node *node);204205errcode_t profile_set_relation_value206(struct profile_node *node, const char *new_value);207208errcode_t profile_rename_node209(struct profile_node *node, const char *new_name);210211/* prof_file.c */212213errcode_t profile_open_file214(const_profile_filespec_t file, prf_file_t *ret_prof,215char **ret_modspec);216217prf_file_t profile_open_memory(void);218219#define profile_update_file(P, M) profile_update_file_data((P)->data, M)220errcode_t profile_update_file_data221(prf_data_t profile, char **ret_modspec);222#define profile_update_file_locked(P, M) profile_update_file_data_locked((P)->data, M)223errcode_t profile_update_file_data_locked224(prf_data_t data, char **ret_modspec);225226#define profile_flush_file(P) (((P) && (P)->magic == PROF_MAGIC_FILE) ? profile_flush_file_data((P)->data) : PROF_MAGIC_FILE)227errcode_t profile_flush_file_data228(prf_data_t data);229230#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)231errcode_t profile_flush_file_data_to_file232(prf_data_t data, const char *outfile);233234errcode_t profile_flush_file_data_to_buffer235(prf_data_t data, char **bufp);236237prf_file_t profile_copy_file238(prf_file_t oldfile);239240void profile_free_file241(prf_file_t profile);242243errcode_t profile_close_file244(prf_file_t profile);245246int profile_file_is_writable247(prf_file_t profile);248249void profile_dereference_data (prf_data_t);250void profile_dereference_data_locked (prf_data_t);251252void profile_lock_global (void);253void profile_unlock_global (void);254255/* prof_init.c -- included from profile.h */256errcode_t profile_ser_size257(profile_t, size_t *);258259errcode_t profile_ser_externalize260(profile_t, unsigned char **, size_t *);261262errcode_t profile_ser_internalize263(profile_t *, unsigned char **, size_t *);264265/* prof_get.c */266267errcode_t profile_get_value268(profile_t profile, const char **names, char **ret_value);269/* Others included from profile.h */270271/* prof_set.c -- included from profile.h */272273274