xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/profile/prof_int.h (revision 12568:0f6ea478c2c7)
10Sstevel@tonic-gate /*
2*12568SShawn.Emery@Sun.COM  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
30Sstevel@tonic-gate  */
40Sstevel@tonic-gate 
50Sstevel@tonic-gate /*
60Sstevel@tonic-gate  * prof-int.h
70Sstevel@tonic-gate  */
80Sstevel@tonic-gate 
97934SMark.Phalan@Sun.COM /* Solaris Kerberos */
100Sstevel@tonic-gate #ifndef __PROF_INT_H
11*12568SShawn.Emery@Sun.COM #define	__PROF_INT_H
120Sstevel@tonic-gate 
130Sstevel@tonic-gate #include <time.h>
14781Sgtb #include <stdio.h>
150Sstevel@tonic-gate 
16781Sgtb #if defined(__MACH__) && defined(__APPLE__)
17781Sgtb #include <TargetConditionals.h>
18781Sgtb #define PROFILE_SUPPORTS_FOREIGN_NEWLINES
190Sstevel@tonic-gate #endif
200Sstevel@tonic-gate 
217934SMark.Phalan@Sun.COM #include "k5-thread.h"
227934SMark.Phalan@Sun.COM #include "k5-platform.h"
237934SMark.Phalan@Sun.COM #include "com_err.h"
247934SMark.Phalan@Sun.COM #include "profile.h"
250Sstevel@tonic-gate 
260Sstevel@tonic-gate typedef long prf_magic_t;
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * This is the structure which stores the profile information for a
300Sstevel@tonic-gate  * particular configuration file.
31781Sgtb  *
32781Sgtb  * Locking strategy:
337934SMark.Phalan@Sun.COM  * - filespec, fslen are fixed after creation
34781Sgtb  * - refcount and next should only be tweaked with the global lock held
35781Sgtb  * - other fields can be tweaked after grabbing the in-struct lock
360Sstevel@tonic-gate  */
37781Sgtb struct _prf_data_t {
38781Sgtb 	prf_magic_t	magic;
39781Sgtb 	k5_mutex_t	lock;
40781Sgtb 	struct profile_node *root;
41781Sgtb 	time_t		last_stat;
42781Sgtb 	time_t		timestamp; /* time tree was last updated from file */
437934SMark.Phalan@Sun.COM 	unsigned long	frac_ts;   /* fractional part of timestamp, if any */
44781Sgtb 	int		flags;	/* r/w, dirty */
45781Sgtb 	int		upd_serial; /* incremented when data changes */
467934SMark.Phalan@Sun.COM 	char		*comment;
477934SMark.Phalan@Sun.COM 
487934SMark.Phalan@Sun.COM 	size_t		fslen;
497934SMark.Phalan@Sun.COM 
507934SMark.Phalan@Sun.COM 	/* Some separation between fields controlled by different
517934SMark.Phalan@Sun.COM 	   mutexes.  Theoretically, both could be accessed at the same
527934SMark.Phalan@Sun.COM 	   time from different threads on different CPUs with separate
537934SMark.Phalan@Sun.COM 	   caches.  Don't let the threads clobber each other's
547934SMark.Phalan@Sun.COM 	   changes.  One mutex controlling the whole thing would be
557934SMark.Phalan@Sun.COM 	   better, but sufficient separation might suffice.
567934SMark.Phalan@Sun.COM 
577934SMark.Phalan@Sun.COM 	   This is icky.  I just hope it's adequate.
587934SMark.Phalan@Sun.COM 
597934SMark.Phalan@Sun.COM 	   For next major release, fix this.  */
607934SMark.Phalan@Sun.COM 	union { double d; void *p; UINT64_TYPE ll; k5_mutex_t m; } pad;
617934SMark.Phalan@Sun.COM 
62781Sgtb 	int		refcount; /* prf_file_t references */
63781Sgtb 	struct _prf_data_t *next;
64781Sgtb 	/* Was: "profile_filespec_t filespec".  Now: flexible char
65781Sgtb 	   array ... except, we need to work in C89, so an array
66781Sgtb 	   length must be specified.  */
677934SMark.Phalan@Sun.COM 	const char	filespec[sizeof("/etc/krb5.conf")];
68781Sgtb };
69781Sgtb 
70781Sgtb typedef struct _prf_data_t *prf_data_t;
71781Sgtb prf_data_t profile_make_prf_data(const char *);
72781Sgtb 
730Sstevel@tonic-gate struct _prf_file_t {
740Sstevel@tonic-gate 	prf_magic_t	magic;
75781Sgtb 	struct _prf_data_t	*data;
760Sstevel@tonic-gate 	struct _prf_file_t *next;
770Sstevel@tonic-gate };
780Sstevel@tonic-gate 
790Sstevel@tonic-gate typedef struct _prf_file_t *prf_file_t;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /*
820Sstevel@tonic-gate  * The profile flags
830Sstevel@tonic-gate  */
840Sstevel@tonic-gate #define PROFILE_FILE_RW		0x0001
850Sstevel@tonic-gate #define PROFILE_FILE_DIRTY	0x0002
86781Sgtb #define PROFILE_FILE_SHARED	0x0004
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate  * This structure defines the high-level, user visible profile_t
900Sstevel@tonic-gate  * object, which is used as a handle by users who need to query some
910Sstevel@tonic-gate  * configuration file(s)
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate struct _profile_t {
940Sstevel@tonic-gate 	prf_magic_t	magic;
950Sstevel@tonic-gate 	prf_file_t	first_file;
960Sstevel@tonic-gate };
970Sstevel@tonic-gate 
980Sstevel@tonic-gate typedef struct _profile_options {
990Sstevel@tonic-gate 	char *name;
1000Sstevel@tonic-gate 	int  *value;
1010Sstevel@tonic-gate 	int  found;
1020Sstevel@tonic-gate } profile_options_boolean;
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate typedef struct _profile_times {
1050Sstevel@tonic-gate 	char *name;
1060Sstevel@tonic-gate 	char **value;
1070Sstevel@tonic-gate 	int  found;
1080Sstevel@tonic-gate } profile_option_strings;
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate /*
111*12568SShawn.Emery@Sun.COM  * Solaris Kerberos: Added here to provide to other non-prof_get functions.
112*12568SShawn.Emery@Sun.COM  * The profile_string_list structure is used for internal booking
113*12568SShawn.Emery@Sun.COM  * purposes to build up the list, which is returned in *ret_list by
114*12568SShawn.Emery@Sun.COM  * the end_list() function.
115*12568SShawn.Emery@Sun.COM  */
116*12568SShawn.Emery@Sun.COM struct profile_string_list {
117*12568SShawn.Emery@Sun.COM 	char	**list;
118*12568SShawn.Emery@Sun.COM 	int	num;
119*12568SShawn.Emery@Sun.COM 	int	max;
120*12568SShawn.Emery@Sun.COM };
121*12568SShawn.Emery@Sun.COM 
122*12568SShawn.Emery@Sun.COM /*
1230Sstevel@tonic-gate  * Used by the profile iterator in prof_get.c
1240Sstevel@tonic-gate  */
1250Sstevel@tonic-gate #define PROFILE_ITER_LIST_SECTION	0x0001
1260Sstevel@tonic-gate #define PROFILE_ITER_SECTIONS_ONLY	0x0002
1270Sstevel@tonic-gate #define PROFILE_ITER_RELATIONS_ONLY	0x0004
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate #define PROFILE_ITER_FINAL_SEEN		0x0100
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate  * Check if a filespec is last in a list (NULL on UNIX, invalid FSSpec on MacOS
1330Sstevel@tonic-gate  */
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate #define	PROFILE_LAST_FILESPEC(x) (((x) == NULL) || ((x)[0] == '\0'))
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate /* profile_parse.c */
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate errcode_t profile_parse_file
140781Sgtb 	(FILE *f, struct profile_node **root);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate errcode_t profile_write_tree_file
143781Sgtb 	(struct profile_node *root, FILE *dstfile);
144781Sgtb 
145781Sgtb errcode_t profile_write_tree_to_buffer
146781Sgtb 	(struct profile_node *root, char **buf);
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate /* prof_tree.c */
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate void profile_free_node
152781Sgtb 	(struct profile_node *relation);
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate errcode_t profile_create_node
155781Sgtb 	(const char *name, const char *value,
156781Sgtb 		   struct profile_node **ret_node);
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate errcode_t profile_verify_node
159781Sgtb 	(struct profile_node *node);
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate errcode_t profile_add_node
162781Sgtb 	(struct profile_node *section,
1630Sstevel@tonic-gate 		    const char *name, const char *value,
164781Sgtb 		    struct profile_node **ret_node);
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate errcode_t profile_make_node_final
167781Sgtb 	(struct profile_node *node);
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate int profile_is_node_final
170781Sgtb 	(struct profile_node *node);
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate const char *profile_get_node_name
173781Sgtb 	(struct profile_node *node);
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate const char *profile_get_node_value
176781Sgtb 	(struct profile_node *node);
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate errcode_t profile_find_node
179781Sgtb 	(struct profile_node *section,
1800Sstevel@tonic-gate 		    const char *name, const char *value,
1810Sstevel@tonic-gate 		    int section_flag, void **state,
182781Sgtb 		    struct profile_node **node);
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate errcode_t profile_find_node_relation
185781Sgtb 	(struct profile_node *section,
1860Sstevel@tonic-gate 		    const char *name, void **state,
187781Sgtb 		    char **ret_name, char **value);
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate errcode_t profile_find_node_subsection
190781Sgtb 	(struct profile_node *section,
1910Sstevel@tonic-gate 		    const char *name, void **state,
192781Sgtb 		    char **ret_name, struct profile_node **subsection);
193781Sgtb 
1940Sstevel@tonic-gate errcode_t profile_get_node_parent
195781Sgtb 	(struct profile_node *section,
196781Sgtb 		   struct profile_node **parent);
197781Sgtb 
1980Sstevel@tonic-gate errcode_t profile_delete_node_relation
199781Sgtb 	(struct profile_node *section, const char *name);
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate errcode_t profile_find_node_name
202781Sgtb 	(struct profile_node *section, void **state,
203781Sgtb 		    char **ret_name);
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate errcode_t profile_node_iterator_create
206781Sgtb 	(profile_t profile, const char *const *names,
207781Sgtb 		   int flags, void **ret_iter);
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate void profile_node_iterator_free
210781Sgtb 	(void	**iter_p);
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate errcode_t profile_node_iterator
213781Sgtb 	(void	**iter_p, struct profile_node **ret_node,
214781Sgtb 		   char **ret_name, char **ret_value);
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate errcode_t profile_remove_node
217781Sgtb 	(struct profile_node *node);
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate errcode_t profile_set_relation_value
220781Sgtb 	(struct profile_node *node, const char *new_value);
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate errcode_t profile_rename_node
223781Sgtb 	(struct profile_node *node, const char *new_name);
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate /* prof_file.c */
2260Sstevel@tonic-gate 
2277934SMark.Phalan@Sun.COM errcode_t KRB5_CALLCONV profile_copy (profile_t, profile_t *);
2287934SMark.Phalan@Sun.COM 
2290Sstevel@tonic-gate errcode_t profile_open_file
230781Sgtb 	(const_profile_filespec_t file, prf_file_t *ret_prof);
231781Sgtb 
232781Sgtb #define profile_update_file(P) profile_update_file_data((P)->data)
233781Sgtb errcode_t profile_update_file_data
234781Sgtb 	(prf_data_t profile);
2350Sstevel@tonic-gate 
236781Sgtb #define profile_flush_file(P) (((P) && (P)->magic == PROF_MAGIC_FILE) ? profile_flush_file_data((P)->data) : PROF_MAGIC_FILE)
237781Sgtb errcode_t profile_flush_file_data
238781Sgtb 	(prf_data_t data);
2390Sstevel@tonic-gate 
240781Sgtb #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)
241781Sgtb errcode_t profile_flush_file_data_to_file
242781Sgtb 	(prf_data_t data, const char *outfile);
243781Sgtb 
244781Sgtb errcode_t profile_flush_file_data_to_buffer
245781Sgtb 	(prf_data_t data, char **bufp);
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate void profile_free_file
248781Sgtb 	(prf_file_t profile);
2490Sstevel@tonic-gate 
2500Sstevel@tonic-gate errcode_t profile_close_file
251781Sgtb 	(prf_file_t profile);
252781Sgtb 
253781Sgtb void profile_dereference_data (prf_data_t);
254781Sgtb void profile_dereference_data_locked (prf_data_t);
255781Sgtb 
256781Sgtb int profile_lock_global (void);
257781Sgtb int profile_unlock_global (void);
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate /* prof_init.c -- included from profile.h */
260781Sgtb errcode_t profile_ser_size
261781Sgtb         (const char *, profile_t, size_t *);
262781Sgtb 
263781Sgtb errcode_t profile_ser_externalize
264781Sgtb         (const char *, profile_t, unsigned char **, size_t *);
265781Sgtb 
266781Sgtb errcode_t profile_ser_internalize
267781Sgtb         (const char *, profile_t *, unsigned char **, size_t *);
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate /* prof_get.c */
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate errcode_t profile_get_value
272781Sgtb 	(profile_t profile, const char **names,
273781Sgtb 		    const char	**ret_value);
274*12568SShawn.Emery@Sun.COM 
275*12568SShawn.Emery@Sun.COM /*
276*12568SShawn.Emery@Sun.COM  * Solaris Kerberos: Need basic routines for other functions besides prof_get.
277*12568SShawn.Emery@Sun.COM  */
278*12568SShawn.Emery@Sun.COM errcode_t init_list(struct profile_string_list *list);
279*12568SShawn.Emery@Sun.COM void end_list(struct profile_string_list *list, char ***ret_list);
280*12568SShawn.Emery@Sun.COM errcode_t add_to_list(struct profile_string_list *list, const char *str);
281*12568SShawn.Emery@Sun.COM 
2820Sstevel@tonic-gate /* Others included from profile.h */
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate /* prof_set.c -- included from profile.h */
2850Sstevel@tonic-gate 
2867934SMark.Phalan@Sun.COM /* Solaris Kerberos */
287*12568SShawn.Emery@Sun.COM #endif /* __PROF_INT_H */
288