17c478bd9Sstevel@tonic-gate /* 2*bfc032a1SShawn Emery * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 37c478bd9Sstevel@tonic-gate */ 47c478bd9Sstevel@tonic-gate 57c478bd9Sstevel@tonic-gate /* 67c478bd9Sstevel@tonic-gate * prof-int.h 77c478bd9Sstevel@tonic-gate */ 87c478bd9Sstevel@tonic-gate 9159d09a2SMark Phalan /* Solaris Kerberos */ 107c478bd9Sstevel@tonic-gate #ifndef __PROF_INT_H 11*bfc032a1SShawn Emery #define __PROF_INT_H 127c478bd9Sstevel@tonic-gate 137c478bd9Sstevel@tonic-gate #include <time.h> 14505d05c7Sgtb #include <stdio.h> 15505d05c7Sgtb 16505d05c7Sgtb #if defined(__MACH__) && defined(__APPLE__) 17505d05c7Sgtb #include <TargetConditionals.h> 18505d05c7Sgtb #define PROFILE_SUPPORTS_FOREIGN_NEWLINES 19505d05c7Sgtb #endif 20505d05c7Sgtb 21159d09a2SMark Phalan #include "k5-thread.h" 22159d09a2SMark Phalan #include "k5-platform.h" 23159d09a2SMark Phalan #include "com_err.h" 24159d09a2SMark Phalan #include "profile.h" 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate typedef long prf_magic_t; 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * This is the structure which stores the profile information for a 307c478bd9Sstevel@tonic-gate * particular configuration file. 31505d05c7Sgtb * 32505d05c7Sgtb * Locking strategy: 33159d09a2SMark Phalan * - filespec, fslen are fixed after creation 34505d05c7Sgtb * - refcount and next should only be tweaked with the global lock held 35505d05c7Sgtb * - other fields can be tweaked after grabbing the in-struct lock 367c478bd9Sstevel@tonic-gate */ 37505d05c7Sgtb struct _prf_data_t { 38505d05c7Sgtb prf_magic_t magic; 39505d05c7Sgtb k5_mutex_t lock; 40505d05c7Sgtb struct profile_node *root; 41505d05c7Sgtb time_t last_stat; 42505d05c7Sgtb time_t timestamp; /* time tree was last updated from file */ 43159d09a2SMark Phalan unsigned long frac_ts; /* fractional part of timestamp, if any */ 44505d05c7Sgtb int flags; /* r/w, dirty */ 45505d05c7Sgtb int upd_serial; /* incremented when data changes */ 46159d09a2SMark Phalan char *comment; 47159d09a2SMark Phalan 48159d09a2SMark Phalan size_t fslen; 49159d09a2SMark Phalan 50159d09a2SMark Phalan /* Some separation between fields controlled by different 51159d09a2SMark Phalan mutexes. Theoretically, both could be accessed at the same 52159d09a2SMark Phalan time from different threads on different CPUs with separate 53159d09a2SMark Phalan caches. Don't let the threads clobber each other's 54159d09a2SMark Phalan changes. One mutex controlling the whole thing would be 55159d09a2SMark Phalan better, but sufficient separation might suffice. 56159d09a2SMark Phalan 57159d09a2SMark Phalan This is icky. I just hope it's adequate. 58159d09a2SMark Phalan 59159d09a2SMark Phalan For next major release, fix this. */ 60159d09a2SMark Phalan union { double d; void *p; UINT64_TYPE ll; k5_mutex_t m; } pad; 61159d09a2SMark Phalan 62505d05c7Sgtb int refcount; /* prf_file_t references */ 63505d05c7Sgtb struct _prf_data_t *next; 64505d05c7Sgtb /* Was: "profile_filespec_t filespec". Now: flexible char 65505d05c7Sgtb array ... except, we need to work in C89, so an array 66505d05c7Sgtb length must be specified. */ 67159d09a2SMark Phalan const char filespec[sizeof("/etc/krb5.conf")]; 68505d05c7Sgtb }; 69505d05c7Sgtb 70505d05c7Sgtb typedef struct _prf_data_t *prf_data_t; 71505d05c7Sgtb prf_data_t profile_make_prf_data(const char *); 72505d05c7Sgtb 737c478bd9Sstevel@tonic-gate struct _prf_file_t { 747c478bd9Sstevel@tonic-gate prf_magic_t magic; 75505d05c7Sgtb struct _prf_data_t *data; 767c478bd9Sstevel@tonic-gate struct _prf_file_t *next; 777c478bd9Sstevel@tonic-gate }; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate typedef struct _prf_file_t *prf_file_t; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* 827c478bd9Sstevel@tonic-gate * The profile flags 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate #define PROFILE_FILE_RW 0x0001 857c478bd9Sstevel@tonic-gate #define PROFILE_FILE_DIRTY 0x0002 86505d05c7Sgtb #define PROFILE_FILE_SHARED 0x0004 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * This structure defines the high-level, user visible profile_t 907c478bd9Sstevel@tonic-gate * object, which is used as a handle by users who need to query some 917c478bd9Sstevel@tonic-gate * configuration file(s) 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate struct _profile_t { 947c478bd9Sstevel@tonic-gate prf_magic_t magic; 957c478bd9Sstevel@tonic-gate prf_file_t first_file; 967c478bd9Sstevel@tonic-gate }; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate typedef struct _profile_options { 997c478bd9Sstevel@tonic-gate char *name; 1007c478bd9Sstevel@tonic-gate int *value; 1017c478bd9Sstevel@tonic-gate int found; 1027c478bd9Sstevel@tonic-gate } profile_options_boolean; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate typedef struct _profile_times { 1057c478bd9Sstevel@tonic-gate char *name; 1067c478bd9Sstevel@tonic-gate char **value; 1077c478bd9Sstevel@tonic-gate int found; 1087c478bd9Sstevel@tonic-gate } profile_option_strings; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 111*bfc032a1SShawn Emery * Solaris Kerberos: Added here to provide to other non-prof_get functions. 112*bfc032a1SShawn Emery * The profile_string_list structure is used for internal booking 113*bfc032a1SShawn Emery * purposes to build up the list, which is returned in *ret_list by 114*bfc032a1SShawn Emery * the end_list() function. 115*bfc032a1SShawn Emery */ 116*bfc032a1SShawn Emery struct profile_string_list { 117*bfc032a1SShawn Emery char **list; 118*bfc032a1SShawn Emery int num; 119*bfc032a1SShawn Emery int max; 120*bfc032a1SShawn Emery }; 121*bfc032a1SShawn Emery 122*bfc032a1SShawn Emery /* 1237c478bd9Sstevel@tonic-gate * Used by the profile iterator in prof_get.c 1247c478bd9Sstevel@tonic-gate */ 1257c478bd9Sstevel@tonic-gate #define PROFILE_ITER_LIST_SECTION 0x0001 1267c478bd9Sstevel@tonic-gate #define PROFILE_ITER_SECTIONS_ONLY 0x0002 1277c478bd9Sstevel@tonic-gate #define PROFILE_ITER_RELATIONS_ONLY 0x0004 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate #define PROFILE_ITER_FINAL_SEEN 0x0100 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* 1327c478bd9Sstevel@tonic-gate * Check if a filespec is last in a list (NULL on UNIX, invalid FSSpec on MacOS 1337c478bd9Sstevel@tonic-gate */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate #define PROFILE_LAST_FILESPEC(x) (((x) == NULL) || ((x)[0] == '\0')) 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* profile_parse.c */ 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate errcode_t profile_parse_file 140505d05c7Sgtb (FILE *f, struct profile_node **root); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate errcode_t profile_write_tree_file 143505d05c7Sgtb (struct profile_node *root, FILE *dstfile); 144505d05c7Sgtb 145505d05c7Sgtb errcode_t profile_write_tree_to_buffer 146505d05c7Sgtb (struct profile_node *root, char **buf); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* prof_tree.c */ 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate void profile_free_node 152505d05c7Sgtb (struct profile_node *relation); 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate errcode_t profile_create_node 155505d05c7Sgtb (const char *name, const char *value, 156505d05c7Sgtb struct profile_node **ret_node); 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate errcode_t profile_verify_node 159505d05c7Sgtb (struct profile_node *node); 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate errcode_t profile_add_node 162505d05c7Sgtb (struct profile_node *section, 1637c478bd9Sstevel@tonic-gate const char *name, const char *value, 164505d05c7Sgtb struct profile_node **ret_node); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate errcode_t profile_make_node_final 167505d05c7Sgtb (struct profile_node *node); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate int profile_is_node_final 170505d05c7Sgtb (struct profile_node *node); 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate const char *profile_get_node_name 173505d05c7Sgtb (struct profile_node *node); 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate const char *profile_get_node_value 176505d05c7Sgtb (struct profile_node *node); 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate errcode_t profile_find_node 179505d05c7Sgtb (struct profile_node *section, 1807c478bd9Sstevel@tonic-gate const char *name, const char *value, 1817c478bd9Sstevel@tonic-gate int section_flag, void **state, 182505d05c7Sgtb struct profile_node **node); 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate errcode_t profile_find_node_relation 185505d05c7Sgtb (struct profile_node *section, 1867c478bd9Sstevel@tonic-gate const char *name, void **state, 187505d05c7Sgtb char **ret_name, char **value); 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate errcode_t profile_find_node_subsection 190505d05c7Sgtb (struct profile_node *section, 1917c478bd9Sstevel@tonic-gate const char *name, void **state, 192505d05c7Sgtb char **ret_name, struct profile_node **subsection); 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate errcode_t profile_get_node_parent 195505d05c7Sgtb (struct profile_node *section, 196505d05c7Sgtb struct profile_node **parent); 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate errcode_t profile_delete_node_relation 199505d05c7Sgtb (struct profile_node *section, const char *name); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate errcode_t profile_find_node_name 202505d05c7Sgtb (struct profile_node *section, void **state, 203505d05c7Sgtb char **ret_name); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate errcode_t profile_node_iterator_create 206505d05c7Sgtb (profile_t profile, const char *const *names, 207505d05c7Sgtb int flags, void **ret_iter); 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate void profile_node_iterator_free 210505d05c7Sgtb (void **iter_p); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate errcode_t profile_node_iterator 213505d05c7Sgtb (void **iter_p, struct profile_node **ret_node, 214505d05c7Sgtb char **ret_name, char **ret_value); 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate errcode_t profile_remove_node 217505d05c7Sgtb (struct profile_node *node); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate errcode_t profile_set_relation_value 220505d05c7Sgtb (struct profile_node *node, const char *new_value); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate errcode_t profile_rename_node 223505d05c7Sgtb (struct profile_node *node, const char *new_name); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate /* prof_file.c */ 2267c478bd9Sstevel@tonic-gate 227159d09a2SMark Phalan errcode_t KRB5_CALLCONV profile_copy (profile_t, profile_t *); 228159d09a2SMark Phalan 2297c478bd9Sstevel@tonic-gate errcode_t profile_open_file 230505d05c7Sgtb (const_profile_filespec_t file, prf_file_t *ret_prof); 2317c478bd9Sstevel@tonic-gate 232505d05c7Sgtb #define profile_update_file(P) profile_update_file_data((P)->data) 233505d05c7Sgtb errcode_t profile_update_file_data 234505d05c7Sgtb (prf_data_t profile); 2357c478bd9Sstevel@tonic-gate 236505d05c7Sgtb #define profile_flush_file(P) (((P) && (P)->magic == PROF_MAGIC_FILE) ? profile_flush_file_data((P)->data) : PROF_MAGIC_FILE) 237505d05c7Sgtb errcode_t profile_flush_file_data 238505d05c7Sgtb (prf_data_t data); 239505d05c7Sgtb 240505d05c7Sgtb #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) 241505d05c7Sgtb errcode_t profile_flush_file_data_to_file 242505d05c7Sgtb (prf_data_t data, const char *outfile); 243505d05c7Sgtb 244505d05c7Sgtb errcode_t profile_flush_file_data_to_buffer 245505d05c7Sgtb (prf_data_t data, char **bufp); 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate void profile_free_file 248505d05c7Sgtb (prf_file_t profile); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate errcode_t profile_close_file 251505d05c7Sgtb (prf_file_t profile); 252505d05c7Sgtb 253505d05c7Sgtb void profile_dereference_data (prf_data_t); 254505d05c7Sgtb void profile_dereference_data_locked (prf_data_t); 255505d05c7Sgtb 256505d05c7Sgtb int profile_lock_global (void); 257505d05c7Sgtb int profile_unlock_global (void); 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* prof_init.c -- included from profile.h */ 260505d05c7Sgtb errcode_t profile_ser_size 261505d05c7Sgtb (const char *, profile_t, size_t *); 262505d05c7Sgtb 263505d05c7Sgtb errcode_t profile_ser_externalize 264505d05c7Sgtb (const char *, profile_t, unsigned char **, size_t *); 265505d05c7Sgtb 266505d05c7Sgtb errcode_t profile_ser_internalize 267505d05c7Sgtb (const char *, profile_t *, unsigned char **, size_t *); 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate /* prof_get.c */ 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate errcode_t profile_get_value 272505d05c7Sgtb (profile_t profile, const char **names, 273505d05c7Sgtb const char **ret_value); 274*bfc032a1SShawn Emery 275*bfc032a1SShawn Emery /* 276*bfc032a1SShawn Emery * Solaris Kerberos: Need basic routines for other functions besides prof_get. 277*bfc032a1SShawn Emery */ 278*bfc032a1SShawn Emery errcode_t init_list(struct profile_string_list *list); 279*bfc032a1SShawn Emery void end_list(struct profile_string_list *list, char ***ret_list); 280*bfc032a1SShawn Emery errcode_t add_to_list(struct profile_string_list *list, const char *str); 281*bfc032a1SShawn Emery 2827c478bd9Sstevel@tonic-gate /* Others included from profile.h */ 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate /* prof_set.c -- included from profile.h */ 2857c478bd9Sstevel@tonic-gate 286159d09a2SMark Phalan /* Solaris Kerberos */ 287*bfc032a1SShawn Emery #endif /* __PROF_INT_H */ 288