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