summaryrefslogtreecommitdiffstats
path: root/src/slave/kproplog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/slave/kproplog.c')
-rw-r--r--src/slave/kproplog.c54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/slave/kproplog.c b/src/slave/kproplog.c
index 853aa0633f..ab49a0fe5e 100644
--- a/src/slave/kproplog.c
+++ b/src/slave/kproplog.c
@@ -11,6 +11,7 @@
#include <locale.h>
#include <stdio.h>
#include <sys/types.h>
+#include <sys/mman.h>
#include <time.h>
#include <limits.h>
#include <locale.h>
@@ -409,6 +410,24 @@ print_update(kdb_hlog_t *ulog, uint32_t entry, uint32_t ulogentries,
}
}
+/* Return a read-only mmap of the ulog, or NULL on failure. Assumes fd is
+ * released on process exit. */
+static kdb_hlog_t *
+map_ulog(const char *filename)
+{
+ int fd;
+ struct stat st;
+ kdb_hlog_t *ulog;
+
+ fd = open(filename, O_RDONLY);
+ if (fd == -1)
+ return NULL;
+ if (fstat(fd, &st) < 0)
+ return NULL;
+ ulog = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ return (ulog == MAP_FAILED) ? NULL : ulog;
+}
+
int
main(int argc, char **argv)
{
@@ -418,7 +437,6 @@ main(int argc, char **argv)
uint32_t entry = 0;
krb5_context context;
kadm5_config_params params;
- kdb_log_context *log_ctx;
kdb_hlog_t *ulog = NULL;
setlocale(LC_ALL, "");
@@ -458,17 +476,23 @@ main(int argc, char **argv)
printf(_("\nKerberos update log (%s)\n"), params.iprop_logfile);
- if (ulog_map(context, params.iprop_logfile, 0,
- reset ? FKADMIND : FKPROPLOG, NULL)) {
- fprintf(stderr, _("Unable to map log file %s\n\n"),
- params.iprop_logfile);
- exit(1);
+ if (reset) {
+ if (ulog_map(context, params.iprop_logfile, params.iprop_ulogsize)) {
+ fprintf(stderr, _("Unable to map log file %s\n\n"),
+ params.iprop_logfile);
+ exit(1);
+ }
+ if (ulog_init_header(context) != 0) {
+ fprintf(stderr, _("Couldn't reinitialize ulog file %s\n\n"),
+ params.iprop_logfile);
+ exit(1);
+ }
+ printf(_("Reinitialized the ulog.\n"));
+ exit(0);
}
- log_ctx = context->kdblog_context;
- if (log_ctx) {
- ulog = log_ctx->ulog;
- } else {
+ ulog = map_ulog(params.iprop_logfile);
+ if (ulog == NULL) {
fprintf(stderr, _("Unable to map log file %s\n\n"),
params.iprop_logfile);
exit(1);
@@ -479,16 +503,6 @@ main(int argc, char **argv)
exit(1);
}
- if (reset) {
- if (ulog_init_header(context) != 0) {
- fprintf(stderr, _("Couldn't reinitialize ulog file %s\n\n"),
- params.iprop_logfile);
- exit(1);
- }
- printf(_("Reinitialized the ulog.\n"));
- exit(0);
- }
-
printf(_("Update log dump :\n"));
printf(_("\tLog version # : %u\n"), ulog->db_version_num);
printf(_("\tLog state : "));