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 {
387c478bd9Sstevel@tonic-gate 	prf_magic_t	magic;
39505d05c7Sgtb 	k5_mutex_t	lock;
407c478bd9Sstevel@tonic-gate 	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 
73505d05c7Sgtb struct _prf_file_t {
74505d05c7Sgtb 	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 
110*bfc032a1SShawn Emery /*
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 
1227c478bd9Sstevel@tonic-gate /*
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);
193505d05c7Sgtb 
1947c478bd9Sstevel@tonic-gate errcode_t profile_get_node_parent
195505d05c7Sgtb 	(struct profile_node *section,
196505d05c7Sgtb 		   struct profile_node **parent);
197