summaryrefslogtreecommitdiffstats
path: root/src/lib/kdb/kdb_log.c
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2009-10-31 00:48:38 +0000
committerTom Yu <tlyu@mit.edu>2009-10-31 00:48:38 +0000
commit02d6bcbc98a214e7aeaaa9f45f0db8784a7b743b (patch)
tree61b9147863cd8be3eff63903dc36cae168254bd5 /src/lib/kdb/kdb_log.c
parent162ab371748cba0cc6f172419bd6e71fa04bb878 (diff)
downloadkrb5-02d6bcbc98a214e7aeaaa9f45f0db8784a7b743b.tar.gz
krb5-02d6bcbc98a214e7aeaaa9f45f0db8784a7b743b.tar.xz
krb5-02d6bcbc98a214e7aeaaa9f45f0db8784a7b743b.zip
make mark-cstyle
make reindent git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23100 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/kdb/kdb_log.c')
-rw-r--r--src/lib/kdb/kdb_log.c975
1 files changed, 488 insertions, 487 deletions
diff --git a/src/lib/kdb/kdb_log.c b/src/lib/kdb/kdb_log.c
index 3652935a14..fe128535cf 100644
--- a/src/lib/kdb/kdb_log.c
+++ b/src/lib/kdb/kdb_log.c
@@ -1,9 +1,10 @@
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-/* #pragma ident "@(#)kdb_log.c 1.3 04/02/23 SMI" */
+/* #pragma ident "@(#)kdb_log.c 1.3 04/02/23 SMI" */
#include <sys/stat.h>
#include <sys/types.h>
@@ -23,15 +24,15 @@
* modify the Kerberos principal update and header logs.
*/
-#define getpagesize() sysconf(_SC_PAGESIZE)
+#define getpagesize() sysconf(_SC_PAGESIZE)
-static int pagesize = 0;
+static int pagesize = 0;
-#define INIT_ULOG(ctx) \
- log_ctx = ctx->kdblog_context; \
- assert(log_ctx != NULL); \
- ulog = log_ctx->ulog; \
- assert(ulog != NULL)
+#define INIT_ULOG(ctx) \
+ log_ctx = ctx->kdblog_context; \
+ assert(log_ctx != NULL); \
+ ulog = log_ctx->ulog; \
+ assert(ulog != NULL)
/* XXX */
typedef unsigned long ulong_t;
@@ -46,9 +47,9 @@ ulog_lock(krb5_context ctx, int mode)
kdb_hlog_t *ulog = NULL;
if (ctx == NULL)
- return KRB5_LOG_ERROR;
+ return KRB5_LOG_ERROR;
if (ctx->kdblog_context == NULL || ctx->kdblog_context->iproprole == IPROP_NULL)
- return 0;
+ return 0;
INIT_ULOG(ctx);
return krb5_lock_file(ctx, log_ctx->ulogfd, mode);
}
@@ -59,23 +60,23 @@ ulog_lock(krb5_context ctx, int mode)
static krb5_error_code
ulog_sync_update(kdb_hlog_t *ulog, kdb_ent_header_t *upd)
{
- ulong_t start, end, size;
- krb5_error_code retval;
+ ulong_t start, end, size;
+ krb5_error_code retval;
if (ulog == NULL)
- return (KRB5_LOG_ERROR);
+ return (KRB5_LOG_ERROR);
if (!pagesize)
- pagesize = getpagesize();
+ pagesize = getpagesize();
start = ((ulong_t)upd) & (~(pagesize-1));
end = (((ulong_t)upd) + ulog->kdb_block +
- (pagesize-1)) & (~(pagesize-1));
+ (pagesize-1)) & (~(pagesize-1));
size = end - start;
if ((retval = msync((caddr_t)start, size, MS_SYNC))) {
- return (retval);
+ return (retval);
}
return (0);
@@ -89,14 +90,14 @@ ulog_sync_header(kdb_hlog_t *ulog)
{
if (!pagesize)
- pagesize = getpagesize();
+ pagesize = getpagesize();
if (msync((caddr_t)ulog, pagesize, MS_SYNC)) {
- /*
- * Couldn't sync to disk, let's panic
- */
- syslog(LOG_ERR, "ulog_sync_header: could not sync to disk");
- abort();
+ /*
+ * Couldn't sync to disk, let's panic
+ */
+ syslog(LOG_ERR, "ulog_sync_header: could not sync to disk");
+ abort();
}
}
@@ -109,10 +110,10 @@ ulog_sync_header(kdb_hlog_t *ulog)
static krb5_error_code
ulog_resize(kdb_hlog_t *ulog, uint32_t ulogentries, int ulogfd, uint_t recsize)
{
- uint_t new_block, new_size;
+ uint_t new_block, new_size;
if (ulog == NULL)
- return (KRB5_LOG_ERROR);
+ return (KRB5_LOG_ERROR);
new_size = sizeof (kdb_hlog_t);
@@ -122,28 +123,28 @@ ulog_resize(kdb_hlog_t *ulog, uint32_t ulogentries, int ulogfd, uint_t recsize)
new_size += ulogentries * new_block;
if (new_size <= MAXLOGLEN) {
- /*
- * Reinit log with new block size
- */
- (void) memset(ulog, 0, sizeof (kdb_hlog_t));
-
- ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
- ulog->db_version_num = KDB_VERSION;
- ulog->kdb_state = KDB_STABLE;
- ulog->kdb_block = new_block;
-
- ulog_sync_header(ulog);
-
- /*
- * Time to expand log considering new block size
- */
- if (extend_file_to(ulogfd, new_size) < 0)
- return errno;
+ /*
+ * Reinit log with new block size
+ */
+ (void) memset(ulog, 0, sizeof (kdb_hlog_t));
+
+ ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
+ ulog->db_version_num = KDB_VERSION;
+ ulog->kdb_state = KDB_STABLE;
+ ulog->kdb_block = new_block;
+
+ ulog_sync_header(ulog);
+
+ /*
+ * Time to expand log considering new block size
+ */
+ if (extend_file_to(ulogfd, new_size) < 0)
+ return errno;
} else {
- /*
- * Can't map into file larger than MAXLOGLEN
- */
- return (KRB5_LOG_ERROR);
+ /*
+ * Can't map into file larger than MAXLOGLEN
+ */
+ return (KRB5_LOG_ERROR);
}
return (0);
@@ -158,25 +159,25 @@ ulog_resize(kdb_hlog_t *ulog, uint32_t ulogentries, int ulogfd, uint_t recsize)
krb5_error_code
ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
{
- XDR xdrs;
- kdbe_time_t ktime;
- struct timeval timestamp;
+ XDR xdrs;
+ kdbe_time_t ktime;
+ struct timeval timestamp;
kdb_ent_header_t *indx_log;
- uint_t i, recsize;
- ulong_t upd_size;
- krb5_error_code retval;
- kdb_sno_t cur_sno;
- kdb_log_context *log_ctx;
- kdb_hlog_t *ulog = NULL;
- uint32_t ulogentries;
- int ulogfd;
+ uint_t i, recsize;
+ ulong_t upd_size;
+ krb5_error_code retval;
+ kdb_sno_t cur_sno;
+ kdb_log_context *log_ctx;
+ kdb_hlog_t *ulog = NULL;
+ uint32_t ulogentries;
+ int ulogfd;
INIT_ULOG(context);
ulogentries = log_ctx->ulogentries;
ulogfd = log_ctx->ulogfd;
if (upd == NULL)
- return (KRB5_LOG_ERROR);
+ return (KRB5_LOG_ERROR);
(void) gettimeofday(&timestamp, NULL);
ktime.seconds = timestamp.tv_sec;
@@ -187,10 +188,10 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
recsize = sizeof (kdb_ent_header_t) + upd_size;
if (recsize > ulog->kdb_block) {
- if ((retval = ulog_resize(ulog, ulogentries, ulogfd, recsize))) {
- /* Resize element array failed */
- return (retval);
- }
+ if ((retval = ulog_resize(ulog, ulogentries, ulogfd, recsize))) {
+ /* Resize element array failed */
+ return (retval);
+ }
}
cur_sno = ulog->kdb_last_sno;
@@ -200,9 +201,9 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
* resyncs once they see their sno > than the masters.
*/
if (cur_sno == ULONG_MAX)
- cur_sno = 1;
+ cur_sno = 1;
else
- cur_sno++;
+ cur_sno++;
/*
* We squirrel this away for finish_update() to index
@@ -224,15 +225,15 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
ulog->kdb_state = KDB_UNSTABLE;
xdrmem_create(&xdrs, (char *)indx_log->entry_data,
- indx_log->kdb_entry_size, XDR_ENCODE);
+ indx_log->kdb_entry_size, XDR_ENCODE);
if (!xdr_kdb_incr_update_t(&xdrs, upd))
- return (KRB5_LOG_CONV);
+ return (KRB5_LOG_CONV);
if ((retval = ulog_sync_update(ulog, indx_log)))
- return (retval);
+ return (retval);
if (ulog->kdb_num < ulogentries)
- ulog->kdb_num++;
+ ulog->kdb_num++;
ulog->kdb_last_sno = cur_sno;
ulog->kdb_last_time = ktime;
@@ -242,13 +243,13 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
* always kdb_entry_sno + 1.
*/
if (cur_sno > ulogentries) {
- i = upd->kdb_entry_sno % ulogentries;
- indx_log = (kdb_ent_header_t *)INDEX(ulog, i);
- ulog->kdb_first_sno = indx_log->kdb_entry_sno;
- ulog->kdb_first_time = indx_log->kdb_time;
+ i = upd->kdb_entry_sno % ulogentries;
+ indx_log = (kdb_ent_header_t *)INDEX(ulog, i);
+ ulog->kdb_first_sno = indx_log->kdb_entry_sno;
+ ulog->kdb_first_time = indx_log->kdb_time;
} else if (cur_sno == 1) {
- ulog->kdb_first_sno = 1;
- ulog->kdb_first_time = indx_log->kdb_time;
+ ulog->kdb_first_sno = 1;
+ ulog->kdb_first_time = indx_log->kdb_time;
}
ulog_sync_header(ulog);
@@ -263,12 +264,12 @@ ulog_add_update(krb5_context context, kdb_incr_update_t *upd)
krb5_error_code
ulog_finish_update(krb5_context context, kdb_incr_update_t *upd)
{
- krb5_error_code retval;
- kdb_ent_header_t *indx_log;
- uint_t i;
- kdb_log_context *log_ctx;
- kdb_hlog_t *ulog = NULL;
- uint32_t ulogentries;
+ krb5_error_code retval;
+ kdb_ent_header_t *indx_log;
+ uint_t i;
+ kdb_log_context *log_ctx;
+ kdb_hlog_t *ulog = NULL;
+ uint32_t ulogentries;
INIT_ULOG(context);
ulogentries = log_ctx->ulogentries;
@@ -282,7 +283,7 @@ ulog_finish_update(krb5_context context, kdb_incr_update_t *upd)
ulog->kdb_state = KDB_STABLE;
if ((retval = ulog_sync_update(ulog, indx_log)))
- return (retval);
+ return (retval);
ulog_sync_header(ulog);
@@ -323,15 +324,15 @@ ulog_delete_update(krb5_context context, kdb_incr_update_t *upd)
krb5_error_code
ulog_replay(krb5_context context, kdb_incr_result_t *incr_ret, char **db_args)
{
- krb5_db_entry *entry = NULL;
- kdb_incr_update_t *upd = NULL, *fupd;
- int i, no_of_updates;
- krb5_error_code retval;
- krb5_principal dbprinc = NULL;
- kdb_last_t errlast;
- char *dbprincstr = NULL;
- kdb_log_context *log_ctx;
- kdb_hlog_t *ulog = NULL;
+ krb5_db_entry *entry = NULL;
+ kdb_incr_update_t *upd = NULL, *fupd;
+ int i, no_of_updates;
+ krb5_error_code retval;
+ krb5_principal dbprinc = NULL;
+ kdb_last_t errlast;
+ char *dbprincstr = NULL;
+ kdb_log_context *log_ctx;
+ kdb_hlog_t *ulog = NULL;
INIT_ULOG(context);
@@ -348,84 +349,84 @@ ulog_replay(krb5_context context, kdb_incr_result_t *incr_ret, char **db_args)
errlast.last_time.useconds = (unsigned int)0;
if ((retval = krb5_db_open(context, db_args,
- KRB5_KDB_OPEN_RW|KRB5_KDB_SRV_TYPE_ADMIN)))
- goto cleanup;
+ KRB5_KDB_OPEN_RW|KRB5_KDB_SRV_TYPE_ADMIN)))
+ goto cleanup;
for (i = 0; i < no_of_updates; i++) {
- int nentry = 1;
+ int nentry = 1;
- if (!upd->kdb_commit)
- continue;
+ if (!upd->kdb_commit)
+ continue;
- if (upd->kdb_deleted) {
- dbprincstr = malloc((upd->kdb_princ_name.utf8str_t_len
- + 1) * sizeof (char));
+ if (upd->kdb_deleted) {
+ dbprincstr = malloc((upd->kdb_princ_name.utf8str_t_len
+ + 1) * sizeof (char));
- if (dbprincstr == NULL) {
- retval = ENOMEM;
- goto cleanup;
- }
+ if (dbprincstr == NULL) {
+ retval = ENOMEM;
+ goto cleanup;
+ }
- (void) strncpy(dbprincstr,
- (char *)upd->kdb_princ_name.utf8str_t_val,
- (upd->kdb_princ_name.utf8str_t_len + 1));
- dbprincstr[upd->kdb_princ_name.utf8str_t_len] = 0;
+ (void) strncpy(dbprincstr,
+ (char *)upd->kdb_princ_name.utf8str_t_val,
+ (upd->kdb_princ_name.utf8str_t_len + 1));
+ dbprincstr[upd->kdb_princ_name.utf8str_t_len] = 0;
- if ((retval = krb5_parse_name(context, dbprincstr,
- &dbprinc))) {
- goto cleanup;
- }
+ if ((retval = krb5_parse_name(context, dbprincstr,
+ &dbprinc))) {
+ goto cleanup;
+ }
- free(dbprincstr);
+ free(dbprincstr);
- retval = krb5int_delete_principal_no_log(context,
- dbprinc,
- &nentry);
+ retval = krb5int_delete_principal_no_log(context,
+ dbprinc,
+ &nentry);
- if (dbprinc) {
- krb5_free_principal(context, dbprinc);
- dbprinc = NULL;
- }
+ if (dbprinc) {
+ krb5_free_principal(context, dbprinc);
+ dbprinc = NULL;
+ }
- if (retval)
- goto cleanup;
- } else {
- entry = (krb5_db_entry *)malloc(sizeof (krb5_db_entry));
+ if (retval)
+ goto cleanup;
+ } else {
+ entry = (krb5_db_entry *)malloc(sizeof (krb5_db_entry));
- if (!entry) {
- retval = errno;
- goto cleanup;
- }
+ if (!entry) {
+ retval = errno;
+ goto cleanup;
+ }
- (void) memset(entry, 0, sizeof (krb5_db_entry));
+ (void) memset(entry, 0, sizeof (krb5_db_entry));
- if ((retval = ulog_conv_2dbentry(context, entry, upd, 1)))
- goto cleanup;
+ if ((retval = ulog_conv_2dbentry(context, entry, upd, 1)))
+ goto cleanup;
- retval = krb5int_put_principal_no_log(context, entry,
- &nentry);
+ retval = krb5int_put_principal_no_log(context, entry,
+ &nentry);
- if (entry) {
- krb5_db_free_principal(context, entry, nentry);
- free(entry);
- entry = NULL;
- }
- if (retval)
- goto cleanup;
- }
+ if (entry) {
+ krb5_db_free_principal(context, entry, nentry);
+ free(entry);
+ entry = NULL;
+ }
+ if (retval)
+ goto cleanup;
+ }
- upd++;
+ upd++;
}
cleanup:
if (fupd)
- ulog_free_entries(fupd, no_of_updates);
+ ulog_free_entries(fupd, no_of_updates);
if (log_ctx && (log_ctx->iproprole == IPROP_SLAVE)) {
- if (retval)
- ulog_finish_update_slave(ulog, errlast);
- else
- ulog_finish_update_slave(ulog, incr_ret->lastentry);
+ if (retval)
+ ulog_finish_update_slave(ulog, errlast);
+ else
+ ulog_finish_update_slave(ulog, incr_ret->lastentry);
}
return (retval);
@@ -440,95 +441,95 @@ cleanup:
static krb5_error_code
ulog_check(krb5_context context, kdb_hlog_t *ulog, char **db_args)
{
- XDR xdrs;
- krb5_error_code retval = 0;
- unsigned int i;
- kdb_ent_header_t *indx_log;
- kdb_incr_update_t *upd = NULL;
- kdb_incr_result_t *incr_ret = NULL;
+ XDR xdrs;
+ krb5_error_code retval = 0;
+ unsigned int i;
+ kdb_ent_header_t *indx_log;
+ kdb_incr_update_t *upd = NULL;
+ kdb_incr_result_t *incr_ret = NULL;
ulog->kdb_state = KDB_STABLE;
for (i = 0; i < ulog->kdb_num; i++) {
- indx_log = (kdb_ent_header_t *)INDEX(ulog, i);
-
- if (indx_log->kdb_umagic != KDB_ULOG_MAGIC) {
- /*
- * Update entry corrupted we should scream and die
- */
- ulog->kdb_state = KDB_CORRUPT;
- retval = KRB5_LOG_CORRUPT;
- break;
- }
-
- if (indx_log->kdb_commit == FALSE) {
- ulog->kdb_state = KDB_UNSTABLE;
-
- incr_ret = (kdb_incr_result_t *)
- malloc(sizeof (kdb_incr_result_t));
- if (incr_ret == NULL) {
- retval = errno;
- goto error;
- }
-
- upd = (kdb_incr_update_t *)
- malloc(sizeof (kdb_incr_update_t));
- if (upd == NULL) {
- retval = errno;
- goto error;
- }
-
- (void) memset(upd, 0, sizeof (kdb_incr_update_t));
- xdrmem_create(&xdrs, (char *)indx_log->entry_data,
- indx_log->kdb_entry_size, XDR_DECODE);
- if (!xdr_kdb_incr_update_t(&xdrs, upd)) {
- retval = KRB5_LOG_CONV;
- goto error;
- }
-
- incr_ret->updates.kdb_ulog_t_len = 1;
- incr_ret->updates.kdb_ulog_t_val = upd;
-
- upd->kdb_commit = TRUE;
-
- /*
- * We don't want to readd this update and just use the
- * existing update to be propagated later on
- */
- ulog_set_role(context, IPROP_NULL);
- retval = ulog_replay(context, incr_ret, db_args);
-
- /*
- * upd was freed by ulog_replay, we NULL
- * the pointer in case we subsequently break from loop.
- */
- upd = NULL;
- if (incr_ret) {
- free(incr_ret);
- incr_ret = NULL;
- }
- ulog_set_role(context, IPROP_MASTER);
-
- if (retval)
- goto error;
-
- /*
- * We flag this as committed since this was
- * the last entry before kadmind crashed, ergo
- * the slaves have not seen this update before
- */
- indx_log->kdb_commit = TRUE;
- retval = ulog_sync_update(ulog, indx_log);
- if (retval)
- goto error;
-
- ulog->kdb_state = KDB_STABLE;
- }
+ indx_log = (kdb_ent_header_t *)INDEX(ulog, i);
+
+ if (indx_log->kdb_umagic != KDB_ULOG_MAGIC) {
+ /*
+ * Update entry corrupted we should scream and die
+ */
+ ulog->kdb_state = KDB_CORRUPT;
+ retval = KRB5_LOG_CORRUPT;
+ break;
+ }
+
+ if (indx_log->kdb_commit == FALSE) {
+ ulog->kdb_state = KDB_UNSTABLE;
+
+ incr_ret = (kdb_incr_result_t *)
+ malloc(sizeof (kdb_incr_result_t));
+ if (incr_ret == NULL) {
+ retval = errno;
+ goto error;
+ }
+
+ upd = (kdb_incr_update_t *)
+ malloc(sizeof (kdb_incr_update_t));
+ if (upd == NULL) {
+ retval = errno;
+ goto error;
+ }
+
+ (void) memset(upd, 0, sizeof (kdb_incr_update_t));
+ xdrmem_create(&xdrs, (char *)indx_log->entry_data,
+ indx_log->kdb_entry_size, XDR_DECODE);
+ if (!xdr_kdb_incr_update_t(&xdrs, upd)) {
+ retval = KRB5_LOG_CONV;
+ goto error;
+ }
+
+ incr_ret->updates.kdb_ulog_t_len = 1;
+ incr_ret->updates.kdb_ulog_t_val = upd;
+
+ upd->kdb_commit = TRUE;
+
+ /*
+ * We don't want to readd this update and just use the
+ * existing update to be propagated later on
+ */
+ ulog_set_role(context, IPROP_NULL);
+ retval = ulog_replay(context, incr_ret, db_args);
+
+ /*
+ * upd was freed by ulog_replay, we NULL
+ * the pointer in case we subsequently break from loop.
+ */
+ upd = NULL;
+ if (incr_ret) {
+ free(incr_ret);
+ incr_ret = NULL;
+ }
+ ulog_set_role(context, IPROP_MASTER);
+
+ if (retval)
+ goto error;
+
+ /*
+ * We flag this as committed since this was
+ * the last entry before kadmind crashed, ergo
+ * the slaves have not seen this update before
+ */
+ indx_log->kdb_commit = TRUE;
+ retval = ulog_sync_update(ulog, indx_log);
+ if (retval)
+ goto error;
+
+ ulog->kdb_state = KDB_STABLE;
+ }
}
error:
if (upd)
- ulog_free_entries(upd, 1);
+ ulog_free_entries(upd, 1);
free(incr_ret);
@@ -547,134 +548,134 @@ error:
*/
krb5_error_code
ulog_map(krb5_context context, const char *logname, uint32_t ulogentries,
- int caller, char **db_args)
+ int caller, char **db_args)
{
- struct stat st;
- krb5_error_code retval;
- uint32_t ulog_filesize;
- kdb_log_context *log_ctx;
- kdb_hlog_t *ulog = NULL;
- int ulogfd = -1;
+ struct stat st;
+ krb5_error_code retval;
+ uint32_t ulog_filesize;
+ kdb_log_context *log_ctx;
+ kdb_hlog_t *ulog = NULL;
+ int ulogfd = -1;
ulog_filesize = sizeof (kdb_hlog_t);
if (stat(logname, &st) == -1) {
- if (caller == FKPROPLOG) {
- /*
- * File doesn't exist so we exit with kproplog
- */
- return (errno);
- }
+ if (caller == FKPROPLOG) {
+ /*
+ * File doesn't exist so we exit with kproplog
+ */
+ return (errno);
+ }
- if ((ulogfd = open(logname, O_RDWR+O_CREAT, 0600)) == -1) {
- return (errno);
- }
+ if ((ulogfd = open(logname, O_RDWR+O_CREAT, 0600)) == -1) {
+ return (errno);
+ }
- if (lseek(ulogfd, 0L, SEEK_CUR) == -1) {
- return (errno);
- }
+ if (lseek(ulogfd, 0L, SEEK_CUR) == -1) {
+ return (errno);
+ }
- if ((caller == FKADMIND) || (caller == FKCOMMAND))
- ulog_filesize += ulogentries * ULOG_BLOCK;
+ if ((caller == FKADMIND) || (caller == FKCOMMAND))
+ ulog_filesize += ulogentries * ULOG_BLOCK;
- if (extend_file_to(ulogfd, ulog_filesize) < 0)
- return errno;
+ if (extend_file_to(ulogfd, ulog_filesize) < 0)
+ return errno;
} else {
- ulogfd = open(logname, O_RDWR, 0600);
- if (ulogfd == -1)
- /*
- * Can't open existing log file
- */
- return errno;
+ ulogfd = open(logname, O_RDWR, 0600);
+ if (ulogfd == -1)
+ /*
+ * Can't open existing log file
+ */
+ return errno;
}
if (caller == FKPROPLOG) {
- if (fstat(ulogfd, &st) < 0) {
- close(ulogfd);
- return errno;
- }
- ulog_filesize = st.st_size;
-
- ulog = (kdb_hlog_t *)mmap(0, ulog_filesize,
- PROT_READ+PROT_WRITE, MAP_PRIVATE, ulogfd, 0);
+ if (fstat(ulogfd, &st) < 0) {
+ close(ulogfd);
+ return errno;
+ }
+ ulog_filesize = st.st_size;
+
+ ulog = (kdb_hlog_t *)mmap(0, ulog_filesize,
+ PROT_READ+PROT_WRITE, MAP_PRIVATE, ulogfd, 0);
} else {
- /*
- * else kadmind, kpropd, & kcommands should udpate stores
- */
- ulog = (kdb_hlog_t *)mmap(0, MAXLOGLEN,
- PROT_READ+PROT_WRITE, MAP_SHARED, ulogfd, 0);
+ /*
+ * else kadmind, kpropd, & kcommands should udpate stores
+ */
+ ulog = (kdb_hlog_t *)mmap(0, MAXLOGLEN,
+ PROT_READ+PROT_WRITE, MAP_SHARED, ulogfd, 0);
}
if ((int)(ulog) == -1) {
- /*
- * Can't map update log file to memory
- */
- close(ulogfd);
- return (errno);
+ /*
+ * Can't map update log file to memory
+ */
+ close(ulogfd);
+ return (errno);
}
if (!context->kdblog_context) {
- if (!(log_ctx = malloc(sizeof (kdb_log_context))))
- return (errno);
- memset(log_ctx, 0, sizeof(*log_ctx));
- context->kdblog_context = log_ctx;
+ if (!(log_ctx = malloc(sizeof (kdb_log_context))))
+ return (errno);
+ memset(log_ctx, 0, sizeof(*log_ctx));
+ context->kdblog_context = log_ctx;
} else
- log_ctx = context->kdblog_context;
+ log_ctx = context->kdblog_context;
log_ctx->ulog = ulog;
log_ctx->ulogentries = ulogentries;
log_ctx->ulogfd = ulogfd;
if (ulog->kdb_hmagic != KDB_ULOG_HDR_MAGIC) {
- if (ulog->kdb_hmagic == 0) {
- /*
- * New update log
- */
- (void) memset(ulog, 0, sizeof (kdb_hlog_t));
-
- ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
- ulog->db_version_num = KDB_VERSION;
- ulog->kdb_state = KDB_STABLE;
- ulog->kdb_block = ULOG_BLOCK;
- if (!(caller == FKPROPLOG))
- ulog_sync_header(ulog);
- } else {
- return (KRB5_LOG_CORRUPT);
- }
+ if (ulog->kdb_hmagic == 0) {
+ /*
+ * New update log
+ */
+ (void) memset(ulog, 0, sizeof (kdb_hlog_t));
+
+ ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
+ ulog->db_version_num = KDB_VERSION;
+ ulog->kdb_state = KDB_STABLE;
+ ulog->kdb_block = ULOG_BLOCK;
+ if (!(caller == FKPROPLOG))
+ ulog_sync_header(ulog);
+ } else {
+ return (KRB5_LOG_CORRUPT);
+ }
}
if (caller == FKADMIND) {
- retval = ulog_lock(context, KRB5_LOCKMODE_EXCLUSIVE);
- if (retval)
- return retval;
- switch (ulog->kdb_state) {
- case KDB_STABLE:
- case KDB_UNSTABLE:
- /*
- * Log is currently un/stable, check anyway
- */
- retval = ulog_check(context, ulog, db_args);
- ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- if (retval == KRB5_LOG_CORRUPT) {
- return (retval);
- }
- break;
- case KDB_CORRUPT:
- ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- return (KRB5_LOG_CORRUPT);
- default:
- /*
- * Invalid db state
- */
- ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- return (KRB5_LOG_ERROR);
- }
+ retval = ulog_lock(context, KRB5_LOCKMODE_EXCLUSIVE);
+ if (retval)
+ return retval;
+ switch (ulog->kdb_state) {
+ case KDB_STABLE:
+ case KDB_UNSTABLE:
+ /*
+ * Log is currently un/stable, check anyway
+ */
+ retval = ulog_check(context, ulog, db_args);
+ ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ if (retval == KRB5_LOG_CORRUPT) {
+ return (retval);
+ }
+ break;
+ case KDB_CORRUPT:
+ ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ return (KRB5_LOG_CORRUPT);
+ default:
+ /*
+ * Invalid db state
+ */
+ ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ return (KRB5_LOG_ERROR);
+ }
} else if ((caller == FKPROPLOG) || (caller == FKPROPD)) {
- /*
- * kproplog and kpropd don't need to do anything else
- */
- return (0);
+ /*
+ * kproplog and kpropd don't need to do anything else
+ */
+ return (0);
}
/*
@@ -683,33 +684,33 @@ ulog_map(krb5_context context, const char *logname, uint32_t ulogentries,
*/
retval = ulog_lock(context, KRB5_LOCKMODE_EXCLUSIVE);
if (retval)
- return retval;
+ return retval;
if (ulog->kdb_num != ulogentries) {
- if ((ulog->kdb_num != 0) &&
- ((ulog->kdb_last_sno > ulog->kdb_num) ||
- (ulog->kdb_num > ulogentries))) {
-
- (void) memset(ulog, 0, sizeof (kdb_hlog_t));
-
- ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
- ulog->db_version_num = KDB_VERSION;
- ulog->kdb_state = KDB_STABLE;
- ulog->kdb_block = ULOG_BLOCK;
-
- ulog_sync_header(ulog);
- }
-
- /*
- * Expand ulog if we have specified a greater size
- */
- if (ulog->kdb_num < ulogentries) {
- ulog_filesize += ulogentries * ulog->kdb_block;
-
- if (extend_file_to(ulogfd, ulog_filesize) < 0) {
- ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- return errno;
- }
- }
+ if ((ulog->kdb_num != 0) &&
+ ((ulog->kdb_last_sno > ulog->kdb_num) ||
+ (ulog->kdb_num > ulogentries))) {
+
+ (void) memset(ulog, 0, sizeof (kdb_hlog_t));
+
+ ulog->kdb_hmagic = KDB_ULOG_HDR_MAGIC;
+ ulog->db_version_num = KDB_VERSION;
+ ulog->kdb_state = KDB_STABLE;
+ ulog->kdb_block = ULOG_BLOCK;
+
+ ulog_sync_header(ulog);
+ }
+
+ /*
+ * Expand ulog if we have specified a greater size
+ */
+ if (ulog->kdb_num < ulogentries) {
+ ulog_filesize += ulogentries * ulog->kdb_block;
+
+ if (extend_file_to(ulogfd, ulog_filesize) < 0) {
+ ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ return errno;
+ }
+ }
}
ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
@@ -720,44 +721,44 @@ ulog_map(krb5_context context, const char *logname, uint32_t ulogentries,
* Get the last set of updates seen, (last+1) to n is returned.
*/
krb5_error_code
-ulog_get_entries(krb5_context context, /* input - krb5 lib config */
- kdb_last_t last, /* input - slave's last sno */
- kdb_incr_result_t *ulog_handle) /* output - incr result for slave */
+ulog_get_entries(krb5_context context, /* input - krb5 lib config */
+ kdb_last_t last, /* input - slave's last sno */
+ kdb_incr_result_t *ulog_handle) /* output - incr result for slave */
{
- XDR xdrs;
- kdb_ent_header_t *indx_log;
- kdb_incr_update_t *upd;
- uint_t indx, count, tdiff;
- uint32_t sno;
- krb5_error_code retval;
- struct timeval timestamp;
- kdb_log_context *log_ctx;
- kdb_hlog_t *ulog = NULL;
- uint32_t ulogentries;
+ XDR xdrs;
+ kdb_ent_header_t *indx_log;
+ kdb_incr_update_t *upd;
+ uint_t indx, count, tdiff;
+ uint32_t sno;
+ krb5_error_code retval;
+ struct timeval timestamp;
+ kdb_log_context *log_ctx;
+ kdb_hlog_t *ulog = NULL;
+ uint32_t ulogentries;
INIT_ULOG(context);
ulogentries = log_ctx->ulogentries;
retval = ulog_lock(context, KRB5_LOCKMODE_SHARED);
if (retval)
- return retval;
+ return retval;
/*
* Check to make sure we don't have a corrupt ulog first.
*/
if (ulog->kdb_state == KDB_CORRUPT) {
- ulog_handle->ret = UPDATE_ERROR;
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- return (KRB5_LOG_CORRUPT);
+ ulog_handle->ret = UPDATE_ERROR;
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ return (KRB5_LOG_CORRUPT);
}
gettimeofday(&timestamp, NULL);
tdiff = timestamp.tv_sec - ulog->kdb_last_time.seconds;
if (tdiff <= ULOG_IDLE_TIME) {
- ulog_handle->ret = UPDATE_BUSY;
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- return (0);
+ ulog_handle->ret = UPDATE_BUSY;
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ return (0);
}
/*
@@ -767,8 +768,8 @@ ulog_get_entries(krb5_context context, /* input - krb5 lib config */
*/
retval = krb5_db_lock(context, KRB5_LOCKMODE_SHARED);
if (retval) {
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- return (retval);
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ return (retval);
}
/*
@@ -776,103 +777,103 @@ ulog_get_entries(krb5_context context, /* input - krb5 lib config */
* the client's ulog has just been created.
*/
if ((last.last_sno > ulog->kdb_last_sno) ||
- (last.last_sno < ulog->kdb_first_sno) ||
- (last.last_sno == 0)) {
- ulog_handle->lastentry.last_sno = ulog->kdb_last_sno;
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- (void) krb5_db_unlock(context);
- ulog_handle->ret = UPDATE_FULL_RESYNC_NEEDED;
- return (0);
+ (last.last_sno < ulog->kdb_first_sno) ||
+ (last.last_sno == 0)) {
+ ulog_handle->lastentry.last_sno = ulog->kdb_last_sno;
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ (void) krb5_db_unlock(context);
+ ulog_handle->ret = UPDATE_FULL_RESYNC_NEEDED;
+ return (0);
} else if (last.last_sno <= ulog->kdb_last_sno) {
- sno = last.last_sno;
-
- indx = (sno - 1) % ulogentries;
-
- indx_log = (kdb_ent_header_t *)INDEX(ulog, indx);
-
- /*
- * Validate the time stamp just to make sure it was the same sno
- */
- if ((indx_log->kdb_time.seconds == last.last_time.seconds) &&
- (indx_log->kdb_time.useconds == last.last_time.useconds)) {
-
- /*
- * If we have the same sno we return success
- */
- if (last.last_sno == ulog->kdb_last_sno) {
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- (void) krb5_db_unlock(context);
- ulog_handle->ret = UPDATE_NIL;
- return (0);
- }
-
- count = ulog->kdb_last_sno - sno;
-
- ulog_handle->updates.kdb_ulog_t_val =
- (kdb_incr_update_t *)malloc(
- sizeof (kdb_incr_update_t) * count);
-
- upd = ulog_handle->updates.kdb_ulog_t_val;
-
- if (upd == NULL) {
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- (void) krb5_db_unlock(context);
- ulog_handle->ret = UPDATE_ERROR;
- return (errno);
- }
-
- while (sno < ulog->kdb_last_sno) {
- indx = sno % ulogentries;
-
- indx_log = (kdb_ent_header_t *)
- INDEX(ulog, indx);
-
- (void) memset(upd, 0,
- sizeof (kdb_incr_update_t));
- xdrmem_create(&xdrs,
- (char *)indx_log->entry_data,
- indx_log->kdb_entry_size, XDR_DECODE);
- if (!xdr_kdb_incr_update_t(&xdrs, upd)) {
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- (void) krb5_db_unlock(context);
- ulog_handle->ret = UPDATE_ERROR;
- return (KRB5_LOG_CONV);
- }
- /*
- * Mark commitment since we didn't
- * want to decode and encode the
- * incr update record the first time.
- */
- upd->kdb_commit = indx_log->kdb_commit;
-
- upd++;
- sno++;
- } /* while */
-
- ulog_handle->updates.kdb_ulog_t_len = count;
-
- ulog_handle->lastentry.last_sno = ulog->kdb_last_sno;
- ulog_handle->lastentry.last_time.seconds =
- ulog->kdb_last_time.seconds;
- ulog_handle->lastentry.last_time.useconds =
- ulog->kdb_last_time.useconds;
- ulog_handle->ret = UPDATE_OK;
-
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- (void) krb5_db_unlock(context);
-
- return (0);
- } else {
- /*
- * We have time stamp mismatch or we no longer have
- * the slave's last sno, so we brute force it
- */
- (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
- (void) krb5_db_unlock(context);
- ulog_handle->ret = UPDATE_FULL_RESYNC_NEEDED;
-
- return (0);
- }
+ sno = last.last_sno;
+
+ indx = (sno - 1) % ulogentries;
+
+ indx_log = (kdb_ent_header_t *)INDEX(ulog, indx);
+
+ /*
+ * Validate the time stamp just to make sure it was the same sno
+ */
+ if ((indx_log->kdb_time.seconds == last.last_time.seconds) &&
+ (indx_log->kdb_time.useconds == last.last_time.useconds)) {
+
+ /*
+ * If we have the same sno we return success
+ */
+ if (last.last_sno == ulog->kdb_last_sno) {
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ (void) krb5_db_unlock(context);
+ ulog_handle->ret = UPDATE_NIL;
+ return (0);
+ }
+
+ count = ulog->kdb_last_sno - sno;
+
+ ulog_handle->updates.kdb_ulog_t_val =
+ (kdb_incr_update_t *)malloc(
+ sizeof (kdb_incr_update_t) * count);
+
+ upd = ulog_handle->updates.kdb_ulog_t_val;
+
+ if (upd == NULL) {
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ (void) krb5_db_unlock(context);
+ ulog_handle->ret = UPDATE_ERROR;
+ return (errno);
+ }
+
+ while (sno < ulog->kdb_last_sno) {
+ indx = sno % ulogentries;
+
+ indx_log = (kdb_ent_header_t *)
+ INDEX(ulog, indx);
+
+ (void) memset(upd, 0,
+ sizeof (kdb_incr_update_t));
+ xdrmem_create(&xdrs,
+ (char *)indx_log->entry_data,
+ indx_log->kdb_entry_size, XDR_DECODE);
+ if (!xdr_kdb_incr_update_t(&xdrs, upd)) {
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ (void) krb5_db_unlock(context);
+ ulog_handle->ret = UPDATE_ERROR;
+ return (KRB5_LOG_CONV);
+ }
+ /*
+ * Mark commitment since we didn't
+ * want to decode and encode the
+ * incr update record the first time.
+ */
+ upd->kdb_commit = indx_log->kdb_commit;
+
+ upd++;
+ sno++;
+ } /* while */
+
+ ulog_handle->updates.kdb_ulog_t_len = count;
+
+ ulog_handle->lastentry.last_sno = ulog->kdb_last_sno;
+ ulog_handle->lastentry.last_time.seconds =
+ ulog->kdb_last_time.seconds;
+ ulog_handle->lastentry.last_time.useconds =
+ ulog->kdb_last_time.useconds;
+ ulog_handle->ret = UPDATE_OK;
+
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ (void) krb5_db_unlock(context);
+
+ return (0);
+ } else {
+ /*
+ * We have time stamp mismatch or we no longer have
+ * the slave's last sno, so we brute force it
+ */
+ (void) ulog_lock(context, KRB5_LOCKMODE_UNLOCK);
+ (void) krb5_db_unlock(context);
+ ulog_handle->ret = UPDATE_FULL_RESYNC_NEEDED;
+
+ return (0);
+ }
}
/*
@@ -886,15 +887,15 @@ ulog_get_entries(krb5_context context, /* input - krb5 lib config */
krb5_error_code
ulog_set_role(krb5_context ctx, iprop_role role)
{
- kdb_log_context *log_ctx;
+ kdb_log_context *log_ctx;
if (!ctx->kdblog_context) {
- if (!(log_ctx = malloc(sizeof (kdb_log_context))))
- return (errno);
- memset(log_ctx, 0, sizeof(*log_ctx));
- ctx->kdblog_context = log_ctx;
+ if (!(log_ctx = malloc(sizeof (kdb_log_context))))
+ return (errno);
+ memset(log_ctx, 0, sizeof(*log_ctx));
+ ctx->kdblog_context = log_ctx;
} else
- log_ctx = ctx->kdblog_context;
+ log_ctx = ctx->kdblog_context;
log_ctx->iproprole = role;
@@ -911,25 +912,25 @@ static int extend_file_to(int fd, uint_t new_size)
current_offset = lseek(fd, 0, SEEK_END);
if (current_offset < 0)
- return -1;
+ return -1;
if (new_size > INT_MAX) {
- errno = EINVAL;
- return -1;
+ errno = EINVAL;
+ return -1;
}
while (current_offset < new_size) {
- int write_size, wrote_size;
- write_size = new_size - current_offset;
- if (write_size > 512)
- write_size = 512;
- wrote_size = write(fd, zero, write_size);
- if (wrote_size < 0)
- return -1;
- if (wrote_size == 0) {
- errno = EINVAL; /* XXX ?? */
- return -1;
- }
- current_offset += wrote_size;
- write_size = new_size - current_offset;
+ int write_size, wrote_size;
+ write_size = new_size - current_offset;
+ if (write_size > 512)
+ write_size = 512;
+ wrote_size = write(fd, zero, write_size);
+ if (wrote_size < 0)
+ return -1;
+ if (wrote_size == 0) {
+ errno = EINVAL; /* XXX ?? */
+ return -1;
+ }
+ current_offset += wrote_size;
+ write_size = new_size - current_offset;
}
return 0;
}