xref: /illumos-gate/usr/src/lib/krb5/kdb/kdb_log.h (revision 1da57d55)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #ifndef	_KDB_LOG_H
7 #define	_KDB_LOG_H
8 
9 #include <k5-int.h>
10 #include <iprop_hdr.h>
11 #include <iprop.h>
12 #include <limits.h>
13 #include <kadm5/admin.h>
14 
15 #ifdef	__cplusplus
16 extern "C" {
17 #endif
18 
19 /*
20  * DB macros
21  */
22 #define	INDEX(ulogaddr, i) ((ulong_t) ulogaddr + sizeof (kdb_hlog_t) + \
23 	(i*ulog->kdb_block))
24 
25 /*
26  * Current DB version #
27  */
28 #define	KDB_VERSION	1
29 
30 /*
31  * DB log states
32  */
33 #define	KDB_STABLE	1
34 #define	KDB_UNSTABLE	2
35 #define	KDB_CORRUPT	3
36 
37 /*
38  * DB log constants
39  */
40 #define	KDB_UMAGIC	0x6661212
41 #define	KDB_HMAGIC	0x6662323
42 
43 /*
44  * DB Flags
45  */
46 #define	FKADMIND	1
47 #define	FKPROPLOG	2
48 #define	FKPROPD		3
49 #define	FKCOMMAND	4	/* Includes kadmin.local and kdb5_util */
50 
51 /*
52  * Default ulog file attributes
53  */
54 #define	ULOG_FILE	"/var/krb5/principal.ulog"
55 #define	MAX_FILENAME	(PATH_MAX + 1)
56 #define	MAX_ULOGENTRIES	2500
57 #define	DEF_ULOGENTRIES	1000
58 #define	ULOG_IDLE_TIME	10		/* in seconds */
59 /*
60  * Max size of update entry + update header
61  * We make this large since resizing can be costly.
62  */
63 #define	ULOG_BLOCK	2048		/* Default size of principal record */
64 
65 #define	MAXLOGLEN	0x10000000	/* 256 MB log file */
66 
67 /*
68  * Prototype declarations
69  */
70 extern krb5_error_code ulog_map(krb5_context context,
71 	kadm5_config_params *params, int caller);
72 extern krb5_error_code ulog_add_update(krb5_context context,
73 	kdb_incr_update_t *upd);
74 extern krb5_error_code ulog_delete_update(krb5_context context,
75 	kdb_incr_update_t *upd);
76 extern krb5_error_code ulog_finish_update(krb5_context context,
77 	kdb_incr_update_t *upd);
78 extern krb5_error_code ulog_get_entries(krb5_context context, kdb_last_t last,
79 	kdb_incr_result_t *ulog_handle);
80 extern krb5_error_code ulog_replay(krb5_context context,
81 	kdb_incr_result_t *incr_ret);
82 extern krb5_error_code ulog_conv_2logentry(krb5_context context,
83 	krb5_db_entry *entries, kdb_incr_update_t *updates, int nentries);
84 extern krb5_error_code ulog_conv_2dbentry(krb5_context context,
85 	krb5_db_entry *entries, kdb_incr_update_t *updates, int nentries);
86 extern void ulog_free_entries(kdb_incr_update_t *updates, int no_of_updates);
87 extern krb5_error_code ulog_set_role(krb5_context ctx, iprop_role role);
88 
89 typedef struct kdb_hlog {
90 	uint32_t	kdb_hmagic;	/* Log header magic # */
91 	uint16_t	db_version_num;	/* Kerberos database version no. */
92 	uint32_t	kdb_num;	/* # of updates in log */
93 	kdbe_time_t	kdb_first_time;	/* Timestamp of first update */
94 	kdbe_time_t	kdb_last_time;	/* Timestamp of last update */
95 	kdb_sno_t	kdb_first_sno;	/* First serial # in the update log */
96 	kdb_sno_t	kdb_last_sno;	/* Last serial # in the update log */
97 	uint16_t	kdb_state;	/* State of update log */
98 	uint16_t	kdb_block;	/* Block size of each element */
99 } kdb_hlog_t;
100 
101 typedef struct kdb_ent_header {
102 	uint32_t	kdb_umagic;	/* Update entry magic # */
103 	kdb_sno_t	kdb_entry_sno;	/* Serial # of entry */
104 	kdbe_time_t	kdb_time;	/* Timestamp of update */
105 	bool_t		kdb_commit;	/* Is the entry committed or not */
106 	uint32_t	kdb_entry_size;	/* Size of update entry */
107 	uchar_t		entry_data[4];	/* Address of kdb_incr_update_t */
108 } kdb_ent_header_t;
109 
110 typedef struct _kdb_log_context {
111 	iprop_role	iproprole;
112 	kdb_hlog_t	*ulog;
113 	uint32_t	ulogentries;
114 	int		ulogfd;
115 } kdb_log_context;
116 
117 #ifdef	__cplusplus
118 }
119 #endif
120 
121 #endif	/* !_KDB_LOG_H */
122