1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
4 * Use is subject to license terms.
5 */
6
7 #ifndef _KDB_LOG_H
8 #define _KDB_LOG_H
9
10 /* #pragma ident "@(#)kdb_log.h 1.3 04/02/23 SMI" */
11
12 #include <iprop_hdr.h>
13 #include <iprop.h>
14 #include <limits.h>
15 #include "kdb.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 /*
22 * Current DB version #
23 */
24 #define KDB_VERSION 1
25
26 /*
27 * DB log states
28 */
29 #define KDB_STABLE 1
30 #define KDB_UNSTABLE 2
31 #define KDB_CORRUPT 3
32
33 /*
34 * DB log constants
35 */
36 #define KDB_ULOG_MAGIC 0x6661212
37 #define KDB_ULOG_HDR_MAGIC 0x6662323
38
39 /*
40 * Default ulog file attributes
41 */
42 #define DEF_ULOGENTRIES 1000
43 #define ULOG_IDLE_TIME 10 /* in seconds */
44 /*
45 * Max size of update entry + update header
46 * We make this large since resizing can be costly.
47 */
48 #define ULOG_BLOCK 2048 /* Default size of principal record */
49
50 #define MAXLOGLEN 0x10000000 /* 256 MB log file */
51
52 /*
53 * Prototype declarations
54 */
55 krb5_error_code ulog_map(krb5_context context, const char *logname,
56 uint32_t entries);
57 krb5_error_code ulog_init_header(krb5_context context);
58 krb5_error_code ulog_add_update(krb5_context context, kdb_incr_update_t *upd);
59 krb5_error_code ulog_get_entries(krb5_context context, const kdb_last_t *last,
60 kdb_incr_result_t *ulog_handle);
61 krb5_error_code ulog_replay(krb5_context context, kdb_incr_result_t *incr_ret,
62 char **db_args);
63 krb5_error_code ulog_conv_2logentry(krb5_context context, krb5_db_entry *entry,
64 kdb_incr_update_t *update);
65 krb5_error_code ulog_conv_2dbentry(krb5_context context, krb5_db_entry **entry,
66 kdb_incr_update_t *update);
67 void ulog_free_entries(kdb_incr_update_t *updates, int no_of_updates);
68 krb5_error_code ulog_set_role(krb5_context ctx, iprop_role role);
69 update_status_t ulog_get_sno_status(krb5_context context,
70 const kdb_last_t *last);
71 krb5_error_code ulog_get_last(krb5_context context, kdb_last_t *last_out);
72 krb5_error_code ulog_set_last(krb5_context context, const kdb_last_t *last);
73 void ulog_fini(krb5_context context);
74
75 typedef struct kdb_hlog {
76 uint32_t kdb_hmagic; /* Log header magic # */
77 uint16_t db_version_num; /* Kerberos database version no. */
78 uint32_t kdb_num; /* # of updates in log */
79 kdbe_time_t kdb_first_time; /* Timestamp of first update */
80 kdbe_time_t kdb_last_time; /* Timestamp of last update */
81 kdb_sno_t kdb_first_sno; /* First serial # in the update log */
82 kdb_sno_t kdb_last_sno; /* Last serial # in the update log */
83 uint16_t kdb_state; /* State of update log */
84 uint16_t kdb_block; /* Block size of each element */
85 } kdb_hlog_t;
86
87 typedef struct kdb_ent_header {
88 uint32_t kdb_umagic; /* Update entry magic # */
89 kdb_sno_t kdb_entry_sno; /* Serial # of entry */
90 kdbe_time_t kdb_time; /* Timestamp of update */
91 bool_t kdb_commit; /* Is the entry committed or not */
92 uint32_t kdb_entry_size; /* Size of update entry */
93 uint8_t entry_data[4]; /* Address of kdb_incr_update_t */
94 } kdb_ent_header_t;
95
96 typedef struct _kdb_log_context {
97 iprop_role iproprole;
98 kdb_hlog_t *ulog;
99 uint32_t ulogentries;
100 int ulogfd;
101 } kdb_log_context;
102
103 /* Return the address of the i'th record in ulog for the given block size. */
104 static inline uint8_t *
ulog_record_ptr(kdb_hlog_t * ulog,size_t i,size_t bsize)105 ulog_record_ptr(kdb_hlog_t *ulog, size_t i, size_t bsize)
106 {
107 return (uint8_t *)ulog + sizeof(*ulog) + i * bsize;
108 }
109
110 /* Return the i'th update entry header for ulog. */
111 static inline kdb_ent_header_t *
ulog_index(kdb_hlog_t * ulog,size_t i)112 ulog_index(kdb_hlog_t *ulog, size_t i)
113 {
114 return (void *)ulog_record_ptr(ulog, i, ulog->kdb_block);
115 }
116
117 #ifdef __cplusplus
118 }
119 #endif
120
121 #endif /* !_KDB_LOG_H */
122