const char *logname, uint32_t entries,
int caller,
char **db_args);
+extern void ulog_init_header(krb5_context context);
extern krb5_error_code ulog_add_update(krb5_context context,
kdb_incr_update_t *upd);
extern krb5_error_code ulog_delete_update(krb5_context context,
* no advantage in incr updates when entire db is replaced
*/
if (!(flags & FLAG_UPDATE)) {
- memset(log_ctx->ulog, 0, sizeof (kdb_hlog_t));
-
- log_ctx->ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
- log_ctx->ulog->db_version_num = KDB_VERSION;
- log_ctx->ulog->kdb_state = KDB_STABLE;
- log_ctx->ulog->kdb_block = ULOG_BLOCK;
-
+ ulog_init_header(util_context);
log_ctx->iproprole = IPROP_NULL;
if (!add_update) {
* We're reinitializing the update log in case one already
* existed, but this should never happen.
*/
- (void) memset(log_ctx->ulog, 0, sizeof (kdb_hlog_t));
-
- log_ctx->ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
- log_ctx->ulog->db_version_num = KDB_VERSION;
- log_ctx->ulog->kdb_state = KDB_STABLE;
- log_ctx->ulog->kdb_block = ULOG_BLOCK;
+ ulog_init_header(util_context);
/*
* Since we're creating a new db we shouldn't worry about
static int extend_file_to(int fd, unsigned int new_size);
+static inline krb5_boolean
+time_equal(const kdbe_time_t *a, const kdbe_time_t *b)
+{
+ return a->seconds == b->seconds && a->useconds == b->useconds;
+}
+
+static void
+time_current(kdbe_time_t *out)
+{
+ struct timeval timestamp;
+
+ (void)gettimeofday(×tamp, NULL);
+ out->seconds = timestamp.tv_sec;
+ out->useconds = timestamp.tv_usec;
+}
+
krb5_error_code
ulog_lock(krb5_context ctx, int mode)
{
{
XDR xdrs;
kdbe_time_t ktime;
- struct timeval timestamp;
kdb_ent_header_t *indx_log;
unsigned int i, recsize;
unsigned long upd_size;
if (upd == NULL)
return KRB5_LOG_ERROR;
- (void)gettimeofday(×tamp, NULL);
- ktime.seconds = timestamp.tv_sec;
- ktime.useconds = timestamp.tv_usec;
+ time_current(&ktime);
upd_size = xdr_sizeof((xdrproc_t)xdr_kdb_incr_update_t, upd);
ulog->db_version_num = KDB_VERSION;
ulog->kdb_state = KDB_STABLE;
ulog->kdb_block = ULOG_BLOCK;
+ time_current(&ulog->kdb_last_time);
+}
+
+/* Reinitialize the log header. Locking is the caller's responsibility. */
+void
+ulog_init_header(krb5_context context)
+{
+ kdb_log_context *log_ctx;
+ kdb_hlog_t *ulog;
+
+ INIT_ULOG(context);
+ ulog_reset(ulog);
+ ulog_sync_header(ulog);
}
/*
return retval;
}
+ /* If we have the same sno and timestamp, return a nil update. If a
+ * different timestamp, the sno was reused and we need a full resync. */
+ if (last.last_sno == ulog->kdb_last_sno) {
+ ulog_handle->ret = time_equal(&last.last_time, &ulog->kdb_last_time) ?
+ UPDATE_NIL : UPDATE_FULL_RESYNC_NEEDED;
+ goto cleanup;
+ }
+
/* We may have overflowed the update log or shrunk the log, or the client
* may have created its ulog. */
if (last.last_sno > ulog->kdb_last_sno ||
- last.last_sno < ulog->kdb_first_sno || last.last_sno == 0) {
+ last.last_sno < ulog->kdb_first_sno) {
ulog_handle->lastentry.last_sno = ulog->kdb_last_sno;
ulog_handle->ret = UPDATE_FULL_RESYNC_NEEDED;
goto cleanup;
indx = (sno - 1) % ulogentries;
indx_log = (kdb_ent_header_t *)INDEX(ulog, indx);
- if (indx_log->kdb_time.seconds != last.last_time.seconds ||
- indx_log->kdb_time.useconds != last.last_time.useconds) {
+ if (!time_equal(&indx_log->kdb_time, &last.last_time)) {
/* We have time stamp mismatch or we no longer have the slave's last
* sno, so we brute force it. */
ulog_handle->ret = UPDATE_FULL_RESYNC_NEEDED;
goto cleanup;
}
- /* If we have the same sno we return success. */
- if (last.last_sno == ulog->kdb_last_sno) {
- ulog_handle->ret = UPDATE_NIL;
- goto cleanup;
- }
-
count = ulog->kdb_last_sno - sno;
upd = calloc(count, sizeof(kdb_incr_update_t));
if (upd == NULL) {
krb5_db_free_policy
krb5_def_store_mkey_list
krb5_db_promote
+ulog_init_header
ulog_map
ulog_set_role
ulog_free_entries
now = time(NULL);
if (frrequested &&
(now - frrequested) < params.iprop_resync_timeout) {
+ if (debug)
+ fprintf(stderr, _("Still waiting for full resync\n"));
break;
} else {
frrequested = now;
}
if (reset) {
- ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
- ulog->db_version_num = KDB_VERSION;
- ulog->kdb_state = KDB_STABLE;
- ulog->kdb_block = ULOG_BLOCK;
- ulog->kdb_first_sno = 0;
- ulog->kdb_first_time.seconds = 0;
- ulog->kdb_first_time.useconds = 0;
- ulog->kdb_last_sno = 0;
- ulog->kdb_last_time.seconds = 0;
- ulog->kdb_last_time.useconds = 0;
- ulog_sync_header(ulog);
+ ulog_init_header(context);
printf(_("Reinitialized the ulog.\n"));
exit(0);
}
kpropd.send_signal(signal.SIGUSR1)
# Detect some failure conditions.
+ if 'Still waiting for full resync' in line:
+ fail('kadmind gave consecutive full resyncs')
if 'Rejected connection' in line:
fail('kpropd rejected kprop connection')
if 'get updates failed' in line:
out = realm.run([kproplog, '-h'])
if 'Last serial # : None' not in out:
fail('Reset of update log on master failed')
-realm.run_kadminl('modprinc -allow_tix w')
-out = realm.run([kproplog, '-h'])
-if 'Last serial # : 1' not in out:
- fail('Update log on master has incorrect last serial number')
# Get and check a full resync.
kpropd.send_signal(signal.SIGUSR1)
wait_for_prop(kpropd, True)
out = realm.run([kproplog, '-h'], slave)
-if 'Last serial # : 1' not in out:
+if 'Last serial # : None' not in out:
fail('Update log on slave has incorrect last serial number')
success('iprop tests')